@conecli/cone-render 0.10.1-shop3.113 → 0.10.1-shop3.115

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: /\.jd\.hk/.test(window.location.hostname) ? '233' : '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
  callRouterAndroid,
2373
2373
  callRouterIOS,
2374
2374
  getMPaasConfigByBussinessKey,
2375
2375
  dealNativePixelToCssPixel,
2376
2376
  draBusinessCustomReport,
2377
2377
  draBusinessCustomLogReport,
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 {
2666
2666
  functionId,
2667
2667
  postEndTime,
2668
2668
  postStartTime,
2669
2669
  originWorkerType,
2670
2670
  workerType,
2671
2671
  } = workerData;
2672
2672
  if (
2673
2673
  functionId &&
2674
2674
  originWorkerType === TaroEventType.jdWorkerPreRequest &&
2675
2675
  postStartTime &&
2676
2676
  postEndTime
2677
2677
  ) {
2678
2678
  const getResTime = Date.now();
2679
2679
  const getMsg = `APP店铺业务worker请求返回结果成功,当前为${originWorkerType === workerType ?
2680
2680
  '预请求(即加载webview过程中接口数据已返回)' :
2681
2681
  '第1次主动请求(因预请求在webview加载过程中未返回)'},functionId是${functionId},接口请求耗时${
2682
2682
  postEndTime - postStartTime
2683
2683
  }ms,接口传输到h5耗时${
2684
2684
  getResTime - postEndTime
2685
2685
  }ms,postStartTime为${postStartTime},postEndTime为${postEndTime},getResTime为${getResTime}`
2686
2686
  draBusinessCustomLogReport(getMsg);
2687
2687
  }
2688
2688
  if (workerType === TaroEventType.jdWorkerPreRequest) {
2689
2689
  this.workerPreRequestData.set(workerData?.functionId, workerData);
2690
2690
  Taro.eventCenter.trigger(workerType, workerData);
2691
2691
  } else if (workerType === TaroEventType.jdWorkerRequest) {
2692
2692
  Taro.eventCenter.trigger(workerType, workerData);
2693
2693
  }
2694
2694
  }
2695
2695
  },
2696
2696
  )
2697
2697
  .then(() => {
2698
2698
  console.log('jd worker注册成功');
2699
2699
  draBusinessCustomLogReport(
2700
2700
  `APP店铺业务worker注册成功, 后续业务请求可以用worker发送,内部走原生请求`,
2701
2701
  );
2702
2702
  this.businessWorkerReady = true;
2703
2703
  resolve(true);
2704
2704
  })
2705
2705
  .catch((error) => {
2706
2706
  console.log(
2707
2707
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
2708
2708
  error,
2709
2709
  );
2710
2710
  draBusinessCustomReport({
2711
2711
  eventName: 'business',
2712
2712
  errorName: 'jmfe_onMsgForWorker_error',
2713
2713
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
2714
2714
  extraData: JSON.stringify({
2715
2715
  businessWorkerVersion:
2716
2716
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
2717
2717
  error,
2718
2718
  }),
2719
2719
  });
2720
2720
  !window?.PAGE_DATA?.businessData
2721
2721
  ?.forbidJdWorkerErrorLoadApiSafeSteadyReay &&
2722
2722
  this.loadApiSafeSteadyReayPromise();
2723
2723
  resolve(false);
2724
2724
  });
2725
2725
  })
