@conecli/cone-render 0.10.1-shop3.10 → 0.10.1-shop3.12

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
  BUSINESS_TYPE,
15
14
  LoadJsInitLoadEnvType,
16
15
  LoadJsInitLoadType,
17
16
  LoadJsInitTriggerType,
18
17
  MPAAS_CONFIG_APP_LOW_VERSION,
19
18
  MPAAS_CONFIG_APP_VERSION,
20
19
  SECTION_HOME_TAB_NAME_TYPE,
21
20
  SECTION_HOME_TAB_TYPE,
22
21
  TaroEventType,
23
22
  WX_BUSINESS_TYPE,
24
23
  WXAPP_BIZ_KEY,
25
24
  WXAPP_BIZ_SHOP_LIGHT_KEY,
26
25
  getSystemInfos,
27
26
  getTaroStorageKeyValue,
28
27
  ipLoc_djd,
29
28
  setTaroStorage,
30
29
  sgmCustomReport,
31
30
  abTestLabels: {},
32
31
  loginState: false,
33
32
  cookiesStr: '',
34
33
  userInfo: userPinKey,
35
34
  isJingGouMiniViewState: false,
36
35
  isJingxiMiniViewState: false,
37
36
  pageInfo: {
38
37
  wxBusinessType: WX_BUSINESS_TYPE.NO,
39
38
  address: '',
40
39
  addressCommaStr: '',
41
40
  un_area: '',
42
41
  vapptype: '1',
43
42
  pageType: 'home',
44
43
  isExposureState: false,
45
44
  moduleId: '',
46
45
  entrance: '',
47
46
  dataType: BUSINESS_TYPE.ONLINE,
48
47
  floorExposureInfo: {},
49
48
  floorVideInfo: {},
50
49
  productVideInfo: {},
51
50
  tabsLoadAllDataInfo: {
52
51
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
53
52
  },
54
53
  updateShopInfosAllState: false,
55
54
  isVipShop: false,
56
55
  isJdShowNativeImmersivePlayer: false,
57
56
  ...shopConfig,
58
57
  pageScrollTop: 0,
59
58
  pageIdxHeightInfo: {
60
59
  list: [],
61
60
  },
62
61
  shopNavBarHeight: 0,
63
62
  },
64
63
  defaultQueryLogInfo: {
65
64
  sourceType: 'JDshop',
66
65
  sourceValue: '',
67
66
  moduleId: 'none',
68
67
  entrance: 'none',
69
68
  },
70
69
  sysInfo: {
71
70
  windowWidth: isPc ? 375 : 0,
72
71
  containerWidth: isPc ? 375 : 0,
73
72
  windowHeight: 0,
74
73
  netWorkType: '4g',
75
74
  jdBottomBarHeight: 0,
76
75
  jdNativeHeaderHeight: 0,
77
76
  isJdTabletDevice: false,
78
77
  isJdTabletLandscape: false,
79
78
  },
80
79
  queryInfo: {},
81
80
  shopInfo: {},
82
81
  openAppData: {},
83
82
  public info: CommonInterFace.BaseConfigInfo;
84
83
  public config: {
85
84
  [key: string]: any;
86
85
  };
87
86
  public lazyContainer: CommonInterFace.lazyContainer;
88
87
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
89
88
  public rootEleNode: HTMLElement | null;
90
89
  public checkStatusAndLoginPromise: object | null;
91
90
  private jmfeRegisterStatePromise: Promise<any> | null;
92
91
  private jdScreenSizeInfoPromise: Promise<any> | null;
93
92
  private rootEleWidthRegisterPromise: Promise<any> | null;
94
93
  private jmfeRegisterState: boolean;
95
94
  public loadJsSdkList: Array<any>;
96
95
  public loadJsSdkListCachePromise: any;
97
96
  public rootEleInitWidth: number;
98
97
  constructor(opt) {
99
98
  this.info = this._getConfig(opt);
100
99
  this.config = {};
101
100
  this.loadJsSdkList = [];
102
101
  this.loadJsSdkListCachePromise = {};
103
102
  this.lazyContainer = {
104
103
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
105
104
  appLazyContainerList: [],
106
105
  appLazyFinishContainerList: [],
107
106
  },
108
107
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
109
108
  appLazyContainerList: [],
110
109
  appLazyFinishContainerList: [],
111
110
  },
112
111
  };
113
112
  this.renderedIsvComponents = {};
114
113
  this.rootEleNode = document.querySelector('body');
115
114
  this.checkStatusAndLoginPromise = null;
116
115
  this.jmfeRegisterStatePromise = null;
117
116
  this.jdScreenSizeInfoPromise = null;
118
117
  this.rootEleWidthRegisterPromise = null;
119
118
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
120
119
  this.loadOtherSdk();
121
120
  if (isJdApp) {
122
121
  this.jmfeReayPromise();
123
122
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
124
123
  }
125
124
  }
126
125
  _getConfig(opt) {
127
126
  return Object.assign({}, DefaultConfig, opt);
128
127
  }
129
128
  _getJdPadMinWidthForListen() {
130
129
  return (
131
130
  isJdApp &&
132
131
  Math.min(window.screen.width, window.screen.height) >
133
132
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
134
133
  );
135
134
  }
136
135
 
137
136
  jmfeReayPromise(): Promise<any> {
138
137
  if (isJdApp) {
139
138
  if (this.jmfeRegisterState) {
140
139
  return Promise.resolve(true);
141
140
  } else {
142
141
  !this.jmfeRegisterStatePromise &&
143
142
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
144
143
  ready('jmfe', 3000)
145
144
  .then(() => {
146
145
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
147
146
  this.jmfeRegisterState = true;
148
147
  resolve(true);
149
148
  console.log('松果app内初始化注册jmfe认证完成');
150
149
  })
151
150
  .catch((err) => {
152
151
  console.error('jmfe ready error', err);
153
152
  reject(false);
154
153
  });
155
154
  }));
156
155
  return this.jmfeRegisterStatePromise;
157
156
  }
158
157
  } else {
159
158
  return Promise.reject(false);
160
159
  }
161
160
  }
162
161
 
163
162
  getJdScreenSizeInfoPromise() {
164
163
  !this.jdScreenSizeInfoPromise &&
165
164
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
166
165
  const getThisTime = Date.now();
167
166
  this.jmfeReayPromise().then(() => {
168
167
  return Promise.race([
169
168
  window.jmfe.getScreenSize(),
170
169
  this.taskTimeoutPromise(() => {
171
170
  return {
172
171
  status: '-10',
173
172
  msg: '获取大屏信息2s超时',
174
173
  };
175
174
  }),
176
175
  ])
177
176
  .then((res) => {
178
177
  console.warn('===获取app大屏信息====', res);
179
178
  const { status, data } = res;
180
179
  if (status === '0' && data) {
181
180
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
182
181
  const getPageInfo = dealNativePixelToCssPixel({
183
182
  pageWidth,
184
183
  pageHeight,
185
184
  });
186
185
  this.info.sysInfo.jdScreenSizeType = sizeType;
187
186
  const getUseTime = Date.now() - getThisTime;
188
187
  console.warn(
189
188
  '===计算是否是app大屏信息,需满足宽度最新720===',
190
189
  getPageInfo,
191
190
  '原始数据',
192
191
  data,
193
192
  '是否是横屏isLandscape为1=',
194
193
  isLandscape,
195
194
  '用时',
196
195
  getUseTime,
197
196
  );
198
197
  if (getPageInfo?.pageWidth > 0) {
199
198
  this.rootEleInitWidth = getPageInfo?.pageWidth;
200
199
  draBusinessCustomReport({
201
200
  type: 'rootEle_width_getJdScreenSizeInfo',
202
201
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
203
202
  originReqDataStr: JSON.stringify({
204
203
  isJdApp,
205
204
  getPageInfo,
206
205
  originData: res,
207
206
  }),
208
207
  });
209
208
  resolve(getPageInfo);
210
209
  } else {
211
210
  resolve({
212
211
  pageWidth: 0,
213
212
  pageHeight: 0,
214
213
  msg: '转换异常',
215
214
  });
216
215
  }
217
216
  } else {
218
217
  resolve({
219
218
  pageWidth: 0,
220
219
  pageHeight: 0,
221
220
  msg: '获取大屏信息异常或者超时',
222
221
  });
223
222
  }
224
223
  })
225
224
  .catch((err) => {
226
225
  console.log('获取大屏信息异常', err);
227
226
  resolve({
228
227
  pageWidth: 0,
229
228
  pageHeight: 0,
230
229
  msg: '获取大屏信息异常',
231
230
  });
232
231
  });
233
232
  });
234
233
  }));
235
234
  return this.jdScreenSizeInfoPromise;
236
235
  }
237
236
 
238
237
  listenJdTabletScreenChange() {
239
238
  this.jmfeReayPromise().then(() => {
240
239
  try {
241
240
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
242
241
  window.jmfe.listenDeviceScreenChange((event) => {
243
242
  console.log(
244
243
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
245
244
  event,
246
245
  '通过前端判断是不是横屏',
247
246
  window.matchMedia('(orientation: landscape)')?.matches,
248
247
  );
249
248
  const { orientation } = event?.data;
250
249
  if (orientation) {
251
250
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
252
251
  Taro.eventCenter.trigger(
253
252
  TaroEventType.TABLE_SCREEN_CHANGE,
254
253
  this.info.sysInfo.isJdTabletLandscape,
255
254
  orientation,
256
255
  );
257
256
  }
258
257
  });
259
258
  } catch (error) {
260
259
  console.log('listenScreenChange的打印error:', error);
261
260
  }
262
261
  });
263
262
  }
264
263
 
265
264
  updateBusinessDomainAndApi(domain, api) {
266
265
  }
267
266
 
268
267
  formatNativeScreenPageData(action) {
269
268
  let getChangePageInfo: any = null;
270
269
  try {
271
270
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
272
271
  JSON.stringify({
273
272
  plugin: 'JDHybridScreenPlugin',
274
273
  action,
275
274
  sync: '1',
276
275
  }),
277
276
  );
278
277
  const getChangePageInfoData =
279
278
  typeof getNativeScreenPageInfoStr === 'string'
280
279
  ? JSON.parse(getNativeScreenPageInfoStr)
281
280
  : null;
282
281
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
283
282
  const { code, data } = getChangePageInfoData;
284
283
  getChangePageInfo = code && code === '0' ? data : null;
285
284
  }
286
285
  } catch (e) {
287
286
  console.log('JDHybridScreenPlugin转换异常', e);
288
287
  }
289
288
  return getChangePageInfo;
290
289
  }
291
290
 
292
291
  isAndroidFoldScreen() {
293
292
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
294
293
  }
295
294
 
296
295
  getJdAndroidPageChangeScreenInfo() {
297
296
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
298
297
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
299
298
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
300
299
  pageWidth: getPageScreenInfo.pageWidth,
301
300
  pageHeight: getPageScreenInfo.pageHeight,
302
301
  });
303
302
  getPageScreenInfo.pageWidth = pageWidth;
304
303
  getPageScreenInfo.pageHeight = pageHeight;
305
304
  }
306
305
  return getPageScreenInfo;
307
306
  }
308
307
 
309
308
  getRootEleWindowWidthInfo() {
310
309
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
311
310
  const getWindowWidth = window.innerWidth;
312
311
  const getScreenWidth = window.screen.width;
313
312
  return {
314
313
  getRootEleWidth,
315
314
  getWindowWidth,
316
315
  getScreenWidth,
317
316
  };
318
317
  }
319
318
 
320
319
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
321
320
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
322
321
  console.log(
323
322
  '当前获取根元素的宽度',
324
323
  getRootEleWidth,
325
324
  'getWindowWidth',
326
325
  getWindowWidth,
327
326
  'getScreenWidth',
328
327
  getScreenWidth,
329
328
  );
330
329
  const getLastWidth =
331
330
  getRootEleWidth > 0
332
331
  ? Math.round(getRootEleWidth)
333
332
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
334
333
  console.warn(
335
334
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
336
335
  );
337
336
  timeout > 0 &&
338
337
  draBusinessCustomReport({
339
338
  type: 'rootEle_width_timeout_getJdScreenSizeInfo',
340
339
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
341
340
  originReqDataStr: JSON.stringify({
342
341
  isJdApp,
343
342
  getRootEleWidth,
344
343
  getWindowWidth,
345
344
  getScreenWidth,
346
345
  ...reportParam,
347
346
  }),
348
347
  });
349
348
  return getLastWidth;
350
349
  }
351
350
 
