@conecli/cone-render 0.10.1-shop-beta.62 → 0.10.1-shop-beta.64

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
  BUSINESS_TYPE,
3
2
  cacheAppKey,
4
3
  cacheAppUuidKey,
5
4
  cacheH5LbsAddressKey,
6
5
  JSSDK_APP_WEBVIEW_CODE,
7
6
  LoadJsInitLoadEnvType,
8
7
  LoadJsInitLoadType,
9
8
  LoadJsInitTriggerType,
10
9
  MPAAS_CONFIG_APP_LOW_VERSION,
11
10
  MPAAS_CONFIG_APP_VERSION,
12
11
  SECTION_HOME_TAB_NAME_TYPE,
13
12
  SECTION_HOME_TAB_TYPE,
14
13
  TaroEventType,
15
14
  WX_BUSINESS_TYPE,
16
15
  WXAPP_BIZ_KEY,
17
16
  WXAPP_BIZ_SHOP_LIGHT_KEY,
18
17
  languageTypeList,
19
18
  getSystemInfos,
20
19
  getTaroStorageKeyValue,
21
20
  ipLoc_djd,
22
21
  setTaroStorage,
23
22
  isInJdAppH5DebugMode,
24
23
  callRouterAndroid,
25
24
  callRouterIOS,
26
25
  getMPaasConfigByBussinessKey,
27
26
  dealNativePixelToCssPixel,
28
27
  draBusinessCustomReport,
29
28
  isAndroidDevice,
30
29
  isH5AndJingGouMini,
31
30
  isIosDevice,
32
31
  isJdAndAndroidDevice,
33
32
  isObject,
34
33
  isPc,
35
34
  isString,
36
35
  jdAppVersion,
37
36
  jdAppVersionStr,
38
37
  serialize,
39
38
  languageNowType,
40
39
  urlCookie,
41
40
  isAscfApp,
42
41
  jdAppVersionCompare,
43
42
  parseQueryUrlObj,
44
43
  abTestLabels: {},
45
44
  nonSellableSkuids: {},
46
45
  loginState: false,
47
46
  cookiesStr: '',
48
47
  userInfo: userPinKey,
49
48
  isImmersive:
50
49
  !window?.shopGlobalSwitch?.disableImmersive &&
51
50
  isJdApp &&
52
51
  window.location?.search.includes('immersive=1'),
53
52
  isJingGouMiniViewState: false,
54
53
  isJingxiMiniViewState: false,
55
54
  baseAddCartSwitch: true,
56
55
  pageInfo: {
57
56
  wxBusinessType: WX_BUSINESS_TYPE.NO,
58
57
  address: '',
59
58
  addressCommaStr: '',
60
59
  fullAddress: '',
61
60
  un_area: '',
62
61
  userLbsAddress: '',
63
62
  vapptype: '1',
64
63
  pageType: 'home',
65
64
  isExposureState: false,
66
65
  moduleId: '',
67
66
  entrance: '',
68
67
  dataType: BUSINESS_TYPE.ONLINE,
69
68
  floorExposureInfo: {},
70
69
  floorVideInfo: {},
71
70
  productVideInfo: {},
72
71
  tabsLoadAllDataInfo: {
73
72
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
74
73
  },
75
74
  updateShopInfosAllState: false,
76
75
  isVipShop: false,
77
76
  isJdShowNativeImmersivePlayer: false,
78
77
  isSuperBrandShop: false,
79
78
  ...shopConfig,
80
79
  pageScrollTop: 0,
81
80
  pageIdxHeightInfo: {
82
81
  list: [],
83
82
  },
84
83
  shopNavBarHeight: 0,
85
84
  },
86
85
  defaultQueryLogInfo: {
87
86
  sourceType: 'JDshop',
88
87
  sourceValue: '',
89
88
  moduleId: 'none',
90
89
  entrance: 'none',
91
90
  },
92
91
  sysInfo: {
93
92
  windowWidth: isPc ? 375 : 0,
94
93
  containerWidth: isPc ? 375 : 0,
95
94
  windowHeight: 0,
96
95
  netWorkType: '4g',
97
96
  jdBottomBarHeight: 0,
98
97
  jdNativeHeaderHeight: 0,
99
98
  isJdTabletDevice: false,
100
99
  isJdTabletLandscape: false,
101
100
  },
102
101
  queryInfo: {},
103
102
  shopInfo: {},
104
103
  openAppData: {},
105
104
  public info: CommonInterFace.BaseConfigInfo;
106
105
  public config: {
107
106
  [key: string]: any;
108
107
  };
109
108
  public lazyContainer: CommonInterFace.lazyContainer;
110
109
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
111
110
  public rootEleNode: HTMLElement | null;
112
111
  public checkStatusAndLoginPromise: object | null;
113
112
  private jmfeRegisterStatePromise: Promise<any> | null;
114
113
  private jdScreenSizeInfoPromise: Promise<any> | null;
115
114
  private rootEleWidthRegisterPromise: Promise<any> | null;
116
115
  private loadJsH5tagStatePromise: Promise<any> | null;
117
116
  private loadJsApiRequestStatePromise: Promise<any> | null;
118
117
  private jmfeRegisterState: boolean;
119
118
  public loadJsSdkList: {
120
119
  src: string;
121
120
  timeout: number;
122
121
  fileName: string;
123
122
  initTriggerType: typeof LoadJsInitTriggerType;
124
123
  initLinkTriggerWay:
125
124
  | 'asyncLoadAppSdkJs'
126
125
  | 'asyncLoadHandlerJs'
127
126
  | 'asyncLoadReportJs'
128
127
  | 'asyncLoadMtkJs'
129
128
  | 'asyncLoadSecurityJs'
130
129
  | 'asyncLoadSgmJs'
131
130
  | 'asyncLoadCartJs'
132
131
  | 'asyncLoadNewDraSdkJs'
133
132
  | 'asyncLoadH5TagJs';
134
133
  initLoadEnvType: typeof LoadJsInitLoadEnvType;
135
134
  defer?: 'true';
136
135
  async?: 'true';
137
136
  crossOrigin: 'anonymous' | '';
138
137
  }[];
139
138
  public loadJsSdkListCachePromise: any;
140
139
  public rootEleInitWidth: number;
141
140
  public lbsAddressCachePromise: Promise<any> | null;
142
141
  public languageCacheProimse: Promise<any> | null;
143
142
  public languageJsonData: any | null;
144
143
  public businessWorkerReady: boolean;
145
144
  public businessWorkerReadyPromise: Promise<any> | null;
146
145
  public workerPreRequestData = new Map<string, any>();
147
146
  constructor(opt) {
148
147
  this.info = this._getConfig(opt);
149
148
  this.config = {};
150
149
  this.loadJsSdkList = [];
151
150
  this.loadJsSdkListCachePromise = {};
152
151
  this.lazyContainer = {
153
152
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
154
153
  appLazyContainerList: [],
155
154
  appLazyFinishContainerList: [],
156
155
  },
157
156
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
158
157
  appLazyContainerList: [],
159
158
  appLazyFinishContainerList: [],
160
159
  },
161
160
  };
162
161
  this.renderedIsvComponents = {};
163
162
  this.rootEleNode = document.querySelector('body');
164
163
  this.checkStatusAndLoginPromise = null;
165
164
  this.jmfeRegisterStatePromise = null;
166
165
  this.jdScreenSizeInfoPromise = null;
167
166
  this.rootEleWidthRegisterPromise = null;
168
167
  this.lbsAddressCachePromise = null;
169
168
  this.languageCacheProimse = null;
170
169
  this.businessWorkerReady = false;
171
170
  this.businessWorkerReadyPromise = null;
172
171
  this.loadJsH5tagStatePromise = null;
173
172
  this.loadJsApiRequestStatePromise = null;
174
173
  this.workerPreRequestData = new Map<string, any>();
175
174
  this.languageJsonData = langeJsonDataForCn;
176
175
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
177
176
  this._init();
178
177
  if (isJdApp) {
179
178
  this.jmfeReayPromise().then(() => {
180
179
  this.jdWorkerReadyPromise();
181
180
  initAccessibility();
182
181
  });
183
182
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
184
183
  }
185
184
  }
186
185
  _getConfig(opt) {
187
186
  return Object.assign({}, DefaultConfig, opt);
188
187
  }
189
188
  _init() {
190
189
  this.loadOtherSdk();
191
190
  this.checkJdAddCartState();
192
191
  this.checkPageDomHeightToReport();
193
192
  }
194
193
  checkPageDomHeightToReport() {
195
194
  Taro.nextTick(() => {
196
195
  setTimeout(() => {
197
196
  const getReportData = {
198
197
  containerFloorLisHeight: -1,
199
198
  appHeight: -1,
200
199
  };
201
200
  const getAppEle = document.getElementById('app');
202
201
  const getFloorContainerEle = document.getElementById('J_shopContainerFloorList');
203
202
  const getNetWorkEle = document.querySelector('.J_shopNetwork');
204
203
  getFloorContainerEle &&
205
204
  (getReportData.containerFloorLisHeight =
206
205
  getFloorContainerEle?.getBoundingClientRect()?.height ?? -1);
207
206
  getAppEle && (getReportData.appHeight = getAppEle?.getBoundingClientRect()?.height ?? -1);
208
207
  const getMaxHeight = Math.max(
209
208
  getReportData.appHeight,
210
209
  getReportData.containerFloorLisHeight,
211
210
  );
212
211
  if (!getNetWorkEle && getMaxHeight > -1 && getMaxHeight < 80) {
213
212
  draBusinessCustomReport({
214
213
  eventName: 'business',
215
214
  errorName: 'pageDomHeightErrorCheck',
216
215
  errorMessage:
217
216
  '当前页面总高度异常小于80px,没有兜底network组件,可能空窗,请检查核对详细信息',
218
217
  extraData: JSON.stringify({
219
218
  data: getReportData,
220
219
  isJdApp,
221
220
  }),
222
221
  });
223
222
  }
224
223
  }, window?.shopGlobalSwitch?.checkPageDomHeightTime || 4000);
225
224
  });
226
225
  }
227
226
 
228
227
  checkJdAddCartState() {
229
228
  const getJdAppForNotMainRemoveCartUaList = isJdApp
230
229
  ? window?.PAGE_DATA?.businessData?.jdAppForNotMainRemoveCartUaList
231
230
  : undefined;
232
231
  if (
233
232
  getJdAppForNotMainRemoveCartUaList &&
234
233
  Array.isArray(getJdAppForNotMainRemoveCartUaList) &&
235
234
  getJdAppForNotMainRemoveCartUaList.length > 0
236
235
  ) {
237
236
  const setFilterReg = new RegExp(getJdAppForNotMainRemoveCartUaList.join('|'), 'i');
238
237
  this.info.baseAddCartSwitch = !setFilterReg.test(window.navigator.userAgent);
239
238
  }
240
239
  }
241
240
 
242
241
  loadApiSafeSteadyReayPromise() {
243
242
  if (!this.loadJsApiRequestStatePromise) {
244
243
  this.loadJsApiRequestStatePromise = this.loadOtherSdk(LoadJsInitTriggerType.API_REQUEST);
245
244
  }
246
245
  return this.loadJsApiRequestStatePromise;
247
246
  }
248
247
 
249
248
  loadH5tagReayPromise() {
250
249
  if (!this.loadJsH5tagStatePromise) {
251
250
  const h5TagJs = this.loadJsSdkList.find((e) => e.fileName === 'h5TagJs');
252
251
  this.loadJsH5tagStatePromise = !h5TagJs
253
252
  ? Promise.resolve(true)
254
253
  : this.loadOtherSdk(LoadJsInitTriggerType.NOW, [
255
254
  Object.assign({}, h5TagJs, {
256
255
  initTriggerType: LoadJsInitTriggerType.NOW,
257
256
  }),
258
257
  ]);
259
258
  }
260
259
  return this.loadJsH5tagStatePromise;
261
260
  }
262
261
 
263
262
  jmfeReayPromise(): Promise<any> {
264
263
  if (isJdApp) {
265
264
  if (this.jmfeRegisterState) {
266
265
  return Promise.resolve(true);
267
266
  } else {
268
267
  !this.jmfeRegisterStatePromise &&
269
268
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
270
269
  ready('jmfe', 3000)
271
270
  .then(() => {
272
271
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
273
272
  this.jmfeRegisterState = true;
274
273
  resolve(true);
275
274
  console.log(
276
275
  '松果app内初始化注册jmfe认证完成',
277
276
  window?.jmfe,
278
277
  '当前版本',
279
278
  window?.jmfe?.VERSION,
280
279
  );
281
280
  })
282
281
  .catch((err) => {
283
282
  console.error('jmfe ready error', err);
284
283
  reject(false);
285
284
  });
286
285
  }));
287
286
  return this.jmfeRegisterStatePromise;
288
287
  }
289
288
  } else {
290
289
  return Promise.reject(false);
291
290
  }
292
291
  }
293
292
 
294
293
  jdWorkerReadyPromise(): Promise<any> {
295
294
  if (isJdApp) {
296
295
  if (this.businessWorkerReady) {
297
296
  return Promise.resolve(true);
298
297
  } else {
299
298
  const getOpenJdWorkerState =
300
299
  window?.PAGE_DATA?.businessData?.businessWorkerVersion &&
301
300
  versionCompare(
302
301
  jdAppVersionStr,
303
302
  window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10',
304
303
  ) >= 0;
305
304
  !this.businessWorkerReadyPromise &&
306
305
  (this.businessWorkerReadyPromise = getOpenJdWorkerState
307
306
  ? new Promise((resolve) => {
308
307
  this.jmfeReayPromise()
309
308
  .then(() => {
310
309
  window.jmfe
311
310
  .onMsgForWorker(
312
311
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
313
312
  (workerData) => {
314
313
  console.log('收到业务jd worker消息结果:', workerData);
315
314
  if (workerData && workerData?.workerType) {
316
315
  const getWorkerType = workerData?.workerType;
317
316
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
318
317
  this.workerPreRequestData.set(workerData?.functionId, workerData);
319
318
  Taro.eventCenter.trigger(getWorkerType, workerData);
320
319
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
321
320
  Taro.eventCenter.trigger(getWorkerType, workerData);
322
321
  }
323
322
  }
324
323
  },
325
324
  )
326
325
  .then(() => {
327
326
  console.log('jd worker注册成功');
328
327
  this.businessWorkerReady = true;
329
328
  resolve(true);
330
329
  })
331
330
  .catch((error) => {
332
331
  console.log(
333
332
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
334
333
  error,
335
334
  );
336
335
  draBusinessCustomReport({
337
336
  eventName: 'business',
338
337
  errorName: 'jmfe_onMsgForWorker_error',
339
338
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
340
339
  extraData: JSON.stringify({
341
340
  businessWorkerVersion:
342
341
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
343
342
  error,
344
343
  }),
345
344
  });
346
345
  resolve(false);
347
346
  });
348
347
  })
349
348
  .catch((err) => {
350
349
  console.log('jmfe超时异常,worker注册失败', err);
351
350
  resolve(false);
352
351
  });
353
352
  })
354
353
  : Promise.resolve(false));
355
354
  }
356
355
  return this.businessWorkerReadyPromise;
357
356
  } else {
358
357
  return Promise.resolve(false);
359
358
  }
360
359
  }
361
360
 
362
361
  taskTimeoutPromise(callBack, timeout = 2000) {
363
362
  return new Promise((resolve) => {
364
363
  setTimeout(
365
364
  () => {
366
365
  const getCallBackRes = typeof callBack === 'function' && callBack();
367
366
  return resolve(getCallBackRes || false);
368
367
  },
369
368
  isInJdAppH5DebugMode ? 0 : timeout,
370
369
  );
371
370
  });
372
371
  }
373
372
  _getJdPadMinWidthForListen() {
374
373
  return (
375
374
  isJdApp &&
376
375
  Math.min(window.screen.width, window.screen.height) >
377
376
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
378
377
  );
379
378
  }
380
379
 
381
380
  getJdScreenSizeInfoPromise() {
382
381
  !this.jdScreenSizeInfoPromise &&
383
382
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
384
383
  const getThisTime = Date.now();
385
384
  this.jmfeReayPromise().then(() => {
386
385
  return Promise.race([
387
386
  window.jmfe.getScreenSize(),
388
387
  this.taskTimeoutPromise(() => {
389
388
  return {
390
389
  status: '-10',
391
390
  msg: '获取大屏信息2s超时',
392
391
  };
393
392
  }),
394
393
  ])
395
394
  .then((res) => {
396
395
  console.warn('===获取app大屏信息====', res);
397
396
  const { status, data } = res;
398
397
  if (status === '0' && data) {
399
398
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
400
399
  const getPageInfo = dealNativePixelToCssPixel({
401
400
  pageWidth,
402
401
  pageHeight,
403
402
  });
404
403
  this.info.sysInfo.jdScreenSizeType = sizeType;
405
404
  const getUseTime = Date.now() - getThisTime;
406
405
  console.warn(
407
406
  '===计算是否是app大屏信息,需满足宽度最新720===',
408
407
  getPageInfo,
409
408
  '原始数据',
410
409
  data,
411
410
  '是否是横屏isLandscape为1=',
412
411
  isLandscape,
413
412
  '用时',
414
413
  getUseTime,
415
414
  );
416
415
  if (getPageInfo?.pageWidth > 0) {
417
416
  this.rootEleInitWidth = getPageInfo?.pageWidth;
418
417
  draBusinessCustomReport({
419
418
  eventName: 'UIInteract',
420
419
  errorName: 'rootEle_width_getJdScreenSizeInfo',
421
420
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
422
421
  extraData: JSON.stringify({
423
422
  isJdApp,
424
423
  getPageInfo,
425
424
  originData: res,
426
425
  }),
427
426
  });
428
427
  resolve(getPageInfo);
429
428
  } else {
430
429
  resolve({
431
430
  pageWidth: 0,
432
431
  pageHeight: 0,
433
432
  msg: '转换异常',
434
433
  });
435
434
  }
436
435
  } else {
437
436
  resolve({
438
437
  pageWidth: 0,
439
438
  pageHeight: 0,
440
439
  msg: '获取大屏信息异常或者超时',
441
440
  });
442
441
  }
443
442
  })
444
443
  .catch((err) => {
445
444
  console.log('获取大屏信息异常', err);
446
445
  resolve({
447
446
  pageWidth: 0,
448
447
  pageHeight: 0,
449
448
  msg: '获取大屏信息异常',
450
449
  });
451
450
  });
452
451
  });
453
452
  }));
454
453
  return this.jdScreenSizeInfoPromise;
455
454
  }
456
455
 
457
456
  listenJdTabletScreenChange() {
458
457
  this.jmfeReayPromise().then(() => {
459
458
  try {
460
459
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
461
460
  window.jmfe.listenDeviceScreenChange((event) => {
462
461
  console.log(
463
462
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
464
463
  event,
465
464
  '通过前端判断是不是横屏',
466
465
  window.matchMedia('(orientation: landscape)')?.matches,
467
466
  );
468
467
  const { orientation } = event?.data;
469
468
  if (orientation) {
470
469
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
471
470
  Taro.eventCenter.trigger(
472
471
  TaroEventType.TABLE_SCREEN_CHANGE,
473
472
  this.info.sysInfo.isJdTabletLandscape,
474
473
  orientation,
475
474
  );
476
475
  }
477
476
  });
478
477
  } catch (error) {
479
478
  console.log('listenScreenChange的打印error:', error);
480
479
  }
481
480
  });
482
481
  }
483
482
 
484
483
  updateBusinessDomainAndApi(domain, api) {
485
484
  }
486
485
 
487
486
  formatNativeScreenPageData(action) {
488
487
  let getChangePageInfo: any = null;
489
488
  try {
490
489
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
491
490
  JSON.stringify({
492
491
  plugin: 'JDHybridScreenPlugin',
493
492
  action,
494
493
  sync: '1',
495
494
  }),
496
495
  );
497
496
  const getChangePageInfoData =
498
497
  typeof getNativeScreenPageInfoStr === 'string'
499
498
  ? JSON.parse(getNativeScreenPageInfoStr)
500
499
  : null;
501
500
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
502
501
  const { code, data } = getChangePageInfoData;
503
502
  getChangePageInfo = code && code === '0' ? data : null;
504
503
  }
505
504
  } catch (e) {
506
505
  console.log('JDHybridScreenPlugin转换异常', e);
507
506
  }
508
507
  return getChangePageInfo;
509
508
  }
510
509
 
511
510
  isAndroidFoldScreen() {
512
511
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
513
512
  }
514
513
 
515
514
  isHarmonyFoldScreenPromise(): Promise<{
516
515
  isFoldScreen: boolean;
517
516
  getFoldDisplayMode?: number;
518
517
  }> {
519
518
  return new Promise((resolve) => {
520
519
  this.jmfeReayPromise()
521
520
  .then(() => {
522
521
  if (window.jmfe?.callNative) {
523
522
  Promise.all([
524
523
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
525
524
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
526
525
  ])
527
526
  .then((res) => {
528
527
  resolve({
529
528
  isFoldScreen: res?.[0]?.data === '1',
530
529
  getFoldDisplayMode: res?.[1]?.data,
531
530
  });
532
531
  })
533
532
  .catch(() => {
534
533
  resolve({
535
534
  isFoldScreen: false,
536
535
  getFoldDisplayMode: undefined,
537
536
  });
538
537
  });
539
538
  } else {
540
539
  resolve({
541
540
  isFoldScreen: false,
542
541
  getFoldDisplayMode: undefined,
543
542
  });
544
543
  }
545
544
  })
546
545
  .catch(() => {
547
546
  resolve({
548
547
  isFoldScreen: false,
549
548
  getFoldDisplayMode: undefined,
550
549
  });
551
550
  });
552
551
  });
553
552
  }
554
553
 
555
554
  getJdAndroidPageChangeScreenInfo() {
556
555
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
557
556
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
558
557
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
559
558
  pageWidth: getPageScreenInfo.pageWidth,
560
559
  pageHeight: getPageScreenInfo.pageHeight,
561
560
  });
562
561
  getPageScreenInfo.pageWidth = pageWidth;
563
562
  getPageScreenInfo.pageHeight = pageHeight;
564
563
  }
565
564
  return getPageScreenInfo;
566
565
  }
567
566
 
568
567
  getRootEleWindowWidthInfo() {
569
568
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
570
569
  const getWindowWidth = window.innerWidth;
571
570
  const getScreenWidth = window.screen.width;
572
571
  return {
573
572
  getRootEleWidth,
574
573
  getWindowWidth,
575
574
  getScreenWidth,
576
575
  };
577
576
  }
578
577
 
579
578
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
580
579
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
581
580
  console.log(
582
581
  '当前获取根元素的宽度',
583
582
  getRootEleWidth,
584
583
  'getWindowWidth',
585
584
  getWindowWidth,
586
585
  'getScreenWidth',
587
586
  getScreenWidth,
588
587
  );