2726
2726
  .catch((error) => {
2727
2727
  console.log('jmfe超时异常,worker注册失败', error);
2728
2728
  draBusinessCustomReport({
2729
2729
  eventName: 'business',
2730
2730
  errorName: 'jmfe_onMsgForWorker_error',
2731
2731
  errorMessage: `jd worker注册失败,原因是jmfe超时异常。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
2732
2732
  extraData: JSON.stringify({
2733
2733
  businessWorkerVersion:
2734
2734
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
2735
2735
  error,
2736
2736
  }),
2737
2737
  });
2738
2738
  !window?.PAGE_DATA?.businessData?.forbidJdWorkerErrorLoadApiSafeSteadyReay &&
2739
2739
  this.loadApiSafeSteadyReayPromise();
2740
2740
  resolve(false);
2741
2741
  });
2742
2742
  })
2743
2743
  : Promise.resolve(false));
2744
2744
  }
2745
2745
  return this.businessWorkerReadyPromise;
2746
2746
  } else {
2747
2747
  return Promise.resolve(false);
2748
2748
  }
2749
2749
  }
2750
2750
 
2751
2751
  taskTimeoutPromise(callBack, timeout = 2000) {
2752
2752
  return new Promise((resolve) => {
2753
2753
  setTimeout(
2754
2754
  () => {
2755
2755
  const getCallBackRes = typeof callBack === 'function' && callBack();
2756
2756
  return resolve(getCallBackRes || false);
2757
2757
  },
2758
2758
  isInJdAppH5DebugMode ? 0 : timeout,
2759
2759
  );
2760
2760
  });
2761
2761
  }
2762
2762
  _getJdPadMinWidthForListen() {
2763
2763
  return (
2764
2764
  isJdApp &&
2765
2765
  Math.min(window.screen.width, window.screen.height) >
2766
2766
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
2767
2767
  );
2768
2768
  }
2769
2769
 
2770
2770
  getJdScreenSizeInfoPromise() {
2771
2771
  !this.jdScreenSizeInfoPromise &&
2772
2772
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
2773
2773
  const getThisTime = Date.now();
2774
2774
  this.jmfeReayPromise().then(() => {
2775
2775
  return Promise.race([
2776
2776
  window.jmfe.getScreenSize(),
2777
2777
  this.taskTimeoutPromise(() => {
2778
2778
  return {
2779
2779
  status: '-10',
2780
2780
  msg: '获取大屏信息2s超时',
2781
2781
  };
2782
2782
  }),
2783
2783
  ])
2784
2784
  .then((res) => {
2785
2785
  console.warn('===获取app大屏信息====', res);
2786
2786
  const { status, data } = res;
2787
2787
  if (status === '0' && data) {
2788
2788
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
2789
2789
  const getPageInfo = dealNativePixelToCssPixel({
2790
2790
  pageWidth,
2791
2791
  pageHeight,
2792
2792
  });
2793
2793
  this.info.sysInfo.jdScreenSizeType = sizeType;
2794
2794
  const getUseTime = Date.now() - getThisTime;
2795
2795
  console.warn(
2796
2796
  '===计算是否是app大屏信息,需满足宽度最新720===',
2797
2797
  getPageInfo,
2798
2798
  '原始数据',
2799
2799
  data,
2800
2800
  '是否是横屏isLandscape为1=',
2801
2801
  isLandscape,
2802
2802
  '用时',
2803
2803
  getUseTime,
2804
2804
  );
2805
2805
  if (getPageInfo?.pageWidth > 0) {
2806
2806
  this.rootEleInitWidth = getPageInfo?.pageWidth;
2807
2807
  draBusinessCustomReport({
2808
2808
  eventName: 'UIInteract',
2809
2809
  errorName: 'rootEle_width_getJdScreenSizeInfo',
2810
2810
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
2811
2811
  extraData: JSON.stringify({
2812
2812
  isJdApp,
2813
2813
  getPageInfo,
2814
2814
  originData: res,
2815
2815
  }),
2816
2816
  });
2817
2817
  resolve(getPageInfo);
2818
2818
  } else {
2819
2819
  resolve({
2820
2820
  pageWidth: 0,
2821
2821
  pageHeight: 0,
2822
2822
  msg: '转换异常',
2823
2823
  });
2824
2824
  }
2825
2825
  } else {
2826
2826
  resolve({
2827
2827
  pageWidth: 0,
2828
2828
  pageHeight: 0,
2829
2829
  msg: '获取大屏信息异常或者超时',
2830
2830
  });
2831
2831
  }
2832
2832
  })
2833
2833
  .catch((err) => {
2834
2834
  console.log('获取大屏信息异常', err);
2835
2835
  resolve({
2836
2836
  pageWidth: 0,
2837
2837
  pageHeight: 0,
2838
2838
  msg: '获取大屏信息异常',
2839
2839
  });
2840
2840
  });
2841
2841
  });
2842
2842
  }));
2843
2843
  return this.jdScreenSizeInfoPromise;
2844
2844
  }
2845
2845
 
2846
2846
  listenJdTabletScreenChange() {
2847
2847
  this.jmfeReayPromise().then(() => {
2848
2848
  try {
2849
2849
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
2850
2850
  window.jmfe.listenDeviceScreenChange((event) => {
2851
2851
  console.log(
2852
2852
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
2853
2853
  event,
2854
2854
  '通过前端判断是不是横屏',
2855
2855
  window.matchMedia('(orientation: landscape)')?.matches,
2856
2856
  );
2857
2857
  const { orientation } = event?.data;
2858
2858
  if (orientation) {
2859
2859
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
2860
2860
  Taro.eventCenter.trigger(
2861
2861
  TaroEventType.TABLE_SCREEN_CHANGE,
2862
2862
  this.info.sysInfo.isJdTabletLandscape,
2863
2863
  orientation,
2864
2864
  );
2865
2865
  }
2866
2866
  });
2867
2867
  } catch (error) {
2868
2868
  console.log('listenScreenChange的打印error:', error);
2869
2869
  }
2870
2870
  });
2871
2871
  }
2872
2872
 
2873
2873
  updateBusinessDomainAndApi(domain, api) {
2874
2874
  }
2875
2875
 
2876
2876
  formatNativeScreenPageData(action) {
2877
2877
  let getChangePageInfo: any = null;
2878
2878
  try {
2879
2879
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
2880
2880
  JSON.stringify({
2881
2881
  plugin: 'JDHybridScreenPlugin',
2882
2882
  action,
2883
2883
  sync: '1',
2884
2884
  }),
2885
2885
  );
2886
2886
  const getChangePageInfoData =
2887
2887
  typeof getNativeScreenPageInfoStr === 'string'
2888
2888
  ? JSON.parse(getNativeScreenPageInfoStr)
2889
2889
  : null;
2890
2890
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
2891
2891
  const { code, data } = getChangePageInfoData;
2892
2892
  getChangePageInfo = code && code === '0' ? data : null;
2893
2893
  }
2894
2894
  } catch (e) {
2895
2895
  console.log('JDHybridScreenPlugin转换异常', e);
2896
2896
  }
2897
2897
  return getChangePageInfo;
2898
2898
  }
2899
2899
 
2900
2900
  isAndroidFoldScreen() {
2901
2901
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
2902
2902
  }
2903
2903
 
2904
2904
  isHarmonyFoldScreenPromise(): Promise<{
2905
2905
  isFoldScreen: boolean;
2906
2906
  getFoldDisplayMode?: number;
2907
2907
  }> {
2908
2908
  return new Promise((resolve) => {
2909
2909
  this.jmfeReayPromise()
2910
2910
  .then(() => {
2911
2911
  if (window.jmfe?.callNative) {
2912
2912
  Promise.all([
2913
2913
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
2914
2914
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
2915
2915
  ])
2916
2916
  .then((res) => {
2917
2917
  resolve({
2918
2918
  isFoldScreen: res?.[0]?.data === '1',
2919
2919
  getFoldDisplayMode: res?.[1]?.data,
2920
2920
  });
2921
2921
  })
2922
2922
  .catch(() => {
2923
2923
  resolve({
2924
2924
  isFoldScreen: false,
2925
2925
  getFoldDisplayMode: undefined,
2926
2926
  });
2927
2927
  });
2928
2928
  } else {
2929
2929
  resolve({
2930
2930
  isFoldScreen: false,
2931
2931
  getFoldDisplayMode: undefined,
2932
2932
  });
2933
2933
  }
2934
2934
  })
2935
2935
  .catch(() => {
2936
2936
  resolve({
2937
2937
  isFoldScreen: false,
2938
2938
  getFoldDisplayMode: undefined,
2939
2939
  });
2940
2940
  });
2941
2941
  });
2942
2942
  }
2943
2943
 
2944
2944
  getJdAndroidPageChangeScreenInfo() {
2945
2945
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
2946
2946
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
2947
2947
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
2948
2948
  pageWidth: getPageScreenInfo.pageWidth,
2949
2949
  pageHeight: getPageScreenInfo.pageHeight,
2950
2950
  });
2951
2951
  getPageScreenInfo.pageWidth = pageWidth;
2952
2952
  getPageScreenInfo.pageHeight = pageHeight;
2953
2953
  }
2954
2954
  return getPageScreenInfo;
2955
2955
  }
2956
2956
 
2957
2957
  getRootEleWindowWidthInfo() {
2958
2958
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
2959
2959
  const getWindowWidth = window.innerWidth;
2960
2960
  const getScreenWidth = window.screen.width;
2961
2961
  return {
2962
2962
  getRootEleWidth,
2963
2963
  getWindowWidth,
2964
2964
  getScreenWidth,
2965
2965
  };
2966
2966
  }
2967
2967
 
2968
2968
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
2969
2969
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
2970
2970
  console.log(
2971
2971
  '当前获取根元素的宽度',
2972
2972
  getRootEleWidth,
2973
2973
  'getWindowWidth',
2974
2974
  getWindowWidth,
2975
2975
  'getScreenWidth',
2976
2976
  getScreenWidth,
2977
2977
  );
2978
2978
  const getLastWidth =
2979
2979
  getRootEleWidth > 0
2980
2980
  ? Math.round(getRootEleWidth)
2981
2981
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
2982
2982
  console.warn(
2983
2983
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2984
2984
  );
2985
2985
  timeout > 0 &&
2986
2986
  draBusinessCustomReport({
2987
2987
  eventName: 'UIInteract',
2988
2988
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
2989
2989
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2990
2990
  extraData: JSON.stringify({
2991
2991
  isJdApp,
2992
2992
  getRootEleWidth,
2993
2993
  getWindowWidth,
2994
2994
  getScreenWidth,
2995
2995
  ...reportParam,
2996
2996
  }),
2997
2997
  });
2998
2998
  return getLastWidth;
2999
2999
  }
3000
3000
 
3001
3001
  getPadWindowRootEleWidthPromise() {
3002
3002
  if (this.rootEleInitWidth > 0) {
3003
3003
  return Promise.resolve(this.rootEleInitWidth);
3004
3004
  } else {
3005
3005
  !this.rootEleWidthRegisterPromise &&
3006
3006
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
3007
3007
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
3008
3008
  if (getRootEleInitWidth > 0) {
3009
3009
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
3010
3010
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
3011
3011
  resolve(this.rootEleInitWidth);
3012
3012
  } else {
3013
3013
  const timerPromise = () => {
3014
3014
  return new Promise((resolve2) => {
3015
3015
  window.setTimeout(() => {
3016
3016
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
3017
3017
  this.getRootEleWindowWidthInfo();
3018
3018
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
3019
3019
  console.warn(
3020
3020
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
3021
3021
  );
3022
3022
  draBusinessCustomReport({
3023
3023
  eventName: 'UIInteract',
3024
3024
  errorName: 'rootEle_width_200_timeout_info',
3025
3025
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
3026
3026
  extraData: JSON.stringify({
3027
3027
  isJdApp,
3028
3028
  getRootEleWidth,
3029
3029
  getWindowWidth,
3030
3030
  getScreenWidth,
3031
3031
  }),
3032
3032
  });
3033
3033
  const getRes =
3034
3034
  getRootEleWidth > 0 && getWindowWidth > 0
3035
3035
  ? Math.min(getRootEleWidth, getWindowWidth)
3036
3036
  : Math.max(getRootEleWidth, getWindowWidth);
3037
3037
  resolve2({
3038
3038
  pageWidth: Math.round(getRes),
3039
3039
  });
3040
3040
  }
3041
3041
  }, 200);
3042
3042
  });
3043
3043
  };
3044
3044
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
3045
3045
  const { pageWidth } = res;
3046
3046
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
3047
3047
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
3048
3048
  });
3049
3049
  }
3050
3050
  }));
3051
3051
  return this.rootEleWidthRegisterPromise;
3052
3052
  }
3053
3053
  }
3054
3054
 
3055
3055
  async getSystemInfo(params) {
3056
3056
  const getParams = Object.assign({}, params || {});
3057
3057
  if (this.rootEleInitWidth > 0) {
3058
3058
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
3059
3059
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
3060
3060
  } else {
3061
3061
  if (this._getJdPadMinWidthForListen()) {
3062
3062
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
3063
3063
  getParams['replaceSystemWidth'] = true;
3064
3064
  }
3065
3065
  }
3066
3066
  isJdApp && this.createLanguagePromise();
3067
3067
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
3068
3068
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
3069
3069
  let _isfoldScreen = false;
3070
3070
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
3071
3071
  console.info(
3072
3072
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
3073
3073
  getStorageData,
3074
3074
  '通过缓存值第一次判断是否是折叠屏',
3075
3075
  getStorageData === 'true',
3076
3076
  );
3077
3077
  if (!getStorageData) {
3078
3078
  _isfoldScreen = this.isAndroidFoldScreen();
3079
3079
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
3080
3080
  } else {
3081
3081
  _isfoldScreen = getStorageData === 'true';
3082
3082
  }
3083
3083
  if (_isfoldScreen) {
3084
3084
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
3085
3085
  if (getJdAndroidPageInfo) {
3086
3086
  info = getSystemInfos(getJdAndroidPageInfo);
3087
3087
  console.warn(
3088
3088
  '当前为松果安卓折叠屏app,获取折叠屏信息',
3089
3089
  getJdAndroidPageInfo,
3090
3090
  '获取转换后的系统信息',
3091
3091
  info,
3092
3092
  );
3093
3093
  draBusinessCustomReport({
3094
3094
  eventName: 'UIInteract',
3095
3095
  errorName: 'android_jdapp_foldScreen_info',
3096
3096
  errorMessage:
3097
3097
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
3098
3098
  extraData: JSON.stringify({
3099
3099
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
3100
3100
  androidPageInfo: getJdAndroidPageInfo,
3101
3101
  jdAppVersionStr,
3102
3102
  taroSysInfo: info,
3103
3103
  }),
3104
3104
  });
3105
3105
  }
3106
3106
  }
3107
3107
  }
3108
3108
  if (isJdApp) {
3109
3109
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
3110
3110
  }
3111
3111
  this.info.sysInfo = {
3112
3112
  actualNavBarHeight: 0,
3113
3113
  ...this.info.sysInfo,
3114
3114
  ...info,
3115
3115
  safeContentHeight: info?.screenHeight,
3116
3116
  headerHeight: 0,
3117
3117
  tabBarHeight: 0,
3118
3118
  languageType: languageNowType,
3119
3119
  };
3120
3120
  if (isJdApp || isH5AndJingGouMini) {
3121
3121
  this.getAddressCachePromise();
3122
3122
  this.getLbsAddressCachePromise();
3123
3123
  }
3124
3124
  if (isJdApp) {
3125
3125
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
3126
3126
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
3127
3127
  this.getJdAppBaseInfo();
3128
3128
  this.getElderModePromise();
3129
3129
  this.getJDAppearanceStatePromise();
3130
3130
  this.createJdAndroidRquestEventForTouchStart();
3131
3131
  }
3132
3132
  this.getWifiVideoAutoPlayAsync();
3133
3133
  this.getMPaasConfigAsync();
3134
3134
  this.getNetWorkType();
3135
3135
  }
3136
3136
 
3137
3137
  getElderModePromise() {
3138
3138
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
3139
3139
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
3140
3140
  } else {
3141
3141
  if (isJdAndAndroidDevice) {
3142
3142
  this.info.sysInfo.jdAppModeType = '0';
3143
3143
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
3144
3144
  } else {
3145
3145
  return Promise.race([
3146
3146
  this.taskTimeoutPromise(() => {
3147
3147
  this.info.sysInfo.jdAppModeType = '0';
3148
3148
  return this.info.sysInfo.jdAppModeType;
3149
3149
  }),
3150
3150
  new Promise((resolve) => {
3151
3151
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
3152
3152
  if (!window[getCallBackName]) {
3153
3153
  window[getCallBackName] = (res) => {
3154
3154
  try {
3155
3155
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3156
3156
  const { status, data, msg } = getResJson;
3157
3157
  console.log(`获取松果app展示模式成功,返回结果${data}`);
3158
3158
  if (status === '0') {
3159
3159
  this.info.sysInfo.jdAppModeType = data;
3160
3160
  resolve(data);
3161
3161
  } else {
3162
3162
  resolve('0');
3163
3163
  }
3164
3164
  } catch (e) {
3165
3165
  resolve('0');
3166
3166
  }
3167
3167
  window[getCallBackName] = null;
3168
3168
  };
3169
3169
  }
3170
3170
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
3171
3171
  method: 'callSyncRouterModuleWithParams',
3172
3172
  params: JSON.stringify({
3173
3173
  routerURL: 'router://JDBModeModule/getCurrentMode',
3174
3174
  routerParam: {},
3175
3175
  callBackName: `window.${getCallBackName}`,
3176
3176
  callBackId: `${getCallBackName}Ios`,
3177
3177
  }),
3178
3178
  });
3179
3179
  }),
3180
3180
  ]);
3181
3181
  }
3182
3182
  }
3183
3183
  }
3184
3184
  getAPPUseStraightCorner() {
3185
3185
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
3186
3186
  const params = {
3187
3187
  routerURL,
3188
3188
  routerParam: {},
3189
3189
  jdRouter: '1',
3190
3190
  };
3191
3191
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
3192
3192
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
3193
3193
  } else {
3194
3194
  return this.jmfeReayPromise()
3195
3195
  .then(() => {
3196
3196
  if (isJdAndHarmonyDevice || !isJdApp) {
3197
3197
  console.log('not APP or is Harmony');
3198
3198
  return Promise.resolve(false);
3199
3199
  }
3200
3200
  console.log('jmfe setShareInfo', params);
3201
3201
  return Promise.race([
3202
3202
  window.jmfe.callRouter(params),
3203
3203
  this.taskTimeoutPromise(() => {
3204
3204
  return false;
3205
3205
  }),
3206
3206
  ]).then(({ status, data }) => {
3207
3207
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
3208
3208
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
3209
3209
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
3210
3210
  return Promise.resolve(status === '0' && Number(data) === 1);
3211
3211
  });
3212
3212
  })
3213
3213
  .catch((e) => {
3214
3214
  console.log('jmfe error', e);
3215
3215
  return Promise.resolve(false);
3216
3216
  });
3217
3217
  }
3218
3218
  }
3219
3219
 
3220
3220
  getJDAppearanceStatePromise() {
3221
3221
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
3222
3222
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
3223
3223
  } else {
3224
3224
  return Promise.race([
3225
3225
  this.taskTimeoutPromise(() => {
3226
3226
  this.info.sysInfo.jdAppearanceState = '0';
3227
3227
  return this.info.sysInfo.jdAppearanceState;
3228
3228
  }),
3229
3229
  new Promise((resolve) => {
3230
3230
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
3231
3231
  if (!window[getCallBackName]) {
3232
3232
  window[getCallBackName] = (res) => {
3233
3233
  try {
3234
3234
  console.log('getJDAppearanceStatePromise', res);
3235
3235
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3236
3236
  const { status, data, msg } = getResJson;
3237
3237
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
3238
3238
  if (status === '0') {
3239
3239
  this.info.sysInfo.jdAppearanceState = data;
3240
3240
  resolve(data);
3241
3241
  } else {
3242
3242
  resolve('0');
3243
3243
  }
3244
3244
  } catch (e) {
3245
3245
  resolve('0');
3246
3246
  }
3247
3247
  window[getCallBackName] = null;
3248
3248
  };
3249
3249
  }
3250
3250
  if (isAndroidDevice) {
3251
3251
  const jsonString = JSON.stringify({
3252
3252
  callBackName: `window.${getCallBackName}`,
3253
3253
  });
3254
3254
  console.log('window.JDAppearance', window?.JDAppearance);
3255
3255
  window?.JDAppearance &&
3256
3256
  window?.JDAppearance?.getUiState &&
3257
3257
  window.JDAppearance.getUiState(jsonString);
3258
3258
  } else {
3259
3259
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
3260
3260
  method: 'callSyncRouterModuleWithParams',
3261
3261
  params: JSON.stringify({
3262
3262
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
3263
3263
  routerParam: {},
3264
3264
  callBackName: `window.${getCallBackName}`,
3265
3265
  callBackId: `${getCallBackName}Ios`,
3266
3266
  }),
3267
3267
  });
3268
3268
  }
3269
3269
  }),
3270
3270
  ]);
3271
3271
  }
3272
3272
  }
3273
3273
 
3274
3274
  createJdAndroidRquestEventForTouchStart() {
3275
3275
  if (isJdAndAndroidDevice && window?.JdAndroid) {
3276
3276
  const rootEleNode = document.querySelector('body');
3277
3277
  if (rootEleNode) {
3278
3278
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
3279
3279
  }
3280
3280
  }
3281
3281
  }
3282
3282
  jdAndroidAddEventListenerTouchStart(e) {
3283
3283
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
3284
3284
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
3285
3285
  const hasCustomEle = e
3286
3286
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
3287
3287
  : false;
3288
3288
  if (!hasCustomEle) {
3289
3289
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
3290
3290
  console.log(
3291
3291
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
3292
3292
  );
3293
3293
  }
3294
3294
  }
3295
3295
  }
3296
3296
  removeJdAndroidRquestEventForTouchStart() {
3297
3297
  if (isJdAndAndroidDevice && window.JdAndroid) {
3298
3298
  const rootEleNode = document.querySelector('body');
3299
3299
  if (rootEleNode) {
3300
3300
  rootEleNode.removeEventListener(
3301
3301
  'touchstart',
3302
3302
  this.jdAndroidAddEventListenerTouchStart,
3303
3303
  false,
3304
3304
  );
3305
3305
  }
3306
3306
  }
3307
3307
  }
3308
3308
 
3309
3309
  getNetWorkType() {
3310
3310
  if (isJdApp) {
3311
3311
  return new Promise((resolve) => {
3312
3312
  this.jmfeReayPromise().then(() => {
3313
3313
  window.jmfe
3314
3314
  .getNetworkStatus()
3315
3315
  .then(({ status, data }) => {
3316
3316
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
3317
3317
  if (status === '0') {
3318
3318
  this.info.sysInfo['networkType'] = data;
3319
3319
  resolve({
3320
3320
  networkType: data,
3321
3321
  });
3322
3322
  } else {
3323
3323
  return this._taroGetNetworkType();
3324
3324
  }
3325
3325
  })
3326
3326
  .catch((err) => {
3327
3327
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
3328
3328
  return this._taroGetNetworkType();
3329
3329
  });
3330
3330
  });
3331
3331
  });
3332
3332
  } else {
3333
3333
  return this._taroGetNetworkType();
3334
3334
  }
3335
3335
  }
3336
3336
  _taroGetNetworkType() {
3337
3337
  return Taro.getNetworkType().then((getRes) => {
3338
3338
  if (getRes && getRes.networkType) {
3339
3339
  this.info.sysInfo['netWorkType'] = getRes.networkType;
3340
3340
  console.log(
3341
3341
  '在app内通过taro对象获取网络状态完成,当前网络状态',
3342
3342
  this.info.sysInfo['netWorkType'],
3343
3343
  );
3344
3344
  }
3345
3345
  return getRes;
3346
3346
  });
3347
3347
  }
3348
3348
 
3349
3349
  getJdAppBaseInfo() {
3350
3350
  const appKeyCacheToCookieMinuteTime =
3351
3351
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
3352
3352
  appUuidCacheToCookieMinuteTime =
3353
3353
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
3354
3354
  getAppKey = cookie.get(cacheAppKey),
3355
3355
  getAppUuidKey = cookie.get(cacheAppUuidKey);
3356
3356
  console.log(
3357
3357
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
3358
3358
  cacheAppKey,
3359
3359
  getAppKey,
3360
3360
  cacheAppUuidKey,
3361
3361
  getAppUuidKey,
3362
3362
  );
3363
3363
  if (
3364
3364
  appKeyCacheToCookieMinuteTime &&
3365
3365
  appUuidCacheToCookieMinuteTime &&
3366
3366
  getAppKey &&
3367
3367
  getAppUuidKey
3368
3368
  ) {
3369
3369
  const [uuid, eufv] = getAppUuidKey.split('@');
3370
3370
  const baseApiKeyParam = {
3371
3371
  uuid,
3372
3372
  };
3373
3373
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
3374
3374
  if (eufv === '1' && /-/.test(uuid)) {
3375
3375
  const [eu, fv] = uuid.split('-');
3376
3376
  baseApiKeyParam['eu'] = eu;
3377
3377
  baseApiKeyParam['fv'] = fv;
3378
3378
  }
3379
3379
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3380
3380
  this.jmfeReayPromise().then(() => {
3381
3381
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
3382
3382
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3383
3383
  });
3384
3384
  } else {
3385
3385
  const checkGetJdAppKeyState =
3386
3386
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
3387
3387
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
3388
3388
  this.jmfeReayPromise().then(() => {
3389
3389
  Promise.all([
3390
3390
  checkGetJdAppKeyState && window.jmfe?.callNative
3391
3391
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
3392
3392
  : Promise.resolve({
3393
3393
  status: '-1000',
3394
3394
  msg: '当前版本不支持获取松果app中的getAppKey',
3395
3395
  data: '-1000',
3396
3396
  }),
3397
3397
  window.jmfe.getDeviceInfo(),
3398
3398
  ]).then((resList) => {
3399
3399
  const [getAppKeyRes, deviceInfoRes] = resList;
3400
3400
  console.log(
3401
3401
  '在app内初始化通过jmfe获取getAppKey结果',
3402
3402
  getAppKeyRes,
3403
3403
  '通过jmfe获取getDeviceInfo获取结果',
3404
3404
  deviceInfoRes,
3405
3405
  );
3406
3406
  const baseApiKeyParam = {};
3407
3407
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
3408
3408
  const getJmfeAppKey = getAppKeyRes?.data;
3409
3409
  if (getJmfeAppKey && getJmfeAppKey !== '') {
3410
3410
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
3411
3411
  const getJdAppKeyCacheToCookieMinuteTime =
3412
3412
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
3413
3413
  if (getJdAppKeyCacheToCookieMinuteTime) {
3414
3414
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
3415
3415
  cookie.set(cacheAppKey, getJmfeAppKey, {
3416
3416
  path: '/',
3417
3417
  expires,
3418
3418
  });
3419
3419
  }
3420
3420
  }
3421
3421
  }
3422
3422
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
3423
3423
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
3424
3424
  if (uuid && uuid !== '') {
3425
3425
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
3426
3426
  baseApiKeyParam['uuid'] = uuid;
3427
3427
  if (eufv === '1' && /-/.test(uuid)) {
3428
3428
  const [eu, fv] = uuid.split('-');
3429
3429
  baseApiKeyParam['eu'] = eu;
3430
3430
  baseApiKeyParam['fv'] = fv;
3431
3431
  }
3432
3432
  const getAppUuidCacheToCookieMinuteTime =
3433
3433
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
3434
3434
  if (getAppUuidCacheToCookieMinuteTime) {
3435
3435
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
3436
3436
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
3437
3437
  path: '/',
3438
3438
  expires,
3439
3439
  });
3440
3440
  }
3441
3441
  }
3442
3442
  }
3443
3443
  console.log(
3444
3444
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
3445
3445
  baseApiKeyParam,
3446
3446
  );
3447
3447
  if (Object.keys(baseApiKeyParam).length > 0) {
3448
3448
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3449
3449
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3450
3450
  }
3451
3451
  });
3452
3452
  });
3453
3453
  }
3454
3454
  }
3455
3455
 
3456
3456
  getCacheAddressRouter() {
3457
3457
  if (isJdApp) {
3458
3458
  if (!isJdAndHarmonyDevice) {
3459
3459
  return Promise.race([
3460
3460
  new Promise((resolve) => {
3461
3461
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
3462
3462
  if (!window[getCallBackName]) {
3463
3463
  window[getCallBackName] = (res) => {
3464
3464
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
3465
3465
  try {
3466
3466
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3467
3467
  resolve(getResJson);
3468
3468
  } catch (e) {
3469
3469
  resolve({
3470
3470
  status: '-1002',
3471
3471
  msg: '地址信息解析json异常',
3472
3472
  res,
3473
3473
  });
3474
3474
  }
3475
3475
  window[getCallBackName] = null;
3476
3476
  };
3477
3477
  }
3478
3478
  const getRouterParam = {
3479
3479
  sceneId: 'basicShoppingProcess',
3480
3480
  };
3481
3481
  if (isAndroidDevice) {
3482
3482
  return callRouterAndroid({
3483
3483
  routerURL: 'router://JDAddressModule/getCacheAddress',
3484
3484
  routerParam: getRouterParam,
3485
3485
  callBackName: getCallBackName,
3486
3486
  isSync: true,
3487
3487
  });
3488
3488
  } else {
3489
3489
  return callRouterIOS({
3490
3490
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
3491
3491
  routerParam: getRouterParam,
3492
3492
  callBackName: getCallBackName,
3493
3493
  });
3494
3494
  }
3495
3495
  }),
3496
3496
  this.taskTimeoutPromise(() => {
3497
3497
  return {
3498
3498
  status: '-1000',
3499
3499
  msg: '原生router协议获取地址信息超时',
3500
3500
  };
3501
3501
  }, 3000),
3502
3502
  ]);
3503
3503
  } else {
3504
3504
  return Promise.race([
3505
3505
  new Promise((resolve) => {
3506
3506
  this.jmfeReayPromise()
3507
3507
  .then(() => {
3508
3508
  const plugin = 'JDHybridRouterPlugin';
3509
3509
  const action = 'callSyncRouterModuleWithParams';
3510
3510
  const params = {
3511
3511
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
3512
3512
  routerParam: '',
3513
3513
  };
3514
3514
  const sync = '1';
3515
3515
  try {
3516
3516
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
3517
3517
  resolve(res);
3518
3518
  });
3519
3519
  } catch (error) {
3520
3520
  resolve({
3521
3521
  status: '-1001',
3522
3522
  msg: '判断jmfe不存在,获取经纬度信息异常',
3523
3523
  });
3524
3524
  }
3525
3525
  })
3526
3526
  .catch(() => {
3527
3527
  resolve({
3528
3528
  status: '-1002',
3529
3529
  msg: '鸿蒙系统调用jmfe异常,获取失败',
3530
3530
  });
3531
3531
  });
3532
3532
  }),
3533
3533
  this.taskTimeoutPromise(() => {
3534
3534
  return {
3535
3535
  status: '-1000',
3536
3536
  msg: '原生router协议获取地址信息超时',
3537
3537
  };
3538
3538
  }, 3000),
3539
3539
  ]);
3540
3540
  }
3541
3541
  } else if (isH5AndJingGouMini) {
3542
3542
  const { areaId, addressName } = this.getJingGouMiniInh5Address();
3543
3543
  if (areaId && areaId !== '' && addressName && addressName !== '') {
3544
3544
  return Promise.resolve({
3545
3545
  status: '0',
3546
3546
  data: {
3547
3547
  areaId,
3548
3548
  fullAddress: addressName,
3549
3549
  },
3550
3550
  });
3551
3551
  } else {
3552
3552
  return Promise.resolve({
3553
3553
  status: '-1002',
3554
3554
  msg: '京购内嵌h5h5暂无业务需要,未实现,获取失败',
3555
3555
  });
3556
3556
  }
3557
3557
  } else {
3558
3558
  return Promise.resolve({
3559
3559
  status: '-1002',
3560
3560
  msg: '普通h5暂无业务需要,未实现,获取失败',
3561
3561
  });
3562
3562
  }
3563
3563
  }
3564
3564
 
3565
3565
  getJingGouMiniInh5Address() {
3566
3566
  let getRes: any = {
3567
3567
  areaId: '',
3568
3568
  addressName: '',
3569
3569
  };
3570
3570
  try {
3571
3571
  const getUrlHast = decodeURIComponent(window.location.hash || '');
3572
3572
  const sensMatch = getUrlHast ? getUrlHast.match(/sens=({.*?})/) : null;
3573
3573
  if (sensMatch && sensMatch[1]) {
3574
3574
  const sensData = JSON.parse(sensMatch[1]);
3575
3575
  const getWqAddr = sensData?.wq_addr || '';
3576
3576
  if (getWqAddr && /\|/.test(getWqAddr)) {
3577
3577
  const addressList = getWqAddr.split(/\|/);
3578
3578
  const [addressId, areaId, areaName, addressName, coordinate] = addressList;
3579
3579
  getRes = {
3580
3580
  addressId,
3581
3581
  areaId,
3582
3582
  areaName,
3583
3583
  addressName,
3584
3584
  coordinate,
3585
3585
  };
3586
3586
  }
3587
3587
  }
3588
3588
  } catch (e) {
3589
3589
  console.log('获取hash转换异常', e);
3590
3590
  }
3591
3591
  return getRes;
3592
3592
  }
3593
3593
 
3594
3594
  getAddressCachePromise() {
3595
3595
  return new Promise((resolve) => {
3596
3596
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
3597
3597
  resolve({
3598
3598
  lat: this.info.sysInfo.lat,
3599
3599
  lng: this.info.sysInfo.lng,
3600
3600
  area: this?.info?.sysInfo?.area,
3601
3601
  fullAddress: this?.info?.pageInfo?.fullAddress,
3602
3602
  });
3603
3603
  } else {
3604
3604
  this.getCacheAddressRouter()
3605
3605
  .then((res) => {
3606
3606
  const { status, data } = res;
3607
3607
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
3608
3608
  if (status === '0' && data) {
3609
3609
  const {
3610
3610
  lat,
3611
3611
  latitude,
3612
3612
  lng,
3613
3613
  longitude,
3614
3614
  provinceId,
3615
3615
  cityId,
3616
3616
  countyId,
3617
3617
  townId,
3618
3618
  fullAddress,
3619
3619
  areaId,
3620
3620
  } = data || {};
3621
3621
  const getAreaIdsEnable = areaId && areaId !== '';
3622
3622
  const getEncodeFullAddress = fullAddress ? encodeURIComponent(fullAddress) : '';
3623
3623
  let area = getAreaIdsEnable ? areaId : '';
3624
3624
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
3625
3625
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
3626
3626
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
3627
3627
  if ((getProvinceIdNum && getProvinceIdNum > 0) || getAreaIdsEnable) {
3628
3628
  area = getAreaIdsEnable
3629
3629
  ? areaId
3630
3630
  : `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
3631
3631
  this.info.pageInfo['address'] = area;
3632
3632
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
3633
3633
  this.info.sysInfo['area'] = area;
3634
3634
  const getUpdateData = {
3635
3635
  area: this.info.pageInfo.address,
3636
3636
  };
3637
3637
  if (fullAddress && fullAddress.length > 0) {
3638
3638
  getUpdateData['fullAddress'] = getEncodeFullAddress;
3639
3639
  this.info.pageInfo['fullAddress'] = getEncodeFullAddress;
3640
3640
  }
3641
3641
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, getUpdateData);
3642
3642
  }
3643
3643
  resolve({
3644
3644
  lat: this.info.sysInfo['lat'],
3645
3645
  lng: this.info.sysInfo['lng'],
3646
3646
  fullAddress: getEncodeFullAddress,
3647
3647
  area: area,
3648
3648
  });
3649
3649
  } else {
3650
3650
  if (typeof res === 'object') {
3651
3651
  draBusinessCustomReport({
3652
3652
  eventName: 'business',
3653
3653
  errorName: 'jdapp_getCacheAddress_info_err',
3654
3654
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
3655
3655
  extraData: JSON.stringify({
3656
3656
  isJdApp,
3657
3657
  jdAppVersion: jdAppVersionStr,
3658
3658
  ...res,
3659
3659
  }),
3660
3660
  });
3661
3661
  }
3662
3662
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
3663
3663
  }
3664
3664
  })