352
351
  getPadWindowRootEleWidthPromise() {
353
352
  if (this.rootEleInitWidth > 0) {
354
353
  return Promise.resolve(this.rootEleInitWidth);
355
354
  } else {
356
355
  !this.rootEleWidthRegisterPromise &&
357
356
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
358
357
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
359
358
  if (getRootEleInitWidth > 0) {
360
359
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
361
360
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
362
361
  resolve(this.rootEleInitWidth);
363
362
  } else {
364
363
  const timerPromise = () => {
365
364
  return new Promise((resolve2) => {
366
365
  window.setTimeout(() => {
367
366
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
368
367
  this.getRootEleWindowWidthInfo();
369
368
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
370
369
  console.warn(
371
370
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
372
371
  );
373
372
  draBusinessCustomReport({
374
373
  type: 'rootEle_width_200_timeout_info',
375
374
  errMsg: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
376
375
  originReqDataStr: JSON.stringify({
377
376
  isJdApp,
378
377
  getRootEleWidth,
379
378
  getWindowWidth,
380
379
  getScreenWidth,
381
380
  }),
382
381
  });
383
382
  const getRes =
384
383
  getRootEleWidth > 0 && getWindowWidth > 0
385
384
  ? Math.min(getRootEleWidth, getWindowWidth)
386
385
  : Math.max(getRootEleWidth, getWindowWidth);
387
386
  resolve2({
388
387
  pageWidth: Math.round(getRes),
389
388
  });
390
389
  }
391
390
  }, 200);
392
391
  });
393
392
  };
394
393
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
395
394
  const { pageWidth } = res;
396
395
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
397
396
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
398
397
  });
399
398
  }
400
399
  }));
401
400
  return this.rootEleWidthRegisterPromise;
402
401
  }
403
402
  }
404
403
 
405
404
  async getSystemInfo(params) {
406
405
  const getParams = Object.assign({}, params || {});
407
406
  if (this.rootEleInitWidth > 0) {
408
407
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
409
408
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
410
409
  } else {
411
410
  if (this._getJdPadMinWidthForListen()) {
412
411
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
413
412
  getParams['replaceSystemWidth'] = true;
414
413
  }
415
414
  }
416
415
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
417
416
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
418
417
  let _isfoldScreen = false;
419
418
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
420
419
  console.info(
421
420
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
422
421
  getStorageData,
423
422
  '通过缓存值第一次判断是否是折叠屏',
424
423
  getStorageData === 'true',
425
424
  );
426
425
  if (!getStorageData) {
427
426
  _isfoldScreen = this.isAndroidFoldScreen();
428
427
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
429
428
  } else {
430
429
  _isfoldScreen = getStorageData === 'true';
431
430
  }
432
431
  if (_isfoldScreen) {
433
432
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
434
433
  if (getJdAndroidPageInfo) {
435
434
  info = getSystemInfos(getJdAndroidPageInfo);
436
435
  console.warn(
437
436
  '当前为松果安卓折叠屏app,获取折叠屏信息',
438
437
  getJdAndroidPageInfo,
439
438
  '获取转换后的系统信息',
440
439
  info,
441
440
  );
442
441
  sgmCustomReport({
443
442
  type: 2,
444
443
  code: 'android_jdapp_foldScreen_info',
445
444
  msg: {
446
445
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
447
446
  androidPageInfo: getJdAndroidPageInfo,
448
447
  jdAppVersionStr,
449
448
  taroSysInfo: info,
450
449
  },
451
450
  });
452
451
  }
453
452
  }
454
453
  }
455
454
  if (isJdApp) {
456
455
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
457
456
  }
458
457
  this.info.sysInfo = {
459
458
  actualNavBarHeight: 0,
460
459
  ...this.info.sysInfo,
461
460
  ...info,
462
461
  safeContentHeight: info?.screenHeight,
463
462
  headerHeight: 0,
464
463
  tabBarHeight: 0,
465
464
  };
466
465
  if (isJdApp) {
467
466
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
468
467
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
469
468
  this.getAddressCachePromise();
470
469
  this.getElderModePromise();
471
470
  this.getJDAppearanceStatePromise();
472
471
  this.createJdAndroidRquestEventForTouchStart();
473
472
  }
474
473
  this.getWifiVideoAutoPlayAsync();
475
474
  this.getMPaasConfigAsync();
476
475
  this.getNetWorkType();
477
476
  }
478
477
 
479
478
  taskTimeoutPromise(callBack, timeout = 2000) {
480
479
  return new Promise((resolve) => {
481
480
  setTimeout(() => {
482
481
  const getCallBackRes = typeof callBack === 'function' && callBack();
483
482
  return resolve(getCallBackRes || false);
484
483
  }, timeout);
485
484
  });
486
485
  }
487
486
 
488
487
  getElderModePromise() {
489
488
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
490
489
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
491
490
  } else {
492
491
  if (isJdAndAndroidDevice) {
493
492
  this.info.sysInfo.jdAppModeType = '0';
494
493
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
495
494
  } else {
496
495
  return Promise.race([
497
496
  this.taskTimeoutPromise(() => {
498
497
  this.info.sysInfo.jdAppModeType = '0';
499
498
  return this.info.sysInfo.jdAppModeType;
500
499
  }),
501
500
  new Promise((resolve) => {
502
501
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
503
502
  if (!window[getCallBackName]) {
504
503
  window[getCallBackName] = (res) => {
505
504
  try {
506
505
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
507
506
  const { status, data, msg } = getResJson;
508
507
  console.log(`获取松果app展示模式成功,返回结果${data}`);
509
508
  if (status === '0') {
510
509
  this.info.sysInfo.jdAppModeType = data;
511
510
  resolve(data);
512
511
  } else {
513
512
  resolve('0');
514
513
  }
515
514
  } catch (e) {
516
515
  resolve('0');
517
516
  }
518
517
  window[getCallBackName] = null;
519
518
  };
520
519
  }
521
520
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
522
521
  method: 'callSyncRouterModuleWithParams',
523
522
  params: JSON.stringify({
524
523
  routerURL: 'router://JDBModeModule/getCurrentMode',
525
524
  routerParam: {},
526
525
  callBackName: `window.${getCallBackName}`,
527
526
  callBackId: `${getCallBackName}Ios`,
528
527
  }),
529
528
  });
530
529
  }),
531
530
  ]);
532
531
  }
533
532
  }
534
533
  }
535
534
  getAPPUseStraightCorner() {
536
535
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
537
536
  const params = {
538
537
  routerURL,
539
538
  routerParam: {},
540
539
  jdRouter: '1',
541
540
  };
542
541
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
543
542
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
544
543
  } else {
545
544
  return this.jmfeReayPromise()
546
545
  .then(() => {
547
546
  if (isJdAndHarmonyDevice || !isJdApp) {
548
547
  console.log('not APP or is Harmony');
549
548
  return Promise.resolve(false);
550
549
  }
551
550
  console.log('jmfe setShareInfo', params);
552
551
  return Promise.race([
553
552
  window.jmfe.callRouter(params),
554
553
  this.taskTimeoutPromise(() => {
555
554
  return false;
556
555
  }),
557
556
  ]).then(({ status, data }) => {
558
557
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
559
558
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
560
559
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
561
560
  return Promise.resolve(status === '0' && Number(data) === 1);
562
561
  });
563
562
  })
564
563
  .catch((e) => {
565
564
  console.log('jmfe error', e);
566
565
  return Promise.resolve(false);
567
566
  });
568
567
  }
569
568
  }
570
569
 
571
570
  getJDAppearanceStatePromise() {
572
571
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
573
572
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
574
573
  } else {
575
574
  return Promise.race([
576
575
  this.taskTimeoutPromise(() => {
577
576
  this.info.sysInfo.jdAppearanceState = '0';
578
577
  return this.info.sysInfo.jdAppearanceState;
579
578
  }),
580
579
  new Promise((resolve) => {
581
580
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
582
581
  if (!window[getCallBackName]) {
583
582
  window[getCallBackName] = (res) => {
584
583
  try {
585
584
  console.log('getJDAppearanceStatePromise', res);
586
585
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
587
586
  const { status, data, msg } = getResJson;
588
587
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
589
588
  if (status === '0') {
590
589
  this.info.sysInfo.jdAppearanceState = data;
591
590
  resolve(data);
592
591
  } else {
593
592
  resolve('0');
594
593
  }
595
594
  } catch (e) {
596
595
  resolve('0');
597
596
  }
598
597
  window[getCallBackName] = null;
599
598
  };
600
599
  }
601
600
  if (isAndroidDevice) {
602
601
  const jsonString = JSON.stringify({
603
602
  callBackName: `window.${getCallBackName}`,
604
603
  });
605
604
  console.log('window.JDAppearance', window?.JDAppearance);
606
605
  window?.JDAppearance &&
607
606
  window?.JDAppearance?.getUiState &&
608
607
  window.JDAppearance.getUiState(jsonString);
609
608
  } else {
610
609
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
611
610
  method: 'callSyncRouterModuleWithParams',
612
611
  params: JSON.stringify({
613
612
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
614
613
  routerParam: {},
615
614
  callBackName: `window.${getCallBackName}`,
616
615
  callBackId: `${getCallBackName}Ios`,
617
616
  }),
618
617
  });
619
618
  }
620
619
  }),
621
620
  ]);
622
621
  }
623
622
  }
624
623
 
625
624
  createJdAndroidRquestEventForTouchStart() {
626
625
  if (isJdAndAndroidDevice && window?.JdAndroid) {
627
626
  const rootEleNode = document.querySelector('body');
628
627
  if (rootEleNode) {
629
628
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
630
629
  }
631
630
  }
632
631
  }
633
632
  jdAndroidAddEventListenerTouchStart(e) {
634
633
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
635
634
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
636
635
  const hasCustomEle = e
637
636
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
638
637
  : false;
639
638
  if (!hasCustomEle) {
640
639
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
641
640
  console.log(
642
641
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
643
642
  );
644
643
  }
645
644
  }
646
645
  }
647
646
  removeJdAndroidRquestEventForTouchStart() {
648
647
  if (isJdAndAndroidDevice && window.JdAndroid) {
649
648
  const rootEleNode = document.querySelector('body');
650
649
  if (rootEleNode) {
651
650
  rootEleNode.removeEventListener(
652
651
  'touchstart',
653
652
  this.jdAndroidAddEventListenerTouchStart,
654
653
  false,
655
654
  );
656
655
  }
657
656
  }
658
657
  }
659
658
 
660
659
  getNetWorkType() {
661
660
  if (isJdApp) {
662
661
  this.jmfeReayPromise().then(() => {
663
662
  window.jmfe
664
663
  .getNetworkStatus()
665
664
  .then(({ status, data }) => {
666
665
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
667
666
  if (status === '0') {
668
667
  this.info.sysInfo['netWorkType'] = data;
669
668
  } else {
670
669
  this._taroGetNetworkType();
671
670
  }
672
671
  })
673
672
  .catch((err) => {
674
673
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
675
674
  this._taroGetNetworkType();
676
675
  });
677
676
  });
678
677
  } else {
679
678
  this._taroGetNetworkType();
680
679
  }
681
680
  }
682
681
  _taroGetNetworkType() {
683
682
  Taro.getNetworkType().then((getRes) => {
684
683
  if (getRes && getRes.networkType) {
685
684
  this.info.sysInfo['netWorkType'] = getRes.networkType;
686
685
  console.log(
687
686
  '在app内通过taro对象获取网络状态完成,当前网络状态',
688
687
  this.info.sysInfo['netWorkType'],
689
688
  );
690
689
  }
691
690
  });
692
691
  }
693
692
 
694
693
  getCacheAddressRouter() {
695
694
  if (window.jmfe && isJdApp) {
696
695
  if (!isJdAndHarmonyDevice) {
697
696
  return Promise.race([
698
697
  window.jmfe.callRouter({
699
698
  jdRouter: '1',
700
699
  routerURL: isAndroidDevice
701
700
  ? 'router://JDAddressModule/getCacheAddress'
702
701
  : 'router://JDBAddressCacheManagerModule/getCacheAddress',
703
702
  routerParam: { sceneId: 'basicShoppingProcess' },
704
703
  }),
705
704
  this.taskTimeoutPromise(() => {
706
705
  return {
707
706
  status: '-1000',
708
707
  msg: '原生router协议获取地址信息超时',
709
708
  };
710
709
  }, 3000),
711
710
  ]);
712
711
  } else {
713
712
  return Promise.resolve({
714
713
  status: '-1001',
715
714
  msg: '鸿蒙系统调用jmfe异常,获取失败',
716
715
  });
717
716
  }
718
717
  } else {
719
718
  return Promise.resolve({
720
719
  status: '-1002',
721
720
  msg: 'jmfe不存在,获取失败',
722
721
  });
723
722
  }
724
723
  }
