@conecli/cone-render 0.8.20-shop.228 → 0.8.20-shop.229

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