@conecli/cone-render 0.8.40 → 0.8.42

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