@conecli/cone-render 0.10.1-beta.3 → 0.10.1-isv2.1

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.
@@ -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_VERSION,
21
20
  MPAAS_CONFIG_APP_LOW_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[
44
43
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
45
44
  ]]: false,
46
45
  },
47
46
  updateShopInfosAllState: false,
48
47
  isVipShop: false,
49
48
  isJdShowNativeImmersivePlayer: false,
50
49
  ...shopConfig,
51
50
  pageScrollTop: 0,
52
51
  pageIdxHeightInfo: {
53
52
  list: [],
54
53
  },
55
54
  shopNavBarHeight: 0,
56
55
  },
57
56
  defaultQueryLogInfo: {
58
57
  sourceType: 'JDshop',
59
58
  sourceValue: '',
60
59
  moduleId: 'none',
61
60
  entrance: 'none',
62
61
  },
63
62
  sysInfo: {
64
63
  windowWidth: isPc ? 375 : 0,
65
64
  containerWidth: isPc ? 375 : 0,
66
65
  windowHeight: 0,
67
66
  netWorkType: '4g',
68
67
  jdBottomBarHeight: 0,
69
68
  jdNativeHeaderHeight: 0,
70
69
  },
71
70
  queryInfo: {},
72
71
  shopInfo: {},
73
72
  openAppData: {},
74
73
  public info: CommonInterFace.BaseConfigInfo
75
74
  public config: {
76
75
  [key: string]: any
77
76
  }
78
77
  public lazyContainer: CommonInterFace.lazyContainer
79
78
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
80
79
  public rootEleNode: HTMLElement | null
81
80
  public checkStatusAndLoginPromise: object | null
82
81
  private jmfeRegisterStatePromise: Promise<any> | null
83
82
  private jmfeRegisterState: boolean
84
83
  constructor(opt) {
85
84
  this.info = this._getConfig(opt)
86
85
  this.config = {}
87
86
  this.lazyContainer = {
88
87
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
89
88
  appLazyContainerList: [],
90
89
  appLazyFinishContainerList: [],
91
90
  },
92
91
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
93
92
  appLazyContainerList: [],
94
93
  appLazyFinishContainerList: [],
95
94
  },
96
95
  }
97
96
  this.renderedIsvComponents = {}
98
97
  this.rootEleNode = document.querySelector('body')
99
98
  this.checkStatusAndLoginPromise = null
100
99
  this.jmfeRegisterStatePromise = null
101
100
  isJdApp && this.jmfeReayPromise()
102
101
  }
103
102
  _getConfig(opt) {
104
103
  return Object.assign({}, DefaultConfig, opt)
105
104
  }
106
105
 
107
106
  jmfeReayPromise(): Promise<any> {
108
107
  if (isJdApp) {
109
108
  if (this.jmfeRegisterState) {
110
109
  return Promise.resolve(true)
111
110
  } else {
112
111
  !this.jmfeRegisterStatePromise &&
113
112
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
114
113
  ready('jmfe', 3000)
115
114
  .then(() => {
116
115
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
117
116
  this.jmfeRegisterState = true
118
117
  resolve(true)
119
118
  console.log('松果app内初始化注册jmfe认证完成')
120
119
  })
121
120
  .catch(() => {
122
121
  reject(false)
123
122
  })
124
123
  }))
125
124
  return this.jmfeRegisterStatePromise
126
125
  }
127
126
  } else {
128
127
  return Promise.reject(false)
129
128
  }
130
129
  }
131
130
 
132
131
  updateBusinessDomainAndApi(domain, api) {
133
132
  }
134
133
 
135
134
  formatNativeScreenPageData(action) {
136
135
  let getChangePageInfo: any = null
137
136
  try {
138
137
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
139
138
  JSON.stringify({
140
139
  plugin: 'JDHybridScreenPlugin',
141
140
  action,
142
141
  sync: '1',
143
142
  }),
144
143
  )
145
144
  const getChangePageInfoData =
146
145
  typeof getNativeScreenPageInfoStr === 'string'
147
146
  ? JSON.parse(getNativeScreenPageInfoStr)
148
147
  : null
149
148
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
150
149
  const { code, data } = getChangePageInfoData
151
150
  getChangePageInfo = code && code === '0' ? data : null
152
151
  }
153
152
  } catch (e) {
154
153
  console.log('JDHybridScreenPlugin转换异常', e)
155
154
  }
156
155
  return getChangePageInfo
157
156
  }
158
157
 
159
158
  isAndroidFoldScreen() {
160
159
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
161
160
  }
162
161
 
163
162
  getJdAndroidPageChangeScreenInfo() {
164
163
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
165
164
  if (
166
165
  getPageScreenInfo &&
167
166
  getPageScreenInfo?.pageWidth &&
168
167
  getPageScreenInfo?.pageHeight
169
168
  ) {
170
169
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
171
170
  pageWidth: getPageScreenInfo.pageWidth,
172
171
  pageHeight: getPageScreenInfo.pageHeight,
173
172
  })
174
173
  getPageScreenInfo.pageWidth = pageWidth
175
174
  getPageScreenInfo.pageHeight = pageHeight
176
175
  }
177
176
  return getPageScreenInfo
178
177
  }
179
178
 
180
179
  getSystemInfo(params) {
181
180
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
182
181
  ? {}
183
182
  : getSystemInfos(params)
184
183
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
185
184
  const isfoldScreen = this.isAndroidFoldScreen()
186
185
  if (isfoldScreen) {
187
186
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
188
187
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
189
188
  console.info(
190
189
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
191
190
  getJdAndroidPageInfo,
192
191
  )
193
192
  }
194
193
  }
195
194
  this.info.sysInfo = {
196
195
  actualNavBarHeight: 0,
197
196
  ...this.info.sysInfo,
198
197
  ...info,
199
198
  safeContentHeight: info?.screenHeight,
200
199
  headerHeight: 0,
201
200
  tabBarHeight: 0,
202
201
  }
203
202
  if (isJdApp) {
204
203
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
205
204
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
206
205
  this.getAddressCachePromise()
207
206
  this.getElderModePromise()
208
207
  this.getJDAppearanceStatePromise()
209
208
  this.createJdAndroidRquestEventForTouchStart()
210
209
  }
211
210
  this.getWifiVideoAutoPlayAsync()
212
211
  this.getMPaasConfigAsync()
213
212
  this.getNetWorkType()
214
213
  }
215
214
 
216
215
  taskTimeoutPromise(callBack, timeout = 2000) {
217
216
  return new Promise(resolve => {
218
217
  setTimeout(() => {
219
218
  const getCallBackRes = typeof callBack === 'function' && callBack()
220
219
  return resolve(getCallBackRes || false)
221
220
  }, timeout)
222
221
  })
223
222
  }
224
223
 
