@conecli/cone-render 0.8.43 → 0.8.45

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