589
588
  const getLastWidth =
590
589
  getRootEleWidth > 0
591
590
  ? Math.round(getRootEleWidth)
592
591
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
593
592
  console.warn(
594
593
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
595
594
  );
596
595
  timeout > 0 &&
597
596
  draBusinessCustomReport({
598
597
  eventName: 'UIInteract',
599
598
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
600
599
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
601
600
  extraData: JSON.stringify({
602
601
  isJdApp,
603
602
  getRootEleWidth,
604
603
  getWindowWidth,
605
604
  getScreenWidth,
606
605
  ...reportParam,
607
606
  }),
608
607
  });
609
608
  return getLastWidth;
610
609
  }
611
610
 
612
611
  getPadWindowRootEleWidthPromise() {
613
612
  if (this.rootEleInitWidth > 0) {
614
613
  return Promise.resolve(this.rootEleInitWidth);
615
614
  } else {
616
615
  !this.rootEleWidthRegisterPromise &&
617
616
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
618
617
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
619
618
  if (getRootEleInitWidth > 0) {
620
619
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
621
620
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
622
621
  resolve(this.rootEleInitWidth);
623
622
  } else {
624
623
  const timerPromise = () => {
625
624
  return new Promise((resolve2) => {
626
625
  window.setTimeout(() => {
627
626
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
628
627
  this.getRootEleWindowWidthInfo();
629
628
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
630
629
  console.warn(
631
630
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
632
631
  );
633
632
  draBusinessCustomReport({
634
633
  eventName: 'UIInteract',
635
634
  errorName: 'rootEle_width_200_timeout_info',
636
635
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
637
636
  extraData: JSON.stringify({
638
637
  isJdApp,
639
638
  getRootEleWidth,
640
639
  getWindowWidth,
641
640
  getScreenWidth,
642
641
  }),
643
642
  });
644
643
  const getRes =
645
644
  getRootEleWidth > 0 && getWindowWidth > 0
646
645
  ? Math.min(getRootEleWidth, getWindowWidth)
647
646
  : Math.max(getRootEleWidth, getWindowWidth);
648
647
  resolve2({
649
648
  pageWidth: Math.round(getRes),
650
649
  });
651
650
  }
652
651
  }, 200);
653
652
  });
654
653
  };
655
654
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
656
655
  const { pageWidth } = res;
657
656
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
658
657
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
659
658
  });
660
659
  }
661
660
  }));
662
661
  return this.rootEleWidthRegisterPromise;
663
662
  }
664
663
  }
665
664
 
666
665
  async getSystemInfo(params) {
667
666
  const getParams = Object.assign({}, params || {});
668
667
  if (this.rootEleInitWidth > 0) {
669
668
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
670
669
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
671
670
  } else {
672
671
  if (this._getJdPadMinWidthForListen()) {
673
672
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
674
673
  getParams['replaceSystemWidth'] = true;
675
674
  }
676
675
  }
677
676
  isJdApp && this.createLanguagePromise();
678
677
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
679
678
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
680
679
  let _isfoldScreen = false;
681
680
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
682
681
  console.info(
683
682
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
684
683
  getStorageData,
685
684
  '通过缓存值第一次判断是否是折叠屏',
686
685
  getStorageData === 'true',
687
686
  );
688
687
  if (!getStorageData) {
689
688
  _isfoldScreen = this.isAndroidFoldScreen();
690
689
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
691
690
  } else {
692
691
  _isfoldScreen = getStorageData === 'true';
693
692
  }
694
693
  if (_isfoldScreen) {
695
694
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
696
695
  if (getJdAndroidPageInfo) {
697
696
  info = getSystemInfos(getJdAndroidPageInfo);
698
697
  console.warn(
699
698
  '当前为松果安卓折叠屏app,获取折叠屏信息',
700
699
  getJdAndroidPageInfo,
701
700
  '获取转换后的系统信息',
702
701
  info,
703
702
  );
704
703
  draBusinessCustomReport({
705
704
  eventName: 'UIInteract',
706
705
  errorName: 'android_jdapp_foldScreen_info',
707
706
  errorMessage:
708
707
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
709
708
  extraData: JSON.stringify({
710
709
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
711
710
  androidPageInfo: getJdAndroidPageInfo,
712
711
  jdAppVersionStr,
713
712
  taroSysInfo: info,
714
713
  }),
715
714
  });
716
715
  }
717
716
  }
718
717
  }
719
718
  if (isJdApp) {
720
719
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
721
720
  }
722
721
  this.info.sysInfo = {
723
722
  actualNavBarHeight: 0,
724
723
  ...this.info.sysInfo,
725
724
  ...info,
726
725
  safeContentHeight: info?.screenHeight,
727
726
  headerHeight: 0,
728
727
  tabBarHeight: 0,
729
728
  languageType: languageNowType,
730
729
  };
731
730
  if (isJdApp || isH5AndJingGouMini) {
732
731
  this.getAddressCachePromise();
733
732
  this.getLbsAddressCachePromise();
734
733
  }
735
734
  if (isJdApp) {
736
735
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
737
736
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
738
737
  this.getJdAppBaseInfo();
739
738
  this.getElderModePromise();
740
739
  this.getJDAppearanceStatePromise();
741
740
  this.createJdAndroidRquestEventForTouchStart();
742
741
  }
743
742
  this.getWifiVideoAutoPlayAsync();
744
743
  this.getMPaasConfigAsync();
745
744
  this.getNetWorkType();
746
745
  }
747
746
 
748
747
  getElderModePromise() {
749
748
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
750
749
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
751
750
  } else {
752
751
  if (isJdAndAndroidDevice) {
753
752
  this.info.sysInfo.jdAppModeType = '0';
754
753
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
755
754
  } else {
756
755
  return Promise.race([
757
756
  this.taskTimeoutPromise(() => {
758
757
  this.info.sysInfo.jdAppModeType = '0';
759
758
  return this.info.sysInfo.jdAppModeType;
760
759
  }),
761
760
  new Promise((resolve) => {
762
761
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
763
762
  if (!window[getCallBackName]) {
764
763
  window[getCallBackName] = (res) => {
765
764
  try {
766
765
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
767
766
  const { status, data, msg } = getResJson;
768
767
  console.log(`获取松果app展示模式成功,返回结果${data}`);
769
768
  if (status === '0') {
770
769
  this.info.sysInfo.jdAppModeType = data;
771
770
  resolve(data);
772
771
  } else {
773
772
  resolve('0');
774
773
  }
775
774
  } catch (e) {
776
775
  resolve('0');
777
776
  }
778
777
  window[getCallBackName] = null;
779
778
  };
780
779
  }
781
780
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
782
781
  method: 'callSyncRouterModuleWithParams',
783
782
  params: JSON.stringify({
784
783
  routerURL: 'router://JDBModeModule/getCurrentMode',
785
784
  routerParam: {},
786
785
  callBackName: `window.${getCallBackName}`,
787
786
  callBackId: `${getCallBackName}Ios`,
788
787
  }),
789
788
  });
790
789
  }),
791
790
  ]);
792
791
  }
793
792
  }
794
793
  }
795
794
  getAPPUseStraightCorner() {
796
795
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
797
796
  const params = {
798
797
  routerURL,
799
798
  routerParam: {},
800
799
  jdRouter: '1',
801
800
  };
802
801
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
803
802
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
804
803
  } else {
805
804
  return this.jmfeReayPromise()
806
805
  .then(() => {
807
806
  if (isJdAndHarmonyDevice || !isJdApp) {
808
807
  console.log('not APP or is Harmony');
809
808
  return Promise.resolve(false);
810
809
  }
811
810
  console.log('jmfe setShareInfo', params);
812
811
  return Promise.race([
813
812
  window.jmfe.callRouter(params),
814
813
  this.taskTimeoutPromise(() => {
815
814
  return false;
816
815
  }),
817
816
  ]).then(({ status, data }) => {
818
817
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
819
818
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
820
819
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
821
820
  return Promise.resolve(status === '0' && Number(data) === 1);
822
821
  });
823
822
  })
824
823
  .catch((e) => {
825
824
  console.log('jmfe error', e);
826
825
  return Promise.resolve(false);
827
826
  });
828
827
  }
829
828
  }
830
829
 
831
830
  getJDAppearanceStatePromise() {
832
831
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
833
832
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
834
833
  } else {
835
834
  return Promise.race([
836
835
  this.taskTimeoutPromise(() => {
837
836
  this.info.sysInfo.jdAppearanceState = '0';
838
837
  return this.info.sysInfo.jdAppearanceState;
839
838
  }),
840
839
  new Promise((resolve) => {
841
840
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
842
841
  if (!window[getCallBackName]) {
843
842
  window[getCallBackName] = (res) => {
844
843
  try {
845
844
  console.log('getJDAppearanceStatePromise', res);
846
845
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
847
846
  const { status, data, msg } = getResJson;
848
847
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
849
848
  if (status === '0') {
850
849
  this.info.sysInfo.jdAppearanceState = data;
851
850
  resolve(data);
852
851
  } else {
853
852
  resolve('0');
854
853
  }
855
854
  } catch (e) {
856
855
  resolve('0');
857
856
  }
858
857
  window[getCallBackName] = null;
859
858
  };
860
859
  }
861
860
  if (isAndroidDevice) {
862
861
  const jsonString = JSON.stringify({
863
862
  callBackName: `window.${getCallBackName}`,
864
863
  });
865
864
  console.log('window.JDAppearance', window?.JDAppearance);
866
865
  window?.JDAppearance &&
867
866
  window?.JDAppearance?.getUiState &&
868
867
  window.JDAppearance.getUiState(jsonString);
869
868
  } else {
870
869
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
871
870
  method: 'callSyncRouterModuleWithParams',
872
871
  params: JSON.stringify({
873
872
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
874
873
  routerParam: {},
875
874
  callBackName: `window.${getCallBackName}`,
876
875
  callBackId: `${getCallBackName}Ios`,
877
876
  }),
878
877
  });
879
878
  }
880
879
  }),
881
880
  ]);
882
881
  }
883
882
  }
884
883
 
885
884
  createJdAndroidRquestEventForTouchStart() {
886
885
  if (isJdAndAndroidDevice && window?.JdAndroid) {
887
886
  const rootEleNode = document.querySelector('body');
888
887
  if (rootEleNode) {
889
888
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
890
889
  }
891
890
  }
892
891
  }
893
892
  jdAndroidAddEventListenerTouchStart(e) {
894
893
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
895
894
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
896
895
  const hasCustomEle = e
897
896
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
898
897
  : false;
899
898
  if (!hasCustomEle) {
900
899
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
901
900
  console.log(
902
901
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
903
902
  );
904
903
  }
905
904
  }
906
905
  }
907
906
  removeJdAndroidRquestEventForTouchStart() {
908
907
  if (isJdAndAndroidDevice && window.JdAndroid) {
909
908
  const rootEleNode = document.querySelector('body');
910
909
  if (rootEleNode) {
911
910
  rootEleNode.removeEventListener(
912
911
  'touchstart',
913
912
  this.jdAndroidAddEventListenerTouchStart,
914
913
  false,
915
914
  );
916
915
  }
917
916
  }
918
917
  }
919
918
 
920
919
  getNetWorkType() {
921
920
  if (isJdApp) {
922
921
  this.jmfeReayPromise().then(() => {
923
922
  window.jmfe
924
923
  .getNetworkStatus()
925
924
  .then(({ status, data }) => {
926
925
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
927
926
  if (status === '0') {
928
927
  this.info.sysInfo['netWorkType'] = data;
929
928
  } else {
930
929
  this._taroGetNetworkType();
931
930
  }
932
931
  })
933
932
  .catch((err) => {
934
933
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
935
934
  this._taroGetNetworkType();
936
935
  });
937
936
  });
938
937
  } else {
939
938
  this._taroGetNetworkType();
940
939
  }
941
940
  }
942
941
  _taroGetNetworkType() {
943
942
  Taro.getNetworkType().then((getRes) => {
944
943
  if (getRes && getRes.networkType) {
945
944
  this.info.sysInfo['netWorkType'] = getRes.networkType;
946
945
  console.log(
947
946
  '在app内通过taro对象获取网络状态完成,当前网络状态',
948
947
  this.info.sysInfo['netWorkType'],
949
948
  );
950
949
  }
951
950
  });
952
951
  }
953
952
 
954
953
  getJdAppBaseInfo() {
955
954
  const appKeyCacheToCookieMinuteTime =
956
955
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
957
956
  appUuidCacheToCookieMinuteTime =
958
957
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
959
958
  getAppKey = cookie.get(cacheAppKey),
960
959
  getAppUuidKey = cookie.get(cacheAppUuidKey);
961
960
  console.log(
962
961
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
963
962
  cacheAppKey,
964
963
  getAppKey,
965
964
  cacheAppUuidKey,
966
965
  getAppUuidKey,
967
966
  );
968
967
  if (
969
968
  appKeyCacheToCookieMinuteTime &&
970
969
  appUuidCacheToCookieMinuteTime &&
971
970
  getAppKey &&
972
971
  getAppUuidKey
973
972
  ) {
974
973
  const [uuid, eufv] = getAppUuidKey.split('@');
975
974
  const baseApiKeyParam = {
976
975
  uuid,
977
976
  };
978
977
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
979
978
  if (eufv === '1' && /-/.test(uuid)) {
980
979
  const [eu, fv] = uuid.split('-');
981
980
  baseApiKeyParam['eu'] = eu;
982
981
  baseApiKeyParam['fv'] = fv;
983
982
  }
984
983
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
985
984
  this.jmfeReayPromise().then(() => {
986
985
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
987
986
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
988
987
  });
989
988
  } else {
990
989
  const checkGetJdAppKeyState =
991
990
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
992
991
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
993
992
  this.jmfeReayPromise().then(() => {
994
993
  Promise.all([
995
994
  checkGetJdAppKeyState && window.jmfe?.callNative
996
995
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
997
996
  : Promise.resolve({
998
997
  status: '-1000',
999
998
  msg: '当前版本不支持获取松果app中的getAppKey',
1000
999
  data: '-1000',
1001
1000
  }),
1002
1001
  window.jmfe.getDeviceInfo(),
1003
1002
  ]).then((resList) => {
1004
1003
  const [getAppKeyRes, deviceInfoRes] = resList;
1005
1004
  console.log(
1006
1005
  '在app内初始化通过jmfe获取getAppKey结果',
1007
1006
  getAppKeyRes,
1008
1007
  '通过jmfe获取getDeviceInfo获取结果',
1009
1008
  deviceInfoRes,
1010
1009
  );
1011
1010
  const baseApiKeyParam = {};
1012
1011
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
1013
1012
  const getJmfeAppKey = getAppKeyRes?.data;
1014
1013
  if (getJmfeAppKey && getJmfeAppKey !== '') {
1015
1014
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
1016
1015
  const getJdAppKeyCacheToCookieMinuteTime =
1017
1016
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
1018
1017
  if (getJdAppKeyCacheToCookieMinuteTime) {
1019
1018
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
1020
1019
  cookie.set(cacheAppKey, getJmfeAppKey, {
1021
1020
  path: '/',
1022
1021
  expires,
1023
1022
  });
1024
1023
  }
1025
1024
  }
1026
1025
  }
1027
1026
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
1028
1027
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
1029
1028
  if (uuid && uuid !== '') {
1030
1029
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
1031
1030
  baseApiKeyParam['uuid'] = uuid;
1032
1031
  if (eufv === '1' && /-/.test(uuid)) {
1033
1032
  const [eu, fv] = uuid.split('-');
1034
1033
  baseApiKeyParam['eu'] = eu;
1035
1034
  baseApiKeyParam['fv'] = fv;
1036
1035
  }
1037
1036
  const getAppUuidCacheToCookieMinuteTime =
1038
1037
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
1039
1038
  if (getAppUuidCacheToCookieMinuteTime) {
1040
1039
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
1041
1040
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
1042
1041
  path: '/',
1043
1042
  expires,
1044
1043
  });
1045
1044
  }
1046
1045
  }
1047
1046
  }
1048
1047
  console.log(
1049
1048
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
1050
1049
  baseApiKeyParam,
1051
1050
  );
1052
1051
  if (Object.keys(baseApiKeyParam).length > 0) {
1053
1052
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
1054
1053
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
1055
1054
  }
1056
1055
  });
1057
1056
  });
1058
1057
  }
1059
1058
  }
1060
1059
 
1061
1060
  getCacheAddressRouter() {
1062
1061
  if (isJdApp) {
1063
1062
  if (!isJdAndHarmonyDevice) {
1064
1063
  return Promise.race([
1065
1064
  new Promise((resolve) => {
1066
1065
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
1067
1066
  if (!window[getCallBackName]) {
1068
1067
  window[getCallBackName] = (res) => {
1069
1068
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
1070
1069
  try {
1071
1070
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1072
1071
  resolve(getResJson);
1073
1072
  } catch (e) {
1074
1073
  resolve({
1075
1074
  status: '-1002',
1076
1075
  msg: '地址信息解析json异常',
1077
1076
  res,
1078
1077
  });
1079
1078
  }
1080
1079
  window[getCallBackName] = null;
1081
1080
  };
1082
1081
  }
1083
1082
  const getRouterParam = {
1084
1083
  sceneId: 'basicShoppingProcess',
1085
1084
  };
1086
1085
  if (isAndroidDevice) {
1087
1086
  return callRouterAndroid({
1088
1087
  routerURL: 'router://JDAddressModule/getCacheAddress',
1089
1088
  routerParam: getRouterParam,
1090
1089
  callBackName: getCallBackName,
1091
1090
  isSync: true,
1092
1091
  });
1093
1092
  } else {
1094
1093
  return callRouterIOS({
1095
1094
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1096
1095
  routerParam: getRouterParam,
1097
1096
  callBackName: getCallBackName,
1098
1097
  });
1099
1098
  }
1100
1099
  }),
1101
1100
  this.taskTimeoutPromise(() => {
1102
1101
  return {
1103
1102
  status: '-1000',
1104
1103
  msg: '原生router协议获取地址信息超时',
1105
1104
  };
1106
1105
  }, 3000),
1107
1106
  ]);
1108
1107
  } else {
1109
1108
  return Promise.race([
1110
1109
  new Promise((resolve) => {
1111
1110
  this.jmfeReayPromise()
1112
1111
  .then(() => {
1113
1112
  const plugin = 'JDHybridRouterPlugin';
1114
1113
  const action = 'callSyncRouterModuleWithParams';
1115
1114
  const params = {
1116
1115
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
1117
1116
  routerParam: '',
1118
1117
  };
1119
1118
  const sync = '1';
1120
1119
  try {
1121
1120
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
1122
1121
  resolve(res);
1123
1122
  });
1124
1123
  } catch (error) {
1125
1124
  resolve({
1126
1125
  status: '-1001',
1127
1126
  msg: '判断jmfe不存在,获取经纬度信息异常',
1128
1127
  });
1129
1128
  }
1130
1129
  })
1131
1130
  .catch(() => {
1132
1131
  resolve({
1133
1132
  status: '-1002',
1134
1133
  msg: '鸿蒙系统调用jmfe异常,获取失败',
1135
1134
  });
1136
1135
  });
1137
1136
  }),
1138
1137
  this.taskTimeoutPromise(() => {
1139
1138
  return {
1140
1139
  status: '-1000',
1141
1140
  msg: '原生router协议获取地址信息超时',
1142
1141
  };
1143
1142
  }, 3000),
1144
1143
  ]);
1145
1144
  }
1146
1145
  } else if (isH5AndJingGouMini) {
1147
1146
  const { areaId, addressName } = this.getJingGouMiniInh5Address();
1148
1147
  if (areaId && areaId !== '' && addressName && addressName !== '') {
1149
1148
  return Promise.resolve({
1150
1149
  status: '0',
1151
1150
  data: {
1152
1151
  areaId,
1153
1152
  fullAddress: addressName,
1154
1153
  },
1155
1154
  });
1156
1155
  } else {
1157
1156
  return Promise.resolve({
1158
1157
  status: '-1002',
1159
1158
  msg: '京购内嵌h5h5暂无业务需要,未实现,获取失败',
1160
1159
  });
1161
1160
  }
1162
1161
  } else {
1163
1162
  return Promise.resolve({
1164
1163
  status: '-1002',
1165
1164
  msg: '普通h5暂无业务需要,未实现,获取失败',
1166
1165
  });
1167
1166
  }
1168
1167
  }
1169
1168
 
1170
1169
  getJingGouMiniInh5Address() {
1171
1170
  let getRes: any = {
1172
1171
  areaId: '',
1173
1172
  addressName: '',
1174
1173
  };
1175
1174
  try {
1176
1175
  const getUrlHast = decodeURIComponent(window.location.hash || '');
1177
1176
  const sensMatch = getUrlHast ? getUrlHast.match(/sens=({.*?})/) : null;
1178
1177
  if (sensMatch && sensMatch[1]) {
1179
1178
  const sensData = JSON.parse(sensMatch[1]);
1180
1179
  const getWqAddr = sensData?.wq_addr || '';
1181
1180
  if (getWqAddr && /\|/.test(getWqAddr)) {
1182
1181
  const addressList = getWqAddr.split(/\|/);
1183
1182
  const [addressId, areaId, areaName, addressName, coordinate] = addressList;
1184
1183
  getRes = {
1185
1184
  addressId,
1186
1185
  areaId,
1187
1186
  areaName,
1188
1187
  addressName,
1189
1188
  coordinate,
1190
1189
  };
1191
1190
  }
1192
1191
  }
1193
1192
  } catch (e) {
1194
1193
  console.log('获取hash转换异常', e);
1195
1194
  }
1196
1195
  return getRes;
1197
1196
  }
1198
1197
 
