@conecli/cone-render 0.10.1-shop3.97 → 0.10.1-shop3.99

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