-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
75 lines (74 loc) · 2.28 KB
/
app.js
File metadata and controls
75 lines (74 loc) · 2.28 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import API from './global/request/api.js'
App({
onLaunch: function () {
// 展示本地存储能力
let user_id = wx.getStorageSync('user_id');
let userInfo = wx.getStorageSync('userInfo');
if (user_id && userInfo){
this.globalData.userInfo = userInfo;
this.globalData.user_id = user_id;
return
}
// this.login()
},
login: function(){
return new Promise((resolve, reject)=>{
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
wx.getUserInfo({
success: res => {
let userInfo = res.userInfo
this.globalData.userInfo = userInfo
wx.setStorageSync('userInfo', userInfo);
wx.login({
success: res => {
if (res.code) {
wx.request({
url: API.login,
method: 'POST',
data: {
code: res.code,
userInfo: userInfo
},
success: res => {
if (res.data.code !== 200) {
console.log(res.data.message)
return
}
this.globalData.user_id = res.data.data
wx.setStorageSync('user_id', res.data.data);
resolve('success')
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}
})
} else {
wx.showModal({
content: '您暂未授权,是否授权',
confirmColor: '#72bd4a',
success: res => {
if (res.confirm) {
wx.openSetting({
success(res){
console.log(!!res.authSetting['scope.userInfo'] ? '设置成功' : '设置失败');
},
});
}
}
});
}
}
})
})
},
globalData: {
userInfo: null,
user_id: null
}
})