225
224
  getElderModePromise() {
226
225
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
227
226
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
228
227
  } else {
229
228
  if (isJdAndAndroidDevice) {
230
229
  this.info.sysInfo.jdAppModeType = '0'
231
230
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
232
231
  } else {
233
232
  return Promise.race([
234
233
  this.taskTimeoutPromise(() => {
235
234
  this.info.sysInfo.jdAppModeType = '0'
236
235
  return this.info.sysInfo.jdAppModeType
237
236
  }),
238
237
  new Promise(resolve => {
239
238
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
240
239
  if (!window[getCallBackName]) {
241
240
  window[getCallBackName] = res => {
242
241
  try {
243
242
  const getResJson =
244
243
  typeof res === 'string' ? JSON.parse(res) : res
245
244
  const { status, data, msg } = getResJson
246
245
  console.log(`获取松果app展示模式成功,返回结果${data}`)
247
246
  if (status === '0') {
248
247
  this.info.sysInfo.jdAppModeType = data
249
248
  resolve(data)
250
249
  } else {
251
250
  resolve('0')
252
251
  }
253
252
  } catch (e) {
254
253
  resolve('0')
255
254
  }
256
255
  window[getCallBackName] = null
257
256
  }
258
257
  }
259
258
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
260
259
  method: 'callSyncRouterModuleWithParams',
261
260
  params: JSON.stringify({
262
261
  routerURL: 'router://JDBModeModule/getCurrentMode',
263
262
  routerParam: {},
264
263
  callBackName: `window.${getCallBackName}`,
265
264
  callBackId: `${getCallBackName}Ios`,
266
265
  }),
267
266
  })
268
267
  }),
269
268
  ])
270
269
  }
271
270
  }
272
271
  }
273
272
 
274
273
  getJDAppearanceStatePromise() {
275
274
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
276
275
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
277
276
  } else {
278
277
  return Promise.race([
279
278
  this.taskTimeoutPromise(() => {
280
279
  this.info.sysInfo.jdAppearanceState = '0'
281
280
  return this.info.sysInfo.jdAppearanceState
282
281
  }),
283
282
  new Promise(resolve => {
284
283
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
285
284
  if (!window[getCallBackName]) {
286
285
  window[getCallBackName] = res => {
287
286
  try {
288
287
  console.log('getJDAppearanceStatePromise', res)
289
288
  const getResJson =
290
289
  typeof res === 'string' ? JSON.parse(res) : res
291
290
  const { status, data, msg } = getResJson
292
291
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
293
292
  if (status === '0') {
294
293
  this.info.sysInfo.jdAppearanceState = data
295
294
  resolve(data)
296
295
  } else {
297
296
  resolve('0')
298
297
  }
299
298
  } catch (e) {
300
299
  resolve('0')
301
300
  }
302
301
  window[getCallBackName] = null
303
302
  }
304
303
  }
305
304
  if (isAndroidDevice) {
306
305
  const jsonString = JSON.stringify({
307
306
  callBackName: `window.${getCallBackName}`,
308
307
  })
309
308
  console.log('window.JDAppearance', window.JDAppearance)
310
309
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
311
310
  } else {
312
311
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
313
312
  method: 'callSyncRouterModuleWithParams',
314
313
  params: JSON.stringify({
315
314
  routerURL:
316
315
  'router://JDWebViewBusinessModule/getJDAppearanceState',
317
316
  routerParam: {},
318
317
  callBackName: `window.${getCallBackName}`,
319
318
  callBackId: `${getCallBackName}Ios`,
320
319
  }),
321
320
  })
322
321
  }
323
322
  }),
324
323
  ])
325
324
  }
326
325
  }
327
326
 
328
327
  createJdAndroidRquestEventForTouchStart() {
329
328
  if (isJdAndAndroidDevice && window.JdAndroid) {
330
329
  const rootEleNode = document.querySelector('body')
331
330
  if (rootEleNode) {
332
331
  rootEleNode.addEventListener(
333
332
  'touchstart',
334
333
  this.jdAndroidAddEventListenerTouchStart,
335
334
  false,
336
335
  )
337
336
  }
338
337
  }
339
338
  }
340
339
  jdAndroidAddEventListenerTouchStart(e) {
341
340
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
342
341
  if (!isH5SwiperCustomEle) {
343
342
  const hasCustomEle = e
344
343
  ? e?.target?.closest('.J_customScroll') ||
345
344
  e?.target?.closest('.J_customLayout')
346
345
  : false
347
346
  if (!hasCustomEle) {
348
347
  window.JdAndroid.requestEvent(false)
349
348
  console.log(
350
349
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
351
350
  )
352
351
  }
353
352
  }
354
353
  }
355
354
  removeJdAndroidRquestEventForTouchStart() {
356
355
  if (isJdAndAndroidDevice && window.JdAndroid) {
357
356
  const rootEleNode = document.querySelector('body')
358
357
  if (rootEleNode) {
359
358
  rootEleNode.removeEventListener(
360
359
  'touchstart',
361
360
  this.jdAndroidAddEventListenerTouchStart,
362
361
  false,
363
362
  )
364
363
  }
365
364
  }
366
365
  }
367
366
 
368
367
  getNetWorkType() {
369
368
  if (isJdApp) {
370
369
  this.jmfeReayPromise().then(() => {
371
370
  window.jmfe
372
371
  .getNetworkStatus()
373
372
  .then(({ status, data }) => {
374
373
  console.log(
375
374
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
376
375
  data,
377
376
  )
378
377
  if (status === '0') {
379
378
  this.info.sysInfo['netWorkType'] = data
380
379
  } else {
381
380
  this._taroGetNetworkType()
382
381
  }
383
382
  })
384
383
  .catch(err => {
385
384
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
386
385
  this._taroGetNetworkType()
387
386
  })
388
387
  })
389
388
  } else {
390
389
  this._taroGetNetworkType()
391
390
  }
392
391
  }
393
392
  _taroGetNetworkType() {
394
393
  Taro.getNetworkType().then(getRes => {
395
394
  if (getRes && getRes.networkType) {
396
395
  this.info.sysInfo['netWorkType'] = getRes.networkType
397
396
  console.log(
398
397
  '在app内通过taro对象获取网络状态完成,当前网络状态',
399
398
  this.info.sysInfo['netWorkType'],
400
399
  )
401
400
  }
402
401
  })
403
402
  }
404
403
 
405
404
  getCacheAddressRouter() {
406
405
  if (!window.jmfe) return
407
406
  if (isAndroidDevice) {
408
407
  return window.jmfe.callRouter({
409
408
  jdRouter: '1',
410
409
  routerURL: 'router://JDAddressModule/getCacheAddress',
411
410
  routerParam: { sceneId: 'basicShoppingProcess' },
412
411
  })
413
412
  } else if (isIosDevice) {
414
413
  return window.jmfe.callRouter({
415
414
  jdRouter: '1',
416
415
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
417
416
  routerParam: { sceneId: 'basicShoppingProcess' },
418
417
  })
419
418
  } else if (isJdAndHarmonyDevice) {
420
419
  return new Promise(resolve => {
421
420
  resolve({})
422
421
  })
423
422
  } else {
424
423
  throw Error(
425
424
  'Unknown device type cannot obtain the address information through the route!',
426
425
  )
427
426
  }
428
427
  }
429
428
 
