@conecli/cone-render 0.8.42 → 0.9.1-isv2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  isJdApp,
3
2
  isIosDevice,
4
3
  isAndroidDevice,
5
4
  isJdAndHarmonyDevice,
6
5
  isJdAndAndroidDevice,
7
6
  jdAppVersion,
8
7
  jdAppVersionStr,
9
8
  isString,
10
9
  isObject,
11
10
  serialize,
12
11
  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
  BUSINESS_TYPE,
850
850
  JSSDK_APP_WEBVIEW_CODE,
851
851
  SECTION_HOME_TAB_NAME_TYPE,
852
852
  SECTION_HOME_TAB_TYPE,
853
853
  WXAPP_BIZ_KEY,
854
854
  WX_BUSINESS_TYPE,
855
855
  MPAAS_CONFIG_APP_VERSION,
856
856
  MPAAS_CONFIG_APP_LOW_VERSION,
857
857
  WXAPP_BIZ_SHOP_LIGHT_KEY,
858
858
  loginState: false,
859
859
  cookiesStr: '',
860
860
  userInfo: userPinKey,
861
861
  isJingGouMiniViewState: false,
862
862
  isJingxiMiniViewState: false,
863
863
  pageInfo: {
864
864
  wxBusinessType: WX_BUSINESS_TYPE.NO,
865
865
  address: '',
866
866
  addressCommaStr: '',
867
867
  un_area: '',
868
868
  vapptype: '1',
869
869
  pageType: 'home',
870
870
  isExposureState: false,
871
871
  moduleId: '',
872
872
  entrance: '',
873
873
  dataType: BUSINESS_TYPE.ONLINE,
874
874
  floorExposureInfo: {},
875
875
  floorVideInfo: {},
876
876
  productVideInfo: {},
877
877
  tabsLoadAllDataInfo: {
878
878
  [SECTION_HOME_TAB_NAME_TYPE[
879
879
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
880
880
  ]]: false,
881
881
  },
882
882
  updateShopInfosAllState: false,
883
883
  isVipShop: false,
884
884
  isJdShowNativeImmersivePlayer: false,
885
885
  ...shopConfig,
886
886
  pageScrollTop: 0,
887
887
  pageIdxHeightInfo: {
888
888
  list: [],
889
889
  },
890
890
  shopNavBarHeight: 0,
891
891
  },
892
892
  defaultQueryLogInfo: {
893
893
  sourceType: 'JDshop',
894
894
  sourceValue: '',
895
895
  moduleId: 'none',
896
896
  entrance: 'none',
897
897
  },
898
898
  sysInfo: {
899
899
  windowWidth: isPc ? 375 : 0,
900
900
  containerWidth: isPc ? 375 : 0,
901
901
  windowHeight: 0,
902
902
  netWorkType: '4g',
903
903
  jdBottomBarHeight: 0,
904
904
  jdNativeHeaderHeight: 0,
905
905
  },
906
906
  queryInfo: {},
907
907
  shopInfo: {},
908
908
  openAppData: {},
909
909
  public info: CommonInterFace.BaseConfigInfo
910
910
  public config: {
911
911
  [key: string]: any
912
912
  }
913
913
  public lazyContainer: CommonInterFace.lazyContainer
914
914
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
915
915
  public rootEleNode: HTMLElement | null
916
916
  public checkStatusAndLoginPromise: object | null
917
917
  private jmfeRegisterStatePromise: Promise<any> | null
918
918
  private jmfeRegisterState: boolean
919
919
  constructor(opt) {
920
920
  this.info = this._getConfig(opt)
921
921
  this.config = {}
922
922
  this.lazyContainer = {
923
923
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
924
924
  appLazyContainerList: [],
925
925
  appLazyFinishContainerList: [],
926
926
  },
927
927
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
928
928
  appLazyContainerList: [],
929
929
  appLazyFinishContainerList: [],
930
930
  },
931
931
  }
932
932
  this.renderedIsvComponents = {}
933
933
  this.rootEleNode = document.querySelector('body')
