50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import commonApi from './api/common';
|
|
import userApi from './api/user';
|
|
const token = wx.getStorageSync('accessToken');
|
|
|
|
App({
|
|
verifyCodeWaitingTime:60,
|
|
onLaunch() {
|
|
// 展示本地存储能力
|
|
const logs = wx.getStorageSync('logs') || []
|
|
logs.unshift(Date.now())
|
|
wx.setStorageSync('logs', logs)
|
|
|
|
// 登录
|
|
wx.login({
|
|
success: res => {
|
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
}
|
|
})
|
|
},
|
|
async getAppConfig(){
|
|
if(!this.globalData.appConfig){
|
|
const data = await commonApi.getConfig();
|
|
this.globalData.appConfig = {};
|
|
data.map((item)=>{
|
|
this.globalData.appConfig[item.key] = item.value;
|
|
})
|
|
}
|
|
return this.globalData.appConfig;
|
|
},
|
|
forceGetUserInfo(){
|
|
this.globalData.userInfoGetTime = null;
|
|
return this.getUserInfo();
|
|
},
|
|
async getUserInfo(){
|
|
if(this.globalData.userInfoGetTime&&
|
|
this.globalData.userInfo&&
|
|
new Date()-this.globalData.userInfoGetTime<1000*60*5){
|
|
return this.globalData.userInfo;
|
|
}
|
|
const data = await userApi.info();
|
|
this.globalData.userInfo = data;
|
|
this.globalData.userInfoGetTime = new Date();
|
|
return data;
|
|
},
|
|
globalData: {
|
|
userInfo: null,
|
|
accessToken:token
|
|
}
|
|
})
|