@conecli/cone-render 0.10.1-shop3.1 → 0.10.1-shop3.2

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