@conecli/cone-render 0.8.20-shop.189 → 0.8.20-shop.190

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