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

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: !window?.shopGlobalSwitch?.disableImmersive && isJdApp && window.location?.search.includes("immersive=1"),
2122
2122
  isJingGouMiniViewState: false,
2123
2123
  isJingxiMiniViewState: false,
2124
2124
  baseAddCartSwitch: true,
2125
2125
  pageInfo: {
2126
2126
  wxBusinessType: WX_BUSINESS_TYPE.NO,
2127
2127
  address: '',
2128
2128
  addressCommaStr: '',
2129
2129
  un_area: '',
2130
2130
  userLbsAddress: '',
2131
2131
  vapptype: '1',
2132
2132
  pageType: 'home',
2133
2133
  isExposureState: false,
2134
2134
  moduleId: '',
2135
2135
  entrance: '',
2136
2136
  dataType: BUSINESS_TYPE.ONLINE,
2137
2137
  floorExposureInfo: {},
2138
2138
  floorVideInfo: {},
2139
2139
  productVideInfo: {},
2140
2140
  tabsLoadAllDataInfo: {
2141
2141
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
2142
2142
  },
2143
2143
  updateShopInfosAllState: false,
2144
2144
  isVipShop: false,
2145
2145
  isJdShowNativeImmersivePlayer: false,
2146
2146
  isSuperBrandShop: false,
2147
2147
  ...shopConfig,
2148
2148
  pageScrollTop: 0,
2149
2149
  pageIdxHeightInfo: {
2150
2150
  list: [],
2151
2151
  },
2152
2152
  shopNavBarHeight: 0,
2153
2153
  },
2154
2154
  defaultQueryLogInfo: {
2155
2155
  sourceType: 'JDshop',
2156
2156
  sourceValue: '',
2157
2157
  moduleId: 'none',
2158
2158
  entrance: 'none',
2159
2159
  },
2160
2160
  sysInfo: {
2161
2161
  windowWidth: isPc ? 375 : 0,
2162
2162
  containerWidth: isPc ? 375 : 0,
2163
2163
  windowHeight: 0,
2164
2164
  netWorkType: '4g',
2165
2165
  jdBottomBarHeight: 0,
2166
2166
  jdNativeHeaderHeight: 0,
2167
2167
  isJdTabletDevice: false,
2168
2168
  isJdTabletLandscape: false,
2169
2169
  },
2170
2170
  queryInfo: {},
2171
2171
  shopInfo: {},
2172
2172
  openAppData: {},
2173
2173
  public info: CommonInterFace.BaseConfigInfo;
2174
2174
  public config: {
2175
2175
  [key: string]: any;
2176
2176
  };
2177
2177
  public lazyContainer: CommonInterFace.lazyContainer;
2178
2178
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
2179
2179
  public rootEleNode: HTMLElement | null;
2180
2180
  public checkStatusAndLoginPromise: object | null;
2181
2181
  private jmfeRegisterStatePromise: Promise<any> | null;
2182
2182
  private jdScreenSizeInfoPromise: Promise<any> | null;
2183
2183
  private rootEleWidthRegisterPromise: Promise<any> | null;
2184
2184
  private loadJsH5tagStatePromise: Promise<any> | null;
2185
2185
  private loadJsApiRequestStatePromise: Promise<any> | null;
2186
2186
  private jmfeRegisterState: boolean;
2187
2187
  public loadJsSdkList: {
2188
2188
  src: string;
2189
2189
  timeout: number;
2190
2190
  fileName: string;
2191
2191
  initTriggerType: typeof LoadJsInitTriggerType;
2192
2192
  initLinkTriggerWay:
2193
2193
  | 'asyncLoadAppSdkJs'
2194
2194
  | 'asyncLoadHandlerJs'
2195
2195
  | 'asyncLoadReportJs'
2196
2196
  | 'asyncLoadMtkJs'
2197
2197
  | 'asyncLoadSecurityJs'
2198
2198
  | 'asyncLoadSgmJs'
2199
2199
  | 'asyncLoadCartJs'
2200
2200
  | 'asyncLoadNewDraSdkJs'
2201
2201
  | 'asyncLoadH5TagJs';
2202
2202
  initLoadEnvType: typeof LoadJsInitLoadEnvType;
2203
2203
  defer?: 'true';
2204
2204
  async?: 'true';
2205
2205
  crossOrigin: 'anonymous' | '';
2206
2206
  }[];
2207
2207
  public loadJsSdkListCachePromise: any;
2208
2208
  public rootEleInitWidth: number;
2209
2209
  public lbsAddressCachePromise: Promise<any> | null;
2210
2210
  public languageCacheProimse: Promise<any> | null;
2211
2211
  public languageJsonData: any | null;
2212
2212
  public businessWorkerReady: boolean;
2213
2213
  public businessWorkerReadyPromise: Promise<any> | null;
2214
2214
  public workerPreRequestData = new Map<string, any>();
2215
2215
  constructor(opt) {
2216
2216
  this.info = this._getConfig(opt);
2217
2217
  this.config = {};
2218
2218
  this.loadJsSdkList = [];
2219
2219
  this.loadJsSdkListCachePromise = {};
2220
2220
  this.lazyContainer = {
2221
2221
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
2222
2222
  appLazyContainerList: [],
2223
2223
  appLazyFinishContainerList: [],
2224
2224
  },
2225
2225
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
2226
2226
  appLazyContainerList: [],
2227
2227
  appLazyFinishContainerList: [],
2228
2228
  },
2229
2229
  };
2230
2230
  this.renderedIsvComponents = {};
2231
2231
  this.rootEleNode = document.querySelector('body');
2232
2232
  this.checkStatusAndLoginPromise = null;
2233
2233
  this.jmfeRegisterStatePromise = null;
2234
2234
  this.jdScreenSizeInfoPromise = null;
2235
2235
  this.rootEleWidthRegisterPromise = null;
2236
2236
  this.lbsAddressCachePromise = null;
2237
2237
  this.languageCacheProimse = null;
2238
2238
  this.businessWorkerReady = false;
2239
2239
  this.businessWorkerReadyPromise = null;
2240
2240
  this.loadJsH5tagStatePromise = null;
2241
2241
  this.loadJsApiRequestStatePromise = null;
2242
2242
  this.workerPreRequestData = new Map<string, any>();
2243
2243
  this.languageJsonData = langeJsonDataForCn;
2244
2244
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
2245
2245
  this._init();
2246
2246
  if (isJdApp) {
2247
2247
  this.jmfeReayPromise().then(() => {
2248
2248
  this.jdWorkerReadyPromise();
2249
2249
  });
2250
2250
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
2251
2251
  }
2252
2252
  }
2253
2253
  _getConfig(opt) {
2254
2254
  return Object.assign({}, DefaultConfig, opt);
2255
2255
  }
2256
2256
  _init(){
2257
2257
  this.loadOtherSdk();
2258
2258
  this.checkJdAddCartState();
2259
2259
  }
2260
2260
 
2261
2261
  checkJdAddCartState(){
2262
2262
  const getJdAppForNotMainRemoveCartUaList = isJdApp ? window?.PAGE_DATA?.businessData?.jdAppForNotMainRemoveCartUaList : undefined;
2263
2263
  if(getJdAppForNotMainRemoveCartUaList && Array.isArray(getJdAppForNotMainRemoveCartUaList) && getJdAppForNotMainRemoveCartUaList.length > 0){
2264
2264
  const setFilterReg = new RegExp(getJdAppForNotMainRemoveCartUaList.join('|'), 'i');
2265
2265
  this.info.baseAddCartSwitch = !setFilterReg.test(window.navigator.userAgent)
2266
2266
  }
2267
2267
  }
2268
2268
 
2269
2269
  loadApiSafeSteadyReayPromise() {
2270
2270
  if (!this.loadJsApiRequestStatePromise) {
2271
2271
  this.loadJsApiRequestStatePromise = this.loadOtherSdk(LoadJsInitTriggerType.API_REQUEST);
2272
2272
  }
2273
2273
  return this.loadJsApiRequestStatePromise;
2274
2274
  }
2275
2275
 
2276
2276
  loadH5tagReayPromise() {
2277
2277
  if (!this.loadJsH5tagStatePromise) {
2278
2278
  const h5TagJs = this.loadJsSdkList.find((e) => e.fileName === 'h5TagJs');
2279
2279
  this.loadJsH5tagStatePromise = !h5TagJs
2280
2280
  ? Promise.resolve(true)
2281
2281
  : this.loadOtherSdk(LoadJsInitTriggerType.NOW, [
2282
2282
  Object.assign({}, h5TagJs, {
2283
2283
  initTriggerType: LoadJsInitTriggerType.NOW,
2284
2284
  }),
2285
2285
  ]);
2286
2286
  }
2287
2287
  return this.loadJsH5tagStatePromise;
2288
2288
  }
2289
2289
 
2290
2290
  jmfeReayPromise(): Promise<any> {
2291
2291
  if (isJdApp) {
2292
2292
  if (this.jmfeRegisterState) {
2293
2293
  return Promise.resolve(true);
2294
2294
  } else {
2295
2295
  !this.jmfeRegisterStatePromise &&
2296
2296
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
2297
2297
  ready('jmfe', 3000)
2298
2298
  .then(() => {
2299
2299
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
2300
2300
  this.jmfeRegisterState = true;
2301
2301
  resolve(true);
2302
2302
  console.log(
2303
2303
  '松果app内初始化注册jmfe认证完成',
2304
2304
  window?.jmfe,
2305
2305
  '当前版本',
2306
2306
  window?.jmfe?.VERSION,
2307
2307
  );
2308
2308
  })
2309
2309
  .catch((err) => {
2310
2310
  console.error('jmfe ready error', err);
2311
2311
  reject(false);
2312
2312
  });
2313
2313
  }));
2314
2314
  return this.jmfeRegisterStatePromise;
2315
2315
  }
2316
2316
  } else {
2317
2317
  return Promise.reject(false);
2318
2318
  }
2319
2319
  }
2320
2320
 