430
429
  getAddressCachePromise() {
431
430
  return new Promise(resolve => {
432
431
  if (
433
432
  this?.info?.sysInfo?.lat &&
434
433
  this?.info?.sysInfo?.lng &&
435
434
  this?.info?.sysInfo?.area
436
435
  ) {
437
436
  resolve({
438
437
  lat: this.info.sysInfo.lat,
439
438
  lng: this.info.sysInfo.lng,
440
439
  area: this?.info?.sysInfo?.area,
441
440
  })
442
441
  } else {
443
442
  this.jmfeReayPromise()
444
443
  .then(() => {
445
444
  this.getCacheAddressRouter()
446
445
  .then(({ status, data }) => {
447
446
  if (status === '0' && data) {
448
447
  const {
449
448
  lat,
450
449
  latitude,
451
450
  lng,
452
451
  longitude,
453
452
  provinceId,
454
453
  cityId,
455
454
  countyId,
456
455
  townId,
457
456
  } = data || {}
458
457
  let area = ''
459
458
  this.info.sysInfo['lat'] = lat || latitude || ''
460
459
  this.info.sysInfo['lng'] = lng || longitude || ''
461
460
  if (provinceId) {
462
461
  area = `${provinceId}_${cityId || 0}_${countyId ||
463
462
  0}_${townId || 0}`
464
463
  this.info.pageInfo['address'] = area
465
464
  this.info.pageInfo['addressCommaStr'] = area.replace(
466
465
  /_/g,
467
466
  ',',
468
467
  )
469
468
  }
470
469
  resolve({
471
470
  lat: lat,
472
471
  lng: lng,
473
472
  area: area,
474
473
  })
475
474
  } else {
476
475
  resolve({ lat: '', lng: '', area: '' })
477
476
  }
478
477
  })
479
478
  .catch(e => {
480
479
  console.log(' ~~ file: index.h5.ts:514 ~~ .catch ~~ e:', e)
481
480
  resolve({ lat: '', lng: '', area: '' })
482
481
  })
483
482
  })
484
483
  .catch(e => {
485
484
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
486
485
  resolve({ lat: '', lng: '', area: '' })
487
486
  console.log('判断jmfe不存在,获取经纬度信息异常')
488
487
  })
489
488
  }
490
489
  })
491
490
  }
492
491
 
493
492
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
494
493
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady)
495
494
  if (!isJdApp) {
496
495
  return
497
496
  }
498
497
  const avifSwitch = await getMPaasConfigByBussinessKey(
499
498
  'avifSwitch',
500
499
  isBeforePageReady,
501
500
  )
502
501
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
503
502
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
504
503
  'isFollowAppVideoPlayStatus',
505
504
  isBeforePageReady,
506
505
  )
507
506
  console.log(
508
507
  'isBeforePageReady:',
509
508
  isBeforePageReady,
510
509
  'isFollowAppVideoPlayStatus:',
511
510
  isFollowAppVideoPlayStatus,
512
511
  )
513
512
  if (
514
513
  isFollowAppVideoPlayStatus === true ||
515
514
  isFollowAppVideoPlayStatus === 'true'
516
515
  ) {
517
516
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
518
517
  }
519
518
  }
520
519
 
521
520
  async getWifiVideoAutoPlayAsync() {
522
521
  this.info.sysInfo['wifiVideoAutoPlay'] = false
523
522
  if (!isJdApp) {
524
523
  return
525
524
  }
526
525
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
527
526
  return 0
528
527
  })
529
528
  if (Number(videoPlayStatus) === 1) {
530
529
  this.info.sysInfo['wifiVideoAutoPlay'] = true
531
530
  }
532
531
  }
533
532
 
534
533
  async getMPaasConfigAsync() {
535
534
  this.info.sysInfo.dynamicConfig = {}
536
535
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
537
536
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
538
537
  return this.updateMPaasConfigAsync(true)
539
538
  }
540
539
 
541
540
  getDynamicConfig(key: string) {
542
541
  return this.info.sysInfo.dynamicConfig[key]
543
542
  }
544
543
  async updateMPaasConfig() {
545
544
  console.log('updateMPaasConfig')
546
545
  if (
547
546
  isIosDevice &&
548
547
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
549
548
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
550
549
  ) {
551
550
  try {
552
551
  await this.updateMPaasConfigAsync(false)
553
552
  } catch (e) {
554
553
  console.log('updateMPaasConfigAsync:', e)
555
554
  }
556
555
  }
557
556
  }
558
557
 
559
558
  toLogin(options) {
560
559
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
561
560
  ? this.toWxAppLogin(options)
562
561
  : this.toWebLogin(options)
563
562
  }
564
563
 
565
564
  doLogin(options) {
566
565
  return this.toLogin(options)
567
566
  }
568
567
 
569
568
  doLoginForJdPin(options = {}) {
570
569
  return this.doLogin({
571
570
  loginColor: {
572
571
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
573
572
  dpin: 0,
574
573
  },
575
574
  ...options,
576
575
  })
577
576
  }
578
577
 
579
578
  toWebLogin(options) {
580
579
  let params: {
581
580
  returnurl: string
582
581
  } = {
583
582
  returnurl: '',
584
583
  }
585
584
  const loginUrl = isPc
586
585
  ? `//passport.jd.com/new/login.aspx`
587
586
  : `${domain.mobileLogin}/user/login.action`
588
587
  const defaultParams = {
589
588
  appid: '100',
590
589
  returnurl: window.location.href,
591
590
  }
592
591
  if (isString(options)) {
593
592
  params = Object.assign({}, defaultParams, {
594
593
  returnurl: options,
595
594
  })
596
595
  } else if (isObject(options)) {
597
596
  const { loginColor, ...otherOptions } = options
598
597
  params = Object.assign({}, defaultParams, otherOptions)
599
598
  } else {
600
599
  params = defaultParams
601
600
  }
602
601
  params.returnurl = encodeURIComponent(params.returnurl)
603
602
  let getFullUrl = loginUrl + '?' + serialize(params)
604
603
  if (isPc) {
605
604
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
606
605
  }
607
606
  return Promise.resolve({
608
607
  h5ToUrl: true,
609
608
  url: getFullUrl,
610
609
  }).then(() => {
611
610
  window.location.href = getFullUrl
612
611
  })
613
612
  }
614
613
 
