-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
53 lines (51 loc) · 1.14 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
//app.js
import Fetch from 'utils/services.js'
function wxlogin(that, cb){
wx.login({
success(res) {
const code = res.code
wx.getUserInfo({
success(res) {
that.globalData.userInfo = res.userInfo
res.userInfo.code = code
res.userInfo.u_type = 1
let data = res.userInfo
Fetch('/wechat/wx/', 'POST', data)
.then(res => {
wx.setStorageSync('token', res.data.token)
that.globalData.token = res.data.token
wx.setStorageSync('self', res.data.user_id)
that.globalData.self = res.data.user_id
that.globalData.gym = res.data.gym || ''
wx.setStorageSync('gym', res.data.gym || '')
typeof cb == 'function' && cb(that.globalData.userInfo)
})
}
})
},
fail(res) {
console.log('fail', res)
}
})
}
App({
onLaunch() {
console.log('app Launching ...')
// if(!this.globalData.token) {
// wxlogin(this)
// }
},
getUserInfo(cb) {
const that = this
// wxlogin(that, cb)
if(this.globalData.userInfo) {
typeof cb == 'function' && cb(this.globalData.userInfo)
} else {
//调用登录接口
wxlogin(that, cb)
}
},
globalData: {
userInfo: null
}
})