@conecli/cone-render 0.8.44 → 0.8.46-beta.0

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