1199
1198
  getAddressCachePromise() {
1200
1199
  return new Promise((resolve) => {
1201
1200
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
1202
1201
  resolve({
1203
1202
  lat: this.info.sysInfo.lat,
1204
1203
  lng: this.info.sysInfo.lng,
1205
1204
  area: this?.info?.sysInfo?.area,
1206
1205
  fullAddress: this?.info?.pageInfo?.fullAddress,
1207
1206
  });
1208
1207
  } else {
1209
1208
  this.getCacheAddressRouter()
1210
1209
  .then((res) => {
1211
1210
  const { status, data } = res;
1212
1211
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
1213
1212
  if (status === '0' && data) {
1214
1213
  const {
1215
1214
  lat,
1216
1215
  latitude,
1217
1216
  lng,
1218
1217
  longitude,
1219
1218
  provinceId,
1220
1219
  cityId,
1221
1220
  countyId,
1222
1221
  townId,
1223
1222
  fullAddress,
1224
1223
  areaId,
1225
1224
  } = data || {};
1226
1225
  const getAreaIdsEnable = areaId && areaId !== '';
1227
1226
  const getEncodeFullAddress = fullAddress ? encodeURIComponent(fullAddress) : '';
1228
1227
  let area = getAreaIdsEnable ? areaId : '';
1229
1228
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
1230
1229
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
1231
1230
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
1232
1231
  if ((getProvinceIdNum && getProvinceIdNum > 0) || getAreaIdsEnable) {
1233
1232
  area = getAreaIdsEnable
1234
1233
  ? areaId
1235
1234
  : `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
1236
1235
  this.info.pageInfo['address'] = area;
1237
1236
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
1238
1237
  this.info.sysInfo['area'] = area;
1239
1238
  const getUpdateData = {
1240
1239
  area: this.info.pageInfo.address,
1241
1240
  };
1242
1241
  if (fullAddress && fullAddress.length > 0) {
1243
1242
  getUpdateData['fullAddress'] = getEncodeFullAddress;
1244
1243
  this.info.pageInfo['fullAddress'] = getEncodeFullAddress;
1245
1244
  }
1246
1245
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, getUpdateData);
1247
1246
  }
1248
1247
  resolve({
1249
1248
  lat: this.info.sysInfo['lat'],
1250
1249
  lng: this.info.sysInfo['lng'],
1251
1250
  fullAddress: getEncodeFullAddress,
1252
1251
  area: area,
1253
1252
  });
1254
1253
  } else {
1255
1254
  if (typeof res === 'object') {
1256
1255
  draBusinessCustomReport({
1257
1256
  eventName: 'business',
1258
1257
  errorName: 'jdapp_getCacheAddress_info_err',
1259
1258
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
1260
1259
  extraData: JSON.stringify({
1261
1260
  isJdApp,
1262
1261
  jdAppVersion: jdAppVersionStr,
1263
1262
  ...res,
1264
1263
  }),
1265
1264
  });
1266
1265
  }
1267
1266
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
1268
1267
  }
1269
1268
  })
1270
1269
  .catch((e) => {
1271
1270
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
1272
1271
  draBusinessCustomReport({
1273
1272
  eventName: 'business',
1274
1273
  errorName: 'jdapp_getCacheAddress_info_catch_err',
1275
1274
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
1276
1275
  extraData: JSON.stringify({
1277
1276
  isJdApp,
1278
1277
  jdAppVersion: jdAppVersionStr,
1279
1278
  }),
1280
1279
  });
1281
1280
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
1282
1281
  });
1283
1282
  }
1284
1283
  });
1285
1284
  }
1286
1285
 
1287
1286
  getLbsCacheAddressRouter() {
1288
1287
  if (isJdApp) {
1289
1288
  if (!isJdAndHarmonyDevice) {
1290
1289
  return Promise.race([
1291
1290
  new Promise((resolve) => {
1292
1291
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
1293
1292
  if (!window[getCallBackName]) {
1294
1293
  window[getCallBackName] = (res) => {
1295
1294
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
1296
1295
  try {
1297
1296
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1298
1297
  resolve(getResJson);
1299
1298
  } catch (e) {
1300
1299
  resolve({
1301
1300
  status: '-1002',
1302
1301
  msg: '地址信息解析json异常',
1303
1302
  res,
1304
1303
  });
1305
1304
  }
1306
1305
  window[getCallBackName] = null;
1307
1306
  };
1308
1307
  }
1309
1308
  const getRouterParam = {
1310
1309
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
1311
1310
  sceneId: 'basicShoppingProcess',
1312
1311
  };
1313
1312
  if (isAndroidDevice) {
1314
1313
  return callRouterAndroid({
1315
1314
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
1316
1315
  routerParam: getRouterParam,
1317
1316
  callBackName: getCallBackName,
1318
1317
  isSync: true,
1319
1318
  hasJdRouter: false,
1320
1319
  });
1321
1320
  } else {
1322
1321
  return callRouterIOS({
1323
1322
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
1324
1323
  routerParam: getRouterParam,
1325
1324
  callBackName: getCallBackName,
1326
1325
  isSync: true,
1327
1326
  });
1328
1327
  }
1329
1328
  }),
1330
1329
  this.taskTimeoutPromise(() => {
1331
1330
  return {
1332
1331
  status: '-1000',
1333
1332
  msg: '原生router协议获取lbs地址信息3s超时',
1334
1333
  };
1335
1334
  }, 3000),
1336
1335
  ]);
1337
1336
  } else {
1338
1337
  return Promise.resolve({
1339
1338
  status: '-1001',
1340
1339
  msg: '鸿蒙系统调用未实现,获取失败',
1341
1340
  });
1342
1341
  }
1343
1342
  } else if (isH5AndJingGouMini) {
1344
1343
  return this.getLocationForGpsPromise();
1345
1344
  } else {
1346
1345
  return Promise.resolve({
1347
1346
  status: '-1002',
1348
1347
  msg: '普通h5暂无业务需要,未实现,获取失败',
1349
1348
  });
1350
1349
  }
1351
1350
  }
1352
1351
  getLocationForGpsPromise() {
1353
1352
  return new Promise((resolve) => {
1354
1353
  let hasGetLocationForGps = true;
1355
1354
  if (urlCookie && urlCookie['loc']) {
1356
1355
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
1357
1356
  urlCookie['loc'].split('_');
1358
1357
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
1359
1358
  if (getProvinceIdNum && getProvinceIdNum > 0) {
1360
1359
  hasGetLocationForGps = false;
1361
1360
  resolve({
1362
1361
  status: '0',
1363
1362
  data: {
1364
1363
  provinceid,
1365
1364
  cityid,
1366
1365
  districtid,
1367
1366
  townid,
1368
1367
  origin: 'wxapp',
1369
1368
  },
1370
1369
  });
1371
1370
  }
1372
1371
  }
1373
1372
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
1374
1373
  window.navigator.geolocation.getCurrentPosition(
1375
1374
  (position) => {
1376
1375
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
1377
1376
  if (position?.coords) {
1378
1377
  resolve({
1379
1378
  status: '0',
1380
1379
  data: {
1381
1380
  srclat: position.coords?.latitude,
1382
1381
  srclng: position.coords.longitude,
1383
1382
  origin: 'h5',
1384
1383
  },
1385
1384
  });
1386
1385
  } else {
1387
1386
  resolve({
1388
1387
  status: '-1001',
1389
1388
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
1390
1389
  position,
1391
1390
  });
1392
1391
  }
1393
1392
  },
1394
1393
  (error) => {
1395
1394
  resolve({
1396
1395
  status: '-1001',
1397
1396
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
1398
1397
  error,
1399
1398
  });
1400
1399
  },
1401
1400
  {
1402
1401
  enableHighAccuracy: false,
1403
1402
  timeout: 3 * 1000,
1404
1403
  maximumAge: 10 * 60 * 1000,
1405
1404
  },
1406
1405
  );
1407
1406
  } else {
1408
1407
  resolve({
1409
1408
  status: '-1001',
1410
1409
  msg: '您的浏览器不支持地理定位',
1411
1410
  });
1412
1411
  }
1413
1412
  });
1414
1413
  }
1415
1414
 
1416
1415
  createLbsCacheAddress(realTimeArea) {
1417
1416
  const getLbsAddressCacheMinuteTime = Number(
1418
1417
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
1419
1418
  );
1420
1419
  console.log(
1421
1420
  '获取lbs缓存到cookie的时间,分钟',
1422
1421
  getLbsAddressCacheMinuteTime,
1423
1422
  'lbsAddressCacheToCookieMinuteTime',
1424
1423
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
1425
1424
  );
1426
1425
  if (getLbsAddressCacheMinuteTime > 0) {
1427
1426
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
1428
1427
  realTimeArea &&
1429
1428
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
1430
1429
  path: '/',
1431
1430
  expires,
1432
1431
  });
1433
1432
  }
1434
1433
  }
1435
1434
 
1436
1435
  getLbsAddressCachePromise() {
1437
1436
  if (!this.lbsAddressCachePromise) {
1438
1437
  this.lbsAddressCachePromise = new Promise((resolve) => {
1439
1438
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
1440
1439
  ? cookie.get(cacheH5LbsAddressKey)
1441
1440
  : '';
1442
1441
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
1443
1442
  if (getUserLbsAddress && getUserLbsAddress !== '') {
1444
1443
  resolve({
1445
1444
  ok: true,
1446
1445
  realTimeArea: getUserLbsAddress,
1447
1446
  });
1448
1447
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
1449
1448
  console.info(
1450
1449
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
1451
1450
  getCookieForLbsAddress,
1452
1451
  );
1453
1452
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
1454
1453
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
1455
1454
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
1456
1455
  realTimeArea: getCookieForLbsAddress,
1457
1456
  });
1458
1457
  resolve({
1459
1458
  ok: true,
1460
1459
  realTimeArea: getCookieForLbsAddress,
1461
1460
  });
1462
1461
  } else {
1463
1462
  this.getLbsCacheAddressRouter()
1464
1463
  .then((res) => {
1465
1464
  const { status, data } = res;
1466
1465
  console.log(
1467
1466
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
1468
1467
  status,
1469
1468
  data,
1470
1469
  res,
1471
1470
  );
1472
1471
  if (status === '0' && data) {
1473
1472
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
1474
1473
  data || {};
1475
1474
  let realTimeArea = '';
1476
1475
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
1477
1476
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
1478
1477
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
1479
1478
  if (getProvinceIdNum && getProvinceIdNum > 0) {
1480
1479
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
1481
1480
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
1482
1481
  this.info.sysInfo['realTimeArea'] = realTimeArea;
1483
1482
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
1484
1483
  realTimeArea: this.info.pageInfo.userLbsAddress,
1485
1484
  });
1486
1485
  this.createLbsCacheAddress(realTimeArea);
1487
1486
  } else {
1488
1487
  !origin && (this.lbsAddressCachePromise = null);
1489
1488
  }
1490
1489
  const getValidRealTimeArea = realTimeArea !== '';
1491
1490
  resolve({
1492
1491
  lat: this.info.sysInfo['srclat'],
1493
1492
  lng: this.info.sysInfo['srclng'],
1494
1493
  realTimeArea: realTimeArea,
1495
1494
  ok: getValidRealTimeArea,
1496
1495
  msg: getValidRealTimeArea
1497
1496
  ? '成功'
1498
1497
  : origin
1499
1498
  ? origin
1500
1499
  : '根据router底层获取lbs地址信息异常,详情见data',
1501
1500
  data: getValidRealTimeArea ? null : res,
1502
1501
  });
1503
1502
  if (!getValidRealTimeArea && !origin) {
1504
1503
  draBusinessCustomReport({
1505
1504
  eventName: 'business',
1506
1505
  errorName: 'h5_getLbsCacheAddress_info_err',
1507
1506
  errorMessage:
1508
1507
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
1509
1508
  extraData: JSON.stringify({
1510
1509
  isJdApp,
1511
1510
  jdAppVersion: jdAppVersionStr,
1512
1511
  }),
1513
1512
  });
1514
1513
  }
1515
1514
  } else {
1516
1515
  typeof res === 'object' &&
1517
1516
  draBusinessCustomReport({
1518
1517
  eventName: 'business',
1519
1518
  errorName: 'h5_getLbsCacheAddress_info_err',
1520
1519
  errorMessage:
1521
1520
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
1522
1521
  extraData: JSON.stringify({
1523
1522
  isJdApp,
1524
1523
  jdAppVersion: jdAppVersionStr,
1525
1524
  ...res,
1526
1525
  }),
1527
1526
  });
1528
1527
  this.lbsAddressCachePromise = null;
1529
1528
  resolve({ realTimeArea: '', ok: false });
1530
1529
  }
1531
1530
  })
1532
1531
  .catch((e) => {
1533
1532
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
1534
1533
  this.lbsAddressCachePromise = null;
1535
1534
  draBusinessCustomReport({
1536
1535
  eventName: 'business',
1537
1536
  errorName: 'h5_getLbsCacheAddress_info_err',
1538
1537
  errorMessage:
1539
1538
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
1540
1539
  extraData: JSON.stringify({
1541
1540
  isJdApp,
1542
1541
  jdAppVersion: jdAppVersionStr,
1543
1542
  }),
1544
1543
  });
1545
1544
  resolve({ realTimeArea: '', ok: false });
1546
1545
  });
1547
1546
  }
1548
1547
  });
1549
1548
  }
1550
1549
  return this.lbsAddressCachePromise;
1551
1550
  }
1552
1551
 
1553
1552
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1554
1553
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
1555
1554
  if (!isJdApp) {
1556
1555
  return;
1557
1556
  }
1558
1557
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
1559
1558
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
1560
1559
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
1561
1560
  'hybridHttpSwitch',
1562
1561
  isBeforePageReady,
1563
1562
  );
1564
1563
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
1565
1564
  'jshopIsVipShop',
1566
1565
  isBeforePageReady,
1567
1566
  );
1568
1567
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
1569
1568
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
1570
1569
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1571
1570
  'isFollowAppVideoPlayStatus',
1572
1571
  isBeforePageReady,
1573
1572
  );
1574
1573
  console.log(
1575
1574
  'isBeforePageReady:',
1576
1575
  isBeforePageReady,
1577
1576
  'isFollowAppVideoPlayStatus:',
1578
1577
  isFollowAppVideoPlayStatus,
1579
1578
  );
1580
1579
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
1581
1580
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
1582
1581
  }
1583
1582
  }
1584
1583
 
1585
1584
  async getWifiVideoAutoPlayAsync() {
1586
1585
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
1587
1586
  if (!isJdApp) {
1588
1587
  return;
1589
1588
  }
1590
1589
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
1591
1590
  return 0;
1592
1591
  });
1593
1592
  if (Number(videoPlayStatus) === 1) {
1594
1593
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
1595
1594
  }
1596
1595
  }
1597
1596
 
1598
1597
  async getMPaasConfigAsync() {
1599
1598
  this.info.sysInfo.dynamicConfig = {};
1600
1599
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
1601
1600
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
1602
1601
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
1603
1602
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
1604
1603
  return this.updateMPaasConfigAsync(true);
1605
1604
  }
1606
1605
 
1607
1606
  getDynamicConfig(key: string) {
1608
1607
  return this.info.sysInfo?.dynamicConfig?.[key];
1609
1608
  }
1610
1609
  async updateMPaasConfig() {
1611
1610
  console.log('updateMPaasConfig');
1612
1611
  if (
1613
1612
  isIosDevice &&
1614
1613
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1615
1614
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1616
1615
  ) {
1617
1616
  try {
1618
1617
  await this.updateMPaasConfigAsync(false);
1619
1618
  } catch (e) {
1620
1619
  console.log('updateMPaasConfigAsync:', e);
1621
1620
  }
1622
1621
  }
1623
1622
  }
1624
1623
 
1625
1624
  toLogin(options) {
1626
1625
  if (isAscfApp) {
1627
1626
  return this.toAscfAppLogin(options);
1628
1627
  }
1629
1628
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1630
1629
  ? this.toWxAppLogin(options)
1631
1630
  : this.toWebLogin(options);
1632
1631
  }
1633
1632
 
1634
1633
  doLogin(options) {
1635
1634
  return this.toLogin(options);
1636
1635
  }
1637
1636
 
1638
1637
  doLoginForJdPin(options = {}) {
1639
1638
  return this.doLogin({
1640
1639
  loginColor: {
1641
1640
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1642
1641
  dpin: 0,
1643
1642
  },
1644
1643
  ...options,
1645
1644
  });
1646
1645
  }
1647
1646
 
1648
1647
  toWebLogin(options) {
1649
1648
  let params: {
1650
1649
  returnurl: string;
1651
1650
  } = {
1652
1651
  returnurl: '',
1653
1652
  };
1654
1653
  const checkToPcLogin = options ? options?.isPc : isPc;
1655
1654
  const loginUrl = checkToPcLogin
1656
1655
  ? `//passport.jd.com/new/login.aspx`
1657
1656
  : `${domain.mobileLogin}/user/login.action`;
1658
1657
  const defaultParams = {
1659
1658
  appid: '100',
1660
1659
  returnurl: window.location.href,
1661
1660
  };
1662
1661
  if (isString(options)) {
1663
1662
  params = Object.assign({}, defaultParams, {
1664
1663
  returnurl: options,
1665
1664
  });
1666
1665
  } else if (isObject(options)) {
1667
1666
  const { loginColor, ...otherOptions } = options;
1668
1667
  params = Object.assign({}, defaultParams, otherOptions);
1669
1668
  } else {
1670
1669
  params = defaultParams;
1671
1670
  }
1672
1671
  params.returnurl = encodeURIComponent(params.returnurl);
1673
1672
  let getFullUrl = loginUrl + '?' + serialize(params);
1674
1673
  if (checkToPcLogin) {
1675
1674
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
1676
1675
  }
1677
1676
  return Promise.resolve({
1678
1677
  h5ToUrl: true,
1679
1678
  url: getFullUrl,
1680
1679
  }).then(() => {
1681
1680
  window.location.href = getFullUrl;
1682
1681
  });
1683
1682
  }
1684
1683
 
1685
1684
  toAscfAppLogin(options = {}) {
1686
1685
  console.log('华为元服务中h5登录跳转', options);
1687
1686
  return Promise.resolve(true).then(() => {
1688
1687
  const returnPage = encodeURIComponent(window.location.href);
1689
1688
  if (has && has.ascfweb) {
1690
1689
  has.ascfweb.redirectTo({
1691
1690
  url: `/pages/login/index/index?isH5=1&returnPage=${returnPage}&pageType=h5&source=shopx`,
1692
1691
  });
1693
1692
  }
1694
1693
  });
1695
1694
  }
1696
1695
 
1697
1696
  toWxAppLogin(options = {}) {
1698
1697
  console.log('微信京购小程序中h5登录跳转', options);
1699
1698
  return Promise.resolve(true).then(() => {
1700
1699
  const { loginColor } = Object.assign(
1701
1700
  {},
1702
1701
  {
1703
1702
  loginColor: {
1704
1703
  biz: WXAPP_BIZ_KEY,
1705
1704
  dpin: 1,
1706
1705
  },
1707
1706
  },
1708
1707
  options,
1709
1708
  );
1710
1709
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1711
1710
  loginColor.biz
1712
1711
  }&url=${encodeURIComponent(window.location.href)}`;
1713
1712
  });
1714
1713
  }
1715
1714
 
1716
1715
  getLoginCookie() {
1717
1716
  return Promise.resolve({
1718
1717
  pin: cookie.get('pin') || '',
1719
1718
  });
1720
1719
  }
1721
1720
 
1722
1721
  clearLoginCookie() {
1723
1722
  cookie.remove('pin');
1724
1723
  }
1725
1724
 
1726
1725
  checkStatusAndLogin(options = {}) {
1727
1726
  if (!this.checkStatusAndLoginPromise) {
1728
1727
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1729
1728
  try {
1730
1729
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
1731
1730
  if (getLoginState) {
1732
1731
  resolve(true);
1733
1732
  } else {
1734
1733
  this.toLogin(options);
1735
1734
  reject(false);
1736
1735
  }
1737
1736
  } catch (e) {
1738
1737
  this.toLogin(options);
1739
1738
  reject(false);
1740
1739
  }
1741
1740
  });
1742
1741
  return this.checkStatusAndLoginPromise;
1743
1742
  } else {
1744
1743
  return this.checkStatusAndLoginPromise
1745
1744
  .then(() => {
1746
1745
  return Promise.resolve(true);
1747
1746
  })
1748
1747
  .catch(() => {
1749
1748
  this.toLogin(options);
1750
1749
  return Promise.reject(true);
1751
1750
  });
1752
1751
  }
1753
1752
  }
1754
1753
 
1755
1754
  checkJdStatusAndLogin(
1756
1755
  options = {
1757
1756
  loginColor: {
1758
1757
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1759
1758
  dpin: 0,
1760
1759
  },
1761
1760
  },
1762
1761
  ) {
1763
1762
  return this.checkStatusAndLogin(options);
1764
1763
  }
1765
1764
 
1766
1765
  doCheckLoginStateAndForApiCheck(options) {
1767
1766
  if (this.info.loginState) {
1768
1767
  return Promise.resolve(true);
1769
1768
  } else {
1770
1769
  return new Promise((resolve, reject) => {
1771
1770
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
1772
1771
  const getWqAuthToken = cookie.get('wq_auth_token');
1773
1772
  const getWqSkey = cookie.get('wq_skey');
1774
1773
  const getWqUin = cookie.get('wq_uin');
1775
1774
  const isLoginState =
1776
1775
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
1777
1776
  if (isLoginState) {
1778
1777
  this.info.loginState = true;
1779
1778
  resolve(true);
1780
1779
  } else {
1781
1780
  reject(false);
1782
1781
  }
1783
1782
  } else {
1784
1783
  Taro.request({
1785
1784
  url: api.isLogin,
1786
1785
  jsonp: true,
1787
1786
  timeout: 3000,
1788
1787
  success: (res) => {
1789
1788
  const { statusCode, data } = res;
1790
1789
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
1791
1790
  this.info.loginState = true;
1792
1791
  resolve(true);
1793
1792
  } else {
1794
1793
  reject(false);
1795
1794
  }
1796
1795
  },
1797
1796
  fail: (err) => {
1798
1797
  console.log('登录检查异常', err);
1799
1798
  reject(false);
1800
1799
  },
1801
1800
  });
1802
1801
  }
1803
1802
  });
1804
1803
  }
1805
1804
  }
1806
1805
 
1807
1806
  checkLoginStatus(options) {
1808
1807
  return new Promise(async (resolve, reject) => {
1809
1808
  try {
1810
1809
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
1811
1810
  if (getLoginState) {
1812
1811
  const { pin } = await this.getLoginCookie();
1813
1812
  this.info.userInfo = {
1814
1813
  pin,
1815
1814
  encodePin: encodeURIComponent(pin),
1816
1815
  ptkey: '',
1817
1816
  };
1818
1817
  resolve(true);
1819
1818
  } else {
1820
1819
  reject(false);
1821
1820
  }
1822
1821
  } catch (e) {
1823
1822
  reject(false);
1824
1823
  }
1825
1824
  });
1826
1825
  }
1827
1826
 
1828
1827
  updatePageAndLogInfo(updateQuery = {}) {
1829
1828
  const createUpdateQueryInfo: {
1830
1829
  query: {
1831
1830
  shopId?: string | number;
1832
1831
  venderId?: string | number;
1833
1832
  };
1834
1833
  updateShopInfoState: boolean;
1835
1834
  } = Object.assign(
1836
1835
  {},
1837
1836
  {
1838
1837
  query: {},
1839
1838
  updateShopInfoState: false,
1840
1839
  },
1841
1840
  updateQuery,
1842
1841
  );
1843
1842
  console.log(
1844
1843
  '获取当前下发的店铺查询参数',
1845
1844
  updateQuery,
1846
1845
  '获取之前保存的shopInfo店铺查询参数',
1847
1846
  this.info?.shopInfo,
1848
1847
  );
1849
1848
  const { query, updateShopInfoState } = createUpdateQueryInfo;
1850
1849
  const { shopId, venderId, un_area } = query;
1851
1850
  if (updateShopInfoState) {
1852
1851
  this.info.queryInfo = {
1853
1852
  ...this.info.queryInfo,
1854
1853
  ...query,
1855
1854
  };
1856
1855
  if (shopId && venderId) {
1857
1856
  this.info.shopInfo = {
1858
1857
  shopId: `${shopId}`,
1859
1858
  venderId: `${venderId}`,
1860
1859
  };
1861
1860
  }
1862
1861
  } else {
1863
1862
  this.info.queryInfo = {
1864
1863
  ...query,
1865
1864
  };
1866
1865
  if (
1867
1866
  this.info.shopInfo?.shopId &&
1868
1867
  this.info.shopInfo?.venderId &&
1869
1868
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
1870
1869
  ) {
1871
1870
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
1872
1871
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
1873
1872
  console.log(
1874
1873
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1875
1874
  this.info.queryInfo,
1876
1875
  );
1877
1876
  }
1878
1877
  }
1879
1878
  this.info.queryInfo['shopId'] &&
1880
1879
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
1881
1880
  this.info.queryInfo['venderId'] &&
1882
1881
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
1883
1882
  console.log(
1884
1883
  'h5==获取店铺下发查询参数\n',
1885
1884
  query,
1886
1885
  '\n获取店铺最后查询参数\n',
1887
1886
  this.info.queryInfo,
1888
1887
  '\n是否为更新店铺状态\n',
1889
1888
  updateShopInfoState,
1890
1889
  );
1891
1890
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
1892
1891
  if (changeArea) {
1893
1892
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
1894
1893
  this.info.pageInfo.address = getBottomAreaStr;
1895
1894
  this.info.pageInfo.un_area = getBottomAreaStr;
1896
1895
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
1897
1896
  }
1898
1897
  }
1899
1898
 
1900
1899
  dealLoadSdkList() {
1901
1900
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
1902
1901
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
1903
1902
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
1904
1903
  let mergeLoadJsList = globalLoadJsList;
1905
1904
  try {
1906
1905
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
1907
1906
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
1908
1907
  getFindIndex !== -1
1909
1908
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
1910
1909
  : accArr.push(current);
1911
1910
  return accArr;
1912
1911
  }, []);
1913
1912
  } catch (e) {
1914
1913
  console.log('LoadJsList合并错误', e);
1915
1914
  }
1916
1915
  console.log(
1917
1916
  'globalLoadJsList',
1918
1917
  globalLoadJsList,
1919
1918
  'businessLoadJsList',
1920
1919
  businessLoadJsList,
1921
1920
  '两个加载jsList集合合并完成',
1922
1921
  mergeLoadJsList,
1923
1922
  );
1924
1923
  this.loadJsSdkList = mergeLoadJsList;
1925
1924
  return this.loadJsSdkList;
1926
1925
  }
1927
1926
 
1928
1927
  renderNextTickLoadSdk(delayTime = 1000) {
1929
1928
  Taro.nextTick(() => {
1930
1929
  console.log(
1931
1930
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
1932
1931
  );
1933
1932
  setTimeout(() => {
1934
1933
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
1935
1934
  }, delayTime);
1936
1935
  });
1937
1936
  }
1938
1937
 
1939
1938
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
1940
1939
  const getLoadJsList =
1941
1940
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
1942
1941
  const getLoadFilterList = getLoadJsList.filter((item) => {
1943
1942
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
1944
1943
  item.initLoadType = undefined;
1945
1944
  }
1946
1945
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
1947
1946
  let getLoastLoadEventState = true;
1948
1947
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
1949
1948
  getLoastLoadEventState = isJdApp;
1950
1949
  }
1951
1950
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
1952
1951
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
1953
1952
  }
1954
1953
  const getInitTriggerType =
1955
1954
  isJdApp && item?.initJdAppTriggerType
1956
1955
  ? item?.initTriggerType
1957
1956
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
1958
1957
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
1959
1958
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
1960
1959
  });
1961
1960
  console.log(
1962
1961
  '获取当前触发方式',
1963
1962
  triggerType,
1964
1963
  '获取当前最后加载的js集合',
1965
1964
  getLoadFilterList,
1966
1965
  '过滤前的加载集合',
1967
1966
  getLoadJsList,
1968
1967
  );
1969
1968
  const loadTasks =
1970
1969
  getLoadFilterList.length > 0
1971
1970
  ? getLoadFilterList.map((item) => {
1972
1971
  const isLoadState = /sgm/.test(item?.fileName)
1973
1972
  ? window?.shopGlobalSwitch?.openSgm === 'true'
1974
1973
  : true;
1975
1974
  if (!isLoadState) {
1976
1975
  return Promise.resolve(true);
1977
1976
  }
1978
1977
  return this.loadItemSdkPromise(item)
1979
1978
  .then((res) => {
1980
1979
  console.info('当前js地址' + item?.src, '加载状态', res);
1981
1980
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
1982
1981
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
1983
1982
  const getNewdraEnableShopIdPercentObj =
1984
1983
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || null;
1985
1984
  const getNewdraEnableVenderIdPercentObj =
1986
1985
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || null;
1987
1986
  let canInitDraRun = true;
1988
1987
  if (getNewdraEnableShopIdPercentObj || getNewdraEnableVenderIdPercentObj) {
1989
1988
  canInitDraRun = this.shouldPercentExecuteNewDra(
1990
1989
  this.getNewDraEnablePercentNum(),
1991
1990
  );
1992
1991
  }
1993
1992
  if (canInitDraRun) {
1994
1993
  window.dra.run('init', { aid: res?.aid });
1995
1994
  window.dra.run('start');
1996
1995
  }
1997
1996
  }
1998
1997
  return true;
1999
1998
  })
2000
1999
  .catch((err) => {
2001
2000
  console.info('当前js地址加载异常', item?.src);
2002
2001
  window?.fetchErrorData &&
2003
2002
  window.fetchErrorData({
2004
2003
  title: '公共js加载异常',
2005
2004
  type: 'jsLoad',
2006
2005
  data: err,
2007
2006
  });
2008
2007
  return true;
2009
2008
  });
2010
2009
  })
2011
2010
  : [];
2012
2011
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
2013
2012
  }
2014
2013
 
2015
2014
  shouldPercentExecuteNewDra(percent) {
2016
2015
  if (percent <= 0) return false;
2017
2016
  if (percent >= 100) return true;
2018
2017
  const getRes = Math.random() < percent / 100;
2019
2018
  console.log('获取dra初始化执行的概率为', percent, '执行结果', getRes);
2020
2019
  return getRes;
2021
2020
  }
2022
2021
 
2023
2022
  getNewDraEnablePercentNum() {
2024
2023
  const getNewdraEnableShopIdPercent =
2025
2024
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || {};
2026
2025
  const getNewdraEnableVenderIdPercent =
2027
2026
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || {};
2028
2027
  const getShopId = parseQueryUrlObj?.shopId || '';
2029
2028
  const getVenderId = parseQueryUrlObj?.venderId || '';
2030
2029
  const getShopIdDraEnablePercent = getNewdraEnableShopIdPercent[getShopId]
2031
2030
  ? getNewdraEnableShopIdPercent[getShopId]
2032
2031
  : getNewdraEnableShopIdPercent?.ids?.includes(getShopId)
2033
2032
  ? getNewdraEnableShopIdPercent?.idsNumber
2034
2033
  : -1;
2035
2034
  const getVenderIdDraEnablePercent = getNewdraEnableVenderIdPercent[getVenderId]
2036
2035
  ? getNewdraEnableVenderIdPercent[getVenderId]
2037
2036
  : getNewdraEnableVenderIdPercent?.ids?.includes(getVenderId)
2038
2037
  ? getNewdraEnableVenderIdPercent?.idsNumber
2039
2038
  : -1;
2040
2039
  if (getShopIdDraEnablePercent > -1 || getVenderIdDraEnablePercent > -1) {
2041
2040
  return getShopIdDraEnablePercent || getVenderIdDraEnablePercent;
2042
2041
  }
2043
2042
  return 100;
2044
2043
  }
2045
2044
  loadScriptEle(jsInfo, resolve, reject) {
2046
2045
  const getFileName = jsInfo?.fileName;
2047
2046
  if (getFileName) {
2048
2047
  const getEleId = `J_loadJs_${getFileName}`;
2049
2048
  const getEle = document.getElementById(getEleId);
2050
2049
  if (!getEle) {
2051
2050
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2052
2051
  const _sgmEle = document.createElement('script');
2053
2052
  _sgmEle.id = getEleId;
2054
2053
  _sgmEle.onload = function () {
2055
2054
  resolve({
2056
2055
  ...jsInfo,
2057
2056
  jsTip: 'js加载成功',
2058
2057
  });
2059
2058
  };
2060
2059
  _sgmEle.onerror = function () {
2061
2060
  reject({
2062
2061
  ...jsInfo,
2063
2062
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2064
2063
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
2065
2064
  });
2066
2065
  };
2067
2066
  const dataAttrList = ['timeout', 'fileName', 'env'];
2068
2067
  const getJsInfoKeyList = Object.keys(jsInfo);
2069
2068
  getJsInfoKeyList.forEach((key) => {
2070
2069
  if (key === 'async') {
2071
2070
  _sgmEle.async = jsInfo[key];
2072
2071
  } else if (key === 'crossOrigin') {
2073
2072
  _sgmEle.crossOrigin = jsInfo[key];
2074
2073
  } else if (key === 'src') {
2075
2074
  _sgmEle.src = `${jsInfo[key]}`;
2076
2075
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
2077
2076
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
2078
2077
  } else {
2079
2078
  _sgmEle.setAttribute(key, jsInfo[key]);
2080
2079
  }
2081
2080
  });
2082
2081
  document.head.appendChild(_sgmEle);
2083
2082
  } else {
2084
2083
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
2085
2084
  resolve({
2086
2085
  ...jsInfo,
2087
2086
  jsTip: 'js本身已存在页面中',
2088
2087
  });
2089
2088
  }
2090
2089
  } else {
2091
2090
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
2092
2091
  }
2093
2092
  }
2094
2093
 
2095
2094
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
2096
2095
  if (jsInfo?.src) {
2097
2096
  const getInitLoadType =
2098
2097
  isJdApp && jsInfo?.initJdAppLoadType
2099
2098
  ? jsInfo?.initJdAppLoadType
2100
2099
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
2101
2100
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
2102
2101
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
2103
2102
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
2104
2103
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
2105
2104
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2106
2105
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2107
2106
  try {
2108
2107
  const jsXhrRequest = new XMLHttpRequest();
2109
2108
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
2110
2109
  const jsUrl = `${jsInfo?.src}`;
2111
2110
  jsXhrRequest.open('GET', jsUrl, true);
2112
2111
  jsXhrRequest.onreadystatechange = () => {
2113
2112
  if (jsXhrRequest.readyState === 4) {
2114
2113
  const getReqStatus = jsXhrRequest.status;
2115
2114
  const statusText = jsXhrRequest.statusText;
2116
2115
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
2117
2116
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
2118
2117
  if (getInsetHeadState) {
2119
2118
  this.loadScriptEle(jsInfo, resolve, reject);
2120
2119
  } else {
2121
2120
  resolve({
2122
2121
  ...jsInfo,
2123
2122
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
2124
2123
  });
2125
2124
  }
2126
2125
  getReqStatus !== 200 &&
2127
2126
  draBusinessCustomReport({
2128
2127
  eventName: 'business',
2129
2128
  errorName: 'js_load_special_code',
2130
2129
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
2131
2130
  extraData: JSON.stringify({
2132
2131
  msg: '当前js加载成功,状态非200,特殊上报观察',
2133
2132
  jsReqState: getReqStatus,
2134
2133
  env: getSgmCustomCode('js_load_special_code'),
2135
2134
  data: jsInfo,
2136
2135
  }),
2137
2136
  });
2138
2137
  } else {
2139
2138
  const getRes = {
2140
2139
  ...jsInfo,
2141
2140
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2142
2141
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
2143
2142
  jsReqState: getReqStatus,
2144
2143
  };
2145
2144
  console.log('当前js请求状态异常,具体信息见', getRes);
2146
2145
  reject(getRes);
2147
2146
  }
2148
2147
  }
2149
2148
  };
2150
2149
  jsXhrRequest.onerror = () => {
2151
2150
  const getRes = {
2152
2151
  ...jsInfo,
2153
2152
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2154
2153
  jsReqError: '请求错误',
2155
2154
  };
2156
2155
  console.log('当前js请求错误', getRes);
2157
2156
  jsXhrRequest.abort();
2158
2157
  reject(getRes);
2159
2158
  };
2160
2159
  jsXhrRequest.ontimeout = () => {
2161
2160
  const getRes = {
2162
2161
  ...jsInfo,
2163
2162
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2164
2163
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
2165
2164
  jsReqState: jsXhrRequest.status,
2166
2165
  };
2167
2166
  console.log('当前js请求超时异常', getRes);
2168
2167
  jsXhrRequest.abort();
2169
2168
  reject(getRes);
2170
2169
  };
2171
2170
  jsXhrRequest.send();
2172
2171
  } catch (e) {
2173
2172
  console.log('执行js请求异常', e);
2174
2173
  reject({
2175
2174
  ...jsInfo,
2176
2175
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2177
2176
  jsReqError: '未知异常',
2178
2177
  error: e,
2179
2178
  });
2180
2179
  }
2181
2180
  });
2182
2181
  } else {
2183
2182
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2184
2183
  return this.loadScriptEle(jsInfo, resolve, reject);
2185
2184
  });
2186
2185
  }
2187
2186
  }
2188
2187
  return this.loadJsSdkListCachePromise[getFileKeyName];
2189
2188
  } else {
2190
2189
  return Promise.resolve({
2191
2190
  ...jsInfo,
2192
2191
  jsTip: 'js加载方式设置为不加载,当前不做处理',
2193
2192
  });
2194
2193
  }
2195
2194
  } else {
2196
2195
  return Promise.reject(jsInfo);
2197
2196
  }
2198
2197
  }
2199
2198
 
2200
2199
  createLanguagePromise() {
2201
2200
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
2202
2201
  if (!this.languageCacheProimse) {
2203
2202
  this.languageCacheProimse = new Promise((resolve, reject) => {
2204
2203
  const { fileName, prefixUrl } = getLanguageConfig;
2205
2204
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
2206
2205
  const dealLanguageFile = () => {
2207
2206
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
2208
2207
  .then((res: any) => {
2209
2208
  if (res && res?.data) {
2210
2209
  this.languageJsonData = res.data;
2211
2210
 
2212
2211
  setTimeout(() => {
2213
2212
  const getOtherLanguageList = languageTypeList.filter(
2214
2213
  (item) => item !== languageNowType,
2215
2214
  );
2216
2215
  getOtherLanguageList.length > 0 &&
2217
2216
  getOtherLanguageList.map((languageTypeKey) => {
2218
2217
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
2219
2218
  });
2220
2219
  }, 3000);
2221
2220
  resolve(res);
2222
2221
  } else {
2223
2222
  reject(res);
2224
2223
  }
2225
2224
  })
2226
2225
  .catch((err) => {
2227
2226
  reject(err);
2228
2227
  });
2229
2228
  };
2230
2229
  if (fileName && prefixUrl) {
2231
2230
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
2232
2231
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
2233
2232
  if (getLocalLangRes) {
2234
2233
  try {
2235
2234
  const getLocalLangJsonData =
2236
2235
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
2237
2236
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
2238
2237
  if (getLocalLangJsonData?.fileName === fileName) {
2239
2238
  const geThisLangData = getLocalLangJsonData.data;
2240
2239
  this.languageJsonData = geThisLangData;
2241
2240
  return resolve({
2242
2241
  ...getLanguageConfig,
2243
2242
  languageNowType,
2244
2243
  data: geThisLangData,
2245
2244
  });
2246
2245
  } else {
2247
2246
  dealLanguageFile();
2248
2247
  }
2249
2248
  } else {
2250
2249
  dealLanguageFile();
2251
2250
  }
2252
2251
  } catch (e) {
2253
2252
  return reject({
2254
2253
  languageNowType,
2255
2254
  msg: '转换错误',
2256
2255
  ...getLanguageConfig,
2257
2256
  });
2258
2257
  }
2259
2258
  } else {
2260
2259
  dealLanguageFile();
2261
2260
  }
2262
2261
  } else {
2263
2262
  return reject({
2264
2263
  languageNowType,
2265
2264
  msg: '文件对象下发异常',
2266
2265
  ...getLanguageConfig,
2267
2266
  });
2268
2267
  }
2269
2268
  });
2270
2269
  }
2271
2270
  return this.languageCacheProimse;
2272
2271
  }
2273
2272
 
2274
2273
  getLanguageFilePromise(info, languageTypeKey) {
2275
2274
  const { fileName, prefixUrl, timeout } = info || {};
2276
2275
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
2277
2276
  return new Promise((resolve, reject) => {
2278
2277
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
2279
2278
  try {
2280
2279
  const langXhrRequest = new XMLHttpRequest();
2281
2280
  langXhrRequest.timeout = timeout || 2000;
2282
2281
  langXhrRequest.open('GET', getUrl, true);
2283
2282
  langXhrRequest.responseType = 'json';
2284
2283
  langXhrRequest.onreadystatechange = () => {
2285
2284
  if (langXhrRequest.readyState === 4) {
2286
2285
  const getReqStatus = langXhrRequest.status;
2287
2286
  const statusText = langXhrRequest.statusText;
2288
2287
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
2289
2288
  const getData = langXhrRequest?.response || false;
2290
2289
  if (getData) {
2291
2290
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
2292
2291
  fileName,
2293
2292
  data: getData,
2294
2293
  });
2295
2294
  resolve({
2296
2295
  ...info,
2297
2296
  languageTypeKey,
2298
2297
  data: getData,
2299
2298
  });
2300
2299
  } else {
2301
2300
  reject({
2302
2301
  ...info,
2303
2302
  languageTypeKey,
2304
2303
  msg: '数据获取异常',
2305
2304
  });
2306
2305
  }
2307
2306
  } else {
2308
2307
  const getRes = {
2309
2308
  ...info,
2310
2309
  languageTypeKey,
2311
2310
  env: getSgmCustomCode(langLoadErrorSgmCode),
2312
2311
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
2313
2312
  };
2314
2313
  console.log('当前lang请求状态异常,具体信息见', getRes);
2315
2314
  reject(getRes);
2316
2315
  }
2317
2316
  }
2318
2317
  };
2319
2318
  langXhrRequest.onerror = () => {
2320
2319
  const getRes = {
2321
2320
  ...info,
2322
2321
  env: getSgmCustomCode(langLoadErrorSgmCode),
2323
2322
  msg: '请求错误',
2324
2323
  };
2325
2324
  console.log('当前lang请求错误', getRes);
2326
2325
  langXhrRequest.abort();
2327
2326
  reject(getRes);
2328
2327
  };
2329
2328
  langXhrRequest.ontimeout = () => {
2330
2329
  const getRes = {
2331
2330
  ...info,
2332
2331
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
2333
2332
  };
2334
2333
  console.log('执行lang多语言请求超时异常', getRes);
2335
2334
  langXhrRequest.abort();
2336
2335
  reject(getRes);
2337
2336
  };
2338
2337
  langXhrRequest.send();
2339
2338
  } catch (e) {
2340
2339
  console.log('执行lang多语言请求异常', e);
2341
2340
  reject({
2342
2341
  ...info,
2343
2342
  env: getSgmCustomCode(langLoadErrorSgmCode),
2344
2343
  msg: '未知异常',
2345
2344
  error: e,
2346
2345
  });
2347
2346
  }
2348
2347
  });
2349
2348
  }
2349
+ import Taro from '@tarojs/taro';
2350
2350
  BUSINESS_TYPE,
2351
2351
  cacheAppKey,
2352
2352
  cacheAppUuidKey,
2353
2353
  cacheH5LbsAddressKey,
2354
2354
  JSSDK_APP_WEBVIEW_CODE,
2355
2355
  LoadJsInitLoadEnvType,
2356
2356
  LoadJsInitLoadType,
2357
2357
  LoadJsInitTriggerType,
2358
2358
  MPAAS_CONFIG_APP_LOW_VERSION,
2359
2359
  MPAAS_CONFIG_APP_VERSION,
2360
2360
  SECTION_HOME_TAB_NAME_TYPE,
2361
2361
  SECTION_HOME_TAB_TYPE,
2362
2362
  TaroEventType,
2363
2363
  WX_BUSINESS_TYPE,
2364
2364
  WXAPP_BIZ_KEY,
2365
2365
  WXAPP_BIZ_SHOP_LIGHT_KEY,
2366
2366
  languageTypeList,
2367
2367
  getSystemInfos,
2368
2368
  getTaroStorageKeyValue,
2369
2369
  ipLoc_djd,
2370
2370
  setTaroStorage,
2371
2371
  isInJdAppH5DebugMode,
2372
2372
  isHarmonyDevice,
2373
2373
  callRouterAndroid,
2374
2374
  callRouterIOS,
2375
2375
  getMPaasConfigByBussinessKey,
2376
2376
  dealNativePixelToCssPixel,
2377
2377
  draBusinessCustomReport,
2378
2378
  isAndroidDevice,
2379
2379
  isH5AndJingGouMini,
2380
2380
  isIosDevice,
2381
2381
  isJdAndAndroidDevice,
2382
2382
  isObject,
2383
2383
  isPc,
2384
2384
  isString,
2385
2385
  jdAppVersion,
2386
2386
  jdAppVersionStr,
2387
2387
  serialize,
2388
2388
  languageNowType,
2389
2389
  urlCookie,
2390
2390
  isAscfApp,
2391
2391
  jdAppVersionCompare,
2392
2392
  parseQueryUrlObj,
2393
2393
  abTestLabels: {},
2394
2394
  nonSellableSkuids: {},
2395
2395
  loginState: false,
2396
2396
  cookiesStr: '',
2397
2397
  userInfo: userPinKey,
2398
2398
  isImmersive:
2399
2399
  !window?.shopGlobalSwitch?.disableImmersive &&
2400
2400
  isJdApp &&
2401
2401
  window.location?.search.includes('immersive=1'),
2402
2402
  isJingGouMiniViewState: false,
2403
2403
  isJingxiMiniViewState: false,
2404
2404
  baseAddCartSwitch: true,
2405
2405
  pageInfo: {
2406
2406
  wxBusinessType: WX_BUSINESS_TYPE.NO,
2407
2407
  address: '',
2408
2408
  addressCommaStr: '',
2409
2409
  fullAddress: '',
2410
2410
  un_area: '',
2411
2411
  userLbsAddress: '',
2412
2412
  vapptype: '1',
2413
2413
  pageType: 'home',
2414
2414
  isExposureState: false,
2415
2415
  moduleId: '',
2416
2416
  entrance: '',
2417
2417
  dataType: BUSINESS_TYPE.ONLINE,
2418
2418
  floorExposureInfo: {},
2419
2419
  floorVideInfo: {},
2420
2420
  productVideInfo: {},
2421
2421
  tabsLoadAllDataInfo: {
2422
2422
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
2423
2423
  },
2424
2424
  updateShopInfosAllState: false,
2425
2425
  isVipShop: false,
2426
2426
  isJdShowNativeImmersivePlayer: false,
2427
2427
  isSuperBrandShop: false,
2428
2428
  ...shopConfig,
2429
2429
  pageScrollTop: 0,
2430
2430
  pageIdxHeightInfo: {
2431
2431
  list: [],
2432
2432
  },
2433
2433
  shopNavBarHeight: 0,
2434
2434
  },
2435
2435
  defaultQueryLogInfo: {
2436
2436
  sourceType: 'JDshop',
2437
2437
  sourceValue: '',
2438
2438
  moduleId: 'none',
2439
2439
  entrance: 'none',
2440
2440
  },
2441
2441
  sysInfo: {
2442
2442
  windowWidth: isPc ? 375 : 0,
2443
2443
  containerWidth: isPc ? 375 : 0,
2444
2444
  windowHeight: 0,
2445
2445
  netWorkType: '4g',
2446
2446
  jdBottomBarHeight: 0,
2447
2447
  jdNativeHeaderHeight: 0,
2448
2448
  isJdTabletDevice: false,
2449
2449
  isJdTabletLandscape: false,
2450
2450
  },
2451
2451
  queryInfo: {},
2452
2452
  shopInfo: {},
2453
2453
  openAppData: {},
2454
2454
  public info: CommonInterFace.BaseConfigInfo;
2455
2455
  public config: {
2456
2456
  [key: string]: any;
2457
2457
  };
2458
2458
  public lazyContainer: CommonInterFace.lazyContainer;
2459
2459
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
2460
2460
  public rootEleNode: HTMLElement | null;
2461
2461
  public checkStatusAndLoginPromise: object | null;
2462
2462
  private jmfeRegisterStatePromise: Promise<any> | null;
2463
2463
  private jdScreenSizeInfoPromise: Promise<any> | null;
2464
2464
  private rootEleWidthRegisterPromise: Promise<any> | null;
2465
2465
  private loadJsH5tagStatePromise: Promise<any> | null;
2466
2466
  private loadJsApiRequestStatePromise: Promise<any> | null;
2467
2467
  private jmfeRegisterState: boolean;
2468
2468
  public loadJsSdkList: {
2469
2469
  src: string;
2470
2470
  timeout: number;
2471
2471
  fileName: string;
2472
2472
  initTriggerType: typeof LoadJsInitTriggerType;
2473
2473
  initLinkTriggerWay:
2474
2474
  | 'asyncLoadAppSdkJs'
2475
2475
  | 'asyncLoadHandlerJs'
2476
2476
  | 'asyncLoadReportJs'
2477
2477
  | 'asyncLoadMtkJs'
2478
2478
  | 'asyncLoadSecurityJs'
2479
2479
  | 'asyncLoadSgmJs'
2480
2480
  | 'asyncLoadCartJs'
2481
2481
  | 'asyncLoadNewDraSdkJs'
2482
2482
  | 'asyncLoadH5TagJs';
2483
2483
  initLoadEnvType: typeof LoadJsInitLoadEnvType;
2484
2484
  defer?: 'true';
2485
2485
  async?: 'true';
2486
2486
  crossOrigin: 'anonymous' | '';
2487
2487
  }[];
2488
2488
  public loadJsSdkListCachePromise: any;
2489
2489
  public rootEleInitWidth: number;
2490
2490
  public lbsAddressCachePromise: Promise<any> | null;
2491
2491
  public languageCacheProimse: Promise<any> | null;
2492
2492
  public languageJsonData: any | null;
2493
2493
  public businessWorkerReady: boolean;
2494
2494
  public businessWorkerReadyPromise: Promise<any> | null;
2495
2495
  public workerPreRequestData = new Map<string, any>();
2496
2496
  constructor(opt) {
2497
2497
  this.info = this._getConfig(opt);
2498
2498
  this.config = {};
2499
2499
  this.loadJsSdkList = [];
2500
2500
  this.loadJsSdkListCachePromise = {};
2501
2501
  this.lazyContainer = {
2502
2502
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
2503
2503
  appLazyContainerList: [],
2504
2504
  appLazyFinishContainerList: [],
2505
2505
  },
2506
2506
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
2507
2507
  appLazyContainerList: [],
2508
2508
  appLazyFinishContainerList: [],
2509
2509
  },
2510
2510
  };
2511
2511
  this.renderedIsvComponents = {};
2512
2512
  this.rootEleNode = document.querySelector('body');
2513
2513
  this.checkStatusAndLoginPromise = null;
2514
2514
  this.jmfeRegisterStatePromise = null;
2515
2515
  this.jdScreenSizeInfoPromise = null;
2516
2516
  this.rootEleWidthRegisterPromise = null;
2517
2517
  this.lbsAddressCachePromise = null;
2518
2518
  this.languageCacheProimse = null;
2519
2519
  this.businessWorkerReady = false;
2520
2520
  this.businessWorkerReadyPromise = null;
2521
2521
  this.loadJsH5tagStatePromise = null;
2522
2522
  this.loadJsApiRequestStatePromise = null;
2523
2523
  this.workerPreRequestData = new Map<string, any>();
2524
2524
  this.languageJsonData = langeJsonDataForCn;
2525
2525
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
2526
2526
  this._init();
2527
2527
  if (isJdApp) {
2528
2528
  this.jmfeReayPromise().then(() => {
2529
2529
  this.jdWorkerReadyPromise();
2530
2530
  initAccessibility();
2531
2531
  });
2532
2532
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
2533
2533
  }
2534
2534
  }
2535
2535
  _getConfig(opt) {
2536
2536
  return Object.assign({}, DefaultConfig, opt);
2537
2537
  }
2538
2538
  _init() {
2539
2539
  this.loadOtherSdk();
2540
2540
  this.checkJdAddCartState();
2541
2541
  this.checkPageDomHeightToReport();
2542
2542
  }
2543
2543
  checkPageDomHeightToReport() {
2544
2544
  Taro.nextTick(() => {
2545
2545
  setTimeout(() => {
2546
2546
  const getReportData = {
2547
2547
  containerFloorLisHeight: -1,
2548
2548
  appHeight: -1,
2549
2549
  };
2550
2550
  const getAppEle = document.getElementById('app');
2551
2551
  const getFloorContainerEle = document.getElementById('J_shopContainerFloorList');
2552
2552
  const getNetWorkEle = document.querySelector('.J_shopNetwork');
2553
2553
  getFloorContainerEle &&
2554
2554
  (getReportData.containerFloorLisHeight =
2555
2555
  getFloorContainerEle?.getBoundingClientRect()?.height ?? -1);
2556
2556
  getAppEle && (getReportData.appHeight = getAppEle?.getBoundingClientRect()?.height ?? -1);
2557
2557
  const getMaxHeight = Math.max(
2558
2558
  getReportData.appHeight,
2559
2559
  getReportData.containerFloorLisHeight,
2560
2560
  );
2561
2561
  if (!getNetWorkEle && getMaxHeight > -1 && getMaxHeight < 80) {
2562
2562
  draBusinessCustomReport({
2563
2563
  eventName: 'business',
2564
2564
  errorName: 'pageDomHeightErrorCheck',
2565
2565
  errorMessage:
2566
2566
  '当前页面总高度异常小于80px,没有兜底network组件,可能空窗,请检查核对详细信息',
2567
2567
  extraData: JSON.stringify({
2568
2568
  data: getReportData,
2569
2569
  isJdApp,
2570
2570
  }),
2571
2571
  });
2572
2572
  }
2573
2573
  }, window?.shopGlobalSwitch?.checkPageDomHeightTime || 4000);
2574
2574
  });
2575
2575
  }
2576
2576
 
2577
2577
  checkJdAddCartState() {
2578
2578
  const getJdAppForNotMainRemoveCartUaList = isJdApp
2579
2579
  ? window?.PAGE_DATA?.businessData?.jdAppForNotMainRemoveCartUaList
2580
2580
  : undefined;
2581
2581
  if (
2582
2582
  getJdAppForNotMainRemoveCartUaList &&
2583
2583
  Array.isArray(getJdAppForNotMainRemoveCartUaList) &&
2584
2584
  getJdAppForNotMainRemoveCartUaList.length > 0
2585
2585
  ) {
2586
2586
  const setFilterReg = new RegExp(getJdAppForNotMainRemoveCartUaList.join('|'), 'i');
2587
2587
  this.info.baseAddCartSwitch = !setFilterReg.test(window.navigator.userAgent);
2588
2588
  }
2589
2589
  }
2590
2590
 
2591
2591
  loadApiSafeSteadyReayPromise() {
2592
2592
  if (!this.loadJsApiRequestStatePromise) {
2593
2593
  this.loadJsApiRequestStatePromise = this.loadOtherSdk(LoadJsInitTriggerType.API_REQUEST);
2594
2594
  }
2595
2595
  return this.loadJsApiRequestStatePromise;
2596
2596
  }
2597
2597
 
2598
2598
  loadH5tagReayPromise() {
2599
2599
  if (!this.loadJsH5tagStatePromise) {
2600
2600
  const h5TagJs = this.loadJsSdkList.find((e) => e.fileName === 'h5TagJs');
2601
2601
  this.loadJsH5tagStatePromise = !h5TagJs
2602
2602
  ? Promise.resolve(true)
2603
2603
  : this.loadOtherSdk(LoadJsInitTriggerType.NOW, [
2604
2604
  Object.assign({}, h5TagJs, {
2605
2605
  initTriggerType: LoadJsInitTriggerType.NOW,
2606
2606
  }),
2607
2607
  ]);
2608
2608
  }
2609
2609
  return this.loadJsH5tagStatePromise;
2610
2610
  }
2611
2611
 
2612
2612
  jmfeReayPromise(): Promise<any> {
2613
2613
  if (isJdApp) {
2614
2614
  if (this.jmfeRegisterState) {
2615
2615
  return Promise.resolve(true);
2616
2616
  } else {
2617
2617
  !this.jmfeRegisterStatePromise &&
2618
2618
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
2619
2619
  ready('jmfe', 3000)
2620
2620
  .then(() => {
2621
2621
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
2622
2622
  this.jmfeRegisterState = true;
2623
2623
  resolve(true);
2624
2624
  console.log(
2625
2625
  '松果app内初始化注册jmfe认证完成',
2626
2626
  window?.jmfe,
2627
2627
  '当前版本',
2628
2628
  window?.jmfe?.VERSION,
2629
2629
  );
2630
2630
  })
2631
2631
  .catch((err) => {
2632
2632
  console.error('jmfe ready error', err);
2633
2633
  reject(false);
2634
2634
  });
2635
2635
  }));
2636
2636
  return this.jmfeRegisterStatePromise;
2637
2637
  }
2638
2638
  } else {
2639
2639
  return Promise.reject(false);
2640
2640
  }
2641
2641
  }
2642
2642
 
2643
2643
  jdWorkerReadyPromise(): Promise<any> {
2644
2644
  if (isJdApp) {
2645
2645
  if (this.businessWorkerReady) {
2646
2646
  return Promise.resolve(true);
2647
2647
  } else {
2648
2648
  const getOpenJdWorkerState =
2649
2649
  window?.PAGE_DATA?.businessData?.businessWorkerVersion &&
2650
2650
  versionCompare(
2651
2651
  jdAppVersionStr,
2652
2652
  window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10',
2653
2653
  ) >= 0;
2654
2654
  !this.businessWorkerReadyPromise &&
2655
2655
  (this.businessWorkerReadyPromise = getOpenJdWorkerState
2656
2656
  ? new Promise((resolve) => {
2657
2657
  this.jmfeReayPromise()
2658
2658
  .then(() => {
2659
2659
  window.jmfe
2660
2660
  .onMsgForWorker(
2661
2661
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
2662
2662
  (workerData) => {
2663
2663
  console.log('收到业务jd worker消息结果:', workerData);
2664
2664
  if (workerData && workerData?.workerType) {
2665
2665
  const getWorkerType = workerData?.workerType;
2666
2666
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
2667
2667
  this.workerPreRequestData.set(workerData?.functionId, workerData);
2668
2668
  Taro.eventCenter.trigger(getWorkerType, workerData);
2669
2669
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
2670
2670
  Taro.eventCenter.trigger(getWorkerType, workerData);
2671
2671
  }
2672
2672
  }
2673
2673
  },
2674
2674
  )
2675
2675
  .then(() => {
2676
2676
  console.log('jd worker注册成功');
2677
2677
  this.businessWorkerReady = true;
2678
2678
  resolve(true);
2679
2679
  })
2680
2680
  .catch((error) => {
2681
2681
  console.log(
2682
2682
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
2683
2683
  error,
2684
2684
  );
2685
2685
  draBusinessCustomReport({
2686
2686
  eventName: 'business',
2687
2687
  errorName: 'jmfe_onMsgForWorker_error',
2688
2688
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
2689
2689
  extraData: JSON.stringify({
2690
2690
  businessWorkerVersion:
2691
2691
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
2692
2692
  error,
2693
2693
  }),
2694
2694
  });
2695
2695
  resolve(false);
2696
2696
  });
2697
2697
  })
2698
2698
  .catch((err) => {
2699
2699
  console.log('jmfe超时异常,worker注册失败', err);
2700
2700
  resolve(false);
2701
2701
  });
2702
2702
  })
2703
2703
  : Promise.resolve(false));
2704
2704
  }
2705
2705
  return this.businessWorkerReadyPromise;
2706
2706
  } else {
2707
2707
  return Promise.resolve(false);
2708
2708
  }
2709
2709
  }
2710
2710
 
2711
2711
  taskTimeoutPromise(callBack, timeout = 2000) {
2712
2712
  return new Promise((resolve) => {
2713
2713
  setTimeout(
2714
2714
  () => {
2715
2715
  const getCallBackRes = typeof callBack === 'function' && callBack();
2716
2716
  return resolve(getCallBackRes || false);
2717
2717
  },
2718
2718
  isInJdAppH5DebugMode ? 0 : timeout,
2719
2719
  );
2720
2720
  });
2721
2721
  }
2722
2722
  _getJdPadMinWidthForListen() {
2723
2723
  return (
2724
2724
  isJdApp &&
2725
2725
  Math.min(window.screen.width, window.screen.height) >
2726
2726
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
2727
2727
  );
2728
2728
  }
2729
2729
 
2730
2730
  getJdScreenSizeInfoPromise() {
2731
2731
  !this.jdScreenSizeInfoPromise &&
2732
2732
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
2733
2733
  const getThisTime = Date.now();
2734
2734
  this.jmfeReayPromise().then(() => {
2735
2735
  return Promise.race([
2736
2736
  window.jmfe.getScreenSize(),
2737
2737
  this.taskTimeoutPromise(() => {
2738
2738
  return {
2739
2739
  status: '-10',
2740
2740
  msg: '获取大屏信息2s超时',
2741
2741
  };
2742
2742
  }),
2743
2743
  ])
2744
2744
  .then((res) => {
2745
2745
  console.warn('===获取app大屏信息====', res);
2746
2746
  const { status, data } = res;
2747
2747
  if (status === '0' && data) {
2748
2748
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
2749
2749
  const getPageInfo = dealNativePixelToCssPixel({
2750
2750
  pageWidth,
2751
2751
  pageHeight,
2752
2752
  });
2753
2753
  this.info.sysInfo.jdScreenSizeType = sizeType;
2754
2754
  const getUseTime = Date.now() - getThisTime;
2755
2755
  console.warn(
2756
2756
  '===计算是否是app大屏信息,需满足宽度最新720===',
2757
2757
  getPageInfo,
2758
2758
  '原始数据',
2759
2759
  data,
2760
2760
  '是否是横屏isLandscape为1=',
2761
2761
  isLandscape,
2762
2762
  '用时',
2763
2763
  getUseTime,
2764
2764
  );
2765
2765
  if (getPageInfo?.pageWidth > 0) {
2766
2766
  this.rootEleInitWidth = getPageInfo?.pageWidth;
2767
2767
  draBusinessCustomReport({
2768
2768
  eventName: 'UIInteract',
2769
2769
  errorName: 'rootEle_width_getJdScreenSizeInfo',
2770
2770
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
2771
2771
  extraData: JSON.stringify({
2772
2772
  isJdApp,
2773
2773
  getPageInfo,
2774
2774
  originData: res,
2775
2775
  }),
2776
2776
  });
2777
2777
  resolve(getPageInfo);
2778
2778
  } else {
2779
2779
  resolve({
2780
2780
  pageWidth: 0,
2781
2781
  pageHeight: 0,
2782
2782
  msg: '转换异常',
2783
2783
  });
2784
2784
  }
2785
2785
  } else {
2786
2786
  resolve({
2787
2787
  pageWidth: 0,
2788
2788
  pageHeight: 0,
2789
2789
  msg: '获取大屏信息异常或者超时',
2790
2790
  });
2791
2791
  }
2792
2792
  })
2793
2793
  .catch((err) => {
2794
2794
  console.log('获取大屏信息异常', err);
2795
2795
  resolve({
2796
2796
  pageWidth: 0,
2797
2797
  pageHeight: 0,
2798
2798
  msg: '获取大屏信息异常',
2799
2799
  });
2800
2800
  });
2801
2801
  });
2802
2802
  }));
2803
2803
  return this.jdScreenSizeInfoPromise;
2804
2804
  }
2805
2805
 
2806
2806
  listenJdTabletScreenChange() {
2807
2807
  this.jmfeReayPromise().then(() => {
2808
2808
  try {
2809
2809
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
2810
2810
  window.jmfe.listenDeviceScreenChange((event) => {
2811
2811
  console.log(
2812
2812
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
2813
2813
  event,
2814
2814
  '通过前端判断是不是横屏',
2815
2815
  window.matchMedia('(orientation: landscape)')?.matches,
2816
2816
  );
2817
2817
  let { orientation } = event?.data;
2818
2818
  if (isHarmonyDevice && !orientation && event && event.data && event.data.data) {
2819
2819
  orientation = event.data.data.orientation;
2820
2820
  }
2821
2821
  if (orientation) {
2822
2822
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
2823
2823
  Taro.eventCenter.trigger(
2824
2824
  TaroEventType.TABLE_SCREEN_CHANGE,
2825
2825
  this.info.sysInfo.isJdTabletLandscape,
2826
2826
  orientation,
2827
2827
  );
2828
2828
  }
2829
2829
  });
2830
2830
  } catch (error) {
2831
2831
  console.log('listenScreenChange的打印error:', error);
2832
2832
  }
2833
2833
  });
2834
2834
  }
2835
2835
 
2836
2836
  updateBusinessDomainAndApi(domain, api) {
2837
2837
  }
2838
2838
 
2839
2839
  formatNativeScreenPageData(action) {
2840
2840
  let getChangePageInfo: any = null;
2841
2841
  try {
2842
2842
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
2843
2843
  JSON.stringify({
2844
2844
  plugin: 'JDHybridScreenPlugin',
2845
2845
  action,
2846
2846
  sync: '1',
2847
2847
  }),
2848
2848
  );
2849
2849
  const getChangePageInfoData =
2850
2850
  typeof getNativeScreenPageInfoStr === 'string'
2851
2851
  ? JSON.parse(getNativeScreenPageInfoStr)
2852
2852
  : null;
2853
2853
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
2854
2854
  const { code, data } = getChangePageInfoData;
2855
2855
  getChangePageInfo = code && code === '0' ? data : null;
2856
2856
  }
2857
2857
  } catch (e) {
2858
2858
  console.log('JDHybridScreenPlugin转换异常', e);
2859
2859
  }
2860
2860
  return getChangePageInfo;
2861
2861
  }
2862
2862
 
2863
2863
  isAndroidFoldScreen() {
2864
2864
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
2865
2865
  }
2866
2866
 
2867
2867
  isHarmonyFoldScreenPromise(): Promise<{
2868
2868
  isFoldScreen: boolean;
2869
2869
  getFoldDisplayMode?: number;
2870
2870
  }> {
2871
2871
  return new Promise((resolve) => {
2872
2872
  this.jmfeReayPromise()
2873
2873
  .then(() => {
2874
2874
  if (window.jmfe?.callNative) {
2875
2875
  Promise.all([
2876
2876
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
2877
2877
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
2878
2878
  ])
2879
2879
  .then((res) => {
2880
2880
  resolve({
2881
2881
  isFoldScreen: res?.[0]?.data === '1',
2882
2882
  getFoldDisplayMode: res?.[1]?.data,
2883
2883
  });
2884
2884
  })
2885
2885
  .catch(() => {
2886
2886
  resolve({
2887
2887
  isFoldScreen: false,
2888
2888
  getFoldDisplayMode: undefined,
2889
2889
  });
2890
2890
  });
2891
2891
  } else {
2892
2892
  resolve({
2893
2893
  isFoldScreen: false,
2894
2894
  getFoldDisplayMode: undefined,
2895
2895
  });
2896
2896
  }
2897
2897
  })
2898
2898
  .catch(() => {
2899
2899
  resolve({
2900
2900
  isFoldScreen: false,
2901
2901
  getFoldDisplayMode: undefined,
2902
2902
  });
2903
2903
  });
2904
2904
  });
2905
2905
  }
2906
2906
 
2907
2907
  getJdAndroidPageChangeScreenInfo() {
2908
2908
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
2909
2909
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
2910
2910
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
2911
2911
  pageWidth: getPageScreenInfo.pageWidth,
2912
2912
  pageHeight: getPageScreenInfo.pageHeight,
2913
2913
  });
2914
2914
  getPageScreenInfo.pageWidth = pageWidth;
2915
2915
  getPageScreenInfo.pageHeight = pageHeight;
2916
2916
  }
2917
2917
  return getPageScreenInfo;
2918
2918
  }
2919
2919
 
2920
2920
  getRootEleWindowWidthInfo() {
2921
2921
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
2922
2922
  const getWindowWidth = window.innerWidth;
2923
2923
  const getScreenWidth = window.screen.width;
2924
2924
  return {
2925
2925
  getRootEleWidth,
2926
2926
  getWindowWidth,
2927
2927
  getScreenWidth,
2928
2928
  };
2929
2929
  }
2930
2930
 
2931
2931
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
2932
2932
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
2933
2933
  console.log(
2934
2934
  '当前获取根元素的宽度',
2935
2935
  getRootEleWidth,
2936
2936
  'getWindowWidth',
2937
2937
  getWindowWidth,
2938
2938
  'getScreenWidth',
2939
2939
  getScreenWidth,
2940
2940
  );
2941
2941
  const getLastWidth =
2942
2942
  getRootEleWidth > 0
2943
2943
  ? Math.round(getRootEleWidth)
2944
2944
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
2945
2945
  console.warn(
2946
2946
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2947
2947
  );
2948
2948
  timeout > 0 &&
2949
2949
  draBusinessCustomReport({
2950
2950
  eventName: 'UIInteract',
2951
2951
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
2952
2952
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2953
2953
  extraData: JSON.stringify({
2954
2954
  isJdApp,
2955
2955
  getRootEleWidth,
2956
2956
  getWindowWidth,
2957
2957
  getScreenWidth,
2958
2958
  ...reportParam,
2959
2959
  }),
2960
2960
  });
2961
2961
  return getLastWidth;
2962
2962
  }
2963
2963
 
2964
2964
  getPadWindowRootEleWidthPromise() {
2965
2965
  if (this.rootEleInitWidth > 0) {
2966
2966
  return Promise.resolve(this.rootEleInitWidth);
2967
2967
  } else {
2968
2968
  !this.rootEleWidthRegisterPromise &&
2969
2969
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
2970
2970
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
2971
2971
  if (getRootEleInitWidth > 0) {
2972
2972
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
2973
2973
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
2974
2974
  resolve(this.rootEleInitWidth);
2975
2975
  } else {
2976
2976
  const timerPromise = () => {
2977
2977
  return new Promise((resolve2) => {
2978
2978
  window.setTimeout(() => {
2979
2979
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
2980
2980
  this.getRootEleWindowWidthInfo();
2981
2981
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
2982
2982
  console.warn(
2983
2983
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
2984
2984
  );
2985
2985
  draBusinessCustomReport({
2986
2986
  eventName: 'UIInteract',
2987
2987
  errorName: 'rootEle_width_200_timeout_info',
2988
2988
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
2989
2989
  extraData: JSON.stringify({
2990
2990
  isJdApp,
2991
2991
  getRootEleWidth,
2992
2992
  getWindowWidth,
2993
2993
  getScreenWidth,
2994
2994
  }),
2995
2995
  });
2996
2996
  const getRes =
2997
2997
  getRootEleWidth > 0 && getWindowWidth > 0
2998
2998
  ? Math.min(getRootEleWidth, getWindowWidth)
2999
2999
  : Math.max(getRootEleWidth, getWindowWidth);
3000
3000
  resolve2({
3001
3001
  pageWidth: Math.round(getRes),
3002
3002
  });
3003
3003
  }
3004
3004
  }, 200);
3005
3005
  });
3006
3006
  };
3007
3007
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
3008
3008
  const { pageWidth } = res;
3009
3009
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
3010
3010
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
3011
3011
  });
3012
3012
  }
3013
3013
  }));
3014
3014
  return this.rootEleWidthRegisterPromise;
3015
3015
  }
3016
3016
  }
3017
3017
 
3018
3018
  async getSystemInfo(params) {
3019
3019
  const getParams = Object.assign({}, params || {});
3020
3020
  if (this.rootEleInitWidth > 0) {
3021
3021
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
3022
3022
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
3023
3023
  } else {
3024
3024
  if (this._getJdPadMinWidthForListen()) {
3025
3025
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
3026
3026
  getParams['replaceSystemWidth'] = true;
3027
3027
  }
3028
3028
  }
3029
3029
  isJdApp && this.createLanguagePromise();
3030
3030
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
3031
3031
  let _isfoldScreen = false;
3032
3032
  if (
3033
3033
  (isJdAndAndroidDevice || isJdAndHarmonyDevice) &&
3034
3034
  (!info?.initWindowWidth || info?.initWindowWidth <= 0)
3035
3035
  ) {
3036
3036
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
3037
3037
  console.info(
3038
3038
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
3039
3039
  getStorageData,
3040
3040
  '通过缓存值第一次判断是否是折叠屏',
3041
3041
  getStorageData === 'true',
3042
3042
  );
3043
3043
  if (!getStorageData && isJdAndAndroidDevice) {
3044
3044
  _isfoldScreen = this.isAndroidFoldScreen();
3045
3045
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
3046
3046
  } else if (!getStorageData && isJdAndHarmonyDevice) {
3047
3047
  const result = await this.isHarmonyFoldScreenPromise();
3048
3048
  _isfoldScreen = result.isFoldScreen;
3049
3049
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
3050
3050
  } else {
3051
3051
  _isfoldScreen = getStorageData === 'true';
3052
3052
  }
3053
3053
  if (_isfoldScreen && isJdAndAndroidDevice) {
3054
3054
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
3055
3055
  if (getJdAndroidPageInfo) {
3056
3056
  info = getSystemInfos(getJdAndroidPageInfo);
3057
3057
  console.warn(
3058
3058
  '当前为松果安卓折叠屏app,获取折叠屏信息',
3059
3059
  getJdAndroidPageInfo,
3060
3060
  '获取转换后的系统信息',
3061
3061
  info,
3062
3062
  );
3063
3063
  draBusinessCustomReport({
3064
3064
  eventName: 'UIInteract',
3065
3065
  errorName: 'android_jdapp_foldScreen_info',
3066
3066
  errorMessage:
3067
3067
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
3068
3068
  extraData: JSON.stringify({
3069
3069
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
3070
3070
  androidPageInfo: getJdAndroidPageInfo,
3071
3071
  jdAppVersionStr,
3072
3072
  taroSysInfo: info,
3073
3073
  }),
3074
3074
  });
3075
3075
  }
3076
3076
  }
3077
3077
  }
3078
3078
  if (isJdApp) {
3079
3079
  (info?.isJdTabletDevice || _isfoldScreen) && this.listenJdTabletScreenChange();
3080
3080
  }
3081
3081
  this.info.sysInfo = {
3082
3082
  actualNavBarHeight: 0,
3083
3083
  ...this.info.sysInfo,
3084
3084
  ...info,
3085
3085
  safeContentHeight: info?.screenHeight,
3086
3086
  headerHeight: 0,
3087
3087
  tabBarHeight: 0,
3088
3088
  languageType: languageNowType,
3089
3089
  };
3090
3090
  if (isJdApp || isH5AndJingGouMini) {
3091
3091
  this.getAddressCachePromise();
3092
3092
  this.getLbsAddressCachePromise();
3093
3093
  }
3094
3094
  if (isJdApp) {
3095
3095
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
3096
3096
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
3097
3097
  this.getJdAppBaseInfo();
3098
3098
  this.getElderModePromise();
3099
3099
  this.getJDAppearanceStatePromise();
3100
3100
  this.createJdAndroidRquestEventForTouchStart();
3101
3101
  }
3102
3102
  this.getWifiVideoAutoPlayAsync();
3103
3103
  this.getMPaasConfigAsync();
3104
3104
  this.getNetWorkType();
3105
3105
  }
3106
3106
 
3107
3107
  getElderModePromise() {
3108
3108
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
3109
3109
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
3110
3110
  } else {
3111
3111
  if (isJdAndAndroidDevice) {
3112
3112
  this.info.sysInfo.jdAppModeType = '0';
3113
3113
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
3114
3114
  } else {
3115
3115
  return Promise.race([
3116
3116
  this.taskTimeoutPromise(() => {
3117
3117
  this.info.sysInfo.jdAppModeType = '0';
3118
3118
  return this.info.sysInfo.jdAppModeType;
3119
3119
  }),
3120
3120
  new Promise((resolve) => {
3121
3121
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
3122
3122
  if (!window[getCallBackName]) {
3123
3123
  window[getCallBackName] = (res) => {
3124
3124
  try {
3125
3125
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3126
3126
  const { status, data, msg } = getResJson;
3127
3127
  console.log(`获取松果app展示模式成功,返回结果${data}`);
3128
3128
  if (status === '0') {
3129
3129
  this.info.sysInfo.jdAppModeType = data;
3130
3130
  resolve(data);
3131
3131
  } else {
3132
3132
  resolve('0');
3133
3133
  }
3134
3134
  } catch (e) {
3135
3135
  resolve('0');
3136
3136
  }
3137
3137
  window[getCallBackName] = null;
3138
3138
  };
3139
3139
  }
3140
3140
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
3141
3141
  method: 'callSyncRouterModuleWithParams',
3142
3142
  params: JSON.stringify({
3143
3143
  routerURL: 'router://JDBModeModule/getCurrentMode',
3144
3144
  routerParam: {},
3145
3145
  callBackName: `window.${getCallBackName}`,
3146
3146
  callBackId: `${getCallBackName}Ios`,
3147
3147
  }),
3148
3148
  });
3149
3149
  }),
3150
3150
  ]);
3151
3151
  }
3152
3152
  }
3153
3153
  }
3154
3154
  getAPPUseStraightCorner() {
3155
3155
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
3156
3156
  const params = {
3157
3157
  routerURL,
3158
3158
  routerParam: {},
3159
3159
  jdRouter: '1',
3160
3160
  };
3161
3161
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
3162
3162
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
3163
3163
  } else {
3164
3164
  return this.jmfeReayPromise()
3165
3165
  .then(() => {
3166
3166
  if (isJdAndHarmonyDevice || !isJdApp) {
3167
3167
  console.log('not APP or is Harmony');
3168
3168
  return Promise.resolve(false);
3169
3169
  }
3170
3170
  console.log('jmfe setShareInfo', params);
3171
3171
  return Promise.race([
3172
3172
  window.jmfe.callRouter(params),
3173
3173
  this.taskTimeoutPromise(() => {
3174
3174
  return false;
3175
3175
  }),
3176
3176
  ]).then(({ status, data }) => {
3177
3177
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
3178
3178
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
3179
3179
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
3180
3180
  return Promise.resolve(status === '0' && Number(data) === 1);
3181
3181
  });
3182
3182
  })
3183
3183
  .catch((e) => {
3184
3184
  console.log('jmfe error', e);
3185
3185
  return Promise.resolve(false);
3186
3186
  });
3187
3187
  }
3188
3188
  }
3189
3189
 
3190
3190
  getJDAppearanceStatePromise() {
3191
3191
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
3192
3192
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
3193
3193
  } else {
3194
3194
  return Promise.race([
3195
3195
  this.taskTimeoutPromise(() => {
3196
3196
  this.info.sysInfo.jdAppearanceState = '0';
3197
3197
  return this.info.sysInfo.jdAppearanceState;
3198
3198
  }),
3199
3199
  new Promise((resolve) => {
3200
3200
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
3201
3201
  if (!window[getCallBackName]) {
3202
3202
  window[getCallBackName] = (res) => {
3203
3203
  try {
3204
3204
  console.log('getJDAppearanceStatePromise', res);
3205
3205
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3206
3206
  const { status, data, msg } = getResJson;
3207
3207
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
3208
3208
  if (status === '0') {
3209
3209
  this.info.sysInfo.jdAppearanceState = data;
3210
3210
  resolve(data);
3211
3211
  } else {
3212
3212
  resolve('0');
3213
3213
  }
3214
3214
  } catch (e) {
3215
3215
  resolve('0');
3216
3216
  }
3217
3217
  window[getCallBackName] = null;
3218
3218
  };
3219
3219
  }
3220
3220
  if (isAndroidDevice) {
3221
3221
  const jsonString = JSON.stringify({
3222
3222
  callBackName: `window.${getCallBackName}`,
3223
3223
  });
3224
3224
  console.log('window.JDAppearance', window?.JDAppearance);
3225
3225
  window?.JDAppearance &&
3226
3226
  window?.JDAppearance?.getUiState &&
3227
3227
  window.JDAppearance.getUiState(jsonString);
3228
3228
  } else {
3229
3229
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
3230
3230
  method: 'callSyncRouterModuleWithParams',
3231
3231
  params: JSON.stringify({
3232
3232
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
3233
3233
  routerParam: {},
3234
3234
  callBackName: `window.${getCallBackName}`,
3235
3235
  callBackId: `${getCallBackName}Ios`,
3236
3236
  }),
3237
3237
  });
3238
3238
  }
3239
3239
  }),
3240
3240
  ]);
3241
3241
  }
3242
3242
  }
3243
3243
 
3244
3244
  createJdAndroidRquestEventForTouchStart() {
3245
3245
  if (isJdAndAndroidDevice && window?.JdAndroid) {
3246
3246
  const rootEleNode = document.querySelector('body');
3247
3247
  if (rootEleNode) {
3248
3248
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
3249
3249
  }
3250
3250
  }
3251
3251
  }
3252
3252
  jdAndroidAddEventListenerTouchStart(e) {
3253
3253
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
3254
3254
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
3255
3255
  const hasCustomEle = e
3256
3256
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
3257
3257
  : false;
3258
3258
  if (!hasCustomEle) {
3259
3259
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
3260
3260
  console.log(
3261
3261
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
3262
3262
  );
3263
3263
  }
3264
3264
  }
3265
3265
  }
3266
3266
  removeJdAndroidRquestEventForTouchStart() {
3267
3267
  if (isJdAndAndroidDevice && window.JdAndroid) {
3268
3268
  const rootEleNode = document.querySelector('body');
3269
3269
  if (rootEleNode) {
3270
3270
  rootEleNode.removeEventListener(
3271
3271
  'touchstart',
3272
3272
  this.jdAndroidAddEventListenerTouchStart,
3273
3273
  false,
3274
3274
  );
3275
3275
  }
3276
3276
  }
3277
3277
  }
3278
3278
 
3279
3279
  getNetWorkType() {
3280
3280
  if (isJdApp) {
3281
3281
  this.jmfeReayPromise().then(() => {
3282
3282
  window.jmfe
3283
3283
  .getNetworkStatus()
3284
3284
  .then(({ status, data }) => {
3285
3285
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
3286
3286
  if (status === '0') {
3287
3287
  this.info.sysInfo['netWorkType'] = data;
3288
3288
  } else {
3289
3289
  this._taroGetNetworkType();
3290
3290
  }
3291
3291
  })
3292
3292
  .catch((err) => {
3293
3293
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
3294
3294
  this._taroGetNetworkType();
3295
3295
  });
3296
3296
  });
3297
3297
  } else {
3298
3298
  this._taroGetNetworkType();
3299
3299
  }
3300
3300
  }
3301
3301
  _taroGetNetworkType() {
3302
3302
  Taro.getNetworkType().then((getRes) => {
3303
3303
  if (getRes && getRes.networkType) {
3304
3304
  this.info.sysInfo['netWorkType'] = getRes.networkType;
3305
3305
  console.log(
3306
3306
  '在app内通过taro对象获取网络状态完成,当前网络状态',
3307
3307
  this.info.sysInfo['netWorkType'],
3308
3308
  );
3309
3309
  }
3310
3310
  });
3311
3311
  }
3312
3312
 
3313
3313
  getJdAppBaseInfo() {
3314
3314
  const appKeyCacheToCookieMinuteTime =
3315
3315
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
3316
3316
  appUuidCacheToCookieMinuteTime =
3317
3317
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
3318
3318
  getAppKey = cookie.get(cacheAppKey),
3319
3319
  getAppUuidKey = cookie.get(cacheAppUuidKey);
3320
3320
  console.log(
3321
3321
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
3322
3322
  cacheAppKey,
3323
3323
  getAppKey,
3324
3324
  cacheAppUuidKey,
3325
3325
  getAppUuidKey,
3326
3326
  );
3327
3327
  if (
3328
3328
  appKeyCacheToCookieMinuteTime &&
3329
3329
  appUuidCacheToCookieMinuteTime &&
3330
3330
  getAppKey &&
3331
3331
  getAppUuidKey
3332
3332
  ) {
3333
3333
  const [uuid, eufv] = getAppUuidKey.split('@');
3334
3334
  const baseApiKeyParam = {
3335
3335
  uuid,
3336
3336
  };
3337
3337
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
3338
3338
  if (eufv === '1' && /-/.test(uuid)) {
3339
3339
  const [eu, fv] = uuid.split('-');
3340
3340
  baseApiKeyParam['eu'] = eu;
3341
3341
  baseApiKeyParam['fv'] = fv;
3342
3342
  }
3343
3343
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3344
3344
  this.jmfeReayPromise().then(() => {
3345
3345
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
3346
3346
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3347
3347
  });
3348
3348
  } else {
3349
3349
  const checkGetJdAppKeyState =
3350
3350
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
3351
3351
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
3352
3352
  this.jmfeReayPromise().then(() => {
3353
3353
  Promise.all([
3354
3354
  checkGetJdAppKeyState && window.jmfe?.callNative
3355
3355
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
3356
3356
  : Promise.resolve({
3357
3357
  status: '-1000',
3358
3358
  msg: '当前版本不支持获取松果app中的getAppKey',
3359
3359
  data: '-1000',
3360
3360
  }),
3361
3361
  window.jmfe.getDeviceInfo(),
3362
3362
  ]).then((resList) => {
3363
3363
  const [getAppKeyRes, deviceInfoRes] = resList;
3364
3364
  console.log(
3365
3365
  '在app内初始化通过jmfe获取getAppKey结果',
3366
3366
  getAppKeyRes,
3367
3367
  '通过jmfe获取getDeviceInfo获取结果',
3368
3368
  deviceInfoRes,
3369
3369
  );
3370
3370
  const baseApiKeyParam = {};
3371
3371
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
3372
3372
  const getJmfeAppKey = getAppKeyRes?.data;
3373
3373
  if (getJmfeAppKey && getJmfeAppKey !== '') {
3374
3374
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
3375
3375
  const getJdAppKeyCacheToCookieMinuteTime =
3376
3376
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
3377
3377
  if (getJdAppKeyCacheToCookieMinuteTime) {
3378
3378
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
3379
3379
  cookie.set(cacheAppKey, getJmfeAppKey, {
3380
3380
  path: '/',
3381
3381
  expires,
3382
3382
  });
3383
3383
  }
3384
3384
  }
3385
3385
  }
3386
3386
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
3387
3387
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
3388
3388
  if (uuid && uuid !== '') {
3389
3389
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
3390
3390
  baseApiKeyParam['uuid'] = uuid;
3391
3391
  if (eufv === '1' && /-/.test(uuid)) {
3392
3392
  const [eu, fv] = uuid.split('-');
3393
3393
  baseApiKeyParam['eu'] = eu;
3394
3394
  baseApiKeyParam['fv'] = fv;
3395
3395
  }
3396
3396
  const getAppUuidCacheToCookieMinuteTime =
3397
3397
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
3398
3398
  if (getAppUuidCacheToCookieMinuteTime) {
3399
3399
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
3400
3400
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
3401
3401
  path: '/',
3402
3402
  expires,
3403
3403
  });
3404
3404
  }
3405
3405
  }
3406
3406
  }
3407
3407
  console.log(
3408
3408
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
3409
3409
  baseApiKeyParam,
3410
3410
  );
3411
3411
  if (Object.keys(baseApiKeyParam).length > 0) {
3412
3412
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3413
3413
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3414
3414
  }
3415
3415
  });
3416
3416
  });
3417
3417
  }
3418
3418
  }
3419
3419
 
3420
3420
  getCacheAddressRouter() {
3421
3421
  if (isJdApp) {
3422
3422
  if (!isJdAndHarmonyDevice) {
3423
3423
  return Promise.race([
3424
3424
  new Promise((resolve) => {
3425
3425
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
3426
3426
  if (!window[getCallBackName]) {
3427
3427
  window[getCallBackName] = (res) => {
3428
3428
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
3429
3429
  try {
3430
3430
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3431
3431
  resolve(getResJson);
3432
3432
  } catch (e) {
3433
3433
  resolve({
3434
3434
  status: '-1002',
3435
3435
  msg: '地址信息解析json异常',
3436
3436
  res,
3437
3437
  });
3438
3438
  }
3439
3439
  window[getCallBackName] = null;
3440
3440
  };
3441
3441
  }
3442
3442
  const getRouterParam = {
3443
3443
  sceneId: 'basicShoppingProcess',
3444
3444
  };
3445
3445
  if (isAndroidDevice) {
3446
3446
  return callRouterAndroid({
3447
3447
  routerURL: 'router://JDAddressModule/getCacheAddress',
3448
3448
  routerParam: getRouterParam,
3449
3449
  callBackName: getCallBackName,
3450
3450
  isSync: true,
3451
3451
  });
3452
3452
  } else {
3453
3453
  return callRouterIOS({
3454
3454
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
3455
3455
  routerParam: getRouterParam,
3456
3456
  callBackName: getCallBackName,
3457
3457
  });
3458
3458
  }
3459
3459
  }),
3460
3460
  this.taskTimeoutPromise(() => {
3461
3461
  return {
3462
3462
  status: '-1000',
3463
3463
  msg: '原生router协议获取地址信息超时',
3464
3464
  };
3465
3465
  }, 3000),
3466
3466
  ]);
3467
3467
  } else {
3468
3468
  return Promise.race([
3469
3469
  new Promise((resolve) => {
3470
3470
  this.jmfeReayPromise()
3471
3471
  .then(() => {
3472
3472
  const plugin = 'JDHybridRouterPlugin';
3473
3473
  const action = 'callSyncRouterModuleWithParams';
3474
3474
  const params = {
3475
3475
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
3476
3476
  routerParam: '',
3477
3477
  };
3478
3478
  const sync = '1';
3479
3479
  try {
3480
3480
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
3481
3481
  resolve(res);
3482
3482
  });
3483
3483
  } catch (error) {
3484
3484
  resolve({
3485
3485
  status: '-1001',
3486
3486
  msg: '判断jmfe不存在,获取经纬度信息异常',
3487
3487
  });
3488
3488
  }
3489
3489
  })
3490
3490
  .catch(() => {
3491
3491
  resolve({
3492
3492
  status: '-1002',
3493
3493
  msg: '鸿蒙系统调用jmfe异常,获取失败',
3494
3494
  });
3495
3495
  });
3496
3496
  }),
3497
3497
  this.taskTimeoutPromise(() => {
3498
3498
  return {
3499
3499
  status: '-1000',
3500
3500
  msg: '原生router协议获取地址信息超时',
3501
3501
  };
3502
3502
  }, 3000),
3503
3503
  ]);
3504
3504
  }
3505
3505
  } else if (isH5AndJingGouMini) {
3506
3506
  const { areaId, addressName } = this.getJingGouMiniInh5Address();
3507
3507
  if (areaId && areaId !== '' && addressName && addressName !== '') {
3508
3508
  return Promise.resolve({
3509
3509
  status: '0',
3510
3510
  data: {
3511
3511
  areaId,
3512
3512
  fullAddress: addressName,
3513
3513
  },
3514
3514
  });
3515
3515
  } else {
3516
3516
  return Promise.resolve({
3517
3517
  status: '-1002',
3518
3518
  msg: '京购内嵌h5h5暂无业务需要,未实现,获取失败',
3519
3519
  });
3520
3520
  }
3521
3521
  } else {
3522
3522
  return Promise.resolve({
3523
3523
  status: '-1002',
3524
3524
  msg: '普通h5暂无业务需要,未实现,获取失败',
3525
3525
  });
3526
3526
  }
3527
3527
  }
3528
3528
 
3529
3529
  getJingGouMiniInh5Address() {
3530
3530
  let getRes: any = {
3531
3531
  areaId: '',
3532
3532
  addressName: '',
3533
3533
  };
3534
3534
  try {
3535
3535
  const getUrlHast = decodeURIComponent(window.location.hash || '');
3536
3536
  const sensMatch = getUrlHast ? getUrlHast.match(/sens=({.*?})/) : null;
3537
3537
  if (sensMatch && sensMatch[1]) {
3538
3538
  const sensData = JSON.parse(sensMatch[1]);
3539
3539
  const getWqAddr = sensData?.wq_addr || '';
3540
3540
  if (getWqAddr && /\|/.test(getWqAddr)) {
3541
3541
  const addressList = getWqAddr.split(/\|/);
3542
3542
  const [addressId, areaId, areaName, addressName, coordinate] = addressList;
3543
3543
  getRes = {
3544
3544
  addressId,
3545
3545
  areaId,
3546
3546
  areaName,
3547
3547
  addressName,
3548
3548
  coordinate,
3549
3549
  };
3550
3550
  }
3551
3551
  }
3552
3552
  } catch (e) {
3553
3553
  console.log('获取hash转换异常', e);
3554
3554
  }
3555
3555
  return getRes;
3556
3556
  }
3557
3557
 
3558
3558
  getAddressCachePromise() {
3559
3559
  return new Promise((resolve) => {
3560
3560
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
3561
3561
  resolve({
3562
3562
  lat: this.info.sysInfo.lat,
3563
3563
  lng: this.info.sysInfo.lng,
3564
3564
  area: this?.info?.sysInfo?.area,
3565
3565
  fullAddress: this?.info?.pageInfo?.fullAddress,
3566
3566
  });
3567
3567
  } else {
3568
3568
  this.getCacheAddressRouter()
3569
3569
  .then((res) => {
3570
3570
  const { status, data } = res;
3571
3571
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
3572
3572
  if (status === '0' && data) {
3573
3573
  const {
3574
3574
  lat,
3575
3575
  latitude,
3576
3576
  lng,
3577
3577
  longitude,
3578
3578
  provinceId,
3579
3579
  cityId,
3580
3580
  countyId,
3581
3581
  townId,
3582
3582
  fullAddress,
3583
3583
  areaId,
3584
3584
  } = data || {};
3585
3585
  const getAreaIdsEnable = areaId && areaId !== '';
3586
3586
  const getEncodeFullAddress = fullAddress ? encodeURIComponent(fullAddress) : '';
3587
3587
  let area = getAreaIdsEnable ? areaId : '';
3588
3588
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
3589
3589
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
3590
3590
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
3591
3591
  if ((getProvinceIdNum && getProvinceIdNum > 0) || getAreaIdsEnable) {
3592
3592
  area = getAreaIdsEnable
3593
3593
  ? areaId
3594
3594
  : `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
3595
3595
  this.info.pageInfo['address'] = area;
3596
3596
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
3597
3597
  this.info.sysInfo['area'] = area;
3598
3598
  const getUpdateData = {
3599
3599
  area: this.info.pageInfo.address,
3600
3600
  };
3601
3601
  if (fullAddress && fullAddress.length > 0) {
3602
3602
  getUpdateData['fullAddress'] = getEncodeFullAddress;
3603
3603
  this.info.pageInfo['fullAddress'] = getEncodeFullAddress;
3604
3604
  }
3605
3605
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, getUpdateData);
3606
3606
  }
3607
3607
  resolve({
3608
3608
  lat: this.info.sysInfo['lat'],
3609
3609
  lng: this.info.sysInfo['lng'],
3610
3610
  fullAddress: getEncodeFullAddress,
3611
3611
  area: area,
3612
3612
  });
3613
3613
  } else {
3614
3614
  if (typeof res === 'object') {
3615
3615
  draBusinessCustomReport({
3616
3616
  eventName: 'business',
3617
3617
  errorName: 'jdapp_getCacheAddress_info_err',
3618
3618
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
3619
3619
  extraData: JSON.stringify({
3620
3620
  isJdApp,
3621
3621
  jdAppVersion: jdAppVersionStr,
3622
3622
  ...res,
3623
3623
  }),
3624
3624
  });
3625
3625
  }
3626
3626
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
3627
3627
  }
3628
3628
  })
3629
3629
  .catch((e) => {
3630
3630
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
3631
3631
  draBusinessCustomReport({
3632
3632
  eventName: 'business',
3633
3633
  errorName: 'jdapp_getCacheAddress_info_catch_err',
3634
3634
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
3635
3635
  extraData: JSON.stringify({
3636
3636
  isJdApp,
3637
3637
  jdAppVersion: jdAppVersionStr,
3638
3638
  }),
3639
3639
  });
3640
3640
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
3641
3641
  });
3642
3642
  }
3643
3643
  });
