-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
38 lines (37 loc) · 998 Bytes
/
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
// app.js
App({
onLaunch() {
var util = require('./utils/util.js')
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
util.tjRequest({
url:'/user/login',
method:'post',
data:{
code: res.code
}
}).then(res=>{
wx.setStorage({key:'token', data:res.data.token})
if(res.data.role === 3)
wx.setStorage({key:'role', data:'admin'})
else if(res.data.role === 1)
wx.setStorage({key:'role', data:'student'})
else if(res.data.role === 2)
wx.setStorage({key:'role', data:'store'})
}).catch(err=>{
wx.setStorage({key:'token', data:''})
if(err.statusCode===404){
wx.redirectTo({
url: '/pages/login/user_role_choice/user_role_choice',
})
}
})
}
})
},
globalData: {
userInfo: null
}
})