3665
3665
  .catch((e) => {
3666
3666
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
3667
3667
  draBusinessCustomReport({
3668
3668
  eventName: 'business',
3669
3669
  errorName: 'jdapp_getCacheAddress_info_catch_err',
3670
3670
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
3671
3671
  extraData: JSON.stringify({
3672
3672
  isJdApp,
3673
3673
  jdAppVersion: jdAppVersionStr,
3674
3674
  }),
3675
3675
  });
3676
3676
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
3677
3677
  });
3678
3678
  }
3679
3679
  });
3680
3680
  }
3681
3681
 
3682
3682
  getLbsCacheAddressRouter() {
3683
3683
  if (isJdApp) {
3684
3684
  if (!isJdAndHarmonyDevice) {
3685
3685
  return Promise.race([
3686
3686
  new Promise((resolve) => {
3687
3687
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
3688
3688
  if (!window[getCallBackName]) {
3689
3689
  window[getCallBackName] = (res) => {
3690
3690
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
3691
3691
  try {
3692
3692
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3693
3693
  resolve(getResJson);
3694
3694
  } catch (e) {
3695
3695
  resolve({
3696
3696
  status: '-1002',
3697
3697
  msg: '地址信息解析json异常',
3698
3698
  res,
3699
3699
  });
3700
3700
  }
3701
3701
  window[getCallBackName] = null;
3702
3702
  };
3703
3703
  }
3704
3704
  const getRouterParam = {
3705
3705
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
3706
3706
  sceneId: 'basicShoppingProcess',
3707
3707
  };
3708
3708
  if (isAndroidDevice) {
3709
3709
  return callRouterAndroid({
3710
3710
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
3711
3711
  routerParam: getRouterParam,
3712
3712
  callBackName: getCallBackName,
3713
3713
  isSync: true,
3714
3714
  hasJdRouter: false,
3715
3715
  });
3716
3716
  } else {
3717
3717
  return callRouterIOS({
3718
3718
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
3719
3719
  routerParam: getRouterParam,
3720
3720
  callBackName: getCallBackName,
3721
3721
  isSync: true,
3722
3722
  });
3723
3723
  }
3724
3724
  }),
3725
3725
  this.taskTimeoutPromise(() => {
3726
3726
  return {
3727
3727
  status: '-1000',
3728
3728
  msg: '原生router协议获取lbs地址信息3s超时',
3729
3729
  };
3730
3730
  }, 3000),
3731
3731
  ]);
3732
3732
  } else {
3733
3733
  return Promise.resolve({
3734
3734
  status: '-1001',
3735
3735
  msg: '鸿蒙系统调用未实现,获取失败',
3736
3736
  });
3737
3737
  }
3738
3738
  } else if (isH5AndJingGouMini) {
3739
3739
  return this.getLocationForGpsPromise();
3740
3740
  } else {
3741
3741
  return Promise.resolve({
3742
3742
  status: '-1002',
3743
3743
  msg: '普通h5暂无业务需要,未实现,获取失败',
3744
3744
  });
3745
3745
  }
3746
3746
  }
