app.js
1.33 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
//app.js
import router from './router/index.js'
import util from './utils/util.js'
import './utils/Track'
import {
ssoApi
} from './api/api'
App({
onLaunch: function () {
/**挂载到wx对象 */
wx.$util = util
wx.$router = router
const systemInfo = wx.getStorageSync('srcm_shopmall_system_info')
if (!systemInfo) wx.getSystemInfo({
success(res) {
util.setStorageSync('srcm_shopmall_system_info', res)
}
})
this.login()
},
login(returnResponse) {
let _this = this
return new Promise((resolve, reject) => {
wx.login({
success({
code
}) {
ssoApi.jsCodeLogin({
code,
appId: _this.globalData.appId
}).then(res => {
wx.$authStatus = res.code != 0
if (returnResponse) {
resolve(res)
} else {
if (res.code != -1) {
if (res.code == 0) {
util.setUserInfo(res.data)
util.setSessionId(res.data.sessionId)
} else {
util.showToast(res.message || '网络异常')
}
}
resolve(res)
}
}).catch(() => {
wx.$authStatus = true
reject()
})
}
})
})
},
globalData: {
}
})