77 lines
2.1 KiB
JavaScript
77 lines
2.1 KiB
JavaScript
import userAPI from './api/user';
|
|
App({
|
|
shareTitle:'我的美搭,分享给你',
|
|
onLaunch() {
|
|
wx.onAppRoute((res)=>{
|
|
const page = getCurrentPages();
|
|
const currentPage = page[page.length-1];
|
|
if(currentPage&&!currentPage.useCustomShare){
|
|
currentPage.onShareAppMessage = async()=>{
|
|
let path = '/pages/try/index/index';
|
|
const token = wx.getStorageSync('token');
|
|
if(token){
|
|
if(!(this.globalData.userInfo&&this.globalData.userInfo.user_code)){
|
|
await this.getUserInfo();
|
|
}
|
|
if(this.globalData.userInfo.user_code){
|
|
path = `${path}?shared_user_code=${this.globalData.userInfo.user_code}`;
|
|
}
|
|
}
|
|
return {
|
|
title:this.shareTitle,
|
|
imageUrl:'/assets/img/share.jpg',
|
|
path:path
|
|
}
|
|
}
|
|
}
|
|
})
|
|
},
|
|
onShow(options){
|
|
if(options.query.shared_user_code){
|
|
this.globalData.shared_user_code = options.query.shared_user_code;
|
|
}
|
|
this.checkUpdate();
|
|
},
|
|
forceGetUserInfo(){
|
|
this.globalData.userInfoGetTime = null;
|
|
return this.getUserInfo();
|
|
},
|
|
async getUserInfo(){
|
|
if(this.globalData.userInfoGetTime&&
|
|
this.globalData.userInfo&&
|
|
new Date()-this.globalData.userInfoGetTime<1000*60*10){
|
|
return this.globalData.userInfo;
|
|
}
|
|
const data = await userAPI.getInfo();
|
|
this.globalData.userInfo = data;
|
|
this.globalData.userInfoGetTime = new Date();
|
|
return data;
|
|
},
|
|
globalData: {
|
|
userInfo: null
|
|
},
|
|
|
|
checkUpdate() {
|
|
if (!wx.canIUse('getUpdateManager')) {
|
|
return;
|
|
}
|
|
const updateManager = wx.getUpdateManager();
|
|
|
|
updateManager.onCheckForUpdate((res) => {
|
|
console.log(res);
|
|
});
|
|
updateManager.onUpdateReady(() => {
|
|
wx.showModal({
|
|
title: '更新提示',
|
|
content: '新版本已准备好,重启应用以使用新版本',
|
|
showCancel: false,
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
updateManager.applyUpdate();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
})
|