3747
3747
  getLocationForGpsPromise() {
3748
3748
  return new Promise((resolve) => {
3749
3749
  let hasGetLocationForGps = true;
3750
3750
  if (urlCookie && urlCookie['loc']) {
3751
3751
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
3752
3752
  urlCookie['loc'].split('_');
3753
3753
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3754
3754
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3755
3755
  hasGetLocationForGps = false;
3756
3756
  resolve({
3757
3757
  status: '0',
3758
3758
  data: {
3759
3759
  provinceid,
3760
3760
  cityid,
3761
3761
  districtid,
3762
3762
  townid,
3763
3763
  origin: 'wxapp',
3764
3764
  },
3765
3765
  });
3766
3766
  }
3767
3767
  }
3768
3768
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
3769
3769
  window.navigator.geolocation.getCurrentPosition(
3770
3770
  (position) => {
3771
3771
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
3772
3772
  if (position?.coords) {
3773
3773
  resolve({
3774
3774
  status: '0',
3775
3775
  data: {
3776
3776
  srclat: position.coords?.latitude,
3777
3777
  srclng: position.coords.longitude,
3778
3778
  origin: 'h5',
3779
3779
  },
3780
3780
  });
3781
3781
  } else {
3782
3782
  resolve({
3783
3783
  status: '-1001',
3784
3784
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
3785
3785
  position,
3786
3786
  });
3787
3787
  }
3788
3788
  },
3789
3789
  (error) => {
3790
3790
  resolve({
3791
3791
  status: '-1001',
3792
3792
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
3793
3793
  error,
3794
3794
  });
3795
3795
  },
3796
3796
  {
3797
3797
  enableHighAccuracy: false,
3798
3798
  timeout: 3 * 1000,
3799
3799
  maximumAge: 10 * 60 * 1000,
3800
3800
  },
3801
3801
  );
3802
3802
  } else {
3803
3803
  resolve({
3804
3804
  status: '-1001',
3805
3805
  msg: '您的浏览器不支持地理定位',
3806
3806
  });
3807
3807
  }
3808
3808
  });
