@conecli/cone-render 0.9.1-shop2.13 → 0.9.1-shop2.14

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 (35) hide show
  1. package/dist/common/const.ts +1 -1
  2. package/dist/common/index.h5.ts +1 -1
  3. package/dist/common/index.weapp.ts +1 -1
  4. package/dist/common/sgmCustomCode.ts +1 -1
  5. package/dist/components/ErrorBoundary.tsx +1 -1
  6. package/dist/components/base/CustomVideo/index.tsx +1 -1
  7. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  8. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  9. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  10. package/dist/components/base/NetworkDataError/index.module.scss +3 -0
  11. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  12. package/dist/components/remoteFloorItem.tsx +1 -1
  13. package/dist/interface/component.ts +1 -1
  14. package/dist/jumpEventReport/base.ts +1 -1
  15. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  16. package/dist/jumpEventReport/web.base.ts +1 -1
  17. package/dist/jumpEventReport/web.jd.ts +1 -1
  18. package/dist/modules/ContainerFloorList/index.h5.module.scss +1 -0
  19. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  20. package/dist/open/api/device.ts +1 -1
  21. package/dist/open/api/request.ts +1 -1
  22. package/dist/open/api/shopMember.ts +1 -1
  23. package/dist/open/api/util.ts +1 -1
  24. package/dist/open/components/index.ts +1 -1
  25. package/dist/sass/app.h5.scss +5 -0
  26. package/dist/service/requestServer.ts +1 -1
  27. package/dist/utils/connectNativeJsBridge.ts +1 -1
  28. package/dist/utils/h5Utils.ts +1 -1
  29. package/dist/utils/index.h5.ts +1 -1
  30. package/dist/utils/index.ts +1 -1
  31. package/dist/utils/index.weapp.ts +1 -1
  32. package/dist/utils/sgmCodeUtils.ts +1 -1
  33. package/dist/utils/taroRenderUtil.ts +1 -1
  34. package/dist/utils/utils.ts +1 -1
  35. package/package.json +1 -1
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  isJdApp,
3
2
  isIosDevice,
4
3
  isAndroidDevice,
5
4
  isJdAndHarmonyDevice,
6
5
  isJdAndAndroidDevice,
7
6
  jdAppVersion,
8
7
  jdAppVersionStr,
9
8
  isString,
10
9
  isObject,
11
10
  serialize,
12
11
  dealNativePixelToCssPixel,
13
12
  BUSINESS_TYPE,
14
13
  JSSDK_APP_WEBVIEW_CODE,
15
14
  SECTION_HOME_TAB_NAME_TYPE,
16
15
  SECTION_HOME_TAB_TYPE,
17
16
  WXAPP_BIZ_KEY,
18
17
  WX_BUSINESS_TYPE,
19
18
  MPAAS_CONFIG_APP_VERSION,
20
19
  MPAAS_CONFIG_APP_LOW_VERSION,
21
20
  WXAPP_BIZ_SHOP_LIGHT_KEY,
22
21
  loginState: false,
23
22
  cookiesStr: '',
24
23
  userInfo: userPinKey,
25
24
  isJingGouMiniViewState: false,
26
25
  isJingxiMiniViewState: false,
27
26
  pageInfo: {
28
27
  wxBusinessType: WX_BUSINESS_TYPE.NO,
29
28
  address: '',
30
29
  addressCommaStr: '',
31
30
  un_area: '',
32
31
  vapptype: '1',
33
32
  pageType: 'home',
34
33
  isExposureState: false,
35
34
  moduleId: '',
36
35
  entrance: '',
37
36
  dataType: BUSINESS_TYPE.ONLINE,
38
37
  floorExposureInfo: {},
39
38
  floorVideInfo: {},
40
39
  productVideInfo: {},
41
40
  tabsLoadAllDataInfo: {
42
41
  [SECTION_HOME_TAB_NAME_TYPE[
43
42
  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
  getCacheAddressRouter() {
404
403
  if (!window.jmfe) return
405
404
  if (isAndroidDevice) {
406
405
  return window.jmfe.callRouter({
407
406
  jdRouter: '1',
408
407
  routerURL: 'router://JDAddressModule/getCacheAddress',
409
408
  routerParam: { sceneId: 'basicShoppingProcess' },
410
409
  })
411
410
  } else if (isIosDevice) {
412
411
  return window.jmfe.callRouter({
413
412
  jdRouter: '1',
414
413
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
415
414
  routerParam: { sceneId: 'basicShoppingProcess' },
416
415
  })
417
416
  } else if (isJdAndHarmonyDevice) {
418
417
  return new Promise(resolve => {
419
418
  resolve({})
420
419
  })
421
420
  } else {
422
421
  throw Error(
423
422
  'Unknown device type cannot obtain the address information through the route!',
424
423
  )
425
424
  }
426
425
  }
427
426
 
428
427
  getAddressCachePromise() {
429
428
  return new Promise(resolve => {
430
429
  if (
431
430
  this?.info?.sysInfo?.lat &&
432
431
  this?.info?.sysInfo?.lng &&
433
432
  this?.info?.sysInfo?.area
434
433
  ) {
435
434
  resolve({
436
435
  lat: this.info.sysInfo.lat,
437
436
  lng: this.info.sysInfo.lng,
438
437
  area: this?.info?.sysInfo?.area,
439
438
  })
440
439
  } else {
441
440
  this.jmfeReayPromise().then(() => {
442
441
  this.getCacheAddressRouter()
443
442
  .then(({ status, data }) => {
444
443
  if (status === '0' && data) {
445
444
  const {
446
445
  lat,
447
446
  latitude,
448
447
  lng,
449
448
  longitude,
450
449
  provinceId,
451
450
  cityId,
452
451
  countyId,
453
452
  townId,
454
453
  } = data || {}
455
454
  let area = ''
456
455
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
457
456
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
458
457
  if (provinceId) {
459
458
  area = `${provinceId}_${cityId || 0}_${countyId ||
460
459
  0}_${townId || 0}`
461
460
  this.info.pageInfo['address'] = area
462
461
  this.info.pageInfo['addressCommaStr'] = area.replace(
463
462
  /_/g,
464
463
  ',',
465
464
  )
466
465
  }
467
466
  resolve({
468
467
  lat: this.info.sysInfo['lat'],
469
468
  lng: this.info.sysInfo['lng'],
470
469
  area: area,
471
470
  })
472
471
  } else {
473
472
  resolve({ lat: '', lng: '', area: '' })
474
473
  }
475
474
  })
476
475
  .catch(e => {
477
476
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
478
477
  resolve({ lat: '', lng: '', area: '' })
479
478
  console.log('判断jmfe不存在,获取经纬度信息异常')
480
479
  })
481
480
  })
482
481
  }
483
482
  })
484
483
  }
485
484
 
486
485
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
487
486
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
488
487
  if (!isJdApp) {
489
488
  return
490
489
  }
491
490
  const avifSwitch = await getMPaasConfigByBussinessKey(
492
491
  'avifSwitch',
493
492
  isBeforePageReady,
494
493
  )
495
494
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
496
495
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
497
496
  'isFollowAppVideoPlayStatus',
498
497
  isBeforePageReady,
499
498
  )
500
499
  console.log(
501
500
  'isBeforePageReady:',
502
501
  isBeforePageReady,
503
502
  'isFollowAppVideoPlayStatus:',
504
503
  isFollowAppVideoPlayStatus,
505
504
  )
506
505
  if (
507
506
  isFollowAppVideoPlayStatus === true ||
508
507
  isFollowAppVideoPlayStatus === 'true'
509
508
  ) {
510
509
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
511
510
  }
512
511
  }
513
512
 
514
513
  async getWifiVideoAutoPlayAsync() {
515
514
  this.info.sysInfo['wifiVideoAutoPlay'] = false
516
515
  if (!isJdApp) {
517
516
  return
518
517
  }
519
518
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
520
519
  return 0
521
520
  })
522
521
  if (Number(videoPlayStatus) === 1) {
523
522
  this.info.sysInfo['wifiVideoAutoPlay'] = true
524
523
  }
525
524
  }
