-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (42 loc) · 1016 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
39
40
41
42
43
44
//app.js
var Util = require('./utils/util.js')
// 获取当前的用户信息
let fetchMemInfo = (that, cb) => {
Util.request('session', 'GET', {}, res => {
that.globalData.session = res.data
})
}
App({
onLaunch: function () {
let that = this
var session = wx.getStorageSync('session')
if (session) {
that.globalData.session = session
return
}
wx.login({
success: function (lores) {
if (lores.code) {
wx.getUserInfo({
success: function (res) {
Util.request('auth/wxsp', 'POST', {
code: lores.code,
info: res.userInfo
}, res => {
that.globalData.session = {
token: res.data.token
}
fetchMemInfo(that, function () {
wx.setStorageSync('session', that.globalData)
})
})
}
})
}
}
})
},
globalData:{
userInfo:null
}
})