@conecli/cone-render 0.10.1-shop3.76 → 0.10.1-shop3.77

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