@conecli/cone-render 0.8.43 → 0.8.44

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