725
724
 
726
725
  getAddressCachePromise() {
727
726
  return new Promise((resolve) => {
728
727
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
729
728
  resolve({
730
729
  lat: this.info.sysInfo.lat,
731
730
  lng: this.info.sysInfo.lng,
732
731
  area: this?.info?.sysInfo?.area,
733
732
  });
734
733
  } else {
735
734
  this.jmfeReayPromise()
736
735
  .then(() => {
737
736
  this.getCacheAddressRouter()
738
737
  .then((res) => {
739
738
  const { status, data } = res;
740
739
  console.log('原生端获取经纬度原始数据结果', status, data);
741
740
  if (status === '0' && data) {
742
741
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
743
742
  data || {};
744
743
  let area = '';
745
744
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
746
745
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
747
746
  if (provinceId) {
748
747
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
749
748
  this.info.pageInfo['address'] = area;
750
749
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
751
750
  Taro.eventCenter.trigger(
752
751
  TaroEventType.USER_AREA_UPDATE,
753
752
  this.info.pageInfo.address,
754
753
  );
755
754
  }
756
755
  resolve({
757
756
  lat: this.info.sysInfo['lat'],
758
757
  lng: this.info.sysInfo['lng'],
759
758
  area: area,
760
759
  });
761
760
  } else {
762
761
  typeof res === 'object' &&
763
762
  sgmCustomReport({
764
763
  type: 3,
765
764
  code: 'jdapp_getCacheAddress_info',
766
765
  msg: {
767
766
  title: '松果app内通过router协议获取用户地址及经纬度信息异常',
768
767
  jdAppVersion: jdAppVersionStr,
769
768
  ...res,
770
769
  },
771
770
  });
772
771
  resolve({ lat: '', lng: '', area: '' });
773
772
  }
774
773
  })
775
774
  .catch((e) => {
776
775
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e);
777
776
  resolve({ lat: '', lng: '', area: '' });
778
777
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
779
778
  });
780
779
  })
781
780
  .catch((e) => {
782
781
  resolve({ lat: '', lng: '', area: '' });
783
782
  console.log('判断jmfe不存在,获取经纬度信息异常e', e);
784
783
  });
785
784
  }
786
785
  });
787
786
  }
788
787
 
789
788
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
790
789
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
791
790
  if (!isJdApp) {
792
791
  return;
793
792
  }
794
793
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
795
794
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
796
795
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
797
796
  'hybridHttpSwitch',
798
797
  isBeforePageReady,
799
798
  );
800
799
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
801
800
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
802
801
  'isFollowAppVideoPlayStatus',
803
802
  isBeforePageReady,
804
803
  );
805
804
  console.log(
806
805
  'isBeforePageReady:',
807
806
  isBeforePageReady,
808
807
  'isFollowAppVideoPlayStatus:',
809
808
  isFollowAppVideoPlayStatus,
810
809
  );
811
810
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
812
811
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
813
812
  }
814
813
  }
815
814
 
816
815
  async getWifiVideoAutoPlayAsync() {
817
816
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
818
817
  if (!isJdApp) {
819
818
  return;
820
819
  }
821
820
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
822
821
  return 0;
823
822
  });
824
823
  if (Number(videoPlayStatus) === 1) {
825
824
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
826
825
  }
827
826
  }
828
827
 
829
828
  async getMPaasConfigAsync() {
830
829
  this.info.sysInfo.dynamicConfig = {};
831
830
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
832
831
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
833
832
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
834
833
  return this.updateMPaasConfigAsync(true);
835
834
  }
836
835
 
837
836
  getDynamicConfig(key: string) {
838
837
  return this.info.sysInfo?.dynamicConfig?.[key];
839
838
  }
840
839
  async updateMPaasConfig() {
841
840
  console.log('updateMPaasConfig');
842
841
  if (
843
842
  isIosDevice &&
844
843
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
845
844
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
846
845
  ) {
847
846
  try {
848
847
  await this.updateMPaasConfigAsync(false);
849
848
  } catch (e) {
850
849
  console.log('updateMPaasConfigAsync:', e);
851
850
  }
852
851
  }
853
852
  }
854
853
 
855
854
  toLogin(options) {
856
855
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
857
856
  ? this.toWxAppLogin(options)
858
857
  : this.toWebLogin(options);
859
858
  }
860
859
 
861
860
  doLogin(options) {
862
861
  return this.toLogin(options);
863
862
  }
864
863
 
865
864
  doLoginForJdPin(options = {}) {
866
865
  return this.doLogin({
867
866
  loginColor: {
868
867
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
869
868
  dpin: 0,
870
869
  },
871
870
  ...options,
872
871
  });
873
872
  }
874
873
 
875
874
  toWebLogin(options) {
876
875
  let params: {
877
876
  returnurl: string;
878
877
  } = {
879
878
  returnurl: '',
880
879
  };
881
880
  const loginUrl = isPc
882
881
  ? `//passport.jd.com/new/login.aspx`
883
882
  : `${domain.mobileLogin}/user/login.action`;
884
883
  const defaultParams = {
885
884
  appid: '100',
886
885
  returnurl: window.location.href,
887
886
  };
888
887
  if (isString(options)) {
889
888
  params = Object.assign({}, defaultParams, {
890
889
  returnurl: options,
891
890
  });
892
891
  } else if (isObject(options)) {
893
892
  const { loginColor, ...otherOptions } = options;
894
893
  params = Object.assign({}, defaultParams, otherOptions);
895
894
  } else {
896
895
  params = defaultParams;
897
896
  }
898
897
  params.returnurl = encodeURIComponent(params.returnurl);
899
898
  let getFullUrl = loginUrl + '?' + serialize(params);
900
899
  if (isPc) {
901
900
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
902
901
  }
903
902
  return Promise.resolve({
904
903
  h5ToUrl: true,
905
904
  url: getFullUrl,
906
905
  }).then(() => {
907
906
  window.location.href = getFullUrl;
908
907
  });
909
908
  }
910
909
 
