This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
46 lines (42 loc) · 1.47 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
// 程序启动页
const { USER_LOGIN } = require('/utils/constant.js');
App({
globalData: {
cust_id: -1,
openid: ''
},
onLaunch: function () {
this.userLogin(this);
},
/**
* 用户登录
*/
userLogin(self) {
const promise = new Promise((resolve, reject) => {
wx.login({
success: function (res) {
if (res.code) {
wx.request({
url: USER_LOGIN,
data: {
code: res.code
},
success: function (result) {
const data = result.data;
if (data.code == 0) {
const openid = data.data.openid;
const cust_id = data.data.cust_id;
wx.setStorageSync('cust_id', cust_id);
wx.setStorageSync('openid', openid);
self.globalData.cust_id = cust_id;
self.globalData.openid = openid;
}
}
})
}
}
});
});
return promise;
}
})