app.js
7.38 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//app.js
// 初始化sentry
import sentryInit from '~/utils/sentryConfig/sentryInit'
const sentry = sentryInit()
wx.$sendSentry = function (e) {
sentry.captureException(e)
}
// 解决showLoading 和 showToast显示异常的问题
import fixWxShowToast from './utils/lib/fixWxShowToast'
fixWxShowToast()
import router from './router/index.js'
// 判断小程序是否需要更新
import getUpdateManager from './utils/lib/wxUpdateManager'
import util from './utils/util.js'
import wxApi from './utils/utils_wx'
// 实例化对象存储
import { Storage } from '~/utils/cache/storage'
const $Storage = new Storage()
import {
setSystem_info,
getNoSignInUuid,
removeSystemStorage,
rmNoSignInUuid
} from '~/utils/cache/storageApi'
setSystem_info() // 存储设备信息
import { checkYqdSuper, checkScene } from '~/store/index'
import eventbus from './utils/eventbus'
import api from './api/api'
import { Version } from 'glsx-common-sdk'
import { areaList } from '@vant/area-data' //预加载省市区
import globalDataFunction from './mixins/globalDataFunction'
/**全埋点 */
import Track from '~/utils/track'
const $Track = new Track()
// 将 api.reNoSignIn() 函数包装为防抖函数
const debouncedReNoSignIn = debounce(function (noSignInUuid, that) {
console.log('debouncedReNoSignIn2222')
api
.reNoSignIn({
noSignInUuid: noSignInUuid
})
.then(res => {
let { code, data } = res
if (code == '0' && data) {
util.setSessionId(data?.sessionId)
// debugger
// 还要判断一下他是不是全部登录完,不是直接打到账号选择页面
if (!data.needSelectAccount) {
wx.reLaunch({ url: '/pages/loading/loading' })
} else {
// debugger
wx.reLaunch({ url: '/pages/accountItems/accountItems' })
}
} else {
util.removeStorage()
removeSystemStorage()
that.login(false)
}
})
}, 0) // 设置防抖时间为 0 秒
// }, 0); // 设置防抖时间为 5 秒
// 定义一个防抖函数
function debounce(func, timeout) {
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(() => {
func.apply(this, args)
}, timeout)
}
}
App({
onLaunch() {
/**挂载到wx对象 */
wx.$storage = $Storage /** 挂载全局缓存方法 */
wx.$router = router
wx.$modal = this.showModal
wx.$util = util
wx.$api = wxApi
wx.$eventbus = eventbus
wx.$areaList = areaList
wx.$track = $Track
let userInfo = util.getStorageSync('dj_boutique_user_info')
// ,this.globalData, userInfo
userInfo && this.gobalCheckYqdSuper(userInfo)
wx.$versionConfig = new Version({
request: {
baseUrl: 'https://config-center-backend.glsx.com.cn/glsxAdmin/config',
isSign: false
}
})
wx.$globalDataFunction = globalDataFunction
},
async getVersionInfo(request) {
if (request) this.globalData.versionData = null
const { versionData } = this.globalData
if (versionData) return versionData
else {
const res = await wx.$versionConfig.get({
moduleUrl: 'dj-car-boutique-work-wechat',
// moduleUrl: 'business-assistant',
env: 'update'
})
this.globalData.versionData = res
return res
}
},
showModal(that, options, id = '#modal') {
// id = id || "#modal";
that.selectComponent(id).showModal(options)
},
gobalCheckYqdSuper(userInfo) {
checkYqdSuper(userInfo, this.globalData)
},
onShow(options) {
wx.onMemoryWarning(function () {
console.log('onMemoryWarningReceive')
})
// console.log('lifeshow')
getUpdateManager()
// options = {
// query: {
// page: 'playVideo',
// type: 1,
// title: '内容通知-培训资料-视频',
// id: 30,
// merchantId: 44211025
// }
// }
if (options) {
console.log('options', options)
let res = checkScene(options)
// console.log(res, 'res')
// 如果需要重新登录 去掉30天免登录逻辑避免自动登录直接跳回到首页去
if (res) {
rmNoSignInUuid()
this.login(true, res)
}
// res &&
}
},
login(relogin, context, RequestMethods) {
let that = this
// 清空多账号信息
if (relogin) {
// 判断有没有 30 天免登陆 有直接跳选园区
let noSignInUuid = getNoSignInUuid()
console.log('noSignInUuid', noSignInUuid)
if (noSignInUuid) {
// 调用防抖函数
debouncedReNoSignIn(noSignInUuid, that)
// util.debounce(() => {
// console.log(1112);
// api
// .reNoSignIn({
// noSignInUuid: noSignInUuid
// })
// .then(res => {
// let { code, data } = res
// if (code == '0' && data) {
// // util.setUserinfo( console.log('noSignInUuid_sessionId',data?.sessionId);
// // wx.reLaunch({url: '/pages/accountItems/accountItems'})
// util.setSessionId(data?.sessionId)
// wx.reLaunch({ url: '/pages/loading/loading' })
// } else {
// util.removeStorage()
// removeSystemStorage()
// that.login(false)
// }
// })
// }, 500, true)
} else {
let thisPage = wx.$router.getPageInstance()
// 启动页loading中的埋点接口 在触发登录超时后 ios端wx.showModal会被页面跳转截断,导致无弹窗,将loading页面这个埋点接口的登录超时不做弹窗处理
if (
thisPage?.route == 'pages/loading/loading' &&
RequestMethods.includes('dj.api.smartcarlife.staff.login.record.save')
)
return
// 标志位 解决安卓查复弹框问题
if (wx.__HAS_NOTLOGIN_MODAL) return false
wx.__HAS_NOTLOGIN_MODAL = true
wx.showModal({
title: '温馨提示',
content: context || '登录过期,请重新登录。',
showCancel: false,
confirmText: '去登录',
confirmColor: '#2C66F7',
success(res) {
if (res.confirm) {
that.globalData.yqdInfo = {}
that.globalData.YQorderSetting = ''
that.globalData.YQList = ''
that.globalData.businessSchoolScene = ''
util.removeStorage()
wx.$relogin = relogin
router.reLaunch('pages.wxLogin')
}
},
complete: () => {
// 这个延迟的目的是为了避免短时间内重复弹出
// 你要是没有这个需要也可以去掉,直接把标志位改成 false 就行
setTimeout(() => {
wx.__HAS_NOTLOGIN_MODAL = false
}, 2000)
}
})
}
} else {
this.globalData.yqdInfo = {}
this.globalData.YQorderSetting = ''
this.globalData.YQList = ''
this.globalData.businessSchoolScene = ''
util.removeStorage()
removeSystemStorage()
wx.$relogin = relogin
router.reLaunch('pages.wxLogin')
}
},
globalData: {
statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'], // 头部导航栏的高度
yqdInfo: {},
isYqdSuper: true,
isStaff: false,
YQorderSetting: '',
count: '',
versionData: null,
businessSchoolScene: '',
ROUTE_QUERY: {}, //路由携带的参数
isChoosingMedia: false
}
})