526
525
 
527
526
  async getMPaasConfigAsync() {
528
527
  this.info.sysInfo.dynamicConfig = {}
529
528
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
530
529
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
531
530
  return this.updateMPaasConfigAsync(true)
532
531
  }
533
532
 
534
533
  getDynamicConfig(key: string){
535
534
  return this.info.sysInfo.dynamicConfig[key]
536
535
  }
537
536
  async updateMPaasConfig() {
538
537
  console.log('updateMPaasConfig')
539
538
  if (
540
539
  isIosDevice &&
541
540
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
542
541
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
543
542
  ) {
544
543
  try {
545
544
  await this.updateMPaasConfigAsync(false)
546
545
  } catch (e) {
547
546
  console.log('updateMPaasConfigAsync:', e)
548
547
  }
549
548
  }
550
549
  }
551
550
 
552
551
  toLogin(options) {
553
552
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
554
553
  ? this.toWxAppLogin(options)
555
554
  : this.toWebLogin(options)
556
555
  }
557
556
 
558
557
  doLogin(options) {
559
558
  return this.toLogin(options)
560
559
  }
561
560
 
562
561
  doLoginForJdPin(options = {}) {
563
562
  return this.doLogin({
564
563
  loginColor: {
565
564
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
566
565
  dpin: 0,
567
566
  },
568
567
  ...options,
569
568
  })
570
569
  }
571
570
 
572
571
  toWebLogin(options) {
573
572
  let params: {
574
573
  returnurl: string
575
574
  } = {
576
575
  returnurl: '',
577
576
  }
578
577
  const loginUrl = isPc
579
578
  ? `//passport.jd.com/new/login.aspx`
580
579
  : `${domain.mobileLogin}/user/login.action`
581
580
  const defaultParams = {
582
581
  appid: '100',
583
582
  returnurl: window.location.href,
584
583
  }
585
584
  if (isString(options)) {
586
585
  params = Object.assign({}, defaultParams, {
587
586
  returnurl: options,
588
587
  })
589
588
  } else if (isObject(options)) {
590
589
  const { loginColor, ...otherOptions } = options
591
590
  params = Object.assign({}, defaultParams, otherOptions)
592
591
  } else {
593
592
  params = defaultParams
594
593
  }
595
594
  params.returnurl = encodeURIComponent(params.returnurl)
596
595
  let getFullUrl = loginUrl + '?' + serialize(params)
597
596
  if (isPc) {
598
597
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
599
598
  }
600
599
  return Promise.resolve({
601
600
  h5ToUrl: true,
602
601
  url: getFullUrl,
603
602
  }).then(() => {
604
603
  window.location.href = getFullUrl
605
604
  })
606
605
  }
607
606
 
