@conecli/cone-render 0.10.1-isv2.1 → 0.10.1-isv2.4

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