3809
3809
  }
3810
3810
 
3811
3811
  createLbsCacheAddress(realTimeArea) {
3812
3812
  const getLbsAddressCacheMinuteTime = Number(
3813
3813
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
3814
3814
  );
3815
3815
  console.log(
3816
3816
  '获取lbs缓存到cookie的时间,分钟',
3817
3817
  getLbsAddressCacheMinuteTime,
3818
3818
  'lbsAddressCacheToCookieMinuteTime',
3819
3819
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
3820
3820
  );
3821
3821
  if (getLbsAddressCacheMinuteTime > 0) {
3822
3822
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
3823
3823
  realTimeArea &&
3824
3824
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
3825
3825
  path: '/',
3826
3826
  expires,
3827
3827
  });
3828
3828
  }
3829
3829
  }
3830
3830
 
3831
3831
  getLbsAddressCachePromise() {
3832
3832
  if (!this.lbsAddressCachePromise) {
3833
3833
  this.lbsAddressCachePromise = new Promise((resolve) => {
3834
3834
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
3835
3835
  ? cookie.get(cacheH5LbsAddressKey)
3836
3836
  : '';
3837
3837
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
3838
3838
  if (getUserLbsAddress && getUserLbsAddress !== '') {
3839
3839
  resolve({
3840
3840
  ok: true,
3841
3841
  realTimeArea: getUserLbsAddress,
3842
3842
  });
3843
3843
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
3844
3844
  console.info(
3845
3845
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
3846
3846
  getCookieForLbsAddress,
3847
3847
  );
3848
3848
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
3849
3849
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
3850
3850
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3851
3851
  realTimeArea: getCookieForLbsAddress,
3852
3852
  });
3853
3853
  resolve({
3854
3854
  ok: true,
3855
3855
  realTimeArea: getCookieForLbsAddress,
3856
3856
  });
3857
3857
  } else {
3858
3858
  this.getLbsCacheAddressRouter()
3859
3859
  .then((res) => {
3860
3860
  const { status, data } = res;
3861
3861
  console.log(
3862
3862
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
3863
3863
  status,
3864
3864
  data,
3865
3865
  res,
3866
3866
  );
3867
3867
  if (status === '0' && data) {
3868
3868
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
3869
3869
  data || {};
3870
3870
  let realTimeArea = '';
3871
3871
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
3872
3872
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
3873
3873
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3874
3874
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3875
3875
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
3876
3876
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
3877
3877
  this.info.sysInfo['realTimeArea'] = realTimeArea;
3878
3878
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3879
3879
  realTimeArea: this.info.pageInfo.userLbsAddress,
3880
3880
  });
3881
3881
  this.createLbsCacheAddress(realTimeArea);
3882
3882
  } else {
3883
3883
  !origin && (this.lbsAddressCachePromise = null);
3884
3884
  }
3885
3885
  const getValidRealTimeArea = realTimeArea !== '';
3886
3886
  resolve({
3887
3887
  lat: this.info.sysInfo['srclat'],
3888
3888
  lng: this.info.sysInfo['srclng'],
3889
3889
  realTimeArea: realTimeArea,
3890
3890
  ok: getValidRealTimeArea,
3891
3891
  msg: getValidRealTimeArea
3892
3892
  ? '成功'
3893
3893
  : origin
3894
3894
  ? origin
3895
3895
  : '根据router底层获取lbs地址信息异常,详情见data',
3896
3896
  data: getValidRealTimeArea ? null : res,
3897
3897
  });
3898
3898
  if (!getValidRealTimeArea && !origin) {
3899
3899
  draBusinessCustomReport({
3900
3900
  eventName: 'business',
3901
3901
  errorName: 'h5_getLbsCacheAddress_info_err',
3902
3902
  errorMessage:
3903
3903
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
3904
3904
  extraData: JSON.stringify({
3905
3905
  isJdApp,
3906
3906
  jdAppVersion: jdAppVersionStr,
3907
3907
  }),
3908
3908
  });
3909
3909
  }
3910
3910
  } else {
3911
3911
  typeof res === 'object' &&
3912
3912
  draBusinessCustomReport({
3913
3913
  eventName: 'business',
3914
3914
  errorName: 'h5_getLbsCacheAddress_info_err',
3915
3915
  errorMessage:
3916
3916
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
3917
3917
  extraData: JSON.stringify({
3918
3918
  isJdApp,
3919
3919
  jdAppVersion: jdAppVersionStr,
3920
3920
  ...res,
3921
3921
  }),
3922
3922
  });
3923
3923
  this.lbsAddressCachePromise = null;
3924
3924
  resolve({ realTimeArea: '', ok: false });
3925
3925
  }
3926
3926
  })
3927
3927
  .catch((e) => {
3928
3928
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
3929
3929
  this.lbsAddressCachePromise = null;
3930
3930
  draBusinessCustomReport({
3931
3931
  eventName: 'business',
3932
3932
  errorName: 'h5_getLbsCacheAddress_info_err',
3933
3933
  errorMessage:
3934
3934
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
3935
3935
  extraData: JSON.stringify({
3936
3936
  isJdApp,
3937
3937
  jdAppVersion: jdAppVersionStr,
3938
3938
  }),
3939
3939
  });
3940
3940
  resolve({ realTimeArea: '', ok: false });
3941
3941
  });
3942
3942
  }
3943
3943
  });
3944
3944
  }
3945
3945
  return this.lbsAddressCachePromise;
3946
3946
  }
3947
3947
 
3948
3948
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
3949
3949
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
3950
3950
  if (!isJdApp) {
3951
3951
  return;
3952
3952
  }
3953
3953
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
3954
3954
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
3955
3955
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
3956
3956
  'hybridHttpSwitch',
