@conecli/cone-render 0.10.1-shop-beta.63 → 0.10.1-shop-beta.65

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