615
614
  toWxAppLogin(options = {}) {
616
615
  console.log('微信京购小程序中h5登录跳转', options)
617
616
  return Promise.resolve(true).then(() => {
618
617
  const { loginColor } = Object.assign(
619
618
  {},
620
619
  {
621
620
  loginColor: {
622
621
  bzi: WXAPP_BIZ_KEY,
623
622
  dpin: 1,
624
623
  },
625
624
  },
626
625
  options,
627
626
  )
628
627
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
629
628
  loginColor.bzi
630
629
  }&url=${encodeURIComponent(window.location.href)}`
631
630
  })
632
631
  }
633
632
 
634
633
  getLoginCookie() {
635
634
  return Promise.resolve({
636
635
  pin: cookie.get('pin') || '',
637
636
  })
638
637
  }
639
638
 
640
639
  clearLoginCookie() {
641
640
  cookie.remove('pin')
642
641
  }
643
642
 
644
643
  checkStatusAndLogin(options = {}) {
645
644
  if (!this.checkStatusAndLoginPromise) {
646
645
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
647
646
  try {
648
647
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
649
648
  options,
650
649
  )
651
650
  if (getLoginState) {
652
651
  resolve(true)
653
652
  } else {
654
653
  this.toLogin(options)
655
654
  reject(false)
656
655
  }
657
656
  } catch (e) {
658
657
  this.toLogin(options)
659
658
  reject(false)
660
659
  }
661
660
  })
662
661
  return this.checkStatusAndLoginPromise
663
662
  } else {
664
663
  return this.checkStatusAndLoginPromise
665
664
  .then(() => {
666
665
  return Promise.resolve(true)
667
666
  })
668
667
  .catch(() => {
669
668
  this.toLogin(options)
670
669
  return Promise.reject(true)
671
670
  })
672
671
  }
673
672
  }
674
673
 
675
674
  checkJdStatusAndLogin(
676
675
  options = {
677
676
  loginColor: {
678
677
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
679
678
  dpin: 0,
680
679
  },
681
680
  },
682
681
  ) {
683
682
  return this.checkStatusAndLogin(options)
684
683
  }
685
684
 
686
685
  doCheckLoginStateAndForApiCheck(options) {
687
686
  if (this.info.loginState) {
688
687
  return Promise.resolve(true)
689
688
  } else {
690
689
  return new Promise((resolve, reject) => {
691
690
  if (
692
691
  this.info.isJingGouMiniViewState ||
693
692
  this.info.isJingxiMiniViewState
694
693
  ) {
695
694
  const getWqAuthToken = cookie.get('wq_auth_token')
696
695
  const getWqSkey = cookie.get('wq_skey')
697
696
  const getWqUin = cookie.get('wq_uin')
698
697
  const isLoginState =
699
698
  options?.loginColor?.dpin === 0
700
699
  ? getWqAuthToken
701
700
  : getWqSkey && getWqUin
702
701
  if (isLoginState) {
703
702
  this.info.loginState = true
704
703
  resolve(true)
705
704
  } else {
706
705
  reject(false)
707
706
  }
708
707
  } else {
709
708
  Taro.request({
710
709
  url: api.isLogin,
711
710
  jsonp: true,
712
711
  timeout: 3000,
713
712
  success: res => {
714
713
  const { statusCode, data } = res
715
714
  if (
716
715
  statusCode === 200 &&
717
716
  data?.islogin &&
718
717
  Number(data.islogin) === 1
719
718
  ) {
720
719
  this.info.loginState = true
721
720
  resolve(true)
722
721
  } else {
723
722
  reject(false)
724
723
  }
725
724
  },
726
725
  fail: err => {
727
726
  console.log('登录检查异常', err)
728
727
  reject(false)
729
728
  },
730
729
  })
731
730
  }
732
731
  })
733
732
  }
734
733
  }
735
734
 
736
735
  checkLoginStatus(options) {
737
736
  return new Promise(async (resolve, reject) => {
738
737
  try {
739
738
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
740
739
  options,
741
740
  )
742
741
  if (getLoginState) {
743
742
  const { pin } = await this.getLoginCookie()
744
743
  this.info.userInfo = {
745
744
  pin,
746
745
  encodePin: encodeURIComponent(pin),
747
746
  ptkey: '',
748
747
  }
749
748
  resolve(true)
750
749
  } else {
751
750
  reject(false)
752
751
  }
753
752
  } catch (e) {
754
753
  reject(false)
755
754
  }
756
755
  })
757
756
  }
758
757
 
759
758
  updatePageAndLogInfo(updateQuery = {}) {
760
759
  const createUpdateQueryInfo: {
761
760
  query: {
762
761
  shopId?: string | number
763
762
  venderId?: string | number
764
763
  }
765
764
  updateShopInfoState: boolean
766
765
  } = Object.assign(
767
766
  {},
768
767
  {
769
768
  query: {},
770
769
  updateShopInfoState: false,
771
770
  },
772
771
  updateQuery,
773
772
  )
774
773
  console.log(
775
774
  '获取当前下发的店铺查询参数',
776
775
  updateQuery,
777
776
  '获取之前保存的shopInfo店铺查询参数',
778
777
  this.info?.shopInfo,
779
778
  )
780
779
  const { query, updateShopInfoState } = createUpdateQueryInfo
781
780
  const { shopId, venderId, un_area } = query
782
781
  if (updateShopInfoState) {
783
782
  this.info.queryInfo = {
784
783
  ...this.info.queryInfo,
785
784
  ...query,
786
785
  }
787
786
  if (shopId && venderId) {
788
787
  this.info.shopInfo = {
789
788
  shopId: `${shopId}`,
790
789
  venderId: `${venderId}`,
791
790
  }
792
791
  }
793
792
  } else {
794
793
  this.info.queryInfo = {
795
794
  ...query,
796
795
  }
797
796
  if (
798
797
  this.info.shopInfo?.shopId &&
799
798
  this.info.shopInfo?.venderId &&
800
799
  (this.info.shopInfo.shopId == shopId ||
801
800
  this.info.shopInfo.venderId == venderId)
802
801
  ) {
803
802
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
804
803
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
805
804
  console.log(
806
805
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
807
806
  this.info.queryInfo,
808
807
  )
809
808
  }
810
809
  }
811
810
  this.info.queryInfo['shopId'] &&
812
811
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
813
812
  this.info.queryInfo['venderId'] &&
814
813
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
815
814
  console.log(
816
815
  'h5==获取店铺下发查询参数\n',
817
816
  query,
818
817
  '\n获取店铺最后查询参数\n',
819
818
  this.info.queryInfo,
820
819
  '\n是否为更新店铺状态\n',
821
820
  updateShopInfoState,
822
821
  )
823
822
  const changeArea =
824
823
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
825
824
  if (changeArea) {
826
825
  this.info.pageInfo.address = changeArea
827
826
  this.info.pageInfo.un_area = changeArea
828
827
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
829
828
  }
830
829
  }
830
+ import Taro from '@tarojs/taro'
831
831
  isJdApp,
832
832
  isIosDevice,
833
833
  isAndroidDevice,
834
834
  isJdAndHarmonyDevice,
835
835
  isJdAndAndroidDevice,
836
836
  jdAppVersion,
837
837
  jdAppVersionStr,
838
838
  isString,
839
839
  isObject,
840
840
  serialize,
841
841
  urlCookie,
842
842
  dealNativePixelToCssPixel,
843
843
  isPc,
844
844
  BUSINESS_TYPE,
845
845
  SECTION_HOME_TAB_NAME_TYPE,
846
846
  SECTION_HOME_TAB_TYPE,
847
847
  WX_BUSINESS_TYPE,
848
848
  WXAPP_BIZ_KEY,
849
849
  MPAAS_CONFIG_APP_LOW_VERSION,
850
850
  MPAAS_CONFIG_APP_VERSION,
851
851
  WXAPP_BIZ_SHOP_LIGHT_KEY,
852
852
  loginState: false,
853
853
  cookiesStr: '',
854
854
  userInfo: userPinKey,
855
855
  isJingGouMiniViewState: false,
856
856
  isJingxiMiniViewState: false,
857
857
  pageInfo: {
858
858
  wxBusinessType: WX_BUSINESS_TYPE.NO,
859
859
  address: '',
860
860
  addressCommaStr: '',
861
861
  un_area: '',
862
862
  vapptype: '1',
863
863
  pageType: 'home',
864
864
  isExposureState: false,
865
865
  moduleId: '',
866
866
  entrance: '',
867
867
  dataType: BUSINESS_TYPE.ONLINE,
868
868
  floorExposureInfo: {},
869
869
  floorVideInfo: {},
870
870
  productVideInfo: {},
871
871
  tabsLoadAllDataInfo: {
872
872
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]:
873
873
  false,
874
874
  },
875
875
  updateShopInfosAllState: false,
876
876
  isVipShop: false,
877
877
  isJdShowNativeImmersivePlayer: false,
878
878
  ...shopConfig,
879
879
  pageScrollTop: 0,
880
880
  pageIdxHeightInfo: {
881
881
  list: [],
882
882
  },
883
883
  shopNavBarHeight: 0,
884
884
  },
885
885
  defaultQueryLogInfo: {
886
886
  sourceType: 'JDshop',
887
887
  sourceValue: '',
888
888
  moduleId: 'none',
889
889
  entrance: 'none',
890
890
  },
891
891
  sysInfo: {
892
892
  windowWidth: isPc ? 375 : 0,
893
893
  containerWidth: isPc ? 375 : 0,
894
894
  windowHeight: 0,
895
895
  netWorkType: '4g',
896
896
  jdBottomBarHeight: 0,
897
897
  jdNativeHeaderHeight: 0,
898
898
  },
899
899
  queryInfo: {},
900
900
  shopInfo: {},
901
901
  openAppData: {},
902
902
  public info: CommonInterFace.BaseConfigInfo
903
903
  public config: {
904
904
  [key: string]: any
905
905
  }
906
906
  public lazyContainer: CommonInterFace.lazyContainer
907
907
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
908
908
  public rootEleNode: HTMLElement | null
909
909
  public checkStatusAndLoginPromise: object | null
910
910
  private jmfeRegisterStatePromise: Promise<any> | null
911
911
  private jmfeRegisterState: boolean
912
912
  constructor(opt) {
913
913
  this.info = this._getConfig(opt)
914
914
  this.config = {}
915
915
  this.lazyContainer = {
916
916
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
917
917
  appLazyContainerList: [],
918
918
  appLazyFinishContainerList: [],
919
919
  },
920
920
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
921
921
  appLazyContainerList: [],
922
922
  appLazyFinishContainerList: [],
923
923
  },
924
924
  }
925
925
  this.renderedIsvComponents = {}
926
926
  this.rootEleNode = document.querySelector('body')
927
927
  this.checkStatusAndLoginPromise = null
928
928
  this.jmfeRegisterStatePromise = null
929
929
  isJdApp && this.jmfeReayPromise()
930
930
  }
931
931
  _getConfig(opt) {
932
932
  return Object.assign({}, DefaultConfig, opt)
933
933
  }
934
934
 
935
935
  jmfeReayPromise(): Promise<any> {
936
936
  if (isJdApp) {
937
937
  if (this.jmfeRegisterState) {
938
938
  return Promise.resolve(true)
939
939
  } else {
940
940
  !this.jmfeRegisterStatePromise &&
941
941
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
942
942
  ready('jmfe', 3000)
943
943
  .then(() => {
944
944
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
945
945
  this.jmfeRegisterState = true
946
946
  resolve(true)
947
947
  console.log('松果app内初始化注册jmfe认证完成')
948
948
  })
949
949
  .catch(() => {
950
950
  reject(false)
951
951
  })
952
952
  }))
953
953
  return this.jmfeRegisterStatePromise
954
954
  }
955
955
  } else {
956
956
  return Promise.reject(false)
957
957
  }
958
958
  }
959
959
 
960
960
  updateBusinessDomainAndApi(domain, api) {
961
961
  }
962
962
 
963
963
  formatNativeScreenPageData(action) {
964
964
  let getChangePageInfo: any = null
965
965
  try {
966
966
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
967
967
  JSON.stringify({
968
968
  plugin: 'JDHybridScreenPlugin',
969
969
  action,
970
970
  sync: '1',
971
971
  }),
972
972
  )
973
973
  const getChangePageInfoData =
974
974
  typeof getNativeScreenPageInfoStr === 'string'
975
975
  ? JSON.parse(getNativeScreenPageInfoStr)
976
976
  : null
977
977
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
978
978
  const { code, data } = getChangePageInfoData
979
979
  getChangePageInfo = code && code === '0' ? data : null
980
980
  }
981
981
  } catch (e) {
982
982
  console.log('JDHybridScreenPlugin转换异常', e)
983
983
  }
984
984
  return getChangePageInfo
985
985
  }
986
986
 
987
987
  isAndroidFoldScreen() {
988
988
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
989
989
  }
990
990
 
991
991
  getJdAndroidPageChangeScreenInfo() {
992
992
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
993
993
  if (
994
994
  getPageScreenInfo &&
995
995
  getPageScreenInfo?.pageWidth &&
996
996
  getPageScreenInfo?.pageHeight
997
997
  ) {
998
998
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
999
999
  pageWidth: getPageScreenInfo.pageWidth,
1000
1000
  pageHeight: getPageScreenInfo.pageHeight,
1001
1001
  })
1002
1002
  getPageScreenInfo.pageWidth = pageWidth
1003
1003
  getPageScreenInfo.pageHeight = pageHeight
1004
1004
  }
1005
1005
  return getPageScreenInfo
1006
1006
  }
1007
1007
 
1008
1008
  getSystemInfo(params) {
1009
1009
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
1010
1010
  ? {}
1011
1011
  : getSystemInfos(params)
1012
1012
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
1013
1013
  const isfoldScreen = this.isAndroidFoldScreen()
1014
1014
  if (isfoldScreen) {
1015
1015
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
1016
1016
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
1017
1017
  console.info(
1018
1018
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
1019
1019
  getJdAndroidPageInfo,
1020
1020
  )
1021
1021
  }
1022
1022
  }
1023
1023
  this.info.sysInfo = {
1024
1024
  actualNavBarHeight: 0,
1025
1025
  ...this.info.sysInfo,
1026
1026
  ...info,
1027
1027
  safeContentHeight: info?.screenHeight,
1028
1028
  headerHeight: 0,
1029
1029
  tabBarHeight: 0,
1030
1030
  }
1031
1031
  if (isJdApp) {
1032
1032
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
1033
1033
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
1034
1034
  this.getAddressCachePromise()
1035
1035
  this.getElderModePromise()
1036
1036
  this.getJDAppearanceStatePromise()
1037
1037
  this.createJdAndroidRquestEventForTouchStart()
1038
1038
  }
1039
1039
  this.getWifiVideoAutoPlayAsync()
1040
1040
  this.getMPaasConfigAsync()
1041
1041
  this.getNetWorkType()
1042
1042
  }
1043
1043
 
1044
1044
  taskTimeoutPromise(callBack, timeout = 2000) {
1045
1045
  return new Promise((resolve) => {
1046
1046
  setTimeout(() => {
1047
1047
  const getCallBackRes = typeof callBack === 'function' && callBack()
1048
1048
  return resolve(getCallBackRes || false)
1049
1049
  }, timeout)
1050
1050
  })
1051
1051
  }
1052
1052
 
1053
1053
  getElderModePromise() {
1054
1054
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1055
1055
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1056
1056
  } else {
1057
1057
  if (isJdAndAndroidDevice) {
1058
1058
  this.info.sysInfo.jdAppModeType = '0'
1059
1059
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1060
1060
  } else {
1061
1061
  return Promise.race([
1062
1062
  this.taskTimeoutPromise(() => {
1063
1063
  this.info.sysInfo.jdAppModeType = '0'
1064
1064
  return this.info.sysInfo.jdAppModeType
1065
1065
  }),
1066
1066
  new Promise((resolve) => {
1067
1067
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
1068
1068
  if (!window[getCallBackName]) {
1069
1069
  window[getCallBackName] = (res) => {
1070
1070
  try {
1071
1071
  const getResJson =
1072
1072
  typeof res === 'string' ? JSON.parse(res) : res
1073
1073
  const { status, data, msg } = getResJson
1074
1074
  console.log(`获取松果app展示模式成功,返回结果${data}`)
1075
1075
  if (status === '0') {
1076
1076
  this.info.sysInfo.jdAppModeType = data
1077
1077
  resolve(data)
1078
1078
  } else {
1079
1079
  resolve('0')
1080
1080
  }
1081
1081
  } catch (e) {
1082
1082
  resolve('0')
1083
1083
  }
1084
1084
  window[getCallBackName] = null
1085
1085
  }
1086
1086
  }
1087
1087
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1088
1088
  method: 'callSyncRouterModuleWithParams',
1089
1089
  params: JSON.stringify({
1090
1090
  routerURL: 'router://JDBModeModule/getCurrentMode',
1091
1091
  routerParam: {},
1092
1092
  callBackName: `window.${getCallBackName}`,
1093
1093
  callBackId: `${getCallBackName}Ios`,
1094
1094
  }),
1095
1095
  })
1096
1096
  }),
1097
1097
  ])
1098
1098
  }
1099
1099
  }
1100
1100
  }
1101
1101
 
1102
1102
  getJDAppearanceStatePromise() {
1103
1103
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1104
1104
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
1105
1105
  } else {
1106
1106
  return Promise.race([
1107
1107
  this.taskTimeoutPromise(() => {
1108
1108
  this.info.sysInfo.jdAppearanceState = '0'
1109
1109
  return this.info.sysInfo.jdAppearanceState
1110
1110
  }),
1111
1111
  new Promise((resolve) => {
1112
1112
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
1113
1113
  if (!window[getCallBackName]) {
1114
1114
  window[getCallBackName] = (res) => {
1115
1115
  try {
1116
1116
  console.log('getJDAppearanceStatePromise', res)
1117
1117
  const getResJson =
1118
1118
  typeof res === 'string' ? JSON.parse(res) : res
1119
1119
  const { status, data, msg } = getResJson
1120
1120
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
1121
1121
  if (status === '0') {
1122
1122
  this.info.sysInfo.jdAppearanceState = data
1123
1123
  resolve(data)
1124
1124
  } else {
1125
1125
  resolve('0')
1126
1126
  }
1127
1127
  } catch (e) {
1128
1128
  resolve('0')
1129
1129
  }
1130
1130
  window[getCallBackName] = null
1131
1131
  }
1132
1132
  }
1133
1133
  if (isAndroidDevice) {
1134
1134
  const jsonString = JSON.stringify({
1135
1135
  callBackName: `window.${getCallBackName}`,
1136
1136
  })
1137
1137
  console.log('window.JDAppearance', window.JDAppearance)
1138
1138
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
1139
1139
  } else {
1140
1140
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1141
1141
  method: 'callSyncRouterModuleWithParams',
1142
1142
  params: JSON.stringify({
1143
1143
  routerURL:
1144
1144
  'router://JDWebViewBusinessModule/getJDAppearanceState',
1145
1145
  routerParam: {},
1146
1146
  callBackName: `window.${getCallBackName}`,
1147
1147
  callBackId: `${getCallBackName}Ios`,
1148
1148
  }),
1149
1149
  })
1150
1150
  }
1151
1151
  }),
1152
1152
  ])
1153
1153
  }
1154
1154
  }
1155
1155
 
1156
1156
  createJdAndroidRquestEventForTouchStart() {
1157
1157
  if (isJdAndAndroidDevice && window.JdAndroid) {
1158
1158
  const rootEleNode = document.querySelector('body')
1159
1159
  if (rootEleNode) {
1160
1160
  rootEleNode.addEventListener(
1161
1161
  'touchstart',
1162
1162
  this.jdAndroidAddEventListenerTouchStart,
1163
1163
  false,
1164
1164
  )
1165
1165
  }
1166
1166
  }
1167
1167
  }
1168
1168
  jdAndroidAddEventListenerTouchStart(e) {
1169
1169
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
1170
1170
  if (!isH5SwiperCustomEle) {
1171
1171
  const hasCustomEle = e
1172
1172
  ? e?.target?.closest('.J_customScroll') ||
1173
1173
  e?.target?.closest('.J_customLayout')
1174
1174
  : false
1175
1175
  if (!hasCustomEle) {
1176
1176
  window.JdAndroid.requestEvent(false)
1177
1177
  console.log(
1178
1178
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1179
1179
  )
1180
1180
  }
1181
1181
  }
1182
1182
  }
1183
1183
  removeJdAndroidRquestEventForTouchStart() {
1184
1184
  if (isJdAndAndroidDevice && window.JdAndroid) {
1185
1185
  const rootEleNode = document.querySelector('body')
1186
1186
  if (rootEleNode) {
1187
1187
  rootEleNode.removeEventListener(
1188
1188
  'touchstart',
1189
1189
  this.jdAndroidAddEventListenerTouchStart,
1190
1190
  false,
1191
1191
  )
1192
1192
  }
1193
1193
  }
1194
1194
  }
1195
1195
 
1196
1196
  getNetWorkType() {
1197
1197
  if (isJdApp) {
1198
1198
  this.jmfeReayPromise().then(() => {
1199
1199
  window.jmfe
1200
1200
  .getNetworkStatus()
1201
1201
  .then(({ status, data }) => {
1202
1202
  console.log(
1203
1203
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
1204
1204
  data,
1205
1205
  )
1206
1206
  if (status === '0') {
1207
1207
  this.info.sysInfo['netWorkType'] = data
1208
1208
  } else {
1209
1209
  this._taroGetNetworkType()
1210
1210
  }
1211
1211
  })
1212
1212
  .catch((err) => {
1213
1213
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
1214
1214
  this._taroGetNetworkType()
1215
1215
  })
1216
1216
  })
1217
1217
  } else {
1218
1218
  this._taroGetNetworkType()
1219
1219
  }
1220
1220
  }
1221
1221
  _taroGetNetworkType() {
1222
1222
  Taro.getNetworkType().then((getRes) => {
1223
1223
  if (getRes && getRes.networkType) {
1224
1224
  this.info.sysInfo['netWorkType'] = getRes.networkType
1225
1225
  console.log(
1226
1226
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1227
1227
  this.info.sysInfo['netWorkType'],
1228
1228
  )
1229
1229
  }
1230
1230
  })
1231
1231
  }
1232
1232
 
1233
1233
  getCacheAddressRouter() {
1234
1234
  if (!window.jmfe) return
1235
1235
  if (isAndroidDevice) {
1236
1236
  return window.jmfe.callRouter({
1237
1237
  jdRouter: '1',
1238
1238
  routerURL: 'router://JDAddressModule/getCacheAddress',
1239
1239
  routerParam: { sceneId: 'basicShoppingProcess' },
1240
1240
  })
1241
1241
  } else if (isIosDevice) {
1242
1242
  return window.jmfe.callRouter({
1243
1243
  jdRouter: '1',
1244
1244
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1245
1245
  routerParam: { sceneId: 'basicShoppingProcess' },
1246
1246
  })
1247
1247
  } else if (isJdAndHarmonyDevice) {
1248
1248
  return new Promise((resolve) => {
1249
1249
  resolve({})
1250
1250
  })
1251
1251
  } else {
1252
1252
  throw Error(
1253
1253
  'Unknown device type cannot obtain the address information through the route!',
1254
1254
  )
1255
1255
  }
1256
1256
  }
1257
1257
 
1258
1258
  getAddressCachePromise() {
1259
1259
  return new Promise((resolve) => {
1260
1260
  if (
1261
1261
  this?.info?.sysInfo?.lat &&
1262
1262
  this?.info?.sysInfo?.lng &&
1263
1263
  this?.info?.sysInfo?.area
1264
1264
  ) {
1265
1265
  resolve({
1266
1266
  lat: this.info.sysInfo.lat,
1267
1267
  lng: this.info.sysInfo.lng,
1268
1268
  area: this?.info?.sysInfo?.area,
1269
1269
  })
1270
1270
  } else {
1271
1271
  this.jmfeReayPromise().then(() => {
1272
1272
  this.getCacheAddressRouter()
1273
1273
  .then(({ status, data }) => {
1274
1274
  if (status === '0' && data) {
1275
1275
  const {
1276
1276
  lat,
1277
1277
  latitude,
1278
1278
  lng,
1279
1279
  longitude,
1280
1280
  provinceId,
1281
1281
  cityId,
1282
1282
  countyId,
1283
1283
  townId,
1284
1284
  } = data || {}
1285
1285
  let area = ''
1286
1286
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
1287
1287
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
1288
1288
  if (provinceId) {
1289
1289
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${
1290
1290
  townId || 0
1291
1291
  }`
1292
1292
  this.info.pageInfo['address'] = area
1293
1293
  this.info.pageInfo['addressCommaStr'] = area.replace(
1294
1294
  /_/g,
1295
1295
  ',',
1296
1296
  )
1297
1297
  }
1298
1298
  resolve({
1299
1299
  lat: this.info.sysInfo['lat'],
1300
1300
  lng: this.info.sysInfo['lng'],
1301
1301
  area: area,
1302
1302
  })
1303
1303
  } else {
1304
1304
  resolve({ lat: '', lng: '', area: '' })
1305
1305
  }