934
934
  this.checkStatusAndLoginPromise = null
935
935
  this.jmfeRegisterStatePromise = null
936
936
  isJdApp && this.jmfeReayPromise()
937
937
  }
938
938
  _getConfig(opt) {
939
939
  return Object.assign({}, DefaultConfig, opt)
940
940
  }
941
941
 
942
942
  jmfeReayPromise(): Promise<any> {
943
943
  if (isJdApp) {
944
944
  if (this.jmfeRegisterState) {
945
945
  return Promise.resolve(true)
946
946
  } else {
947
947
  !this.jmfeRegisterStatePromise &&
948
948
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
949
949
  ready('jmfe', 3000)
950
950
  .then(() => {
951
951
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
952
952
  this.jmfeRegisterState = true
953
953
  resolve(true)
954
954
  console.log('松果app内初始化注册jmfe认证完成')
955
955
  })
956
956
  .catch(() => {
957
957
  reject(false)
958
958
  })
959
959
  }))
960
960
  return this.jmfeRegisterStatePromise
961
961
  }
962
962
  } else {
963
963
  return Promise.reject(false)
964
964
  }
965
965
  }
966
966
 
967
967
  updateBusinessDomainAndApi(domain, api) {
968
968
  }
969
969
 
970
970
  formatNativeScreenPageData(action) {
971
971
  let getChangePageInfo: any = null
972
972
  try {
973
973
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
974
974
  JSON.stringify({
975
975
  plugin: 'JDHybridScreenPlugin',
976
976
  action,
977
977
  sync: '1',
978
978
  }),
979
979
  )
980
980
  const getChangePageInfoData =
981
981
  typeof getNativeScreenPageInfoStr === 'string'
982
982
  ? JSON.parse(getNativeScreenPageInfoStr)
983
983
  : null
984
984
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
985
985
  const { code, data } = getChangePageInfoData
986
986
  getChangePageInfo = code && code === '0' ? data : null
987
987
  }
988
988
  } catch (e) {
989
989
  console.log('JDHybridScreenPlugin转换异常', e)
990
990
  }
991
991
  return getChangePageInfo
992
992
  }
993
993
 
994
994
  isAndroidFoldScreen() {
995
995
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
996
996
  }
997
997
 
998
998
  getJdAndroidPageChangeScreenInfo() {
999
999
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
1000
1000
  if (
1001
1001
  getPageScreenInfo &&
1002
1002
  getPageScreenInfo?.pageWidth &&
1003
1003
  getPageScreenInfo?.pageHeight
1004
1004
  ) {
1005
1005
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1006
1006
  pageWidth: getPageScreenInfo.pageWidth,
1007
1007
  pageHeight: getPageScreenInfo.pageHeight,
1008
1008
  })
1009
1009
  getPageScreenInfo.pageWidth = pageWidth
1010
1010
  getPageScreenInfo.pageHeight = pageHeight
1011
1011
  }
1012
1012
  return getPageScreenInfo
1013
1013
  }
1014
1014
 
1015
1015
  getSystemInfo(params) {
1016
1016
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
1017
1017
  ? {}
1018
1018
  : getSystemInfos(params)
1019
1019
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
1020
1020
  const isfoldScreen = this.isAndroidFoldScreen()
1021
1021
  if (isfoldScreen) {
1022
1022
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
1023
1023
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
1024
1024
  console.info(
1025
1025
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
1026
1026
  getJdAndroidPageInfo,
1027
1027
  )
1028
1028
  }
1029
1029
  }
1030
1030
  this.info.sysInfo = {
1031
1031
  actualNavBarHeight: 0,
1032
1032
  ...this.info.sysInfo,
1033
1033
  ...info,
1034
1034
  safeContentHeight: info?.screenHeight,
1035
1035
  headerHeight: 0,
1036
1036
  tabBarHeight: 0,
1037
1037
  }
1038
1038
  if (isJdApp) {
1039
1039
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
1040
1040
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
1041
1041
  this.getAddressCachePromise()
1042
1042
  this.getElderModePromise()
1043
1043
  this.getJDAppearanceStatePromise()
1044
1044
  this.createJdAndroidRquestEventForTouchStart()
1045
1045
  }
