@conecli/cone-render 0.10.1-shop3.105 → 0.10.1-shop3.107

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