1306
1306
  })
1307
1307
  .catch((e) => {
1308
1308
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
1309
1309
  resolve({ lat: '', lng: '', area: '' })
1310
1310
  console.log('判断jmfe不存在,获取经纬度信息异常')
1311
1311
  })
1312
1312
  })
1313
1313
  }
1314
1314
  })
1315
1315
  }
1316
1316
 
1317
1317
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1318
1318
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady)
1319
1319
  if (!isJdApp) {
1320
1320
  return
1321
1321
  }
1322
1322
  const avifSwitch = await getMPaasConfigByBussinessKey(
1323
1323
  'avifSwitch',
1324
1324
  isBeforePageReady,
1325
1325
  )
1326
1326
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
1327
1327
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1328
1328
  'isFollowAppVideoPlayStatus',
1329
1329
  isBeforePageReady,
1330
1330
  )
1331
1331
  console.log(
1332
1332
  'isBeforePageReady:',
1333
1333
  isBeforePageReady,
1334
1334
  'isFollowAppVideoPlayStatus:',
1335
1335
  isFollowAppVideoPlayStatus,
1336
1336
  )
1337
1337
  if (
1338
1338
  isFollowAppVideoPlayStatus === true ||
1339
1339
  isFollowAppVideoPlayStatus === 'true'
1340
1340
  ) {
1341
1341
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
1342
1342
  }