3957
3957
  isBeforePageReady,
3958
3958
  );
3959
3959
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
3960
3960
  'jshopIsVipShop',
3961
3961
  isBeforePageReady,
3962
3962
  );
3963
3963
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
3964
3964
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
3965
3965
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
3966
3966
  'isFollowAppVideoPlayStatus',
3967
3967
  isBeforePageReady,
3968
3968
  );
3969
3969
  console.log(
3970
3970
  'isBeforePageReady:',
3971
3971
  isBeforePageReady,
3972
3972
  'isFollowAppVideoPlayStatus:',
3973
3973
  isFollowAppVideoPlayStatus,
3974
3974
  );
3975
3975
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
3976
3976
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
3977
3977
  }
3978
3978
  }
3979
3979
 
3980
3980
  async getWifiVideoAutoPlayAsync() {
3981
3981
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
3982
3982
  if (!isJdApp) {
3983
3983
  return;
3984
3984
  }
3985
3985
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
3986
3986
  return 0;
3987
3987
  });
3988
3988
  if (Number(videoPlayStatus) === 1) {
3989
3989
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
3990
3990
  }
3991
3991
  }
3992
3992
 
3993
3993
  async getMPaasConfigAsync() {
3994
3994
  this.info.sysInfo.dynamicConfig = {};
3995
3995
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
3996
3996
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
3997
3997
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
3998
3998
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
3999
3999
  return this.updateMPaasConfigAsync(true);
4000
4000
  }
4001
4001
 
4002
4002
  getDynamicConfig(key: string) {
4003
4003
  return this.info.sysInfo?.dynamicConfig?.[key];
4004
4004
  }
4005
4005
  async updateMPaasConfig() {
4006
4006
  console.log('updateMPaasConfig');
4007
4007
  if (
4008
4008
  isIosDevice &&
4009
4009
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
4010
4010
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
4011
4011
  ) {
4012
4012
  try {
4013
4013
  await this.updateMPaasConfigAsync(false);
4014
4014
  } catch (e) {
4015
4015
  console.log('updateMPaasConfigAsync:', e);
4016
4016
  }
4017
4017
  }
4018
4018
  }
4019
4019
 
4020
4020
  toLogin(options) {
4021
4021
  if (isAscfApp) {
4022
4022
  return this.toAscfAppLogin(options);
4023
4023
  }
4024
4024
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
4025
4025
  ? this.toWxAppLogin(options)
4026
4026
  : this.toWebLogin(options);
4027
4027
  }
4028
4028
 
4029
4029
  doLogin(options) {
4030
4030
  return this.toLogin(options);
4031
4031
  }
4032
4032
 
4033
4033
  doLoginForJdPin(options = {}) {
4034
4034
  return this.doLogin({
4035
4035
  loginColor: {
4036
4036
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
4037
4037
  dpin: 0,
4038
4038
  },
4039
4039
  ...options,
4040
4040
  });
4041
4041
  }
4042
4042
 
4043
4043
  toWebLogin(options) {
4044
4044
  let params: {
4045
4045
  returnurl: string;
4046
4046
  } = {
4047
4047
  returnurl: '',
4048
4048
  };
4049
4049
  const checkToPcLogin = options ? options?.isPc : isPc;
4050
4050
  const loginUrl = checkToPcLogin
4051
4051
  ? `//passport.jd.com/new/login.aspx`
4052
4052
  : `${domain.mobileLogin}/user/login.action`;
4053
4053
  const defaultParams = {
4054
4054
  appid: /\.jd\.hk/.test(window.location.hostname) ? '233' : '100',
4055
4055
  returnurl: window.location.href,
4056
4056
  };
4057
4057
  if (isString(options)) {
4058
4058
  params = Object.assign({}, defaultParams, {
4059
4059
  returnurl: options,
4060
4060
  });
4061
4061
  } else if (isObject(options)) {
4062
4062
  const { loginColor, ...otherOptions } = options;
4063
4063
  params = Object.assign({}, defaultParams, otherOptions);
4064
4064
  } else {
4065
4065
  params = defaultParams;
4066
4066
  }
4067
4067
  params.returnurl = encodeURIComponent(params.returnurl);
4068
4068
  let getFullUrl = loginUrl + '?' + serialize(params);
4069
4069
  if (checkToPcLogin) {
4070
4070
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
4071
4071
  }
4072
4072
  return Promise.resolve({
4073
4073
  h5ToUrl: true,
4074
4074
  url: getFullUrl,
4075
4075
  }).then(() => {
4076
4076
  window.location.href = getFullUrl;
4077
4077
  });
4078
4078
  }
4079
4079
 
4080
4080
  toAscfAppLogin(options = {}) {
4081
4081
  console.log('华为元服务中h5登录跳转', options);
4082
4082
  return Promise.resolve(true).then(() => {
4083
4083
  const returnPage = encodeURIComponent(window.location.href);
4084
4084
  if (has && has.ascfweb) {
4085
4085
  has.ascfweb.redirectTo({
4086
4086
  url: `/pages/login/index/index?isH5=1&returnPage=${returnPage}&pageType=h5&source=shopx`,
4087
4087
  });
4088
4088
  }
4089
4089
  });
4090
4090
  }
4091
4091
 