3644
3644
  }
3645
3645
 
3646
3646
  getLbsCacheAddressRouter() {
3647
3647
  if (isJdApp) {
3648
3648
  if (!isJdAndHarmonyDevice) {
3649
3649
  return Promise.race([
3650
3650
  new Promise((resolve) => {
3651
3651
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
3652
3652
  if (!window[getCallBackName]) {
3653
3653
  window[getCallBackName] = (res) => {
3654
3654
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
3655
3655
  try {
3656
3656
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3657
3657
  resolve(getResJson);
3658
3658
  } catch (e) {
3659
3659
  resolve({
3660
3660
  status: '-1002',
3661
3661
  msg: '地址信息解析json异常',
3662
3662
  res,
3663
3663
  });
3664
3664
  }
3665
3665
  window[getCallBackName] = null;
3666
3666
  };
3667
3667
  }
3668
3668
  const getRouterParam = {
3669
3669
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
3670
3670
  sceneId: 'basicShoppingProcess',
3671
3671
  };
3672
3672
  if (isAndroidDevice) {
3673
3673
  return callRouterAndroid({
3674
3674
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
3675
3675
  routerParam: getRouterParam,
3676
3676
  callBackName: getCallBackName,
3677
3677
  isSync: true,
3678
3678
  hasJdRouter: false,
3679
3679
  });
3680
3680
  } else {
3681
3681
  return callRouterIOS({
3682
3682
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
3683
3683
  routerParam: getRouterParam,
3684
3684
  callBackName: getCallBackName,
3685
3685
  isSync: true,
3686
3686
  });
3687
3687
  }
3688
3688
  }),
3689
3689
  this.taskTimeoutPromise(() => {
3690
3690
  return {
3691
3691
  status: '-1000',
3692
3692
  msg: '原生router协议获取lbs地址信息3s超时',
3693
3693
  };
3694
3694
  }, 3000),
3695
3695
  ]);
3696
3696
  } else {
3697
3697
  return Promise.resolve({
3698
3698
  status: '-1001',
3699
3699
  msg: '鸿蒙系统调用未实现,获取失败',
3700
3700
  });
3701
3701
  }
3702
3702
  } else if (isH5AndJingGouMini) {
3703
3703
  return this.getLocationForGpsPromise();
3704
3704
  } else {
3705
3705
  return Promise.resolve({
3706
3706
  status: '-1002',
3707
3707
  msg: '普通h5暂无业务需要,未实现,获取失败',
3708
3708
  });
3709
3709
  }
3710
3710
  }
