@conecli/cone-render 0.10.1-shop3.5 → 0.10.1-shop3.7

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