@conecli/cone-render 0.8.20-shop.131 → 0.8.20-shop.132

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
  isIosDevice,
3
2
  isAndroidDevice,
4
3
  isJdAndHarmonyDevice,
5
4
  isJdAndAndroidDevice,
6
5
  jdAppVersion,
7
6
  jdAppVersionStr,
8
7
  isString,
9
8
  isObject,
10
9
  serialize,
11
10
  dealNativePixelToCssPixel,
12
11
  isPc,
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
  LoadJsInitLoadEnvType,
23
22
  LoadJsInitLoadType,
24
23
  LoadJsInitTriggerType
25
24
  const designWidth = 750
26
25
  return (
27
26
  Math.ceil(
28
27
  (((parseInt(String(size), 10) / 40) * 750) / designWidth) * 10000,
29
28
  ) /
30
29
  10000 +
31
30
  'rem'
32
31
  )
33
32
  loginState: false,
34
33
  cookiesStr: '',
35
34
  userInfo: userPinKey,
36
35
  isJingGouMiniViewState: false,
37
36
  isJingxiMiniViewState: false,
38
37
  pageInfo: {
39
38
  wxBusinessType: WX_BUSINESS_TYPE.NO,
40
39
  address: '',
41
40
  addressCommaStr: '',
42
41
  un_area: '',
43
42
  vapptype: '1',
44
43
  pageType: 'home',
45
44
  isExposureState: false,
46
45
  moduleId: '',
47
46
  entrance: '',
48
47
  dataType: BUSINESS_TYPE.ONLINE,
49
48
  floorExposureInfo: {},
50
49
  floorVideInfo: {},
51
50
  productVideInfo: {},
52
51
  tabsLoadAllDataInfo: {
53
52
  [SECTION_HOME_TAB_NAME_TYPE[
54
53
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
55
54
  ]]: false,
56
55
  },
57
56
  updateShopInfosAllState: false,
58
57
  isVipShop: false,
59
58
  isJdShowNativeImmersivePlayer: false,
60
59
  ...shopConfig,
61
60
  pageScrollTop: 0,
62
61
  pageIdxHeightInfo: {
63
62
  list: [],
64
63
  },
65
64
  shopNavBarHeight: 0,
66
65
  },
67
66
  defaultQueryLogInfo: {
68
67
  sourceType: 'JDshop',
69
68
  sourceValue: '',
70
69
  moduleId: 'none',
71
70
  entrance: 'none',
72
71
  },
73
72
  sysInfo: {
74
73
  windowWidth: isPc ? 375 : 0,
75
74
  containerWidth: isPc ? 375 : 0,
76
75
  windowHeight: 0,
77
76
  netWorkType: '4g',
78
77
  jdBottomBarHeight: 0,
79
78
  jdNativeHeaderHeight: 0,
80
79
  },
81
80
  queryInfo: {},
82
81
  shopInfo: {},
83
82
  openAppData: {},
84
83
  public info: CommonInterFace.BaseConfigInfo
85
84
  public config: {
86
85
  [key: string]: any
87
86
  }
88
87
  public lazyContainer: CommonInterFace.lazyContainer
89
88
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
90
89
  public rootEleNode: HTMLElement | null
91
90
  public checkStatusAndLoginPromise: object | null
92
91
  private jmfeRegisterStatePromise: Promise<any> | null
93
92
  private jmfeRegisterState: boolean
94
93
  public loadJsSdkList: Array<any>
95
94
  public loadJsSdkListCachePromise: any
96
95
  constructor(opt) {
97
96
  this.info = this._getConfig(opt)
98
97
  this.config = {}
99
98
  this.loadJsSdkList = []
100
99
  this.loadJsSdkListCachePromise = {}
101
100
  this.lazyContainer = {
102
101
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
103
102
  appLazyContainerList: [],
104
103
  appLazyFinishContainerList: [],
105
104
  },
106
105
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
107
106
  appLazyContainerList: [],
108
107
  appLazyFinishContainerList: [],
109
108
  },
110
109
  }
111
110
  this.renderedIsvComponents = {}
112
111
  this.rootEleNode = document.querySelector('body')
113
112
  this.checkStatusAndLoginPromise = null
114
113
  this.jmfeRegisterStatePromise = null
115
114
  this.loadOtherSdk()
116
115
  isJdApp && this.jmfeReayPromise()
117
116
  }
118
117
  _getConfig(opt) {
119
118
  return Object.assign({}, DefaultConfig, opt)
120
119
  }
121
120
 
122
121
  jmfeReayPromise(): Promise<any> {
123
122
  if (isJdApp) {
124
123
  if (this.jmfeRegisterState) {
125
124
  return Promise.resolve(true)
126
125
  } else {
127
126
  !this.jmfeRegisterStatePromise &&
128
127
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
129
128
  ready('jmfe', 3000)
130
129
  .then(() => {
131
130
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
132
131
  this.jmfeRegisterState = true
133
132
  resolve(true)
134
133
  console.log('松果app内初始化注册jmfe认证完成')
135
134
  })
136
135
  .catch(() => {
137
136
  reject(false)
138
137
  })
139
138
  }))
140
139
  return this.jmfeRegisterStatePromise
141
140
  }
142
141
  } else {
143
142
  return Promise.reject(false)
144
143
  }
145
144
  }
146
145
 
147
146
  updateBusinessDomainAndApi(domain, api) {
148
147
  }
149
148
 
150
149
  formatNativeScreenPageData(action) {
151
150
  let getChangePageInfo: any = null
152
151
  try {
153
152
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
154
153
  JSON.stringify({
155
154
  plugin: 'JDHybridScreenPlugin',
156
155
  action,
157
156
  sync: '1',
158
157
  }),
159
158
  )
160
159
  const getChangePageInfoData =
161
160
  typeof getNativeScreenPageInfoStr === 'string'
162
161
  ? JSON.parse(getNativeScreenPageInfoStr)
163
162
  : null
164
163
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
165
164
  const { code, data } = getChangePageInfoData
166
165
  getChangePageInfo = code && code === '0' ? data : null
167
166
  }
168
167
  } catch (e) {
169
168
  console.log('JDHybridScreenPlugin转换异常', e)
170
169
  }
171
170
  return getChangePageInfo
172
171
  }
173
172
 
174
173
  isAndroidFoldScreen() {
175
174
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
176
175
  }
177
176
 
178
177
  getJdAndroidPageChangeScreenInfo() {
179
178
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
180
179
  if (
181
180
  getPageScreenInfo &&
182
181
  getPageScreenInfo?.pageWidth &&
183
182
  getPageScreenInfo?.pageHeight
184
183
  ) {
185
184
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
186
185
  pageWidth: getPageScreenInfo.pageWidth,
187
186
  pageHeight: getPageScreenInfo.pageHeight,
188
187
  })
189
188
  getPageScreenInfo.pageWidth = pageWidth
190
189
  getPageScreenInfo.pageHeight = pageHeight
191
190
  }
192
191
  return getPageScreenInfo
193
192
  }
194
193
 
195
194
  getSystemInfo(params) {
196
195
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
197
196
  ? {}
198
197
  : getSystemInfos(params)
199
198
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
200
199
  const isfoldScreen = this.isAndroidFoldScreen()
201
200
  if (isfoldScreen) {
202
201
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
203
202
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
204
203
  console.info(
205
204
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
206
205
  getJdAndroidPageInfo,
207
206
  )
208
207
  }
209
208
  }
210
209
  this.info.sysInfo = {
211
210
  actualNavBarHeight: 0,
212
211
  ...this.info.sysInfo,
213
212
  ...info,
214
213
  safeContentHeight: info?.screenHeight,
215
214
  headerHeight: 0,
216
215
  tabBarHeight: 0,
217
216
  }
218
217
  if (isJdApp) {
219
218
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
220
219
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
221
220
  this.getAddressCachePromise()
222
221
  this.getElderModePromise()
223
222
  this.getJDAppearanceStatePromise()
224
223
  this.createJdAndroidRquestEventForTouchStart()
225
224
  }
226
225
  this.getWifiVideoAutoPlayAsync()
227
226
  this.getMPaasConfigAsync()
228
227
  this.getNetWorkType()
229
228
  }
230
229
 
231
230
  taskTimeoutPromise(callBack, timeout = 2000) {
232
231
  return new Promise(resolve => {
233
232
  setTimeout(() => {
234
233
  const getCallBackRes = typeof callBack === 'function' && callBack()
235
234
  return resolve(getCallBackRes || false)
236
235
  }, timeout)
237
236
  })
238
237
  }
239
238
 
240
239
  getElderModePromise() {
241
240
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
242
241
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
243
242
  } else {
244
243
  if (isJdAndAndroidDevice) {
245
244
  this.info.sysInfo.jdAppModeType = '0'
246
245
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
247
246
  } else {
248
247
  return Promise.race([
249
248
  this.taskTimeoutPromise(() => {
250
249
  this.info.sysInfo.jdAppModeType = '0'
251
250
  return this.info.sysInfo.jdAppModeType
252
251
  }),
253
252
  new Promise(resolve => {
254
253
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
255
254
  if (!window[getCallBackName]) {
256
255
  window[getCallBackName] = res => {
257
256
  try {
258
257
  const getResJson =
259
258
  typeof res === 'string' ? JSON.parse(res) : res
260
259
  const { status, data, msg } = getResJson
261
260
  console.log(`获取松果app展示模式成功,返回结果${data}`)
262
261
  if (status === '0') {
263
262
  this.info.sysInfo.jdAppModeType = data
264
263
  resolve(data)
265
264
  } else {
266
265
  resolve('0')
267
266
  }
268
267
  } catch (e) {
269
268
  resolve('0')
270
269
  }
271
270
  window[getCallBackName] = null
272
271
  }
273
272
  }
274
273
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
275
274
  method: 'callSyncRouterModuleWithParams',
276
275
  params: JSON.stringify({
277
276
  routerURL: 'router://JDBModeModule/getCurrentMode',
278
277
  routerParam: {},
279
278
  callBackName: `window.${getCallBackName}`,
280
279
  callBackId: `${getCallBackName}Ios`,
281
280
  }),
282
281
  })
283
282
  }),
284
283
  ])
285
284
  }
286
285
  }
287
286
  }