4092
4092
  toWxAppLogin(options = {}) {
4093
4093
  console.log('微信京购小程序中h5登录跳转', options);
4094
4094
  return Promise.resolve(true).then(() => {
4095
4095
  const { loginColor } = Object.assign(
4096
4096
  {},
4097
4097
  {
4098
4098
  loginColor: {
4099
4099
  biz: WXAPP_BIZ_KEY,
4100
4100
  dpin: 1,
4101
4101
  },
4102
4102
  },
4103
4103
  options,
4104
4104
  );
4105
4105
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
4106
4106
  loginColor.biz
4107
4107
  }&url=${encodeURIComponent(window.location.href)}`;
4108
4108
  });
4109
4109
  }
4110
4110
 
4111
4111
  getLoginCookie() {
4112
4112
  return Promise.resolve({
4113
4113
  pin: cookie.get('pin') || '',
4114
4114
  });
4115
4115
  }
4116
4116
 
4117
4117
  clearLoginCookie() {
4118
4118
  cookie.remove('pin');
4119
4119
  }
4120
4120
 
4121
4121
  checkStatusAndLogin(options = {}) {
4122
4122
  if (!this.checkStatusAndLoginPromise) {
4123
4123
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
4124
4124
  try {
4125
4125
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
4126
4126
  if (getLoginState) {
4127
4127
  resolve(true);
4128
4128
  } else {
4129
4129
  this.toLogin(options);
4130
4130
  reject(false);
4131
4131
  }
4132
4132
  } catch (e) {
4133
4133
  this.toLogin(options);
4134
4134
  reject(false);
4135
4135
  }
4136
4136
  });
4137
4137
  return this.checkStatusAndLoginPromise;
4138
4138
  } else {
4139
4139
  return this.checkStatusAndLoginPromise
4140
4140
  .then(() => {
4141
4141
  return Promise.resolve(true);
4142
4142
  })
4143
4143
  .catch(() => {
4144
4144
  this.toLogin(options);
4145
4145
  return Promise.reject(true);
4146
4146
  });
4147
4147
  }
4148
4148
  }
4149
4149
 
4150
4150
  checkJdStatusAndLogin(
4151
4151
  options = {
4152
4152
  loginColor: {
4153
4153
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
4154
4154
  dpin: 0,
4155
4155
  },
4156
4156
  },
4157
4157
  ) {
4158
4158
  return this.checkStatusAndLogin(options);
4159
4159
  }
4160
4160
 
4161
4161
  doCheckLoginStateAndForApiCheck(options) {
4162
4162
  if (this.info.loginState) {
4163
4163
  return Promise.resolve(true);
4164
4164
  } else {
4165
4165
  return new Promise((resolve, reject) => {
4166
4166
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
4167
4167
  const getWqAuthToken = cookie.get('wq_auth_token');
4168
4168
  const getWqSkey = cookie.get('wq_skey');
4169
4169
  const getWqUin = cookie.get('wq_uin');
4170
4170
  const isLoginState =
4171
4171
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
4172
4172
  if (isLoginState) {
4173
4173
  this.info.loginState = true;
4174
4174
  resolve(true);
4175
4175
  } else {
4176
4176
  reject(false);
4177
4177
  }
4178
4178
  } else {
4179
4179
  Taro.request({
4180
4180
  url: api.isLogin,
4181
4181
  jsonp: true,
4182
4182
  timeout: 3000,
4183
4183
  success: (res) => {
4184
4184
  const { statusCode, data } = res;
4185
4185
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
4186
4186
  this.info.loginState = true;
4187
4187
  resolve(true);
4188
4188
  } else {
4189
4189
  reject(false);
4190
4190
  }
4191
4191
  },
4192
4192
  fail: (err) => {
4193
4193
  console.log('登录检查异常', err);
4194
4194
  reject(false);
4195
4195
  },
4196
4196
  });
4197
4197
  }
4198
4198
  });
4199
4199
  }
4200
4200
  }
4201
4201
 
4202
4202
  checkLoginStatus(options) {
4203
4203
  return new Promise(async (resolve, reject) => {
4204
4204
  try {
4205
4205
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
4206
4206
  if (getLoginState) {
4207
4207
  const { pin } = await this.getLoginCookie();
4208
4208
  this.info.userInfo = {
4209
4209
  pin,
4210
4210
  encodePin: encodeURIComponent(pin),
4211
4211
  ptkey: '',
4212
4212
  };
4213
4213
  resolve(true);
4214
4214
  } else {
4215
4215
  reject(false);
4216
4216
  }
4217
4217
  } catch (e) {
4218
4218
  reject(false);
4219
4219
  }
4220
4220
  });
4221
4221
  }
4222
4222
 
4223
4223
  updatePageAndLogInfo(updateQuery = {}) {
4224
4224
  const createUpdateQueryInfo: {
4225
4225
  query: {
4226
4226
  shopId?: string | number;
4227
4227
  venderId?: string | number;
4228
4228
  };
4229
4229
  updateShopInfoState: boolean;
4230
4230
  } = Object.assign(
4231
4231
  {},
4232
4232
  {
4233
4233
  query: {},
4234
4234
  updateShopInfoState: false,
4235
4235
  },
4236
4236
  updateQuery,
4237
4237
  );
4238
4238
  console.log(
4239
4239
  '获取当前下发的店铺查询参数',
4240
4240
  updateQuery,
4241
4241
  '获取之前保存的shopInfo店铺查询参数',
4242
4242
  this.info?.shopInfo,
4243
4243
  );
4244
4244
  const { query, updateShopInfoState } = createUpdateQueryInfo;
4245
4245
  const { shopId, venderId, un_area } = query;
4246
4246
  if (updateShopInfoState) {
4247
4247
  this.info.queryInfo = {
4248
4248
  ...this.info.queryInfo,
4249
4249
  ...query,
4250
4250
  };
4251
4251
  if (shopId && venderId) {
4252
4252
  this.info.shopInfo = {
4253
4253
  shopId: `${shopId}`,
4254
4254
  venderId: `${venderId}`,
4255
4255
  };
4256
4256
  }
4257
4257
  } else {
4258
4258
  this.info.queryInfo = {
4259
4259
  ...query,
4260
4260
  };
4261
4261
  if (
4262
4262
  this.info.shopInfo?.shopId &&
4263
4263
  this.info.shopInfo?.venderId &&
4264
4264
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
4265
4265
  ) {
4266
4266
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
4267
4267
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
4268
4268
  console.log(
4269
4269
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
4270
4270
  this.info.queryInfo,
4271
4271
  );
4272
4272
  }
4273
4273
  }
4274
4274
  this.info.queryInfo['shopId'] &&
4275
4275
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
4276
4276
  this.info.queryInfo['venderId'] &&
4277
4277
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
4278
4278
  console.log(
4279
4279
  'h5==获取店铺下发查询参数\n',
4280
4280
  query,
4281
4281
  '\n获取店铺最后查询参数\n',
4282
4282
  this.info.queryInfo,
4283
4283
  '\n是否为更新店铺状态\n',
4284
4284
  updateShopInfoState,
4285
4285
  );
4286
4286
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
4287
4287
  if (changeArea) {
4288
4288
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
4289
4289
  this.info.pageInfo.address = getBottomAreaStr;
4290
4290
  this.info.pageInfo.un_area = getBottomAreaStr;
4291
4291
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
4292
4292
  }
4293
4293
  }
4294
4294
 
4295
4295
  dealLoadSdkList() {
4296
4296
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
4297
4297
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
4298
4298
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
4299
4299
  let mergeLoadJsList = globalLoadJsList;
4300
4300
  try {
4301
4301
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
4302
4302
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
4303
4303
  getFindIndex !== -1
4304
4304
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
4305
4305
  : accArr.push(current);
4306
4306
  return accArr;
4307
4307
  }, []);
4308
4308
  } catch (e) {
4309
4309
  console.log('LoadJsList合并错误', e);
4310
4310
  }
4311
4311
  console.log(
4312
4312
  'globalLoadJsList',
4313
4313
  globalLoadJsList,
4314
4314
  'businessLoadJsList',
4315
4315
  businessLoadJsList,
4316
4316
  '两个加载jsList集合合并完成',
4317
4317
  mergeLoadJsList,
4318
4318
  );
4319
4319
  this.loadJsSdkList = mergeLoadJsList;
4320
4320
  return this.loadJsSdkList;
4321
4321
  }
4322
4322
 
4323
4323
  renderNextTickLoadSdk(delayTime = 1000, callback) {
4324
4324
  Taro.nextTick(() => {
4325
4325
  console.log(
4326
4326
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
4327
4327
  );
4328
4328
  setTimeout(() => {
4329
4329
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
4330
4330
  typeof callback === 'function' && callback();
4331
4331
  }, delayTime);
4332
4332
  });
4333
4333
  }
4334
4334
 
4335
4335
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
4336
4336
  const getLoadJsList =
4337
4337
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
4338
4338
  const getLoadFilterList = getLoadJsList.filter((item) => {
4339
4339
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
4340
4340
  item.initLoadType = undefined;
4341
4341
  }
4342
4342
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
4343
4343
  let getLoastLoadEventState = true;
4344
4344
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
4345
4345
  getLoastLoadEventState = isJdApp;
4346
4346
  }
4347
4347
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
4348
4348
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
4349
4349
  }
4350
4350
  const getInitTriggerType =
4351
4351
  isJdApp && item?.initJdAppTriggerType
4352
4352
  ? item?.initJdAppTriggerType
4353
4353
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
4354
4354
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
4355
4355
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
4356
4356
  });
4357
4357
  console.log(
4358
4358
  '获取当前触发方式',
4359
4359
  triggerType,
4360
4360
  '获取当前最后加载的js集合',
4361
4361
  getLoadFilterList,
4362
4362
  '过滤前的加载集合',
4363
4363
  getLoadJsList,
4364
4364
  );
4365
4365
  const loadTasks =
4366
4366
  getLoadFilterList.length > 0
4367
4367
  ? getLoadFilterList.map((item) => {
4368
4368
  const isLoadState = /sgm/.test(item?.fileName)
4369
4369
  ? window?.shopGlobalSwitch?.openSgm === 'true'
4370
4370
  : true;
4371
4371
  if (!isLoadState) {
4372
4372
  return Promise.resolve(true);
4373
4373
  }
4374
4374
  return this.loadItemSdkPromise(item)
4375
4375
  .then((res) => {
4376
4376
  console.info('当前js地址' + item?.src, '加载状态', res);
4377
4377
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
4378
4378
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
4379
4379
  const getNewdraEnableShopIdPercentObj =
4380
4380
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || null;
4381
4381
  const getNewdraEnableVenderIdPercentObj =
4382
4382
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || null;
4383
4383
  let canInitDraRun = true;
4384
4384
  if (getNewdraEnableShopIdPercentObj || getNewdraEnableVenderIdPercentObj) {
4385
4385
  canInitDraRun = this.shouldPercentExecuteNewDra(
4386
4386
  this.getNewDraEnablePercentNum(),
4387
4387
  );
4388
4388
  }
4389
4389
  if (canInitDraRun) {
4390
4390
  window.dra.run('init', { aid: res?.aid });
4391
4391
  window.dra.run('start');
4392
4392
  }
4393
4393
  }
4394
4394
  return true;
4395
4395
  })
4396
4396
  .catch((err) => {
4397
4397
  console.info('当前js地址加载异常', item?.src);
4398
4398
  window?.fetchErrorData &&
4399
4399
  window.fetchErrorData({
4400
4400
  title: '公共js加载异常',
4401
4401
  type: 'jsLoad',
4402
4402
  data: err,
4403
4403
  });
4404
4404
  return true;
4405
4405
  });
4406
4406
  })
4407
4407
  : [];
4408
4408
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
4409
4409
  }
4410
4410
 
4411
4411
  shouldPercentExecuteNewDra(percent) {
4412
4412
  if (percent <= 0) return false;
4413
4413
  if (percent >= 100) return true;
4414
4414
  const getRes = Math.random() < percent / 100;
4415
4415
  console.log('获取dra初始化执行的概率为', percent, '执行结果', getRes);
4416
4416
  return getRes;
4417
4417
  }
4418
4418
 
4419
4419
  getNewDraEnablePercentNum() {
4420
4420
  const getNewdraEnableShopIdPercent =
4421
4421
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || {};
4422
4422
  const getNewdraEnableVenderIdPercent =
4423
4423
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || {};
4424
4424
  const getShopId = parseQueryUrlObj?.shopId || '';
4425
4425
  const getVenderId = parseQueryUrlObj?.venderId || '';
4426
4426
  const getShopIdDraEnablePercent = getNewdraEnableShopIdPercent[getShopId]
4427
4427
  ? getNewdraEnableShopIdPercent[getShopId]
4428
4428
  : getNewdraEnableShopIdPercent?.ids?.includes(getShopId)
4429
4429
  ? getNewdraEnableShopIdPercent?.idsNumber
4430
4430
  : -1;
4431
4431
  const getVenderIdDraEnablePercent = getNewdraEnableVenderIdPercent[getVenderId]
4432
4432
  ? getNewdraEnableVenderIdPercent[getVenderId]
4433
4433
  : getNewdraEnableVenderIdPercent?.ids?.includes(getVenderId)
4434
4434
  ? getNewdraEnableVenderIdPercent?.idsNumber
4435
4435
  : -1;
4436
4436
  if (getShopIdDraEnablePercent > -1 || getVenderIdDraEnablePercent > -1) {
4437
4437
  return getShopIdDraEnablePercent || getVenderIdDraEnablePercent;
4438
4438
  }
4439
4439
  return 100;
4440
4440
  }
4441
4441
  loadScriptEle(jsInfo, resolve, reject) {
4442
4442
  const getFileName = jsInfo?.fileName;
4443
4443
  if (getFileName) {
4444
4444
  const getEleId = `J_loadJs_${getFileName}`;
4445
4445
  const getEle = document.getElementById(getEleId);
4446
4446
  if (!getEle) {
4447
4447
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4448
4448
  const _sgmEle = document.createElement('script');
4449
4449
  _sgmEle.id = getEleId;
4450
4450
  _sgmEle.onload = function () {
4451
4451
  resolve({
4452
4452
  ...jsInfo,
4453
4453
  jsTip: 'js加载成功',
4454
4454
  });
4455
4455
  };
4456
4456
  _sgmEle.onerror = function () {
4457
4457
  reject({
4458
4458
  ...jsInfo,
4459
4459
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4460
4460
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
4461
4461
  });
4462
4462
  };
4463
4463
  const dataAttrList = ['timeout', 'fileName', 'env'];
4464
4464
  const getJsInfoKeyList = Object.keys(jsInfo);
4465
4465
  getJsInfoKeyList.forEach((key) => {
4466
4466
  if (key === 'async') {
4467
4467
  _sgmEle.async = jsInfo[key];
4468
4468
  } else if (key === 'crossOrigin') {
4469
4469
  _sgmEle.crossOrigin = jsInfo[key];
4470
4470
  } else if (key === 'src') {
4471
4471
  _sgmEle.src = `${jsInfo[key]}`;
4472
4472
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
4473
4473
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
4474
4474
  } else {
4475
4475
  _sgmEle.setAttribute(key, jsInfo[key]);
4476
4476
  }
4477
4477
  });
4478
4478
  document.head.appendChild(_sgmEle);
4479
4479
  } else {
4480
4480
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
4481
4481
  resolve({
4482
4482
  ...jsInfo,
4483
4483
  jsTip: 'js本身已存在页面中',
4484
4484
  });
4485
4485
  }
4486
4486
  } else {
4487
4487
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
4488
4488
  }
4489
4489
  }
4490
4490
 
4491
4491
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
4492
4492
  if (jsInfo?.src) {
4493
4493
  const getInitLoadType =
4494
4494
  isJdApp && jsInfo?.initJdAppLoadType
4495
4495
  ? jsInfo?.initJdAppLoadType
4496
4496
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
4497
4497
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
4498
4498
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
4499
4499
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
4500
4500
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
4501
4501
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4502
4502
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4503
4503
  try {
4504
4504
  const jsXhrRequest = new XMLHttpRequest();
4505
4505
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
4506
4506
  const jsUrl = `${jsInfo?.src}`;
4507
4507
  jsXhrRequest.open('GET', jsUrl, true);
4508
4508
  jsXhrRequest.onreadystatechange = () => {
4509
4509
  if (jsXhrRequest.readyState === 4) {
4510
4510
  const getReqStatus = jsXhrRequest.status;
4511
4511
  const statusText = jsXhrRequest.statusText;
4512
4512
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4513
4513
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
4514
4514
  if (getInsetHeadState) {
4515
4515
  this.loadScriptEle(jsInfo, resolve, reject);
4516
4516
  } else {
4517
4517
  resolve({
4518
4518
  ...jsInfo,
4519
4519
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
4520
4520
  });
4521
4521
  }
4522
4522
  getReqStatus !== 200 &&
4523
4523
  draBusinessCustomReport({
4524
4524
  eventName: 'business',
4525
4525
  errorName: 'js_load_special_code',
4526
4526
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
4527
4527
  extraData: JSON.stringify({
4528
4528
  msg: '当前js加载成功,状态非200,特殊上报观察',
4529
4529
  jsReqState: getReqStatus,
4530
4530
  env: getSgmCustomCode('js_load_special_code'),
4531
4531
  data: jsInfo,
4532
4532
  }),
4533
4533
  });
4534
4534
  } else {
4535
4535
  const getRes = {
4536
4536
  ...jsInfo,
4537
4537
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4538
4538
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4539
4539
  jsReqState: getReqStatus,
4540
4540
  };
4541
4541
  console.log('当前js请求状态异常,具体信息见', getRes);
4542
4542
  reject(getRes);
4543
4543
  }
4544
4544
  }
4545
4545
  };
4546
4546
  jsXhrRequest.onerror = () => {
4547
4547
  const getRes = {
4548
4548
  ...jsInfo,
4549
4549
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4550
4550
  jsReqError: '请求错误',
4551
4551
  };
4552
4552
  console.log('当前js请求错误', getRes);
4553
4553
  jsXhrRequest.abort();
4554
4554
  reject(getRes);
4555
4555
  };
4556
4556
  jsXhrRequest.ontimeout = () => {
4557
4557
  const getRes = {
4558
4558
  ...jsInfo,
4559
4559
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4560
4560
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
4561
4561
  jsReqState: jsXhrRequest.status,
4562
4562
  };
4563
4563
  console.log('当前js请求超时异常', getRes);
4564
4564
  jsXhrRequest.abort();
4565
4565
  reject(getRes);
4566
4566
  };
4567
4567
  jsXhrRequest.send();
4568
4568
  } catch (e) {
4569
4569
  console.log('执行js请求异常', e);
4570
4570
  reject({
4571
4571
  ...jsInfo,
4572
4572
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4573
4573
  jsReqError: '未知异常',
4574
4574
  error: e,
4575
4575
  });
4576
4576
  }
4577
4577
  });
4578
4578
  } else {
4579
4579
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4580
4580
  return this.loadScriptEle(jsInfo, resolve, reject);
4581
4581
  });
4582
4582
  }
4583
4583
  }
4584
4584
  return this.loadJsSdkListCachePromise[getFileKeyName];
4585
4585
  } else {
4586
4586
  return Promise.resolve({
4587
4587
  ...jsInfo,
4588
4588
  jsTip: 'js加载方式设置为不加载,当前不做处理',
4589
4589
  });
4590
4590
  }
4591
4591
  } else {
4592
4592
  return Promise.reject(jsInfo);
4593
4593
  }
4594
4594
  }
4595
4595
 
4596
4596
  createLanguagePromise() {
4597
4597
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
4598
4598
  if (!this.languageCacheProimse) {
4599
4599
  this.languageCacheProimse = new Promise((resolve, reject) => {
4600
4600
  const { fileName, prefixUrl } = getLanguageConfig;
4601
4601
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
4602
4602
  const dealLanguageFile = () => {
4603
4603
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
4604
4604
  .then((res: any) => {
4605
4605
  if (res && res?.data) {
4606
4606
  this.languageJsonData = res.data;
4607
4607
 
4608
4608
  setTimeout(() => {
4609
4609
  const getOtherLanguageList = languageTypeList.filter(
4610
4610
  (item) => item !== languageNowType,
4611
4611
  );
4612
4612
  getOtherLanguageList.length > 0 &&
4613
4613
  getOtherLanguageList.map((languageTypeKey) => {
4614
4614
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
4615
4615
  });
4616
4616
  }, 3000);
4617
4617
  resolve(res);
4618
4618
  } else {
4619
4619
  reject(res);
4620
4620
  }
4621
4621
  })
4622
4622
  .catch((err) => {
4623
4623
  reject(err);
4624
4624
  });
4625
4625
  };
4626
4626
  if (fileName && prefixUrl) {
4627
4627
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
4628
4628
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
4629
4629
  if (getLocalLangRes) {
4630
4630
  try {
4631
4631
  const getLocalLangJsonData =
4632
4632
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
4633
4633
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
4634
4634
  if (getLocalLangJsonData?.fileName === fileName) {
4635
4635
  const geThisLangData = getLocalLangJsonData.data;
4636
4636
  this.languageJsonData = geThisLangData;
4637
4637
  return resolve({
4638
4638
  ...getLanguageConfig,
4639
4639
  languageNowType,
4640
4640
  data: geThisLangData,
4641
4641
  });
4642
4642
  } else {
4643
4643
  dealLanguageFile();
4644
4644
  }
4645
4645
  } else {
4646
4646
  dealLanguageFile();
4647
4647
  }
4648
4648
  } catch (e) {
4649
4649
  return reject({
4650
4650
  languageNowType,
4651
4651
  msg: '转换错误',
4652
4652
  ...getLanguageConfig,
4653
4653
  });
4654
4654
  }
4655
4655
  } else {
4656
4656
  dealLanguageFile();
4657
4657
  }
4658
4658
  } else {
4659
4659
  return reject({
4660
4660
  languageNowType,
4661
4661
  msg: '文件对象下发异常',
4662
4662
  ...getLanguageConfig,
4663
4663
  });
4664
4664
  }
4665
4665
  });
4666
4666
  }
4667
4667
  return this.languageCacheProimse;
4668
4668
  }
4669
4669
 
4670
4670
  getLanguageFilePromise(info, languageTypeKey) {
4671
4671
  const { fileName, prefixUrl, timeout } = info || {};
4672
4672
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
4673
4673
  return new Promise((resolve, reject) => {
4674
4674
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
4675
4675
  try {
4676
4676
  const langXhrRequest = new XMLHttpRequest();
4677
4677
  langXhrRequest.timeout = timeout || 2000;
4678
4678
  langXhrRequest.open('GET', getUrl, true);
4679
4679
  langXhrRequest.responseType = 'json';
4680
4680
  langXhrRequest.onreadystatechange = () => {
4681
4681
  if (langXhrRequest.readyState === 4) {
4682
4682
  const getReqStatus = langXhrRequest.status;
4683
4683
  const statusText = langXhrRequest.statusText;
4684
4684
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4685
4685
  const getData = langXhrRequest?.response || false;
4686
4686
  if (getData) {
4687
4687
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
4688
4688
  fileName,
4689
4689
  data: getData,
4690
4690
  });
4691
4691
  resolve({
4692
4692
  ...info,
4693
4693
  languageTypeKey,
4694
4694
  data: getData,
4695
4695
  });
4696
4696
  } else {
4697
4697
  reject({
4698
4698
  ...info,
4699
4699
  languageTypeKey,
4700
4700
  msg: '数据获取异常',
4701
4701
  });
4702
4702
  }
4703
4703
  } else {
4704
4704
  const getRes = {
4705
4705
  ...info,
4706
4706
  languageTypeKey,
4707
4707
  env: getSgmCustomCode(langLoadErrorSgmCode),
4708
4708
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4709
4709
  };
4710
4710
  console.log('当前lang请求状态异常,具体信息见', getRes);
4711
4711
  reject(getRes);
4712
4712
  }
4713
4713
  }
4714
4714
  };
4715
4715
  langXhrRequest.onerror = () => {
4716
4716
  const getRes = {
4717
4717
  ...info,
4718
4718
  env: getSgmCustomCode(langLoadErrorSgmCode),
4719
4719
  msg: '请求错误',
4720
4720
  };
4721
4721
  console.log('当前lang请求错误', getRes);
4722
4722
  langXhrRequest.abort();
4723
4723
  reject(getRes);
4724
4724
  };
4725
4725
  langXhrRequest.ontimeout = () => {
4726
4726
  const getRes = {
4727
4727
  ...info,
4728
4728
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
4729
4729
  };
4730
4730
  console.log('执行lang多语言请求超时异常', getRes);
4731
4731
  langXhrRequest.abort();
4732
4732
  reject(getRes);
4733
4733
  };
4734
4734
  langXhrRequest.send();
4735
4735
  } catch (e) {
4736
4736
  console.log('执行lang多语言请求异常', e);
4737
4737
  reject({
4738
4738
  ...info,
4739
4739
  env: getSgmCustomCode(langLoadErrorSgmCode),
4740
4740
  msg: '未知异常',
4741
4741
  error: e,
4742
4742
  });
4743
4743
  }
4744
4744
  });
4745
4745
  }