1343
1343
  }
1344
1344
 
1345
1345
  async getWifiVideoAutoPlayAsync() {
1346
1346
  this.info.sysInfo['wifiVideoAutoPlay'] = false
1347
1347
  if (!isJdApp) {
1348
1348
  return
1349
1349
  }
1350
1350
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
1351
1351
  return 0
1352
1352
  })
1353
1353
  if (Number(videoPlayStatus) === 1) {
1354
1354
  this.info.sysInfo['wifiVideoAutoPlay'] = true
1355
1355
  }
1356
1356
  }
1357
1357
 
1358
1358
  async getMPaasConfigAsync() {
1359
1359
  this.info.sysInfo.dynamicConfig = {}
1360
1360
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
1361
1361
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
1362
1362
  return this.updateMPaasConfigAsync(true)
1363
1363
  }
1364
1364
 
1365
1365
  getDynamicConfig(key: string) {
1366
1366
  return this.info.sysInfo.dynamicConfig[key]
1367
1367
  }
1368
1368
  async updateMPaasConfig() {
1369
1369
  console.log('updateMPaasConfig')
1370
1370
  if (
1371
1371
  isIosDevice &&
1372
1372
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1373
1373
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1374
1374
  ) {
1375
1375
  try {
1376
1376
  await this.updateMPaasConfigAsync(false)
1377
1377
  } catch (e) {
1378
1378
  console.log('updateMPaasConfigAsync:', e)
1379
1379
  }
1380
1380
  }
1381
1381
  }
