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

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