2321
2321
  jdWorkerReadyPromise(): Promise<any> {
2322
2322
  if (isJdApp) {
2323
2323
  if (this.businessWorkerReady) {
2324
2324
  return Promise.resolve(true);
2325
2325
  } else {
2326
2326
  const getOpenJdWorkerState =
2327
2327
  window?.PAGE_DATA?.businessData?.businessWorkerVersion &&
2328
2328
  versionCompare(
2329
2329
  jdAppVersionStr,
2330
2330
  window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10',
2331
2331
  ) >= 0;
2332
2332
  !this.businessWorkerReadyPromise &&
2333
2333
  (this.businessWorkerReadyPromise = getOpenJdWorkerState
2334
2334
  ? new Promise((resolve) => {
2335
2335
  this.jmfeReayPromise()
2336
2336
  .then(() => {
2337
2337
  window.jmfe
2338
2338
  .onMsgForWorker(
2339
2339
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
2340
2340
  (workerData) => {
2341
2341
  console.log('收到业务jd worker消息结果:', workerData);
2342
2342
  if (workerData && workerData?.workerType) {
2343
2343
  const getWorkerType = workerData?.workerType;
2344
2344
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
2345
2345
  this.workerPreRequestData.set(workerData?.functionId, workerData);
2346
2346
  Taro.eventCenter.trigger(getWorkerType, workerData);
2347
2347
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
2348
2348
  Taro.eventCenter.trigger(getWorkerType, workerData);
2349
2349
  }
2350
2350
  }
2351
2351
  },
2352
2352
  )
2353
2353
  .then(() => {
2354
2354
  console.log('jd worker注册成功');
2355
2355
  this.businessWorkerReady = true;
2356
2356
  resolve(true);
2357
2357
  })
2358
2358
  .catch((error) => {
2359
2359
  console.log(
2360
2360
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
2361
2361
  error,
2362
2362
  );
2363
2363
  draBusinessCustomReport({
2364
2364
  eventName: 'business',
2365
2365
  errorName: 'jmfe_onMsgForWorker_error',
2366
2366
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
2367
2367
  extraData: JSON.stringify({
2368
2368
  businessWorkerVersion:
2369
2369
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
2370
2370
  error,
2371
2371
  }),
2372
2372
  });
2373
2373
  resolve(false);
2374
2374
  });
2375
2375
  })
2376
2376
  .catch((err) => {
2377
2377
  console.log('jmfe超时异常,worker注册失败', err);
2378
2378
  resolve(false);
2379
2379
  });
2380
2380
  })
2381
2381
  : Promise.resolve(false));
2382
2382
  }
2383
2383
  return this.businessWorkerReadyPromise;
2384
2384
  } else {
2385
2385
  return Promise.resolve(false);
2386
2386
  }
2387
2387
  }
2388
2388
 
2389
2389
  taskTimeoutPromise(callBack, timeout = 2000) {
2390
2390
  return new Promise((resolve) => {
2391
2391
  setTimeout(
2392
2392
  () => {
2393
2393
  const getCallBackRes = typeof callBack === 'function' && callBack();
2394
2394
  return resolve(getCallBackRes || false);
2395
2395
  },
2396
2396
  isInJdAppH5DebugMode ? 0 : timeout,
2397
2397
  );
2398
2398
  });
2399
2399
  }
2400
2400
  _getJdPadMinWidthForListen() {
2401
2401
  return (
2402
2402
  isJdApp &&
2403
2403
  Math.min(window.screen.width, window.screen.height) >
2404
2404
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
2405
2405
  );
2406
2406
  }
2407
2407
 
2408
2408
  getJdScreenSizeInfoPromise() {
2409
2409
  !this.jdScreenSizeInfoPromise &&
2410
2410
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
2411
2411
  const getThisTime = Date.now();
2412
2412
  this.jmfeReayPromise().then(() => {
2413
2413
  return Promise.race([
2414
2414
  window.jmfe.getScreenSize(),
2415
2415
  this.taskTimeoutPromise(() => {
2416
2416
  return {
2417
2417
  status: '-10',
2418
2418
  msg: '获取大屏信息2s超时',
2419
2419
  };
2420
2420
  }),
2421
2421
  ])
2422
2422
  .then((res) => {
2423
2423
  console.warn('===获取app大屏信息====', res);
2424
2424
  const { status, data } = res;
2425
2425
  if (status === '0' && data) {
2426
2426
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
2427
2427
  const getPageInfo = dealNativePixelToCssPixel({
2428
2428
  pageWidth,
2429
2429
  pageHeight,
2430
2430
  });
2431
2431
  this.info.sysInfo.jdScreenSizeType = sizeType;
2432
2432
  const getUseTime = Date.now() - getThisTime;
2433
2433
  console.warn(
2434
2434
  '===计算是否是app大屏信息,需满足宽度最新720===',
2435
2435
  getPageInfo,
2436
2436
  '原始数据',
2437
2437
  data,
2438
2438
  '是否是横屏isLandscape为1=',
2439
2439
  isLandscape,
2440
2440
  '用时',
2441
2441
  getUseTime,
2442
2442
  );
2443
2443
  if (getPageInfo?.pageWidth > 0) {
2444
2444
  this.rootEleInitWidth = getPageInfo?.pageWidth;
2445
2445
  draBusinessCustomReport({
2446
2446
  eventName: 'UIInteract',
2447
2447
  errorName: 'rootEle_width_getJdScreenSizeInfo',
2448
2448
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
2449
2449
  extraData: JSON.stringify({
2450
2450
  isJdApp,
2451
2451
  getPageInfo,
2452
2452
  originData: res,
2453
2453
  }),
2454
2454
  });
2455
2455
  resolve(getPageInfo);
2456
2456
  } else {
2457
2457
  resolve({
2458
2458
  pageWidth: 0,
2459
2459
  pageHeight: 0,
2460
2460
  msg: '转换异常',
2461
2461
  });
2462
2462
  }
2463
2463
  } else {
2464
2464
  resolve({
2465
2465
  pageWidth: 0,
2466
2466
  pageHeight: 0,
2467
2467
  msg: '获取大屏信息异常或者超时',
2468
2468
  });
2469
2469
  }
2470
2470
  })
2471
2471
  .catch((err) => {
2472
2472
  console.log('获取大屏信息异常', err);
2473
2473
  resolve({
2474
2474
  pageWidth: 0,
2475
2475
  pageHeight: 0,
2476
2476
  msg: '获取大屏信息异常',
2477
2477
  });
2478
2478
  });
2479
2479
  });
2480
2480
  }));
2481
2481
  return this.jdScreenSizeInfoPromise;
2482
2482
  }
2483
2483
 
2484
2484
  listenJdTabletScreenChange() {
2485
2485
  this.jmfeReayPromise().then(() => {
2486
2486
  try {
2487
2487
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
2488
2488
  window.jmfe.listenDeviceScreenChange((event) => {
2489
2489
  console.log(
2490
2490
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
2491
2491
  event,
2492
2492
  '通过前端判断是不是横屏',
2493
2493
  window.matchMedia('(orientation: landscape)')?.matches,
2494
2494
  );
2495
2495
  const { orientation } = event?.data;
2496
2496
  if (orientation) {
2497
2497
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
2498
2498
  Taro.eventCenter.trigger(
2499
2499
  TaroEventType.TABLE_SCREEN_CHANGE,
2500
2500
  this.info.sysInfo.isJdTabletLandscape,
2501
2501
  orientation,
2502
2502
  );
2503
2503
  }
2504
2504
  });
2505
2505
  } catch (error) {
2506
2506
  console.log('listenScreenChange的打印error:', error);
2507
2507
  }
2508
2508
  });
2509
2509
  }
2510
2510
 
2511
2511
  updateBusinessDomainAndApi(domain, api) {
2512
2512
  }
2513
2513
 
2514
2514
  formatNativeScreenPageData(action) {
2515
2515
  let getChangePageInfo: any = null;
2516
2516
  try {
2517
2517
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
2518
2518
  JSON.stringify({
2519
2519
  plugin: 'JDHybridScreenPlugin',
2520
2520
  action,
2521
2521
  sync: '1',
2522
2522
  }),
2523
2523
  );
2524
2524
  const getChangePageInfoData =
2525
2525
  typeof getNativeScreenPageInfoStr === 'string'
2526
2526
  ? JSON.parse(getNativeScreenPageInfoStr)
2527
2527
  : null;
2528
2528
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
2529
2529
  const { code, data } = getChangePageInfoData;
2530
2530
  getChangePageInfo = code && code === '0' ? data : null;
2531
2531
  }
2532
2532
  } catch (e) {
2533
2533
  console.log('JDHybridScreenPlugin转换异常', e);
2534
2534
  }
2535
2535
  return getChangePageInfo;
2536
2536
  }
2537
2537
 
2538
2538
  isAndroidFoldScreen() {
2539
2539
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
2540
2540
  }
2541
2541
 
2542
2542
  isHarmonyFoldScreenPromise(): Promise<{
2543
2543
  isFoldScreen: boolean;
2544
2544
  getFoldDisplayMode?: number;
2545
2545
  }> {
2546
2546
  return new Promise((resolve) => {
2547
2547
  this.jmfeReayPromise()
2548
2548
  .then(() => {
2549
2549
  if (window.jmfe?.callNative) {
2550
2550
  Promise.all([
2551
2551
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
2552
2552
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
2553
2553
  ])
2554
2554
  .then((res) => {
2555
2555
  resolve({
2556
2556
  isFoldScreen: res?.[0]?.data === '1',
2557
2557
  getFoldDisplayMode: res?.[1]?.data,
2558
2558
  });
2559
2559
  })
2560
2560
  .catch(() => {
2561
2561
  resolve({
2562
2562
  isFoldScreen: false,
2563
2563
  getFoldDisplayMode: undefined,
2564
2564
  });
2565
2565
  });
2566
2566
  } else {
2567
2567
  resolve({
2568
2568
  isFoldScreen: false,
2569
2569
  getFoldDisplayMode: undefined,
2570
2570
  });
2571
2571
  }
2572
2572
  })
2573
2573
  .catch(() => {
2574
2574
  resolve({
2575
2575
  isFoldScreen: false,
2576
2576
  getFoldDisplayMode: undefined,
2577
2577
  });
2578
2578
  });
2579
2579
  });
2580
2580
  }
2581
2581
 
2582
2582
  getJdAndroidPageChangeScreenInfo() {
2583
2583
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
2584
2584
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
2585
2585
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
2586
2586
  pageWidth: getPageScreenInfo.pageWidth,
2587
2587
  pageHeight: getPageScreenInfo.pageHeight,
2588
2588
  });
2589
2589
  getPageScreenInfo.pageWidth = pageWidth;
2590
2590
  getPageScreenInfo.pageHeight = pageHeight;
2591
2591
  }
2592
2592
  return getPageScreenInfo;
2593
2593
  }
2594
2594
 