288
287
  getAPPUseStraightCorner() {
289
288
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable'
290
289
  const params = {
291
290
  routerURL,
292
291
  routerParam: {},
293
292
  jdRouter: '1',
294
293
  }
295
294
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
296
295
  return Promise.resolve(this.info.sysInfo.jdStraightCorner)
297
296
  } else {
298
297
  return this.jmfeReayPromise()
299
298
  .then(() => {
300
299
  if(isJdAndHarmonyDevice || !isJdApp) {
301
300
  console.log('not APP or is Harmony')
302
301
  return Promise.resolve(false)
303
302
  }
304
303
  console.log('jmfe setShareInfo', params)
305
304
  return Promise.race([window.jmfe.callRouter(params), this.taskTimeoutPromise(() => {return false})])
306
305
  .then(({ status, data }) => {
307
306
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data)
308
307
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status)
309
308
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1
310
309
  return Promise.resolve( status === '0' && Number(data) === 1)
311
310
  })
312
311
  })
313
312
  .catch(e => {
314
313
  console.log('jmfe error', e)
315
314
  return Promise.resolve(false)
316
315
  })
317
316
  }
318
317
  }
319
318
 
320
319
  getJDAppearanceStatePromise() {
321
320
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
322
321
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
323
322
  } else {
324
323
  return Promise.race([
325
324
  this.taskTimeoutPromise(() => {
326
325
  this.info.sysInfo.jdAppearanceState = '0'
327
326
  return this.info.sysInfo.jdAppearanceState
328
327
  }),
329
328
  new Promise(resolve => {
330
329
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
331
330
  if (!window[getCallBackName]) {
332
331
  window[getCallBackName] = res => {
333
332
  try {
334
333
  console.log('getJDAppearanceStatePromise', res)
335
334
  const getResJson =
336
335
  typeof res === 'string' ? JSON.parse(res) : res
337
336
  const { status, data, msg } = getResJson
338
337
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
339
338
  if (status === '0') {
340
339
  this.info.sysInfo.jdAppearanceState = data
341
340
  resolve(data)
342
341
  } else {
343
342
  resolve('0')
344
343
  }
345
344
  } catch (e) {
346
345
  resolve('0')
347
346
  }
348
347
  window[getCallBackName] = null
349
348
  }
350
349
  }
351
350
  if (isAndroidDevice) {
352
351
  const jsonString = JSON.stringify({
353
352
  callBackName: `window.${getCallBackName}`,
354
353
  })
355
354
  console.log('window.JDAppearance', window.JDAppearance)
356
355
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
357
356
  } else {
358
357
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
359
358
  method: 'callSyncRouterModuleWithParams',
360
359
  params: JSON.stringify({
361
360
  routerURL:
362
361
  'router://JDWebViewBusinessModule/getJDAppearanceState',
363
362
  routerParam: {},
364
363
  callBackName: `window.${getCallBackName}`,
365
364
  callBackId: `${getCallBackName}Ios`,
366
365
  }),
367
366
  })
368
367
  }
369
368
  }),
370
369
  ])
371
370
  }
372
371
  }
373
372
 
374
373
  createJdAndroidRquestEventForTouchStart() {
375
374
  if (isJdAndAndroidDevice && window.JdAndroid) {
376
375
  const rootEleNode = document.querySelector('body')
377
376
  if (rootEleNode) {
378
377
  rootEleNode.addEventListener(
379
378
  'touchstart',
380
379
  this.jdAndroidAddEventListenerTouchStart,
381
380
  false,
382
381
  )
383
382
  }
384
383
  }
385
384
  }
386
385
  jdAndroidAddEventListenerTouchStart(e) {
387
386
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
388
387
  if (!isH5SwiperCustomEle) {
389
388
  const hasCustomEle = e
390
389
  ? e?.target?.closest('.J_customScroll') ||
391
390
  e?.target?.closest('.J_customLayout')
392
391
  : false
393
392
  if (!hasCustomEle) {
394
393
  window.JdAndroid.requestEvent(false)
395
394
  console.log(
396
395
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
397
396
  )
398
397
  }
399
398
  }
400
399
  }
401
400
  removeJdAndroidRquestEventForTouchStart() {
402
401
  if (isJdAndAndroidDevice && window.JdAndroid) {
403
402
  const rootEleNode = document.querySelector('body')
404
403
  if (rootEleNode) {
405
404
  rootEleNode.removeEventListener(
406
405
  'touchstart',
407
406
  this.jdAndroidAddEventListenerTouchStart,
408
407
  false,
409
408
  )
410
409
  }
411
410
  }
412
411
  }
413
412
 
414
413
  getNetWorkType() {
415
414
  if (isJdApp) {
416
415
  this.jmfeReayPromise().then(() => {
417
416
  window.jmfe
418
417
  .getNetworkStatus()
419
418
  .then(({ status, data }) => {
420
419
  console.log(
421
420
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
422
421
  data,
423
422
  )
424
423
  if (status === '0') {
425
424
  this.info.sysInfo['netWorkType'] = data
426
425
  } else {
427
426
  this._taroGetNetworkType()
428
427
  }
429
428
  })
430
429
  .catch(err => {
431
430
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
432
431
  this._taroGetNetworkType()
433
432
  })
434
433
  })
435
434
  } else {
436
435
  this._taroGetNetworkType()
437
436
  }
438
437
  }
439
438
  _taroGetNetworkType() {
440
439
  Taro.getNetworkType().then(getRes => {
441
440
  if (getRes && getRes.networkType) {
442
441
  this.info.sysInfo['netWorkType'] = getRes.networkType
443
442
  console.log(
444
443
  '在app内通过taro对象获取网络状态完成,当前网络状态',
445
444
  this.info.sysInfo['netWorkType'],
446
445
  )
447
446
  }
448
447
  })
449
448
  }
450
449
 
451
450
  getCacheAddressRouter() {
452
451
  if (!window.jmfe) return
453
452
  if (isAndroidDevice) {
454
453
  return window.jmfe.callRouter({
455
454
  jdRouter: '1',
456
455
  routerURL: 'router://JDAddressModule/getCacheAddress',
457
456
  routerParam: { sceneId: 'basicShoppingProcess' },
458
457
  })
459
458
  } else if (isIosDevice) {
460
459
  return window.jmfe.callRouter({
461
460
  jdRouter: '1',
462
461
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
463
462
  routerParam: { sceneId: 'basicShoppingProcess' },
464
463
  })
465
464
  } else if (isJdAndHarmonyDevice) {
466
465
  return new Promise(resolve => {
467
466
  resolve({})
468
467
  })
469
468
  } else {
470
469
  throw Error(
471
470
  'Unknown device type cannot obtain the address information through the route!',
472
471
  )
473
472
  }
474
473
  }
475
474
 
476
475
  getAddressCachePromise() {
477
476
  return new Promise(resolve => {
478
477
  if (
479
478
  this?.info?.sysInfo?.lat &&
480
479
  this?.info?.sysInfo?.lng &&
481
480
  this?.info?.sysInfo?.area
482
481
  ) {
483
482
  resolve({
484
483
  lat: this.info.sysInfo.lat,
485
484
  lng: this.info.sysInfo.lng,
486
485
  area: this?.info?.sysInfo?.area,
487
486
  })
488
487
  } else {
489
488
  this.jmfeReayPromise().then(() => {
490
489
  this.getCacheAddressRouter()
491
490
  .then(({ status, data }) => {
492
491
  console.log("原生端获取经纬度原始数据结果",status,data)
493
492
  if (status === '0' && data) {
494
493
  const {
495
494
  lat,
496
495
  latitude,
497
496
  lng,
498
497
  longitude,
499
498
  provinceId,
500
499
  cityId,
501
500
  countyId,
502
501
  townId,
503
502
  } = data || {}
504
503
  let area = ''
505
504
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
506
505
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
507
506
  if (provinceId) {
508
507
  area = `${provinceId}_${cityId || 0}_${countyId ||
509
508
  0}_${townId || 0}`
510
509
  this.info.pageInfo['address'] = area
511
510
  this.info.pageInfo['addressCommaStr'] = area.replace(
512
511
  /_/g,
513
512
  ',',
514
513
  )
515
514
  }
516
515
  resolve({
517
516
  lat: this.info.sysInfo['lat'],
518
517
  lng: this.info.sysInfo['lng'],
519
518
  area: area,
520
519
  })
521
520
  } else {
522
521
  resolve({ lat: '', lng: '', area: '' })
523
522
  }
524
523
  })
525
524
  .catch(e => {
526
525
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
527
526
  resolve({ lat: '', lng: '', area: '' })
528
527
  console.log('判断jmfe不存在,获取经纬度信息异常')
529
528
  })
530
529
  })
531
530
  }
532
531
  })
533
532
  }
534
533
 
535
534
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
536
535
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
537
536
  if (!isJdApp) {
538
537
  return
539
538
  }
540
539
  const avifSwitch = await getMPaasConfigByBussinessKey(
541
540
  'avifSwitch',
542
541
  isBeforePageReady,
543
542
  )
544
543
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
545
544
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
546
545
  'isFollowAppVideoPlayStatus',
547
546
  isBeforePageReady,
548
547
  )
549
548
  console.log(
550
549
  'isBeforePageReady:',
551
550
  isBeforePageReady,
552
551
  'isFollowAppVideoPlayStatus:',
553
552
  isFollowAppVideoPlayStatus,
554
553
  )
555
554
  if (
556
555
  isFollowAppVideoPlayStatus === true ||
557
556
  isFollowAppVideoPlayStatus === 'true'
558
557
  ) {
559
558
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
560
559
  }
561
560
  }
562
561
 
563
562
  async getWifiVideoAutoPlayAsync() {
564
563
  this.info.sysInfo['wifiVideoAutoPlay'] = false
565
564
  if (!isJdApp) {
566
565
  return
567
566
  }
568
567
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
569
568
  return 0
570
569
  })
571
570
  if (Number(videoPlayStatus) === 1) {
572
571
  this.info.sysInfo['wifiVideoAutoPlay'] = true
573
572
  }
574
573
  }
575
574
 
576
575
  async getMPaasConfigAsync() {
577
576
  this.info.sysInfo.dynamicConfig = {}
578
577
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
579
578
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
580
579
  return this.updateMPaasConfigAsync(true)
581
580
  }
582
581
 
583
582
  getDynamicConfig(key: string){
584
583
  return this.info.sysInfo.dynamicConfig[key]
585
584
  }
