@conecli/cone-render 0.9.1-shop2.16 → 0.9.1-shop2.18

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