2595
2595
  getRootEleWindowWidthInfo() {
2596
2596
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
2597
2597
  const getWindowWidth = window.innerWidth;
2598
2598
  const getScreenWidth = window.screen.width;
2599
2599
  return {
2600
2600
  getRootEleWidth,
2601
2601
  getWindowWidth,
2602
2602
  getScreenWidth,
2603
2603
  };
2604
2604
  }
2605
2605
 
2606
2606
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
2607
2607
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
2608
2608
  console.log(
2609
2609
  '当前获取根元素的宽度',
2610
2610
  getRootEleWidth,
2611
2611
  'getWindowWidth',
2612
2612
  getWindowWidth,
2613
2613
  'getScreenWidth',
2614
2614
  getScreenWidth,
2615
2615
  );
2616
2616
  const getLastWidth =
2617
2617
  getRootEleWidth > 0
2618
2618
  ? Math.round(getRootEleWidth)
2619
2619
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
2620
2620
  console.warn(
2621
2621
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2622
2622
  );
2623
2623
  timeout > 0 &&
2624
2624
  draBusinessCustomReport({
2625
2625
  eventName: 'UIInteract',
2626
2626
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
2627
2627
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2628
2628
  extraData: JSON.stringify({
2629
2629
  isJdApp,
2630
2630
  getRootEleWidth,
2631
2631
  getWindowWidth,
2632
2632
  getScreenWidth,
2633
2633
  ...reportParam,
2634
2634
  }),
2635
2635
  });
2636
2636
  return getLastWidth;
2637
2637
  }
2638
2638
 
2639
2639
  getPadWindowRootEleWidthPromise() {
2640
2640
  if (this.rootEleInitWidth > 0) {
2641
2641
  return Promise.resolve(this.rootEleInitWidth);
2642
2642
  } else {
2643
2643
  !this.rootEleWidthRegisterPromise &&
2644
2644
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
2645
2645
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
2646
2646
  if (getRootEleInitWidth > 0) {
2647
2647
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
2648
2648
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
2649
2649
  resolve(this.rootEleInitWidth);
2650
2650
  } else {
2651
2651
  const timerPromise = () => {
2652
2652
  return new Promise((resolve2) => {
2653
2653
  window.setTimeout(() => {
2654
2654
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
2655
2655
  this.getRootEleWindowWidthInfo();
2656
2656
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
2657
2657
  console.warn(
2658
2658
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
2659
2659
  );
2660
2660
  draBusinessCustomReport({
2661
2661
  eventName: 'UIInteract',
2662
2662
  errorName: 'rootEle_width_200_timeout_info',
2663
2663
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
2664
2664
  extraData: JSON.stringify({
2665
2665
  isJdApp,
2666
2666
  getRootEleWidth,
2667
2667
  getWindowWidth,
2668
2668
  getScreenWidth,
2669
2669
  }),
2670
2670
  });
2671
2671
  const getRes =
2672
2672
  getRootEleWidth > 0 && getWindowWidth > 0
2673
2673
  ? Math.min(getRootEleWidth, getWindowWidth)
2674
2674
  : Math.max(getRootEleWidth, getWindowWidth);
2675
2675
  resolve2({
2676
2676
  pageWidth: Math.round(getRes),
2677
2677
  });
2678
2678
  }
2679
2679
  }, 200);
2680
2680
  });
2681
2681
  };
2682
2682
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
2683
2683
  const { pageWidth } = res;
2684
2684
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
2685
2685
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
2686
2686
  });
2687
2687
  }
2688
2688
  }));
2689
2689
  return this.rootEleWidthRegisterPromise;
2690
2690
  }
2691
2691
  }
2692
2692
 
2693
2693
  async getSystemInfo(params) {
2694
2694
  const getParams = Object.assign({}, params || {});
2695
2695
  if (this.rootEleInitWidth > 0) {
2696
2696
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
2697
2697
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
2698
2698
  } else {
2699
2699
  if (this._getJdPadMinWidthForListen()) {
2700
2700
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
2701
2701
  getParams['replaceSystemWidth'] = true;
2702
2702
  }
2703
2703
  }
2704
2704
  isJdApp && this.createLanguagePromise();
2705
2705
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
2706
2706
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
2707
2707
  let _isfoldScreen = false;
2708
2708
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
2709
2709
  console.info(
2710
2710
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
2711
2711
  getStorageData,
2712
2712
  '通过缓存值第一次判断是否是折叠屏',
2713
2713
  getStorageData === 'true',
2714
2714
  );
2715
2715
  if (!getStorageData) {
2716
2716
  _isfoldScreen = this.isAndroidFoldScreen();
2717
2717
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
2718
2718
  } else {
2719
2719
  _isfoldScreen = getStorageData === 'true';
2720
2720
  }
2721
2721
  if (_isfoldScreen) {
2722
2722
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
2723
2723
  if (getJdAndroidPageInfo) {
2724
2724
  info = getSystemInfos(getJdAndroidPageInfo);
2725
2725
  console.warn(
2726
2726
  '当前为松果安卓折叠屏app,获取折叠屏信息',
2727
2727
  getJdAndroidPageInfo,
2728
2728
  '获取转换后的系统信息',
2729
2729
  info,
2730
2730
  );
2731
2731
  draBusinessCustomReport({
2732
2732
  eventName: 'UIInteract',
2733
2733
  errorName: 'android_jdapp_foldScreen_info',
2734
2734
  errorMessage:
2735
2735
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
2736
2736
  extraData: JSON.stringify({
2737
2737
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
2738
2738
  androidPageInfo: getJdAndroidPageInfo,
2739
2739
  jdAppVersionStr,
2740
2740
  taroSysInfo: info,
2741
2741
  }),
2742
2742
  });
2743
2743
  }
2744
2744
  }
2745
2745
  }
2746
2746
  if (isJdApp) {
2747
2747
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
2748
2748
  }
2749
2749
  this.info.sysInfo = {
2750
2750
  actualNavBarHeight: 0,
2751
2751
  ...this.info.sysInfo,
2752
2752
  ...info,
2753
2753
  safeContentHeight: info?.screenHeight,
2754
2754
  headerHeight: 0,
2755
2755
  tabBarHeight: 0,
2756
2756
  languageType: languageNowType,
2757
2757
  };
2758
2758
  if (isJdApp || isH5AndJingGouMini) {
2759
2759
  this.getLbsAddressCachePromise();
2760
2760
  }
2761
2761
  if (isJdApp) {
2762
2762
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
2763
2763
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
2764
2764
  this.getJdAppBaseInfo();
2765
2765
  this.getAddressCachePromise();
2766
2766
  this.getElderModePromise();
2767
2767
  this.getJDAppearanceStatePromise();
2768
2768
  this.createJdAndroidRquestEventForTouchStart();
2769
2769
  }
2770
2770
  this.getWifiVideoAutoPlayAsync();
2771
2771
  this.getMPaasConfigAsync();
2772
2772
  this.getNetWorkType();
2773
2773
  }
2774
2774
 
2775
2775
  getElderModePromise() {
2776
2776
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
2777
2777
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
2778
2778
  } else {
2779
2779
  if (isJdAndAndroidDevice) {
2780
2780
  this.info.sysInfo.jdAppModeType = '0';
2781
2781
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
2782
2782
  } else {
2783
2783
  return Promise.race([
2784
2784
  this.taskTimeoutPromise(() => {
2785
2785
  this.info.sysInfo.jdAppModeType = '0';
2786
2786
  return this.info.sysInfo.jdAppModeType;
2787
2787
  }),
2788
2788
  new Promise((resolve) => {
2789
2789
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
2790
2790
  if (!window[getCallBackName]) {
2791
2791
  window[getCallBackName] = (res) => {
2792
2792
  try {
2793
2793
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2794
2794
  const { status, data, msg } = getResJson;
2795
2795
  console.log(`获取松果app展示模式成功,返回结果${data}`);
2796
2796
  if (status === '0') {
2797
2797
  this.info.sysInfo.jdAppModeType = data;
2798
2798
  resolve(data);
2799
2799
  } else {
2800
2800
  resolve('0');
2801
2801
  }
2802
2802
  } catch (e) {
2803
2803
  resolve('0');
2804
2804
  }
2805
2805
  window[getCallBackName] = null;
2806
2806
  };
2807
2807
  }
2808
2808
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
2809
2809
  method: 'callSyncRouterModuleWithParams',
2810
2810
  params: JSON.stringify({
2811
2811
  routerURL: 'router://JDBModeModule/getCurrentMode',
2812
2812
  routerParam: {},
2813
2813
  callBackName: `window.${getCallBackName}`,
2814
2814
  callBackId: `${getCallBackName}Ios`,
2815
2815
  }),
2816
2816
  });
2817
2817
  }),
2818
2818
  ]);
2819
2819
  }
2820
2820
  }
2821
2821
  }
2822
2822
  getAPPUseStraightCorner() {
2823
2823
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
2824
2824
  const params = {
2825
2825
  routerURL,
2826
2826
  routerParam: {},
2827
2827
  jdRouter: '1',
2828
2828
  };
2829
2829
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
2830
2830
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
2831
2831
  } else {
2832
2832
  return this.jmfeReayPromise()
2833
2833
  .then(() => {
2834
2834
  if (isJdAndHarmonyDevice || !isJdApp) {
2835
2835
  console.log('not APP or is Harmony');
2836
2836
  return Promise.resolve(false);
2837
2837
  }
2838
2838
  console.log('jmfe setShareInfo', params);
2839
2839
  return Promise.race([
2840
2840
  window.jmfe.callRouter(params),
2841
2841
  this.taskTimeoutPromise(() => {
2842
2842
  return false;
2843
2843
  }),
2844
2844
  ]).then(({ status, data }) => {
2845
2845
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
2846
2846
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
2847
2847
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
2848
2848
  return Promise.resolve(status === '0' && Number(data) === 1);
2849
2849
  });
2850
2850
  })
2851
2851
  .catch((e) => {
2852
2852
  console.log('jmfe error', e);
2853
2853
  return Promise.resolve(false);
2854
2854
  });
2855
2855
  }
2856
2856
  }
2857
2857
 
