@conecli/cone-render 0.9.1-shop2.27 → 0.9.1-shop2.28

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