1382
1382
 
1383
1383
  toLogin(options) {
1384
1384
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1385
1385
  ? this.toWxAppLogin(options)
1386
1386
  : this.toWebLogin(options)
1387
1387
  }
1388
1388
 
1389
1389
  doLogin(options) {
1390
1390
  return this.toLogin(options)
1391
1391
  }
1392
1392
 
1393
1393
  doLoginForJdPin(options = {}) {
1394
1394
  return this.doLogin({
1395
1395
  loginColor: {
1396
1396
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1397
1397
  dpin: 0,
1398
1398
  },
1399
1399
  ...options,
1400
1400
  })
1401
1401
  }
1402
1402
 
1403
1403
  toWebLogin(options) {
1404
1404
  let params: {
1405
1405
  returnurl: string
1406
1406
  } = {
1407
1407
  returnurl: '',
1408
1408
  }
1409
1409
  const loginUrl = isPc
1410
1410
  ? `//passport.jd.com/new/login.aspx`
1411
1411
  : `${domain.mobileLogin}/user/login.action`
1412
1412
  const defaultParams = {
1413
1413
  appid: '100',
1414
1414
  returnurl: window.location.href,
1415
1415
  }
1416
1416
  if (isString(options)) {
1417
1417
  params = Object.assign({}, defaultParams, {
1418
1418
  returnurl: options,
1419
1419
  })
1420
1420
  } else if (isObject(options)) {
1421
1421
  const { loginColor, ...otherOptions } = options
1422
1422
  params = Object.assign({}, defaultParams, otherOptions)
1423
1423
  } else {
1424
1424
  params = defaultParams
1425
1425
  }
1426
1426
  params.returnurl = encodeURIComponent(params.returnurl)
1427
1427
  let getFullUrl = loginUrl + '?' + serialize(params)
1428
1428
  if (isPc) {
1429
1429
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1430
1430
  }
1431
1431
  return Promise.resolve({
1432
1432
  h5ToUrl: true,
1433
1433
  url: getFullUrl,
1434
1434
  }).then(() => {
1435
1435
  window.location.href = getFullUrl
1436
1436
  })
1437
1437
  }
1438
1438
 