911
910
  toWxAppLogin(options = {}) {
912
911
  console.log('微信京购小程序中h5登录跳转', options);
913
912
  return Promise.resolve(true).then(() => {
914
913
  const { loginColor } = Object.assign(
915
914
  {},
916
915
  {
917
916
  loginColor: {
918
917
  biz: WXAPP_BIZ_KEY,
919
918
  dpin: 1,
920
919
  },
921
920
  },
922
921
  options,
923
922
  );
924
923
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
925
924
  loginColor.biz
926
925
  }&url=${encodeURIComponent(window.location.href)}`;
927
926
  });
928
927
  }
929
928
 
930
929
  getLoginCookie() {
931
930
  return Promise.resolve({
932
931
  pin: cookie.get('pin') || '',
933
932
  });
934
933
  }
935
934
 
936
935
  clearLoginCookie() {
937
936
  cookie.remove('pin');
938
937
  }
939
938
 
940
939
  checkStatusAndLogin(options = {}) {
941
940
  if (!this.checkStatusAndLoginPromise) {
942
941
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
943
942
  try {
944
943
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
945
944
  if (getLoginState) {
946
945
  resolve(true);
947
946
  } else {
948
947
  this.toLogin(options);
949
948
  reject(false);
950
949
  }
951
950
  } catch (e) {
952
951
  this.toLogin(options);
953
952
  reject(false);
954
953
  }
955
954
  });
956
955
  return this.checkStatusAndLoginPromise;
957
956
  } else {
958
957
  return this.checkStatusAndLoginPromise
959
958
  .then(() => {
960
959
  return Promise.resolve(true);
961
960
  })
962
961
  .catch(() => {
963
962
  this.toLogin(options);
964
963
  return Promise.reject(true);
965
964
  });
966
965
  }
967
966
  }
968
967
 
969
968
  checkJdStatusAndLogin(
970
969
  options = {
971
970
  loginColor: {
972
971
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
973
972
  dpin: 0,
974
973
  },
975
974
  },
976
975
  ) {
977
976
  return this.checkStatusAndLogin(options);
978
977
  }
979
978
 
980
979
  doCheckLoginStateAndForApiCheck(options) {
981
980
  if (this.info.loginState) {
982
981
  return Promise.resolve(true);
983
982
  } else {
984
983
  return new Promise((resolve, reject) => {
985
984
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
986
985
  const getWqAuthToken = cookie.get('wq_auth_token');
987
986
  const getWqSkey = cookie.get('wq_skey');
988
987
  const getWqUin = cookie.get('wq_uin');
989
988
  const isLoginState =
990
989
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
991
990
  if (isLoginState) {
992
991
  this.info.loginState = true;
993
992
  resolve(true);
994
993
  } else {
995
994
  reject(false);
996
995
  }
997
996
  } else {
998
997
  Taro.request({
999
998
  url: api.isLogin,
1000
999
  jsonp: true,
1001
1000
  timeout: 3000,
1002
1001
  success: (res) => {
1003
1002
  const { statusCode, data } = res;
1004
1003
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
1005
1004
  this.info.loginState = true;
1006
1005
  resolve(true);
1007
1006
  } else {
1008
1007
  reject(false);
1009
1008
  }
1010
1009
  },
1011
1010
  fail: (err) => {
1012
1011
  console.log('登录检查异常', err);
1013
1012
  reject(false);
1014
1013
  },
1015
1014
  });
1016
1015
  }
1017
1016
  });
1018
1017
  }
1019
1018
  }
1020
1019
 
1021
1020
  checkLoginStatus(options) {
1022
1021
  return new Promise(async (resolve, reject) => {
1023
1022
  try {
1024
1023
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
1025
1024
  if (getLoginState) {
1026
1025
  const { pin } = await this.getLoginCookie();
1027
1026
  this.info.userInfo = {
1028
1027
  pin,
1029
1028
  encodePin: encodeURIComponent(pin),
1030
1029
  ptkey: '',
1031
1030
  };
1032
1031
  resolve(true);
1033
1032
  } else {
1034
1033
  reject(false);
1035
1034
  }
1036
1035
  } catch (e) {
1037
1036
  reject(false);
1038
1037
  }
1039
1038
  });
1040
1039
  }
1041
1040
 
1042
1041
  updatePageAndLogInfo(updateQuery = {}) {
1043
1042
  const createUpdateQueryInfo: {
1044
1043
  query: {
1045
1044
  shopId?: string | number;
1046
1045
  venderId?: string | number;
1047
1046
  };
1048
1047
  updateShopInfoState: boolean;
1049
1048
  } = Object.assign(
1050
1049
  {},
1051
1050
  {
1052
1051
  query: {},
1053
1052
  updateShopInfoState: false,
1054
1053
  },
1055
1054
  updateQuery,
1056
1055
  );
1057
1056
  console.log(
1058
1057
  '获取当前下发的店铺查询参数',
1059
1058
  updateQuery,
1060
1059
  '获取之前保存的shopInfo店铺查询参数',
1061
1060
  this.info?.shopInfo,
1062
1061
  );
1063
1062
  const { query, updateShopInfoState } = createUpdateQueryInfo;
1064
1063
  const { shopId, venderId, un_area } = query;
1065
1064
  if (updateShopInfoState) {
1066
1065
  this.info.queryInfo = {
1067
1066
  ...this.info.queryInfo,
1068
1067
  ...query,
1069
1068
  };
1070
1069
  if (shopId && venderId) {
1071
1070
  this.info.shopInfo = {
1072
1071
  shopId: `${shopId}`,
1073
1072
  venderId: `${venderId}`,
1074
1073
  };
1075
1074
  }
1076
1075
  } else {
1077
1076
  this.info.queryInfo = {
1078
1077
  ...query,
1079
1078
  };
1080
1079
  if (
1081
1080
  this.info.shopInfo?.shopId &&
1082
1081
  this.info.shopInfo?.venderId &&
1083
1082
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
1084
1083
  ) {
1085
1084
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
1086
1085
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
1087
1086
  console.log(
1088
1087
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1089
1088
  this.info.queryInfo,
1090
1089
  );
1091
1090
  }
1092
1091
  }
1093
1092
  this.info.queryInfo['shopId'] &&
1094
1093
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
1095
1094
  this.info.queryInfo['venderId'] &&
1096
1095
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
1097
1096
  console.log(
1098
1097
  'h5==获取店铺下发查询参数\n',
1099
1098
  query,
1100
1099
  '\n获取店铺最后查询参数\n',
1101
1100
  this.info.queryInfo,
1102
1101
  '\n是否为更新店铺状态\n',
1103
1102
  updateShopInfoState,
1104
1103
  );
1105
1104
  const changeArea = un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : '';
1106
1105
  if (changeArea) {
1107
1106
  this.info.pageInfo.address = changeArea;
1108
1107
  this.info.pageInfo.un_area = changeArea;
1109
1108
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',');
1110
1109
  }
1111
1110
  }
1112
1111
 
1113
1112
  dealLoadSdkList() {
1114
1113
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
1115
1114
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
1116
1115
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
1117
1116
  let mergeLoadJsList = globalLoadJsList;
1118
1117
  try {
1119
1118
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
1120
1119
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
1121
1120
  getFindIndex !== -1
1122
1121
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
1123
1122
  : accArr.push(current);
1124
1123
  return accArr;
1125
1124
  }, []);
1126
1125
  } catch (e) {
1127
1126
  console.log('LoadJsList合并错误', e);
1128
1127
  }
1129
1128
  console.log(
1130
1129
  'globalLoadJsList',
1131
1130
  globalLoadJsList,
1132
1131
  'businessLoadJsList',
1133
1132
  businessLoadJsList,
1134
1133
  '两个加载jsList集合合并完成',
1135
1134
  mergeLoadJsList,
1136
1135
  );
1137
1136
  this.loadJsSdkList = mergeLoadJsList;
1138
1137
  return this.loadJsSdkList;
1139
1138
  }
1140
1139
 
1141
1140
  renderNextTickLoadSdk() {
1142
1141
  Taro.nextTick(() => {
1143
1142
  console.log(
1144
1143
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
1145
1144
  );
1146
1145
  setTimeout(() => {
1147
1146
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
1148
1147
  }, 1000);
1149
1148
  });
1150
1149
  }
1151
1150
 
1152
1151
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
1153
1152
  const getLoadJsList =
1154
1153
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
1155
1154
  const getLoadFilterList = getLoadJsList.filter((item) => {
1156
1155
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
1157
1156
  let getLoastLoadEventState = true;
1158
1157
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
1159
1158
  getLoastLoadEventState = isJdApp;
1160
1159
  }
1161
1160
  else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
1162
1161
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice
1163
1162
  }
1164
1163
  const getInitTriggerType =
1165
1164
  isJdApp && item?.initJdAppTriggerType
1166
1165
  ? item?.initTriggerType
1167
1166
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
1168
1167
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
1169
1168
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
1170
1169
  });
1171
1170
  console.log(
1172
1171
  '获取当前触发方式',
1173
1172
  triggerType,
1174
1173
  '获取当前最后加载的js集合',
1175
1174
  getLoadFilterList,
1176
1175
  '过滤前的加载集合',
1177
1176
  getLoadJsList,
1178
1177
  );
1179
1178
  getLoadFilterList.length > 0 &&
1180
1179
  getLoadFilterList.forEach((item) => {
1181
1180
  const isLoadState = /sgm/.test(item?.fileName)
1182
1181
  ? window?.shopGlobalSwitch?.openSgm === 'true'
1183
1182
  : true;
1184
1183
  isLoadState &&
1185
1184
  this.loadItemSdkPromise(item)
1186
1185
  .then((res) => {
1187
1186
  console.info('当前js地址' + item?.src, '加载状态', res);
1188
1187
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
1189
1188
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
1190
1189
  window.dra.run('init', { aid: res?.aid });
1191
1190
  window.dra.run('start');
1192
1191
  }
1193
1192
  })
1194
1193
  .catch((err) => {
1195
1194
  console.info('当前js地址加载异常', item?.src);
1196
1195
  window?.fetchErrorData &&
1197
1196
  window.fetchErrorData({
1198
1197
  title: '公共js加载异常',
1199
1198
  type: 'jsLoad',
1200
1199
  data: err,
1201
1200
  });
1202
1201
  });
1203
1202
  });
1204
1203
  }
1205
1204
  loadScriptEle(jsInfo, resolve, reject) {
1206
1205
  const getFileName = jsInfo?.fileName;
1207
1206
  if (getFileName) {
1208
1207
  const getEleId = `J_loadJs_${getFileName}`;
1209
1208
  const getEle = document.getElementById(getEleId);
1210
1209
  if (!getEle) {
1211
1210
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1212
1211
  const _sgmEle = document.createElement('script');
1213
1212
  _sgmEle.id = getEleId;
1214
1213
  _sgmEle.onload = function () {
1215
1214
  resolve({
1216
1215
  ...jsInfo,
1217
1216
  jsTip: 'js加载成功',
1218
1217
  });
1219
1218
  };
1220
1219
  _sgmEle.onerror = function () {
1221
1220
  reject({
1222
1221
  ...jsInfo,
1223
1222
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1224
1223
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
1225
1224
  });
1226
1225
  };
1227
1226
  const dataAttrList = ['timeout', 'fileName', 'env'];
1228
1227
  const getJsInfoKeyList = Object.keys(jsInfo);
1229
1228
  getJsInfoKeyList.forEach((key) => {
1230
1229
  if (key === 'async') {
1231
1230
  _sgmEle.async = jsInfo[key];
1232
1231
  } else if (key === 'crossOrigin') {
1233
1232
  _sgmEle.crossOrigin = jsInfo[key];
1234
1233
  } else if (key === 'src') {
1235
1234
  _sgmEle.src = `${jsInfo[key]}`;
1236
1235
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
1237
1236
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
1238
1237
  } else {
1239
1238
  _sgmEle.setAttribute(key, jsInfo[key]);
1240
1239
  }
1241
1240
  });
1242
1241
  document.head.appendChild(_sgmEle);
1243
1242
  } else {
1244
1243
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
1245
1244
  resolve({
1246
1245
  ...jsInfo,
1247
1246
  jsTip: 'js本身已存在页面中',
1248
1247
  });
1249
1248
  }
1250
1249
  } else {
1251
1250
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
1252
1251
  }
1253
1252
  }
1254
1253
 
1255
1254
  loadItemSdkPromise(jsInfo = {}) {
1256
1255
  if (jsInfo?.src) {
1257
1256
  const getInitLoadType =
1258
1257
  isJdApp && jsInfo?.initJdAppLoadType
1259
1258
  ? jsInfo?.initJdAppLoadType
1260
1259
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
1261
1260
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
1262
1261
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
1263
1262
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
1264
1263
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
1265
1264
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1266
1265
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1267
1266
  try {
1268
1267
  const jsXhrRequest = new XMLHttpRequest();
1269
1268
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
1270
1269
  const jsUrl = `${jsInfo?.src}`;
1271
1270
  jsXhrRequest.open('GET', jsUrl, true);
1272
1271
  jsXhrRequest.onreadystatechange = () => {
1273
1272
  if (jsXhrRequest.readyState === 4) {
1274
1273
  const getReqStatus = jsXhrRequest.status;
1275
1274
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
1276
1275
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
1277
1276
  if (getInsetHeadState) {
1278
1277
  this.loadScriptEle(jsInfo, resolve, reject);
1279
1278
  } else {
1280
1279
  resolve({
1281
1280
  ...jsInfo,
1282
1281
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
1283
1282
  });
1284
1283
  }
1285
1284
  getReqStatus !== 200 &&
1286
1285
  sgmCustomReport({
1287
1286
  type: 3,
1288
1287
  code: 'js_load_special_code',
1289
1288
  msg: {
1290
1289
  msg: '当前js加载成功,状态非200,特殊上报观察',
1291
1290
  jsReqState: getReqStatus,
1292
1291
  env: getSgmCustomCode('js_load_special_code'),
1293
1292
  data: jsInfo,
1294
1293
  },
1295
1294
  });
1296
1295
  } else {
1297
1296
  const getRes = {
1298
1297
  ...jsInfo,
1299
1298
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1300
1299
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
1301
1300
  jsReqState: getReqStatus,
1302
1301
  };
1303
1302
  console.log('当前js请求状态异常,具体信息见', getRes);
1304
1303
  reject(getRes);
1305
1304
  }
1306
1305
  }
1307
1306
  };
1308
1307
  jsXhrRequest.onerror = () => {
1309
1308
  const getRes = {
1310
1309
  ...jsInfo,
1311
1310
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1312
1311
  jsReqError: '请求错误',
1313
1312
  };
1314
1313
  console.log('当前js请求错误', getRes);
1315
1314
  jsXhrRequest.abort();
1316
1315
  reject(getRes);
1317
1316
  };
1318
1317
  jsXhrRequest.ontimeout = () => {
1319
1318
  const getRes = {
1320
1319
  ...jsInfo,
1321
1320
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1322
1321
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
1323
1322
  jsReqState: jsXhrRequest.status,
1324
1323
  };
1325
1324
  console.log('当前js请求超时异常', getRes);
1326
1325
  jsXhrRequest.abort();
1327
1326
  reject(getRes);
1328
1327
  };
1329
1328
  jsXhrRequest.send();
1330
1329
  } catch (e) {
1331
1330
  console.log('执行js请求异常', e);
1332
1331
  reject({
1333
1332
  ...jsInfo,
1334
1333
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1335
1334
  jsReqError: '未知异常',
1336
1335
  error: e,
1337
1336
  });
1338
1337
  }
1339
1338
  });
1340
1339
  } else {
1341
1340
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1342
1341
  return this.loadScriptEle(jsInfo, resolve, reject);
1343
1342
  });
1344
1343
  }
1345
1344
  }
1346
1345
  return this.loadJsSdkListCachePromise[getFileKeyName];
1347
1346
  } else {
1348
1347
  return Promise.resolve({
1349
1348
  ...jsInfo,
1350
1349
  jsTip: 'js加载方式设置为不加载,当前不做处理',
1351
1350
  });
1352
1351
  }
1353
1352
  } else {
1354
1353
  return Promise.reject(jsInfo);
1355
1354
  }
1356
1355
  }
1356
+ import Taro from '@tarojs/taro';
1357
1357
  dealNativePixelToCssPixel,
1358
1358
  isAndroidDevice,
1359
1359
  isIosDevice,
1360
1360
  isJdAndAndroidDevice,
1361
1361
  isJdAndHarmonyDevice,
1362
1362
  isObject,
1363
1363
  isPc,
1364
1364
  isString,
1365
1365
  jdAppVersion,
1366
1366
  jdAppVersionStr,
1367
1367
  serialize,
1368
1368
  draBusinessCustomReport,
1369
1369
  BUSINESS_TYPE,
1370
1370
  LoadJsInitLoadEnvType,
1371
1371
  LoadJsInitLoadType,
1372
1372
  LoadJsInitTriggerType,
1373
1373
  MPAAS_CONFIG_APP_LOW_VERSION,
1374
1374
  MPAAS_CONFIG_APP_VERSION,
1375
1375
  SECTION_HOME_TAB_NAME_TYPE,
1376
1376
  SECTION_HOME_TAB_TYPE,
1377
1377
  TaroEventType,
1378
1378
  WX_BUSINESS_TYPE,
1379
1379
  WXAPP_BIZ_KEY,
1380
1380
  WXAPP_BIZ_SHOP_LIGHT_KEY,
1381
1381
  JSSDK_APP_WEBVIEW_CODE,
1382
1382
  getSystemInfos,
1383
1383
  getTaroStorageKeyValue,
1384
1384
  ipLoc_djd,
1385
1385
  setTaroStorage,
1386
1386
  sgmCustomReport,
1387
1387
  abTestLabels: {},
1388
1388
  loginState: false,
1389
1389
  cookiesStr: '',
1390
1390
  userInfo: userPinKey,
1391
1391
  isJingGouMiniViewState: false,
1392
1392
  isJingxiMiniViewState: false,
1393
1393
  pageInfo: {
1394
1394
  wxBusinessType: WX_BUSINESS_TYPE.NO,
1395
1395
  address: '',
1396
1396
  addressCommaStr: '',
1397
1397
  un_area: '',
1398
1398
  vapptype: '1',
1399
1399
  pageType: 'home',
1400
1400
  isExposureState: false,
1401
1401
  moduleId: '',
1402
1402
  entrance: '',
1403
1403
  dataType: BUSINESS_TYPE.ONLINE,
1404
1404
  floorExposureInfo: {},
1405
1405
  floorVideInfo: {},
1406
1406
  productVideInfo: {},
1407
1407
  tabsLoadAllDataInfo: {
1408
1408
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
1409
1409
  },
1410
1410
  updateShopInfosAllState: false,
1411
1411
  isVipShop: false,
1412
1412
  isJdShowNativeImmersivePlayer: false,
1413
1413
  ...shopConfig,
1414
1414
  pageScrollTop: 0,
1415
1415
  pageIdxHeightInfo: {
1416
1416
  list: [],
1417
1417
  },
1418
1418
  shopNavBarHeight: 0,
1419
1419
  },
1420
1420
  defaultQueryLogInfo: {
1421
1421
  sourceType: 'JDshop',
1422
1422
  sourceValue: '',
1423
1423
  moduleId: 'none',
1424
1424
  entrance: 'none',
1425
1425
  },
1426
1426
  sysInfo: {
1427
1427
  windowWidth: isPc ? 375 : 0,
1428
1428
  containerWidth: isPc ? 375 : 0,
1429
1429
  windowHeight: 0,
1430
1430
  netWorkType: '4g',
1431
1431
  jdBottomBarHeight: 0,
1432
1432
  jdNativeHeaderHeight: 0,
1433
1433
  isJdTabletDevice: false,
1434
1434
  isJdTabletLandscape: false,
1435
1435
  },
1436
1436
  queryInfo: {},
1437
1437
  shopInfo: {},
1438
1438
  openAppData: {},
1439
1439
  public info: CommonInterFace.BaseConfigInfo;
1440
1440
  public config: {
1441
1441
  [key: string]: any;
1442
1442
  };
1443
1443
  public lazyContainer: CommonInterFace.lazyContainer;
1444
1444
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
1445
1445
  public rootEleNode: HTMLElement | null;
1446
1446
  public checkStatusAndLoginPromise: object | null;
1447
1447
  private jmfeRegisterStatePromise: Promise<any> | null;
1448
1448
  private jdScreenSizeInfoPromise: Promise<any> | null;
1449
1449
  private rootEleWidthRegisterPromise: Promise<any> | null;
1450
1450
  private jmfeRegisterState: boolean;
1451
1451
  public loadJsSdkList: Array<any>;
1452
1452
  public loadJsSdkListCachePromise: any;
1453
1453
  public rootEleInitWidth: number;
1454
1454
  constructor(opt) {
1455
1455
  this.info = this._getConfig(opt);
1456
1456
  this.config = {};
1457
1457
  this.loadJsSdkList = [];
1458
1458
  this.loadJsSdkListCachePromise = {};
1459
1459
  this.lazyContainer = {
1460
1460
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
1461
1461
  appLazyContainerList: [],
1462
1462
  appLazyFinishContainerList: [],
1463
1463
  },
1464
1464
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
1465
1465
  appLazyContainerList: [],
1466
1466
  appLazyFinishContainerList: [],
1467
1467
  },
1468
1468
  };
1469
1469
  this.renderedIsvComponents = {};
1470
1470
  this.rootEleNode = document.querySelector('body');
1471
1471
  this.checkStatusAndLoginPromise = null;
1472
1472
  this.jmfeRegisterStatePromise = null;
1473
1473
  this.jdScreenSizeInfoPromise = null;
1474
1474
  this.rootEleWidthRegisterPromise = null;
1475
1475
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
1476
1476
  this.loadOtherSdk();
1477
1477
  if (isJdApp) {
1478
1478
  this.jmfeReayPromise();
1479
1479
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
1480
1480
  }
1481
1481
  }
1482
1482
  _getConfig(opt) {
1483
1483
  return Object.assign({}, DefaultConfig, opt);
1484
1484
  }
1485
1485
  _getJdPadMinWidthForListen() {
1486
1486
  return (
1487
1487
  isJdApp &&
1488
1488
  Math.min(window.screen.width, window.screen.height) >
1489
1489
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
1490
1490
  );
1491
1491
  }
1492
1492
 
1493
1493
  jmfeReayPromise(): Promise<any> {
1494
1494
  if (isJdApp) {
1495
1495
  if (this.jmfeRegisterState) {
1496
1496
  return Promise.resolve(true);
1497
1497
  } else {
1498
1498
  !this.jmfeRegisterStatePromise &&
1499
1499
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
1500
1500
  ready('jmfe', 3000)
1501
1501
  .then(() => {
1502
1502
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
1503
1503
  this.jmfeRegisterState = true;
1504
1504
  resolve(true);
1505
1505
  console.log('松果app内初始化注册jmfe认证完成');
1506
1506
  })
1507
1507
  .catch((err) => {
1508
1508
  console.error('jmfe ready error', err);
1509
1509
  reject(false);
1510
1510
  });
1511
1511
  }));
1512
1512
  return this.jmfeRegisterStatePromise;
1513
1513
  }
1514
1514
  } else {
1515
1515
  return Promise.reject(false);
1516
1516
  }
1517
1517
  }
1518
1518
 
1519
1519
  getJdScreenSizeInfoPromise() {
1520
1520
  !this.jdScreenSizeInfoPromise &&
1521
1521
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
1522
1522
  const getThisTime = Date.now();
1523
1523
  this.jmfeReayPromise().then(() => {
1524
1524
  return Promise.race([
1525
1525
  window.jmfe.getScreenSize(),
1526
1526
  this.taskTimeoutPromise(() => {
1527
1527
  return {
1528
1528
  status: '-10',
1529
1529
  msg: '获取大屏信息2s超时',
1530
1530
  };
1531
1531
  }),
1532
1532
  ])
1533
1533
  .then((res) => {
1534
1534
  console.warn('===获取app大屏信息====', res);
1535
1535
  const { status, data } = res;
1536
1536
  if (status === '0' && data) {
1537
1537
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
1538
1538
  const getPageInfo = dealNativePixelToCssPixel({
1539
1539
  pageWidth,
1540
1540
  pageHeight,
1541
1541
  });
1542
1542
  this.info.sysInfo.jdScreenSizeType = sizeType;
1543
1543
  const getUseTime = Date.now() - getThisTime;
1544
1544
  console.warn(
1545
1545
  '===计算是否是app大屏信息,需满足宽度最新720===',
1546
1546
  getPageInfo,
1547
1547
  '原始数据',
1548
1548
  data,
1549
1549
  '是否是横屏isLandscape为1=',
1550
1550
  isLandscape,
1551
1551
  '用时',
1552
1552
  getUseTime,
1553
1553
  );
1554
1554
  if (getPageInfo?.pageWidth > 0) {
1555
1555
  this.rootEleInitWidth = getPageInfo?.pageWidth;
1556
1556
  draBusinessCustomReport({
1557
1557
  type: 'rootEle_width_getJdScreenSizeInfo',
1558
1558
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
1559
1559
  originReqDataStr: JSON.stringify({
1560
1560
  isJdApp,
1561
1561
  getPageInfo,
1562
1562
  originData: res,
1563
1563
  }),
1564
1564
  });
1565
1565
  resolve(getPageInfo);
1566
1566
  } else {
1567
1567
  resolve({
1568
1568
  pageWidth: 0,
1569
1569
  pageHeight: 0,
1570
1570
  msg: '转换异常',
1571
1571
  });
1572
1572
  }
1573
1573
  } else {
1574
1574
  resolve({
1575
1575
  pageWidth: 0,
1576
1576
  pageHeight: 0,
1577
1577
  msg: '获取大屏信息异常或者超时',
1578
1578
  });
1579
1579
  }
1580
1580
  })
1581
1581
  .catch((err) => {
1582
1582
  console.log('获取大屏信息异常', err);
1583
1583
  resolve({
1584
1584
  pageWidth: 0,
1585
1585
  pageHeight: 0,
1586
1586
  msg: '获取大屏信息异常',
1587
1587
  });
1588
1588
  });
1589
1589
  });
1590
1590
  }));
1591
1591
  return this.jdScreenSizeInfoPromise;
1592
1592
  }
1593
1593
 
1594
1594
  listenJdTabletScreenChange() {
1595
1595
  this.jmfeReayPromise().then(() => {
1596
1596
  try {
1597
1597
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
1598
1598
  window.jmfe.listenDeviceScreenChange((event) => {
1599
1599
  console.log(
1600
1600
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
1601
1601
  event,
1602
1602
  '通过前端判断是不是横屏',
1603
1603
  window.matchMedia('(orientation: landscape)')?.matches,
1604
1604
  );
1605
1605
  const { orientation } = event?.data;
1606
1606
  if (orientation) {
1607
1607
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
1608
1608
  Taro.eventCenter.trigger(
1609
1609
  TaroEventType.TABLE_SCREEN_CHANGE,
1610
1610
  this.info.sysInfo.isJdTabletLandscape,
1611
1611
  orientation,
1612
1612
  );
1613
1613
  }
1614
1614
  });
1615
1615
  } catch (error) {
1616
1616
  console.log('listenScreenChange的打印error:', error);
1617
1617
  }
1618
1618
  });
1619
1619
  }
1620
1620
 
1621
1621
  updateBusinessDomainAndApi(domain, api) {
1622
1622
  }
1623
1623
 
1624
1624
  formatNativeScreenPageData(action) {
1625
1625
  let getChangePageInfo: any = null;
1626
1626
  try {
1627
1627
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
1628
1628
  JSON.stringify({
1629
1629
  plugin: 'JDHybridScreenPlugin',
1630
1630
  action,
1631
1631
  sync: '1',
1632
1632
  }),
1633
1633
  );
1634
1634
  const getChangePageInfoData =
1635
1635
  typeof getNativeScreenPageInfoStr === 'string'
1636
1636
  ? JSON.parse(getNativeScreenPageInfoStr)
1637
1637
  : null;
1638
1638
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
1639
1639
  const { code, data } = getChangePageInfoData;
1640
1640
  getChangePageInfo = code && code === '0' ? data : null;
1641
1641
  }
1642
1642
  } catch (e) {
1643
1643
  console.log('JDHybridScreenPlugin转换异常', e);
1644
1644
  }
1645
1645
  return getChangePageInfo;
1646
1646
  }
1647
1647
 
1648
1648
  isAndroidFoldScreen() {
1649
1649
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
1650
1650
  }
1651
1651
 
1652
1652
  getJdAndroidPageChangeScreenInfo() {
1653
1653
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
1654
1654
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
1655
1655
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1656
1656
  pageWidth: getPageScreenInfo.pageWidth,
1657
1657
  pageHeight: getPageScreenInfo.pageHeight,
1658
1658
  });
1659
1659
  getPageScreenInfo.pageWidth = pageWidth;
1660
1660
  getPageScreenInfo.pageHeight = pageHeight;
1661
1661
  }
1662
1662
  return getPageScreenInfo;
1663
1663
  }
1664
1664
 
1665
1665
  getRootEleWindowWidthInfo() {
1666
1666
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
1667
1667
  const getWindowWidth = window.innerWidth;
1668
1668
  const getScreenWidth = window.screen.width;
1669
1669
  return {
1670
1670
  getRootEleWidth,
1671
1671
  getWindowWidth,
1672
1672
  getScreenWidth,
1673
1673
  };
1674
1674
  }
1675
1675
 
1676
1676
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
1677
1677
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
1678
1678
  console.log(
1679
1679
  '当前获取根元素的宽度',
1680
1680
  getRootEleWidth,
1681
1681
  'getWindowWidth',
1682
1682
  getWindowWidth,
1683
1683
  'getScreenWidth',
1684
1684
  getScreenWidth,
1685
1685
  );
1686
1686
  const getLastWidth =
1687
1687
  getRootEleWidth > 0
1688
1688
  ? Math.round(getRootEleWidth)
1689
1689
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
1690
1690
  console.warn(
1691
1691
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1692
1692
  );
1693
1693
  timeout > 0 &&
1694
1694
  draBusinessCustomReport({
1695
1695
  type: 'rootEle_width_timeout_getJdScreenSizeInfo',
1696
1696
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1697
1697
  originReqDataStr: JSON.stringify({
1698
1698
  isJdApp,
1699
1699
  getRootEleWidth,
1700
1700
  getWindowWidth,
1701
1701
  getScreenWidth,
1702
1702
  ...reportParam,
1703
1703
  }),
1704
1704
  });
1705
1705
  return getLastWidth;
1706
1706
  }
1707
1707
 
1708
1708
  getPadWindowRootEleWidthPromise() {
1709
1709
  if (this.rootEleInitWidth > 0) {
1710
1710
  return Promise.resolve(this.rootEleInitWidth);
1711
1711
  } else {
1712
1712
  !this.rootEleWidthRegisterPromise &&
1713
1713
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
1714
1714
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
1715
1715
  if (getRootEleInitWidth > 0) {
1716
1716
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
1717
1717
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
1718
1718
  resolve(this.rootEleInitWidth);
1719
1719
  } else {
1720
1720
  const timerPromise = () => {
1721
1721
  return new Promise((resolve2) => {
1722
1722
  window.setTimeout(() => {
1723
1723
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
1724
1724
  this.getRootEleWindowWidthInfo();
1725
1725
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
1726
1726
  console.warn(
1727
1727
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
1728
1728
  );
1729
1729
  draBusinessCustomReport({
1730
1730
  type: 'rootEle_width_200_timeout_info',
1731
1731
  errMsg: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
1732
1732
  originReqDataStr: JSON.stringify({
1733
1733
  isJdApp,
1734
1734
  getRootEleWidth,
1735
1735
  getWindowWidth,
1736
1736
  getScreenWidth,
1737
1737
  }),
1738
1738
  });
1739
1739
  const getRes =
1740
1740
  getRootEleWidth > 0 && getWindowWidth > 0
1741
1741
  ? Math.min(getRootEleWidth, getWindowWidth)
1742
1742
  : Math.max(getRootEleWidth, getWindowWidth);
1743
1743
  resolve2({
1744
1744
  pageWidth: Math.round(getRes),
1745
1745
  });
1746
1746
  }
1747
1747
  }, 200);
1748
1748
  });
1749
1749
  };
1750
1750
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
1751
1751
  const { pageWidth } = res;
1752
1752
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
1753
1753
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
1754
1754
  });
1755
1755
  }
1756
1756
  }));
1757
1757
  return this.rootEleWidthRegisterPromise;
1758
1758
  }
1759
1759
  }
1760
1760
 
1761
1761
  async getSystemInfo(params) {
1762
1762
  const getParams = Object.assign({}, params || {});
1763
1763
  if (this.rootEleInitWidth > 0) {
1764
1764
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
1765
1765
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
1766
1766
  } else {
1767
1767
  if (this._getJdPadMinWidthForListen()) {
1768
1768
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
1769
1769
  getParams['replaceSystemWidth'] = true;
1770
1770
  }
1771
1771
  }
1772
1772
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
1773
1773
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
1774
1774
  let _isfoldScreen = false;
1775
1775
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
1776
1776
  console.info(
1777
1777
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
1778
1778
  getStorageData,
1779
1779
  '通过缓存值第一次判断是否是折叠屏',
1780
1780
  getStorageData === 'true',
1781
1781
  );
1782
1782
  if (!getStorageData) {
1783
1783
  _isfoldScreen = this.isAndroidFoldScreen();
1784
1784
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
1785
1785
  } else {
1786
1786
  _isfoldScreen = getStorageData === 'true';
1787
1787
  }
1788
1788
  if (_isfoldScreen) {
1789
1789
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
1790
1790
  if (getJdAndroidPageInfo) {
1791
1791
  info = getSystemInfos(getJdAndroidPageInfo);
1792
1792
  console.warn(
1793
1793
  '当前为松果安卓折叠屏app,获取折叠屏信息',
1794
1794
  getJdAndroidPageInfo,
1795
1795
  '获取转换后的系统信息',
1796
1796
  info,
1797
1797
  );
1798
1798
  sgmCustomReport({
1799
1799
  type: 2,
1800
1800
  code: 'android_jdapp_foldScreen_info',
1801
1801
  msg: {
1802
1802
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
1803
1803
  androidPageInfo: getJdAndroidPageInfo,
1804
1804
  jdAppVersionStr,
1805
1805
  taroSysInfo: info,
1806
1806
  },
1807
1807
  });
1808
1808
  }
1809
1809
  }
1810
1810
  }
1811
1811
  if (isJdApp) {
1812
1812
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
1813
1813
  }
1814
1814
  this.info.sysInfo = {
1815
1815
  actualNavBarHeight: 0,
1816
1816
  ...this.info.sysInfo,
1817
1817
  ...info,
1818
1818
  safeContentHeight: info?.screenHeight,
1819
1819
  headerHeight: 0,
1820
1820
  tabBarHeight: 0,
1821
1821
  };
1822
1822
  if (isJdApp) {
1823
1823
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
1824
1824
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
1825
1825
  this.getAddressCachePromise();
1826
1826
  this.getElderModePromise();
1827
1827
  this.getJDAppearanceStatePromise();
1828
1828
  this.createJdAndroidRquestEventForTouchStart();
1829
1829
  }
1830
1830
  this.getWifiVideoAutoPlayAsync();
1831
1831
  this.getMPaasConfigAsync();
1832
1832
  this.getNetWorkType();
1833
1833
  }
1834
1834
 
1835
1835
  taskTimeoutPromise(callBack, timeout = 2000) {
1836
1836
  return new Promise((resolve) => {
1837
1837
  setTimeout(() => {
1838
1838
  const getCallBackRes = typeof callBack === 'function' && callBack();
1839
1839
  return resolve(getCallBackRes || false);
1840
1840
  }, timeout);
1841
1841
  });
1842
1842
  }
1843
1843
 
1844
1844
  getElderModePromise() {
1845
1845
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1846
1846
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1847
1847
  } else {
1848
1848
  if (isJdAndAndroidDevice) {
1849
1849
  this.info.sysInfo.jdAppModeType = '0';
1850
1850
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1851
1851
  } else {
1852
1852
  return Promise.race([
1853
1853
  this.taskTimeoutPromise(() => {
1854
1854
  this.info.sysInfo.jdAppModeType = '0';
1855
1855
  return this.info.sysInfo.jdAppModeType;
1856
1856
  }),
1857
1857
  new Promise((resolve) => {
1858
1858
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
1859
1859
  if (!window[getCallBackName]) {
1860
1860
  window[getCallBackName] = (res) => {
1861
1861
  try {
1862
1862
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1863
1863
  const { status, data, msg } = getResJson;
1864
1864
  console.log(`获取松果app展示模式成功,返回结果${data}`);
1865
1865
  if (status === '0') {
1866
1866
  this.info.sysInfo.jdAppModeType = data;
1867
1867
  resolve(data);
1868
1868
  } else {
1869
1869
  resolve('0');
1870
1870
  }
1871
1871
  } catch (e) {
1872
1872
  resolve('0');
1873
1873
  }
1874
1874
  window[getCallBackName] = null;
1875
1875
  };
1876
1876
  }
1877
1877
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1878
1878
  method: 'callSyncRouterModuleWithParams',
1879
1879
  params: JSON.stringify({
1880
1880
  routerURL: 'router://JDBModeModule/getCurrentMode',
1881
1881
  routerParam: {},
1882
1882
  callBackName: `window.${getCallBackName}`,
1883
1883
  callBackId: `${getCallBackName}Ios`,
1884
1884
  }),
1885
1885
  });
1886
1886
  }),
1887
1887
  ]);
1888
1888
  }
1889
1889
  }
1890
1890
  }
1891
1891
  getAPPUseStraightCorner() {
1892
1892
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
1893
1893
  const params = {
1894
1894
  routerURL,
1895
1895
  routerParam: {},
1896
1896
  jdRouter: '1',
1897
1897
  };
1898
1898
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
1899
1899
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
1900
1900
  } else {
1901
1901
  return this.jmfeReayPromise()
1902
1902
  .then(() => {
1903
1903
  if (isJdAndHarmonyDevice || !isJdApp) {
1904
1904
  console.log('not APP or is Harmony');
1905
1905
  return Promise.resolve(false);
1906
1906
  }
1907
1907
  console.log('jmfe setShareInfo', params);
1908
1908
  return Promise.race([
1909
1909
  window.jmfe.callRouter(params),
1910
1910
  this.taskTimeoutPromise(() => {
1911
1911
  return false;
1912
1912
  }),
1913
1913
  ]).then(({ status, data }) => {
1914
1914
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
1915
1915
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
1916
1916
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
1917
1917
  return Promise.resolve(status === '0' && Number(data) === 1);
1918
1918
  });
1919
1919
  })
1920
1920
  .catch((e) => {
1921
1921
  console.log('jmfe error', e);
1922
1922
  return Promise.resolve(false);
1923
1923
  });
1924
1924
  }
1925
1925
  }
1926
1926
 
1927
1927
  getJDAppearanceStatePromise() {
1928
1928
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1929
1929
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
1930
1930
  } else {
1931
1931
  return Promise.race([
1932
1932
  this.taskTimeoutPromise(() => {
1933
1933
  this.info.sysInfo.jdAppearanceState = '0';
1934
1934
  return this.info.sysInfo.jdAppearanceState;
1935
1935
  }),
1936
1936
  new Promise((resolve) => {
1937
1937
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
1938
1938
  if (!window[getCallBackName]) {
1939
1939
  window[getCallBackName] = (res) => {
1940
1940
  try {
1941
1941
  console.log('getJDAppearanceStatePromise', res);
1942
1942
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1943
1943
  const { status, data, msg } = getResJson;
1944
1944
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
1945
1945
  if (status === '0') {
1946
1946
  this.info.sysInfo.jdAppearanceState = data;
1947
1947
  resolve(data);
1948
1948
  } else {
1949
1949
  resolve('0');
1950
1950
  }
1951
1951
  } catch (e) {
1952
1952
  resolve('0');
1953
1953
  }
1954
1954
  window[getCallBackName] = null;
1955
1955
  };
1956
1956
  }
1957
1957
  if (isAndroidDevice) {
1958
1958
  const jsonString = JSON.stringify({
1959
1959
  callBackName: `window.${getCallBackName}`,
1960
1960
  });
1961
1961
  console.log('window.JDAppearance', window?.JDAppearance);
1962
1962
  window?.JDAppearance &&
1963
1963
  window?.JDAppearance?.getUiState &&
1964
1964
  window.JDAppearance.getUiState(jsonString);
1965
1965
  } else {
1966
1966
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1967
1967
  method: 'callSyncRouterModuleWithParams',
1968
1968
  params: JSON.stringify({
1969
1969
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
1970
1970
  routerParam: {},
1971
1971
  callBackName: `window.${getCallBackName}`,
1972
1972
  callBackId: `${getCallBackName}Ios`,
1973
1973
  }),
1974
1974
  });
1975
1975
  }
1976
1976
  }),
1977
1977
  ]);
1978
1978
  }
1979
1979
  }
1980
1980
 
1981
1981
  createJdAndroidRquestEventForTouchStart() {
1982
1982
  if (isJdAndAndroidDevice && window?.JdAndroid) {
1983
1983
  const rootEleNode = document.querySelector('body');
1984
1984
  if (rootEleNode) {
1985
1985
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
1986
1986
  }
1987
1987
  }
1988
1988
  }
1989
1989
  jdAndroidAddEventListenerTouchStart(e) {
1990
1990
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
1991
1991
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
1992
1992
  const hasCustomEle = e
1993
1993
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
1994
1994
  : false;
1995
1995
  if (!hasCustomEle) {
1996
1996
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
1997
1997
  console.log(
1998
1998
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1999
1999
  );
2000
2000
  }
2001
2001
  }
2002
2002
  }
2003
2003
  removeJdAndroidRquestEventForTouchStart() {
2004
2004
  if (isJdAndAndroidDevice && window.JdAndroid) {
2005
2005
  const rootEleNode = document.querySelector('body');
2006
2006
  if (rootEleNode) {
2007
2007
  rootEleNode.removeEventListener(
2008
2008
  'touchstart',
2009
2009
  this.jdAndroidAddEventListenerTouchStart,
2010
2010
  false,
2011
2011
  );
2012
2012
  }
2013
2013
  }
2014
2014
  }
2015
2015
 
2016
2016
  getNetWorkType() {
2017
2017
  if (isJdApp) {
2018
2018
  this.jmfeReayPromise().then(() => {
2019
2019
  window.jmfe
2020
2020
  .getNetworkStatus()
2021
2021
  .then(({ status, data }) => {
2022
2022
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
2023
2023
  if (status === '0') {
2024
2024
  this.info.sysInfo['netWorkType'] = data;
2025
2025
  } else {
2026
2026
  this._taroGetNetworkType();
2027
2027
  }
2028
2028
  })
2029
2029
  .catch((err) => {
2030
2030
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
2031
2031
  this._taroGetNetworkType();
2032
2032
  });
2033
2033
  });
2034
2034
  } else {
2035
2035
  this._taroGetNetworkType();
2036
2036
  }
2037
2037
  }
2038
2038
  _taroGetNetworkType() {
2039
2039
  Taro.getNetworkType().then((getRes) => {
2040
2040
  if (getRes && getRes.networkType) {
2041
2041
  this.info.sysInfo['netWorkType'] = getRes.networkType;
2042
2042
  console.log(
2043
2043
  '在app内通过taro对象获取网络状态完成,当前网络状态',
2044
2044
  this.info.sysInfo['netWorkType'],
2045
2045
  );
2046
2046
  }
2047
2047
  });
2048
2048
  }
2049
2049
 
2050
2050
  getCacheAddressRouter() {
2051
2051
  if (window.jmfe && isJdApp) {
2052
2052
  if (!isJdAndHarmonyDevice) {
2053
2053
  return Promise.race([
2054
2054
  window.jmfe.callRouter({
2055
2055
  jdRouter: '1',
2056
2056
  routerURL: isAndroidDevice
2057
2057
  ? 'router://JDAddressModule/getCacheAddress'
2058
2058
  : 'router://JDBAddressCacheManagerModule/getCacheAddress',
2059
2059
  routerParam: { sceneId: 'basicShoppingProcess' },
2060
2060
  }),
2061
2061
  this.taskTimeoutPromise(() => {
2062
2062
  return {
2063
2063
  status: '-1000',
2064
2064
  msg: '原生router协议获取地址信息超时',
2065
2065
  };
2066
2066
  }, 3000),
2067
2067
  ]);
2068
2068
  } else {
2069
2069
  return Promise.resolve({
2070
2070
  status: '-1001',
2071
2071
  msg: '鸿蒙系统调用jmfe异常,获取失败',
2072
2072
  });
2073
2073
  }
2074
2074
  } else {
2075
2075
  return Promise.resolve({
2076
2076
  status: '-1002',
2077
2077
  msg: 'jmfe不存在,获取失败',
2078
2078
  });
2079
2079
  }
2080
2080
  }
2081
2081
 
2082
2082
  getAddressCachePromise() {
2083
2083
  return new Promise((resolve) => {
2084
2084
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
2085
2085
  resolve({
2086
2086
  lat: this.info.sysInfo.lat,
2087
2087
  lng: this.info.sysInfo.lng,
2088
2088
  area: this?.info?.sysInfo?.area,
2089
2089
  });
2090
2090
  } else {
2091
2091
  this.jmfeReayPromise()
2092
2092
  .then(() => {
2093
2093
  this.getCacheAddressRouter()
2094
2094
  .then((res) => {
2095
2095
  const { status, data } = res;
2096
2096
  console.log('原生端获取经纬度原始数据结果', status, data);
2097
2097
  if (status === '0' && data) {
2098
2098
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
2099
2099
  data || {};
2100
2100
  let area = '';
2101
2101
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
2102
2102
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
2103
2103
  if (provinceId) {
2104
2104
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
2105
2105
  this.info.pageInfo['address'] = area;
2106
2106
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
2107
2107
  Taro.eventCenter.trigger(
2108
2108
  TaroEventType.USER_AREA_UPDATE,
2109
2109
  this.info.pageInfo.address,
2110
2110
  );
2111
2111
  }
2112
2112
  resolve({
2113
2113
  lat: this.info.sysInfo['lat'],
2114
2114
  lng: this.info.sysInfo['lng'],
2115
2115
  area: area,
2116
2116
  });
2117
2117
  } else {
2118
2118
  typeof res === 'object' &&
2119
2119
  sgmCustomReport({
2120
2120
  type: 3,
2121
2121
  code: 'jdapp_getCacheAddress_info',
2122
2122
  msg: {
2123
2123
  title: '松果app内通过router协议获取用户地址及经纬度信息异常',
2124
2124
  jdAppVersion: jdAppVersionStr,
2125
2125
  ...res,
2126
2126
  },
2127
2127
  });
2128
2128
  resolve({ lat: '', lng: '', area: '' });
2129
2129
  }
2130
2130
  })
2131
2131
  .catch((e) => {
2132
2132
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e);
2133
2133
  resolve({ lat: '', lng: '', area: '' });
2134
2134
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
2135
2135
  });
2136
2136
  })
2137
2137
  .catch((e) => {
2138
2138
  resolve({ lat: '', lng: '', area: '' });
2139
2139
  console.log('判断jmfe不存在,获取经纬度信息异常e', e);
2140
2140
  });
2141
2141
  }
2142
2142
  });
2143
2143
  }
2144
2144
 
2145
2145
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
2146
2146
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
2147
2147
  if (!isJdApp) {
2148
2148
  return;
2149
2149
  }
2150
2150
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
2151
2151
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
2152
2152
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
2153
2153
  'hybridHttpSwitch',
2154
2154
  isBeforePageReady,
2155
2155
  );
2156
2156
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
2157
2157
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
2158
2158
  'isFollowAppVideoPlayStatus',
2159
2159
  isBeforePageReady,
2160
2160
  );
2161
2161
  console.log(
2162
2162
  'isBeforePageReady:',
2163
2163
  isBeforePageReady,
2164
2164
  'isFollowAppVideoPlayStatus:',
2165
2165
  isFollowAppVideoPlayStatus,
2166
2166
  );
2167
2167
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
2168
2168
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
2169
2169
  }
2170
2170
  }
2171
2171
 
2172
2172
  async getWifiVideoAutoPlayAsync() {
2173
2173
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
2174
2174
  if (!isJdApp) {
2175
2175
  return;
2176
2176
  }
2177
2177
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
2178
2178
  return 0;
2179
2179
  });
2180
2180
  if (Number(videoPlayStatus) === 1) {
2181
2181
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
2182
2182
  }
2183
2183
  }
2184
2184
 
2185
2185
  async getMPaasConfigAsync() {
2186
2186
  this.info.sysInfo.dynamicConfig = {};
2187
2187
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
2188
2188
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
2189
2189
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
2190
2190
  return this.updateMPaasConfigAsync(true);
2191
2191
  }
2192
2192
 
2193
2193
  getDynamicConfig(key: string) {
2194
2194
  return this.info.sysInfo?.dynamicConfig?.[key];
2195
2195
  }
2196
2196
  async updateMPaasConfig() {
2197
2197
  console.log('updateMPaasConfig');
2198
2198
  if (
2199
2199
  isIosDevice &&
2200
2200
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
2201
2201
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
2202
2202
  ) {
2203
2203
  try {
2204
2204
  await this.updateMPaasConfigAsync(false);
2205
2205
  } catch (e) {
2206
2206
  console.log('updateMPaasConfigAsync:', e);
2207
2207
  }
2208
2208
  }
2209
2209
  }
2210
2210
 
2211
2211
  toLogin(options) {
2212
2212
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
2213
2213
  ? this.toWxAppLogin(options)
2214
2214
  : this.toWebLogin(options);
2215
2215
  }
2216
2216
 
2217
2217
  doLogin(options) {
2218
2218
  return this.toLogin(options);
2219
2219
  }
2220
2220
 
2221
2221
  doLoginForJdPin(options = {}) {
2222
2222
  return this.doLogin({
2223
2223
  loginColor: {
2224
2224
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2225
2225
  dpin: 0,
2226
2226
  },
2227
2227
  ...options,
2228
2228
  });
2229
2229
  }
2230
2230
 
2231
2231
  toWebLogin(options) {
2232
2232
  let params: {
2233
2233
  returnurl: string;
2234
2234
  } = {
2235
2235
  returnurl: '',
2236
2236
  };
2237
2237
  const loginUrl = isPc
2238
2238
  ? `//passport.jd.com/new/login.aspx`
2239
2239
  : `${domain.mobileLogin}/user/login.action`;
2240
2240
  const defaultParams = {
2241
2241
  appid: '100',
2242
2242
  returnurl: window.location.href,
2243
2243
  };
2244
2244
  if (isString(options)) {
2245
2245
  params = Object.assign({}, defaultParams, {
2246
2246
  returnurl: options,
2247
2247
  });
2248
2248
  } else if (isObject(options)) {
2249
2249
  const { loginColor, ...otherOptions } = options;
2250
2250
  params = Object.assign({}, defaultParams, otherOptions);
2251
2251
  } else {
2252
2252
  params = defaultParams;
2253
2253
  }
2254
2254
  params.returnurl = encodeURIComponent(params.returnurl);
2255
2255
  let getFullUrl = loginUrl + '?' + serialize(params);
2256
2256
  if (isPc) {
2257
2257
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
2258
2258
  }
2259
2259
  return Promise.resolve({
2260
2260
  h5ToUrl: true,
2261
2261
  url: getFullUrl,
2262
2262
  }).then(() => {
2263
2263
  window.location.href = getFullUrl;
2264
2264
  });
2265
2265
  }
2266
2266
 
2267
2267
  toWxAppLogin(options = {}) {
2268
2268
  console.log('微信京购小程序中h5登录跳转', options);
2269
2269
  return Promise.resolve(true).then(() => {
2270
2270
  const { loginColor } = Object.assign(
2271
2271
  {},
2272
2272
  {
2273
2273
  loginColor: {
2274
2274
  biz: WXAPP_BIZ_KEY,
2275
2275
  dpin: 1,
2276
2276
  },
2277
2277
  },
2278
2278
  options,
2279
2279
  );
2280
2280
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
2281
2281
  loginColor.biz
2282
2282
  }&url=${encodeURIComponent(window.location.href)}`;
2283
2283
  });
2284
2284
  }
2285
2285
 
2286
2286
  getLoginCookie() {
2287
2287
  return Promise.resolve({
2288
2288
  pin: cookie.get('pin') || '',
2289
2289
  });
2290
2290
  }
2291
2291
 
2292
2292
  clearLoginCookie() {
2293
2293
  cookie.remove('pin');
2294
2294
  }
2295
2295
 
2296
2296
  checkStatusAndLogin(options = {}) {
2297
2297
  if (!this.checkStatusAndLoginPromise) {
2298
2298
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
2299
2299
  try {
2300
2300
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2301
2301
  if (getLoginState) {
2302
2302
  resolve(true);
2303
2303
  } else {
2304
2304
  this.toLogin(options);
2305
2305
  reject(false);
2306
2306
  }
2307
2307
  } catch (e) {
2308
2308
  this.toLogin(options);
2309
2309
  reject(false);
2310
2310
  }
2311
2311
  });
2312
2312
  return this.checkStatusAndLoginPromise;
2313
2313
  } else {
2314
2314
  return this.checkStatusAndLoginPromise
2315
2315
  .then(() => {
2316
2316
  return Promise.resolve(true);
2317
2317
  })
2318
2318
  .catch(() => {
2319
2319
  this.toLogin(options);
2320
2320
  return Promise.reject(true);
2321
2321
  });
2322
2322
  }
2323
2323
  }
2324
2324
 
2325
2325
  checkJdStatusAndLogin(
2326
2326
  options = {
2327
2327
  loginColor: {
2328
2328
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2329
2329
  dpin: 0,
2330
2330
  },
2331
2331
  },
2332
2332
  ) {
2333
2333
  return this.checkStatusAndLogin(options);
2334
2334
  }
2335
2335
 
2336
2336
  doCheckLoginStateAndForApiCheck(options) {
2337
2337
  if (this.info.loginState) {
2338
2338
  return Promise.resolve(true);
2339
2339
  } else {
2340
2340
  return new Promise((resolve, reject) => {
2341
2341
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
2342
2342
  const getWqAuthToken = cookie.get('wq_auth_token');
2343
2343
  const getWqSkey = cookie.get('wq_skey');
2344
2344
  const getWqUin = cookie.get('wq_uin');
2345
2345
  const isLoginState =
2346
2346
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
2347
2347
  if (isLoginState) {
2348
2348
  this.info.loginState = true;
2349
2349
  resolve(true);
2350
2350
  } else {
2351
2351
  reject(false);
2352
2352
  }
2353
2353
  } else {
2354
2354
  Taro.request({
2355
2355
  url: api.isLogin,
2356
2356
  jsonp: true,
2357
2357
  timeout: 3000,
2358
2358
  success: (res) => {
2359
2359
  const { statusCode, data } = res;
2360
2360
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
2361
2361
  this.info.loginState = true;
2362
2362
  resolve(true);
2363
2363
  } else {
2364
2364
  reject(false);
2365
2365
  }
2366
2366
  },
2367
2367
  fail: (err) => {
2368
2368
  console.log('登录检查异常', err);
2369
2369
  reject(false);
2370
2370
  },
2371
2371
  });
2372
2372
  }
2373
2373
  });
2374
2374
  }
2375
2375
  }
2376
2376
 
2377
2377
  checkLoginStatus(options) {
2378
2378
  return new Promise(async (resolve, reject) => {
2379
2379
  try {
2380
2380
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2381
2381
  if (getLoginState) {
2382
2382
  const { pin } = await this.getLoginCookie();
2383
2383
  this.info.userInfo = {
2384
2384
  pin,
2385
2385
  encodePin: encodeURIComponent(pin),
2386
2386
  ptkey: '',
2387
2387
  };
2388
2388
  resolve(true);
2389
2389
  } else {
2390
2390
  reject(false);
2391
2391
  }
2392
2392
  } catch (e) {
2393
2393
  reject(false);
2394
2394
  }
2395
2395
  });
2396
2396
  }
2397
2397
 
2398
2398
  updatePageAndLogInfo(updateQuery = {}) {
2399
2399
  const createUpdateQueryInfo: {
2400
2400
  query: {
2401
2401
  shopId?: string | number;
2402
2402
  venderId?: string | number;
2403
2403
  };
2404
2404
  updateShopInfoState: boolean;
2405
2405
  } = Object.assign(
2406
2406
  {},
2407
2407
  {
2408
2408
  query: {},
2409
2409
  updateShopInfoState: false,
2410
2410
  },
2411
2411
  updateQuery,
2412
2412
  );
2413
2413
  console.log(
2414
2414
  '获取当前下发的店铺查询参数',
2415
2415
  updateQuery,
2416
2416
  '获取之前保存的shopInfo店铺查询参数',
2417
2417
  this.info?.shopInfo,
2418
2418
  );
2419
2419
  const { query, updateShopInfoState } = createUpdateQueryInfo;
2420
2420
  const { shopId, venderId, un_area } = query;
2421
2421
  if (updateShopInfoState) {
2422
2422
  this.info.queryInfo = {
2423
2423
  ...this.info.queryInfo,
2424
2424
  ...query,
2425
2425
  };
2426
2426
  if (shopId && venderId) {
2427
2427
  this.info.shopInfo = {
2428
2428
  shopId: `${shopId}`,
2429
2429
  venderId: `${venderId}`,
2430
2430
  };
2431
2431
  }
2432
2432
  } else {
2433
2433
  this.info.queryInfo = {
2434
2434
  ...query,
2435
2435
  };
2436
2436
  if (
2437
2437
  this.info.shopInfo?.shopId &&
2438
2438
  this.info.shopInfo?.venderId &&
2439
2439
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
2440
2440
  ) {
2441
2441
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
2442
2442
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
2443
2443
  console.log(
2444
2444
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
2445
2445
  this.info.queryInfo,
2446
2446
  );
2447
2447
  }
2448
2448
  }
2449
2449
  this.info.queryInfo['shopId'] &&
2450
2450
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
2451
2451
  this.info.queryInfo['venderId'] &&
2452
2452
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
2453
2453
  console.log(
2454
2454
  'h5==获取店铺下发查询参数\n',
2455
2455
  query,
2456
2456
  '\n获取店铺最后查询参数\n',
2457
2457
  this.info.queryInfo,
2458
2458
  '\n是否为更新店铺状态\n',
2459
2459
  updateShopInfoState,
2460
2460
  );
2461
2461
  const changeArea = un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : '';
2462
2462
  if (changeArea) {
2463
2463
  this.info.pageInfo.address = changeArea;
2464
2464
  this.info.pageInfo.un_area = changeArea;
2465
2465
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',');
2466
2466
  }
2467
2467
  }
2468
2468
 
2469
2469
  dealLoadSdkList() {
2470
2470
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
2471
2471
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
2472
2472
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
2473
2473
  let mergeLoadJsList = globalLoadJsList;
2474
2474
  try {
2475
2475
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
2476
2476
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
2477
2477
  getFindIndex !== -1
2478
2478
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
2479
2479
  : accArr.push(current);
2480
2480
  return accArr;
2481
2481
  }, []);
2482
2482
  } catch (e) {
2483
2483
  console.log('LoadJsList合并错误', e);
2484
2484
  }
2485
2485
  console.log(
2486
2486
  'globalLoadJsList',
2487
2487
  globalLoadJsList,
2488
2488
  'businessLoadJsList',
2489
2489
  businessLoadJsList,
2490
2490
  '两个加载jsList集合合并完成',
2491
2491
  mergeLoadJsList,
2492
2492
  );
2493
2493
  this.loadJsSdkList = mergeLoadJsList;
2494
2494
  return this.loadJsSdkList;
2495
2495
  }
2496
2496
 
2497
2497
  renderNextTickLoadSdk() {
2498
2498
  Taro.nextTick(() => {
2499
2499
  console.log(
2500
2500
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
2501
2501
  );
2502
2502
  setTimeout(() => {
2503
2503
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
2504
2504
  }, 1000);
2505
2505
  });
2506
2506
  }
2507
2507
 
2508
2508
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
2509
2509
  const getLoadJsList =
2510
2510
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
2511
2511
  const getLoadFilterList = getLoadJsList.filter((item) => {
2512
2512
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
2513
2513
  let getLoastLoadEventState = true;
2514
2514
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
2515
2515
  getLoastLoadEventState = isJdApp;
2516
2516
  }
2517
2517
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
2518
2518
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
2519
2519
  }
2520
2520
  const getInitTriggerType =
2521
2521
  isJdApp && item?.initJdAppTriggerType
2522
2522
  ? item?.initTriggerType
2523
2523
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
2524
2524
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
2525
2525
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
2526
2526
  });
2527
2527
  console.log(
2528
2528
  '获取当前触发方式',
2529
2529
  triggerType,
2530
2530
  '获取当前最后加载的js集合',
2531
2531
  getLoadFilterList,
2532
2532
  '过滤前的加载集合',
2533
2533
  getLoadJsList,
2534
2534
  );
2535
2535
  getLoadFilterList.length > 0 &&
2536
2536
  getLoadFilterList.forEach((item) => {
2537
2537
  const isLoadState = /sgm/.test(item?.fileName)
2538
2538
  ? window?.shopGlobalSwitch?.openSgm === 'true'
2539
2539
  : true;
2540
2540
  isLoadState &&
2541
2541
  this.loadItemSdkPromise(item)
2542
2542
  .then((res) => {
2543
2543
  console.info('当前js地址' + item?.src, '加载状态', res);
2544
2544
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
2545
2545
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
2546
2546
  window.dra.run('init', { aid: res?.aid });
2547
2547
  window.dra.run('start');
2548
2548
  }
2549
2549
  })
2550
2550
  .catch((err) => {
2551
2551
  console.info('当前js地址加载异常', item?.src);
2552
2552
  window?.fetchErrorData &&
2553
2553
  window.fetchErrorData({
2554
2554
  title: '公共js加载异常',
2555
2555
  type: 'jsLoad',
2556
2556
  data: err,
2557
2557
  });
2558
2558
  });
2559
2559
  });
2560
2560
  }
2561
2561
  loadScriptEle(jsInfo, resolve, reject) {
2562
2562
  const getFileName = jsInfo?.fileName;
2563
2563
  if (getFileName) {
2564
2564
  const getEleId = `J_loadJs_${getFileName}`;
2565
2565
  const getEle = document.getElementById(getEleId);
2566
2566
  if (!getEle) {
2567
2567
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2568
2568
  const _sgmEle = document.createElement('script');
2569
2569
  _sgmEle.id = getEleId;
2570
2570
  _sgmEle.onload = function () {
2571
2571
  resolve({
2572
2572
  ...jsInfo,
2573
2573
  jsTip: 'js加载成功',
2574
2574
  });
2575
2575
  };
2576
2576
  _sgmEle.onerror = function () {
2577
2577
  reject({
2578
2578
  ...jsInfo,
2579
2579
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2580
2580
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
2581
2581
  });
2582
2582
  };
2583
2583
  const dataAttrList = ['timeout', 'fileName', 'env'];
2584
2584
  const getJsInfoKeyList = Object.keys(jsInfo);
2585
2585
  getJsInfoKeyList.forEach((key) => {
2586
2586
  if (key === 'async') {
2587
2587
  _sgmEle.async = jsInfo[key];
2588
2588
  } else if (key === 'crossOrigin') {
2589
2589
  _sgmEle.crossOrigin = jsInfo[key];
2590
2590
  } else if (key === 'src') {
2591
2591
  _sgmEle.src = `${jsInfo[key]}`;
2592
2592
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
2593
2593
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
2594
2594
  } else {
2595
2595
  _sgmEle.setAttribute(key, jsInfo[key]);
2596
2596
  }
2597
2597
  });
2598
2598
  document.head.appendChild(_sgmEle);
2599
2599
  } else {
2600
2600
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
2601
2601
  resolve({
2602
2602
  ...jsInfo,
2603
2603
  jsTip: 'js本身已存在页面中',
2604
2604
  });
2605
2605
  }
2606
2606
  } else {
2607
2607
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
2608
2608
  }
2609
2609
  }
2610
2610
 
2611
2611
  loadItemSdkPromise(jsInfo = {}) {
2612
2612
  if (jsInfo?.src) {
2613
2613
  const getInitLoadType =
2614
2614
  isJdApp && jsInfo?.initJdAppLoadType
2615
2615
  ? jsInfo?.initJdAppLoadType
2616
2616
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
2617
2617
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
2618
2618
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
2619
2619
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
2620
2620
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
2621
2621
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2622
2622
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2623
2623
  try {
2624
2624
  const jsXhrRequest = new XMLHttpRequest();
2625
2625
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
2626
2626
  const jsUrl = `${jsInfo?.src}`;
2627
2627
  jsXhrRequest.open('GET', jsUrl, true);
2628
2628
  jsXhrRequest.onreadystatechange = () => {
2629
2629
  if (jsXhrRequest.readyState === 4) {
2630
2630
  const getReqStatus = jsXhrRequest.status;
2631
2631
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
2632
2632
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
2633
2633
  if (getInsetHeadState) {
2634
2634
  this.loadScriptEle(jsInfo, resolve, reject);
2635
2635
  } else {
2636
2636
  resolve({
2637
2637
  ...jsInfo,
2638
2638
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
2639
2639
  });
2640
2640
  }
2641
2641
  getReqStatus !== 200 &&
2642
2642
  sgmCustomReport({
2643
2643
  type: 3,
2644
2644
  code: 'js_load_special_code',
2645
2645
  msg: {
2646
2646
  msg: '当前js加载成功,状态非200,特殊上报观察',
2647
2647
  jsReqState: getReqStatus,
2648
2648
  env: getSgmCustomCode('js_load_special_code'),
2649
2649
  data: jsInfo,
2650
2650
  },
2651
2651
  });
2652
2652
  } else {
2653
2653
  const getRes = {
2654
2654
  ...jsInfo,
2655
2655
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2656
2656
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
2657
2657
  jsReqState: getReqStatus,
2658
2658
  };
2659
2659
  console.log('当前js请求状态异常,具体信息见', getRes);
2660
2660
  reject(getRes);
2661
2661
  }
2662
2662
  }
2663
2663
  };
2664
2664
  jsXhrRequest.onerror = () => {
2665
2665
  const getRes = {
2666
2666
  ...jsInfo,
2667
2667
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2668
2668
  jsReqError: '请求错误',
2669
2669
  };
2670
2670
  console.log('当前js请求错误', getRes);
2671
2671
  jsXhrRequest.abort();
2672
2672
  reject(getRes);
2673
2673
  };
2674
2674
  jsXhrRequest.ontimeout = () => {
2675
2675
  const getRes = {
2676
2676
  ...jsInfo,
2677
2677
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2678
2678
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
2679
2679
  jsReqState: jsXhrRequest.status,
2680
2680
  };
2681
2681
  console.log('当前js请求超时异常', getRes);
2682
2682
  jsXhrRequest.abort();
2683
2683
  reject(getRes);
2684
2684
  };
2685
2685
  jsXhrRequest.send();
2686
2686
  } catch (e) {
2687
2687
  console.log('执行js请求异常', e);
2688
2688
  reject({
2689
2689
  ...jsInfo,
2690
2690
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2691
2691
  jsReqError: '未知异常',
2692
2692
  error: e,
2693
2693
  });
2694
2694
  }
2695
2695
  });
2696
2696
  } else {
2697
2697
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2698
2698
  return this.loadScriptEle(jsInfo, resolve, reject);
2699
2699
  });
2700
2700
  }
2701
2701
  }
2702
2702
  return this.loadJsSdkListCachePromise[getFileKeyName];
2703
2703
  } else {
2704
2704
  return Promise.resolve({
2705
2705
  ...jsInfo,
2706
2706
  jsTip: 'js加载方式设置为不加载,当前不做处理',
2707
2707
  });
2708
2708
  }
2709
2709
  } else {
2710
2710
  return Promise.reject(jsInfo);
2711
2711
  }
2712
2712
  }