586
585
  async updateMPaasConfig() {
587
586
  console.log('updateMPaasConfig')
588
587
  if (
589
588
  isIosDevice &&
590
589
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
591
590
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
592
591
  ) {
593
592
  try {
594
593
  await this.updateMPaasConfigAsync(false)
595
594
  } catch (e) {
596
595
  console.log('updateMPaasConfigAsync:', e)
597
596
  }
598
597
  }
599
598
  }
600
599
 
601
600
  toLogin(options) {
602
601
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
603
602
  ? this.toWxAppLogin(options)
604
603
  : this.toWebLogin(options)
605
604
  }
606
605
 
607
606
  doLogin(options) {
608
607
  return this.toLogin(options)
609
608
  }
610
609
 
611
610
  doLoginForJdPin(options = {}) {
612
611
  return this.doLogin({
613
612
  loginColor: {
614
613
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
615
614
  dpin: 0,
616
615
  },
617
616
  ...options,
618
617
  })
619
618
  }
620
619
 
621
620
  toWebLogin(options) {
622
621
  let params: {
623
622
  returnurl: string
624
623
  } = {
625
624
  returnurl: '',
626
625
  }
627
626
  const loginUrl = isPc
628
627
  ? `//passport.jd.com/new/login.aspx`
629
628
  : `${domain.mobileLogin}/user/login.action`
630
629
  const defaultParams = {
631
630
  appid: '100',
632
631
  returnurl: window.location.href,
633
632
  }
634
633
  if (isString(options)) {
635
634
  params = Object.assign({}, defaultParams, {
636
635
  returnurl: options,
637
636
  })
638
637
  } else if (isObject(options)) {
639
638
  const { loginColor, ...otherOptions } = options
640
639
  params = Object.assign({}, defaultParams, otherOptions)
641
640
  } else {
642
641
  params = defaultParams
643
642
  }
644
643
  params.returnurl = encodeURIComponent(params.returnurl)
645
644
  let getFullUrl = loginUrl + '?' + serialize(params)
646
645
  if (isPc) {
647
646
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
648
647
  }
649
648
  return Promise.resolve({
650
649
  h5ToUrl: true,
651
650
  url: getFullUrl,
652
651
  }).then(() => {
653
652
  window.location.href = getFullUrl
654
653
  })
655
654
  }
656
655
 