1046
1046
  this.getWifiVideoAutoPlayAsync()
1047
1047
  this.getMPaasConfigAsync()
1048
1048
  this.getNetWorkType()
1049
1049
  }
1050
1050
 
1051
1051
  taskTimeoutPromise(callBack, timeout = 2000) {
1052
1052
  return new Promise(resolve => {
1053
1053
  setTimeout(() => {
1054
1054
  const getCallBackRes = typeof callBack === 'function' && callBack()
1055
1055
  return resolve(getCallBackRes || false)
1056
1056
  }, timeout)
1057
1057
  })
1058
1058
  }
1059
1059
 
1060
1060
  getElderModePromise() {
1061
1061
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1062
1062
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1063
1063
  } else {
1064
1064
  if (isJdAndAndroidDevice) {
1065
1065
  this.info.sysInfo.jdAppModeType = '0'
1066
1066
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1067
1067
  } else {
1068
1068
  return Promise.race([
1069
1069
  this.taskTimeoutPromise(() => {
1070
1070
  this.info.sysInfo.jdAppModeType = '0'
1071
1071
  return this.info.sysInfo.jdAppModeType
1072
1072
  }),
1073
1073
  new Promise(resolve => {
1074
1074
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
1075
1075
  if (!window[getCallBackName]) {
1076
1076
  window[getCallBackName] = res => {
1077
1077
  try {
1078
1078
  const getResJson =
1079
1079
  typeof res === 'string' ? JSON.parse(res) : res
1080
1080
  const { status, data, msg } = getResJson
1081
1081
  console.log(`获取松果app展示模式成功,返回结果${data}`)
1082
1082
  if (status === '0') {
1083
1083
  this.info.sysInfo.jdAppModeType = data
1084
1084
  resolve(data)
1085
1085
  } else {
1086
1086
  resolve('0')
1087
1087
  }
1088
1088
  } catch (e) {
1089
1089
  resolve('0')
1090
1090
  }
1091
1091
  window[getCallBackName] = null
1092
1092
  }
1093
1093
  }
1094
1094
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1095
1095
  method: 'callSyncRouterModuleWithParams',
1096
1096
  params: JSON.stringify({
1097
1097
  routerURL: 'router://JDBModeModule/getCurrentMode',
1098
1098
  routerParam: {},
1099
1099
  callBackName: `window.${getCallBackName}`,
1100
1100
  callBackId: `${getCallBackName}Ios`,
1101
1101
  }),
1102
1102
  })
1103
1103
  }),
1104
1104
  ])
1105
1105
  }
1106
1106
  }
1107
1107
  }
1108
1108
 
1109
1109
  getJDAppearanceStatePromise() {
1110
1110
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1111
1111
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
1112
1112
  } else {
1113
1113
  return Promise.race([
1114
1114
  this.taskTimeoutPromise(() => {
1115
1115
  this.info.sysInfo.jdAppearanceState = '0'
1116
1116
  return this.info.sysInfo.jdAppearanceState
1117
1117
  }),
1118
1118
  new Promise(resolve => {
1119
1119
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
1120
1120
  if (!window[getCallBackName]) {
1121
1121
  window[getCallBackName] = res => {
1122
1122
  try {
1123
1123
  console.log('getJDAppearanceStatePromise', res)
1124
1124
  const getResJson =
1125
1125
  typeof res === 'string' ? JSON.parse(res) : res
1126
1126
  const { status, data, msg } = getResJson
1127
1127
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
1128
1128
  if (status === '0') {
1129
1129
  this.info.sysInfo.jdAppearanceState = data
1130
1130
  resolve(data)
1131
1131
  } else {
1132
1132
  resolve('0')
1133
1133
  }
1134
1134
  } catch (e) {
1135
1135
  resolve('0')
1136
1136
  }
1137
1137
  window[getCallBackName] = null
1138
1138
  }
1139
1139
  }
1140
1140
  if (isAndroidDevice) {
1141
1141
  const jsonString = JSON.stringify({
1142
1142
  callBackName: `window.${getCallBackName}`,
1143
1143
  })
1144
1144
  console.log('window.JDAppearance', window.JDAppearance)
1145
1145
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
1146
1146
  } else {
1147
1147
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1148
1148
  method: 'callSyncRouterModuleWithParams',
1149
1149
  params: JSON.stringify({
1150
1150
  routerURL:
1151
1151
  'router://JDWebViewBusinessModule/getJDAppearanceState',
1152
1152
  routerParam: {},
1153
1153
  callBackName: `window.${getCallBackName}`,
1154
1154
  callBackId: `${getCallBackName}Ios`,
1155
1155
  }),
1156
1156
  })
1157
1157
  }
1158
1158
  }),
1159
1159
  ])
