@conecli/cone-render 0.10.1-shop3.114 → 0.10.1-shop3.116

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