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