3711
3711
  getLocationForGpsPromise() {
3712
3712
  return new Promise((resolve) => {
3713
3713
  let hasGetLocationForGps = true;
3714
3714
  if (urlCookie && urlCookie['loc']) {
3715
3715
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
3716
3716
  urlCookie['loc'].split('_');
3717
3717
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3718
3718
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3719
3719
  hasGetLocationForGps = false;
3720
3720
  resolve({
3721
3721
  status: '0',
3722
3722
  data: {
3723
3723
  provinceid,
3724
3724
  cityid,
3725
3725
  districtid,
3726
3726
  townid,
3727
3727
  origin: 'wxapp',
3728
3728
  },
3729
3729
  });
3730
3730
  }
3731
3731
  }
3732
3732
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
3733
3733
  window.navigator.geolocation.getCurrentPosition(
3734
3734
  (position) => {
3735
3735
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
3736
3736
  if (position?.coords) {
3737
3737
  resolve({
3738
3738
  status: '0',
3739
3739
  data: {
3740
3740
  srclat: position.coords?.latitude,
3741
3741
  srclng: position.coords.longitude,
3742
3742
  origin: 'h5',
3743
3743
  },
3744
3744
  });
3745
3745
  } else {
3746
3746
  resolve({
3747
3747
  status: '-1001',
3748
3748
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
3749
3749
  position,
3750
3750
  });
3751
3751
  }
3752
3752
  },
3753
3753
  (error) => {
3754
3754
  resolve({
3755
3755
  status: '-1001',
3756
3756
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
3757
3757
  error,
3758
3758
  });
3759
3759
  },
3760
3760
  {
3761
3761
  enableHighAccuracy: false,
3762
3762
  timeout: 3 * 1000,
3763
3763
  maximumAge: 10 * 60 * 1000,
3764
3764
  },
3765
3765
  );
3766
3766
  } else {
3767
3767
  resolve({
3768
3768
  status: '-1001',
3769
3769
  msg: '您的浏览器不支持地理定位',
3770
3770
  });
3771
3771
  }
3772
3772
  });