657
656
  toWxAppLogin(options = {}) {
658
657
  console.log('微信京购小程序中h5登录跳转', options)
659
658
  return Promise.resolve(true).then(() => {
660
659
  const { loginColor } = Object.assign(
661
660
  {},
662
661
  {
663
662
  loginColor: {
664
663
  biz: WXAPP_BIZ_KEY,
665
664
  dpin: 1,
666
665
  },
667
666
  },
668
667
  options,
669
668
  )
670
669
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
671
670
  loginColor.biz
672
671
  }&url=${encodeURIComponent(window.location.href)}`
673
672
  })
674
673
  }
675
674
 
676
675
  getLoginCookie() {
677
676
  return Promise.resolve({
678
677
  pin: cookie.get('pin') || '',
679
678
  })
680
679
  }
681
680
 
682
681
  clearLoginCookie() {
683
682
  cookie.remove('pin')
684
683
  }
685
684
 
686
685
  checkStatusAndLogin(options = {}) {
687
686
  if (!this.checkStatusAndLoginPromise) {
688
687
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
689
688
  try {
690
689
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
691
690
  options,
692
691
  )
693
692
  if (getLoginState) {
694
693
  resolve(true)
695
694
  } else {
696
695
  this.toLogin(options)
697
696
  reject(false)
698
697
  }
699
698
  } catch (e) {
700
699
  this.toLogin(options)
701
700
  reject(false)
702
701
  }
703
702
  })
704
703
  return this.checkStatusAndLoginPromise
705
704
  } else {
706
705
  return this.checkStatusAndLoginPromise
707
706
  .then(() => {
708
707
  return Promise.resolve(true)
709
708
  })
710
709
  .catch(() => {
711
710
  this.toLogin(options)
712
711
  return Promise.reject(true)
713
712
  })
714
713
  }
715
714
  }
716
715
 
717
716
  checkJdStatusAndLogin(
718
717
  options = {
719
718
  loginColor: {
720
719
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
721
720
  dpin: 0,
722
721
  },
723
722
  },
724
723
  ) {
725
724
  return this.checkStatusAndLogin(options)
726
725
  }
727
726
 
728
727
  doCheckLoginStateAndForApiCheck(options) {
729
728
  if (this.info.loginState) {
730
729
  return Promise.resolve(true)
731
730
  } else {
732
731
  return new Promise((resolve, reject) => {
733
732
  if (
734
733
  this.info.isJingGouMiniViewState ||
735
734
  this.info.isJingxiMiniViewState
736
735
  ) {
737
736
  const getWqAuthToken = cookie.get('wq_auth_token')
738
737
  const getWqSkey = cookie.get('wq_skey')
739
738
  const getWqUin = cookie.get('wq_uin')
740
739
  const isLoginState =
741
740
  options?.loginColor?.dpin === 0
742
741
  ? getWqAuthToken
743
742
  : getWqSkey && getWqUin
744
743
  if (isLoginState) {
745
744
  this.info.loginState = true
746
745
  resolve(true)
747
746
  } else {
748
747
  reject(false)
749
748
  }
750
749
  } else {
751
750
  Taro.request({
752
751
  url: api.isLogin,
753
752
  jsonp: true,
754
753
  timeout: 3000,
755
754
  success: res => {
756
755
  const { statusCode, data } = res
757
756
  if (
758
757
  statusCode === 200 &&
759
758
  data?.islogin &&
760
759
  Number(data.islogin) === 1
761
760
  ) {
762
761
  this.info.loginState = true
763
762
  resolve(true)
764
763
  } else {
765
764
  reject(false)
766
765
  }
767
766
  },
768
767
  fail: err => {
769
768
  console.log('登录检查异常', err)
770
769
  reject(false)
771
770
  },
772
771
  })
773
772
  }
774
773
  })
775
774
  }
776
775
  }
777
776
 
778
777
  checkLoginStatus(options) {
779
778
  return new Promise(async (resolve, reject) => {
780
779
  try {
781
780
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
782
781
  options,
783
782
  )
784
783
  if (getLoginState) {
785
784
  const { pin } = await this.getLoginCookie()
786
785
  this.info.userInfo = {
787
786
  pin,
788
787
  encodePin: encodeURIComponent(pin),
789
788
  ptkey: '',
790
789
  }
791
790
  resolve(true)
792
791
  } else {
793
792
  reject(false)
794
793
  }
795
794
  } catch (e) {
796
795
  reject(false)
797
796
  }
798
797
  })
799
798
  }
800
799
 
801
800
  updatePageAndLogInfo(updateQuery = {}) {
802
801
  const createUpdateQueryInfo: {
803
802
  query: {
804
803
  shopId?: string | number
805
804
  venderId?: string | number
806
805
  }
807
806
  updateShopInfoState: boolean
808
807
  } = Object.assign(
809
808
  {},
810
809
  {
811
810
  query: {},
812
811
  updateShopInfoState: false,
813
812
  },
814
813
  updateQuery,
815
814
  )
816
815
  console.log(
817
816
  '获取当前下发的店铺查询参数',
818
817
  updateQuery,
819
818
  '获取之前保存的shopInfo店铺查询参数',
820
819
  this.info?.shopInfo,
821
820
  )
822
821
  const { query, updateShopInfoState } = createUpdateQueryInfo
823
822
  const { shopId, venderId, un_area } = query
824
823
  if (updateShopInfoState) {
825
824
  this.info.queryInfo = {
826
825
  ...this.info.queryInfo,
827
826
  ...query,
828
827
  }
829
828
  if (shopId && venderId) {
830
829
  this.info.shopInfo = {
831
830
  shopId: `${shopId}`,
832
831
  venderId: `${venderId}`,
833
832
  }
834
833
  }
835
834
  } else {
836
835
  this.info.queryInfo = {
837
836
  ...query,
838
837
  }
839
838
  if (
840
839
  this.info.shopInfo?.shopId &&
841
840
  this.info.shopInfo?.venderId &&
842
841
  (this.info.shopInfo.shopId == shopId ||
843
842
  this.info.shopInfo.venderId == venderId)
844
843
  ) {
845
844
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
846
845
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
847
846
  console.log(
848
847
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
849
848
  this.info.queryInfo,
850
849
  )
851
850
  }
852
851
  }
853
852
  this.info.queryInfo['shopId'] &&
854
853
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
855
854
  this.info.queryInfo['venderId'] &&
856
855
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
857
856
  console.log(
858
857
  'h5==获取店铺下发查询参数\n',
859
858
  query,
860
859
  '\n获取店铺最后查询参数\n',
861
860
  this.info.queryInfo,
862
861
  '\n是否为更新店铺状态\n',
863
862
  updateShopInfoState,
864
863
  )
865
864
  const changeArea =
866
865
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
867
866
  if (changeArea) {
868
867
  this.info.pageInfo.address = changeArea
869
868
  this.info.pageInfo.un_area = changeArea
870
869
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
871
870
  }
872
871
  }
873
872
 
874
873
  dealLoadSdkList(){
875
874
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
876
875
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? []
877
876
  const concatLoadJsList = [].concat(globalLoadJsList,businessLoadJsList)
878
877
  let mergeLoadJsList = globalLoadJsList
879
878
  try {
880
879
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
881
880
  const getFindIndex = accArr.findIndex(item => item?.fileName === current?.fileName);
882
881
  getFindIndex !== -1 ? (accArr[getFindIndex] = {...accArr[getFindIndex],...current }) : accArr.push(current);
883
882
  return accArr;
884
883
  }, []);
885
884
  }catch (e) {
886
885
  console.log("LoadJsList合并错误", e)
887
886
  }
888
887
  console.log("globalLoadJsList",globalLoadJsList,"businessLoadJsList",businessLoadJsList,"两个加载jsList集合合并完成", mergeLoadJsList)
889
888
  this.loadJsSdkList = mergeLoadJsList
890
889
  return this.loadJsSdkList
891
890
  }
892
891
 
893
892
  renderNextTickLoadSdk(){
894
893
  Taro.nextTick(() => {
895
894
  console.log("页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======")
896
895
  setTimeout(() => {
897
896
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK,this.loadJsSdkList)
898
897
  },1000)
899
898
  })
900
899
  }
901
900
 
902
901
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW,loadJsList:any[] = [] ) {
903
902
  const getLoadJsList = Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList()
904
903
  const getLoadFilterList = getLoadJsList.filter(item => {
905
904
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL
906
905
  let getLoastLoadEventState = true
907
906
  if(getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP){
908
907
  getLoastLoadEventState = isJdApp
909
908
  }
910
909
  else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
911
910
  getLoastLoadEventState = !isJdApp
912
911
  }
913
912
  const getInitTriggerType = isJdApp && item?.initJdAppTriggerType ? item?.initTriggerType : item?.initTriggerType || LoadJsInitTriggerType.NOW
914
913
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false
915
914
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay
916
915
  })
917
916
  console.log("获取当前触发方式",triggerType,"获取当前最后加载的js集合",getLoadFilterList,"过滤前的加载集合",getLoadJsList)
918
917
  getLoadFilterList.length > 0 && getLoadFilterList.forEach((item) => {
919
918
  const isLoadState = /sgm/.test(item?.fileName) ? window?.shopGlobalSwitch?.openSgm === "true" : true
920
919
  isLoadState && this.loadItemSdkPromise(item)
921
920
  .then((res) => {
922
921
  console.info('当前js地址' + item?.src, '加载状态', res)
923
922
  })
924
923
  .catch((err) => {
925
924
  console.info('当前js地址加载异常', item?.src)
926
925
  window?.fetchErrorData &&
927
926
  window.fetchErrorData({
928
927
  title: '公共js加载异常',
929
928
  type: "jsLoad",
930
929
  data: err,
931
930
  })
932
931
  })
933
932
  })
934
933
  }
935
934
  loadScriptEle(jsInfo,resolve,reject){
936
935
  const getFileName = jsInfo?.fileName;
937
936
  if(getFileName){
938
937
  const getEleId = `J_loadJs_${getFileName}`
939
938
  const getEle = document.getElementById(getEleId)
940
939
  if (!getEle) {
941
940
  const jsLoadErrorSgmCode = `jsLoadError_${
942
941
  jsInfo?.fileName || 'customJs'
943
942
  }`
944
943
  const _sgmEle = document.createElement('script')
945
944
  _sgmEle.id = getEleId
946
945
  _sgmEle.onload = function () {
947
946
  resolve({
948
947
  ...jsInfo,
949
948
  jsTip: "js加载成功",
950
949
  })
951
950
  }
952
951
  _sgmEle.onerror = function () {
953
952
  reject({
954
953
  ...jsInfo,
955
954
  env: getSgmCustomCode(jsLoadErrorSgmCode),
956
955
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
957
956
  })
958
957
  }
959
958
  const dataAttrList = ['timeout','fileName',"env"]
960
959
  const getJsInfoKeyList = Object.keys(jsInfo)
961
960
  getJsInfoKeyList.forEach(key => {
962
961
  if(key === "async"){
963
962
  _sgmEle.async = jsInfo[key]
964
963
  }else if(key === "crossOrigin"){
965
964
  _sgmEle.crossOrigin = jsInfo[key]
966
965
  }else if(key === "src"){
967
966
  _sgmEle.src = `${jsInfo[key]}`
968
967
  }else if(dataAttrList.includes(key) || /init/.test(key)) {
969
968
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key])
970
969
  }else {
971
970
  _sgmEle.setAttribute(key, jsInfo[key])
972
971
  }
973
972
  })
974
973
  document.head.appendChild(_sgmEle)
975
974
  }else {
976
975
  console.log(`当前${jsInfo?.fileName || "js"}已经存在页面中,可以直接调用相关方法`,jsInfo)
977
976
  resolve({
978
977
  ...jsInfo,
979
978
  jsTip: "js本身已存在页面中",
980
979
  })
981
980
  }
982
981
  }else {
983
982
  console.warn("当前js资源信息缺少必要的参数fileName,请关注",jsInfo)
984
983
  }
985
984
  }
986
985
 
987
986
  loadItemSdkPromise(jsInfo = {}){
988
987
  if(jsInfo?.src){
989
988
  const getInitLoadType = isJdApp && jsInfo?.initJdAppLoadType ? jsInfo?.initJdAppLoadType : jsInfo?.initLoadType || LoadJsInitLoadType.ALL
990
989
  if(getInitLoadType !== LoadJsInitLoadType.NONE){
991
990
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src
992
991
  if (!this.loadJsSdkListCachePromise[getFileKeyName]){
993
992
  if(getInitLoadType !== LoadJsInitLoadType.INSERT_ELE){
994
993
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
995
994
  const jsLoadErrorSgmCode = `jsLoadError_${
996
995
  jsInfo?.fileName || 'customJs'
997
996
  }`
998
997
  try {
999
998
  const jsXhrRequest = new XMLHttpRequest();
1000
999
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000
1001
1000
  const jsUrl = `${jsInfo?.src}`
1002
1001
  jsXhrRequest.open('GET', jsUrl, true);
1003
1002
  jsXhrRequest.onload = () => {
1004
1003
  if (jsXhrRequest.status === 200) {
1005
1004
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL
1006
1005
  if(getInsetHeadState){
1007
1006
  this.loadScriptEle(jsInfo,resolve,reject)
1008
1007
  }else {
1009
1008
  resolve({
1010
1009
  ...jsInfo,
1011
1010
  jsTip: "js请求成功,暂未插入head节点,业务自行单独插入",
1012
1011
  })
1013
1012
  }
1014
1013
  }else {
1015
1014
  const getRes = {
1016
1015
  ...jsInfo,
1017
1016
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1018
1017
  jsReqError: `请求状态异常,状态为${jsXhrRequest?.status}`,
1019
1018
  jsReqState: jsXhrRequest?.status,
1020
1019
  }
1021
1020
  console.log("当前js请求状态异常", getRes)
1022
1021
  reject(getRes)
1023
1022
  }
1024
1023
  }
1025
1024
  jsXhrRequest.onerror = () => {
1026
1025
  const getRes = {
1027
1026
  ...jsInfo,
1028
1027
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1029
1028
  jsReqError: '请求错误',
1030
1029
  }
1031
1030
  console.log("当前js请求错误", getRes)
1032
1031
  jsXhrRequest.abort()
1033
1032
  reject(getRes)
1034
1033
  }
1035
1034
  jsXhrRequest.ontimeout = () => {
1036
1035
  const getRes = {
1037
1036
  ...jsInfo,
1038
1037
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1039
1038
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
1040
1039
  }
1041
1040
  console.log("当前js请求超时异常", getRes)
1042
1041
  jsXhrRequest.abort()
1043
1042
  reject(getRes)
1044
1043
  }
1045
1044
  jsXhrRequest.send();
1046
1045
  }catch (e) {
1047
1046
  console.log("执行js请求异常",e)
1048
1047
  reject({
1049
1048
  ...jsInfo,
1050
1049
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1051
1050
  jsReqError: '未知异常',
1052
1051
  error: e,
1053
1052
  })
1054
1053
  }
1055
1054
  })
1056
1055
  }else {
1057
1056
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
1058
1057
  return this.loadScriptEle(jsInfo,resolve,reject)
1059
1058
  })
1060
1059
  }
1061
1060
  }
1062
1061
  return this.loadJsSdkListCachePromise[getFileKeyName]
1063
1062
  }else {
1064
1063
  return Promise.resolve({
1065
1064
  ...jsInfo,
1066
1065
  jsTip: "js加载方式设置为不加载,当前不做处理",
1067
1066
  })
1068
1067
  }
1069
1068
  }else {
1070
1069
  return Promise.reject(jsInfo)
1071
1070
  }
1072
1071
  }
1072
+ import Taro from '@tarojs/taro'
1073
1073
  isIosDevice,
1074
1074
  isAndroidDevice,
1075
1075
  isJdAndHarmonyDevice,
1076
1076
  isJdAndAndroidDevice,
1077
1077
  jdAppVersion,
1078
1078
  jdAppVersionStr,
1079
1079
  isString,
1080
1080
  isObject,
1081
1081
  serialize,
1082
1082
  dealNativePixelToCssPixel,
1083
1083
  isPc,
1084
1084
  BUSINESS_TYPE,
1085
1085
  JSSDK_APP_WEBVIEW_CODE,
1086
1086
  SECTION_HOME_TAB_NAME_TYPE,
1087
1087
  SECTION_HOME_TAB_TYPE,
1088
1088
  WXAPP_BIZ_KEY,
1089
1089
  WX_BUSINESS_TYPE,
1090
1090
  MPAAS_CONFIG_APP_VERSION,
1091
1091
  MPAAS_CONFIG_APP_LOW_VERSION,
1092
1092
  WXAPP_BIZ_SHOP_LIGHT_KEY,
1093
1093
  LoadJsInitLoadEnvType,
1094
1094
  LoadJsInitLoadType,
1095
1095
  LoadJsInitTriggerType
1096
1096
  const designWidth = 750
1097
1097
  return (
1098
1098
  Math.ceil(
1099
1099
  (((parseInt(String(size), 10) / 40) * 750) / designWidth) * 10000,
1100
1100
  ) /
1101
1101
  10000 +
1102
1102
  'rem'
1103
1103
  )
1104
1104
  loginState: false,
1105
1105
  cookiesStr: '',
1106
1106
  userInfo: userPinKey,
1107
1107
  isJingGouMiniViewState: false,
1108
1108
  isJingxiMiniViewState: false,
1109
1109
  pageInfo: {
1110
1110
  wxBusinessType: WX_BUSINESS_TYPE.NO,
1111
1111
  address: '',
1112
1112
  addressCommaStr: '',
1113
1113
  un_area: '',
1114
1114
  vapptype: '1',
1115
1115
  pageType: 'home',
1116
1116
  isExposureState: false,
1117
1117
  moduleId: '',
1118
1118
  entrance: '',
1119
1119
  dataType: BUSINESS_TYPE.ONLINE,
1120
1120
  floorExposureInfo: {},
1121
1121
  floorVideInfo: {},
1122
1122
  productVideInfo: {},
1123
1123
  tabsLoadAllDataInfo: {
1124
1124
  [SECTION_HOME_TAB_NAME_TYPE[
1125
1125
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
1126
1126
  ]]: false,
1127
1127
  },
1128
1128
  updateShopInfosAllState: false,
1129
1129
  isVipShop: false,
1130
1130
  isJdShowNativeImmersivePlayer: false,
1131
1131
  ...shopConfig,
1132
1132
  pageScrollTop: 0,
1133
1133
  pageIdxHeightInfo: {
1134
1134
  list: [],
1135
1135
  },
1136
1136
  shopNavBarHeight: 0,
1137
1137
  },
1138
1138
  defaultQueryLogInfo: {
1139
1139
  sourceType: 'JDshop',
1140
1140
  sourceValue: '',
1141
1141
  moduleId: 'none',
1142
1142
  entrance: 'none',
1143
1143
  },
1144
1144
  sysInfo: {
1145
1145
  windowWidth: isPc ? 375 : 0,
1146
1146
  containerWidth: isPc ? 375 : 0,
1147
1147
  windowHeight: 0,
1148
1148
  netWorkType: '4g',
1149
1149
  jdBottomBarHeight: 0,
1150
1150
  jdNativeHeaderHeight: 0,
1151
1151
  },
1152
1152
  queryInfo: {},
1153
1153
  shopInfo: {},
1154
1154
  openAppData: {},
1155
1155
  public info: CommonInterFace.BaseConfigInfo
1156
1156
  public config: {
1157
1157
  [key: string]: any
1158
1158
  }
1159
1159
  public lazyContainer: CommonInterFace.lazyContainer
1160
1160
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
1161
1161
  public rootEleNode: HTMLElement | null
1162
1162
  public checkStatusAndLoginPromise: object | null
1163
1163
  private jmfeRegisterStatePromise: Promise<any> | null
1164
1164
  private jmfeRegisterState: boolean
1165
1165
  public loadJsSdkList: Array<any>
1166
1166
  public loadJsSdkListCachePromise: any
1167
1167
  constructor(opt) {
1168
1168
  this.info = this._getConfig(opt)
1169
1169
  this.config = {}
1170
1170
  this.loadJsSdkList = []
1171
1171
  this.loadJsSdkListCachePromise = {}
1172
1172
  this.lazyContainer = {
1173
1173
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
1174
1174
  appLazyContainerList: [],
1175
1175
  appLazyFinishContainerList: [],
1176
1176
  },
1177
1177
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
1178
1178
  appLazyContainerList: [],
1179
1179
  appLazyFinishContainerList: [],
1180
1180
  },
1181
1181
  }
1182
1182
  this.renderedIsvComponents = {}
1183
1183
  this.rootEleNode = document.querySelector('body')
1184
1184
  this.checkStatusAndLoginPromise = null
1185
1185
  this.jmfeRegisterStatePromise = null
1186
1186
  this.loadOtherSdk()
1187
1187
  isJdApp && this.jmfeReayPromise()
1188
1188
  }
1189
1189
  _getConfig(opt) {
1190
1190
  return Object.assign({}, DefaultConfig, opt)
1191
1191
  }
1192
1192
 
1193
1193
  jmfeReayPromise(): Promise<any> {
1194
1194
  if (isJdApp) {
1195
1195
  if (this.jmfeRegisterState) {
1196
1196
  return Promise.resolve(true)
1197
1197
  } else {
1198
1198
  !this.jmfeRegisterStatePromise &&
1199
1199
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
1200
1200
  ready('jmfe', 3000)
1201
1201
  .then(() => {
1202
1202
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
1203
1203
  this.jmfeRegisterState = true
1204
1204
  resolve(true)
1205
1205
  console.log('松果app内初始化注册jmfe认证完成')
1206
1206
  })
1207
1207
  .catch(() => {
1208
1208
  reject(false)
1209
1209
  })
1210
1210
  }))
1211
1211
  return this.jmfeRegisterStatePromise
1212
1212
  }
1213
1213
  } else {
1214
1214
  return Promise.reject(false)
1215
1215
  }
1216
1216
  }
1217
1217
 
1218
1218
  updateBusinessDomainAndApi(domain, api) {
1219
1219
  }
1220
1220
 
1221
1221
  formatNativeScreenPageData(action) {
1222
1222
  let getChangePageInfo: any = null
1223
1223
  try {
1224
1224
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
1225
1225
  JSON.stringify({
1226
1226
  plugin: 'JDHybridScreenPlugin',
1227
1227
  action,
1228
1228
  sync: '1',
1229
1229
  }),
1230
1230
  )
1231
1231
  const getChangePageInfoData =
1232
1232
  typeof getNativeScreenPageInfoStr === 'string'
1233
1233
  ? JSON.parse(getNativeScreenPageInfoStr)
1234
1234
  : null
1235
1235
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
1236
1236
  const { code, data } = getChangePageInfoData
1237
1237
  getChangePageInfo = code && code === '0' ? data : null
1238
1238
  }
1239
1239
  } catch (e) {
1240
1240
  console.log('JDHybridScreenPlugin转换异常', e)
1241
1241
  }
1242
1242
  return getChangePageInfo
1243
1243
  }
1244
1244
 
1245
1245
  isAndroidFoldScreen() {
1246
1246
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
1247
1247
  }
1248
1248
 
1249
1249
  getJdAndroidPageChangeScreenInfo() {
1250
1250
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
1251
1251
  if (
1252
1252
  getPageScreenInfo &&
1253
1253
  getPageScreenInfo?.pageWidth &&
1254
1254
  getPageScreenInfo?.pageHeight
1255
1255
  ) {
1256
1256
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1257
1257
  pageWidth: getPageScreenInfo.pageWidth,
1258
1258
  pageHeight: getPageScreenInfo.pageHeight,
1259
1259
  })
1260
1260
  getPageScreenInfo.pageWidth = pageWidth
1261
1261
  getPageScreenInfo.pageHeight = pageHeight
1262
1262
  }
1263
1263
  return getPageScreenInfo
1264
1264
  }
1265
1265
 
1266
1266
  getSystemInfo(params) {
1267
1267
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
1268
1268
  ? {}
1269
1269
  : getSystemInfos(params)
1270
1270
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
1271
1271
  const isfoldScreen = this.isAndroidFoldScreen()
1272
1272
  if (isfoldScreen) {
1273
1273
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
1274
1274
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
1275
1275
  console.info(
1276
1276
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
1277
1277
  getJdAndroidPageInfo,
1278
1278
  )
1279
1279
  }
1280
1280
  }
1281
1281
  this.info.sysInfo = {
1282
1282
  actualNavBarHeight: 0,
1283
1283
  ...this.info.sysInfo,
1284
1284
  ...info,
1285
1285
  safeContentHeight: info?.screenHeight,
1286
1286
  headerHeight: 0,
1287
1287
  tabBarHeight: 0,
1288
1288
  }
1289
1289
  if (isJdApp) {
1290
1290
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
1291
1291
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
1292
1292
  this.getAddressCachePromise()
1293
1293
  this.getElderModePromise()
1294
1294
  this.getJDAppearanceStatePromise()
1295
1295
  this.createJdAndroidRquestEventForTouchStart()
1296
1296
  }
1297
1297
  this.getWifiVideoAutoPlayAsync()
1298
1298
  this.getMPaasConfigAsync()
1299
1299
  this.getNetWorkType()
1300
1300
  }
1301
1301
 
1302
1302
  taskTimeoutPromise(callBack, timeout = 2000) {
1303
1303
  return new Promise(resolve => {
1304
1304
  setTimeout(() => {
1305
1305
  const getCallBackRes = typeof callBack === 'function' && callBack()
1306
1306
  return resolve(getCallBackRes || false)
1307
1307
  }, timeout)
1308
1308
  })
1309
1309
  }
1310
1310
 
1311
1311
  getElderModePromise() {
1312
1312
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1313
1313
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1314
1314
  } else {
1315
1315
  if (isJdAndAndroidDevice) {
1316
1316
  this.info.sysInfo.jdAppModeType = '0'
1317
1317
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1318
1318
  } else {
1319
1319
  return Promise.race([
1320
1320
  this.taskTimeoutPromise(() => {
1321
1321
  this.info.sysInfo.jdAppModeType = '0'
1322
1322
  return this.info.sysInfo.jdAppModeType
1323
1323
  }),
1324
1324
  new Promise(resolve => {
1325
1325
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
1326
1326
  if (!window[getCallBackName]) {
1327
1327
  window[getCallBackName] = res => {
1328
1328
  try {
1329
1329
  const getResJson =
1330
1330
  typeof res === 'string' ? JSON.parse(res) : res
1331
1331
  const { status, data, msg } = getResJson
1332
1332
  console.log(`获取松果app展示模式成功,返回结果${data}`)
1333
1333
  if (status === '0') {
1334
1334
  this.info.sysInfo.jdAppModeType = data
1335
1335
  resolve(data)
1336
1336
  } else {
1337
1337
  resolve('0')
1338
1338
  }
1339
1339
  } catch (e) {
1340
1340
  resolve('0')
1341
1341
  }
1342
1342
  window[getCallBackName] = null
1343
1343
  }
1344
1344
  }
1345
1345
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1346
1346
  method: 'callSyncRouterModuleWithParams',
1347
1347
  params: JSON.stringify({
1348
1348
  routerURL: 'router://JDBModeModule/getCurrentMode',
1349
1349
  routerParam: {},
1350
1350
  callBackName: `window.${getCallBackName}`,
1351
1351
  callBackId: `${getCallBackName}Ios`,
1352
1352
  }),
1353
1353
  })
1354
1354
  }),
1355
1355
  ])
1356
1356
  }
1357
1357
  }
1358
1358
  }
1359
1359
  getAPPUseStraightCorner() {
1360
1360
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable'
1361
1361
  const params = {
1362
1362
  routerURL,
1363
1363
  routerParam: {},
1364
1364
  jdRouter: '1',
1365
1365
  }
1366
1366
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
1367
1367
  return Promise.resolve(this.info.sysInfo.jdStraightCorner)
1368
1368
  } else {
1369
1369
  return this.jmfeReayPromise()
1370
1370
  .then(() => {
1371
1371
  if(isJdAndHarmonyDevice || !isJdApp) {
1372
1372
  console.log('not APP or is Harmony')
1373
1373
  return Promise.resolve(false)
1374
1374
  }
1375
1375
  console.log('jmfe setShareInfo', params)
1376
1376
  return Promise.race([window.jmfe.callRouter(params), this.taskTimeoutPromise(() => {return false})])
1377
1377
  .then(({ status, data }) => {
1378
1378
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data)
1379
1379
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status)
1380
1380
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1
1381
1381
  return Promise.resolve( status === '0' && Number(data) === 1)
1382
1382
  })
1383
1383
  })
1384
1384
  .catch(e => {
1385
1385
  console.log('jmfe error', e)
1386
1386
  return Promise.resolve(false)
1387
1387
  })
1388
1388
  }
1389
1389
  }
1390
1390
 
1391
1391
  getJDAppearanceStatePromise() {
1392
1392
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1393
1393
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
1394
1394
  } else {
1395
1395
  return Promise.race([
1396
1396
  this.taskTimeoutPromise(() => {
1397
1397
  this.info.sysInfo.jdAppearanceState = '0'
1398
1398
  return this.info.sysInfo.jdAppearanceState
1399
1399
  }),
1400
1400
  new Promise(resolve => {
1401
1401
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
1402
1402
  if (!window[getCallBackName]) {
1403
1403
  window[getCallBackName] = res => {
1404
1404
  try {
1405
1405
  console.log('getJDAppearanceStatePromise', res)
1406
1406
  const getResJson =
1407
1407
  typeof res === 'string' ? JSON.parse(res) : res
1408
1408
  const { status, data, msg } = getResJson
1409
1409
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
1410
1410
  if (status === '0') {
1411
1411
  this.info.sysInfo.jdAppearanceState = data
1412
1412
  resolve(data)
1413
1413
  } else {
1414
1414
  resolve('0')
1415
1415
  }
1416
1416
  } catch (e) {
1417
1417
  resolve('0')
1418
1418
  }
1419
1419
  window[getCallBackName] = null
1420
1420
  }
1421
1421
  }
1422
1422
  if (isAndroidDevice) {
1423
1423
  const jsonString = JSON.stringify({
1424
1424
  callBackName: `window.${getCallBackName}`,
1425
1425
  })
1426
1426
  console.log('window.JDAppearance', window.JDAppearance)
1427
1427
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
1428
1428
  } else {
1429
1429
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1430
1430
  method: 'callSyncRouterModuleWithParams',
1431
1431
  params: JSON.stringify({
1432
1432
  routerURL:
1433
1433
  'router://JDWebViewBusinessModule/getJDAppearanceState',
1434
1434
  routerParam: {},
1435
1435
  callBackName: `window.${getCallBackName}`,
1436
1436
  callBackId: `${getCallBackName}Ios`,
1437
1437
  }),
1438
1438
  })
1439
1439
  }
1440
1440
  }),
1441
1441
  ])
1442
1442
  }
1443
1443
  }
1444
1444
 
1445
1445
  createJdAndroidRquestEventForTouchStart() {
1446
1446
  if (isJdAndAndroidDevice && window.JdAndroid) {
1447
1447
  const rootEleNode = document.querySelector('body')
1448
1448
  if (rootEleNode) {
1449
1449
  rootEleNode.addEventListener(
1450
1450
  'touchstart',
1451
1451
  this.jdAndroidAddEventListenerTouchStart,
1452
1452
  false,
1453
1453
  )
1454
1454
  }
1455
1455
  }
1456
1456
  }
1457
1457
  jdAndroidAddEventListenerTouchStart(e) {
1458
1458
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
1459
1459
  if (!isH5SwiperCustomEle) {
1460
1460
  const hasCustomEle = e
1461
1461
  ? e?.target?.closest('.J_customScroll') ||
1462
1462
  e?.target?.closest('.J_customLayout')
1463
1463
  : false
1464
1464
  if (!hasCustomEle) {
1465
1465
  window.JdAndroid.requestEvent(false)
1466
1466
  console.log(
1467
1467
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1468
1468
  )
1469
1469
  }
1470
1470
  }
1471
1471
  }
1472
1472
  removeJdAndroidRquestEventForTouchStart() {
1473
1473
  if (isJdAndAndroidDevice && window.JdAndroid) {
1474
1474
  const rootEleNode = document.querySelector('body')
1475
1475
  if (rootEleNode) {
1476
1476
  rootEleNode.removeEventListener(
1477
1477
  'touchstart',
1478
1478
  this.jdAndroidAddEventListenerTouchStart,
1479
1479
  false,
1480
1480
  )
1481
1481
  }
1482
1482
  }
1483
1483
  }
1484
1484
 
1485
1485
  getNetWorkType() {
1486
1486
  if (isJdApp) {
1487
1487
  this.jmfeReayPromise().then(() => {
1488
1488
  window.jmfe
1489
1489
  .getNetworkStatus()
1490
1490
  .then(({ status, data }) => {
1491
1491
  console.log(
1492
1492
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
1493
1493
  data,
1494
1494
  )
1495
1495
  if (status === '0') {
1496
1496
  this.info.sysInfo['netWorkType'] = data
1497
1497
  } else {
1498
1498
  this._taroGetNetworkType()
1499
1499
  }
1500
1500
  })
1501
1501
  .catch(err => {
1502
1502
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
1503
1503
  this._taroGetNetworkType()
1504
1504
  })
1505
1505
  })
1506
1506
  } else {
1507
1507
  this._taroGetNetworkType()
1508
1508
  }
1509
1509
  }
1510
1510
  _taroGetNetworkType() {
1511
1511
  Taro.getNetworkType().then(getRes => {
1512
1512
  if (getRes && getRes.networkType) {
1513
1513
  this.info.sysInfo['netWorkType'] = getRes.networkType
1514
1514
  console.log(
1515
1515
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1516
1516
  this.info.sysInfo['netWorkType'],
1517
1517
  )
1518
1518
  }
1519
1519
  })
1520
1520
  }
1521
1521
 
1522
1522
  getCacheAddressRouter() {
1523
1523
  if (!window.jmfe) return
1524
1524
  if (isAndroidDevice) {
1525
1525
  return window.jmfe.callRouter({
1526
1526
  jdRouter: '1',
1527
1527
  routerURL: 'router://JDAddressModule/getCacheAddress',
1528
1528
  routerParam: { sceneId: 'basicShoppingProcess' },
1529
1529
  })
1530
1530
  } else if (isIosDevice) {
1531
1531
  return window.jmfe.callRouter({
1532
1532
  jdRouter: '1',
1533
1533
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1534
1534
  routerParam: { sceneId: 'basicShoppingProcess' },
1535
1535
  })
1536
1536
  } else if (isJdAndHarmonyDevice) {
1537
1537
  return new Promise(resolve => {
1538
1538
  resolve({})
1539
1539
  })
1540
1540
  } else {
1541
1541
  throw Error(
1542
1542
  'Unknown device type cannot obtain the address information through the route!',
1543
1543
  )
1544
1544
  }
1545
1545
  }
1546
1546
 
1547
1547
  getAddressCachePromise() {
1548
1548
  return new Promise(resolve => {
1549
1549
  if (
1550
1550
  this?.info?.sysInfo?.lat &&
1551
1551
  this?.info?.sysInfo?.lng &&
1552
1552
  this?.info?.sysInfo?.area
1553
1553
  ) {
1554
1554
  resolve({
1555
1555
  lat: this.info.sysInfo.lat,
1556
1556
  lng: this.info.sysInfo.lng,
1557
1557
  area: this?.info?.sysInfo?.area,
1558
1558
  })
1559
1559
  } else {
1560
1560
  this.jmfeReayPromise().then(() => {
1561
1561
  this.getCacheAddressRouter()
1562
1562
  .then(({ status, data }) => {
1563
1563
  console.log("原生端获取经纬度原始数据结果",status,data)
1564
1564
  if (status === '0' && data) {
1565
1565
  const {
1566
1566
  lat,
1567
1567
  latitude,
1568
1568
  lng,
1569
1569
  longitude,
1570
1570
  provinceId,
1571
1571
  cityId,
1572
1572
  countyId,
1573
1573
  townId,
1574
1574
  } = data || {}
1575
1575
  let area = ''
1576
1576
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
1577
1577
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
1578
1578
  if (provinceId) {
1579
1579
  area = `${provinceId}_${cityId || 0}_${countyId ||
1580
1580
  0}_${townId || 0}`
1581
1581
  this.info.pageInfo['address'] = area
1582
1582
  this.info.pageInfo['addressCommaStr'] = area.replace(
1583
1583
  /_/g,
1584
1584
  ',',
1585
1585
  )
1586
1586
  }
1587
1587
  resolve({
1588
1588
  lat: this.info.sysInfo['lat'],
1589
1589
  lng: this.info.sysInfo['lng'],
1590
1590
  area: area,
1591
1591
  })
1592
1592
  } else {
1593
1593
  resolve({ lat: '', lng: '', area: '' })
1594
1594
  }
1595
1595
  })
1596
1596
  .catch(e => {
1597
1597
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
1598
1598
  resolve({ lat: '', lng: '', area: '' })
1599
1599
  console.log('判断jmfe不存在,获取经纬度信息异常')
1600
1600
  })
1601
1601
  })
1602
1602
  }
1603
1603
  })
1604
1604
  }
1605
1605
 
1606
1606
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1607
1607
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
1608
1608
  if (!isJdApp) {
1609
1609
  return
1610
1610
  }
1611
1611
  const avifSwitch = await getMPaasConfigByBussinessKey(
1612
1612
  'avifSwitch',
1613
1613
  isBeforePageReady,
1614
1614
  )
1615
1615
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
1616
1616
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1617
1617
  'isFollowAppVideoPlayStatus',
1618
1618
  isBeforePageReady,
1619
1619
  )
1620
1620
  console.log(
1621
1621
  'isBeforePageReady:',
1622
1622
  isBeforePageReady,
1623
1623
  'isFollowAppVideoPlayStatus:',
1624
1624
  isFollowAppVideoPlayStatus,
1625
1625
  )
1626
1626
  if (
1627
1627
  isFollowAppVideoPlayStatus === true ||
1628
1628
  isFollowAppVideoPlayStatus === 'true'
1629
1629
  ) {
1630
1630
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
1631
1631
  }
1632
1632
  }
1633
1633
 
1634
1634
  async getWifiVideoAutoPlayAsync() {
1635
1635
  this.info.sysInfo['wifiVideoAutoPlay'] = false
1636
1636
  if (!isJdApp) {
1637
1637
  return
1638
1638
  }
1639
1639
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
1640
1640
  return 0
1641
1641
  })
1642
1642
  if (Number(videoPlayStatus) === 1) {
1643
1643
  this.info.sysInfo['wifiVideoAutoPlay'] = true
1644
1644
  }
1645
1645
  }
1646
1646
 
1647
1647
  async getMPaasConfigAsync() {
1648
1648
  this.info.sysInfo.dynamicConfig = {}
1649
1649
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
1650
1650
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
1651
1651
  return this.updateMPaasConfigAsync(true)
1652
1652
  }
1653
1653
 
1654
1654
  getDynamicConfig(key: string){
1655
1655
  return this.info.sysInfo.dynamicConfig[key]
1656
1656
  }
1657
1657
  async updateMPaasConfig() {
1658
1658
  console.log('updateMPaasConfig')
1659
1659
  if (
1660
1660
  isIosDevice &&
1661
1661
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1662
1662
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1663
1663
  ) {
1664
1664
  try {
1665
1665
  await this.updateMPaasConfigAsync(false)
1666
1666
  } catch (e) {
1667
1667
  console.log('updateMPaasConfigAsync:', e)
1668
1668
  }
1669
1669
  }
1670
1670
  }
1671
1671
 
1672
1672
  toLogin(options) {
1673
1673
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1674
1674
  ? this.toWxAppLogin(options)
1675
1675
  : this.toWebLogin(options)
1676
1676
  }
1677
1677
 
1678
1678
  doLogin(options) {
1679
1679
  return this.toLogin(options)
1680
1680
  }
1681
1681
 
1682
1682
  doLoginForJdPin(options = {}) {
1683
1683
  return this.doLogin({
1684
1684
  loginColor: {
1685
1685
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1686
1686
  dpin: 0,
1687
1687
  },
1688
1688
  ...options,
1689
1689
  })
1690
1690
  }
1691
1691
 
1692
1692
  toWebLogin(options) {
1693
1693
  let params: {
1694
1694
  returnurl: string
1695
1695
  } = {
1696
1696
  returnurl: '',
1697
1697
  }
1698
1698
  const loginUrl = isPc
1699
1699
  ? `//passport.jd.com/new/login.aspx`
1700
1700
  : `${domain.mobileLogin}/user/login.action`
1701
1701
  const defaultParams = {
1702
1702
  appid: '100',
1703
1703
  returnurl: window.location.href,
1704
1704
  }
1705
1705
  if (isString(options)) {
1706
1706
  params = Object.assign({}, defaultParams, {
1707
1707
  returnurl: options,
1708
1708
  })
1709
1709
  } else if (isObject(options)) {
1710
1710
  const { loginColor, ...otherOptions } = options
1711
1711
  params = Object.assign({}, defaultParams, otherOptions)
1712
1712
  } else {
1713
1713
  params = defaultParams
1714
1714
  }
1715
1715
  params.returnurl = encodeURIComponent(params.returnurl)
1716
1716
  let getFullUrl = loginUrl + '?' + serialize(params)
1717
1717
  if (isPc) {
1718
1718
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1719
1719
  }
1720
1720
  return Promise.resolve({
1721
1721
  h5ToUrl: true,
1722
1722
  url: getFullUrl,
1723
1723
  }).then(() => {
1724
1724
  window.location.href = getFullUrl
1725
1725
  })
1726
1726
  }
1727
1727
 
1728
1728
  toWxAppLogin(options = {}) {
1729
1729
  console.log('微信京购小程序中h5登录跳转', options)
1730
1730
  return Promise.resolve(true).then(() => {
1731
1731
  const { loginColor } = Object.assign(
1732
1732
  {},
1733
1733
  {
1734
1734
  loginColor: {
1735
1735
  biz: WXAPP_BIZ_KEY,
1736
1736
  dpin: 1,
1737
1737
  },
1738
1738
  },
1739
1739
  options,
1740
1740
  )
1741
1741
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1742
1742
  loginColor.biz
1743
1743
  }&url=${encodeURIComponent(window.location.href)}`
1744
1744
  })
1745
1745
  }
1746
1746
 
1747
1747
  getLoginCookie() {
1748
1748
  return Promise.resolve({
1749
1749
  pin: cookie.get('pin') || '',
1750
1750
  })
1751
1751
  }
1752
1752
 
1753
1753
  clearLoginCookie() {
1754
1754
  cookie.remove('pin')
1755
1755
  }
1756
1756
 
1757
1757
  checkStatusAndLogin(options = {}) {
1758
1758
  if (!this.checkStatusAndLoginPromise) {
1759
1759
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1760
1760
  try {
1761
1761
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1762
1762
  options,
1763
1763
  )
1764
1764
  if (getLoginState) {
1765
1765
  resolve(true)
1766
1766
  } else {
1767
1767
  this.toLogin(options)
1768
1768
  reject(false)
1769
1769
  }
1770
1770
  } catch (e) {
1771
1771
  this.toLogin(options)
1772
1772
  reject(false)
1773
1773
  }
1774
1774
  })
1775
1775
  return this.checkStatusAndLoginPromise
1776
1776
  } else {
1777
1777
  return this.checkStatusAndLoginPromise
1778
1778
  .then(() => {
1779
1779
  return Promise.resolve(true)
1780
1780
  })
1781
1781
  .catch(() => {
1782
1782
  this.toLogin(options)
1783
1783
  return Promise.reject(true)
1784
1784
  })
1785
1785
  }
1786
1786
  }
1787
1787
 
1788
1788
  checkJdStatusAndLogin(
1789
1789
  options = {
1790
1790
  loginColor: {
1791
1791
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1792
1792
  dpin: 0,
1793
1793
  },
1794
1794
  },
1795
1795
  ) {
1796
1796
  return this.checkStatusAndLogin(options)
1797
1797
  }
1798
1798
 
1799
1799
  doCheckLoginStateAndForApiCheck(options) {
1800
1800
  if (this.info.loginState) {
1801
1801
  return Promise.resolve(true)
1802
1802
  } else {
1803
1803
  return new Promise((resolve, reject) => {
1804
1804
  if (
1805
1805
  this.info.isJingGouMiniViewState ||
1806
1806
  this.info.isJingxiMiniViewState
1807
1807
  ) {
1808
1808
  const getWqAuthToken = cookie.get('wq_auth_token')
1809
1809
  const getWqSkey = cookie.get('wq_skey')
1810
1810
  const getWqUin = cookie.get('wq_uin')
1811
1811
  const isLoginState =
1812
1812
  options?.loginColor?.dpin === 0
1813
1813
  ? getWqAuthToken
1814
1814
  : getWqSkey && getWqUin
1815
1815
  if (isLoginState) {
1816
1816
  this.info.loginState = true
1817
1817
  resolve(true)
1818
1818
  } else {
1819
1819
  reject(false)
1820
1820
  }
1821
1821
  } else {
1822
1822
  Taro.request({
1823
1823
  url: api.isLogin,
1824
1824
  jsonp: true,
1825
1825
  timeout: 3000,
1826
1826
  success: res => {
1827
1827
  const { statusCode, data } = res
1828
1828
  if (
1829
1829
  statusCode === 200 &&
1830
1830
  data?.islogin &&
1831
1831
  Number(data.islogin) === 1
1832
1832
  ) {
1833
1833
  this.info.loginState = true
1834
1834
  resolve(true)
1835
1835
  } else {
1836
1836
  reject(false)
1837
1837
  }
1838
1838
  },
1839
1839
  fail: err => {
1840
1840
  console.log('登录检查异常', err)
1841
1841
  reject(false)
1842
1842
  },
1843
1843
  })
1844
1844
  }
1845
1845
  })
1846
1846
  }
1847
1847
  }
1848
1848
 
1849
1849
  checkLoginStatus(options) {
1850
1850
  return new Promise(async (resolve, reject) => {
1851
1851
  try {
1852
1852
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1853
1853
  options,
1854
1854
  )
1855
1855
  if (getLoginState) {
1856
1856
  const { pin } = await this.getLoginCookie()
1857
1857
  this.info.userInfo = {
1858
1858
  pin,
1859
1859
  encodePin: encodeURIComponent(pin),
1860
1860
  ptkey: '',
1861
1861
  }
1862
1862
  resolve(true)
1863
1863
  } else {
1864
1864
  reject(false)
1865
1865
  }
1866
1866
  } catch (e) {
1867
1867
  reject(false)
1868
1868
  }
1869
1869
  })
1870
1870
  }
1871
1871
 
1872
1872
  updatePageAndLogInfo(updateQuery = {}) {
1873
1873
  const createUpdateQueryInfo: {
1874
1874
  query: {
1875
1875
  shopId?: string | number
1876
1876
  venderId?: string | number
1877
1877
  }
1878
1878
  updateShopInfoState: boolean
1879
1879
  } = Object.assign(
1880
1880
  {},
1881
1881
  {
1882
1882
  query: {},
1883
1883
  updateShopInfoState: false,
1884
1884
  },
1885
1885
  updateQuery,
1886
1886
  )
1887
1887
  console.log(
1888
1888
  '获取当前下发的店铺查询参数',
1889
1889
  updateQuery,
1890
1890
  '获取之前保存的shopInfo店铺查询参数',
1891
1891
  this.info?.shopInfo,
1892
1892
  )
1893
1893
  const { query, updateShopInfoState } = createUpdateQueryInfo
1894
1894
  const { shopId, venderId, un_area } = query
1895
1895
  if (updateShopInfoState) {
1896
1896
  this.info.queryInfo = {
1897
1897
  ...this.info.queryInfo,
1898
1898
  ...query,
1899
1899
  }
1900
1900
  if (shopId && venderId) {
1901
1901
  this.info.shopInfo = {
1902
1902
  shopId: `${shopId}`,
1903
1903
  venderId: `${venderId}`,
1904
1904
  }
1905
1905
  }
1906
1906
  } else {
1907
1907
  this.info.queryInfo = {
1908
1908
  ...query,
1909
1909
  }
1910
1910
  if (
1911
1911
  this.info.shopInfo?.shopId &&
1912
1912
  this.info.shopInfo?.venderId &&
1913
1913
  (this.info.shopInfo.shopId == shopId ||
1914
1914
  this.info.shopInfo.venderId == venderId)
1915
1915
  ) {
1916
1916
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1917
1917
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1918
1918
  console.log(
1919
1919
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1920
1920
  this.info.queryInfo,
1921
1921
  )
1922
1922
  }
1923
1923
  }
1924
1924
  this.info.queryInfo['shopId'] &&
1925
1925
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1926
1926
  this.info.queryInfo['venderId'] &&
1927
1927
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1928
1928
  console.log(
1929
1929
  'h5==获取店铺下发查询参数\n',
1930
1930
  query,
1931
1931
  '\n获取店铺最后查询参数\n',
1932
1932
  this.info.queryInfo,
1933
1933
  '\n是否为更新店铺状态\n',
1934
1934
  updateShopInfoState,
1935
1935
  )
1936
1936
  const changeArea =
1937
1937
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1938
1938
  if (changeArea) {
1939
1939
  this.info.pageInfo.address = changeArea
1940
1940
  this.info.pageInfo.un_area = changeArea
1941
1941
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1942
1942
  }
1943
1943
  }
1944
1944
 
1945
1945
  dealLoadSdkList(){
1946
1946
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
1947
1947
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? []
1948
1948
  const concatLoadJsList = [].concat(globalLoadJsList,businessLoadJsList)
1949
1949
  let mergeLoadJsList = globalLoadJsList
1950
1950
  try {
1951
1951
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
1952
1952
  const getFindIndex = accArr.findIndex(item => item?.fileName === current?.fileName);
1953
1953
  getFindIndex !== -1 ? (accArr[getFindIndex] = {...accArr[getFindIndex],...current }) : accArr.push(current);
1954
1954
  return accArr;
1955
1955
  }, []);
1956
1956
  }catch (e) {
1957
1957
  console.log("LoadJsList合并错误", e)
1958
1958
  }
1959
1959
  console.log("globalLoadJsList",globalLoadJsList,"businessLoadJsList",businessLoadJsList,"两个加载jsList集合合并完成", mergeLoadJsList)
1960
1960
  this.loadJsSdkList = mergeLoadJsList
1961
1961
  return this.loadJsSdkList
1962
1962
  }
1963
1963
 
1964
1964
  renderNextTickLoadSdk(){
1965
1965
  Taro.nextTick(() => {
1966
1966
  console.log("页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======")
1967
1967
  setTimeout(() => {
1968
1968
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK,this.loadJsSdkList)
1969
1969
  },1000)
1970
1970
  })
1971
1971
  }
1972
1972
 
1973
1973
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW,loadJsList:any[] = [] ) {
1974
1974
  const getLoadJsList = Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList()
1975
1975
  const getLoadFilterList = getLoadJsList.filter(item => {
1976
1976
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL
1977
1977
  let getLoastLoadEventState = true
1978
1978
  if(getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP){
1979
1979
  getLoastLoadEventState = isJdApp
1980
1980
  }
1981
1981
  else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
1982
1982
  getLoastLoadEventState = !isJdApp
1983
1983
  }
1984
1984
  const getInitTriggerType = isJdApp && item?.initJdAppTriggerType ? item?.initTriggerType : item?.initTriggerType || LoadJsInitTriggerType.NOW
1985
1985
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false
1986
1986
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay
1987
1987
  })
1988
1988
  console.log("获取当前触发方式",triggerType,"获取当前最后加载的js集合",getLoadFilterList,"过滤前的加载集合",getLoadJsList)
1989
1989
  getLoadFilterList.length > 0 && getLoadFilterList.forEach((item) => {
1990
1990
  const isLoadState = /sgm/.test(item?.fileName) ? window?.shopGlobalSwitch?.openSgm === "true" : true
1991
1991
  isLoadState && this.loadItemSdkPromise(item)
1992
1992
  .then((res) => {
1993
1993
  console.info('当前js地址' + item?.src, '加载状态', res)
1994
1994
  })
1995
1995
  .catch((err) => {
1996
1996
  console.info('当前js地址加载异常', item?.src)
1997
1997
  window?.fetchErrorData &&
1998
1998
  window.fetchErrorData({
1999
1999
  title: '公共js加载异常',
2000
2000
  type: "jsLoad",
2001
2001
  data: err,
2002
2002
  })
2003
2003
  })
2004
2004
  })
2005
2005
  }
2006
2006
  loadScriptEle(jsInfo,resolve,reject){
2007
2007
  const getFileName = jsInfo?.fileName;
2008
2008
  if(getFileName){
2009
2009
  const getEleId = `J_loadJs_${getFileName}`
2010
2010
  const getEle = document.getElementById(getEleId)
2011
2011
  if (!getEle) {
2012
2012
  const jsLoadErrorSgmCode = `jsLoadError_${
2013
2013
  jsInfo?.fileName || 'customJs'
2014
2014
  }`
2015
2015
  const _sgmEle = document.createElement('script')
2016
2016
  _sgmEle.id = getEleId
2017
2017
  _sgmEle.onload = function () {
2018
2018
  resolve({
2019
2019
  ...jsInfo,
2020
2020
  jsTip: "js加载成功",
2021
2021
  })
2022
2022
  }
2023
2023
  _sgmEle.onerror = function () {
2024
2024
  reject({
2025
2025
  ...jsInfo,
2026
2026
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2027
2027
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
2028
2028
  })
2029
2029
  }
2030
2030
  const dataAttrList = ['timeout','fileName',"env"]
2031
2031
  const getJsInfoKeyList = Object.keys(jsInfo)
2032
2032
  getJsInfoKeyList.forEach(key => {
2033
2033
  if(key === "async"){
2034
2034
  _sgmEle.async = jsInfo[key]
2035
2035
  }else if(key === "crossOrigin"){
2036
2036
  _sgmEle.crossOrigin = jsInfo[key]
2037
2037
  }else if(key === "src"){
2038
2038
  _sgmEle.src = `${jsInfo[key]}`
2039
2039
  }else if(dataAttrList.includes(key) || /init/.test(key)) {
2040
2040
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key])
2041
2041
  }else {
2042
2042
  _sgmEle.setAttribute(key, jsInfo[key])
2043
2043
  }
2044
2044
  })
2045
2045
  document.head.appendChild(_sgmEle)
2046
2046
  }else {
2047
2047
  console.log(`当前${jsInfo?.fileName || "js"}已经存在页面中,可以直接调用相关方法`,jsInfo)
2048
2048
  resolve({
2049
2049
  ...jsInfo,
2050
2050
  jsTip: "js本身已存在页面中",
2051
2051
  })
2052
2052
  }
2053
2053
  }else {
2054
2054
  console.warn("当前js资源信息缺少必要的参数fileName,请关注",jsInfo)
2055
2055
  }
2056
2056
  }
2057
2057
 
2058
2058
  loadItemSdkPromise(jsInfo = {}){
2059
2059
  if(jsInfo?.src){
2060
2060
  const getInitLoadType = isJdApp && jsInfo?.initJdAppLoadType ? jsInfo?.initJdAppLoadType : jsInfo?.initLoadType || LoadJsInitLoadType.ALL
2061
2061
  if(getInitLoadType !== LoadJsInitLoadType.NONE){
2062
2062
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src
2063
2063
  if (!this.loadJsSdkListCachePromise[getFileKeyName]){
2064
2064
  if(getInitLoadType !== LoadJsInitLoadType.INSERT_ELE){
2065
2065
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
2066
2066
  const jsLoadErrorSgmCode = `jsLoadError_${
2067
2067
  jsInfo?.fileName || 'customJs'
2068
2068
  }`
2069
2069
  try {
2070
2070
  const jsXhrRequest = new XMLHttpRequest();
2071
2071
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000
2072
2072
  const jsUrl = `${jsInfo?.src}`
2073
2073
  jsXhrRequest.open('GET', jsUrl, true);
2074
2074
  jsXhrRequest.onreadystatechange = () => {
2075
2075
  if (jsXhrRequest.readyState === 4){
2076
2076
  const getReqStatus = jsXhrRequest.status
2077
2077
  if (getReqStatus >= 200 && getReqStatus < 300 || getReqStatus === 304){
2078
2078
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL
2079
2079
  if(getInsetHeadState){
2080
2080
  this.loadScriptEle(jsInfo,resolve,reject)
2081
2081
  }else {
2082
2082
  resolve({
2083
2083
  ...jsInfo,
2084
2084
  jsTip: "js请求成功,暂未插入head节点,业务自行单独插入",
2085
2085
  })
2086
2086
  }
2087
2087
  getReqStatus !== 200 && sgmCustomReport({
2088
2088
  type: 3,
2089
2089
  code: "js_load_special_code",
2090
2090
  msg: {
2091
2091
  msg: "当前js加载成功,状态非200,特殊上报观察",
2092
2092
  jsReqState: getReqStatus,
2093
2093
  env: getSgmCustomCode("js_load_special_code"),
2094
2094
  data: jsInfo
2095
2095
  }
2096
2096
  })
2097
2097
  }else {
2098
2098
  const getRes = {
2099
2099
  ...jsInfo,
2100
2100
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2101
2101
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
2102
2102
  jsReqState: getReqStatus,
2103
2103
  }
2104
2104
  console.log("当前js请求状态异常,具体信息见", getRes)
2105
2105
  reject(getRes)
2106
2106
  }
2107
2107
  }
2108
2108
  };
2109
2109
  jsXhrRequest.onerror = () => {
2110
2110
  const getRes = {
2111
2111
  ...jsInfo,
2112
2112
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2113
2113
  jsReqError: '请求错误',
2114
2114
  }
2115
2115
  console.log("当前js请求错误", getRes)
2116
2116
  jsXhrRequest.abort()
2117
2117
  reject(getRes)
2118
2118
  }
2119
2119
  jsXhrRequest.ontimeout = () => {
2120
2120
  const getRes = {
2121
2121
  ...jsInfo,
2122
2122
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2123
2123
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
2124
2124
  jsReqState: jsXhrRequest.status,
2125
2125
  }
2126
2126
  console.log("当前js请求超时异常", getRes)
2127
2127
  jsXhrRequest.abort()
2128
2128
  reject(getRes)
2129
2129
  }
2130
2130
  jsXhrRequest.send();
2131
2131
  }catch (e) {
2132
2132
  console.log("执行js请求异常",e)
2133
2133
  reject({
2134
2134
  ...jsInfo,
2135
2135
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2136
2136
  jsReqError: '未知异常',
2137
2137
  error: e,
2138
2138
  })
2139
2139
  }
2140
2140
  })
2141
2141
  }else {
2142
2142
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
2143
2143
  return this.loadScriptEle(jsInfo,resolve,reject)
2144
2144
  })
2145
2145
  }
2146
2146
  }
2147
2147
  return this.loadJsSdkListCachePromise[getFileKeyName]
2148
2148
  }else {
2149
2149
  return Promise.resolve({
2150
2150
  ...jsInfo,
2151
2151
  jsTip: "js加载方式设置为不加载,当前不做处理",
2152
2152
  })
2153
2153
  }
2154
2154
  }else {
2155
2155
  return Promise.reject(jsInfo)
2156
2156
  }
2157
2157
  }