1160
1160
  }
1161
1161
  }
1162
1162
 
1163
1163
  createJdAndroidRquestEventForTouchStart() {
1164
1164
  if (isJdAndAndroidDevice && window.JdAndroid) {
1165
1165
  const rootEleNode = document.querySelector('body')
1166
1166
  if (rootEleNode) {
1167
1167
  rootEleNode.addEventListener(
1168
1168
  'touchstart',
1169
1169
  this.jdAndroidAddEventListenerTouchStart,
1170
1170
  false,
1171
1171
  )
1172
1172
  }
1173
1173
  }
1174
1174
  }
1175
1175
  jdAndroidAddEventListenerTouchStart(e) {
1176
1176
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
1177
1177
  if (!isH5SwiperCustomEle) {
1178
1178
  const hasCustomEle = e
1179
1179
  ? e?.target?.closest('.J_customScroll') ||
1180
1180
  e?.target?.closest('.J_customLayout')
1181
1181
  : false
1182
1182
  if (!hasCustomEle) {
1183
1183
  window.JdAndroid.requestEvent(false)
1184
1184
  console.log(
1185
1185
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1186
1186
  )
1187
1187
  }
1188
1188
  }
1189
1189
  }
1190
1190
  removeJdAndroidRquestEventForTouchStart() {
1191
1191
  if (isJdAndAndroidDevice && window.JdAndroid) {
1192
1192
  const rootEleNode = document.querySelector('body')
1193
1193
  if (rootEleNode) {
1194
1194
  rootEleNode.removeEventListener(
1195
1195
  'touchstart',
1196
1196
  this.jdAndroidAddEventListenerTouchStart,
1197
1197
  false,
1198
1198
  )
1199
1199
  }
1200
1200
  }
1201
1201
  }
1202
1202
 
1203
1203
  getNetWorkType() {
1204
1204
  if (isJdApp) {
1205
1205
  this.jmfeReayPromise().then(() => {
1206
1206
  window.jmfe
1207
1207
  .getNetworkStatus()
1208
1208
  .then(({ status, data }) => {
1209
1209
  console.log(
1210
1210
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
1211
1211
  data,
1212
1212
  )
1213
1213
  if (status === '0') {
1214
1214
  this.info.sysInfo['netWorkType'] = data
1215
1215
  } else {
1216
1216
  this._taroGetNetworkType()
1217
1217
  }
1218
1218
  })
1219
1219
  .catch(err => {
1220
1220
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
1221
1221
  this._taroGetNetworkType()
1222
1222
  })
1223
1223
  })
1224
1224
  } else {
1225
1225
  this._taroGetNetworkType()
1226
1226
  }
1227
1227
  }
1228
1228
  _taroGetNetworkType() {
1229
1229
  Taro.getNetworkType().then(getRes => {
1230
1230
  if (getRes && getRes.networkType) {
1231
1231
  this.info.sysInfo['netWorkType'] = getRes.networkType
1232
1232
  console.log(
1233
1233
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1234
1234
  this.info.sysInfo['netWorkType'],
1235
1235
  )
1236
1236
  }
1237
1237
  })
1238
1238
  }