3773
3773
  }
3774
3774
 
3775
3775
  createLbsCacheAddress(realTimeArea) {
3776
3776
  const getLbsAddressCacheMinuteTime = Number(
3777
3777
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
3778
3778
  );
3779
3779
  console.log(
3780
3780
  '获取lbs缓存到cookie的时间,分钟',
3781
3781
  getLbsAddressCacheMinuteTime,
3782
3782
  'lbsAddressCacheToCookieMinuteTime',
3783
3783
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
3784
3784
  );
3785
3785
  if (getLbsAddressCacheMinuteTime > 0) {
3786
3786
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
3787
3787
  realTimeArea &&
3788
3788
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
3789
3789
  path: '/',
3790
3790
  expires,
3791
3791
  });
3792
3792
  }
3793
3793
  }
3794
3794
 
3795
3795
  getLbsAddressCachePromise() {
3796
3796
  if (!this.lbsAddressCachePromise) {
3797
3797
  this.lbsAddressCachePromise = new Promise((resolve) => {
3798
3798
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
3799
3799
  ? cookie.get(cacheH5LbsAddressKey)
3800
3800
  : '';
3801
3801
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
3802
3802
  if (getUserLbsAddress && getUserLbsAddress !== '') {
3803
3803
  resolve({
3804
3804
  ok: true,
3805
3805
  realTimeArea: getUserLbsAddress,
3806
3806
  });
3807
3807
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
3808
3808
  console.info(
3809
3809
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
3810
3810
  getCookieForLbsAddress,
3811
3811
  );
3812
3812
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
3813
3813
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
3814
3814
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3815
3815
  realTimeArea: getCookieForLbsAddress,
3816
3816
  });
3817
3817
  resolve({
3818
3818
  ok: true,
3819
3819
  realTimeArea: getCookieForLbsAddress,
3820
3820
  });
3821
3821
  } else {
3822
3822
  this.getLbsCacheAddressRouter()
3823
3823
  .then((res) => {
3824
3824
  const { status, data } = res;
3825
3825
  console.log(
3826
3826
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
3827
3827
  status,
3828
3828
  data,
3829
3829
  res,
3830
3830
  );
3831
3831
  if (status === '0' && data) {
3832
3832
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
3833
3833
  data || {};
3834
3834
  let realTimeArea = '';
3835
3835
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
3836
3836
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
3837
3837
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3838
3838
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3839
3839
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
3840
3840
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
3841
3841
  this.info.sysInfo['realTimeArea'] = realTimeArea;
3842
3842
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3843
3843
  realTimeArea: this.info.pageInfo.userLbsAddress,
3844
3844
  });
3845
3845
  this.createLbsCacheAddress(realTimeArea);
3846
3846
  } else {
3847
3847
  !origin && (this.lbsAddressCachePromise = null);
3848
3848
  }
3849
3849
  const getValidRealTimeArea = realTimeArea !== '';
3850
3850
  resolve({
3851
3851
  lat: this.info.sysInfo['srclat'],
3852
3852
  lng: this.info.sysInfo['srclng'],
3853
3853
  realTimeArea: realTimeArea,
3854
3854
  ok: getValidRealTimeArea,
3855
3855
  msg: getValidRealTimeArea
3856
3856
  ? '成功'
3857
3857
  : origin
3858
3858
  ? origin
3859
3859
  : '根据router底层获取lbs地址信息异常,详情见data',
3860
3860
  data: getValidRealTimeArea ? null : res,
3861
3861
  });
3862
3862
  if (!getValidRealTimeArea && !origin) {
3863
3863
  draBusinessCustomReport({
3864
3864
  eventName: 'business',
3865
3865
  errorName: 'h5_getLbsCacheAddress_info_err',
3866
3866
  errorMessage:
3867
3867
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
3868
3868
  extraData: JSON.stringify({
3869
3869
  isJdApp,
3870
3870
  jdAppVersion: jdAppVersionStr,
3871
3871
  }),
3872
3872
  });
3873
3873
  }
3874
3874
  } else {
3875
3875
  typeof res === 'object' &&
3876
3876
  draBusinessCustomReport({
3877
3877
  eventName: 'business',
3878
3878
  errorName: 'h5_getLbsCacheAddress_info_err',
3879
3879
  errorMessage:
3880
3880
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
3881
3881
  extraData: JSON.stringify({
3882
3882
  isJdApp,
3883
3883
  jdAppVersion: jdAppVersionStr,
3884
3884
  ...res,
3885
3885
  }),
3886
3886
  });
3887
3887
  this.lbsAddressCachePromise = null;
3888
3888
  resolve({ realTimeArea: '', ok: false });
3889
3889
  }
3890
3890
  })