1439
1439
  toWxAppLogin(options = {}) {
1440
1440
  console.log('微信京购小程序中h5登录跳转', options)
1441
1441
  return Promise.resolve(true).then(() => {
1442
1442
  const { loginColor } = Object.assign(
1443
1443
  {},
1444
1444
  {
1445
1445
  loginColor: {
1446
1446
  bzi: WXAPP_BIZ_KEY,
1447
1447
  dpin: 1,
1448
1448
  },
1449
1449
  },
1450
1450
  options,
1451
1451
  )
1452
1452
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1453
1453
  loginColor.bzi
1454
1454
  }&url=${encodeURIComponent(window.location.href)}`
1455
1455
  })
1456
1456
  }
1457
1457
 
1458
1458
  getLoginCookie() {
1459
1459
  return Promise.resolve({
1460
1460
  pin: cookie.get('pin') || '',
1461
1461
  })
1462
1462
  }
1463
1463
 
1464
1464
  clearLoginCookie() {
1465
1465
  cookie.remove('pin')
1466
1466
  }
1467
1467
 
1468
1468
  checkStatusAndLogin(options = {}) {
1469
1469
  if (!this.checkStatusAndLoginPromise) {
1470
1470
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1471
1471
  try {
1472
1472
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1473
1473
  options,
1474
1474
  )
1475
1475
  if (getLoginState) {
1476
1476
  resolve(true)
1477
1477
  } else {
1478
1478
  this.toLogin(options)
1479
1479
  reject(false)
1480
1480
  }
1481
1481
  } catch (e) {
1482
1482
  this.toLogin(options)
1483
1483
  reject(false)
1484
1484
  }
1485
1485
  })
1486
1486
  return this.checkStatusAndLoginPromise
1487
1487
  } else {
1488
1488
  return this.checkStatusAndLoginPromise
1489
1489
  .then(() => {
1490
1490
  return Promise.resolve(true)
1491
1491
  })
1492
1492
  .catch(() => {
1493
1493
  this.toLogin(options)
1494
1494
  return Promise.reject(true)
1495
1495
  })
1496
1496
  }
1497
1497
  }
1498
1498
 
1499
1499
  checkJdStatusAndLogin(
1500
1500
  options = {
1501
1501
  loginColor: {
1502
1502
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
1503
1503
  dpin: 0,
1504
1504
  },
1505
1505
  },
1506
1506
  ) {
1507
1507
  return this.checkStatusAndLogin(options)
1508
1508
  }
1509
1509
 
1510
1510
  doCheckLoginStateAndForApiCheck(options) {
1511
1511
  if (this.info.loginState) {
1512
1512
  return Promise.resolve(true)
1513
1513
  } else {
1514
1514
  return new Promise((resolve, reject) => {
1515
1515
  if (
1516
1516
  this.info.isJingGouMiniViewState ||
1517
1517
  this.info.isJingxiMiniViewState
1518
1518
  ) {
1519
1519
  const getWqAuthToken = cookie.get('wq_auth_token')
1520
1520
  const getWqSkey = cookie.get('wq_skey')
1521
1521
  const getWqUin = cookie.get('wq_uin')
1522
1522
  const isLoginState =
1523
1523
  options?.loginColor?.dpin === 0
1524
1524
  ? getWqAuthToken
1525
1525
  : getWqSkey && getWqUin
1526
1526
  if (isLoginState) {
1527
1527
  this.info.loginState = true
1528
1528
  resolve(true)
1529
1529
  } else {
1530
1530
  reject(false)
1531
1531
  }
1532
1532
  } else {
1533
1533
  Taro.request({
1534
1534
  url: api.isLogin,
1535
1535
  jsonp: true,
1536
1536
  timeout: 3000,
1537
1537
  success: (res) => {
1538
1538
  const { statusCode, data } = res
1539
1539
  if (
1540
1540
  statusCode === 200 &&
1541
1541
  data?.islogin &&
1542
1542
  Number(data.islogin) === 1
1543
1543
  ) {
1544
1544
  this.info.loginState = true
1545
1545
  resolve(true)
1546
1546
  } else {
1547
1547
  reject(false)
1548
1548
  }
1549
1549
  },
1550
1550
  fail: (err) => {
1551
1551
  console.log('登录检查异常', err)
1552
1552
  reject(false)
1553
1553
  },
1554
1554
  })
1555
1555
  }
1556
1556
  })
1557
1557
  }
1558
1558
  }
1559
1559
 
1560
1560
  checkLoginStatus(options) {
1561
1561
  return new Promise(async (resolve, reject) => {
1562
1562
  try {
1563
1563
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1564
1564
  options,
1565
1565
  )
1566
1566
  if (getLoginState) {
1567
1567
  const { pin } = await this.getLoginCookie()
1568
1568
  this.info.userInfo = {
1569
1569
  pin,
1570
1570
  encodePin: encodeURIComponent(pin),
1571
1571
  ptkey: '',
1572
1572
  }
1573
1573
  resolve(true)
1574
1574
  } else {
1575
1575
  reject(false)
1576
1576
  }
1577
1577
  } catch (e) {
1578
1578
  reject(false)
1579
1579
  }
1580
1580
  })
1581
1581
  }
1582
1582
 
1583
1583
  updatePageAndLogInfo(updateQuery = {}) {
1584
1584
  const createUpdateQueryInfo: {
1585
1585
  query: {
1586
1586
  shopId?: string | number
1587
1587
  venderId?: string | number
1588
1588
  }
1589
1589
  updateShopInfoState: boolean
1590
1590
  } = Object.assign(
1591
1591
  {},
1592
1592
  {
1593
1593
  query: {},
1594
1594
  updateShopInfoState: false,
1595
1595
  },
1596
1596
  updateQuery,
1597
1597
  )
1598
1598
  console.log(
1599
1599
  '获取当前下发的店铺查询参数',
1600
1600
  updateQuery,
1601
1601
  '获取之前保存的shopInfo店铺查询参数',
1602
1602
  this.info?.shopInfo,
1603
1603
  )
1604
1604
  const { query, updateShopInfoState } = createUpdateQueryInfo
1605
1605
  const { shopId, venderId, un_area } = query
1606
1606
  if (updateShopInfoState) {
1607
1607
  this.info.queryInfo = {
1608
1608
  ...this.info.queryInfo,
1609
1609
  ...query,
1610
1610
  }
1611
1611
  if (shopId && venderId) {
1612
1612
  this.info.shopInfo = {
1613
1613
  shopId: `${shopId}`,
1614
1614
  venderId: `${venderId}`,
1615
1615
  }
1616
1616
  }
1617
1617
  } else {
1618
1618
  this.info.queryInfo = {
1619
1619
  ...query,
1620
1620
  }
1621
1621
  if (
1622
1622
  this.info.shopInfo?.shopId &&
1623
1623
  this.info.shopInfo?.venderId &&
1624
1624
  (this.info.shopInfo.shopId == shopId ||
1625
1625
  this.info.shopInfo.venderId == venderId)
1626
1626
  ) {
1627
1627
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1628
1628
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1629
1629
  console.log(
1630
1630
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1631
1631
  this.info.queryInfo,
1632
1632
  )
1633
1633
  }
1634
1634
  }
1635
1635
  this.info.queryInfo['shopId'] &&
1636
1636
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1637
1637
  this.info.queryInfo['venderId'] &&
1638
1638
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1639
1639
  console.log(
1640
1640
  'h5==获取店铺下发查询参数\n',
1641
1641
  query,
1642
1642
  '\n获取店铺最后查询参数\n',
1643
1643
  this.info.queryInfo,
1644
1644
  '\n是否为更新店铺状态\n',
1645
1645
  updateShopInfoState,
1646
1646
  )
1647
1647
  const changeArea =
1648
1648
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1649
1649
  if (changeArea) {
1650
1650
  this.info.pageInfo.address = changeArea
1651
1651
  this.info.pageInfo.un_area = changeArea
1652
1652
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1653
1653
  }
1654
1654
  }