2858
2858
  getJDAppearanceStatePromise() {
2859
2859
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
2860
2860
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
2861
2861
  } else {
2862
2862
  return Promise.race([
2863
2863
  this.taskTimeoutPromise(() => {
2864
2864
  this.info.sysInfo.jdAppearanceState = '0';
2865
2865
  return this.info.sysInfo.jdAppearanceState;
2866
2866
  }),
2867
2867
  new Promise((resolve) => {
2868
2868
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
2869
2869
  if (!window[getCallBackName]) {
2870
2870
  window[getCallBackName] = (res) => {
2871
2871
  try {
2872
2872
  console.log('getJDAppearanceStatePromise', res);
2873
2873
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2874
2874
  const { status, data, msg } = getResJson;
2875
2875
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
2876
2876
  if (status === '0') {
2877
2877
  this.info.sysInfo.jdAppearanceState = data;
2878
2878
  resolve(data);
2879
2879
  } else {
2880
2880
  resolve('0');
2881
2881
  }
2882
2882
  } catch (e) {
2883
2883
  resolve('0');
2884
2884
  }
2885
2885
  window[getCallBackName] = null;
2886
2886
  };
2887
2887
  }
2888
2888
  if (isAndroidDevice) {
2889
2889
  const jsonString = JSON.stringify({
2890
2890
  callBackName: `window.${getCallBackName}`,
2891
2891
  });
2892
2892
  console.log('window.JDAppearance', window?.JDAppearance);
2893
2893
  window?.JDAppearance &&
2894
2894
  window?.JDAppearance?.getUiState &&
2895
2895
  window.JDAppearance.getUiState(jsonString);
2896
2896
  } else {
2897
2897
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
2898
2898
  method: 'callSyncRouterModuleWithParams',
2899
2899
  params: JSON.stringify({
2900
2900
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
2901
2901
  routerParam: {},
2902
2902
  callBackName: `window.${getCallBackName}`,
2903
2903
  callBackId: `${getCallBackName}Ios`,
2904
2904
  }),
2905
2905
  });
2906
2906
  }
2907
2907
  }),
2908
2908
  ]);
2909
2909
  }
2910
2910
  }
2911
2911
 
2912
2912
  createJdAndroidRquestEventForTouchStart() {
2913
2913
  if (isJdAndAndroidDevice && window?.JdAndroid) {
2914
2914
  const rootEleNode = document.querySelector('body');
2915
2915
  if (rootEleNode) {
2916
2916
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
2917
2917
  }
2918
2918
  }
2919
2919
  }
2920
2920
  jdAndroidAddEventListenerTouchStart(e) {
2921
2921
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
2922
2922
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
2923
2923
  const hasCustomEle = e
2924
2924
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
2925
2925
  : false;
2926
2926
  if (!hasCustomEle) {
2927
2927
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
2928
2928
  console.log(
2929
2929
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
2930
2930
  );
2931
2931
  }
2932
2932
  }
2933
2933
  }
2934
2934
  removeJdAndroidRquestEventForTouchStart() {
2935
2935
  if (isJdAndAndroidDevice && window.JdAndroid) {
2936
2936
  const rootEleNode = document.querySelector('body');
2937
2937
  if (rootEleNode) {
2938
2938
  rootEleNode.removeEventListener(
2939
2939
  'touchstart',
2940
2940
  this.jdAndroidAddEventListenerTouchStart,
2941
2941
  false,
2942
2942
  );
2943
2943
  }
2944
2944
  }
2945
2945
  }
2946
2946
 
2947
2947
  getNetWorkType() {
2948
2948
  if (isJdApp) {
2949
2949
  this.jmfeReayPromise().then(() => {
2950
2950
  window.jmfe
2951
2951
  .getNetworkStatus()
2952
2952
  .then(({ status, data }) => {
2953
2953
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
2954
2954
  if (status === '0') {
2955
2955
  this.info.sysInfo['netWorkType'] = data;
2956
2956
  } else {
2957
2957
  this._taroGetNetworkType();
2958
2958
  }
2959
2959
  })
2960
2960
  .catch((err) => {
2961
2961
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
2962
2962
  this._taroGetNetworkType();
2963
2963
  });
2964
2964
  });
2965
2965
  } else {
2966
2966
  this._taroGetNetworkType();
2967
2967
  }
2968
2968
  }
2969
2969
  _taroGetNetworkType() {
2970
2970
  Taro.getNetworkType().then((getRes) => {
2971
2971
  if (getRes && getRes.networkType) {
2972
2972
  this.info.sysInfo['netWorkType'] = getRes.networkType;
2973
2973
  console.log(
2974
2974
  '在app内通过taro对象获取网络状态完成,当前网络状态',
2975
2975
  this.info.sysInfo['netWorkType'],
2976
2976
  );
2977
2977
  }
2978
2978
  });
2979
2979
  }
2980
2980
 
2981
2981
  getJdAppBaseInfo() {
2982
2982
  const appKeyCacheToCookieMinuteTime =
2983
2983
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
2984
2984
  appUuidCacheToCookieMinuteTime =
2985
2985
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
2986
2986
  getAppKey = cookie.get(cacheAppKey),
2987
2987
  getAppUuidKey = cookie.get(cacheAppUuidKey);
2988
2988
  console.log(
2989
2989
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
2990
2990
  cacheAppKey,
2991
2991
  getAppKey,
2992
2992
  cacheAppUuidKey,
2993
2993
  getAppUuidKey,
2994
2994
  );
2995
2995
  if (
2996
2996
  appKeyCacheToCookieMinuteTime &&
2997
2997
  appUuidCacheToCookieMinuteTime &&
2998
2998
  getAppKey &&
2999
2999
  getAppUuidKey
3000
3000
  ) {
3001
3001
  const [uuid, eufv] = getAppUuidKey.split('@');
3002
3002
  const baseApiKeyParam = {
3003
3003
  uuid,
3004
3004
  };
3005
3005
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
3006
3006
  if (eufv === '1' && /-/.test(uuid)) {
3007
3007
  const [eu, fv] = uuid.split('-');
3008
3008
  baseApiKeyParam['eu'] = eu;
3009
3009
  baseApiKeyParam['fv'] = fv;
3010
3010
  }
3011
3011
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3012
3012
  this.jmfeReayPromise().then(() => {
3013
3013
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
3014
3014
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3015
3015
  });
3016
3016
  } else {
3017
3017
  const checkGetJdAppKeyState =
3018
3018
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
3019
3019
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
3020
3020
  this.jmfeReayPromise().then(() => {
3021
3021
  Promise.all([
3022
3022
  checkGetJdAppKeyState && window.jmfe?.callNative
3023
3023
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
3024
3024
  : Promise.resolve({
3025
3025
  status: '-1000',
3026
3026
  msg: '当前版本不支持获取松果app中的getAppKey',
3027
3027
  data: '-1000',
3028
3028
  }),
3029
3029
  window.jmfe.getDeviceInfo(),
3030
3030
  ]).then((resList) => {
3031
3031
  const [getAppKeyRes, deviceInfoRes] = resList;
3032
3032
  console.log(
3033
3033
  '在app内初始化通过jmfe获取getAppKey结果',
3034
3034
  getAppKeyRes,
3035
3035
  '通过jmfe获取getDeviceInfo获取结果',
3036
3036
  deviceInfoRes,
3037
3037
  );
3038
3038
  const baseApiKeyParam = {};
3039
3039
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
3040
3040
  const getJmfeAppKey = getAppKeyRes?.data;
3041
3041
  if (getJmfeAppKey && getJmfeAppKey !== '') {
3042
3042
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
3043
3043
  const getJdAppKeyCacheToCookieMinuteTime =
3044
3044
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
3045
3045
  if (getJdAppKeyCacheToCookieMinuteTime) {
3046
3046
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
3047
3047
  cookie.set(cacheAppKey, getJmfeAppKey, {
3048
3048
  path: '/',
3049
3049
  expires,
3050
3050
  });
3051
3051
  }
3052
3052
  }
3053
3053
  }
3054
3054
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
3055
3055
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
3056
3056
  if (uuid && uuid !== '') {
3057
3057
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
3058
3058
  baseApiKeyParam['uuid'] = uuid;
3059
3059
  if (eufv === '1' && /-/.test(uuid)) {
3060
3060
  const [eu, fv] = uuid.split('-');
3061
3061
  baseApiKeyParam['eu'] = eu;
3062
3062
  baseApiKeyParam['fv'] = fv;
3063
3063
  }
3064
3064
  const getAppUuidCacheToCookieMinuteTime =
3065
3065
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
3066
3066
  if (getAppUuidCacheToCookieMinuteTime) {
3067
3067
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
3068
3068
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
3069
3069
  path: '/',
3070
3070
  expires,
3071
3071
  });
3072
3072
  }
3073
3073
  }
3074
3074
  }
3075
3075
  console.log(
3076
3076
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
3077
3077
  baseApiKeyParam,
3078
3078
  );
3079
3079
  if (Object.keys(baseApiKeyParam).length > 0) {
3080
3080
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3081
3081
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3082
3082
  }
3083
3083
  });
3084
3084
  });
3085
3085
  }
3086
3086
  }
3087
3087
 
3088
3088
  getCacheAddressRouter() {
3089
3089
  if (isJdApp) {
3090
3090
  if (!isJdAndHarmonyDevice) {
3091
3091
  return Promise.race([
3092
3092
  new Promise((resolve) => {
3093
3093
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
3094
3094
  if (!window[getCallBackName]) {
3095
3095
  window[getCallBackName] = (res) => {
3096
3096
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
3097
3097
  try {
3098
3098
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3099
3099
  resolve(getResJson);
3100
3100
  } catch (e) {
3101
3101
  resolve({
3102
3102
  status: '-1002',
3103
3103
  msg: '地址信息解析json异常',
3104
3104
  res,
3105
3105
  });
3106
3106
  }
3107
3107
  window[getCallBackName] = null;
3108
3108
  };
3109
3109
  }
3110
3110
  const getRouterParam = {
3111
3111
  sceneId: 'basicShoppingProcess',
3112
3112
  };
3113
3113
  if (isAndroidDevice) {
3114
3114
  return callRouterAndroid({
3115
3115
  routerURL: 'router://JDAddressModule/getCacheAddress',
3116
3116
  routerParam: getRouterParam,
3117
3117
  callBackName: getCallBackName,
3118
3118
  isSync: true,
3119
3119
  });
3120
3120
  } else {
3121
3121
  return callRouterIOS({
3122
3122
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
3123
3123
  routerParam: getRouterParam,
3124
3124
  callBackName: getCallBackName,
3125
3125
  });
3126
3126
  }
3127
3127
  }),
3128
3128
  this.taskTimeoutPromise(() => {
3129
3129
  return {
3130
3130
  status: '-1000',
3131
3131
  msg: '原生router协议获取地址信息超时',
3132
3132
  };
3133
3133
  }, 3000),
3134
3134
  ]);
3135
3135
  } else {
3136
3136
  return Promise.race([
3137
3137
  new Promise((resolve) => {
3138
3138
  this.jmfeReayPromise()
3139
3139
  .then(() => {
3140
3140
  const plugin = 'JDHybridRouterPlugin';
3141
3141
  const action = 'callSyncRouterModuleWithParams';
3142
3142
  const params = {
3143
3143
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
3144
3144
  routerParam: '',
3145
3145
  };
3146
3146
  const sync = '1';
3147
3147
  try {
3148
3148
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
3149
3149
  resolve(res);
3150
3150
  });
3151
3151
  } catch (error) {
3152
3152
  resolve({
3153
3153
  status: '-1001',
3154
3154
  msg: '判断jmfe不存在,获取经纬度信息异常',
3155
3155
  });
3156
3156
  }
3157
3157
  })
3158
3158
  .catch(() => {
3159
3159
  resolve({
3160
3160
  status: '-1002',
3161
3161
  msg: '鸿蒙系统调用jmfe异常,获取失败',
3162
3162
  });
3163
3163
  });
3164
3164
  }),
3165
3165
  this.taskTimeoutPromise(() => {
3166
3166
  return {
3167
3167
  status: '-1000',
3168
3168
  msg: '原生router协议获取地址信息超时',
3169
3169
  };
3170
3170
  }, 3000),
3171
3171
  ]);
3172
3172
  }