3891
3891
  .catch((e) => {
3892
3892
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
3893
3893
  this.lbsAddressCachePromise = null;
3894
3894
  draBusinessCustomReport({
3895
3895
  eventName: 'business',
3896
3896
  errorName: 'h5_getLbsCacheAddress_info_err',
3897
3897
  errorMessage:
3898
3898
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
3899
3899
  extraData: JSON.stringify({
3900
3900
  isJdApp,
3901
3901
  jdAppVersion: jdAppVersionStr,
3902
3902
  }),
3903
3903
  });
3904
3904
  resolve({ realTimeArea: '', ok: false });
3905
3905
  });
3906
3906
  }
3907
3907
  });
3908
3908
  }
3909
3909
  return this.lbsAddressCachePromise;
3910
3910
  }
3911
3911
 
3912
3912
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
3913
3913
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
3914
3914
  if (!isJdApp) {
3915
3915
  return;
3916
3916
  }
3917
3917
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
3918
3918
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
3919
3919
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
3920
3920
  'hybridHttpSwitch',
3921
3921
  isBeforePageReady,
3922
3922
  );
3923
3923
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
3924
3924
  'jshopIsVipShop',
3925
3925
  isBeforePageReady,
3926
3926
  );
3927
3927
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
3928
3928
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
3929
3929
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
3930
3930
  'isFollowAppVideoPlayStatus',
3931
3931
  isBeforePageReady,
3932
3932
  );
3933
3933
  console.log(
3934
3934
  'isBeforePageReady:',
3935
3935
  isBeforePageReady,
3936
3936
  'isFollowAppVideoPlayStatus:',
3937
3937
  isFollowAppVideoPlayStatus,
3938
3938
  );
3939
3939
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
3940
3940
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
3941
3941
  }
3942
3942
  }
3943
3943
 
3944
3944
  async getWifiVideoAutoPlayAsync() {
3945
3945
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
3946
3946
  if (!isJdApp) {
3947
3947
  return;
3948
3948
  }
3949
3949
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
3950
3950
  return 0;
3951
3951
  });
3952
3952
  if (Number(videoPlayStatus) === 1) {
3953
3953
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
3954
3954
  }
3955
3955
  }
3956
3956
 
3957
3957
  async getMPaasConfigAsync() {
3958
3958
  this.info.sysInfo.dynamicConfig = {};
3959
3959
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
3960
3960
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
3961
3961
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
3962
3962
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
3963
3963
  return this.updateMPaasConfigAsync(true);
3964
3964
  }
3965
3965
 
3966
3966
  getDynamicConfig(key: string) {
3967
3967
  return this.info.sysInfo?.dynamicConfig?.[key];
3968
3968
  }
3969
3969
  async updateMPaasConfig() {
3970
3970
  console.log('updateMPaasConfig');
3971
3971
  if (
3972
3972
  isIosDevice &&
3973
3973
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
3974
3974
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
3975
3975
  ) {
3976
3976
  try {
3977
3977
  await this.updateMPaasConfigAsync(false);
3978
3978
  } catch (e) {
3979
3979
  console.log('updateMPaasConfigAsync:', e);
3980
3980
  }
3981
3981
  }
3982
3982
  }
3983
3983
 
3984
3984
  toLogin(options) {
3985
3985
  if (isAscfApp) {
3986
3986
  return this.toAscfAppLogin(options);
3987
3987
  }
3988
3988
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
3989
3989
  ? this.toWxAppLogin(options)
3990
3990
  : this.toWebLogin(options);
3991
3991
  }
3992
3992
 
3993
3993
  doLogin(options) {
3994
3994
  return this.toLogin(options);
3995
3995
  }
3996
3996
 
3997
3997
  doLoginForJdPin(options = {}) {
3998
3998
  return this.doLogin({
3999
3999
  loginColor: {
4000
4000
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
4001
4001
  dpin: 0,
4002
4002
  },
4003
4003
  ...options,
4004
4004
  });
4005
4005
  }
4006
4006
 
4007
4007
  toWebLogin(options) {
4008
4008
  let params: {
4009
4009
  returnurl: string;
4010
4010
  } = {
4011
4011
  returnurl: '',
4012
4012
  };
4013
4013
  const checkToPcLogin = options ? options?.isPc : isPc;
4014
4014
  const loginUrl = checkToPcLogin
4015
4015
  ? `//passport.jd.com/new/login.aspx`
4016
4016
  : `${domain.mobileLogin}/user/login.action`;
4017
4017
  const defaultParams = {
4018
4018
  appid: '100',
4019
4019
  returnurl: window.location.href,
4020
4020
  };
4021
4021
  if (isString(options)) {
4022
4022
  params = Object.assign({}, defaultParams, {
4023
4023
  returnurl: options,
4024
4024
  });
4025
4025
  } else if (isObject(options)) {
4026
4026
  const { loginColor, ...otherOptions } = options;
4027
4027
  params = Object.assign({}, defaultParams, otherOptions);
4028
4028
  } else {
4029
4029
  params = defaultParams;
4030
4030
  }
4031
4031
  params.returnurl = encodeURIComponent(params.returnurl);
4032
4032
  let getFullUrl = loginUrl + '?' + serialize(params);
4033
4033
  if (checkToPcLogin) {
4034
4034
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
4035
4035
  }
4036
4036
  return Promise.resolve({
4037
4037
  h5ToUrl: true,
4038
4038
  url: getFullUrl,
4039
4039
  }).then(() => {
4040
4040
  window.location.href = getFullUrl;
4041
4041
  });
4042
4042
  }
4043
4043
 
4044
4044
  toAscfAppLogin(options = {}) {
4045
4045
  console.log('华为元服务中h5登录跳转', options);
4046
4046
  return Promise.resolve(true).then(() => {
4047
4047
  const returnPage = encodeURIComponent(window.location.href);
4048
4048
  if (has && has.ascfweb) {
4049
4049
  has.ascfweb.redirectTo({
4050
4050
  url: `/pages/login/index/index?isH5=1&returnPage=${returnPage}&pageType=h5&source=shopx`,
4051
4051
  });
4052
4052
  }
4053
4053
  });
4054
4054
  }
4055
4055
 
