-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
61 lines (55 loc) · 1.36 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
54
55
56
57
58
59
60
61
//app.js
var api = require('utils/api.js')
App({
onLaunch: function () {
},
// 获取微信授权凭证
getWXAuthor: function (callback) {
var that = this;
if (that.globalData.userId) {
typeof callback == "function" && callback(true);
} else {
//调用登录接口
wx.login({
success: function (e) {
that.globalData.code = e.code;
wx.setStorage({
key: "code",
data: e.code,
})
let param = {
'code': e.code
};
api.connectWX(param, function (res) {
console.log(res);
if (res.code == '1') {
if(res.data.id != '0'){
that.globalData.userId = res.data.id;
wx.setStorage({
key: "userId",
data: res.data.id,
})
typeof callback == "function" && callback(true);
}
}
typeof callback == "function" && callback(false);
});
}
});
}
},
getUserId: function (callback) {
var userId = wx.getStorageSync('userId');
if (userId != '') {
this.globalData.userId = userId;
typeof callback == "function" && callback(true);
}
else{
// 未登录
// this.getWXAuthor();
}
},
globalData: {
userId: null
}
})