3173
3173
  } else if (isH5AndJingGouMini) {
3174
3174
  return Promise.resolve({
3175
3175
  status: '-1002',
3176
3176
  msg: '普通h5暂无业务需要,未实现,获取失败',
3177
3177
  });
3178
3178
  } else {
3179
3179
  return Promise.resolve({
3180
3180
  status: '-1002',
3181
3181
  msg: '普通h5暂无业务需要,未实现,获取失败',
3182
3182
  });
3183
3183
  }
3184
3184
  }
3185
3185
 
3186
3186
  getAddressCachePromise() {
3187
3187
  return new Promise((resolve) => {
3188
3188
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
3189
3189
  resolve({
3190
3190
  lat: this.info.sysInfo.lat,
3191
3191
  lng: this.info.sysInfo.lng,
3192
3192
  area: this?.info?.sysInfo?.area,
3193
3193
  });
3194
3194
  } else {
3195
3195
  this.getCacheAddressRouter()
3196
3196
  .then((res) => {
3197
3197
  const { status, data } = res;
3198
3198
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
3199
3199
  if (status === '0' && data) {
3200
3200
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
3201
3201
  data || {};
3202
3202
  let area = '';
3203
3203
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
3204
3204
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
3205
3205
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
3206
3206
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3207
3207
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
3208
3208
  this.info.pageInfo['address'] = area;
3209
3209
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
3210
3210
  this.info.sysInfo['area'] = area;
3211
3211
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3212
3212
  area: this.info.pageInfo.address,
3213
3213
  });
3214
3214
  }
3215
3215
  resolve({
3216
3216
  lat: this.info.sysInfo['lat'],
3217
3217
  lng: this.info.sysInfo['lng'],
3218
3218
  area: area,
3219
3219
  });
3220
3220
  } else {
3221
3221
  if (typeof res === 'object') {
3222
3222
  draBusinessCustomReport({
3223
3223
  eventName: 'business',
3224
3224
  errorName: 'jdapp_getCacheAddress_info_err',
3225
3225
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
3226
3226
  extraData: JSON.stringify({
3227
3227
  isJdApp,
3228
3228
  jdAppVersion: jdAppVersionStr,
3229
3229
  ...res,
3230
3230
  }),
3231
3231
  });
3232
3232
  }
3233
3233
  resolve({ lat: '', lng: '', area: '' });
3234
3234
  }
3235
3235
  })
3236
3236
  .catch((e) => {
3237
3237
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
3238
3238
  draBusinessCustomReport({
3239
3239
  eventName: 'business',
3240
3240
  errorName: 'jdapp_getCacheAddress_info_catch_err',
3241
3241
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
3242
3242
  extraData: JSON.stringify({
3243
3243
  isJdApp,
3244
3244
  jdAppVersion: jdAppVersionStr,
3245
3245
  }),
3246
3246
  });
3247
3247
  resolve({ lat: '', lng: '', area: '' });
3248
3248
  });
3249
3249
  }
3250
3250
  });
3251
3251
  }
3252
3252
 
3253
3253
  getLbsCacheAddressRouter() {
3254
3254
  if (isJdApp) {
3255
3255
  if (!isJdAndHarmonyDevice) {
3256
3256
  return Promise.race([
3257
3257
  new Promise((resolve) => {
3258
3258
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
3259
3259
  if (!window[getCallBackName]) {
3260
3260
  window[getCallBackName] = (res) => {
3261
3261
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
3262
3262
  try {
3263
3263
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3264
3264
  resolve(getResJson);
3265
3265
  } catch (e) {
3266
3266
  resolve({
3267
3267
  status: '-1002',
3268
3268
  msg: '地址信息解析json异常',
3269
3269
  res,
3270
3270
  });
3271
3271
  }
3272
3272
  window[getCallBackName] = null;
3273
3273
  };
3274
3274
  }
3275
3275
  const getRouterParam = {
3276
3276
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
3277
3277
  sceneId: 'basicShoppingProcess',
3278
3278
  };
3279
3279
  if (isAndroidDevice) {
3280
3280
  return callRouterAndroid({
3281
3281
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
3282
3282
  routerParam: getRouterParam,
3283
3283
  callBackName: getCallBackName,
3284
3284
  isSync: true,
3285
3285
  hasJdRouter: false,
3286
3286
  });
3287
3287
  } else {
3288
3288
  return callRouterIOS({
3289
3289
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
3290
3290
  routerParam: getRouterParam,
3291
3291
  callBackName: getCallBackName,
3292
3292
  isSync: true,
3293
3293
  });
3294
3294
  }
3295
3295
  }),
3296
3296
  this.taskTimeoutPromise(() => {
3297
3297
  return {
3298
3298
  status: '-1000',
3299
3299
  msg: '原生router协议获取lbs地址信息3s超时',
3300
3300
  };
3301
3301
  }, 3000),
3302
3302
  ]);
3303
3303
  } else {
3304
3304
  return Promise.resolve({
3305
3305
  status: '-1001',
3306
3306
  msg: '鸿蒙系统调用未实现,获取失败',
3307
3307
  });
3308
3308
  }
3309
3309
  } else if (isH5AndJingGouMini) {
3310
3310
  return this.getLocationForGpsPromise();
3311
3311
  } else {
3312
3312
  return Promise.resolve({
3313
3313
  status: '-1002',
3314
3314
  msg: '普通h5暂无业务需要,未实现,获取失败',
3315
3315
  });
3316
3316
  }
3317
3317
  }
3318
3318
  getLocationForGpsPromise() {
3319
3319
  return new Promise((resolve) => {
3320
3320
  let hasGetLocationForGps = true;
3321
3321
  if (urlCookie && urlCookie['loc']) {
3322
3322
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
3323
3323
  urlCookie['loc'].split('_');
3324
3324
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3325
3325
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3326
3326
  hasGetLocationForGps = false;
3327
3327
  resolve({
3328
3328
  status: '0',
3329
3329
  data: {
3330
3330
  provinceid,
3331
3331
  cityid,
3332
3332
  districtid,
3333
3333
  townid,
3334
3334
  origin: 'wxapp',
3335
3335
  },
3336
3336
  });
3337
3337
  }
3338
3338
  }
3339
3339
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
3340
3340
  window.navigator.geolocation.getCurrentPosition(
3341
3341
  (position) => {
3342
3342
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
3343
3343
  if (position?.coords) {
3344
3344
  resolve({
3345
3345
  status: '0',
3346
3346
  data: {
3347
3347
  srclat: position.coords?.latitude,
3348
3348
  srclng: position.coords.longitude,
3349
3349
  origin: 'h5',
3350
3350
  },
3351
3351
  });
3352
3352
  } else {
3353
3353
  resolve({
3354
3354
  status: '-1001',
3355
3355
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
3356
3356
  position,
3357
3357
  });
3358
3358
  }
3359
3359
  },
3360
3360
  (error) => {
3361
3361
  resolve({
3362
3362
  status: '-1001',
3363
3363
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
3364
3364
  error,
3365
3365
  });
3366
3366
  },
3367
3367
  {
3368
3368
  enableHighAccuracy: false,
3369
3369
  timeout: 3 * 1000,
3370
3370
  maximumAge: 10 * 60 * 1000,
3371
3371
  },
3372
3372
  );
3373
3373
  } else {
3374
3374
  resolve({
3375
3375
  status: '-1001',
3376
3376
  msg: '您的浏览器不支持地理定位',
3377
3377
  });
3378
3378
  }
3379
3379
  });
3380
3380
  }
3381
3381
 
3382
3382
  createLbsCacheAddress(realTimeArea) {
3383
3383
  const getLbsAddressCacheMinuteTime = Number(
3384
3384
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
3385
3385
  );
3386
3386
  console.log(
3387
3387
  '获取lbs缓存到cookie的时间,分钟',
3388
3388
  getLbsAddressCacheMinuteTime,
3389
3389
  'lbsAddressCacheToCookieMinuteTime',
3390
3390
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
3391
3391
  );
3392
3392
  if (getLbsAddressCacheMinuteTime > 0) {
3393
3393
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
3394
3394
  realTimeArea &&
3395
3395
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
3396
3396
  path: '/',
3397
3397
  expires,
3398
3398
  });
3399
3399
  }
3400
3400
  }
3401
3401
 
