77 lines
1.7 KiB
JavaScript
77 lines
1.7 KiB
JavaScript
import userApi from './api/user';
|
|
import commonApi from './api/common';
|
|
App({
|
|
onLaunch() {
|
|
// 展示本地存储能力
|
|
const logs = wx.getStorageSync('logs') || []
|
|
logs.unshift(Date.now())
|
|
wx.setStorageSync('logs', logs)
|
|
|
|
// 登录
|
|
wx.login({
|
|
success: res => {
|
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
}
|
|
})
|
|
wx.getStorage({
|
|
key:'accessToken',
|
|
success:(res)=>{
|
|
this.globalData.accessToken = res.data;
|
|
if(res.data){
|
|
userApi.info().then((data)=>{
|
|
this.globalData.userInfo = data;
|
|
});
|
|
}
|
|
}
|
|
})
|
|
},
|
|
navToLogin(){
|
|
wx.navigateTo({
|
|
url: '/pages/login/login',
|
|
})
|
|
},
|
|
globalData: {
|
|
userInfo: null,
|
|
accessToken:null,
|
|
community:{
|
|
_list:[],
|
|
lastFetchTime:null,
|
|
getList(){
|
|
let lft = this.lastFetchTime;
|
|
return new Promise((rs,rj)=>{
|
|
if(!lft&&new Date()-lft>30){
|
|
commonApi.community.list().then((data)=>{
|
|
this.lastFetchTime = new Date();
|
|
this._list = data;
|
|
rs(data)
|
|
})
|
|
}else{
|
|
rs(this._list);
|
|
}
|
|
})
|
|
},
|
|
},
|
|
address:{
|
|
_list:[],
|
|
lastFetchTime:null,
|
|
getList(){
|
|
let lft = this.lastFetchTime;
|
|
return new Promise((rs,rj)=>{
|
|
if(!lft&&new Date()-lft>30){
|
|
commonApi.address.list().then((data)=>{
|
|
this.lastFetchTime = new Date();
|
|
this._list = data;
|
|
rs(data)
|
|
})
|
|
}else{
|
|
rs(this._list);
|
|
}
|
|
})
|
|
},
|
|
}
|
|
},
|
|
getAddressList(){
|
|
|
|
}
|
|
})
|