@conecli/cone-render 0.10.1-shop-beta.2 → 0.10.1-shop-beta.4

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