app.js
2.59 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//app.js
import router from './router/index.js'
import util from './utils/util.js'
import './utils/Track'
import {
ssoApi,
wechatApi
} from './api/api'
import {trackData} from './utils/data'
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
const systemInfo = wx.getStorageSync('aicard_system_info')
if (!systemInfo) wx.getSystemInfo({
success(res) {
util.setStorageSync('aicard_system_info', res)
}
})
if (options.path != 'pages/tab/index/index') {
this.login()
}
},
login(returnResponse) {
let _this = this
let openId = null
return new Promise((resolve, reject) => {
wx.login({
success({
code
}) {
ssoApi.jsCodeLogin({
code,
appId: wx.$appId
}).then(res => {
wx.$authStatus = res.code != 0
util.setSessionId(res.data.sessionId)
openId = res.data.openId
util.setStorageSync('openId', openId)
if (wx.$trackData.scene) {
_this.getScene(wx.$trackData.scene).then(res => {
wx.$trackData.merchant = res.merchantId
wx.$trackData.cardId = res.cardId
util.setStorageSync('scene', res)
const systemInfo = JSON.parse(wx.getStorageSync('aicard_system_info'))
wx.$trackData.type = systemInfo.environment ? 2 : 1
wx.$Track.sendTrack(trackData.COMPANY, openId)
})
}
ssoApi.getUserInfo({
openId
}).then(result => {
if (returnResponse) {
resolve(result)
} else {
if (result.code == 0) {
util.setUserInfo(result.data)
} else {
util.showToast(result.message || '网络异常')
}
resolve(result)
}
})
}).catch(() => {
wx.$authStatus = true
reject()
})
}
})
})
},
getScene(scene) {
return new Promise((resolve, reject) => {
wechatApi.getSceneById({
id: decodeURIComponent(scene).split('=')[1]
}).then(({data}) => {
let op = {}
data.scene.split('&').map(item => {
const [key, val] = item.split("=")
op[key] = val
})
resolve(op)
})
})
},
globalData: {
}
})