| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //app.js
- var app = getApp();
- // var wxh = require('../../utils/wxh.js');
- App({
- onLaunch: function () {
- // 展示本地存储能力
- var that = this;
- var logs = wx.getStorageSync('logs') || []
- logs.unshift(Date.now())
- wx.setStorageSync('logs', logs)
- that.getRoutineStyle();
- },
- globalData: {
- routineStyle:'#ffffff',
- uid: null,
- openPages:'',
- spid:0,
- urlImages: '',
- url: 'https://shop.crmeb.net/'
- },
- getRoutineStyle:function(){
- var that = this;
- wx.request({
- url: that.globalData.url + '/routine/login/get_routine_style',
- method: 'post',
- dataType : 'json',
- success: function (res) {
- that.globalData.routineStyle = res.data.data.routine_style;
- that.setBarColor();
- }
- })
- },
- setBarColor:function(){
- var that = this;
- wx.setNavigationBarColor({
- frontColor: '#000000',
- backgroundColor: that.globalData.routineStyle,
- })
- },
- setUserInfo : function(){
- var that = this;
- if (that.globalData.uid == null) {//是否存在用户信息,如果不存在跳转到首页
- wx.showToast({
- title: '用户信息获取失败',
- icon: 'none',
- duration: 1500,
- })
- setTimeout(function () {
- wx.navigateTo({
- url: '/pages/enter/enter',
- })
- }, 2000)
- }
- },
- getUserInfo: function () {
- var that = this;
- wx.getUserInfo({
- lang: 'zh_CN',
- success: function (res) {
- var userInfo = res.userInfo
- wx.login({
- success: function (res) {
- if (res.code) {
- userInfo.code = res.code;
- userInfo.spid = that.globalData.spid;
- wx.request({
- url: that.globalData.url + '/routine/login/index',
- method: 'post',
- dataType : 'json',
- data: {
- info: userInfo
- },
- success: function (res) {
- that.globalData.uid = res.data.data.uid;
- if (!res.data.data.status){
- wx.redirectTo({
- url: '/pages/login-status/login-status',
- })
- }
- if (that.globalData.openPages != '') {
- wx.navigateTo({
- url: that.globalData.openPages
- })
- } else {
- wx.switchTab({
- url: '/pages/index/index'
- })
- }
- },
- fail: function () {
- console.log('获取用户信息失败');
- wx.navigateTo({
- url: '/pages/enter/enter',
- })
- },
- })
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- },
- fail: function () {
- console.log('获取用户信息失败');
- wx.navigateTo({
- url: '/pages/enter/enter',
- })
- },
- })
- },
- fail:function(){
- console.log('获取用户信息失败');
- wx.navigateTo({
- url: '/pages/enter/enter',
- })
- },
- })
- },
- getUserInfoEnter: function () {
- var that = this;
- wx.getUserInfo({
- lang: 'zh_CN',
- success: function (res) {
- var userInfo = res.userInfo
- wx.login({
- success: function (res) {
- if (res.code) {
- userInfo.code = res.code;
- userInfo.spid = that.globalData.spid;
- wx.request({
- url: that.globalData.url + '/routine/login/index',
- method: 'post',
- dataType : 'json',
- data: {
- info: userInfo
- },
- success: function (res) {
- that.globalData.uid = res.data.data.uid;
- if (that.globalData.openPages != '') {
- wx.navigateTo({
- url: that.globalData.openPages
- })
- } else {
- wx.reLaunch({
- url: '/pages/index/index'
- })
- }
- }
- })
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- },
- fail: function (res) {
- wx.showToast({
- title: '授权失败,请重新打开小程序',
- icon: 'none',
- duration: 1500,
- })
- }
- })
- },
- fail: function (res) {
- wx.showToast({
- title: '授权失败,请重新授权',
- icon: 'none',
- duration: 1500,
- })
- }
- })
- },
- })
|