// app.ts import api from "./api/index"; App({ globalData: { getUserLoad: false }, onLaunch() { // 登录 const nowTime = Date.now() - (wx.getStorageSync("tokenTime") || 0) >= 86400000 * 7; (!wx.getStorageSync("token") || nowTime) && this.wLogin(); // 获取用户手机号 this.globalData.phone = wx.getStorageSync("userphone") || ""; // 获取授权内容 wx.getSetting({ success: res => { this.globalData.setting = res ? res.authSetting : {} } }); this.globalData.SystemInfo = wx.getSystemInfoSync(); this.globalData.FileSystemManager = wx.getFileSystemManager(); console.log(this.globalData.SystemInfo.SDKVersion); }, wLogin() { wx.login({ fail: err => { console.log(err) }, success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId this.login({ data: { code: res.code }, success: (res: any) => { wx.setStorageSync("token", res.token); wx.setStorageSync("tokenTime", Date.now()); } }) }, }) }, ...api })