3402
3402
  getLbsAddressCachePromise() {
3403
3403
  if (!this.lbsAddressCachePromise) {
3404
3404
  this.lbsAddressCachePromise = new Promise((resolve) => {
3405
3405
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
3406
3406
  ? cookie.get(cacheH5LbsAddressKey)
3407
3407
  : '';
3408
3408
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
3409
3409
  if (getUserLbsAddress && getUserLbsAddress !== '') {
3410
3410
  resolve({
3411
3411
  ok: true,
3412
3412
  realTimeArea: getUserLbsAddress,
3413
3413
  });
3414
3414
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
3415
3415
  console.info(
3416
3416
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
3417
3417
  getCookieForLbsAddress,
3418
3418
  );
3419
3419
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
3420
3420
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
3421
3421
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3422
3422
  realTimeArea: getCookieForLbsAddress,
3423
3423
  });
3424
3424
  resolve({
3425
3425
  ok: true,
3426
3426
  realTimeArea: getCookieForLbsAddress,
3427
3427
  });
3428
3428
  } else {
3429
3429
  this.getLbsCacheAddressRouter()
3430
3430
  .then((res) => {
3431
3431
  const { status, data } = res;
3432
3432
  console.log(
3433
3433
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
3434
3434
  status,
3435
3435
  data,
3436
3436
  res,
3437
3437
  );
3438
3438
  if (status === '0' && data) {
3439
3439
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
3440
3440
  data || {};
3441
3441
  let realTimeArea = '';
3442
3442
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
3443
3443
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
3444
3444
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3445
3445
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3446
3446
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
3447
3447
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
3448
3448
  this.info.sysInfo['realTimeArea'] = realTimeArea;
3449
3449
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3450
3450
  realTimeArea: this.info.pageInfo.userLbsAddress,
3451
3451
  });
3452
3452
  this.createLbsCacheAddress(realTimeArea);
3453
3453
  } else {
3454
3454
  !origin && (this.lbsAddressCachePromise = null);
3455
3455
  }
3456
3456
  const getValidRealTimeArea = realTimeArea !== '';
3457
3457
  resolve({
3458
3458
  lat: this.info.sysInfo['srclat'],
3459
3459
  lng: this.info.sysInfo['srclng'],
3460
3460
  realTimeArea: realTimeArea,
3461
3461
  ok: getValidRealTimeArea,
3462
3462
  msg: getValidRealTimeArea
3463
3463
  ? '成功'
3464
3464
  : origin
3465
3465
  ? origin
3466
3466
  : '根据router底层获取lbs地址信息异常,详情见data',
3467
3467
  data: getValidRealTimeArea ? null : res,
3468
3468
  });
3469
3469
  if (!getValidRealTimeArea && !origin) {
3470
3470
  draBusinessCustomReport({
3471
3471
  eventName: 'business',
3472
3472
  errorName: 'h5_getLbsCacheAddress_info_err',
3473
3473
  errorMessage:
3474
3474
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
3475
3475
  extraData: JSON.stringify({
3476
3476
  isJdApp,
3477
3477
  jdAppVersion: jdAppVersionStr,
3478
3478
  }),
3479
3479
  });
3480
3480
  }
3481
3481
  } else {
3482
3482
  typeof res === 'object' &&
3483
3483
  draBusinessCustomReport({
3484
3484
  eventName: 'business',
3485
3485
  errorName: 'h5_getLbsCacheAddress_info_err',
3486
3486
  errorMessage:
3487
3487
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
3488
3488
  extraData: JSON.stringify({
3489
3489
  isJdApp,
3490
3490
  jdAppVersion: jdAppVersionStr,
3491
3491
  ...res,
3492
3492
  }),
3493
3493
  });
3494
3494
  this.lbsAddressCachePromise = null;
3495
3495
  resolve({ realTimeArea: '', ok: false });
3496
3496
  }
3497
3497
  })
3498
3498
  .catch((e) => {
3499
3499
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
3500
3500
  this.lbsAddressCachePromise = null;
3501
3501
  draBusinessCustomReport({
3502
3502
  eventName: 'business',
3503
3503
  errorName: 'h5_getLbsCacheAddress_info_err',
3504
3504
  errorMessage:
3505
3505
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
3506
3506
  extraData: JSON.stringify({
3507
3507
  isJdApp,
3508
3508
  jdAppVersion: jdAppVersionStr,
3509
3509
  }),
3510
3510
  });
3511
3511
  resolve({ realTimeArea: '', ok: false });
3512
3512
  });
3513
3513
  }
3514
3514
  });
3515
3515
  }
3516
3516
  return this.lbsAddressCachePromise;
3517
3517
  }
3518
3518
 
3519
3519
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
3520
3520
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
3521
3521
  if (!isJdApp) {
3522
3522
  return;
3523
3523
  }
3524
3524
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
3525
3525
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
3526
3526
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
3527
3527
  'hybridHttpSwitch',
3528
3528
  isBeforePageReady,
3529
3529
  );
3530
3530
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
3531
3531
  'jshopIsVipShop',
3532
3532
  isBeforePageReady,
3533
3533
  );
3534
3534
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
3535
3535
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
3536
3536
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
3537
3537
  'isFollowAppVideoPlayStatus',
3538
3538
  isBeforePageReady,
3539
3539
  );
3540
3540
  console.log(
3541
3541
  'isBeforePageReady:',
3542
3542
  isBeforePageReady,
3543
3543
  'isFollowAppVideoPlayStatus:',
3544
3544
  isFollowAppVideoPlayStatus,
3545
3545
  );
3546
3546
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
3547
3547
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
3548
3548
  }
3549
3549
  }
3550
3550
 
3551
3551
  async getWifiVideoAutoPlayAsync() {
3552
3552
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
3553
3553
  if (!isJdApp) {
3554
3554
  return;
3555
3555
  }
3556
3556
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
3557
3557
  return 0;
3558
3558
  });
3559
3559
  if (Number(videoPlayStatus) === 1) {
3560
3560
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
3561
3561
  }
3562
3562
  }
3563
3563
 
3564
3564
  async getMPaasConfigAsync() {
3565
3565
  this.info.sysInfo.dynamicConfig = {};
3566
3566
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
3567
3567
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
3568
3568
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
3569
3569
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
3570
3570
  return this.updateMPaasConfigAsync(true);
3571
3571
  }
3572
3572
 
3573
3573
  getDynamicConfig(key: string) {
3574
3574
  return this.info.sysInfo?.dynamicConfig?.[key];
3575
3575
  }
3576
3576
  async updateMPaasConfig() {
3577
3577
  console.log('updateMPaasConfig');
3578
3578
  if (
3579
3579
  isIosDevice &&
3580
3580
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
3581
3581
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
3582
3582
  ) {
3583
3583
  try {
3584
3584
  await this.updateMPaasConfigAsync(false);
3585
3585
  } catch (e) {
3586
3586
  console.log('updateMPaasConfigAsync:', e);
3587
3587
  }
3588
3588
  }
3589
3589
  }
3590
3590
 
3591
3591
  toLogin(options) {
3592
3592
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
3593
3593
  ? this.toWxAppLogin(options)
3594
3594
  : this.toWebLogin(options);
3595
3595
  }
3596
3596
 
3597
3597
  doLogin(options) {
3598
3598
  return this.toLogin(options);
3599
3599
  }
3600
3600
 
3601
3601
  doLoginForJdPin(options = {}) {
3602
3602
  return this.doLogin({
3603
3603
  loginColor: {
3604
3604
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
3605
3605
  dpin: 0,
3606
3606
  },
3607
3607
  ...options,
3608
3608
  });
3609
3609
  }
3610
3610
 
3611
3611
  toWebLogin(options) {
3612
3612
  let params: {
3613
3613
  returnurl: string;
3614
3614
  } = {
3615
3615
  returnurl: '',
3616
3616
  };
3617
3617
  const checkToPcLogin = options ? options?.isPc : isPc;
3618
3618
  const loginUrl = checkToPcLogin
3619
3619
  ? `//passport.jd.com/new/login.aspx`
3620
3620
  : `${domain.mobileLogin}/user/login.action`;
3621
3621
  const defaultParams = {
3622
3622
  appid: '100',
3623
3623
  returnurl: window.location.href,
3624
3624
  };
3625
3625
  if (isString(options)) {
3626
3626
  params = Object.assign({}, defaultParams, {
3627
3627
  returnurl: options,
3628
3628
  });
3629
3629
  } else if (isObject(options)) {
3630
3630
  const { loginColor, ...otherOptions } = options;
3631
3631
  params = Object.assign({}, defaultParams, otherOptions);
3632
3632
  } else {
3633
3633
  params = defaultParams;
3634
3634
  }
3635
3635
  params.returnurl = encodeURIComponent(params.returnurl);
3636
3636
  let getFullUrl = loginUrl + '?' + serialize(params);
3637
3637
  if (checkToPcLogin) {
3638
3638
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
3639
3639
  }
3640
3640
  return Promise.resolve({
3641
3641
  h5ToUrl: true,
3642
3642
  url: getFullUrl,
3643
3643
  }).then(() => {
3644
3644
  window.location.href = getFullUrl;
3645
3645
  });
3646
3646
  }
3647
3647
 
