-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
70 lines (64 loc) · 2.06 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
62
63
64
65
66
67
68
69
70
// app.js
const api = require("./config/api")
App({
api: api,
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
let that = this;
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 token 与 用户信息
if (res.code) {
wx.request({
url: api.loginAPI,
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
'code': res.code,
},
success: function (r) {
console.log(r.data.data.token);
if(r.data.code === 0){ //登录成功
that.globalData.token = r.data.data.token;
that.globalData.name = r.data.data.name;
that.globalData.num = r.data.data.num;
that.globalData.classnum = r.data.data.classnum;
//检测是否有回调函数,如果有,则执行
if(that.userInfoCallback){
that.userInfoCallback(res)
}
if(r.data.data.num === ''){ //需要完善个人信息
wx.showModal({
title: '个人信息待完善',
content: '是否完善个人信息?',
success (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/selfset/selfset',
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
}
}
})
}
}
})
},
globalData: {
name: '',
num: '',
classnum: '',
token: ''
}
})