app.js
1.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//app.js
import router from './router/index.js'
import util from './utils/util.js'
import './utils/Track'
import {
ssoApi,
wechantApi
} from './api/api'
App({
onLaunch: function (options) {
/**挂载到wx对象 */
wx.$util = util
wx.$router = router
wx.$imgUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/'
wx.$appId = wx.getAccountInfoSync().miniProgram.appId
this.globalData.appId = wx.getAccountInfoSync().miniProgram.appId
const systemInfo = wx.getStorageSync('srcm_shopmall_system_info')
if (!systemInfo) wx.getSystemInfo({
success(res) {
util.setStorageSync('srcm_shopmall_system_info', res)
}
})
console.log(options)
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 => {
console.log(res)
wx.$authStatus = res.code != 0
util.setSessionId(res.data.sessionId)
const openId = res.data.openId
wechantApi.getUserInfo({
openId
}).then(result => {
console.log(result)
if (returnResponse) {
console.log(result,' ====')
resolve(result)
} else {
if (result.code != -1) {
if (result.code == 0) {
util.setUserInfo(result.data)
if (result.data.nickName) {
wx.$nickName = result.data.nickName
}
} else {
util.showToast(result.message || '网络异常')
}
}
resolve(result)
}
})
}).catch(() => {
wx.$authStatus = true
reject()
})
}
})
})
},
globalData: {
}
})