3648
3648
  toWxAppLogin(options = {}) {
3649
3649
  console.log('微信京购小程序中h5登录跳转', options);
3650
3650
  return Promise.resolve(true).then(() => {
3651
3651
  const { loginColor } = Object.assign(
3652
3652
  {},
3653
3653
  {
3654
3654
  loginColor: {
3655
3655
  biz: WXAPP_BIZ_KEY,
3656
3656
  dpin: 1,
3657
3657
  },
3658
3658
  },
3659
3659
  options,
3660
3660
  );
3661
3661
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
3662
3662
  loginColor.biz
3663
3663
  }&url=${encodeURIComponent(window.location.href)}`;
3664
3664
  });
3665
3665
  }
3666
3666
 
3667
3667
  getLoginCookie() {
3668
3668
  return Promise.resolve({
3669
3669
  pin: cookie.get('pin') || '',
3670
3670
  });
3671
3671
  }
3672
3672
 
3673
3673
  clearLoginCookie() {
3674
3674
  cookie.remove('pin');
3675
3675
  }
3676
3676
 
3677
3677
  checkStatusAndLogin(options = {}) {
3678
3678
  if (!this.checkStatusAndLoginPromise) {
3679
3679
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
3680
3680
  try {
3681
3681
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
3682
3682
  if (getLoginState) {
3683
3683
  resolve(true);
3684
3684
  } else {
3685
3685
  this.toLogin(options);
3686
3686
  reject(false);
3687
3687
  }
3688
3688
  } catch (e) {
3689
3689
  this.toLogin(options);
3690
3690
  reject(false);
3691
3691
  }
3692
3692
  });
3693
3693
  return this.checkStatusAndLoginPromise;
3694
3694
  } else {
3695
3695
  return this.checkStatusAndLoginPromise
3696
3696
  .then(() => {
3697
3697
  return Promise.resolve(true);
3698
3698
  })
3699
3699
  .catch(() => {
3700
3700
  this.toLogin(options);
3701
3701
  return Promise.reject(true);
3702
3702
  });
3703
3703
  }
3704
3704
  }
3705
3705
 
3706
3706
  checkJdStatusAndLogin(
3707
3707
  options = {
3708
3708
  loginColor: {
3709
3709
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
3710
3710
  dpin: 0,
3711
3711
  },
3712
3712
  },
3713
3713
  ) {
3714
3714
  return this.checkStatusAndLogin(options);
3715
3715
  }
3716
3716
 
3717
3717
  doCheckLoginStateAndForApiCheck(options) {
3718
3718
  if (this.info.loginState) {
3719
3719
  return Promise.resolve(true);
3720
3720
  } else {
3721
3721
  return new Promise((resolve, reject) => {
3722
3722
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
3723
3723
  const getWqAuthToken = cookie.get('wq_auth_token');
3724
3724
  const getWqSkey = cookie.get('wq_skey');
3725
3725
  const getWqUin = cookie.get('wq_uin');
3726
3726
  const isLoginState =
3727
3727
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
3728
3728
  if (isLoginState) {
3729
3729
  this.info.loginState = true;
3730
3730
  resolve(true);
3731
3731
  } else {
3732
3732
  reject(false);
3733
3733
  }
3734
3734
  } else {
3735
3735
  Taro.request({
3736
3736
  url: api.isLogin,
3737
3737
  jsonp: true,
3738
3738
  timeout: 3000,
3739
3739
  success: (res) => {
3740
3740
  const { statusCode, data } = res;
3741
3741
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
3742
3742
  this.info.loginState = true;
3743
3743
  resolve(true);
3744
3744
  } else {
3745
3745
  reject(false);
3746
3746
  }
3747
3747
  },
3748
3748
  fail: (err) => {
3749
3749
  console.log('登录检查异常', err);
3750
3750
  reject(false);
3751
3751
  },
3752
3752
  });
3753
3753
  }
3754
3754
  });
3755
3755
  }
3756
3756
  }
3757
3757
 
3758
3758
  checkLoginStatus(options) {
3759
3759
  return new Promise(async (resolve, reject) => {
3760
3760
  try {
3761
3761
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
3762
3762
  if (getLoginState) {
3763
3763
  const { pin } = await this.getLoginCookie();
3764
3764
  this.info.userInfo = {
3765
3765
  pin,
3766
3766
  encodePin: encodeURIComponent(pin),
3767
3767
  ptkey: '',
3768
3768
  };
3769
3769
  resolve(true);
3770
3770
  } else {
3771
3771
  reject(false);
3772
3772
  }
3773
3773
  } catch (e) {
3774
3774
  reject(false);
3775
3775
  }
3776
3776
  });
3777
3777
  }
3778
3778
 
3779
3779
  updatePageAndLogInfo(updateQuery = {}) {
3780
3780
  const createUpdateQueryInfo: {
3781
3781
  query: {
3782
3782
  shopId?: string | number;
3783
3783
  venderId?: string | number;
3784
3784
  };
3785
3785
  updateShopInfoState: boolean;
3786
3786
  } = Object.assign(
3787
3787
  {},
3788
3788
  {
3789
3789
  query: {},
3790
3790
  updateShopInfoState: false,
3791
3791
  },
3792
3792
  updateQuery,
3793
3793
  );
3794
3794
  console.log(
3795
3795
  '获取当前下发的店铺查询参数',
3796
3796
  updateQuery,
3797
3797
  '获取之前保存的shopInfo店铺查询参数',
3798
3798
  this.info?.shopInfo,
3799
3799
  );
3800
3800
  const { query, updateShopInfoState } = createUpdateQueryInfo;
3801
3801
  const { shopId, venderId, un_area } = query;
3802
3802
  if (updateShopInfoState) {
3803
3803
  this.info.queryInfo = {
3804
3804
  ...this.info.queryInfo,
3805
3805
  ...query,
3806
3806
  };
3807
3807
  if (shopId && venderId) {
3808
3808
  this.info.shopInfo = {
3809
3809
  shopId: `${shopId}`,
3810
3810
  venderId: `${venderId}`,
3811
3811
  };
3812
3812
  }
3813
3813
  } else {
3814
3814
  this.info.queryInfo = {
3815
3815
  ...query,
3816
3816
  };
3817
3817
  if (
3818
3818
  this.info.shopInfo?.shopId &&
3819
3819
  this.info.shopInfo?.venderId &&
3820
3820
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
3821
3821
  ) {
3822
3822
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
3823
3823
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
3824
3824
  console.log(
3825
3825
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
3826
3826
  this.info.queryInfo,
3827
3827
  );
3828
3828
  }
3829
3829
  }
3830
3830
  this.info.queryInfo['shopId'] &&
3831
3831
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
3832
3832
  this.info.queryInfo['venderId'] &&
3833
3833
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
3834
3834
  console.log(
3835
3835
  'h5==获取店铺下发查询参数\n',
3836
3836
  query,
3837
3837
  '\n获取店铺最后查询参数\n',
3838
3838
  this.info.queryInfo,
3839
3839
  '\n是否为更新店铺状态\n',
3840
3840
  updateShopInfoState,
3841
3841
  );
3842
3842
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
3843
3843
  if (changeArea) {
3844
3844
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
3845
3845
  this.info.pageInfo.address = getBottomAreaStr;
3846
3846
  this.info.pageInfo.un_area = getBottomAreaStr;
3847
3847
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
3848
3848
  }
3849
3849
  }
3850
3850
 
3851
3851
  dealLoadSdkList() {
3852
3852
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
3853
3853
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
3854
3854
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
3855
3855
  let mergeLoadJsList = globalLoadJsList;
3856
3856
  try {
3857
3857
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
3858
3858
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
3859
3859
  getFindIndex !== -1
3860
3860
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
3861
3861
  : accArr.push(current);
3862
3862
  return accArr;
3863
3863
  }, []);
3864
3864
  } catch (e) {
3865
3865
  console.log('LoadJsList合并错误', e);
3866
3866
  }
3867
3867
  console.log(
3868
3868
  'globalLoadJsList',
3869
3869
  globalLoadJsList,
3870
3870
  'businessLoadJsList',
3871
3871
  businessLoadJsList,
3872
3872
  '两个加载jsList集合合并完成',
3873
3873
  mergeLoadJsList,
3874
3874
  );
3875
3875
  this.loadJsSdkList = mergeLoadJsList;
3876
3876
  return this.loadJsSdkList;
3877
3877
  }
3878
3878
 
3879
3879
  renderNextTickLoadSdk(delayTime = 1000) {
3880
3880
  Taro.nextTick(() => {
3881
3881
  console.log(
3882
3882
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
3883
3883
  );
3884
3884
  setTimeout(() => {
3885
3885
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
3886
3886
  }, delayTime);
3887
3887
  });
3888
3888
  }
3889
3889
 
3890
3890
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
3891
3891
  const getLoadJsList =
3892
3892
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
3893
3893
  const getLoadFilterList = getLoadJsList.filter((item) => {
3894
3894
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
3895
3895
  item.initLoadType = undefined;
3896
3896
  }
3897
3897
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
3898
3898
  let getLoastLoadEventState = true;
3899
3899
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
3900
3900
  getLoastLoadEventState = isJdApp;
3901
3901
  }
3902
3902
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
3903
3903
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
3904
3904
  }
3905
3905
  const getInitTriggerType =
3906
3906
  isJdApp && item?.initJdAppTriggerType
3907
3907
  ? item?.initTriggerType
3908
3908
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
3909
3909
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
3910
3910
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
3911
3911
  });
3912
3912
  console.log(
3913
3913
  '获取当前触发方式',
3914
3914
  triggerType,
3915
3915
  '获取当前最后加载的js集合',
3916
3916
  getLoadFilterList,
3917
3917
  '过滤前的加载集合',
3918
3918
  getLoadJsList,
3919
3919
  );
3920
3920
  const loadTasks =
3921
3921
  getLoadFilterList.length > 0
3922
3922
  ? getLoadFilterList.map((item) => {
3923
3923
  const isLoadState = /sgm/.test(item?.fileName)
3924
3924
  ? window?.shopGlobalSwitch?.openSgm === 'true'
3925
3925
  : true;
3926
3926
  if (!isLoadState) {
3927
3927
  return Promise.resolve(true);
3928
3928
  }
3929
3929
  return this.loadItemSdkPromise(item)
3930
3930
  .then((res) => {
3931
3931
  console.info('当前js地址' + item?.src, '加载状态', res);
3932
3932
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
3933
3933
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
3934
3934
  window.dra.run('init', { aid: res?.aid });
3935
3935
  window.dra.run('start');
3936
3936
  }
3937
3937
  return true;
3938
3938
  })
3939
3939
  .catch((err) => {
3940
3940
  console.info('当前js地址加载异常', item?.src);
3941
3941
  window?.fetchErrorData &&
3942
3942
  window.fetchErrorData({
3943
3943
  title: '公共js加载异常',
3944
3944
  type: 'jsLoad',
3945
3945
  data: err,
3946
3946
  });
3947
3947
  return true;
3948
3948
  });
3949
3949
  })
3950
3950
  : [];
3951
3951
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
3952
3952
  }
3953
3953
  loadScriptEle(jsInfo, resolve, reject) {
3954
3954
  const getFileName = jsInfo?.fileName;
3955
3955
  if (getFileName) {
3956
3956
  const getEleId = `J_loadJs_${getFileName}`;
3957
3957
  const getEle = document.getElementById(getEleId);
3958
3958
  if (!getEle) {
3959
3959
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3960
3960
  const _sgmEle = document.createElement('script');
3961
3961
  _sgmEle.id = getEleId;
3962
3962
  _sgmEle.onload = function () {
3963
3963
  resolve({
3964
3964
  ...jsInfo,
3965
3965
  jsTip: 'js加载成功',
3966
3966
  });
3967
3967
  };
3968
3968
  _sgmEle.onerror = function () {
3969
3969
  reject({
3970
3970
  ...jsInfo,
3971
3971
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3972
3972
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
3973
3973
  });
3974
3974
  };
3975
3975
  const dataAttrList = ['timeout', 'fileName', 'env'];
3976
3976
  const getJsInfoKeyList = Object.keys(jsInfo);
3977
3977
  getJsInfoKeyList.forEach((key) => {
3978
3978
  if (key === 'async') {
3979
3979
  _sgmEle.async = jsInfo[key];
3980
3980
  } else if (key === 'crossOrigin') {
3981
3981
  _sgmEle.crossOrigin = jsInfo[key];
3982
3982
  } else if (key === 'src') {
3983
3983
  _sgmEle.src = `${jsInfo[key]}`;
3984
3984
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
3985
3985
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
3986
3986
  } else {
3987
3987
  _sgmEle.setAttribute(key, jsInfo[key]);
3988
3988
  }
3989
3989
  });
3990
3990
  document.head.appendChild(_sgmEle);
3991
3991
  } else {
3992
3992
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
3993
3993
  resolve({
3994
3994
  ...jsInfo,
3995
3995
  jsTip: 'js本身已存在页面中',
3996
3996
  });
3997
3997
  }
3998
3998
  } else {
3999
3999
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
4000
4000
  }
4001
4001
  }
4002
4002
 
4003
4003
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
4004
4004
  if (jsInfo?.src) {
4005
4005
  const getInitLoadType =
4006
4006
  isJdApp && jsInfo?.initJdAppLoadType
4007
4007
  ? jsInfo?.initJdAppLoadType
4008
4008
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
4009
4009
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
4010
4010
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
4011
4011
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
4012
4012
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
4013
4013
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4014
4014
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4015
4015
  try {
4016
4016
  const jsXhrRequest = new XMLHttpRequest();
4017
4017
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
4018
4018
  const jsUrl = `${jsInfo?.src}`;
4019
4019
  jsXhrRequest.open('GET', jsUrl, true);
4020
4020
  jsXhrRequest.onreadystatechange = () => {
4021
4021
  if (jsXhrRequest.readyState === 4) {
4022
4022
  const getReqStatus = jsXhrRequest.status;
4023
4023
  const statusText = jsXhrRequest.statusText;
4024
4024
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4025
4025
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
4026
4026
  if (getInsetHeadState) {
4027
4027
  this.loadScriptEle(jsInfo, resolve, reject);
4028
4028
  } else {
4029
4029
  resolve({
4030
4030
  ...jsInfo,
4031
4031
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
4032
4032
  });
4033
4033
  }
4034
4034
  getReqStatus !== 200 &&
4035
4035
  draBusinessCustomReport({
4036
4036
  eventName: 'business',
4037
4037
  errorName: 'js_load_special_code',
4038
4038
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
4039
4039
  extraData: JSON.stringify({
4040
4040
  msg: '当前js加载成功,状态非200,特殊上报观察',
4041
4041
  jsReqState: getReqStatus,
4042
4042
  env: getSgmCustomCode('js_load_special_code'),
4043
4043
  data: jsInfo,
4044
4044
  }),
4045
4045
  });
4046
4046
  } else {
4047
4047
  const getRes = {
4048
4048
  ...jsInfo,
4049
4049
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4050
4050
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4051
4051
  jsReqState: getReqStatus,
4052
4052
  };
4053
4053
  console.log('当前js请求状态异常,具体信息见', getRes);
4054
4054
  reject(getRes);
4055
4055
  }
4056
4056
  }
4057
4057
  };
4058
4058
  jsXhrRequest.onerror = () => {
4059
4059
  const getRes = {
4060
4060
  ...jsInfo,
4061
4061
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4062
4062
  jsReqError: '请求错误',
4063
4063
  };
4064
4064
  console.log('当前js请求错误', getRes);
4065
4065
  jsXhrRequest.abort();
4066
4066
  reject(getRes);
4067
4067
  };
4068
4068
  jsXhrRequest.ontimeout = () => {
4069
4069
  const getRes = {
4070
4070
  ...jsInfo,
4071
4071
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4072
4072
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
4073
4073
  jsReqState: jsXhrRequest.status,
4074
4074
  };
4075
4075
  console.log('当前js请求超时异常', getRes);
4076
4076
  jsXhrRequest.abort();
4077
4077
  reject(getRes);
4078
4078
  };
4079
4079
  jsXhrRequest.send();
4080
4080
  } catch (e) {
4081
4081
  console.log('执行js请求异常', e);
4082
4082
  reject({
4083
4083
  ...jsInfo,
4084
4084
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4085
4085
  jsReqError: '未知异常',
4086
4086
  error: e,
4087
4087
  });
4088
4088
  }
4089
4089
  });
4090
4090
  } else {
4091
4091
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4092
4092
  return this.loadScriptEle(jsInfo, resolve, reject);
4093
4093
  });
4094
4094
  }
4095
4095
  }
4096
4096
  return this.loadJsSdkListCachePromise[getFileKeyName];
4097
4097
  } else {
4098
4098
  return Promise.resolve({
4099
4099
  ...jsInfo,
4100
4100
  jsTip: 'js加载方式设置为不加载,当前不做处理',
4101
4101
  });
4102
4102
  }
4103
4103
  } else {
4104
4104
  return Promise.reject(jsInfo);
4105
4105
  }
4106
4106
  }
4107
4107
 
4108
4108
  createLanguagePromise() {
4109
4109
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
4110
4110
  if (!this.languageCacheProimse) {
4111
4111
  this.languageCacheProimse = new Promise((resolve, reject) => {
4112
4112
  const { fileName, prefixUrl } = getLanguageConfig;
4113
4113
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
4114
4114
  const dealLanguageFile = () => {
4115
4115
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
4116
4116
  .then((res: any) => {
4117
4117
  if (res && res?.data) {
4118
4118
  this.languageJsonData = res.data;
4119
4119
 
4120
4120
  setTimeout(() => {
4121
4121
  const getOtherLanguageList = languageTypeList.filter(
4122
4122
  (item) => item !== languageNowType,
4123
4123
  );
4124
4124
  getOtherLanguageList.length > 0 &&
4125
4125
  getOtherLanguageList.map((languageTypeKey) => {
4126
4126
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
4127
4127
  });
4128
4128
  }, 3000);
4129
4129
  resolve(res);
4130
4130
  } else {
4131
4131
  reject(res);
4132
4132
  }
4133
4133
  })
4134
4134
  .catch((err) => {
4135
4135
  reject(err);
4136
4136
  });
4137
4137
  };
4138
4138
  if (fileName && prefixUrl) {
4139
4139
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
4140
4140
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
4141
4141
  if (getLocalLangRes) {
4142
4142
  try {
4143
4143
  const getLocalLangJsonData =
4144
4144
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
4145
4145
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
4146
4146
  if (getLocalLangJsonData?.fileName === fileName) {
4147
4147
  const geThisLangData = getLocalLangJsonData.data;
4148
4148
  this.languageJsonData = geThisLangData;
4149
4149
  return resolve({
4150
4150
  ...getLanguageConfig,
4151
4151
  languageNowType,
4152
4152
  data: geThisLangData,
4153
4153
  });
4154
4154
  } else {
4155
4155
  dealLanguageFile();
4156
4156
  }
4157
4157
  } else {
4158
4158
  dealLanguageFile();
4159
4159
  }
4160
4160
  } catch (e) {
4161
4161
  return reject({
4162
4162
  languageNowType,
4163
4163
  msg: '转换错误',
4164
4164
  ...getLanguageConfig,
4165
4165
  });
4166
4166
  }
4167
4167
  } else {
4168
4168
  dealLanguageFile();
4169
4169
  }
4170
4170
  } else {
4171
4171
  return reject({
4172
4172
  languageNowType,
4173
4173
  msg: '文件对象下发异常',
4174
4174
  ...getLanguageConfig,
4175
4175
  });
4176
4176
  }
4177
4177
  });
4178
4178
  }
4179
4179
  return this.languageCacheProimse;
4180
4180
  }
4181
4181
 
4182
4182
  getLanguageFilePromise(info, languageTypeKey) {
4183
4183
  const { fileName, prefixUrl, timeout } = info || {};
4184
4184
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
4185
4185
  return new Promise((resolve, reject) => {
4186
4186
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
4187
4187
  try {
4188
4188
  const langXhrRequest = new XMLHttpRequest();
4189
4189
  langXhrRequest.timeout = timeout || 2000;
4190
4190
  langXhrRequest.open('GET', getUrl, true);
4191
4191
  langXhrRequest.responseType = 'json';
4192
4192
  langXhrRequest.onreadystatechange = () => {
4193
4193
  if (langXhrRequest.readyState === 4) {
4194
4194
  const getReqStatus = langXhrRequest.status;
4195
4195
  const statusText = langXhrRequest.statusText;
4196
4196
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4197
4197
  const getData = langXhrRequest?.response || false;
4198
4198
  if (getData) {
4199
4199
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
4200
4200
  fileName,
4201
4201
  data: getData,
4202
4202
  });
4203
4203
  resolve({
4204
4204
  ...info,
4205
4205
  languageTypeKey,
4206
4206
  data: getData,
4207
4207
  });
4208
4208
  } else {
4209
4209
  reject({
4210
4210
  ...info,
4211
4211
  languageTypeKey,
4212
4212
  msg: '数据获取异常',
4213
4213
  });
4214
4214
  }
4215
4215
  } else {
4216
4216
  const getRes = {
4217
4217
  ...info,
4218
4218
  languageTypeKey,
4219
4219
  env: getSgmCustomCode(langLoadErrorSgmCode),
4220
4220
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4221
4221
  };
4222
4222
  console.log('当前lang请求状态异常,具体信息见', getRes);
4223
4223
  reject(getRes);
4224
4224
  }
4225
4225
  }
4226
4226
  };
4227
4227
  langXhrRequest.onerror = () => {
4228
4228
  const getRes = {
4229
4229
  ...info,
4230
4230
  env: getSgmCustomCode(langLoadErrorSgmCode),
4231
4231
  msg: '请求错误',
4232
4232
  };
4233
4233
  console.log('当前lang请求错误', getRes);
4234
4234
  langXhrRequest.abort();
4235
4235
  reject(getRes);
4236
4236
  };
4237
4237
  langXhrRequest.ontimeout = () => {
4238
4238
  const getRes = {
4239
4239
  ...info,
4240
4240
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
4241
4241
  };
4242
4242
  console.log('执行lang多语言请求超时异常', getRes);
4243
4243
  langXhrRequest.abort();
4244
4244
  reject(getRes);
4245
4245
  };
4246
4246
  langXhrRequest.send();
4247
4247
  } catch (e) {
4248
4248
  console.log('执行lang多语言请求异常', e);
4249
4249
  reject({
4250
4250
  ...info,
4251
4251
  env: getSgmCustomCode(langLoadErrorSgmCode),
4252
4252
  msg: '未知异常',
4253
4253
  error: e,
4254
4254
  });
4255
4255
  }
4256
4256
  });
4257
4257
  }