1239
1239
  getCacheAddressRouter() {
1240
1240
  if (!window.jmfe) return
1241
1241
  if (isAndroidDevice) {
1242
1242
  return window.jmfe.callRouter({
1243
1243
  jdRouter: '1',
1244
1244
  routerURL: 'router://JDAddressModule/getCacheAddress',
1245
1245
  routerParam: { sceneId: 'basicShoppingProcess' },
1246
1246
  })
1247
1247
  } else if (isIosDevice) {
1248
1248
  return window.jmfe.callRouter({
1249
1249
  jdRouter: '1',
1250
1250
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1251
1251
  routerParam: { sceneId: 'basicShoppingProcess' },
1252
1252
  })
1253
1253
  } else if (isJdAndHarmonyDevice) {
1254
1254
  return new Promise(resolve => {
1255
1255
  resolve({})
1256
1256
  })
1257
1257
  } else {
1258
1258
  throw Error(
1259
1259
  'Unknown device type cannot obtain the address information through the route!',
1260
1260
  )
1261
1261
  }
1262
1262
  }
1263
1263
 
1264
1264
  getAddressCachePromise() {
1265
1265
  return new Promise(resolve => {
1266
1266
  if (
1267
1267
  this?.info?.sysInfo?.lat &&
1268
1268
  this?.info?.sysInfo?.lng &&
1269
1269
  this?.info?.sysInfo?.area
1270
1270
  ) {
1271
1271
  resolve({
1272
1272
  lat: this.info.sysInfo.lat,
1273
1273
  lng: this.info.sysInfo.lng,
1274
1274
  area: this?.info?.sysInfo?.area,
1275
1275
  })
1276
1276
  } else {
1277
1277
  this.jmfeReayPromise().then(() => {
1278
1278
  this.getCacheAddressRouter()
1279
1279
  .then(({ status, data }) => {
1280
1280
  if (status === '0' && data) {
1281
1281
  const {
1282
1282
  lat,
1283
1283
  latitude,
1284
1284
  lng,
1285
1285
  longitude,
1286
1286
  provinceId,
1287
1287
  cityId,
1288
1288
  countyId,
1289
1289
  townId,
1290
1290
  } = data || {}
1291
1291
  let area = ''
1292
1292
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
1293
1293
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
1294
1294
  if (provinceId) {
1295
1295
  area = `${provinceId}_${cityId || 0}_${countyId ||
1296
1296
  0}_${townId || 0}`
1297
1297
  this.info.pageInfo['address'] = area
1298
1298
  this.info.pageInfo['addressCommaStr'] = area.replace(
1299
1299
  /_/g,
1300
1300
  ',',
1301
1301
  )
1302
1302
  }
1303
1303
  resolve({
1304
1304
  lat: this.info.sysInfo['lat'],
1305
1305
  lng: this.info.sysInfo['lng'],
1306
1306
  area: area,
1307
1307
  })
1308
1308
  } else {
1309
1309
  resolve({ lat: '', lng: '', area: '' })
1310
1310
  }
1311
1311
  })
1312
1312
  .catch(e => {
1313
1313
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
1314
1314
  resolve({ lat: '', lng: '', area: '' })
1315
1315
  console.log('判断jmfe不存在,获取经纬度信息异常')
1316
1316
  })
1317
1317
  })
1318
1318
  }
1319
1319
  })
1320
1320
  }
1321
1321
 
1322
1322
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1323
1323
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
1324
1324
  if (!isJdApp) {
1325
1325
  return
1326
1326
  }
1327
1327
  const avifSwitch = await getMPaasConfigByBussinessKey(
1328
1328
  'avifSwitch',
1329
1329
  isBeforePageReady,
1330
1330
  )
1331
1331
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
1332
1332
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1333
1333
  'isFollowAppVideoPlayStatus',
1334
1334
  isBeforePageReady,
1335
1335
  )
1336
1336
  console.log(
1337
1337
  'isBeforePageReady:',
1338
1338
  isBeforePageReady,
1339
1339
  'isFollowAppVideoPlayStatus:',
1340
1340
  isFollowAppVideoPlayStatus,
1341
1341
  )