4056
4056
  toWxAppLogin(options = {}) {
4057
4057
  console.log('微信京购小程序中h5登录跳转', options);
4058
4058
  return Promise.resolve(true).then(() => {
4059
4059
  const { loginColor } = Object.assign(
4060
4060
  {},
4061
4061
  {
4062
4062
  loginColor: {
4063
4063
  biz: WXAPP_BIZ_KEY,
4064
4064
  dpin: 1,
4065
4065
  },
4066
4066
  },
4067
4067
  options,
4068
4068
  );
4069
4069
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
4070
4070
  loginColor.biz
4071
4071
  }&url=${encodeURIComponent(window.location.href)}`;
4072
4072
  });
4073
4073
  }
4074
4074
 
4075
4075
  getLoginCookie() {
4076
4076
  return Promise.resolve({
4077
4077
  pin: cookie.get('pin') || '',
4078
4078
  });
4079
4079
  }
4080
4080
 
4081
4081
  clearLoginCookie() {
4082
4082
  cookie.remove('pin');
4083
4083
  }
4084
4084
 
4085
4085
  checkStatusAndLogin(options = {}) {
4086
4086
  if (!this.checkStatusAndLoginPromise) {
4087
4087
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
4088
4088
  try {
4089
4089
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
4090
4090
  if (getLoginState) {
4091
4091
  resolve(true);
4092
4092
  } else {
4093
4093
  this.toLogin(options);
4094
4094
  reject(false);
4095
4095
  }
4096
4096
  } catch (e) {
4097
4097
  this.toLogin(options);
4098
4098
  reject(false);
4099
4099
  }
4100
4100
  });
4101
4101
  return this.checkStatusAndLoginPromise;
4102
4102
  } else {
4103
4103
  return this.checkStatusAndLoginPromise
4104
4104
  .then(() => {
4105
4105
  return Promise.resolve(true);
4106
4106
  })
4107
4107
  .catch(() => {
4108
4108
  this.toLogin(options);
4109
4109
  return Promise.reject(true);
4110
4110
  });
4111
4111
  }
4112
4112
  }
4113
4113
 
4114
4114
  checkJdStatusAndLogin(
4115
4115
  options = {
4116
4116
  loginColor: {
4117
4117
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
4118
4118
  dpin: 0,
4119
4119
  },
4120
4120
  },
4121
4121
  ) {
4122
4122
  return this.checkStatusAndLogin(options);
4123
4123
  }
4124
4124
 
4125
4125
  doCheckLoginStateAndForApiCheck(options) {
4126
4126
  if (this.info.loginState) {
4127
4127
  return Promise.resolve(true);
4128
4128
  } else {
4129
4129
  return new Promise((resolve, reject) => {
4130
4130
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
4131
4131
  const getWqAuthToken = cookie.get('wq_auth_token');
4132
4132
  const getWqSkey = cookie.get('wq_skey');
4133
4133
  const getWqUin = cookie.get('wq_uin');
4134
4134
  const isLoginState =
4135
4135
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
4136
4136
  if (isLoginState) {
4137
4137
  this.info.loginState = true;
4138
4138
  resolve(true);
4139
4139
  } else {
4140
4140
  reject(false);
4141
4141
  }
4142
4142
  } else {
4143
4143
  Taro.request({
4144
4144
  url: api.isLogin,
4145
4145
  jsonp: true,
4146
4146
  timeout: 3000,
4147
4147
  success: (res) => {
4148
4148
  const { statusCode, data } = res;
4149
4149
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
4150
4150
  this.info.loginState = true;
4151
4151
  resolve(true);
4152
4152
  } else {
4153
4153
  reject(false);
4154
4154
  }
4155
4155
  },
4156
4156
  fail: (err) => {
4157
4157
  console.log('登录检查异常', err);
4158
4158
  reject(false);
4159
4159
  },
4160
4160
  });
4161
4161
  }
4162
4162
  });
4163
4163
  }
4164
4164
  }
4165
4165
 
4166
4166
  checkLoginStatus(options) {
4167
4167
  return new Promise(async (resolve, reject) => {
4168
4168
  try {
4169
4169
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
4170
4170
  if (getLoginState) {
4171
4171
  const { pin } = await this.getLoginCookie();
4172
4172
  this.info.userInfo = {
4173
4173
  pin,
4174
4174
  encodePin: encodeURIComponent(pin),
4175
4175
  ptkey: '',
4176
4176
  };
4177
4177
  resolve(true);
4178
4178
  } else {
4179
4179
  reject(false);
4180
4180
  }
4181
4181
  } catch (e) {
4182
4182
  reject(false);
4183
4183
  }
4184
4184
  });
4185
4185
  }
4186
4186
 
4187
4187
  updatePageAndLogInfo(updateQuery = {}) {
4188
4188
  const createUpdateQueryInfo: {
4189
4189
  query: {
4190
4190
  shopId?: string | number;
4191
4191
  venderId?: string | number;
4192
4192
  };
4193
4193
  updateShopInfoState: boolean;
4194
4194
  } = Object.assign(
4195
4195
  {},
4196
4196
  {
4197
4197
  query: {},
4198
4198
  updateShopInfoState: false,
4199
4199
  },
4200
4200
  updateQuery,
4201
4201
  );
4202
4202
  console.log(
4203
4203
  '获取当前下发的店铺查询参数',
4204
4204
  updateQuery,
4205
4205
  '获取之前保存的shopInfo店铺查询参数',
4206
4206
  this.info?.shopInfo,
4207
4207
  );
4208
4208
  const { query, updateShopInfoState } = createUpdateQueryInfo;
4209
4209
  const { shopId, venderId, un_area } = query;
4210
4210
  if (updateShopInfoState) {
4211
4211
  this.info.queryInfo = {
4212
4212
  ...this.info.queryInfo,
4213
4213
  ...query,
4214
4214
  };
4215
4215
  if (shopId && venderId) {
4216
4216
  this.info.shopInfo = {
4217
4217
  shopId: `${shopId}`,
4218
4218
  venderId: `${venderId}`,
4219
4219
  };
4220
4220
  }
4221
4221
  } else {
4222
4222
  this.info.queryInfo = {
4223
4223
  ...query,
4224
4224
  };
4225
4225
  if (
4226
4226
  this.info.shopInfo?.shopId &&
4227
4227
  this.info.shopInfo?.venderId &&
4228
4228
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
4229
4229
  ) {
4230
4230
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
4231
4231
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
4232
4232
  console.log(
4233
4233
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
4234
4234
  this.info.queryInfo,
4235
4235
  );
4236
4236
  }
4237
4237
  }
4238
4238
  this.info.queryInfo['shopId'] &&
4239
4239
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
4240
4240
  this.info.queryInfo['venderId'] &&
4241
4241
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
4242
4242
  console.log(
4243
4243
  'h5==获取店铺下发查询参数\n',
4244
4244
  query,
4245
4245
  '\n获取店铺最后查询参数\n',
4246
4246
  this.info.queryInfo,
4247
4247
  '\n是否为更新店铺状态\n',
4248
4248
  updateShopInfoState,
4249
4249
  );
4250
4250
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
4251
4251
  if (changeArea) {
4252
4252
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
4253
4253
  this.info.pageInfo.address = getBottomAreaStr;
4254
4254
  this.info.pageInfo.un_area = getBottomAreaStr;
4255
4255
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
4256
4256
  }
4257
4257
  }
4258
4258
 
4259
4259
  dealLoadSdkList() {
4260
4260
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
4261
4261
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
4262
4262
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
4263
4263
  let mergeLoadJsList = globalLoadJsList;
4264
4264
  try {
4265
4265
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
4266
4266
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
4267
4267
  getFindIndex !== -1
4268
4268
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
4269
4269
  : accArr.push(current);
4270
4270
  return accArr;
4271
4271
  }, []);
4272
4272
  } catch (e) {
4273
4273
  console.log('LoadJsList合并错误', e);
4274
4274
  }
4275
4275
  console.log(
4276
4276
  'globalLoadJsList',
4277
4277
  globalLoadJsList,
4278
4278
  'businessLoadJsList',
4279
4279
  businessLoadJsList,
4280
4280
  '两个加载jsList集合合并完成',
4281
4281
  mergeLoadJsList,
4282
4282
  );
4283
4283
  this.loadJsSdkList = mergeLoadJsList;
4284
4284
  return this.loadJsSdkList;
4285
4285
  }
4286
4286
 
4287
4287
  renderNextTickLoadSdk(delayTime = 1000) {
4288
4288
  Taro.nextTick(() => {
4289
4289
  console.log(
4290
4290
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
4291
4291
  );
4292
4292
  setTimeout(() => {
4293
4293
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
4294
4294
  }, delayTime);
4295
4295
  });
4296
4296
  }
4297
4297
 
4298
4298
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
4299
4299
  const getLoadJsList =
4300
4300
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
4301
4301
  const getLoadFilterList = getLoadJsList.filter((item) => {
4302
4302
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
4303
4303
  item.initLoadType = undefined;
4304
4304
  }
4305
4305
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
4306
4306
  let getLoastLoadEventState = true;
4307
4307
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
4308
4308
  getLoastLoadEventState = isJdApp;
4309
4309
  }
4310
4310
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
4311
4311
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
4312
4312
  }
4313
4313
  const getInitTriggerType =
4314
4314
  isJdApp && item?.initJdAppTriggerType
4315
4315
  ? item?.initTriggerType
4316
4316
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
4317
4317
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
4318
4318
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
4319
4319
  });
4320
4320
  console.log(
4321
4321
  '获取当前触发方式',
4322
4322
  triggerType,
4323
4323
  '获取当前最后加载的js集合',
4324
4324
  getLoadFilterList,
4325
4325
  '过滤前的加载集合',
4326
4326
  getLoadJsList,
4327
4327
  );
4328
4328
  const loadTasks =
4329
4329
  getLoadFilterList.length > 0
4330
4330
  ? getLoadFilterList.map((item) => {
4331
4331
  const isLoadState = /sgm/.test(item?.fileName)
4332
4332
  ? window?.shopGlobalSwitch?.openSgm === 'true'
4333
4333
  : true;
4334
4334
  if (!isLoadState) {
4335
4335
  return Promise.resolve(true);
4336
4336
  }
4337
4337
  return this.loadItemSdkPromise(item)
4338
4338
  .then((res) => {
4339
4339
  console.info('当前js地址' + item?.src, '加载状态', res);
4340
4340
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
4341
4341
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
4342
4342
  const getNewdraEnableShopIdPercentObj =
4343
4343
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || null;
4344
4344
  const getNewdraEnableVenderIdPercentObj =
4345
4345
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || null;
4346
4346
  let canInitDraRun = true;
4347
4347
  if (getNewdraEnableShopIdPercentObj || getNewdraEnableVenderIdPercentObj) {
4348
4348
  canInitDraRun = this.shouldPercentExecuteNewDra(
4349
4349
  this.getNewDraEnablePercentNum(),
4350
4350
  );
4351
4351
  }
4352
4352
  if (canInitDraRun) {
4353
4353
  window.dra.run('init', { aid: res?.aid });
4354
4354
  window.dra.run('start');
4355
4355
  }
4356
4356
  }
4357
4357
  return true;
4358
4358
  })
4359
4359
  .catch((err) => {
4360
4360
  console.info('当前js地址加载异常', item?.src);
4361
4361
  window?.fetchErrorData &&
4362
4362
  window.fetchErrorData({
4363
4363
  title: '公共js加载异常',
4364
4364
  type: 'jsLoad',
4365
4365
  data: err,
4366
4366
  });
4367
4367
  return true;
4368
4368
  });
4369
4369
  })
4370
4370
  : [];
4371
4371
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
4372
4372
  }
4373
4373
 
4374
4374
  shouldPercentExecuteNewDra(percent) {
4375
4375
  if (percent <= 0) return false;
4376
4376
  if (percent >= 100) return true;
4377
4377
  const getRes = Math.random() < percent / 100;
4378
4378
  console.log('获取dra初始化执行的概率为', percent, '执行结果', getRes);
4379
4379
  return getRes;
4380
4380
  }
4381
4381
 
4382
4382
  getNewDraEnablePercentNum() {
4383
4383
  const getNewdraEnableShopIdPercent =
4384
4384
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || {};
4385
4385
  const getNewdraEnableVenderIdPercent =
4386
4386
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || {};
4387
4387
  const getShopId = parseQueryUrlObj?.shopId || '';
4388
4388
  const getVenderId = parseQueryUrlObj?.venderId || '';
4389
4389
  const getShopIdDraEnablePercent = getNewdraEnableShopIdPercent[getShopId]
4390
4390
  ? getNewdraEnableShopIdPercent[getShopId]
4391
4391
  : getNewdraEnableShopIdPercent?.ids?.includes(getShopId)
4392
4392
  ? getNewdraEnableShopIdPercent?.idsNumber
4393
4393
  : -1;
4394
4394
  const getVenderIdDraEnablePercent = getNewdraEnableVenderIdPercent[getVenderId]
4395
4395
  ? getNewdraEnableVenderIdPercent[getVenderId]
4396
4396
  : getNewdraEnableVenderIdPercent?.ids?.includes(getVenderId)
4397
4397
  ? getNewdraEnableVenderIdPercent?.idsNumber
4398
4398
  : -1;
4399
4399
  if (getShopIdDraEnablePercent > -1 || getVenderIdDraEnablePercent > -1) {
4400
4400
  return getShopIdDraEnablePercent || getVenderIdDraEnablePercent;
4401
4401
  }
4402
4402
  return 100;
4403
4403
  }
4404
4404
  loadScriptEle(jsInfo, resolve, reject) {
4405
4405
  const getFileName = jsInfo?.fileName;
4406
4406
  if (getFileName) {
4407
4407
  const getEleId = `J_loadJs_${getFileName}`;
4408
4408
  const getEle = document.getElementById(getEleId);
4409
4409
  if (!getEle) {
4410
4410
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4411
4411
  const _sgmEle = document.createElement('script');
4412
4412
  _sgmEle.id = getEleId;
4413
4413
  _sgmEle.onload = function () {
4414
4414
  resolve({
4415
4415
  ...jsInfo,
4416
4416
  jsTip: 'js加载成功',
4417
4417
  });
4418
4418
  };
4419
4419
  _sgmEle.onerror = function () {
4420
4420
  reject({
4421
4421
  ...jsInfo,
4422
4422
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4423
4423
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
4424
4424
  });
4425
4425
  };
4426
4426
  const dataAttrList = ['timeout', 'fileName', 'env'];
4427
4427
  const getJsInfoKeyList = Object.keys(jsInfo);
4428
4428
  getJsInfoKeyList.forEach((key) => {
4429
4429
  if (key === 'async') {
4430
4430
  _sgmEle.async = jsInfo[key];
4431
4431
  } else if (key === 'crossOrigin') {
4432
4432
  _sgmEle.crossOrigin = jsInfo[key];
4433
4433
  } else if (key === 'src') {
4434
4434
  _sgmEle.src = `${jsInfo[key]}`;
4435
4435
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
4436
4436
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
4437
4437
  } else {
4438
4438
  _sgmEle.setAttribute(key, jsInfo[key]);
4439
4439
  }
4440
4440
  });
4441
4441
  document.head.appendChild(_sgmEle);
4442
4442
  } else {
4443
4443
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
4444
4444
  resolve({
4445
4445
  ...jsInfo,
4446
4446
  jsTip: 'js本身已存在页面中',
4447
4447
  });
4448
4448
  }
4449
4449
  } else {
4450
4450
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
4451
4451
  }
4452
4452
  }
4453
4453
 
4454
4454
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
4455
4455
  if (jsInfo?.src) {
4456
4456
  const getInitLoadType =
4457
4457
  isJdApp && jsInfo?.initJdAppLoadType
4458
4458
  ? jsInfo?.initJdAppLoadType
4459
4459
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
4460
4460
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
4461
4461
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
4462
4462
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
4463
4463
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
4464
4464
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4465
4465
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4466
4466
  try {
4467
4467
  const jsXhrRequest = new XMLHttpRequest();
4468
4468
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
4469
4469
  const jsUrl = `${jsInfo?.src}`;
4470
4470
  jsXhrRequest.open('GET', jsUrl, true);
4471
4471
  jsXhrRequest.onreadystatechange = () => {
4472
4472
  if (jsXhrRequest.readyState === 4) {
4473
4473
  const getReqStatus = jsXhrRequest.status;
4474
4474
  const statusText = jsXhrRequest.statusText;
4475
4475
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4476
4476
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
4477
4477
  if (getInsetHeadState) {
4478
4478
  this.loadScriptEle(jsInfo, resolve, reject);
4479
4479
  } else {
4480
4480
  resolve({
4481
4481
  ...jsInfo,
4482
4482
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
4483
4483
  });
4484
4484
  }
4485
4485
  getReqStatus !== 200 &&
4486
4486
  draBusinessCustomReport({
4487
4487
  eventName: 'business',
4488
4488
  errorName: 'js_load_special_code',
4489
4489
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
4490
4490
  extraData: JSON.stringify({
4491
4491
  msg: '当前js加载成功,状态非200,特殊上报观察',
4492
4492
  jsReqState: getReqStatus,
4493
4493
  env: getSgmCustomCode('js_load_special_code'),
4494
4494
  data: jsInfo,
4495
4495
  }),
4496
4496
  });
4497
4497
  } else {
4498
4498
  const getRes = {
4499
4499
  ...jsInfo,
4500
4500
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4501
4501
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4502
4502
  jsReqState: getReqStatus,
4503
4503
  };
4504
4504
  console.log('当前js请求状态异常,具体信息见', getRes);
4505
4505
  reject(getRes);
4506
4506
  }
4507
4507
  }
4508
4508
  };
4509
4509
  jsXhrRequest.onerror = () => {
4510
4510
  const getRes = {
4511
4511
  ...jsInfo,
4512
4512
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4513
4513
  jsReqError: '请求错误',
4514
4514
  };
4515
4515
  console.log('当前js请求错误', getRes);
4516
4516
  jsXhrRequest.abort();
4517
4517
  reject(getRes);
4518
4518
  };
4519
4519
  jsXhrRequest.ontimeout = () => {
4520
4520
  const getRes = {
4521
4521
  ...jsInfo,
4522
4522
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4523
4523
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
4524
4524
  jsReqState: jsXhrRequest.status,
4525
4525
  };
4526
4526
  console.log('当前js请求超时异常', getRes);
4527
4527
  jsXhrRequest.abort();
4528
4528
  reject(getRes);
4529
4529
  };
4530
4530
  jsXhrRequest.send();
4531
4531
  } catch (e) {
4532
4532
  console.log('执行js请求异常', e);
4533
4533
  reject({
4534
4534
  ...jsInfo,
4535
4535
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4536
4536
  jsReqError: '未知异常',
4537
4537
  error: e,
4538
4538
  });
4539
4539
  }
4540
4540
  });
4541
4541
  } else {
4542
4542
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4543
4543
  return this.loadScriptEle(jsInfo, resolve, reject);
4544
4544
  });
4545
4545
  }
4546
4546
  }
4547
4547
  return this.loadJsSdkListCachePromise[getFileKeyName];
4548
4548
  } else {
4549
4549
  return Promise.resolve({
4550
4550
  ...jsInfo,
4551
4551
  jsTip: 'js加载方式设置为不加载,当前不做处理',
4552
4552
  });
4553
4553
  }
4554
4554
  } else {
4555
4555
  return Promise.reject(jsInfo);
4556
4556
  }
4557
4557
  }
4558
4558
 
4559
4559
  createLanguagePromise() {
4560
4560
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
4561
4561
  if (!this.languageCacheProimse) {
4562
4562
  this.languageCacheProimse = new Promise((resolve, reject) => {
4563
4563
  const { fileName, prefixUrl } = getLanguageConfig;
4564
4564
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
4565
4565
  const dealLanguageFile = () => {
4566
4566
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
4567
4567
  .then((res: any) => {
4568
4568
  if (res && res?.data) {
4569
4569
  this.languageJsonData = res.data;
4570
4570
 
4571
4571
  setTimeout(() => {
4572
4572
  const getOtherLanguageList = languageTypeList.filter(
4573
4573
  (item) => item !== languageNowType,
4574
4574
  );
4575
4575
  getOtherLanguageList.length > 0 &&
4576
4576
  getOtherLanguageList.map((languageTypeKey) => {
4577
4577
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
4578
4578
  });
4579
4579
  }, 3000);
4580
4580
  resolve(res);
4581
4581
  } else {
4582
4582
  reject(res);
4583
4583
  }
4584
4584
  })
4585
4585
  .catch((err) => {
4586
4586
  reject(err);
4587
4587
  });
4588
4588
  };
4589
4589
  if (fileName && prefixUrl) {
4590
4590
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
4591
4591
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
4592
4592
  if (getLocalLangRes) {
4593
4593
  try {
4594
4594
  const getLocalLangJsonData =
4595
4595
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
4596
4596
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
4597
4597
  if (getLocalLangJsonData?.fileName === fileName) {
4598
4598
  const geThisLangData = getLocalLangJsonData.data;
4599
4599
  this.languageJsonData = geThisLangData;
4600
4600
  return resolve({
4601
4601
  ...getLanguageConfig,
4602
4602
  languageNowType,
4603
4603
  data: geThisLangData,
4604
4604
  });
4605
4605
  } else {
4606
4606
  dealLanguageFile();
4607
4607
  }
4608
4608
  } else {
4609
4609
  dealLanguageFile();
4610
4610
  }
4611
4611
  } catch (e) {
4612
4612
  return reject({
4613
4613
  languageNowType,
4614
4614
  msg: '转换错误',
4615
4615
  ...getLanguageConfig,
4616
4616
  });
4617
4617
  }
4618
4618
  } else {
4619
4619
  dealLanguageFile();
4620
4620
  }
4621
4621
  } else {
4622
4622
  return reject({
4623
4623
  languageNowType,
4624
4624
  msg: '文件对象下发异常',
4625
4625
  ...getLanguageConfig,
4626
4626
  });
4627
4627
  }
4628
4628
  });
4629
4629
  }
4630
4630
  return this.languageCacheProimse;
4631
4631
  }
4632
4632
 
4633
4633
  getLanguageFilePromise(info, languageTypeKey) {
4634
4634
  const { fileName, prefixUrl, timeout } = info || {};
4635
4635
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
4636
4636
  return new Promise((resolve, reject) => {
4637
4637
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
4638
4638
  try {
4639
4639
  const langXhrRequest = new XMLHttpRequest();
4640
4640
  langXhrRequest.timeout = timeout || 2000;
4641
4641
  langXhrRequest.open('GET', getUrl, true);
4642
4642
  langXhrRequest.responseType = 'json';
4643
4643
  langXhrRequest.onreadystatechange = () => {
4644
4644
  if (langXhrRequest.readyState === 4) {
4645
4645
  const getReqStatus = langXhrRequest.status;
4646
4646
  const statusText = langXhrRequest.statusText;
4647
4647
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4648
4648
  const getData = langXhrRequest?.response || false;
4649
4649
  if (getData) {
4650
4650
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
4651
4651
  fileName,
4652
4652
  data: getData,
4653
4653
  });
4654
4654
  resolve({
4655
4655
  ...info,
4656
4656
  languageTypeKey,
4657
4657
  data: getData,
4658
4658
  });
4659
4659
  } else {
4660
4660
  reject({
4661
4661
  ...info,
4662
4662
  languageTypeKey,
4663
4663
  msg: '数据获取异常',
4664
4664
  });
4665
4665
  }
4666
4666
  } else {
4667
4667
  const getRes = {
4668
4668
  ...info,
4669
4669
  languageTypeKey,
4670
4670
  env: getSgmCustomCode(langLoadErrorSgmCode),
4671
4671
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4672
4672
  };
4673
4673
  console.log('当前lang请求状态异常,具体信息见', getRes);
4674
4674
  reject(getRes);
4675
4675
  }
4676
4676
  }
4677
4677
  };
4678
4678
  langXhrRequest.onerror = () => {
4679
4679
  const getRes = {
4680
4680
  ...info,
4681
4681
  env: getSgmCustomCode(langLoadErrorSgmCode),
4682
4682
  msg: '请求错误',
4683
4683
  };
4684
4684
  console.log('当前lang请求错误', getRes);
4685
4685
  langXhrRequest.abort();
4686
4686
  reject(getRes);
4687
4687
  };
4688
4688
  langXhrRequest.ontimeout = () => {
4689
4689
  const getRes = {
4690
4690
  ...info,
4691
4691
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
4692
4692
  };
4693
4693
  console.log('执行lang多语言请求超时异常', getRes);
4694
4694
  langXhrRequest.abort();
4695
4695
  reject(getRes);
4696
4696
  };
4697
4697
  langXhrRequest.send();
4698
4698
  } catch (e) {
4699
4699
  console.log('执行lang多语言请求异常', e);
4700
4700
  reject({
4701
4701
  ...info,
4702
4702
  env: getSgmCustomCode(langLoadErrorSgmCode),
4703
4703
  msg: '未知异常',
4704
4704
  error: e,
4705
4705
  });
4706
4706
  }
4707
4707
  });
4708
4708
  }