@conecli/cone-render 0.10.1-shop3.15 → 0.10.1-shop3.16

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