1342
1342
  if (
1343
1343
  isFollowAppVideoPlayStatus === true ||
1344
1344
  isFollowAppVideoPlayStatus === 'true'
1345
1345
  ) {
1346
1346
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
1347
1347
  }
1348
1348
  }
1349
1349
 
1350
1350
  async getWifiVideoAutoPlayAsync() {
1351
1351
  this.info.sysInfo['wifiVideoAutoPlay'] = false
1352
1352
  if (!isJdApp) {
1353
1353
  return
1354
1354
  }
1355
1355
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
1356
1356
  return 0
1357
1357
  })
1358
1358
  if (Number(videoPlayStatus) === 1) {
1359
1359
  this.info.sysInfo['wifiVideoAutoPlay'] = true
1360
1360
  }
1361
1361
  }
1362
1362
 
1363
1363
  async getMPaasConfigAsync() {
1364
1364
  this.info.sysInfo.dynamicConfig = {}
1365
1365
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
1366
1366
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
1367
1367
  return this.updateMPaasConfigAsync(true)
1368
1368
  }
1369
1369
 
1370
1370
  getDynamicConfig(key: string){
1371
1371
  return this.info.sysInfo.dynamicConfig[key]
1372
1372
  }
1373
1373
  async updateMPaasConfig() {
1374
1374
  console.log('updateMPaasConfig')
1375
1375
  if (
1376
1376
  isIosDevice &&
1377
1377
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1378
1378
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1379
1379
  ) {
1380
1380
  try {
1381
1381
  await this.updateMPaasConfigAsync(false)
1382
1382
  } catch (e) {
1383
1383
  console.log('updateMPaasConfigAsync:', e)
1384
1384
  }
1385
1385
  }
1386
1386
  }
1387
1387
 
1388
1388
  toLogin(options) {
1389
1389
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1390
1390
  ? this.toWxAppLogin(options)
1391
1391
  : this.toWebLogin(options)
1392
1392
  }
1393
1393
 
1394
1394
  doLogin(options) {
1395
1395
  return this.toLogin(options)
1396
1396
  }
1397
1397
 
1398
1398
  doLoginForJdPin(options = {}) {
1399
1399
  return this.doLogin({
1400
1400
  loginColor: {
1401
1401
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1402
1402
  dpin: 0,
1403
1403
  },
1404
1404
  ...options,
1405
1405
  })
1406
1406
  }
1407
1407
 
1408
1408
  toWebLogin(options) {
1409
1409
  let params: {
1410
1410
  returnurl: string
1411
1411
  } = {
1412
1412
  returnurl: '',
1413
1413
  }
1414
1414
  const loginUrl = isPc
1415
1415
  ? `//passport.jd.com/new/login.aspx`
1416
1416
  : `${domain.mobileLogin}/user/login.action`
1417
1417
  const defaultParams = {
1418
1418
  appid: '100',
1419
1419
  returnurl: window.location.href,
1420
1420
  }
1421
1421
  if (isString(options)) {
1422
1422
  params = Object.assign({}, defaultParams, {
1423
1423
  returnurl: options,
1424
1424
  })
1425
1425
  } else if (isObject(options)) {
1426
1426
  const { loginColor, ...otherOptions } = options
1427
1427
  params = Object.assign({}, defaultParams, otherOptions)
1428
1428
  } else {
1429
1429
  params = defaultParams
1430
1430
  }
1431
1431
  params.returnurl = encodeURIComponent(params.returnurl)
1432
1432
  let getFullUrl = loginUrl + '?' + serialize(params)
1433
1433
  if (isPc) {
1434
1434
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1435
1435
  }
1436
1436
  return Promise.resolve({
1437
1437
  h5ToUrl: true,
1438
1438
  url: getFullUrl,
1439
1439
  }).then(() => {
1440
1440
  window.location.href = getFullUrl
1441
1441
  })
1442
1442
  }
1443
1443
 
