@conecli/cone-render 0.9.1-shop2.22 → 0.9.1-shop2.23

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