@conecli/cone-render 0.10.1-shop3.34 → 0.10.1-shop3.36

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