1444
1444
  toWxAppLogin(options = {}) {
1445
1445
  console.log('微信京购小程序中h5登录跳转', options)
1446
1446
  return Promise.resolve(true).then(() => {
1447
1447
  const { loginColor } = Object.assign(
1448
1448
  {},
1449
1449
  {
1450
1450
  loginColor: {
1451
1451
  bzi: WXAPP_BIZ_KEY,
1452
1452
  dpin: 1,
1453
1453
  },
1454
1454
  },
1455
1455
  options,
1456
1456
  )
1457
1457
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1458
1458
  loginColor.bzi
1459
1459
  }&url=${encodeURIComponent(window.location.href)}`
1460
1460
  })
1461
1461
  }
1462
1462
 
1463
1463
  getLoginCookie() {
1464
1464
  return Promise.resolve({
1465
1465
  pin: cookie.get('pin') || '',
1466
1466
  })
1467
1467
  }
1468
1468
 
1469
1469
  clearLoginCookie() {
1470
1470
  cookie.remove('pin')
1471
1471
  }
1472
1472
 
1473
1473
  checkStatusAndLogin(options = {}) {
1474
1474
  if (!this.checkStatusAndLoginPromise) {
1475
1475
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1476
1476
  try {
1477
1477
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1478
1478
  options,
1479
1479
  )
1480
1480
  if (getLoginState) {
1481
1481
  resolve(true)
1482
1482
  } else {
1483
1483
  this.toLogin(options)
1484
1484
  reject(false)
1485
1485
  }
1486
1486
  } catch (e) {
1487
1487
  this.toLogin(options)
1488
1488
  reject(false)
1489
1489
  }
1490
1490
  })
1491
1491
  return this.checkStatusAndLoginPromise
1492
1492
  } else {
1493
1493
  return this.checkStatusAndLoginPromise
1494
1494
  .then(() => {
1495
1495
  return Promise.resolve(true)
1496
1496
  })
1497
1497
  .catch(() => {
1498
1498
  this.toLogin(options)
1499
1499
  return Promise.reject(true)
1500
1500
  })
1501
1501
  }
1502
1502
  }
1503
1503
 
1504
1504
  checkJdStatusAndLogin(
1505
1505
  options = {
1506
1506
  loginColor: {
1507
1507
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
1508
1508
  dpin: 0,
1509
1509
  },
1510
1510
  },
1511
1511
  ) {
1512
1512
  return this.checkStatusAndLogin(options)
1513
1513
  }
1514
1514
 
1515
1515
  doCheckLoginStateAndForApiCheck(options) {
1516
1516
  if (this.info.loginState) {
1517
1517
  return Promise.resolve(true)
1518
1518
  } else {
1519
1519
  return new Promise((resolve, reject) => {
1520
1520
  if (
1521
1521
  this.info.isJingGouMiniViewState ||
1522
1522
  this.info.isJingxiMiniViewState
1523
1523
  ) {
1524
1524
  const getWqAuthToken = cookie.get('wq_auth_token')
1525
1525
  const getWqSkey = cookie.get('wq_skey')
1526
1526
  const getWqUin = cookie.get('wq_uin')
1527
1527
  const isLoginState =
1528
1528
  options?.loginColor?.dpin === 0
1529
1529
  ? getWqAuthToken
1530
1530
  : getWqSkey && getWqUin
1531
1531
  if (isLoginState) {
1532
1532
  this.info.loginState = true
1533
1533
  resolve(true)
1534
1534
  } else {
1535
1535
  reject(false)
1536
1536
  }
1537
1537
  } else {
1538
1538
  Taro.request({
1539
1539
  url: api.isLogin,
1540
1540
  jsonp: true,
1541
1541
  timeout: 3000,
1542
1542
  success: res => {
1543
1543
  const { statusCode, data } = res
1544
1544
  if (
1545
1545
  statusCode === 200 &&
1546
1546
  data?.islogin &&
1547
1547
  Number(data.islogin) === 1
1548
1548
  ) {
1549
1549
  this.info.loginState = true
1550
1550
  resolve(true)
1551
1551
  } else {
1552
1552
  reject(false)
1553
1553
  }
1554
1554
  },
1555
1555
  fail: err => {
1556
1556
  console.log('登录检查异常', err)
1557
1557
  reject(false)
1558
1558
  },
1559
1559
  })
1560
1560
  }
1561
1561
  })
1562
1562
  }
1563
1563
  }
1564
1564
 
1565
1565
  checkLoginStatus(options) {
1566
1566
  return new Promise(async (resolve, reject) => {
1567
1567
  try {
1568
1568
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1569
1569
  options,
1570
1570
  )
1571
1571
  if (getLoginState) {
1572
1572
  const { pin } = await this.getLoginCookie()
1573
1573
  this.info.userInfo = {
1574
1574
  pin,
1575
1575
  encodePin: encodeURIComponent(pin),
1576
1576
  ptkey: '',
1577
1577
  }
1578
1578
  resolve(true)
1579
1579
  } else {
1580
1580
  reject(false)
1581
1581
  }
1582
1582
  } catch (e) {
1583
1583
  reject(false)
1584
1584
  }
1585
1585
  })
1586
1586
  }
1587
1587
 
1588
1588
  updatePageAndLogInfo(updateQuery = {}) {
1589
1589
  const createUpdateQueryInfo: {
1590
1590
  query: {
1591
1591
  shopId?: string | number
1592
1592
  venderId?: string | number
1593
1593
  }
1594
1594
  updateShopInfoState: boolean
1595
1595
  } = Object.assign(
1596
1596
  {},
1597
1597
  {
1598
1598
  query: {},
1599
1599
  updateShopInfoState: false,
1600
1600
  },
1601
1601
  updateQuery,
1602
1602
  )
1603
1603
  console.log(
1604
1604
  '获取当前下发的店铺查询参数',
1605
1605
  updateQuery,
1606
1606
  '获取之前保存的shopInfo店铺查询参数',
1607
1607
  this.info?.shopInfo,
1608
1608
  )
1609
1609
  const { query, updateShopInfoState } = createUpdateQueryInfo
1610
1610
  const { shopId, venderId, un_area } = query
1611
1611
  if (updateShopInfoState) {
1612
1612
  this.info.queryInfo = {
1613
1613
  ...this.info.queryInfo,
1614
1614
  ...query,
1615
1615
  }
1616
1616
  if (shopId && venderId) {
1617
1617
  this.info.shopInfo = {
1618
1618
  shopId: `${shopId}`,
1619
1619
  venderId: `${venderId}`,
1620
1620
  }
1621
1621
  }
1622
1622
  } else {
1623
1623
  this.info.queryInfo = {
1624
1624
  ...query,
1625
1625
  }
1626
1626
  if (
1627
1627
  this.info.shopInfo?.shopId &&
1628
1628
  this.info.shopInfo?.venderId &&
1629
1629
  (this.info.shopInfo.shopId == shopId ||
1630
1630
  this.info.shopInfo.venderId == venderId)
1631
1631
  ) {
1632
1632
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1633
1633
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1634
1634
  console.log(
1635
1635
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1636
1636
  this.info.queryInfo,
1637
1637
  )
1638
1638
  }
1639
1639
  }
1640
1640
  this.info.queryInfo['shopId'] &&
1641
1641
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1642
1642
  this.info.queryInfo['venderId'] &&
1643
1643
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1644
1644
  console.log(
1645
1645
  'h5==获取店铺下发查询参数\n',
1646
1646
  query,
1647
1647
  '\n获取店铺最后查询参数\n',
1648
1648
  this.info.queryInfo,
1649
1649
  '\n是否为更新店铺状态\n',
1650
1650
  updateShopInfoState,
1651
1651
  )
1652
1652
  const changeArea =
1653
1653
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1654
1654
  if (changeArea) {
1655
1655
  this.info.pageInfo.address = changeArea
1656
1656
  this.info.pageInfo.un_area = changeArea
1657
1657
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1658
1658
  }
1659
1659
  }