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

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