import gulpError from './utils/gulpError'; import userModel from './utils/userModel' import { currentUser } from './api/api' App({ onLaunch() { let that = this; wx.getSystemInfo({ success: function (res) { that.globalData.statusBarHeight = res.statusBarHeight console.log(res) } }) const token = wx.getStorageSync('token') || ''; if (!token) { wx.login({ success: res1 => { // 发送 res.code 到后台换取 openId, sessionKey, unionId console.log(res1.code) const param = { code: res1.code } userModel.login(param).then(res => { currentUser().then(res => { this.globalData.currentUser = res.data wx.reLaunch({ url: '/pages/index/index', }) }) }).catch(() => { wx.reLaunch({ url: '/pages/login/login', }) }) } }) } else { currentUser().then(res => { this.globalData.currentUser = res.data wx.reLaunch({ url: '/pages/index/index', }) }) } }, onShow() { if (gulpError !== 'gulpErrorPlaceHolder') { wx.redirectTo({ url: `/pages/gulp-error/index?gulpError=${gulpError}`, }); } }, globalData: { currentUser: {}, statusBarHeight: 0 } });