@conecli/cone-render 0.9.1-shop2.21 → 0.9.1-shop2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/index.h5.ts +1 -1
- package/package.json +1 -1
package/dist/common/index.h5.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
isIosDevice,
|
|
3
2
|
isAndroidDevice,
|
|
4
3
|
isJdAndHarmonyDevice,
|
|
5
4
|
isJdAndAndroidDevice,
|
|
6
5
|
jdAppVersion,
|
|
7
6
|
jdAppVersionStr,
|
|
8
7
|
isString,
|
|
9
8
|
isObject,
|
|
10
9
|
serialize,
|
|
11
10
|
dealNativePixelToCssPixel,
|
|
12
11
|
isPc,
|
|
13
12
|
BUSINESS_TYPE,
|
|
14
13
|
JSSDK_APP_WEBVIEW_CODE,
|
|
15
14
|
SECTION_HOME_TAB_NAME_TYPE,
|
|
16
15
|
SECTION_HOME_TAB_TYPE,
|
|
17
16
|
WXAPP_BIZ_KEY,
|
|
18
17
|
WX_BUSINESS_TYPE,
|
|
19
18
|
MPAAS_CONFIG_APP_VERSION,
|
|
20
19
|
MPAAS_CONFIG_APP_LOW_VERSION,
|
|
21
20
|
WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
22
21
|
LoadJsInitLoadEnvType,
|
|
23
22
|
LoadJsInitLoadType,
|
|
24
23
|
LoadJsInitTriggerType
|
|
25
24
|
loginState: false,
|
|
26
25
|
cookiesStr: '',
|
|
27
26
|
userInfo: userPinKey,
|
|
28
27
|
isJingGouMiniViewState: false,
|
|
29
28
|
isJingxiMiniViewState: false,
|
|
30
29
|
pageInfo: {
|
|
31
30
|
wxBusinessType: WX_BUSINESS_TYPE.NO,
|
|
32
31
|
address: '',
|
|
33
32
|
addressCommaStr: '',
|
|
34
33
|
un_area: '',
|
|
35
34
|
vapptype: '1',
|
|
36
35
|
pageType: 'home',
|
|
37
36
|
isExposureState: false,
|
|
38
37
|
moduleId: '',
|
|
39
38
|
entrance: '',
|
|
40
39
|
dataType: BUSINESS_TYPE.ONLINE,
|
|
41
40
|
floorExposureInfo: {},
|
|
42
41
|
floorVideInfo: {},
|
|
43
42
|
productVideInfo: {},
|
|
44
43
|
tabsLoadAllDataInfo: {
|
|
45
44
|
[SECTION_HOME_TAB_NAME_TYPE[
|
|
46
45
|
SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
|
|
47
46
|
]]: false,
|
|
48
47
|
},
|
|
49
48
|
updateShopInfosAllState: false,
|
|
50
49
|
isVipShop: false,
|
|
51
50
|
isJdShowNativeImmersivePlayer: false,
|
|
52
51
|
...shopConfig,
|
|
53
52
|
pageScrollTop: 0,
|
|
54
53
|
pageIdxHeightInfo: {
|
|
55
54
|
list: [],
|
|
56
55
|
},
|
|
57
56
|
shopNavBarHeight: 0,
|
|
58
57
|
},
|
|
59
58
|
defaultQueryLogInfo: {
|
|
60
59
|
sourceType: 'JDshop',
|
|
61
60
|
sourceValue: '',
|
|
62
61
|
moduleId: 'none',
|
|
63
62
|
entrance: 'none',
|
|
64
63
|
},
|
|
65
64
|
sysInfo: {
|
|
66
65
|
windowWidth: isPc ? 375 : 0,
|
|
67
66
|
containerWidth: isPc ? 375 : 0,
|
|
68
67
|
windowHeight: 0,
|
|
69
68
|
netWorkType: '4g',
|
|
70
69
|
jdBottomBarHeight: 0,
|
|
71
70
|
jdNativeHeaderHeight: 0,
|
|
72
71
|
},
|
|
73
72
|
queryInfo: {},
|
|
74
73
|
shopInfo: {},
|
|
75
74
|
openAppData: {},
|
|
76
75
|
public info: CommonInterFace.BaseConfigInfo
|
|
77
76
|
public config: {
|
|
78
77
|
[key: string]: any
|
|
79
78
|
}
|
|
80
79
|
public lazyContainer: CommonInterFace.lazyContainer
|
|
81
80
|
public renderedIsvComponents: CommonInterFace.renderedIsvComponents
|
|
82
81
|
public rootEleNode: HTMLElement | null
|
|
83
82
|
public checkStatusAndLoginPromise: object | null
|
|
84
83
|
private jmfeRegisterStatePromise: Promise<any> | null
|
|
85
84
|
private jmfeRegisterState: boolean
|
|
86
85
|
public loadJsSdkList: Array<any>
|
|
87
86
|
public loadJsSdkListCachePromise: any
|
|
88
87
|
constructor(opt) {
|
|
89
88
|
this.info = this._getConfig(opt)
|
|
90
89
|
this.config = {}
|
|
91
90
|
this.loadJsSdkList = []
|
|
92
91
|
this.loadJsSdkListCachePromise = {}
|
|
93
92
|
this.lazyContainer = {
|
|
94
93
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
|
|
95
94
|
appLazyContainerList: [],
|
|
96
95
|
appLazyFinishContainerList: [],
|
|
97
96
|
},
|
|
98
97
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
|
|
99
98
|
appLazyContainerList: [],
|
|
100
99
|
appLazyFinishContainerList: [],
|
|
101
100
|
},
|
|
102
101
|
}
|
|
103
102
|
this.renderedIsvComponents = {}
|
|
104
103
|
this.rootEleNode = document.querySelector('body')
|
|
105
104
|
this.checkStatusAndLoginPromise = null
|
|
106
105
|
this.jmfeRegisterStatePromise = null
|
|
107
106
|
this.loadOtherSdk()
|
|
108
107
|
isJdApp && this.jmfeReayPromise()
|
|
109
108
|
}
|
|
110
109
|
_getConfig(opt) {
|
|
111
110
|
return Object.assign({}, DefaultConfig, opt)
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
jmfeReayPromise(): Promise<any> {
|
|
115
114
|
if (isJdApp) {
|
|
116
115
|
if (this.jmfeRegisterState) {
|
|
117
116
|
return Promise.resolve(true)
|
|
118
117
|
} else {
|
|
119
118
|
!this.jmfeRegisterStatePromise &&
|
|
120
119
|
(this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
|
|
121
120
|
ready('jmfe', 3000)
|
|
122
121
|
.then(() => {
|
|
123
122
|
window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
|
|
124
123
|
this.jmfeRegisterState = true
|
|
125
124
|
resolve(true)
|
|
126
125
|
console.log('松果app内初始化注册jmfe认证完成')
|
|
127
126
|
})
|
|
128
127
|
.catch(() => {
|
|
129
128
|
reject(false)
|
|
130
129
|
})
|
|
131
130
|
}))
|
|
132
131
|
return this.jmfeRegisterStatePromise
|
|
133
132
|
}
|
|
134
133
|
} else {
|
|
135
134
|
return Promise.reject(false)
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
updateBusinessDomainAndApi(domain, api) {
|
|
140
139
|
}
|
|
141
140
|
|
|
142
141
|
formatNativeScreenPageData(action) {
|
|
143
142
|
let getChangePageInfo: any = null
|
|
144
143
|
try {
|
|
145
144
|
const getNativeScreenPageInfoStr = window.XWebView?._callNative(
|
|
146
145
|
JSON.stringify({
|
|
147
146
|
plugin: 'JDHybridScreenPlugin',
|
|
148
147
|
action,
|
|
149
148
|
sync: '1',
|
|
150
149
|
}),
|
|
151
150
|
)
|
|
152
151
|
const getChangePageInfoData =
|
|
153
152
|
typeof getNativeScreenPageInfoStr === 'string'
|
|
154
153
|
? JSON.parse(getNativeScreenPageInfoStr)
|
|
155
154
|
: null
|
|
156
155
|
if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
|
|
157
156
|
const { code, data } = getChangePageInfoData
|
|
158
157
|
getChangePageInfo = code && code === '0' ? data : null
|
|
159
158
|
}
|
|
160
159
|
} catch (e) {
|
|
161
160
|
console.log('JDHybridScreenPlugin转换异常', e)
|
|
162
161
|
}
|
|
163
162
|
return getChangePageInfo
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
isAndroidFoldScreen() {
|
|
167
166
|
return this.formatNativeScreenPageData('isFoldScreen') === '1'
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
getJdAndroidPageChangeScreenInfo() {
|
|
171
170
|
const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
|
|
172
171
|
if (
|
|
173
172
|
getPageScreenInfo &&
|
|
174
173
|
getPageScreenInfo?.pageWidth &&
|
|
175
174
|
getPageScreenInfo?.pageHeight
|
|
176
175
|
) {
|
|
177
176
|
const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
|
|
178
177
|
pageWidth: getPageScreenInfo.pageWidth,
|
|
179
178
|
pageHeight: getPageScreenInfo.pageHeight,
|
|
180
179
|
})
|
|
181
180
|
getPageScreenInfo.pageWidth = pageWidth
|
|
182
181
|
getPageScreenInfo.pageHeight = pageHeight
|
|
183
182
|
}
|
|
184
183
|
return getPageScreenInfo
|
|
185
184
|
}
|
|
186
185
|
|
|
187
186
|
getSystemInfo(params) {
|
|
188
187
|
let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
|
|
189
188
|
? {}
|
|
190
189
|
: getSystemInfos(params)
|
|
191
190
|
if (isJdAndAndroidDevice && window.innerWidth <= 0) {
|
|
192
191
|
const isfoldScreen = this.isAndroidFoldScreen()
|
|
193
192
|
if (isfoldScreen) {
|
|
194
193
|
const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
|
|
195
194
|
getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
|
|
196
195
|
console.info(
|
|
197
196
|
'安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
|
|
198
197
|
getJdAndroidPageInfo,
|
|
199
198
|
)
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
this.info.sysInfo = {
|
|
203
202
|
actualNavBarHeight: 0,
|
|
204
203
|
...this.info.sysInfo,
|
|
205
204
|
...info,
|
|
206
205
|
safeContentHeight: info?.screenHeight,
|
|
207
206
|
headerHeight: 0,
|
|
208
207
|
tabBarHeight: 0,
|
|
209
208
|
}
|
|
210
209
|
if (isJdApp) {
|
|
211
210
|
this.info.sysInfo['hostVersionName'] = jdAppVersionStr
|
|
212
211
|
this.info.sysInfo['hostAppVersion'] = jdAppVersion
|
|
213
212
|
this.getAddressCachePromise()
|
|
214
213
|
this.getElderModePromise()
|
|
215
214
|
this.getJDAppearanceStatePromise()
|
|
216
215
|
this.createJdAndroidRquestEventForTouchStart()
|
|
217
216
|
}
|
|
218
217
|
this.getWifiVideoAutoPlayAsync()
|
|
219
218
|
this.getMPaasConfigAsync()
|
|
220
219
|
this.getNetWorkType()
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
taskTimeoutPromise(callBack, timeout = 2000) {
|
|
224
223
|
return new Promise(resolve => {
|
|
225
224
|
setTimeout(() => {
|
|
226
225
|
const getCallBackRes = typeof callBack === 'function' && callBack()
|
|
227
226
|
return resolve(getCallBackRes || false)
|
|
228
227
|
}, timeout)
|
|
229
228
|
})
|
|
230
229
|
}
|
|
231
230
|
|
|
232
231
|
getElderModePromise() {
|
|
233
232
|
if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
|
|
234
233
|
return Promise.resolve(this.info.sysInfo.jdAppModeType)
|
|
235
234
|
} else {
|
|
236
235
|
if (isJdAndAndroidDevice) {
|
|
237
236
|
this.info.sysInfo.jdAppModeType = '0'
|
|
238
237
|
return Promise.resolve(this.info.sysInfo.jdAppModeType)
|
|
239
238
|
} else {
|
|
240
239
|
return Promise.race([
|
|
241
240
|
this.taskTimeoutPromise(() => {
|
|
242
241
|
this.info.sysInfo.jdAppModeType = '0'
|
|
243
242
|
return this.info.sysInfo.jdAppModeType
|
|
244
243
|
}),
|
|
245
244
|
new Promise(resolve => {
|
|
246
245
|
const getCallBackName = `getJdCurrentModeType${Date.now()}`
|
|
247
246
|
if (!window[getCallBackName]) {
|
|
248
247
|
window[getCallBackName] = res => {
|
|
249
248
|
try {
|
|
250
249
|
const getResJson =
|
|
251
250
|
typeof res === 'string' ? JSON.parse(res) : res
|
|
252
251
|
const { status, data, msg } = getResJson
|
|
253
252
|
console.log(`获取松果app展示模式成功,返回结果${data}`)
|
|
254
253
|
if (status === '0') {
|
|
255
254
|
this.info.sysInfo.jdAppModeType = data
|
|
256
255
|
resolve(data)
|
|
257
256
|
} else {
|
|
258
257
|
resolve('0')
|
|
259
258
|
}
|
|
260
259
|
} catch (e) {
|
|
261
260
|
resolve('0')
|
|
262
261
|
}
|
|
263
262
|
window[getCallBackName] = null
|
|
264
263
|
}
|
|
265
264
|
}
|
|
266
265
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
267
266
|
method: 'callSyncRouterModuleWithParams',
|
|
268
267
|
params: JSON.stringify({
|
|
269
268
|
routerURL: 'router://JDBModeModule/getCurrentMode',
|
|
270
269
|
routerParam: {},
|
|
271
270
|
callBackName: `window.${getCallBackName}`,
|
|
272
271
|
callBackId: `${getCallBackName}Ios`,
|
|
273
272
|
}),
|
|
274
273
|
})
|
|
275
274
|
}),
|
|
276
275
|
])
|
|
277
276
|
}
|
|
278
277
|
}
|
|
279
278
|
}
|
|
280
279
|
|
|
281
280
|
getJDAppearanceStatePromise() {
|
|
282
281
|
if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
|
|
283
282
|
return Promise.resolve(this.info.sysInfo.jdAppearanceState)
|
|
284
283
|
} else {
|
|
285
284
|
return Promise.race([
|
|
286
285
|
this.taskTimeoutPromise(() => {
|
|
287
286
|
this.info.sysInfo.jdAppearanceState = '0'
|
|
288
287
|
return this.info.sysInfo.jdAppearanceState
|
|
289
288
|
}),
|
|
290
289
|
new Promise(resolve => {
|
|
291
290
|
const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
|
|
292
291
|
if (!window[getCallBackName]) {
|
|
293
292
|
window[getCallBackName] = res => {
|
|
294
293
|
try {
|
|
295
294
|
console.log('getJDAppearanceStatePromise', res)
|
|
296
295
|
const getResJson =
|
|
297
296
|
typeof res === 'string' ? JSON.parse(res) : res
|
|
298
297
|
const { status, data, msg } = getResJson
|
|
299
298
|
console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
|
|
300
299
|
if (status === '0') {
|
|
301
300
|
this.info.sysInfo.jdAppearanceState = data
|
|
302
301
|
resolve(data)
|
|
303
302
|
} else {
|
|
304
303
|
resolve('0')
|
|
305
304
|
}
|
|
306
305
|
} catch (e) {
|
|
307
306
|
resolve('0')
|
|
308
307
|
}
|
|
309
308
|
window[getCallBackName] = null
|
|
310
309
|
}
|
|
311
310
|
}
|
|
312
311
|
if (isAndroidDevice) {
|
|
313
312
|
const jsonString = JSON.stringify({
|
|
314
313
|
callBackName: `window.${getCallBackName}`,
|
|
315
314
|
})
|
|
316
315
|
console.log('window.JDAppearance', window.JDAppearance)
|
|
317
316
|
window.JDAppearance && window.JDAppearance.getUiState(jsonString)
|
|
318
317
|
} else {
|
|
319
318
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
320
319
|
method: 'callSyncRouterModuleWithParams',
|
|
321
320
|
params: JSON.stringify({
|
|
322
321
|
routerURL:
|
|
323
322
|
'router://JDWebViewBusinessModule/getJDAppearanceState',
|
|
324
323
|
routerParam: {},
|
|
325
324
|
callBackName: `window.${getCallBackName}`,
|
|
326
325
|
callBackId: `${getCallBackName}Ios`,
|
|
327
326
|
}),
|
|
328
327
|
})
|
|
329
328
|
}
|
|
330
329
|
}),
|
|
331
330
|
])
|
|
332
331
|
}
|
|
333
332
|
}
|
|
334
333
|
|
|
335
334
|
createJdAndroidRquestEventForTouchStart() {
|
|
336
335
|
if (isJdAndAndroidDevice && window.JdAndroid) {
|
|
337
336
|
const rootEleNode = document.querySelector('body')
|
|
338
337
|
if (rootEleNode) {
|
|
339
338
|
rootEleNode.addEventListener(
|
|
340
339
|
'touchstart',
|
|
341
340
|
this.jdAndroidAddEventListenerTouchStart,
|
|
342
341
|
false,
|
|
343
342
|
)
|
|
344
343
|
}
|
|
345
344
|
}
|
|
346
345
|
}
|
|
347
346
|
jdAndroidAddEventListenerTouchStart(e) {
|
|
348
347
|
const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
|
|
349
348
|
if (!isH5SwiperCustomEle) {
|
|
350
349
|
const hasCustomEle = e
|
|
351
350
|
? e?.target?.closest('.J_customScroll') ||
|
|
352
351
|
e?.target?.closest('.J_customLayout')
|
|
353
352
|
: false
|
|
354
353
|
if (!hasCustomEle) {
|
|
355
354
|
window.JdAndroid.requestEvent(false)
|
|
356
355
|
console.log(
|
|
357
356
|
'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
|
|
358
357
|
)
|
|
359
358
|
}
|
|
360
359
|
}
|
|
361
360
|
}
|
|
362
361
|
removeJdAndroidRquestEventForTouchStart() {
|
|
363
362
|
if (isJdAndAndroidDevice && window.JdAndroid) {
|
|
364
363
|
const rootEleNode = document.querySelector('body')
|
|
365
364
|
if (rootEleNode) {
|
|
366
365
|
rootEleNode.removeEventListener(
|
|
367
366
|
'touchstart',
|
|
368
367
|
this.jdAndroidAddEventListenerTouchStart,
|
|
369
368
|
false,
|
|
370
369
|
)
|
|
371
370
|
}
|
|
372
371
|
}
|
|
373
372
|
}
|
|
374
373
|
|
|
375
374
|
getNetWorkType() {
|
|
376
375
|
if (isJdApp) {
|
|
377
376
|
this.jmfeReayPromise().then(() => {
|
|
378
377
|
window.jmfe
|
|
379
378
|
.getNetworkStatus()
|
|
380
379
|
.then(({ status, data }) => {
|
|
381
380
|
console.log(
|
|
382
381
|
'在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
|
|
383
382
|
data,
|
|
384
383
|
)
|
|
385
384
|
if (status === '0') {
|
|
386
385
|
this.info.sysInfo['netWorkType'] = data
|
|
387
386
|
} else {
|
|
388
387
|
this._taroGetNetworkType()
|
|
389
388
|
}
|
|
390
389
|
})
|
|
391
390
|
.catch(err => {
|
|
392
391
|
console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
|
|
393
392
|
this._taroGetNetworkType()
|
|
394
393
|
})
|
|
395
394
|
})
|
|
396
395
|
} else {
|
|
397
396
|
this._taroGetNetworkType()
|
|
398
397
|
}
|
|
399
398
|
}
|
|
400
399
|
_taroGetNetworkType() {
|
|
401
400
|
Taro.getNetworkType().then(getRes => {
|
|
402
401
|
if (getRes && getRes.networkType) {
|
|
403
402
|
this.info.sysInfo['netWorkType'] = getRes.networkType
|
|
404
403
|
console.log(
|
|
405
404
|
'在app内通过taro对象获取网络状态完成,当前网络状态',
|
|
406
405
|
this.info.sysInfo['netWorkType'],
|
|
407
406
|
)
|
|
408
407
|
}
|
|
409
408
|
})
|
|
410
409
|
}
|
|
411
410
|
getCacheAddressRouter() {
|
|
412
411
|
if (!window.jmfe) return
|
|
413
412
|
if (isAndroidDevice) {
|
|
414
413
|
return window.jmfe.callRouter({
|
|
415
414
|
jdRouter: '1',
|
|
416
415
|
routerURL: 'router://JDAddressModule/getCacheAddress',
|
|
417
416
|
routerParam: { sceneId: 'basicShoppingProcess' },
|
|
418
417
|
})
|
|
419
418
|
} else if (isIosDevice) {
|
|
420
419
|
return window.jmfe.callRouter({
|
|
421
420
|
jdRouter: '1',
|
|
422
421
|
routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
|
|
423
422
|
routerParam: { sceneId: 'basicShoppingProcess' },
|
|
424
423
|
})
|
|
425
424
|
} else if (isJdAndHarmonyDevice) {
|
|
426
425
|
return new Promise(resolve => {
|
|
427
426
|
resolve({})
|
|
428
427
|
})
|
|
429
428
|
} else {
|
|
430
429
|
throw Error(
|
|
431
430
|
'Unknown device type cannot obtain the address information through the route!',
|
|
432
431
|
)
|
|
433
432
|
}
|
|
434
433
|
}
|
|
435
434
|
|
|
436
435
|
getAddressCachePromise() {
|
|
437
436
|
return new Promise(resolve => {
|
|
438
437
|
if (
|
|
439
438
|
this?.info?.sysInfo?.lat &&
|
|
440
439
|
this?.info?.sysInfo?.lng &&
|
|
441
440
|
this?.info?.sysInfo?.area
|
|
442
441
|
) {
|
|
443
442
|
resolve({
|
|
444
443
|
lat: this.info.sysInfo.lat,
|
|
445
444
|
lng: this.info.sysInfo.lng,
|
|
446
445
|
area: this?.info?.sysInfo?.area,
|
|
447
446
|
})
|
|
448
447
|
} else {
|
|
449
448
|
this.jmfeReayPromise().then(() => {
|
|
450
449
|
this.getCacheAddressRouter()
|
|
451
450
|
.then(({ status, data }) => {
|
|
452
451
|
console.log("原生端获取经纬度原始数据结果",status,data)
|
|
453
452
|
if (status === '0' && data) {
|
|
454
453
|
const {
|
|
455
454
|
lat,
|
|
456
455
|
latitude,
|
|
457
456
|
lng,
|
|
458
457
|
longitude,
|
|
459
458
|
provinceId,
|
|
460
459
|
cityId,
|
|
461
460
|
countyId,
|
|
462
461
|
townId,
|
|
463
462
|
} = data || {}
|
|
464
463
|
let area = ''
|
|
465
464
|
this.info.sysInfo['lat'] = `${lat || latitude || ''}`
|
|
466
465
|
this.info.sysInfo['lng'] = `${lng || longitude || ''}`
|
|
467
466
|
if (provinceId) {
|
|
468
467
|
area = `${provinceId}_${cityId || 0}_${countyId ||
|
|
469
468
|
0}_${townId || 0}`
|
|
470
469
|
this.info.pageInfo['address'] = area
|
|
471
470
|
this.info.pageInfo['addressCommaStr'] = area.replace(
|
|
472
471
|
/_/g,
|
|
473
472
|
',',
|
|
474
473
|
)
|
|
475
474
|
}
|
|
476
475
|
})
|
|
477
476
|
.catch(e => {
|
|
478
477
|
console.log(' ~~ file: index.h5.ts:514 ~~ .catch ~~ e:', e)
|
|
479
478
|
resolve({ lat: '', lng: '', area: '' })
|
|
480
479
|
}
|
|
481
480
|
})
|
|
482
481
|
.catch(e => {
|
|
483
482
|
console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
|
|
484
483
|
resolve({ lat: '', lng: '', area: '' })
|
|
485
484
|
console.log('判断jmfe不存在,获取经纬度信息异常')
|
|
486
485
|
})
|
|
487
486
|
})
|
|
488
487
|
}
|
|
489
488
|
})
|
|
490
489
|
}
|
|
491
490
|
|
|
492
491
|
async updateMPaasConfigAsync(isBeforePageReady: boolean) {
|
|
493
492
|
console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
|
|
494
493
|
if (!isJdApp) {
|
|
495
494
|
return
|
|
496
495
|
}
|
|
497
496
|
const avifSwitch = await getMPaasConfigByBussinessKey(
|
|
498
497
|
'avifSwitch',
|
|
499
498
|
isBeforePageReady,
|
|
500
499
|
)
|
|
501
500
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
|
|
502
501
|
const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
|
|
503
502
|
'isFollowAppVideoPlayStatus',
|
|
504
503
|
isBeforePageReady,
|
|
505
504
|
)
|
|
506
505
|
console.log(
|
|
507
506
|
'isBeforePageReady:',
|
|
508
507
|
isBeforePageReady,
|
|
509
508
|
'isFollowAppVideoPlayStatus:',
|
|
510
509
|
isFollowAppVideoPlayStatus,
|
|
511
510
|
)
|
|
512
511
|
if (
|
|
513
512
|
isFollowAppVideoPlayStatus === true ||
|
|
514
513
|
isFollowAppVideoPlayStatus === 'true'
|
|
515
514
|
) {
|
|
516
515
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
|
|
517
516
|
}
|
|
518
517
|
}
|
|
519
518
|
|
|
520
519
|
async getWifiVideoAutoPlayAsync() {
|
|
521
520
|
this.info.sysInfo['wifiVideoAutoPlay'] = false
|
|
522
521
|
if (!isJdApp) {
|
|
523
522
|
return
|
|
524
523
|
}
|
|
525
524
|
const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
|
|
526
525
|
return 0
|
|
527
526
|
})
|
|
528
527
|
if (Number(videoPlayStatus) === 1) {
|
|
529
528
|
this.info.sysInfo['wifiVideoAutoPlay'] = true
|
|
530
529
|
}
|
|
531
530
|
}
|
|
532
531
|
|
|
533
532
|
async getMPaasConfigAsync() {
|
|
534
533
|
this.info.sysInfo.dynamicConfig = {}
|
|
535
534
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
|
|
536
535
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
|
|
537
536
|
return this.updateMPaasConfigAsync(true)
|
|
538
537
|
}
|
|
539
538
|
|
|
540
539
|
getDynamicConfig(key: string){
|
|
541
540
|
return this.info.sysInfo.dynamicConfig[key]
|
|
542
541
|
}
|
|
543
542
|
async updateMPaasConfig() {
|
|
544
543
|
console.log('updateMPaasConfig')
|
|
545
544
|
if (
|
|
546
545
|
isIosDevice &&
|
|
547
546
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
|
|
548
547
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
|
|
549
548
|
) {
|
|
550
549
|
try {
|
|
551
550
|
await this.updateMPaasConfigAsync(false)
|
|
552
551
|
} catch (e) {
|
|
553
552
|
console.log('updateMPaasConfigAsync:', e)
|
|
554
553
|
}
|
|
555
554
|
}
|
|
556
555
|
}
|
|
557
556
|
|
|
558
557
|
toLogin(options) {
|
|
559
558
|
return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
|
|
560
559
|
? this.toWxAppLogin(options)
|
|
561
560
|
: this.toWebLogin(options)
|
|
562
561
|
}
|
|
563
562
|
|
|
564
563
|
doLogin(options) {
|
|
565
564
|
return this.toLogin(options)
|
|
566
565
|
}
|
|
567
566
|
|
|
568
567
|
doLoginForJdPin(options = {}) {
|
|
569
568
|
return this.doLogin({
|
|
570
569
|
loginColor: {
|
|
571
570
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
572
571
|
dpin: 0,
|
|
573
572
|
},
|
|
574
573
|
...options,
|
|
575
574
|
})
|
|
576
575
|
}
|
|
577
576
|
|
|
578
577
|
toWebLogin(options) {
|
|
579
578
|
let params: {
|
|
580
579
|
returnurl: string
|
|
581
580
|
} = {
|
|
582
581
|
returnurl: '',
|
|
583
582
|
}
|
|
584
583
|
const loginUrl = isPc
|
|
585
584
|
? `//passport.jd.com/new/login.aspx`
|
|
586
585
|
: `${domain.mobileLogin}/user/login.action`
|
|
587
586
|
const defaultParams = {
|
|
588
587
|
appid: '100',
|
|
589
588
|
returnurl: window.location.href,
|
|
590
589
|
}
|
|
591
590
|
if (isString(options)) {
|
|
592
591
|
params = Object.assign({}, defaultParams, {
|
|
593
592
|
returnurl: options,
|
|
594
593
|
})
|
|
595
594
|
} else if (isObject(options)) {
|
|
596
595
|
const { loginColor, ...otherOptions } = options
|
|
597
596
|
params = Object.assign({}, defaultParams, otherOptions)
|
|
598
597
|
} else {
|
|
599
598
|
params = defaultParams
|
|
600
599
|
}
|
|
601
600
|
params.returnurl = encodeURIComponent(params.returnurl)
|
|
602
601
|
let getFullUrl = loginUrl + '?' + serialize(params)
|
|
603
602
|
if (isPc) {
|
|
604
603
|
getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
|
|
605
604
|
}
|
|
606
605
|
return Promise.resolve({
|
|
607
606
|
h5ToUrl: true,
|
|
608
607
|
url: getFullUrl,
|
|
609
608
|
}).then(() => {
|
|
610
609
|
window.location.href = getFullUrl
|
|
611
610
|
})
|
|
612
611
|
}
|
|
613
612
|
|
|
614
613
|
toWxAppLogin(options = {}) {
|
|
615
614
|
console.log('微信京购小程序中h5登录跳转', options)
|
|
616
615
|
return Promise.resolve(true).then(() => {
|
|
617
616
|
const { loginColor } = Object.assign(
|
|
618
617
|
{},
|
|
619
618
|
{
|
|
620
619
|
loginColor: {
|
|
621
620
|
biz: WXAPP_BIZ_KEY,
|
|
622
621
|
dpin: 1,
|
|
623
622
|
},
|
|
624
623
|
},
|
|
625
624
|
options,
|
|
626
625
|
)
|
|
627
626
|
window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
|
|
628
627
|
loginColor.biz
|
|
629
628
|
}&url=${encodeURIComponent(window.location.href)}`
|
|
630
629
|
})
|
|
631
630
|
}
|
|
632
631
|
|
|
633
632
|
getLoginCookie() {
|
|
634
633
|
return Promise.resolve({
|
|
635
634
|
pin: cookie.get('pin') || '',
|
|
636
635
|
})
|
|
637
636
|
}
|
|
638
637
|
|
|
639
638
|
clearLoginCookie() {
|
|
640
639
|
cookie.remove('pin')
|
|
641
640
|
}
|
|
642
641
|
|
|
643
642
|
checkStatusAndLogin(options = {}) {
|
|
644
643
|
if (!this.checkStatusAndLoginPromise) {
|
|
645
644
|
this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
|
|
646
645
|
try {
|
|
647
646
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(
|
|
648
647
|
options,
|
|
649
648
|
)
|
|
650
649
|
if (getLoginState) {
|
|
651
650
|
resolve(true)
|
|
652
651
|
} else {
|
|
653
652
|
this.toLogin(options)
|
|
654
653
|
reject(false)
|
|
655
654
|
}
|
|
656
655
|
} catch (e) {
|
|
657
656
|
this.toLogin(options)
|
|
658
657
|
reject(false)
|
|
659
658
|
}
|
|
660
659
|
})
|
|
661
660
|
return this.checkStatusAndLoginPromise
|
|
662
661
|
} else {
|
|
663
662
|
return this.checkStatusAndLoginPromise
|
|
664
663
|
.then(() => {
|
|
665
664
|
return Promise.resolve(true)
|
|
666
665
|
})
|
|
667
666
|
.catch(() => {
|
|
668
667
|
this.toLogin(options)
|
|
669
668
|
return Promise.reject(true)
|
|
670
669
|
})
|
|
671
670
|
}
|
|
672
671
|
}
|
|
673
672
|
|
|
674
673
|
checkJdStatusAndLogin(
|
|
675
674
|
options = {
|
|
676
675
|
loginColor: {
|
|
677
676
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
678
677
|
dpin: 0,
|
|
679
678
|
},
|
|
680
679
|
},
|
|
681
680
|
) {
|
|
682
681
|
return this.checkStatusAndLogin(options)
|
|
683
682
|
}
|
|
684
683
|
|
|
685
684
|
doCheckLoginStateAndForApiCheck(options) {
|
|
686
685
|
if (this.info.loginState) {
|
|
687
686
|
return Promise.resolve(true)
|
|
688
687
|
} else {
|
|
689
688
|
return new Promise((resolve, reject) => {
|
|
690
689
|
if (
|
|
691
690
|
this.info.isJingGouMiniViewState ||
|
|
692
691
|
this.info.isJingxiMiniViewState
|
|
693
692
|
) {
|
|
694
693
|
const getWqAuthToken = cookie.get('wq_auth_token')
|
|
695
694
|
const getWqSkey = cookie.get('wq_skey')
|
|
696
695
|
const getWqUin = cookie.get('wq_uin')
|
|
697
696
|
const isLoginState =
|
|
698
697
|
options?.loginColor?.dpin === 0
|
|
699
698
|
? getWqAuthToken
|
|
700
699
|
: getWqSkey && getWqUin
|
|
701
700
|
if (isLoginState) {
|
|
702
701
|
this.info.loginState = true
|
|
703
702
|
resolve(true)
|
|
704
703
|
} else {
|
|
705
704
|
reject(false)
|
|
706
705
|
}
|
|
707
706
|
} else {
|
|
708
707
|
Taro.request({
|
|
709
708
|
url: api.isLogin,
|
|
710
709
|
jsonp: true,
|
|
711
710
|
timeout: 3000,
|
|
712
711
|
success: res => {
|
|
713
712
|
const { statusCode, data } = res
|
|
714
713
|
if (
|
|
715
714
|
statusCode === 200 &&
|
|
716
715
|
data?.islogin &&
|
|
717
716
|
Number(data.islogin) === 1
|
|
718
717
|
) {
|
|
719
718
|
this.info.loginState = true
|
|
720
719
|
resolve(true)
|
|
721
720
|
} else {
|
|
722
721
|
reject(false)
|
|
723
722
|
}
|
|
724
723
|
},
|
|
725
724
|
fail: err => {
|
|
726
725
|
console.log('登录检查异常', err)
|
|
727
726
|
reject(false)
|
|
728
727
|
},
|
|
729
728
|
})
|
|
730
729
|
}
|
|
731
730
|
})
|
|
732
731
|
}
|
|
733
732
|
}
|
|
734
733
|
|
|
735
734
|
checkLoginStatus(options) {
|
|
736
735
|
return new Promise(async (resolve, reject) => {
|
|
737
736
|
try {
|
|
738
737
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(
|
|
739
738
|
options,
|
|
740
739
|
)
|
|
741
740
|
if (getLoginState) {
|
|
742
741
|
const { pin } = await this.getLoginCookie()
|
|
743
742
|
this.info.userInfo = {
|
|
744
743
|
pin,
|
|
745
744
|
encodePin: encodeURIComponent(pin),
|
|
746
745
|
ptkey: '',
|
|
747
746
|
}
|
|
748
747
|
resolve(true)
|
|
749
748
|
} else {
|
|
750
749
|
reject(false)
|
|
751
750
|
}
|
|
752
751
|
} catch (e) {
|
|
753
752
|
reject(false)
|
|
754
753
|
}
|
|
755
754
|
})
|
|
756
755
|
}
|
|
757
756
|
|
|
758
757
|
updatePageAndLogInfo(updateQuery = {}) {
|
|
759
758
|
const createUpdateQueryInfo: {
|
|
760
759
|
query: {
|
|
761
760
|
shopId?: string | number
|
|
762
761
|
venderId?: string | number
|
|
763
762
|
}
|
|
764
763
|
updateShopInfoState: boolean
|
|
765
764
|
} = Object.assign(
|
|
766
765
|
{},
|
|
767
766
|
{
|
|
768
767
|
query: {},
|
|
769
768
|
updateShopInfoState: false,
|
|
770
769
|
},
|
|
771
770
|
updateQuery,
|
|
772
771
|
)
|
|
773
772
|
console.log(
|
|
774
773
|
'获取当前下发的店铺查询参数',
|
|
775
774
|
updateQuery,
|
|
776
775
|
'获取之前保存的shopInfo店铺查询参数',
|
|
777
776
|
this.info?.shopInfo,
|
|
778
777
|
)
|
|
779
778
|
const { query, updateShopInfoState } = createUpdateQueryInfo
|
|
780
779
|
const { shopId, venderId, un_area } = query
|
|
781
780
|
if (updateShopInfoState) {
|
|
782
781
|
this.info.queryInfo = {
|
|
783
782
|
...this.info.queryInfo,
|
|
784
783
|
...query,
|
|
785
784
|
}
|
|
786
785
|
if (shopId && venderId) {
|
|
787
786
|
this.info.shopInfo = {
|
|
788
787
|
shopId: `${shopId}`,
|
|
789
788
|
venderId: `${venderId}`,
|
|
790
789
|
}
|
|
791
790
|
}
|
|
792
791
|
} else {
|
|
793
792
|
this.info.queryInfo = {
|
|
794
793
|
...query,
|
|
795
794
|
}
|
|
796
795
|
if (
|
|
797
796
|
this.info.shopInfo?.shopId &&
|
|
798
797
|
this.info.shopInfo?.venderId &&
|
|
799
798
|
(this.info.shopInfo.shopId == shopId ||
|
|
800
799
|
this.info.shopInfo.venderId == venderId)
|
|
801
800
|
) {
|
|
802
801
|
this.info.queryInfo.shopId = this.info.shopInfo.shopId
|
|
803
802
|
this.info.queryInfo.venderId = this.info.shopInfo.venderId
|
|
804
803
|
console.log(
|
|
805
804
|
'当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
|
|
806
805
|
this.info.queryInfo,
|
|
807
806
|
)
|
|
808
807
|
}
|
|
809
808
|
}
|
|
810
809
|
this.info.queryInfo['shopId'] &&
|
|
811
810
|
(this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
|
|
812
811
|
this.info.queryInfo['venderId'] &&
|
|
813
812
|
(this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
|
|
814
813
|
console.log(
|
|
815
814
|
'h5==获取店铺下发查询参数\n',
|
|
816
815
|
query,
|
|
817
816
|
'\n获取店铺最后查询参数\n',
|
|
818
817
|
this.info.queryInfo,
|
|
819
818
|
'\n是否为更新店铺状态\n',
|
|
820
819
|
updateShopInfoState,
|
|
821
820
|
)
|
|
822
821
|
const changeArea =
|
|
823
822
|
un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
|
|
824
823
|
if (changeArea) {
|
|
825
824
|
this.info.pageInfo.address = changeArea
|
|
826
825
|
this.info.pageInfo.un_area = changeArea
|
|
827
826
|
this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
|
|
828
827
|
}
|
|
829
828
|
}
|
|
830
829
|
|
|
831
830
|
dealLoadSdkList(){
|
|
832
831
|
const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
|
|
833
832
|
const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? []
|
|
834
833
|
const concatLoadJsList = [].concat(globalLoadJsList,businessLoadJsList)
|
|
835
834
|
let mergeLoadJsList = globalLoadJsList
|
|
836
835
|
try {
|
|
837
836
|
mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
|
|
838
837
|
const getFindIndex = accArr.findIndex(item => item?.fileName === current?.fileName);
|
|
839
838
|
getFindIndex !== -1 ? (accArr[getFindIndex] = {...accArr[getFindIndex],...current }) : accArr.push(current);
|
|
840
839
|
return accArr;
|
|
841
840
|
}, []);
|
|
842
841
|
}catch (e) {
|
|
843
842
|
console.log("LoadJsList合并错误", e)
|
|
844
843
|
}
|
|
845
844
|
console.log("globalLoadJsList",globalLoadJsList,"businessLoadJsList",businessLoadJsList,"两个加载jsList集合合并完成", mergeLoadJsList)
|
|
846
845
|
this.loadJsSdkList = mergeLoadJsList
|
|
847
846
|
return this.loadJsSdkList
|
|
848
847
|
}
|
|
849
848
|
|
|
850
849
|
renderNextTickLoadSdk(){
|
|
851
850
|
Taro.nextTick(() => {
|
|
852
851
|
console.log("页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======")
|
|
853
852
|
setTimeout(() => {
|
|
854
853
|
this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK,this.loadJsSdkList)
|
|
855
854
|
},1000)
|
|
856
855
|
})
|
|
857
856
|
}
|
|
858
857
|
|
|
859
858
|
loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW,loadJsList:any[] = [] ) {
|
|
860
859
|
const getLoadJsList = Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList()
|
|
861
860
|
const getLoadFilterList = getLoadJsList.filter(item => {
|
|
862
861
|
const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL
|
|
863
862
|
let getLoastLoadEventState = true
|
|
864
863
|
if(getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP){
|
|
865
864
|
getLoastLoadEventState = isJdApp
|
|
866
865
|
}
|
|
867
866
|
else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
|
|
868
867
|
getLoastLoadEventState = !isJdApp
|
|
869
868
|
}
|
|
870
869
|
const getInitTriggerType = isJdApp && item?.initJdAppTriggerType ? item?.initTriggerType : item?.initTriggerType || LoadJsInitTriggerType.NOW
|
|
871
870
|
const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false
|
|
872
871
|
return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay
|
|
873
872
|
})
|
|
874
873
|
console.log("获取当前触发方式",triggerType,"获取当前最后加载的js集合",getLoadFilterList,"过滤前的加载集合",getLoadJsList)
|
|
875
874
|
getLoadFilterList.length > 0 && getLoadFilterList.forEach((item) => {
|
|
876
875
|
const isLoadState = /sgm/.test(item?.fileName) ? window?.shopGlobalSwitch?.openSgm === "true" : true
|
|
877
876
|
isLoadState && this.loadItemSdkPromise(item)
|
|
878
877
|
.then((res) => {
|
|
879
878
|
console.info('当前js地址' + item?.src, '加载状态', res)
|
|
880
879
|
})
|
|
881
880
|
.catch((err) => {
|
|
882
881
|
console.info('当前js地址加载异常', item?.src)
|
|
883
882
|
window?.fetchErrorData &&
|
|
884
883
|
window.fetchErrorData({
|
|
885
884
|
title: '公共js加载异常',
|
|
886
885
|
type: "jsLoad",
|
|
887
886
|
data: err,
|
|
888
887
|
})
|
|
889
888
|
})
|
|
890
889
|
})
|
|
891
890
|
}
|
|
892
891
|
loadScriptEle(jsInfo,resolve,reject){
|
|
893
892
|
const getFileName = jsInfo?.fileName;
|
|
894
893
|
if(getFileName){
|
|
895
894
|
const getEleId = `J_loadJs_${getFileName}`
|
|
896
895
|
const getEle = document.getElementById(getEleId)
|
|
897
896
|
if (!getEle) {
|
|
898
897
|
const jsLoadErrorSgmCode = `jsLoadError_${
|
|
899
898
|
jsInfo?.fileName || 'customJs'
|
|
900
899
|
}`
|
|
901
900
|
const _sgmEle = document.createElement('script')
|
|
902
901
|
_sgmEle.id = getEleId
|
|
903
902
|
_sgmEle.onload = function () {
|
|
904
903
|
resolve({
|
|
905
904
|
...jsInfo,
|
|
906
905
|
jsTip: "js加载成功",
|
|
907
906
|
})
|
|
908
907
|
}
|
|
909
908
|
_sgmEle.onerror = function () {
|
|
910
909
|
reject({
|
|
911
910
|
...jsInfo,
|
|
912
911
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
913
912
|
jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
|
|
914
913
|
})
|
|
915
914
|
}
|
|
916
915
|
const dataAttrList = ['timeout','fileName',"env"]
|
|
917
916
|
const getJsInfoKeyList = Object.keys(jsInfo)
|
|
918
917
|
getJsInfoKeyList.forEach(key => {
|
|
919
918
|
if(key === "async"){
|
|
920
919
|
_sgmEle.async = jsInfo[key]
|
|
921
920
|
}else if(key === "crossOrigin"){
|
|
922
921
|
_sgmEle.crossOrigin = jsInfo[key]
|
|
923
922
|
}else if(key === "src"){
|
|
924
923
|
_sgmEle.src = `${jsInfo[key]}`
|
|
925
924
|
}else if(dataAttrList.includes(key) || /init/.test(key)) {
|
|
926
925
|
_sgmEle.setAttribute(`data-${key}`, jsInfo[key])
|
|
927
926
|
}else {
|
|
928
927
|
_sgmEle.setAttribute(key, jsInfo[key])
|
|
929
928
|
}
|
|
930
929
|
})
|
|
931
930
|
document.head.appendChild(_sgmEle)
|
|
932
931
|
}else {
|
|
933
932
|
console.log(`当前${jsInfo?.fileName || "js"}已经存在页面中,可以直接调用相关方法`,jsInfo)
|
|
934
933
|
resolve({
|
|
935
934
|
...jsInfo,
|
|
936
935
|
jsTip: "js本身已存在页面中",
|
|
937
936
|
})
|
|
938
937
|
}
|
|
939
938
|
}else {
|
|
940
939
|
console.warn("当前js资源信息缺少必要的参数fileName,请关注",jsInfo)
|
|
941
940
|
}
|
|
942
941
|
}
|
|
943
942
|
|
|
944
943
|
loadItemSdkPromise(jsInfo = {}){
|
|
945
944
|
if(jsInfo?.src){
|
|
946
945
|
const getInitLoadType = isJdApp && jsInfo?.initJdAppLoadType ? jsInfo?.initJdAppLoadType : jsInfo?.initLoadType || LoadJsInitLoadType.ALL
|
|
947
946
|
if(getInitLoadType !== LoadJsInitLoadType.NONE){
|
|
948
947
|
const getFileKeyName = jsInfo?.fileName || jsInfo?.src
|
|
949
948
|
if (!this.loadJsSdkListCachePromise[getFileKeyName]){
|
|
950
949
|
if(getInitLoadType !== LoadJsInitLoadType.INSERT_ELE){
|
|
951
950
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
|
|
952
951
|
const jsLoadErrorSgmCode = `jsLoadError_${
|
|
953
952
|
jsInfo?.fileName || 'customJs'
|
|
954
953
|
}`
|
|
955
954
|
try {
|
|
956
955
|
const jsXhrRequest = new XMLHttpRequest();
|
|
957
956
|
jsXhrRequest.timeout = jsInfo?.timeout ?? 2000
|
|
958
957
|
const jsUrl = `${jsInfo?.src}`
|
|
959
958
|
jsXhrRequest.open('GET', jsUrl, true);
|
|
960
959
|
jsXhrRequest.onload = () => {
|
|
961
960
|
if (jsXhrRequest.status === 200) {
|
|
962
961
|
const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL
|
|
963
962
|
if(getInsetHeadState){
|
|
964
963
|
this.loadScriptEle(jsInfo,resolve,reject)
|
|
965
964
|
}else {
|
|
966
965
|
resolve({
|
|
967
966
|
...jsInfo,
|
|
968
967
|
jsTip: "js请求成功,暂未插入head节点,业务自行单独插入",
|
|
969
968
|
})
|
|
970
969
|
}
|
|
971
970
|
}else {
|
|
972
971
|
const getRes = {
|
|
973
972
|
...jsInfo,
|
|
974
973
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
975
974
|
jsReqError: `请求状态异常,状态为${jsXhrRequest?.status}`,
|
|
976
975
|
jsReqState: jsXhrRequest?.status,
|
|
977
976
|
}
|
|
978
977
|
console.log("当前js请求状态异常", getRes)
|
|
979
978
|
reject(getRes)
|
|
980
979
|
}
|
|
981
980
|
}
|
|
982
981
|
jsXhrRequest.onerror = () => {
|
|
983
982
|
const getRes = {
|
|
984
983
|
...jsInfo,
|
|
985
984
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
986
985
|
jsReqError: '请求错误',
|
|
987
986
|
}
|
|
988
987
|
console.log("当前js请求错误", getRes)
|
|
989
988
|
jsXhrRequest.abort()
|
|
990
989
|
reject(getRes)
|
|
991
990
|
}
|
|
992
991
|
jsXhrRequest.ontimeout = () => {
|
|
993
992
|
const getRes = {
|
|
994
993
|
...jsInfo,
|
|
995
994
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
996
995
|
jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
|
|
997
996
|
}
|
|
998
997
|
console.log("当前js请求超时异常", getRes)
|
|
999
998
|
jsXhrRequest.abort()
|
|
1000
999
|
reject(getRes)
|
|
1001
1000
|
}
|
|
1002
1001
|
jsXhrRequest.send();
|
|
1003
1002
|
}catch (e) {
|
|
1004
1003
|
console.log("执行js请求异常",e)
|
|
1005
1004
|
reject({
|
|
1006
1005
|
...jsInfo,
|
|
1007
1006
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1008
1007
|
jsReqError: '未知异常',
|
|
1009
1008
|
error: e,
|
|
1010
1009
|
})
|
|
1011
1010
|
}
|
|
1012
1011
|
})
|
|
1013
1012
|
}else {
|
|
1014
1013
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
|
|
1015
1014
|
return this.loadScriptEle(jsInfo,resolve,reject)
|
|
1016
1015
|
})
|
|
1017
1016
|
}
|
|
1018
1017
|
}
|
|
1019
1018
|
return this.loadJsSdkListCachePromise[getFileKeyName]
|
|
1020
1019
|
}else {
|
|
1021
1020
|
return Promise.resolve({
|
|
1022
1021
|
...jsInfo,
|
|
1023
1022
|
jsTip: "js加载方式设置为不加载,当前不做处理",
|
|
1024
1023
|
})
|
|
1025
1024
|
}
|
|
1026
1025
|
}else {
|
|
1027
1026
|
return Promise.reject(jsInfo)
|
|
1028
1027
|
}
|
|
1029
1028
|
}
|
|
1029
|
+
import Taro from '@tarojs/taro'
|
|
1030
1030
|
isIosDevice,
|
|
1031
1031
|
isAndroidDevice,
|
|
1032
1032
|
isJdAndHarmonyDevice,
|
|
1033
1033
|
isJdAndAndroidDevice,
|
|
1034
1034
|
jdAppVersion,
|
|
1035
1035
|
jdAppVersionStr,
|
|
1036
1036
|
isString,
|
|
1037
1037
|
isObject,
|
|
1038
1038
|
serialize,
|
|
1039
1039
|
dealNativePixelToCssPixel,
|
|
1040
1040
|
isPc,
|
|
1041
1041
|
BUSINESS_TYPE,
|
|
1042
1042
|
JSSDK_APP_WEBVIEW_CODE,
|
|
1043
1043
|
SECTION_HOME_TAB_NAME_TYPE,
|
|
1044
1044
|
SECTION_HOME_TAB_TYPE,
|
|
1045
1045
|
WXAPP_BIZ_KEY,
|
|
1046
1046
|
WX_BUSINESS_TYPE,
|
|
1047
1047
|
MPAAS_CONFIG_APP_VERSION,
|
|
1048
1048
|
MPAAS_CONFIG_APP_LOW_VERSION,
|
|
1049
1049
|
WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
1050
1050
|
LoadJsInitLoadEnvType,
|
|
1051
1051
|
LoadJsInitLoadType,
|
|
1052
1052
|
LoadJsInitTriggerType
|
|
1053
1053
|
loginState: false,
|
|
1054
1054
|
cookiesStr: '',
|
|
1055
1055
|
userInfo: userPinKey,
|
|
1056
1056
|
isJingGouMiniViewState: false,
|
|
1057
1057
|
isJingxiMiniViewState: false,
|
|
1058
1058
|
pageInfo: {
|
|
1059
1059
|
wxBusinessType: WX_BUSINESS_TYPE.NO,
|
|
1060
1060
|
address: '',
|
|
1061
1061
|
addressCommaStr: '',
|
|
1062
1062
|
un_area: '',
|
|
1063
1063
|
vapptype: '1',
|
|
1064
1064
|
pageType: 'home',
|
|
1065
1065
|
isExposureState: false,
|
|
1066
1066
|
moduleId: '',
|
|
1067
1067
|
entrance: '',
|
|
1068
1068
|
dataType: BUSINESS_TYPE.ONLINE,
|
|
1069
1069
|
floorExposureInfo: {},
|
|
1070
1070
|
floorVideInfo: {},
|
|
1071
1071
|
productVideInfo: {},
|
|
1072
1072
|
tabsLoadAllDataInfo: {
|
|
1073
1073
|
[SECTION_HOME_TAB_NAME_TYPE[
|
|
1074
1074
|
SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
|
|
1075
1075
|
]]: false,
|
|
1076
1076
|
},
|
|
1077
1077
|
updateShopInfosAllState: false,
|
|
1078
1078
|
isVipShop: false,
|
|
1079
1079
|
isJdShowNativeImmersivePlayer: false,
|
|
1080
1080
|
...shopConfig,
|
|
1081
1081
|
pageScrollTop: 0,
|
|
1082
1082
|
pageIdxHeightInfo: {
|
|
1083
1083
|
list: [],
|
|
1084
1084
|
},
|
|
1085
1085
|
shopNavBarHeight: 0,
|
|
1086
1086
|
},
|
|
1087
1087
|
defaultQueryLogInfo: {
|
|
1088
1088
|
sourceType: 'JDshop',
|
|
1089
1089
|
sourceValue: '',
|
|
1090
1090
|
moduleId: 'none',
|
|
1091
1091
|
entrance: 'none',
|
|
1092
1092
|
},
|
|
1093
1093
|
sysInfo: {
|
|
1094
1094
|
windowWidth: isPc ? 375 : 0,
|
|
1095
1095
|
containerWidth: isPc ? 375 : 0,
|
|
1096
1096
|
windowHeight: 0,
|
|
1097
1097
|
netWorkType: '4g',
|
|
1098
1098
|
jdBottomBarHeight: 0,
|
|
1099
1099
|
jdNativeHeaderHeight: 0,
|
|
1100
1100
|
},
|
|
1101
1101
|
queryInfo: {},
|
|
1102
1102
|
shopInfo: {},
|
|
1103
1103
|
openAppData: {},
|
|
1104
1104
|
public info: CommonInterFace.BaseConfigInfo
|
|
1105
1105
|
public config: {
|
|
1106
1106
|
[key: string]: any
|
|
1107
1107
|
}
|
|
1108
1108
|
public lazyContainer: CommonInterFace.lazyContainer
|
|
1109
1109
|
public renderedIsvComponents: CommonInterFace.renderedIsvComponents
|
|
1110
1110
|
public rootEleNode: HTMLElement | null
|
|
1111
1111
|
public checkStatusAndLoginPromise: object | null
|
|
1112
1112
|
private jmfeRegisterStatePromise: Promise<any> | null
|
|
1113
1113
|
private jmfeRegisterState: boolean
|
|
1114
1114
|
public loadJsSdkList: Array<any>
|
|
1115
1115
|
public loadJsSdkListCachePromise: any
|
|
1116
1116
|
constructor(opt) {
|
|
1117
1117
|
this.info = this._getConfig(opt)
|
|
1118
1118
|
this.config = {}
|
|
1119
1119
|
this.loadJsSdkList = []
|
|
1120
1120
|
this.loadJsSdkListCachePromise = {}
|
|
1121
1121
|
this.lazyContainer = {
|
|
1122
1122
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
|
|
1123
1123
|
appLazyContainerList: [],
|
|
1124
1124
|
appLazyFinishContainerList: [],
|
|
1125
1125
|
},
|
|
1126
1126
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
|
|
1127
1127
|
appLazyContainerList: [],
|
|
1128
1128
|
appLazyFinishContainerList: [],
|
|
1129
1129
|
},
|
|
1130
1130
|
}
|
|
1131
1131
|
this.renderedIsvComponents = {}
|
|
1132
1132
|
this.rootEleNode = document.querySelector('body')
|
|
1133
1133
|
this.checkStatusAndLoginPromise = null
|
|
1134
1134
|
this.jmfeRegisterStatePromise = null
|
|
1135
1135
|
this.loadOtherSdk()
|
|
1136
1136
|
isJdApp && this.jmfeReayPromise()
|
|
1137
1137
|
}
|
|
1138
1138
|
_getConfig(opt) {
|
|
1139
1139
|
return Object.assign({}, DefaultConfig, opt)
|
|
1140
1140
|
}
|
|
1141
1141
|
|
|
1142
1142
|
jmfeReayPromise(): Promise<any> {
|
|
1143
1143
|
if (isJdApp) {
|
|
1144
1144
|
if (this.jmfeRegisterState) {
|
|
1145
1145
|
return Promise.resolve(true)
|
|
1146
1146
|
} else {
|
|
1147
1147
|
!this.jmfeRegisterStatePromise &&
|
|
1148
1148
|
(this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
|
|
1149
1149
|
ready('jmfe', 3000)
|
|
1150
1150
|
.then(() => {
|
|
1151
1151
|
window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
|
|
1152
1152
|
this.jmfeRegisterState = true
|
|
1153
1153
|
resolve(true)
|
|
1154
1154
|
console.log('松果app内初始化注册jmfe认证完成')
|
|
1155
1155
|
})
|
|
1156
1156
|
.catch(() => {
|
|
1157
1157
|
reject(false)
|
|
1158
1158
|
})
|
|
1159
1159
|
}))
|
|
1160
1160
|
return this.jmfeRegisterStatePromise
|
|
1161
1161
|
}
|
|
1162
1162
|
} else {
|
|
1163
1163
|
return Promise.reject(false)
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
1167
|
updateBusinessDomainAndApi(domain, api) {
|
|
1168
1168
|
}
|
|
1169
1169
|
|
|
1170
1170
|
formatNativeScreenPageData(action) {
|
|
1171
1171
|
let getChangePageInfo: any = null
|
|
1172
1172
|
try {
|
|
1173
1173
|
const getNativeScreenPageInfoStr = window.XWebView?._callNative(
|
|
1174
1174
|
JSON.stringify({
|
|
1175
1175
|
plugin: 'JDHybridScreenPlugin',
|
|
1176
1176
|
action,
|
|
1177
1177
|
sync: '1',
|
|
1178
1178
|
}),
|
|
1179
1179
|
)
|
|
1180
1180
|
const getChangePageInfoData =
|
|
1181
1181
|
typeof getNativeScreenPageInfoStr === 'string'
|
|
1182
1182
|
? JSON.parse(getNativeScreenPageInfoStr)
|
|
1183
1183
|
: null
|
|
1184
1184
|
if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
|
|
1185
1185
|
const { code, data } = getChangePageInfoData
|
|
1186
1186
|
getChangePageInfo = code && code === '0' ? data : null
|
|
1187
1187
|
}
|
|
1188
1188
|
} catch (e) {
|
|
1189
1189
|
console.log('JDHybridScreenPlugin转换异常', e)
|
|
1190
1190
|
}
|
|
1191
1191
|
return getChangePageInfo
|
|
1192
1192
|
}
|
|
1193
1193
|
|
|
1194
1194
|
isAndroidFoldScreen() {
|
|
1195
1195
|
return this.formatNativeScreenPageData('isFoldScreen') === '1'
|
|
1196
1196
|
}
|
|
1197
1197
|
|
|
1198
1198
|
getJdAndroidPageChangeScreenInfo() {
|
|
1199
1199
|
const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
|
|
1200
1200
|
if (
|
|
1201
1201
|
getPageScreenInfo &&
|
|
1202
1202
|
getPageScreenInfo?.pageWidth &&
|
|
1203
1203
|
getPageScreenInfo?.pageHeight
|
|
1204
1204
|
) {
|
|
1205
1205
|
const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
|
|
1206
1206
|
pageWidth: getPageScreenInfo.pageWidth,
|
|
1207
1207
|
pageHeight: getPageScreenInfo.pageHeight,
|
|
1208
1208
|
})
|
|
1209
1209
|
getPageScreenInfo.pageWidth = pageWidth
|
|
1210
1210
|
getPageScreenInfo.pageHeight = pageHeight
|
|
1211
1211
|
}
|
|
1212
1212
|
return getPageScreenInfo
|
|
1213
1213
|
}
|
|
1214
1214
|
|
|
1215
1215
|
getSystemInfo(params) {
|
|
1216
1216
|
let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
|
|
1217
1217
|
? {}
|
|
1218
1218
|
: getSystemInfos(params)
|
|
1219
1219
|
if (isJdAndAndroidDevice && window.innerWidth <= 0) {
|
|
1220
1220
|
const isfoldScreen = this.isAndroidFoldScreen()
|
|
1221
1221
|
if (isfoldScreen) {
|
|
1222
1222
|
const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
|
|
1223
1223
|
getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
|
|
1224
1224
|
console.info(
|
|
1225
1225
|
'安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
|
|
1226
1226
|
getJdAndroidPageInfo,
|
|
1227
1227
|
)
|
|
1228
1228
|
}
|
|
1229
1229
|
}
|
|
1230
1230
|
this.info.sysInfo = {
|
|
1231
1231
|
actualNavBarHeight: 0,
|
|
1232
1232
|
...this.info.sysInfo,
|
|
1233
1233
|
...info,
|
|
1234
1234
|
safeContentHeight: info?.screenHeight,
|
|
1235
1235
|
headerHeight: 0,
|
|
1236
1236
|
tabBarHeight: 0,
|
|
1237
1237
|
}
|
|
1238
1238
|
if (isJdApp) {
|
|
1239
1239
|
this.info.sysInfo['hostVersionName'] = jdAppVersionStr
|
|
1240
1240
|
this.info.sysInfo['hostAppVersion'] = jdAppVersion
|
|
1241
1241
|
this.getAddressCachePromise()
|
|
1242
1242
|
this.getElderModePromise()
|
|
1243
1243
|
this.getJDAppearanceStatePromise()
|
|
1244
1244
|
this.createJdAndroidRquestEventForTouchStart()
|
|
1245
1245
|
}
|
|
1246
1246
|
this.getWifiVideoAutoPlayAsync()
|
|
1247
1247
|
this.getMPaasConfigAsync()
|
|
1248
1248
|
this.getNetWorkType()
|
|
1249
1249
|
}
|
|
1250
1250
|
|
|
1251
1251
|
taskTimeoutPromise(callBack, timeout = 2000) {
|
|
1252
1252
|
return new Promise(resolve => {
|
|
1253
1253
|
setTimeout(() => {
|
|
1254
1254
|
const getCallBackRes = typeof callBack === 'function' && callBack()
|
|
1255
1255
|
return resolve(getCallBackRes || false)
|
|
1256
1256
|
}, timeout)
|
|
1257
1257
|
})
|
|
1258
1258
|
}
|
|
1259
1259
|
|
|
1260
1260
|
getElderModePromise() {
|
|
1261
1261
|
if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
|
|
1262
1262
|
return Promise.resolve(this.info.sysInfo.jdAppModeType)
|
|
1263
1263
|
} else {
|
|
1264
1264
|
if (isJdAndAndroidDevice) {
|
|
1265
1265
|
this.info.sysInfo.jdAppModeType = '0'
|
|
1266
1266
|
return Promise.resolve(this.info.sysInfo.jdAppModeType)
|
|
1267
1267
|
} else {
|
|
1268
1268
|
return Promise.race([
|
|
1269
1269
|
this.taskTimeoutPromise(() => {
|
|
1270
1270
|
this.info.sysInfo.jdAppModeType = '0'
|
|
1271
1271
|
return this.info.sysInfo.jdAppModeType
|
|
1272
1272
|
}),
|
|
1273
1273
|
new Promise(resolve => {
|
|
1274
1274
|
const getCallBackName = `getJdCurrentModeType${Date.now()}`
|
|
1275
1275
|
if (!window[getCallBackName]) {
|
|
1276
1276
|
window[getCallBackName] = res => {
|
|
1277
1277
|
try {
|
|
1278
1278
|
const getResJson =
|
|
1279
1279
|
typeof res === 'string' ? JSON.parse(res) : res
|
|
1280
1280
|
const { status, data, msg } = getResJson
|
|
1281
1281
|
console.log(`获取松果app展示模式成功,返回结果${data}`)
|
|
1282
1282
|
if (status === '0') {
|
|
1283
1283
|
this.info.sysInfo.jdAppModeType = data
|
|
1284
1284
|
resolve(data)
|
|
1285
1285
|
} else {
|
|
1286
1286
|
resolve('0')
|
|
1287
1287
|
}
|
|
1288
1288
|
} catch (e) {
|
|
1289
1289
|
resolve('0')
|
|
1290
1290
|
}
|
|
1291
1291
|
window[getCallBackName] = null
|
|
1292
1292
|
}
|
|
1293
1293
|
}
|
|
1294
1294
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
1295
1295
|
method: 'callSyncRouterModuleWithParams',
|
|
1296
1296
|
params: JSON.stringify({
|
|
1297
1297
|
routerURL: 'router://JDBModeModule/getCurrentMode',
|
|
1298
1298
|
routerParam: {},
|
|
1299
1299
|
callBackName: `window.${getCallBackName}`,
|
|
1300
1300
|
callBackId: `${getCallBackName}Ios`,
|
|
1301
1301
|
}),
|
|
1302
1302
|
})
|
|
1303
1303
|
}),
|
|
1304
1304
|
])
|
|
1305
1305
|
}
|
|
1306
1306
|
}
|
|
1307
1307
|
}
|
|
1308
1308
|
|
|
1309
1309
|
getJDAppearanceStatePromise() {
|
|
1310
1310
|
if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
|
|
1311
1311
|
return Promise.resolve(this.info.sysInfo.jdAppearanceState)
|
|
1312
1312
|
} else {
|
|
1313
1313
|
return Promise.race([
|
|
1314
1314
|
this.taskTimeoutPromise(() => {
|
|
1315
1315
|
this.info.sysInfo.jdAppearanceState = '0'
|
|
1316
1316
|
return this.info.sysInfo.jdAppearanceState
|
|
1317
1317
|
}),
|
|
1318
1318
|
new Promise(resolve => {
|
|
1319
1319
|
const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
|
|
1320
1320
|
if (!window[getCallBackName]) {
|
|
1321
1321
|
window[getCallBackName] = res => {
|
|
1322
1322
|
try {
|
|
1323
1323
|
console.log('getJDAppearanceStatePromise', res)
|
|
1324
1324
|
const getResJson =
|
|
1325
1325
|
typeof res === 'string' ? JSON.parse(res) : res
|
|
1326
1326
|
const { status, data, msg } = getResJson
|
|
1327
1327
|
console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
|
|
1328
1328
|
if (status === '0') {
|
|
1329
1329
|
this.info.sysInfo.jdAppearanceState = data
|
|
1330
1330
|
resolve(data)
|
|
1331
1331
|
} else {
|
|
1332
1332
|
resolve('0')
|
|
1333
1333
|
}
|
|
1334
1334
|
} catch (e) {
|
|
1335
1335
|
resolve('0')
|
|
1336
1336
|
}
|
|
1337
1337
|
window[getCallBackName] = null
|
|
1338
1338
|
}
|
|
1339
1339
|
}
|
|
1340
1340
|
if (isAndroidDevice) {
|
|
1341
1341
|
const jsonString = JSON.stringify({
|
|
1342
1342
|
callBackName: `window.${getCallBackName}`,
|
|
1343
1343
|
})
|
|
1344
1344
|
console.log('window.JDAppearance', window.JDAppearance)
|
|
1345
1345
|
window.JDAppearance && window.JDAppearance.getUiState(jsonString)
|
|
1346
1346
|
} else {
|
|
1347
1347
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
1348
1348
|
method: 'callSyncRouterModuleWithParams',
|
|
1349
1349
|
params: JSON.stringify({
|
|
1350
1350
|
routerURL:
|
|
1351
1351
|
'router://JDWebViewBusinessModule/getJDAppearanceState',
|
|
1352
1352
|
routerParam: {},
|
|
1353
1353
|
callBackName: `window.${getCallBackName}`,
|
|
1354
1354
|
callBackId: `${getCallBackName}Ios`,
|
|
1355
1355
|
}),
|
|
1356
1356
|
})
|
|
1357
1357
|
}
|
|
1358
1358
|
}),
|
|
1359
1359
|
])
|
|
1360
1360
|
}
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
1363
|
createJdAndroidRquestEventForTouchStart() {
|
|
1364
1364
|
if (isJdAndAndroidDevice && window.JdAndroid) {
|
|
1365
1365
|
const rootEleNode = document.querySelector('body')
|
|
1366
1366
|
if (rootEleNode) {
|
|
1367
1367
|
rootEleNode.addEventListener(
|
|
1368
1368
|
'touchstart',
|
|
1369
1369
|
this.jdAndroidAddEventListenerTouchStart,
|
|
1370
1370
|
false,
|
|
1371
1371
|
)
|
|
1372
1372
|
}
|
|
1373
1373
|
}
|
|
1374
1374
|
}
|
|
1375
1375
|
jdAndroidAddEventListenerTouchStart(e) {
|
|
1376
1376
|
const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
|
|
1377
1377
|
if (!isH5SwiperCustomEle) {
|
|
1378
1378
|
const hasCustomEle = e
|
|
1379
1379
|
? e?.target?.closest('.J_customScroll') ||
|
|
1380
1380
|
e?.target?.closest('.J_customLayout')
|
|
1381
1381
|
: false
|
|
1382
1382
|
if (!hasCustomEle) {
|
|
1383
1383
|
window.JdAndroid.requestEvent(false)
|
|
1384
1384
|
console.log(
|
|
1385
1385
|
'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
|
|
1386
1386
|
)
|
|
1387
1387
|
}
|
|
1388
1388
|
}
|
|
1389
1389
|
}
|
|
1390
1390
|
removeJdAndroidRquestEventForTouchStart() {
|
|
1391
1391
|
if (isJdAndAndroidDevice && window.JdAndroid) {
|
|
1392
1392
|
const rootEleNode = document.querySelector('body')
|
|
1393
1393
|
if (rootEleNode) {
|
|
1394
1394
|
rootEleNode.removeEventListener(
|
|
1395
1395
|
'touchstart',
|
|
1396
1396
|
this.jdAndroidAddEventListenerTouchStart,
|
|
1397
1397
|
false,
|
|
1398
1398
|
)
|
|
1399
1399
|
}
|
|
1400
1400
|
}
|
|
1401
1401
|
}
|
|
1402
1402
|
|
|
1403
1403
|
getNetWorkType() {
|
|
1404
1404
|
if (isJdApp) {
|
|
1405
1405
|
this.jmfeReayPromise().then(() => {
|
|
1406
1406
|
window.jmfe
|
|
1407
1407
|
.getNetworkStatus()
|
|
1408
1408
|
.then(({ status, data }) => {
|
|
1409
1409
|
console.log(
|
|
1410
1410
|
'在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
|
|
1411
1411
|
data,
|
|
1412
1412
|
)
|
|
1413
1413
|
if (status === '0') {
|
|
1414
1414
|
this.info.sysInfo['netWorkType'] = data
|
|
1415
1415
|
} else {
|
|
1416
1416
|
this._taroGetNetworkType()
|
|
1417
1417
|
}
|
|
1418
1418
|
})
|
|
1419
1419
|
.catch(err => {
|
|
1420
1420
|
console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
|
|
1421
1421
|
this._taroGetNetworkType()
|
|
1422
1422
|
})
|
|
1423
1423
|
})
|
|
1424
1424
|
} else {
|
|
1425
1425
|
this._taroGetNetworkType()
|
|
1426
1426
|
}
|
|
1427
1427
|
}
|
|
1428
1428
|
_taroGetNetworkType() {
|
|
1429
1429
|
Taro.getNetworkType().then(getRes => {
|
|
1430
1430
|
if (getRes && getRes.networkType) {
|
|
1431
1431
|
this.info.sysInfo['netWorkType'] = getRes.networkType
|
|
1432
1432
|
console.log(
|
|
1433
1433
|
'在app内通过taro对象获取网络状态完成,当前网络状态',
|
|
1434
1434
|
this.info.sysInfo['netWorkType'],
|
|
1435
1435
|
)
|
|
1436
1436
|
}
|
|
1437
1437
|
})
|
|
1438
1438
|
}
|
|
1439
1439
|
getCacheAddressRouter() {
|
|
1440
1440
|
if (!window.jmfe) return
|
|
1441
1441
|
if (isAndroidDevice) {
|
|
1442
1442
|
return window.jmfe.callRouter({
|
|
1443
1443
|
jdRouter: '1',
|
|
1444
1444
|
routerURL: 'router://JDAddressModule/getCacheAddress',
|
|
1445
1445
|
routerParam: { sceneId: 'basicShoppingProcess' },
|
|
1446
1446
|
})
|
|
1447
1447
|
} else if (isIosDevice) {
|
|
1448
1448
|
return window.jmfe.callRouter({
|
|
1449
1449
|
jdRouter: '1',
|
|
1450
1450
|
routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
|
|
1451
1451
|
routerParam: { sceneId: 'basicShoppingProcess' },
|
|
1452
1452
|
})
|
|
1453
1453
|
} else if (isJdAndHarmonyDevice) {
|
|
1454
1454
|
return new Promise(resolve => {
|
|
1455
1455
|
resolve({})
|
|
1456
1456
|
})
|
|
1457
1457
|
} else {
|
|
1458
1458
|
throw Error(
|
|
1459
1459
|
'Unknown device type cannot obtain the address information through the route!',
|
|
1460
1460
|
)
|
|
1461
1461
|
}
|
|
1462
1462
|
}
|
|
1463
1463
|
|
|
1464
1464
|
getAddressCachePromise() {
|
|
1465
1465
|
return new Promise(resolve => {
|
|
1466
1466
|
if (
|
|
1467
1467
|
this?.info?.sysInfo?.lat &&
|
|
1468
1468
|
this?.info?.sysInfo?.lng &&
|
|
1469
1469
|
this?.info?.sysInfo?.area
|
|
1470
1470
|
) {
|
|
1471
1471
|
resolve({
|
|
1472
1472
|
lat: this.info.sysInfo.lat,
|
|
1473
1473
|
lng: this.info.sysInfo.lng,
|
|
1474
1474
|
area: this?.info?.sysInfo?.area,
|
|
1475
1475
|
})
|
|
1476
1476
|
} else {
|
|
1477
1477
|
this.jmfeReayPromise().then(() => {
|
|
1478
1478
|
this.getCacheAddressRouter()
|
|
1479
1479
|
.then(({ status, data }) => {
|
|
1480
1480
|
console.log("原生端获取经纬度原始数据结果",status,data)
|
|
1481
1481
|
if (status === '0' && data) {
|
|
1482
1482
|
const {
|
|
1483
1483
|
lat,
|
|
1484
1484
|
latitude,
|
|
1485
1485
|
lng,
|
|
1486
1486
|
longitude,
|
|
1487
1487
|
provinceId,
|
|
1488
1488
|
cityId,
|
|
1489
1489
|
countyId,
|
|
1490
1490
|
townId,
|
|
1491
1491
|
} = data || {}
|
|
1492
1492
|
let area = ''
|
|
1493
1493
|
this.info.sysInfo['lat'] = `${lat || latitude || ''}`
|
|
1494
1494
|
this.info.sysInfo['lng'] = `${lng || longitude || ''}`
|
|
1495
1495
|
if (provinceId) {
|
|
1496
1496
|
area = `${provinceId}_${cityId || 0}_${countyId ||
|
|
1497
1497
|
0}_${townId || 0}`
|
|
1498
1498
|
this.info.pageInfo['address'] = area
|
|
1499
1499
|
this.info.pageInfo['addressCommaStr'] = area.replace(
|
|
1500
1500
|
/_/g,
|
|
1501
1501
|
',',
|
|
1502
1502
|
)
|
|
1503
1503
|
}
|
|
1504
1504
|
resolve({
|
|
1505
1505
|
lat: this.info.sysInfo['lat'],
|
|
1506
1506
|
lng: this.info.sysInfo['lng'],
|
|
1507
1507
|
area: area,
|
|
1508
1508
|
})
|
|
1509
1509
|
} else {
|
|
1510
1510
|
resolve({ lat: '', lng: '', area: '' })
|
|
1511
1511
|
}
|
|
1512
1512
|
})
|
|
1513
1513
|
.catch(e => {
|
|
1514
1514
|
console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
|
|
1515
1515
|
resolve({ lat: '', lng: '', area: '' })
|
|
1516
1516
|
console.log('判断jmfe不存在,获取经纬度信息异常')
|
|
1517
1517
|
})
|
|
1518
1518
|
})
|
|
1519
1519
|
}
|
|
1520
1520
|
})
|
|
1521
1521
|
}
|
|
1522
1522
|
|
|
1523
1523
|
async updateMPaasConfigAsync(isBeforePageReady: boolean) {
|
|
1524
1524
|
console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
|
|
1525
1525
|
if (!isJdApp) {
|
|
1526
1526
|
return
|
|
1527
1527
|
}
|
|
1528
1528
|
const avifSwitch = await getMPaasConfigByBussinessKey(
|
|
1529
1529
|
'avifSwitch',
|
|
1530
1530
|
isBeforePageReady,
|
|
1531
1531
|
)
|
|
1532
1532
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
|
|
1533
1533
|
const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
|
|
1534
1534
|
'isFollowAppVideoPlayStatus',
|
|
1535
1535
|
isBeforePageReady,
|
|
1536
1536
|
)
|
|
1537
1537
|
console.log(
|
|
1538
1538
|
'isBeforePageReady:',
|
|
1539
1539
|
isBeforePageReady,
|
|
1540
1540
|
'isFollowAppVideoPlayStatus:',
|
|
1541
1541
|
isFollowAppVideoPlayStatus,
|
|
1542
1542
|
)
|
|
1543
1543
|
if (
|
|
1544
1544
|
isFollowAppVideoPlayStatus === true ||
|
|
1545
1545
|
isFollowAppVideoPlayStatus === 'true'
|
|
1546
1546
|
) {
|
|
1547
1547
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
|
|
1548
1548
|
}
|
|
1549
1549
|
}
|
|
1550
1550
|
|
|
1551
1551
|
async getWifiVideoAutoPlayAsync() {
|
|
1552
1552
|
this.info.sysInfo['wifiVideoAutoPlay'] = false
|
|
1553
1553
|
if (!isJdApp) {
|
|
1554
1554
|
return
|
|
1555
1555
|
}
|
|
1556
1556
|
const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
|
|
1557
1557
|
return 0
|
|
1558
1558
|
})
|
|
1559
1559
|
if (Number(videoPlayStatus) === 1) {
|
|
1560
1560
|
this.info.sysInfo['wifiVideoAutoPlay'] = true
|
|
1561
1561
|
}
|
|
1562
1562
|
}
|
|
1563
1563
|
|
|
1564
1564
|
async getMPaasConfigAsync() {
|
|
1565
1565
|
this.info.sysInfo.dynamicConfig = {}
|
|
1566
1566
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
|
|
1567
1567
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
|
|
1568
1568
|
return this.updateMPaasConfigAsync(true)
|
|
1569
1569
|
}
|
|
1570
1570
|
|
|
1571
1571
|
getDynamicConfig(key: string){
|
|
1572
1572
|
return this.info.sysInfo.dynamicConfig[key]
|
|
1573
1573
|
}
|
|
1574
1574
|
async updateMPaasConfig() {
|
|
1575
1575
|
console.log('updateMPaasConfig')
|
|
1576
1576
|
if (
|
|
1577
1577
|
isIosDevice &&
|
|
1578
1578
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
|
|
1579
1579
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
|
|
1580
1580
|
) {
|
|
1581
1581
|
try {
|
|
1582
1582
|
await this.updateMPaasConfigAsync(false)
|
|
1583
1583
|
} catch (e) {
|
|
1584
1584
|
console.log('updateMPaasConfigAsync:', e)
|
|
1585
1585
|
}
|
|
1586
1586
|
}
|
|
1587
1587
|
}
|
|
1588
1588
|
|
|
1589
1589
|
toLogin(options) {
|
|
1590
1590
|
return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
|
|
1591
1591
|
? this.toWxAppLogin(options)
|
|
1592
1592
|
: this.toWebLogin(options)
|
|
1593
1593
|
}
|
|
1594
1594
|
|
|
1595
1595
|
doLogin(options) {
|
|
1596
1596
|
return this.toLogin(options)
|
|
1597
1597
|
}
|
|
1598
1598
|
|
|
1599
1599
|
doLoginForJdPin(options = {}) {
|
|
1600
1600
|
return this.doLogin({
|
|
1601
1601
|
loginColor: {
|
|
1602
1602
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
1603
1603
|
dpin: 0,
|
|
1604
1604
|
},
|
|
1605
1605
|
...options,
|
|
1606
1606
|
})
|
|
1607
1607
|
}
|
|
1608
1608
|
|
|
1609
1609
|
toWebLogin(options) {
|
|
1610
1610
|
let params: {
|
|
1611
1611
|
returnurl: string
|
|
1612
1612
|
} = {
|
|
1613
1613
|
returnurl: '',
|
|
1614
1614
|
}
|
|
1615
1615
|
const loginUrl = isPc
|
|
1616
1616
|
? `//passport.jd.com/new/login.aspx`
|
|
1617
1617
|
: `${domain.mobileLogin}/user/login.action`
|
|
1618
1618
|
const defaultParams = {
|
|
1619
1619
|
appid: '100',
|
|
1620
1620
|
returnurl: window.location.href,
|
|
1621
1621
|
}
|
|
1622
1622
|
if (isString(options)) {
|
|
1623
1623
|
params = Object.assign({}, defaultParams, {
|
|
1624
1624
|
returnurl: options,
|
|
1625
1625
|
})
|
|
1626
1626
|
} else if (isObject(options)) {
|
|
1627
1627
|
const { loginColor, ...otherOptions } = options
|
|
1628
1628
|
params = Object.assign({}, defaultParams, otherOptions)
|
|
1629
1629
|
} else {
|
|
1630
1630
|
params = defaultParams
|
|
1631
1631
|
}
|
|
1632
1632
|
params.returnurl = encodeURIComponent(params.returnurl)
|
|
1633
1633
|
let getFullUrl = loginUrl + '?' + serialize(params)
|
|
1634
1634
|
if (isPc) {
|
|
1635
1635
|
getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
|
|
1636
1636
|
}
|
|
1637
1637
|
return Promise.resolve({
|
|
1638
1638
|
h5ToUrl: true,
|
|
1639
1639
|
url: getFullUrl,
|
|
1640
1640
|
}).then(() => {
|
|
1641
1641
|
window.location.href = getFullUrl
|
|
1642
1642
|
})
|
|
1643
1643
|
}
|
|
1644
1644
|
|
|
1645
1645
|
toWxAppLogin(options = {}) {
|
|
1646
1646
|
console.log('微信京购小程序中h5登录跳转', options)
|
|
1647
1647
|
return Promise.resolve(true).then(() => {
|
|
1648
1648
|
const { loginColor } = Object.assign(
|
|
1649
1649
|
{},
|
|
1650
1650
|
{
|
|
1651
1651
|
loginColor: {
|
|
1652
1652
|
biz: WXAPP_BIZ_KEY,
|
|
1653
1653
|
dpin: 1,
|
|
1654
1654
|
},
|
|
1655
1655
|
},
|
|
1656
1656
|
options,
|
|
1657
1657
|
)
|
|
1658
1658
|
window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
|
|
1659
1659
|
loginColor.biz
|
|
1660
1660
|
}&url=${encodeURIComponent(window.location.href)}`
|
|
1661
1661
|
})
|
|
1662
1662
|
}
|
|
1663
1663
|
|
|
1664
1664
|
getLoginCookie() {
|
|
1665
1665
|
return Promise.resolve({
|
|
1666
1666
|
pin: cookie.get('pin') || '',
|
|
1667
1667
|
})
|
|
1668
1668
|
}
|
|
1669
1669
|
|
|
1670
1670
|
clearLoginCookie() {
|
|
1671
1671
|
cookie.remove('pin')
|
|
1672
1672
|
}
|
|
1673
1673
|
|
|
1674
1674
|
checkStatusAndLogin(options = {}) {
|
|
1675
1675
|
if (!this.checkStatusAndLoginPromise) {
|
|
1676
1676
|
this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
|
|
1677
1677
|
try {
|
|
1678
1678
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(
|
|
1679
1679
|
options,
|
|
1680
1680
|
)
|
|
1681
1681
|
if (getLoginState) {
|
|
1682
1682
|
resolve(true)
|
|
1683
1683
|
} else {
|
|
1684
1684
|
this.toLogin(options)
|
|
1685
1685
|
reject(false)
|
|
1686
1686
|
}
|
|
1687
1687
|
} catch (e) {
|
|
1688
1688
|
this.toLogin(options)
|
|
1689
1689
|
reject(false)
|
|
1690
1690
|
}
|
|
1691
1691
|
})
|
|
1692
1692
|
return this.checkStatusAndLoginPromise
|
|
1693
1693
|
} else {
|
|
1694
1694
|
return this.checkStatusAndLoginPromise
|
|
1695
1695
|
.then(() => {
|
|
1696
1696
|
return Promise.resolve(true)
|
|
1697
1697
|
})
|
|
1698
1698
|
.catch(() => {
|
|
1699
1699
|
this.toLogin(options)
|
|
1700
1700
|
return Promise.reject(true)
|
|
1701
1701
|
})
|
|
1702
1702
|
}
|
|
1703
1703
|
}
|
|
1704
1704
|
|
|
1705
1705
|
checkJdStatusAndLogin(
|
|
1706
1706
|
options = {
|
|
1707
1707
|
loginColor: {
|
|
1708
1708
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
1709
1709
|
dpin: 0,
|
|
1710
1710
|
},
|
|
1711
1711
|
},
|
|
1712
1712
|
) {
|
|
1713
1713
|
return this.checkStatusAndLogin(options)
|
|
1714
1714
|
}
|
|
1715
1715
|
|
|
1716
1716
|
doCheckLoginStateAndForApiCheck(options) {
|
|
1717
1717
|
if (this.info.loginState) {
|
|
1718
1718
|
return Promise.resolve(true)
|
|
1719
1719
|
} else {
|
|
1720
1720
|
return new Promise((resolve, reject) => {
|
|
1721
1721
|
if (
|
|
1722
1722
|
this.info.isJingGouMiniViewState ||
|
|
1723
1723
|
this.info.isJingxiMiniViewState
|
|
1724
1724
|
) {
|
|
1725
1725
|
const getWqAuthToken = cookie.get('wq_auth_token')
|
|
1726
1726
|
const getWqSkey = cookie.get('wq_skey')
|
|
1727
1727
|
const getWqUin = cookie.get('wq_uin')
|
|
1728
1728
|
const isLoginState =
|
|
1729
1729
|
options?.loginColor?.dpin === 0
|
|
1730
1730
|
? getWqAuthToken
|
|
1731
1731
|
: getWqSkey && getWqUin
|
|
1732
1732
|
if (isLoginState) {
|
|
1733
1733
|
this.info.loginState = true
|
|
1734
1734
|
resolve(true)
|
|
1735
1735
|
} else {
|
|
1736
1736
|
reject(false)
|
|
1737
1737
|
}
|
|
1738
1738
|
} else {
|
|
1739
1739
|
Taro.request({
|
|
1740
1740
|
url: api.isLogin,
|
|
1741
1741
|
jsonp: true,
|
|
1742
1742
|
timeout: 3000,
|
|
1743
1743
|
success: res => {
|
|
1744
1744
|
const { statusCode, data } = res
|
|
1745
1745
|
if (
|
|
1746
1746
|
statusCode === 200 &&
|
|
1747
1747
|
data?.islogin &&
|
|
1748
1748
|
Number(data.islogin) === 1
|
|
1749
1749
|
) {
|
|
1750
1750
|
this.info.loginState = true
|
|
1751
1751
|
resolve(true)
|
|
1752
1752
|
} else {
|
|
1753
1753
|
reject(false)
|
|
1754
1754
|
}
|
|
1755
1755
|
},
|
|
1756
1756
|
fail: err => {
|
|
1757
1757
|
console.log('登录检查异常', err)
|
|
1758
1758
|
reject(false)
|
|
1759
1759
|
},
|
|
1760
1760
|
})
|
|
1761
1761
|
}
|
|
1762
1762
|
})
|
|
1763
1763
|
}
|
|
1764
1764
|
}
|
|
1765
1765
|
|
|
1766
1766
|
checkLoginStatus(options) {
|
|
1767
1767
|
return new Promise(async (resolve, reject) => {
|
|
1768
1768
|
try {
|
|
1769
1769
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(
|
|
1770
1770
|
options,
|
|
1771
1771
|
)
|
|
1772
1772
|
if (getLoginState) {
|
|
1773
1773
|
const { pin } = await this.getLoginCookie()
|
|
1774
1774
|
this.info.userInfo = {
|
|
1775
1775
|
pin,
|
|
1776
1776
|
encodePin: encodeURIComponent(pin),
|
|
1777
1777
|
ptkey: '',
|
|
1778
1778
|
}
|
|
1779
1779
|
resolve(true)
|
|
1780
1780
|
} else {
|
|
1781
1781
|
reject(false)
|
|
1782
1782
|
}
|
|
1783
1783
|
} catch (e) {
|
|
1784
1784
|
reject(false)
|
|
1785
1785
|
}
|
|
1786
1786
|
})
|
|
1787
1787
|
}
|
|
1788
1788
|
|
|
1789
1789
|
updatePageAndLogInfo(updateQuery = {}) {
|
|
1790
1790
|
const createUpdateQueryInfo: {
|
|
1791
1791
|
query: {
|
|
1792
1792
|
shopId?: string | number
|
|
1793
1793
|
venderId?: string | number
|
|
1794
1794
|
}
|
|
1795
1795
|
updateShopInfoState: boolean
|
|
1796
1796
|
} = Object.assign(
|
|
1797
1797
|
{},
|
|
1798
1798
|
{
|
|
1799
1799
|
query: {},
|
|
1800
1800
|
updateShopInfoState: false,
|
|
1801
1801
|
},
|
|
1802
1802
|
updateQuery,
|
|
1803
1803
|
)
|
|
1804
1804
|
console.log(
|
|
1805
1805
|
'获取当前下发的店铺查询参数',
|
|
1806
1806
|
updateQuery,
|
|
1807
1807
|
'获取之前保存的shopInfo店铺查询参数',
|
|
1808
1808
|
this.info?.shopInfo,
|
|
1809
1809
|
)
|
|
1810
1810
|
const { query, updateShopInfoState } = createUpdateQueryInfo
|
|
1811
1811
|
const { shopId, venderId, un_area } = query
|
|
1812
1812
|
if (updateShopInfoState) {
|
|
1813
1813
|
this.info.queryInfo = {
|
|
1814
1814
|
...this.info.queryInfo,
|
|
1815
1815
|
...query,
|
|
1816
1816
|
}
|
|
1817
1817
|
if (shopId && venderId) {
|
|
1818
1818
|
this.info.shopInfo = {
|
|
1819
1819
|
shopId: `${shopId}`,
|
|
1820
1820
|
venderId: `${venderId}`,
|
|
1821
1821
|
}
|
|
1822
1822
|
}
|
|
1823
1823
|
} else {
|
|
1824
1824
|
this.info.queryInfo = {
|
|
1825
1825
|
...query,
|
|
1826
1826
|
}
|
|
1827
1827
|
if (
|
|
1828
1828
|
this.info.shopInfo?.shopId &&
|
|
1829
1829
|
this.info.shopInfo?.venderId &&
|
|
1830
1830
|
(this.info.shopInfo.shopId == shopId ||
|
|
1831
1831
|
this.info.shopInfo.venderId == venderId)
|
|
1832
1832
|
) {
|
|
1833
1833
|
this.info.queryInfo.shopId = this.info.shopInfo.shopId
|
|
1834
1834
|
this.info.queryInfo.venderId = this.info.shopInfo.venderId
|
|
1835
1835
|
console.log(
|
|
1836
1836
|
'当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
|
|
1837
1837
|
this.info.queryInfo,
|
|
1838
1838
|
)
|
|
1839
1839
|
}
|
|
1840
1840
|
}
|
|
1841
1841
|
this.info.queryInfo['shopId'] &&
|
|
1842
1842
|
(this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
|
|
1843
1843
|
this.info.queryInfo['venderId'] &&
|
|
1844
1844
|
(this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
|
|
1845
1845
|
console.log(
|
|
1846
1846
|
'h5==获取店铺下发查询参数\n',
|
|
1847
1847
|
query,
|
|
1848
1848
|
'\n获取店铺最后查询参数\n',
|
|
1849
1849
|
this.info.queryInfo,
|
|
1850
1850
|
'\n是否为更新店铺状态\n',
|
|
1851
1851
|
updateShopInfoState,
|
|
1852
1852
|
)
|
|
1853
1853
|
const changeArea =
|
|
1854
1854
|
un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
|
|
1855
1855
|
if (changeArea) {
|
|
1856
1856
|
this.info.pageInfo.address = changeArea
|
|
1857
1857
|
this.info.pageInfo.un_area = changeArea
|
|
1858
1858
|
this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
|
|
1859
1859
|
}
|
|
1860
1860
|
}
|
|
1861
1861
|
|
|
1862
1862
|
dealLoadSdkList(){
|
|
1863
1863
|
const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
|
|
1864
1864
|
const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? []
|
|
1865
1865
|
const concatLoadJsList = [].concat(globalLoadJsList,businessLoadJsList)
|
|
1866
1866
|
let mergeLoadJsList = globalLoadJsList
|
|
1867
1867
|
try {
|
|
1868
1868
|
mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
|
|
1869
1869
|
const getFindIndex = accArr.findIndex(item => item?.fileName === current?.fileName);
|
|
1870
1870
|
getFindIndex !== -1 ? (accArr[getFindIndex] = {...accArr[getFindIndex],...current }) : accArr.push(current);
|
|
1871
1871
|
return accArr;
|
|
1872
1872
|
}, []);
|
|
1873
1873
|
}catch (e) {
|
|
1874
1874
|
console.log("LoadJsList合并错误", e)
|
|
1875
1875
|
}
|
|
1876
1876
|
console.log("globalLoadJsList",globalLoadJsList,"businessLoadJsList",businessLoadJsList,"两个加载jsList集合合并完成", mergeLoadJsList)
|
|
1877
1877
|
this.loadJsSdkList = mergeLoadJsList
|
|
1878
1878
|
return this.loadJsSdkList
|
|
1879
1879
|
}
|
|
1880
1880
|
|
|
1881
1881
|
renderNextTickLoadSdk(){
|
|
1882
1882
|
Taro.nextTick(() => {
|
|
1883
1883
|
console.log("页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======")
|
|
1884
1884
|
setTimeout(() => {
|
|
1885
1885
|
this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK,this.loadJsSdkList)
|
|
1886
1886
|
},1000)
|
|
1887
1887
|
})
|
|
1888
1888
|
}
|
|
1889
1889
|
|
|
1890
1890
|
loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW,loadJsList:any[] = [] ) {
|
|
1891
1891
|
const getLoadJsList = Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList()
|
|
1892
1892
|
const getLoadFilterList = getLoadJsList.filter(item => {
|
|
1893
1893
|
const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL
|
|
1894
1894
|
let getLoastLoadEventState = true
|
|
1895
1895
|
if(getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP){
|
|
1896
1896
|
getLoastLoadEventState = isJdApp
|
|
1897
1897
|
}
|
|
1898
1898
|
else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
|
|
1899
1899
|
getLoastLoadEventState = !isJdApp
|
|
1900
1900
|
}
|
|
1901
1901
|
const getInitTriggerType = isJdApp && item?.initJdAppTriggerType ? item?.initTriggerType : item?.initTriggerType || LoadJsInitTriggerType.NOW
|
|
1902
1902
|
const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false
|
|
1903
1903
|
return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay
|
|
1904
1904
|
})
|
|
1905
1905
|
console.log("获取当前触发方式",triggerType,"获取当前最后加载的js集合",getLoadFilterList,"过滤前的加载集合",getLoadJsList)
|
|
1906
1906
|
getLoadFilterList.length > 0 && getLoadFilterList.forEach((item) => {
|
|
1907
1907
|
const isLoadState = /sgm/.test(item?.fileName) ? window?.shopGlobalSwitch?.openSgm === "true" : true
|
|
1908
1908
|
isLoadState && this.loadItemSdkPromise(item)
|
|
1909
1909
|
.then((res) => {
|
|
1910
1910
|
console.info('当前js地址' + item?.src, '加载状态', res)
|
|
1911
1911
|
})
|
|
1912
1912
|
.catch((err) => {
|
|
1913
1913
|
console.info('当前js地址加载异常', item?.src)
|
|
1914
1914
|
window?.fetchErrorData &&
|
|
1915
1915
|
window.fetchErrorData({
|
|
1916
1916
|
title: '公共js加载异常',
|
|
1917
1917
|
type: "jsLoad",
|
|
1918
1918
|
data: err,
|
|
1919
1919
|
})
|
|
1920
1920
|
})
|
|
1921
1921
|
})
|
|
1922
1922
|
}
|
|
1923
1923
|
loadScriptEle(jsInfo,resolve,reject){
|
|
1924
1924
|
const getFileName = jsInfo?.fileName;
|
|
1925
1925
|
if(getFileName){
|
|
1926
1926
|
const getEleId = `J_loadJs_${getFileName}`
|
|
1927
1927
|
const getEle = document.getElementById(getEleId)
|
|
1928
1928
|
if (!getEle) {
|
|
1929
1929
|
const jsLoadErrorSgmCode = `jsLoadError_${
|
|
1930
1930
|
jsInfo?.fileName || 'customJs'
|
|
1931
1931
|
}`
|
|
1932
1932
|
const _sgmEle = document.createElement('script')
|
|
1933
1933
|
_sgmEle.id = getEleId
|
|
1934
1934
|
_sgmEle.onload = function () {
|
|
1935
1935
|
resolve({
|
|
1936
1936
|
...jsInfo,
|
|
1937
1937
|
jsTip: "js加载成功",
|
|
1938
1938
|
})
|
|
1939
1939
|
}
|
|
1940
1940
|
_sgmEle.onerror = function () {
|
|
1941
1941
|
reject({
|
|
1942
1942
|
...jsInfo,
|
|
1943
1943
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1944
1944
|
jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
|
|
1945
1945
|
})
|
|
1946
1946
|
}
|
|
1947
1947
|
const dataAttrList = ['timeout','fileName',"env"]
|
|
1948
1948
|
const getJsInfoKeyList = Object.keys(jsInfo)
|
|
1949
1949
|
getJsInfoKeyList.forEach(key => {
|
|
1950
1950
|
if(key === "async"){
|
|
1951
1951
|
_sgmEle.async = jsInfo[key]
|
|
1952
1952
|
}else if(key === "crossOrigin"){
|
|
1953
1953
|
_sgmEle.crossOrigin = jsInfo[key]
|
|
1954
1954
|
}else if(key === "src"){
|
|
1955
1955
|
_sgmEle.src = `${jsInfo[key]}`
|
|
1956
1956
|
}else if(dataAttrList.includes(key) || /init/.test(key)) {
|
|
1957
1957
|
_sgmEle.setAttribute(`data-${key}`, jsInfo[key])
|
|
1958
1958
|
}else {
|
|
1959
1959
|
_sgmEle.setAttribute(key, jsInfo[key])
|
|
1960
1960
|
}
|
|
1961
1961
|
})
|
|
1962
1962
|
document.head.appendChild(_sgmEle)
|
|
1963
1963
|
}else {
|
|
1964
1964
|
console.log(`当前${jsInfo?.fileName || "js"}已经存在页面中,可以直接调用相关方法`,jsInfo)
|
|
1965
1965
|
resolve({
|
|
1966
1966
|
...jsInfo,
|
|
1967
1967
|
jsTip: "js本身已存在页面中",
|
|
1968
1968
|
})
|
|
1969
1969
|
}
|
|
1970
1970
|
}else {
|
|
1971
1971
|
console.warn("当前js资源信息缺少必要的参数fileName,请关注",jsInfo)
|
|
1972
1972
|
}
|
|
1973
1973
|
}
|
|
1974
1974
|
|
|
1975
1975
|
loadItemSdkPromise(jsInfo = {}){
|
|
1976
1976
|
if(jsInfo?.src){
|
|
1977
1977
|
const getInitLoadType = isJdApp && jsInfo?.initJdAppLoadType ? jsInfo?.initJdAppLoadType : jsInfo?.initLoadType || LoadJsInitLoadType.ALL
|
|
1978
1978
|
if(getInitLoadType !== LoadJsInitLoadType.NONE){
|
|
1979
1979
|
const getFileKeyName = jsInfo?.fileName || jsInfo?.src
|
|
1980
1980
|
if (!this.loadJsSdkListCachePromise[getFileKeyName]){
|
|
1981
1981
|
if(getInitLoadType !== LoadJsInitLoadType.INSERT_ELE){
|
|
1982
1982
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
|
|
1983
1983
|
const jsLoadErrorSgmCode = `jsLoadError_${
|
|
1984
1984
|
jsInfo?.fileName || 'customJs'
|
|
1985
1985
|
}`
|
|
1986
1986
|
try {
|
|
1987
1987
|
const jsXhrRequest = new XMLHttpRequest();
|
|
1988
1988
|
jsXhrRequest.timeout = jsInfo?.timeout ?? 2000
|
|
1989
1989
|
const jsUrl = `${jsInfo?.src}`
|
|
1990
1990
|
jsXhrRequest.open('GET', jsUrl, true);
|
|
1991
1991
|
jsXhrRequest.onload = () => {
|
|
1992
1992
|
if (jsXhrRequest.status === 200) {
|
|
1993
1993
|
const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL
|
|
1994
1994
|
if(getInsetHeadState){
|
|
1995
1995
|
this.loadScriptEle(jsInfo,resolve,reject)
|
|
1996
1996
|
}else {
|
|
1997
1997
|
resolve({
|
|
1998
1998
|
...jsInfo,
|
|
1999
1999
|
jsTip: "js请求成功,暂未插入head节点,业务自行单独插入",
|
|
2000
2000
|
})
|
|
2001
2001
|
}
|
|
2002
2002
|
}else {
|
|
2003
2003
|
const getRes = {
|
|
2004
2004
|
...jsInfo,
|
|
2005
2005
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
2006
2006
|
jsReqError: `请求状态异常,状态为${jsXhrRequest?.status}`,
|
|
2007
2007
|
jsReqState: jsXhrRequest?.status,
|
|
2008
2008
|
}
|
|
2009
2009
|
console.log("当前js请求状态异常", getRes)
|
|
2010
2010
|
reject(getRes)
|
|
2011
2011
|
}
|
|
2012
2012
|
}
|
|
2013
2013
|
jsXhrRequest.onerror = () => {
|
|
2014
2014
|
const getRes = {
|
|
2015
2015
|
...jsInfo,
|
|
2016
2016
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
2017
2017
|
jsReqError: '请求错误',
|
|
2018
2018
|
}
|
|
2019
2019
|
console.log("当前js请求错误", getRes)
|
|
2020
2020
|
jsXhrRequest.abort()
|
|
2021
2021
|
reject(getRes)
|
|
2022
2022
|
}
|
|
2023
2023
|
jsXhrRequest.ontimeout = () => {
|
|
2024
2024
|
const getRes = {
|
|
2025
2025
|
...jsInfo,
|
|
2026
2026
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
2027
2027
|
jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
|
|
2028
2028
|
}
|
|
2029
2029
|
console.log("当前js请求超时异常", getRes)
|
|
2030
2030
|
jsXhrRequest.abort()
|
|
2031
2031
|
reject(getRes)
|
|
2032
2032
|
}
|
|
2033
2033
|
jsXhrRequest.send();
|
|
2034
2034
|
}catch (e) {
|
|
2035
2035
|
console.log("执行js请求异常",e)
|
|
2036
2036
|
reject({
|
|
2037
2037
|
...jsInfo,
|
|
2038
2038
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
2039
2039
|
jsReqError: '未知异常',
|
|
2040
2040
|
error: e,
|
|
2041
2041
|
})
|
|
2042
2042
|
}
|
|
2043
2043
|
})
|
|
2044
2044
|
}else {
|
|
2045
2045
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
|
|
2046
2046
|
return this.loadScriptEle(jsInfo,resolve,reject)
|
|
2047
2047
|
})
|
|
2048
2048
|
}
|
|
2049
2049
|
}
|
|
2050
2050
|
return this.loadJsSdkListCachePromise[getFileKeyName]
|
|
2051
2051
|
}else {
|
|
2052
2052
|
return Promise.resolve({
|
|
2053
2053
|
...jsInfo,
|
|
2054
2054
|
jsTip: "js加载方式设置为不加载,当前不做处理",
|
|
2055
2055
|
})
|
|
2056
2056
|
}
|
|
2057
2057
|
}else {
|
|
2058
2058
|
return Promise.reject(jsInfo)
|
|
2059
2059
|
}
|
|
2060
2060
|
}
|