@conecli/cone-render 0.9.1-shop2.18 → 0.9.1-shop2.19

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