-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (49 loc) · 1.51 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//app.js
App({
onLaunch: function () {
this.login().then((res)=>{
this.globalData.code = res;
}).catch(()=>{
wx.showToast({
title: '网络异常!',
icon: "none",
duration: 1000
});
});
// 获取系统状态栏信息
wx.getSystemInfo({
success: e => {
this.globalData.StatusBar = e.statusBarHeight;
let capsule = wx.getMenuButtonBoundingClientRect();
if (capsule) {
this.globalData.Custom = capsule;
this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
} else {
this.globalData.CustomBar = e.statusBarHeight + 50;
}
}
})
},
globalData: {
userInfo: null
},
login: function() {
return new Promise((resolve,reject)=>{
let token = wx.getStorageSync("token") || "";
// 登录接口,没有token,那么获取到 code 存到 data 里面,使用code向服务器端获取token
if (!token) {
wx.login({
success: codeInfo => {
console.log("code: ",codeInfo);
let code = codeInfo.code;
resolve(code)
},
fail(err){
console.log("登录异常");
reject(err)
}
});
}
})
},
})