608
607
  toWxAppLogin(options = {}) {
609
608
  console.log('微信京购小程序中h5登录跳转', options)
610
609
  return Promise.resolve(true).then(() => {
611
610
  const { loginColor } = Object.assign(
612
611
  {},
613
612
  {
614
613
  loginColor: {
615
614
  bzi: WXAPP_BIZ_KEY,
616
615
  dpin: 1,
617
616
  },
618
617
  },
619
618
  options,
620
619
  )
621
620
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
622
621
  loginColor.bzi
623
622
  }&url=${encodeURIComponent(window.location.href)}`
624
623
  })
625
624
  }
626
625
 
627
626
  getLoginCookie() {
628
627
  return Promise.resolve({
629
628
  pin: cookie.get('pin') || '',
630
629
  })
631
630
  }
632
631
 
633
632
  clearLoginCookie() {
634
633
  cookie.remove('pin')
635
634
  }
636
635
 
637
636
  checkStatusAndLogin(options = {}) {
638
637
  if (!this.checkStatusAndLoginPromise) {
639
638
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
640
639
  try {
641
640
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
642
641
  options,
643
642
  )
644
643
  if (getLoginState) {
645
644
  resolve(true)
646
645
  } else {
647
646
  this.toLogin(options)
648
647
  reject(false)
649
648
  }
650
649
  } catch (e) {
651
650
  this.toLogin(options)
652
651
  reject(false)
653
652
  }
654
653
  })
655
654
  return this.checkStatusAndLoginPromise
656
655
  } else {
657
656
  return this.checkStatusAndLoginPromise
658
657
  .then(() => {
659
658
  return Promise.resolve(true)
660
659
  })
661
660
  .catch(() => {
662
661
  this.toLogin(options)
663
662
  return Promise.reject(true)
664
663
  })
665
664
  }
666
665
  }
667
666
 
668
667
  checkJdStatusAndLogin(
669
668
  options = {
670
669
  loginColor: {
671
670
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
672
671
  dpin: 0,
673
672
  },
674
673
  },
675
674
  ) {
676
675
  return this.checkStatusAndLogin(options)
677
676
  }
678
677
 
679
678
  doCheckLoginStateAndForApiCheck(options) {
680
679
  if (this.info.loginState) {
681
680
  return Promise.resolve(true)
682
681
  } else {
683
682
  return new Promise((resolve, reject) => {
684
683
  if (
685
684
  this.info.isJingGouMiniViewState ||
686
685
  this.info.isJingxiMiniViewState
687
686
  ) {
688
687
  const getWqAuthToken = cookie.get('wq_auth_token')
689
688
  const getWqSkey = cookie.get('wq_skey')
690
689
  const getWqUin = cookie.get('wq_uin')
691
690
  const isLoginState =
692
691
  options?.loginColor?.dpin === 0
693
692
  ? getWqAuthToken
694
693
  : getWqSkey && getWqUin
695
694
  if (isLoginState) {
696
695
  this.info.loginState = true
697
696
  resolve(true)
698
697
  } else {
699
698
  reject(false)
700
699
  }
701
700
  } else {
702
701
  Taro.request({
703
702
  url: api.isLogin,
704
703
  jsonp: true,
705
704
  timeout: 3000,
706
705
  success: res => {
707
706
  const { statusCode, data } = res
708
707
  if (
709
708
  statusCode === 200 &&
710
709
  data?.islogin &&
711
710
  Number(data.islogin) === 1
712
711
  ) {
713
712
  this.info.loginState = true
714
713
  resolve(true)
715
714
  } else {
716
715
  reject(false)
717
716
  }
718
717
  },
719
718
  fail: err => {
720
719
  console.log('登录检查异常', err)
721
720
  reject(false)
722
721
  },
723
722
  })
724
723
  }
725
724
  })
726
725
  }
727
726
  }
728
727
 
729
728
  checkLoginStatus(options) {
730
729
  return new Promise(async (resolve, reject) => {
731
730
  try {
732
731
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
733
732
  options,
734
733
  )
735
734
  if (getLoginState) {
736
735
  const { pin } = await this.getLoginCookie()
737
736
  this.info.userInfo = {
738
737
  pin,
739
738
  encodePin: encodeURIComponent(pin),
740
739
  ptkey: '',
741
740
  }
742
741
  resolve(true)
743
742
  } else {
744
743
  reject(false)
745
744
  }
746
745
  } catch (e) {
747
746
  reject(false)
748
747
  }
749
748
  })
750
749
  }
751
750
 
752
751
  updatePageAndLogInfo(updateQuery = {}) {
753
752
  const createUpdateQueryInfo: {
754
753
  query: {
755
754
  shopId?: string | number
756
755
  venderId?: string | number
757
756
  }
758
757
  updateShopInfoState: boolean
759
758
  } = Object.assign(
760
759
  {},
761
760
  {
762
761
  query: {},
763
762
  updateShopInfoState: false,
764
763
  },
765
764
  updateQuery,
766
765
  )
767
766
  console.log(
768
767
  '获取当前下发的店铺查询参数',
769
768
  updateQuery,
770
769
  '获取之前保存的shopInfo店铺查询参数',
771
770
  this.info?.shopInfo,
772
771
  )
773
772
  const { query, updateShopInfoState } = createUpdateQueryInfo
774
773
  const { shopId, venderId, un_area } = query
775
774
  if (updateShopInfoState) {
776
775
  this.info.queryInfo = {
777
776
  ...this.info.queryInfo,
778
777
  ...query,
779
778
  }
780
779
  if (shopId && venderId) {
781
780
  this.info.shopInfo = {
782
781
  shopId: `${shopId}`,
783
782
  venderId: `${venderId}`,
784
783
  }
785
784
  }
786
785
  } else {
787
786
  this.info.queryInfo = {
788
787
  ...query,
789
788
  }
790
789
  if (
791
790
  this.info.shopInfo?.shopId &&
792
791
  this.info.shopInfo?.venderId &&
793
792
  (this.info.shopInfo.shopId == shopId ||
794
793
  this.info.shopInfo.venderId == venderId)
795
794
  ) {
796
795
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
797
796
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
798
797
  console.log(
799
798
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
800
799
  this.info.queryInfo,
801
800
  )
802
801
  }
803
802
  }
804
803
  this.info.queryInfo['shopId'] &&
805
804
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
806
805
  this.info.queryInfo['venderId'] &&
807
806
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
808
807
  console.log(
809
808
  'h5==获取店铺下发查询参数\n',
810
809
  query,
811
810
  '\n获取店铺最后查询参数\n',
812
811
  this.info.queryInfo,
813
812
  '\n是否为更新店铺状态\n',
814
813
  updateShopInfoState,
815
814
  )
816
815
  const changeArea =
817
816
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
818
817
  if (changeArea) {
819
818
  this.info.pageInfo.address = changeArea
820
819
  this.info.pageInfo.un_area = changeArea
821
820
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
822
821
  }
823
822
  }
823
+ import Taro from '@tarojs/taro'
824
824
  isJdApp,
825
825
  isIosDevice,
826
826
  isAndroidDevice,
827
827
  isJdAndHarmonyDevice,
828
828
  isJdAndAndroidDevice,
829
829
  jdAppVersion,
830
830
  jdAppVersionStr,
831
831
  isString,
832
832
  isObject,
833
833
  serialize,
834
834
  dealNativePixelToCssPixel,
835
835
  isPc,
836
836
  BUSINESS_TYPE,
837
837
  JSSDK_APP_WEBVIEW_CODE,
838
838
  SECTION_HOME_TAB_NAME_TYPE,
839
839
  SECTION_HOME_TAB_TYPE,
840
840
  WXAPP_BIZ_KEY,
841
841
  WX_BUSINESS_TYPE,
842
842
  MPAAS_CONFIG_APP_VERSION,
843
843
  MPAAS_CONFIG_APP_LOW_VERSION,
844
844
  WXAPP_BIZ_SHOP_LIGHT_KEY,
845
845
  loginState: false,
846
846
  cookiesStr: '',
847
847
  userInfo: userPinKey,
848
848
  isJingGouMiniViewState: false,
849
849
  isJingxiMiniViewState: false,
850
850
  pageInfo: {
851
851
  wxBusinessType: WX_BUSINESS_TYPE.NO,
852
852
  address: '',
853
853
  addressCommaStr: '',
854
854
  un_area: '',
855
855
  vapptype: '1',
856
856
  pageType: 'home',
857
857
  isExposureState: false,
858
858
  moduleId: '',
859
859
  entrance: '',
860
860
  dataType: BUSINESS_TYPE.ONLINE,
861
861
  floorExposureInfo: {},
862
862
  floorVideInfo: {},
863
863
  productVideInfo: {},
864
864
  tabsLoadAllDataInfo: {
865
865
  [SECTION_HOME_TAB_NAME_TYPE[
866
866
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
867
867
  ]]: false,
868
868
  },
869
869
  updateShopInfosAllState: false,
870
870
  isVipShop: false,
871
871
  isJdShowNativeImmersivePlayer: false,
872
872
  ...shopConfig,
873
873
  pageScrollTop: 0,
874
874
  pageIdxHeightInfo: {
875
875
  list: [],
876
876
  },
877
877
  shopNavBarHeight: 0,
878
878
  },
879
879
  defaultQueryLogInfo: {
880
880
  sourceType: 'JDshop',
881
881
  sourceValue: '',
882
882
  moduleId: 'none',
883
883
  entrance: 'none',
884
884
  },
885
885
  sysInfo: {
886
886
  windowWidth: isPc ? 375 : 0,
887
887
  containerWidth: isPc ? 375 : 0,
888
888
  windowHeight: 0,
889
889
  netWorkType: '4g',
890
890
  jdBottomBarHeight: 0,
891
891
  jdNativeHeaderHeight: 0,
892
892
  },
893
893
  queryInfo: {},
894
894
  shopInfo: {},
895
895
  openAppData: {},
896
896
  public info: CommonInterFace.BaseConfigInfo
897
897
  public config: {
898
898
  [key: string]: any
899
899
  }
900
900
  public lazyContainer: CommonInterFace.lazyContainer
901
901
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
902
902
  public rootEleNode: HTMLElement | null
903
903
  public checkStatusAndLoginPromise: object | null
904
904
  private jmfeRegisterStatePromise: Promise<any> | null
905
905
  private jmfeRegisterState: boolean
906
906
  constructor(opt) {
907
907
  this.info = this._getConfig(opt)
908
908
  this.config = {}
909
909
  this.lazyContainer = {
910
910
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
911
911
  appLazyContainerList: [],
912
912
  appLazyFinishContainerList: [],
913
913
  },
914
914
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
915
915
  appLazyContainerList: [],
916
916
  appLazyFinishContainerList: [],
917
917
  },
918
918
  }
919
919
  this.renderedIsvComponents = {}
920
920
  this.rootEleNode = document.querySelector('body')
921
921
  this.checkStatusAndLoginPromise = null
922
922
  this.jmfeRegisterStatePromise = null
923
923
  isJdApp && this.jmfeReayPromise()
924
924
  }
925
925
  _getConfig(opt) {
926
926
  return Object.assign({}, DefaultConfig, opt)
927
927
  }
928
928
 
929
929
  jmfeReayPromise(): Promise<any> {
930
930
  if (isJdApp) {
931
931
  if (this.jmfeRegisterState) {
932
932
  return Promise.resolve(true)
933
933
  } else {
934
934
  !this.jmfeRegisterStatePromise &&
935
935
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
936
936
  ready('jmfe', 3000)
937
937
  .then(() => {
938
938
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
939
939
  this.jmfeRegisterState = true
940
940
  resolve(true)
941
941
  console.log('松果app内初始化注册jmfe认证完成')
942
942
  })
943
943
  .catch(() => {
944
944
  reject(false)
945
945
  })
946
946
  }))
947
947
  return this.jmfeRegisterStatePromise
948
948
  }
949
949
  } else {
950
950
  return Promise.reject(false)
951
951
  }
952
952
  }
953
953
 
954
954
  updateBusinessDomainAndApi(domain, api) {
955
955
  }
956
956
 
957
957
  formatNativeScreenPageData(action) {
958
958
  let getChangePageInfo: any = null
959
959
  try {
960
960
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
961
961
  JSON.stringify({
962
962
  plugin: 'JDHybridScreenPlugin',
963
963
  action,
964
964
  sync: '1',
965
965
  }),
966
966
  )
967
967
  const getChangePageInfoData =
968
968
  typeof getNativeScreenPageInfoStr === 'string'
969
969
  ? JSON.parse(getNativeScreenPageInfoStr)
970
970
  : null
971
971
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
972
972
  const { code, data } = getChangePageInfoData
973
973
  getChangePageInfo = code && code === '0' ? data : null
974
974
  }
975
975
  } catch (e) {
976
976
  console.log('JDHybridScreenPlugin转换异常', e)
977
977
  }
978
978
  return getChangePageInfo
979
979
  }
980
980
 
981
981
  isAndroidFoldScreen() {
982
982
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
983
983
  }
984
984
 
985
985
  getJdAndroidPageChangeScreenInfo() {
986
986
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
987
987
  if (
988
988
  getPageScreenInfo &&
989
989
  getPageScreenInfo?.pageWidth &&
990
990
  getPageScreenInfo?.pageHeight
991
991
  ) {
992
992
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
993
993
  pageWidth: getPageScreenInfo.pageWidth,
994
994
  pageHeight: getPageScreenInfo.pageHeight,
995
995
  })
996
996
  getPageScreenInfo.pageWidth = pageWidth
997
997
  getPageScreenInfo.pageHeight = pageHeight
998
998
  }
999
999
  return getPageScreenInfo
1000
1000
  }
1001
1001
 
1002
1002
  getSystemInfo(params) {
1003
1003
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
1004
1004
  ? {}
1005
1005
  : getSystemInfos(params)
1006
1006
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
1007
1007
  const isfoldScreen = this.isAndroidFoldScreen()
1008
1008
  if (isfoldScreen) {
1009
1009
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
1010
1010
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
1011
1011
  console.info(
1012
1012
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
1013
1013
  getJdAndroidPageInfo,
1014
1014
  )
1015
1015
  }
1016
1016
  }
1017
1017
  this.info.sysInfo = {
1018
1018
  actualNavBarHeight: 0,
1019
1019
  ...this.info.sysInfo,
1020
1020
  ...info,
1021
1021
  safeContentHeight: info?.screenHeight,
1022
1022
  headerHeight: 0,
1023
1023
  tabBarHeight: 0,
1024
1024
  }
1025
1025
  if (isJdApp) {
1026
1026
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
1027
1027
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
1028
1028
  this.getAddressCachePromise()
1029
1029
  this.getElderModePromise()
1030
1030
  this.getJDAppearanceStatePromise()
1031
1031
  this.createJdAndroidRquestEventForTouchStart()
1032
1032
  }
1033
1033
  this.getWifiVideoAutoPlayAsync()
1034
1034
  this.getMPaasConfigAsync()
1035
1035
  this.getNetWorkType()
1036
1036
  }
1037
1037
 
1038
1038
  taskTimeoutPromise(callBack, timeout = 2000) {
1039
1039
  return new Promise(resolve => {
1040
1040
  setTimeout(() => {
1041
1041
  const getCallBackRes = typeof callBack === 'function' && callBack()
1042
1042
  return resolve(getCallBackRes || false)
1043
1043
  }, timeout)
1044
1044
  })
1045
1045
  }
1046
1046
 
1047
1047
  getElderModePromise() {
1048
1048
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1049
1049
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1050
1050
  } else {
1051
1051
  if (isJdAndAndroidDevice) {
1052
1052
  this.info.sysInfo.jdAppModeType = '0'
1053
1053
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1054
1054
  } else {
1055
1055
  return Promise.race([
1056
1056
  this.taskTimeoutPromise(() => {
1057
1057
  this.info.sysInfo.jdAppModeType = '0'
1058
1058
  return this.info.sysInfo.jdAppModeType
1059
1059
  }),
1060
1060
  new Promise(resolve => {
1061
1061
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
1062
1062
  if (!window[getCallBackName]) {
1063
1063
  window[getCallBackName] = res => {
1064
1064
  try {
1065
1065
  const getResJson =
1066
1066
  typeof res === 'string' ? JSON.parse(res) : res
1067
1067
  const { status, data, msg } = getResJson
1068
1068
  console.log(`获取松果app展示模式成功,返回结果${data}`)
1069
1069
  if (status === '0') {
1070
1070
  this.info.sysInfo.jdAppModeType = data
1071
1071
  resolve(data)
1072
1072
  } else {
1073
1073
  resolve('0')
1074
1074
  }
1075
1075
  } catch (e) {
1076
1076
  resolve('0')
1077
1077
  }
1078
1078
  window[getCallBackName] = null
1079
1079
  }
1080
1080
  }
1081
1081
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1082
1082
  method: 'callSyncRouterModuleWithParams',
1083
1083
  params: JSON.stringify({
1084
1084
  routerURL: 'router://JDBModeModule/getCurrentMode',
1085
1085
  routerParam: {},
1086
1086
  callBackName: `window.${getCallBackName}`,
1087
1087
  callBackId: `${getCallBackName}Ios`,
1088
1088
  }),
1089
1089
  })
1090
1090
  }),
1091
1091
  ])
1092
1092
  }
1093
1093
  }
1094
1094
  }
1095
1095
 
1096
1096
  getJDAppearanceStatePromise() {
1097
1097
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1098
1098
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
1099
1099
  } else {
1100
1100
  return Promise.race([
1101
1101
  this.taskTimeoutPromise(() => {
1102
1102
  this.info.sysInfo.jdAppearanceState = '0'
1103
1103
  return this.info.sysInfo.jdAppearanceState
1104
1104
  }),
1105
1105
  new Promise(resolve => {
1106
1106
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
1107
1107
  if (!window[getCallBackName]) {
1108
1108
  window[getCallBackName] = res => {
1109
1109
  try {
1110
1110
  console.log('getJDAppearanceStatePromise', res)
1111
1111
  const getResJson =
1112
1112
  typeof res === 'string' ? JSON.parse(res) : res
1113
1113
  const { status, data, msg } = getResJson
1114
1114
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
1115
1115
  if (status === '0') {
1116
1116
  this.info.sysInfo.jdAppearanceState = data
1117
1117
  resolve(data)
1118
1118
  } else {
1119
1119
  resolve('0')
1120
1120
  }
1121
1121
  } catch (e) {
1122
1122
  resolve('0')
1123
1123
  }
1124
1124
  window[getCallBackName] = null
1125
1125
  }
1126
1126
  }
1127
1127
  if (isAndroidDevice) {
1128
1128
  const jsonString = JSON.stringify({
1129
1129
  callBackName: `window.${getCallBackName}`,
1130
1130
  })
1131
1131
  console.log('window.JDAppearance', window.JDAppearance)
1132
1132
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
1133
1133
  } else {
1134
1134
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1135
1135
  method: 'callSyncRouterModuleWithParams',
1136
1136
  params: JSON.stringify({
1137
1137
  routerURL:
1138
1138
  'router://JDWebViewBusinessModule/getJDAppearanceState',
1139
1139
  routerParam: {},
1140
1140
  callBackName: `window.${getCallBackName}`,
1141
1141
  callBackId: `${getCallBackName}Ios`,
1142
1142
  }),
1143
1143
  })
1144
1144
  }
1145
1145
  }),
1146
1146
  ])
1147
1147
  }
1148
1148
  }
1149
1149
 
1150
1150
  createJdAndroidRquestEventForTouchStart() {
1151
1151
  if (isJdAndAndroidDevice && window.JdAndroid) {
1152
1152
  const rootEleNode = document.querySelector('body')
1153
1153
  if (rootEleNode) {
1154
1154
  rootEleNode.addEventListener(
1155
1155
  'touchstart',
1156
1156
  this.jdAndroidAddEventListenerTouchStart,
1157
1157
  false,
1158
1158
  )
1159
1159
  }
1160
1160
  }
1161
1161
  }
1162
1162
  jdAndroidAddEventListenerTouchStart(e) {
1163
1163
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
1164
1164
  if (!isH5SwiperCustomEle) {
1165
1165
  const hasCustomEle = e
1166
1166
  ? e?.target?.closest('.J_customScroll') ||
1167
1167
  e?.target?.closest('.J_customLayout')
1168
1168
  : false
1169
1169
  if (!hasCustomEle) {
1170
1170
  window.JdAndroid.requestEvent(false)
1171
1171
  console.log(
1172
1172
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1173
1173
  )
1174
1174
  }
1175
1175
  }
1176
1176
  }
1177
1177
  removeJdAndroidRquestEventForTouchStart() {
1178
1178
  if (isJdAndAndroidDevice && window.JdAndroid) {
1179
1179
  const rootEleNode = document.querySelector('body')
1180
1180
  if (rootEleNode) {
1181
1181
  rootEleNode.removeEventListener(
1182
1182
  'touchstart',
1183
1183
  this.jdAndroidAddEventListenerTouchStart,
1184
1184
  false,
1185
1185
  )
1186
1186
  }
1187
1187
  }
1188
1188
  }
1189
1189
 
1190
1190
  getNetWorkType() {
1191
1191
  if (isJdApp) {
1192
1192
  this.jmfeReayPromise().then(() => {
1193
1193
  window.jmfe
1194
1194
  .getNetworkStatus()
1195
1195
  .then(({ status, data }) => {
1196
1196
  console.log(
1197
1197
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
1198
1198
  data,
1199
1199
  )
1200
1200
  if (status === '0') {
1201
1201
  this.info.sysInfo['netWorkType'] = data
1202
1202
  } else {
1203
1203
  this._taroGetNetworkType()
1204
1204
  }
1205
1205
  })
1206
1206
  .catch(err => {
1207
1207
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
1208
1208
  this._taroGetNetworkType()
1209
1209
  })
1210
1210
  })
1211
1211
  } else {
1212
1212
  this._taroGetNetworkType()
1213
1213
  }
1214
1214
  }
1215
1215
  _taroGetNetworkType() {
1216
1216
  Taro.getNetworkType().then(getRes => {
1217
1217
  if (getRes && getRes.networkType) {
1218
1218
  this.info.sysInfo['netWorkType'] = getRes.networkType
1219
1219
  console.log(
1220
1220
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1221
1221
  this.info.sysInfo['netWorkType'],
1222
1222
  )
1223
1223
  }
1224
1224
  })
1225
1225
  }
1226
1226
  getCacheAddressRouter() {
1227
1227
  if (!window.jmfe) return
1228
1228
  if (isAndroidDevice) {
1229
1229
  return window.jmfe.callRouter({
1230
1230
  jdRouter: '1',
1231
1231
  routerURL: 'router://JDAddressModule/getCacheAddress',
1232
1232
  routerParam: { sceneId: 'basicShoppingProcess' },
1233
1233
  })
1234
1234
  } else if (isIosDevice) {
1235
1235
  return window.jmfe.callRouter({
1236
1236
  jdRouter: '1',
1237
1237
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1238
1238
  routerParam: { sceneId: 'basicShoppingProcess' },
1239
1239
  })
1240
1240
  } else if (isJdAndHarmonyDevice) {
1241
1241
  return new Promise(resolve => {
1242
1242
  resolve({})
1243
1243
  })
1244
1244
  } else {
1245
1245
  throw Error(
1246
1246
  'Unknown device type cannot obtain the address information through the route!',
1247
1247
  )
1248
1248
  }
1249
1249
  }
1250
1250
 
1251
1251
  getAddressCachePromise() {
1252
1252
  return new Promise(resolve => {
1253
1253
  if (
1254
1254
  this?.info?.sysInfo?.lat &&
1255
1255
  this?.info?.sysInfo?.lng &&
1256
1256
  this?.info?.sysInfo?.area
1257
1257
  ) {
1258
1258
  resolve({
1259
1259
  lat: this.info.sysInfo.lat,
1260
1260
  lng: this.info.sysInfo.lng,
1261
1261
  area: this?.info?.sysInfo?.area,
1262
1262
  })
1263
1263
  } else {
1264
1264
  this.jmfeReayPromise().then(() => {
1265
1265
  this.getCacheAddressRouter()
1266
1266
  .then(({ status, data }) => {
1267
1267
  if (status === '0' && data) {
1268
1268
  const {
1269
1269
  lat,
1270
1270
  latitude,
1271
1271
  lng,
1272
1272
  longitude,
1273
1273
  provinceId,
1274
1274
  cityId,
1275
1275
  countyId,
1276
1276
  townId,
1277
1277
  } = data || {}
1278
1278
  let area = ''
1279
1279
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
1280
1280
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
1281
1281
  if (provinceId) {
1282
1282
  area = `${provinceId}_${cityId || 0}_${countyId ||
1283
1283
  0}_${townId || 0}`
1284
1284
  this.info.pageInfo['address'] = area
1285
1285
  this.info.pageInfo['addressCommaStr'] = area.replace(
1286
1286
  /_/g,
1287
1287
  ',',
1288
1288
  )
1289
1289
  }
1290
1290
  resolve({
1291
1291
  lat: this.info.sysInfo['lat'],
1292
1292
  lng: this.info.sysInfo['lng'],
1293
1293
  area: area,
1294
1294
  })
1295
1295
  } else {
1296
1296
  resolve({ lat: '', lng: '', area: '' })
1297
1297
  }
1298
1298
  })
1299
1299
  .catch(e => {
1300
1300
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
1301
1301
  resolve({ lat: '', lng: '', area: '' })
1302
1302
  console.log('判断jmfe不存在,获取经纬度信息异常')
1303
1303
  })
1304
1304
  })
1305
1305
  }
1306
1306
  })
1307
1307
  }
1308
1308
 
1309
1309
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1310
1310
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
1311
1311
  if (!isJdApp) {
1312
1312
  return
1313
1313
  }
1314
1314
  const avifSwitch = await getMPaasConfigByBussinessKey(
1315
1315
  'avifSwitch',
1316
1316
  isBeforePageReady,
1317
1317
  )
1318
1318
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
1319
1319
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1320
1320
  'isFollowAppVideoPlayStatus',
1321
1321
  isBeforePageReady,
1322
1322
  )
1323
1323
  console.log(
1324
1324
  'isBeforePageReady:',
1325
1325
  isBeforePageReady,
1326
1326
  'isFollowAppVideoPlayStatus:',
1327
1327
  isFollowAppVideoPlayStatus,
1328
1328
  )
1329
1329
  if (
1330
1330
  isFollowAppVideoPlayStatus === true ||
1331
1331
  isFollowAppVideoPlayStatus === 'true'
1332
1332
  ) {
1333
1333
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
1334
1334
  }
1335
1335
  }
1336
1336
 
1337
1337
  async getWifiVideoAutoPlayAsync() {
1338
1338
  this.info.sysInfo['wifiVideoAutoPlay'] = false
1339
1339
  if (!isJdApp) {
1340
1340
  return
1341
1341
  }
1342
1342
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
1343
1343
  return 0
1344
1344
  })
1345
1345
  if (Number(videoPlayStatus) === 1) {
1346
1346
  this.info.sysInfo['wifiVideoAutoPlay'] = true
1347
1347
  }
1348
1348
  }
1349
1349
 
1350
1350
  async getMPaasConfigAsync() {
1351
1351
  this.info.sysInfo.dynamicConfig = {}
1352
1352
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
1353
1353
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
1354
1354
  return this.updateMPaasConfigAsync(true)
1355
1355
  }
1356
1356
 
1357
1357
  getDynamicConfig(key: string){
1358
1358
  return this.info.sysInfo.dynamicConfig[key]
1359
1359
  }
1360
1360
  async updateMPaasConfig() {
1361
1361
  console.log('updateMPaasConfig')
1362
1362
  if (
1363
1363
  isIosDevice &&
1364
1364
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1365
1365
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1366
1366
  ) {
1367
1367
  try {
1368
1368
  await this.updateMPaasConfigAsync(false)
1369
1369
  } catch (e) {
1370
1370
  console.log('updateMPaasConfigAsync:', e)
1371
1371
  }
1372
1372
  }
1373
1373
  }
1374
1374
 
1375
1375
  toLogin(options) {
1376
1376
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1377
1377
  ? this.toWxAppLogin(options)
1378
1378
  : this.toWebLogin(options)
1379
1379
  }
1380
1380
 
1381
1381
  doLogin(options) {
1382
1382
  return this.toLogin(options)
1383
1383
  }
1384
1384
 
1385
1385
  doLoginForJdPin(options = {}) {
1386
1386
  return this.doLogin({
1387
1387
  loginColor: {
1388
1388
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1389
1389
  dpin: 0,
1390
1390
  },
1391
1391
  ...options,
1392
1392
  })
1393
1393
  }
1394
1394
 
1395
1395
  toWebLogin(options) {
1396
1396
  let params: {
1397
1397
  returnurl: string
1398
1398
  } = {
1399
1399
  returnurl: '',
1400
1400
  }
1401
1401
  const loginUrl = isPc
1402
1402
  ? `//passport.jd.com/new/login.aspx`
1403
1403
  : `${domain.mobileLogin}/user/login.action`
1404
1404
  const defaultParams = {
1405
1405
  appid: '100',
1406
1406
  returnurl: window.location.href,
1407
1407
  }
1408
1408
  if (isString(options)) {
1409
1409
  params = Object.assign({}, defaultParams, {
1410
1410
  returnurl: options,
1411
1411
  })
1412
1412
  } else if (isObject(options)) {
1413
1413
  const { loginColor, ...otherOptions } = options
1414
1414
  params = Object.assign({}, defaultParams, otherOptions)
1415
1415
  } else {
1416
1416
  params = defaultParams
1417
1417
  }
1418
1418
  params.returnurl = encodeURIComponent(params.returnurl)
1419
1419
  let getFullUrl = loginUrl + '?' + serialize(params)
1420
1420
  if (isPc) {
1421
1421
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1422
1422
  }
1423
1423
  return Promise.resolve({
1424
1424
  h5ToUrl: true,
1425
1425
  url: getFullUrl,
1426
1426
  }).then(() => {
1427
1427
  window.location.href = getFullUrl
1428
1428
  })
1429
1429
  }
1430
1430
 
1431
1431
  toWxAppLogin(options = {}) {
1432
1432
  console.log('微信京购小程序中h5登录跳转', options)
1433
1433
  return Promise.resolve(true).then(() => {
1434
1434
  const { loginColor } = Object.assign(
1435
1435
  {},
1436
1436
  {
1437
1437
  loginColor: {
1438
1438
  biz: WXAPP_BIZ_KEY,
1439
1439
  dpin: 1,
1440
1440
  },
1441
1441
  },
1442
1442
  options,
1443
1443
  )
1444
1444
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1445
1445
  loginColor.biz
1446
1446
  }&url=${encodeURIComponent(window.location.href)}`
1447
1447
  })
1448
1448
  }
1449
1449
 
1450
1450
  getLoginCookie() {
1451
1451
  return Promise.resolve({
1452
1452
  pin: cookie.get('pin') || '',
1453
1453
  })
1454
1454
  }
1455
1455
 
1456
1456
  clearLoginCookie() {
1457
1457
  cookie.remove('pin')
1458
1458
  }
1459
1459
 
1460
1460
  checkStatusAndLogin(options = {}) {
1461
1461
  if (!this.checkStatusAndLoginPromise) {
1462
1462
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1463
1463
  try {
1464
1464
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1465
1465
  options,
1466
1466
  )
1467
1467
  if (getLoginState) {
1468
1468
  resolve(true)
1469
1469
  } else {
1470
1470
  this.toLogin(options)
1471
1471
  reject(false)
1472
1472
  }
1473
1473
  } catch (e) {
1474
1474
  this.toLogin(options)
1475
1475
  reject(false)
1476
1476
  }
1477
1477
  })
1478
1478
  return this.checkStatusAndLoginPromise
1479
1479
  } else {
1480
1480
  return this.checkStatusAndLoginPromise
1481
1481
  .then(() => {
1482
1482
  return Promise.resolve(true)
1483
1483
  })
1484
1484
  .catch(() => {
1485
1485
  this.toLogin(options)
1486
1486
  return Promise.reject(true)
1487
1487
  })
1488
1488
  }
1489
1489
  }
1490
1490
 
1491
1491
  checkJdStatusAndLogin(
1492
1492
  options = {
1493
1493
  loginColor: {
1494
1494
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1495
1495
  dpin: 0,
1496
1496
  },
1497
1497
  },
1498
1498
  ) {
1499
1499
  return this.checkStatusAndLogin(options)
1500
1500
  }
1501
1501
 
1502
1502
  doCheckLoginStateAndForApiCheck(options) {
1503
1503
  if (this.info.loginState) {
1504
1504
  return Promise.resolve(true)
1505
1505
  } else {
1506
1506
  return new Promise((resolve, reject) => {
1507
1507
  if (
1508
1508
  this.info.isJingGouMiniViewState ||
1509
1509
  this.info.isJingxiMiniViewState
1510
1510
  ) {
1511
1511
  const getWqAuthToken = cookie.get('wq_auth_token')
1512
1512
  const getWqSkey = cookie.get('wq_skey')
1513
1513
  const getWqUin = cookie.get('wq_uin')
1514
1514
  const isLoginState =
1515
1515
  options?.loginColor?.dpin === 0
1516
1516
  ? getWqAuthToken
1517
1517
  : getWqSkey && getWqUin
1518
1518
  if (isLoginState) {
1519
1519
  this.info.loginState = true
1520
1520
  resolve(true)
1521
1521
  } else {
1522
1522
  reject(false)
1523
1523
  }
1524
1524
  } else {
1525
1525
  Taro.request({
1526
1526
  url: api.isLogin,
1527
1527
  jsonp: true,
1528
1528
  timeout: 3000,
1529
1529
  success: res => {
1530
1530
  const { statusCode, data } = res
1531
1531
  if (
1532
1532
  statusCode === 200 &&
1533
1533
  data?.islogin &&
1534
1534
  Number(data.islogin) === 1
1535
1535
  ) {
1536
1536
  this.info.loginState = true
1537
1537
  resolve(true)
1538
1538
  } else {
1539
1539
  reject(false)
1540
1540
  }
1541
1541
  },
1542
1542
  fail: err => {
1543
1543
  console.log('登录检查异常', err)
1544
1544
  reject(false)
1545
1545
  },
1546
1546
  })
1547
1547
  }
1548
1548
  })
1549
1549
  }
1550
1550
  }
1551
1551
 
1552
1552
  checkLoginStatus(options) {
1553
1553
  return new Promise(async (resolve, reject) => {
1554
1554
  try {
1555
1555
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1556
1556
  options,
1557
1557
  )
1558
1558
  if (getLoginState) {
1559
1559
  const { pin } = await this.getLoginCookie()
1560
1560
  this.info.userInfo = {
1561
1561
  pin,
1562
1562
  encodePin: encodeURIComponent(pin),
1563
1563
  ptkey: '',
1564
1564
  }
1565
1565
  resolve(true)
1566
1566
  } else {
1567
1567
  reject(false)
1568
1568
  }
1569
1569
  } catch (e) {
1570
1570
  reject(false)
1571
1571
  }
1572
1572
  })
1573
1573
  }
1574
1574
 
1575
1575
  updatePageAndLogInfo(updateQuery = {}) {
1576
1576
  const createUpdateQueryInfo: {
1577
1577
  query: {
1578
1578
  shopId?: string | number
1579
1579
  venderId?: string | number
1580
1580
  }
1581
1581
  updateShopInfoState: boolean
1582
1582
  } = Object.assign(
1583
1583
  {},
1584
1584
  {
1585
1585
  query: {},
1586
1586
  updateShopInfoState: false,
1587
1587
  },
1588
1588
  updateQuery,
1589
1589
  )
1590
1590
  console.log(
1591
1591
  '获取当前下发的店铺查询参数',
1592
1592
  updateQuery,
1593
1593
  '获取之前保存的shopInfo店铺查询参数',
1594
1594
  this.info?.shopInfo,
1595
1595
  )
1596
1596
  const { query, updateShopInfoState } = createUpdateQueryInfo
1597
1597
  const { shopId, venderId, un_area } = query
1598
1598
  if (updateShopInfoState) {
1599
1599
  this.info.queryInfo = {
1600
1600
  ...this.info.queryInfo,
1601
1601
  ...query,
1602
1602
  }
1603
1603
  if (shopId && venderId) {
1604
1604
  this.info.shopInfo = {
1605
1605
  shopId: `${shopId}`,
1606
1606
  venderId: `${venderId}`,
1607
1607
  }
1608
1608
  }
1609
1609
  } else {
1610
1610
  this.info.queryInfo = {
1611
1611
  ...query,
1612
1612
  }
1613
1613
  if (
1614
1614
  this.info.shopInfo?.shopId &&
1615
1615
  this.info.shopInfo?.venderId &&
1616
1616
  (this.info.shopInfo.shopId == shopId ||
1617
1617
  this.info.shopInfo.venderId == venderId)
1618
1618
  ) {
1619
1619
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1620
1620
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1621
1621
  console.log(
1622
1622
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1623
1623
  this.info.queryInfo,
1624
1624
  )
1625
1625
  }
1626
1626
  }
1627
1627
  this.info.queryInfo['shopId'] &&
1628
1628
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1629
1629
  this.info.queryInfo['venderId'] &&
1630
1630
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1631
1631
  console.log(
1632
1632
  'h5==获取店铺下发查询参数\n',
1633
1633
  query,
1634
1634
  '\n获取店铺最后查询参数\n',
1635
1635
  this.info.queryInfo,
1636
1636
  '\n是否为更新店铺状态\n',
1637
1637
  updateShopInfoState,
1638
1638
  )
1639
1639
  const changeArea =
1640
1640
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1641
1641
  if (changeArea) {
1642
1642
  this.info.pageInfo.address = changeArea
1643
1643
  this.info.pageInfo.un_area = changeArea
1644
1644
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1645
1645
  }
1646
1646
  }