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

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 : ipLoc_djd ? ipLoc_djd : '';
1128
1127
  if (changeArea) {
1129
1128
  this.info.pageInfo.address = changeArea;
1130
1129
  this.info.pageInfo.un_area = changeArea;
1131
1130
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',');
1132
1131
  }
1133
1132
  }
1134
1133
 
1135
1134
  dealLoadSdkList() {
1136
1135
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
1137
1136
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
1138
1137
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
1139
1138
  let mergeLoadJsList = globalLoadJsList;
1140
1139
  try {
1141
1140
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
1142
1141
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
1143
1142
  getFindIndex !== -1
1144
1143
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
1145
1144
  : accArr.push(current);
1146
1145
  return accArr;
1147
1146
  }, []);
1148
1147
  } catch (e) {
1149
1148
  console.log('LoadJsList合并错误', e);
1150
1149
  }
1151
1150
  console.log(
1152
1151
  'globalLoadJsList',
1153
1152
  globalLoadJsList,
1154
1153
  'businessLoadJsList',
1155
1154
  businessLoadJsList,
1156
1155
  '两个加载jsList集合合并完成',
1157
1156
  mergeLoadJsList,
1158
1157
  );
1159
1158
  this.loadJsSdkList = mergeLoadJsList;
1160
1159
  return this.loadJsSdkList;
1161
1160
  }
1162
1161
 
1163
1162
  renderNextTickLoadSdk() {
1164
1163
  Taro.nextTick(() => {
1165
1164
  console.log(
1166
1165
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
1167
1166
  );
1168
1167
  setTimeout(() => {
1169
1168
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
1170
1169
  }, 1000);
1171
1170
  });
1172
1171
  }
1173
1172
 
1174
1173
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
1175
1174
  const getLoadJsList =
1176
1175
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
1177
1176
  const getLoadFilterList = getLoadJsList.filter((item) => {
1178
1177
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
1179
1178
  let getLoastLoadEventState = true;
1180
1179
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
1181
1180
  getLoastLoadEventState = isJdApp;
1182
1181
  }
1183
1182
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
1184
1183
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
1185
1184
  }
1186
1185
  const getInitTriggerType =
1187
1186
  isJdApp && item?.initJdAppTriggerType
1188
1187
  ? item?.initTriggerType
1189
1188
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
1190
1189
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
1191
1190
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
1192
1191
  });
1193
1192
  console.log(
1194
1193
  '获取当前触发方式',
1195
1194
  triggerType,
1196
1195
  '获取当前最后加载的js集合',
1197
1196
  getLoadFilterList,
1198
1197
  '过滤前的加载集合',
1199
1198
  getLoadJsList,
1200
1199
  );
1201
1200
  getLoadFilterList.length > 0 &&
1202
1201
  getLoadFilterList.forEach((item) => {
1203
1202
  const isLoadState = /sgm/.test(item?.fileName)
1204
1203
  ? window?.shopGlobalSwitch?.openSgm === 'true'
1205
1204
  : true;
1206
1205
  isLoadState &&
1207
1206
  this.loadItemSdkPromise(item)
1208
1207
  .then((res) => {
1209
1208
  console.info('当前js地址' + item?.src, '加载状态', res);
1210
1209
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
1211
1210
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
1212
1211
  window.dra.run('init', { aid: res?.aid });
1213
1212
  window.dra.run('start');
1214
1213
  }
1215
1214
  })
1216
1215
  .catch((err) => {
1217
1216
  console.info('当前js地址加载异常', item?.src);
1218
1217
  window?.fetchErrorData &&
1219
1218
  window.fetchErrorData({
1220
1219
  title: '公共js加载异常',
1221
1220
  type: 'jsLoad',
1222
1221
  data: err,
1223
1222
  });
1224
1223
  });
1225
1224
  });
1226
1225
  }
1227
1226
  loadScriptEle(jsInfo, resolve, reject) {
1228
1227
  const getFileName = jsInfo?.fileName;
1229
1228
  if (getFileName) {
1230
1229
  const getEleId = `J_loadJs_${getFileName}`;
1231
1230
  const getEle = document.getElementById(getEleId);
1232
1231
  if (!getEle) {
1233
1232
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1234
1233
  const _sgmEle = document.createElement('script');
1235
1234
  _sgmEle.id = getEleId;
1236
1235
  _sgmEle.onload = function () {
1237
1236
  resolve({
1238
1237
  ...jsInfo,
1239
1238
  jsTip: 'js加载成功',
1240
1239
  });
1241
1240
  };
1242
1241
  _sgmEle.onerror = function () {
1243
1242
  reject({
1244
1243
  ...jsInfo,
1245
1244
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1246
1245
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
1247
1246
  });
1248
1247
  };
1249
1248
  const dataAttrList = ['timeout', 'fileName', 'env'];
1250
1249
  const getJsInfoKeyList = Object.keys(jsInfo);
1251
1250
  getJsInfoKeyList.forEach((key) => {
1252
1251
  if (key === 'async') {
1253
1252
  _sgmEle.async = jsInfo[key];
1254
1253
  } else if (key === 'crossOrigin') {
1255
1254
  _sgmEle.crossOrigin = jsInfo[key];
1256
1255
  } else if (key === 'src') {
1257
1256
  _sgmEle.src = `${jsInfo[key]}`;
1258
1257
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
1259
1258
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
1260
1259
  } else {
1261
1260
  _sgmEle.setAttribute(key, jsInfo[key]);
1262
1261
  }
1263
1262
  });
1264
1263
  document.head.appendChild(_sgmEle);
1265
1264
  } else {
1266
1265
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
1267
1266
  resolve({
1268
1267
  ...jsInfo,
1269
1268
  jsTip: 'js本身已存在页面中',
1270
1269
  });
1271
1270
  }
1272
1271
  } else {
1273
1272
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
1274
1273
  }
1275
1274
  }
1276
1275
 
1277
1276
  loadItemSdkPromise(jsInfo = {}) {
1278
1277
  if (jsInfo?.src) {
1279
1278
  const getInitLoadType =
1280
1279
  isJdApp && jsInfo?.initJdAppLoadType
1281
1280
  ? jsInfo?.initJdAppLoadType
1282
1281
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
1283
1282
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
1284
1283
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
1285
1284
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
1286
1285
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
1287
1286
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1288
1287
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1289
1288
  try {
1290
1289
  const jsXhrRequest = new XMLHttpRequest();
1291
1290
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
1292
1291
  const jsUrl = `${jsInfo?.src}`;
1293
1292
  jsXhrRequest.open('GET', jsUrl, true);
1294
1293
  jsXhrRequest.onreadystatechange = () => {
1295
1294
  if (jsXhrRequest.readyState === 4) {
1296
1295
  const getReqStatus = jsXhrRequest.status;
1297
1296
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
1298
1297
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
1299
1298
  if (getInsetHeadState) {
1300
1299
  this.loadScriptEle(jsInfo, resolve, reject);
1301
1300
  } else {
1302
1301
  resolve({
1303
1302
  ...jsInfo,
1304
1303
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
1305
1304
  });
1306
1305
  }
1307
1306
  getReqStatus !== 200 &&
1308
1307
  sgmCustomReport({
1309
1308
  type: 3,
1310
1309
  code: 'js_load_special_code',
1311
1310
  msg: {
1312
1311
  msg: '当前js加载成功,状态非200,特殊上报观察',
1313
1312
  jsReqState: getReqStatus,
1314
1313
  env: getSgmCustomCode('js_load_special_code'),
1315
1314
  data: jsInfo,
1316
1315
  },
1317
1316
  });
1318
1317
  } else {
1319
1318
  const getRes = {
1320
1319
  ...jsInfo,
1321
1320
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1322
1321
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
1323
1322
  jsReqState: getReqStatus,
1324
1323
  };
1325
1324
  console.log('当前js请求状态异常,具体信息见', getRes);
1326
1325
  reject(getRes);
1327
1326
  }
1328
1327
  }
1329
1328
  };
1330
1329
  jsXhrRequest.onerror = () => {
1331
1330
  const getRes = {
1332
1331
  ...jsInfo,
1333
1332
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1334
1333
  jsReqError: '请求错误',
1335
1334
  };
1336
1335
  console.log('当前js请求错误', getRes);
1337
1336
  jsXhrRequest.abort();
1338
1337
  reject(getRes);
1339
1338
  };
1340
1339
  jsXhrRequest.ontimeout = () => {
1341
1340
  const getRes = {
1342
1341
  ...jsInfo,
1343
1342
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1344
1343
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
1345
1344
  jsReqState: jsXhrRequest.status,
1346
1345
  };
1347
1346
  console.log('当前js请求超时异常', getRes);
1348
1347
  jsXhrRequest.abort();
1349
1348
  reject(getRes);
1350
1349
  };
1351
1350
  jsXhrRequest.send();
1352
1351
  } catch (e) {
1353
1352
  console.log('执行js请求异常', e);
1354
1353
  reject({
1355
1354
  ...jsInfo,
1356
1355
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1357
1356
  jsReqError: '未知异常',
1358
1357
  error: e,
1359
1358
  });
1360
1359
  }
1361
1360
  });
1362
1361
  } else {
1363
1362
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1364
1363
  return this.loadScriptEle(jsInfo, resolve, reject);
1365
1364
  });
1366
1365
  }
1367
1366
  }
1368
1367
  return this.loadJsSdkListCachePromise[getFileKeyName];
1369
1368
  } else {
1370
1369
  return Promise.resolve({
1371
1370
  ...jsInfo,
1372
1371
  jsTip: 'js加载方式设置为不加载,当前不做处理',
1373
1372
  });
1374
1373
  }
1375
1374
  } else {
1376
1375
  return Promise.reject(jsInfo);
1377
1376
  }
1378
1377
  }
1378
+ import Taro from '@tarojs/taro';
1379
1379
  dealNativePixelToCssPixel,
1380
1380
  isAndroidDevice,
1381
1381
  isIosDevice,
1382
1382
  isJdAndAndroidDevice,
1383
1383
  isJdAndHarmonyDevice,
1384
1384
  isObject,
1385
1385
  isPc,
1386
1386
  isString,
1387
1387
  jdAppVersion,
1388
1388
  jdAppVersionStr,
1389
1389
  serialize,
1390
1390
  draBusinessCustomReport,
1391
1391
  BUSINESS_TYPE,
1392
1392
  LoadJsInitLoadEnvType,
1393
1393
  LoadJsInitLoadType,
1394
1394
  LoadJsInitTriggerType,
1395
1395
  MPAAS_CONFIG_APP_LOW_VERSION,
1396
1396
  MPAAS_CONFIG_APP_VERSION,
1397
1397
  SECTION_HOME_TAB_NAME_TYPE,
1398
1398
  SECTION_HOME_TAB_TYPE,
1399
1399
  TaroEventType,
1400
1400
  WX_BUSINESS_TYPE,
1401
1401
  WXAPP_BIZ_KEY,
1402
1402
  WXAPP_BIZ_SHOP_LIGHT_KEY,
1403
1403
  JSSDK_APP_WEBVIEW_CODE,
1404
1404
  getSystemInfos,
1405
1405
  getTaroStorageKeyValue,
1406
1406
  ipLoc_djd,
1407
1407
  setTaroStorage,
1408
1408
  sgmCustomReport,
1409
1409
  const designWidth = 750;
1410
1410
  return (
1411
1411
  Math.ceil((((parseInt(String(size), 10) / 40) * 750) / designWidth) * 10000) / 10000 + 'rem'
1412
1412
  );
1413
1413
  abTestLabels: {},
1414
1414
  loginState: false,
1415
1415
  cookiesStr: '',
1416
1416
  userInfo: userPinKey,
1417
1417
  isJingGouMiniViewState: false,
1418
1418
  isJingxiMiniViewState: false,
1419
1419
  pageInfo: {
1420
1420
  wxBusinessType: WX_BUSINESS_TYPE.NO,
1421
1421
  address: '',
1422
1422
  addressCommaStr: '',
1423
1423
  un_area: '',
1424
1424
  vapptype: '1',
1425
1425
  pageType: 'home',
1426
1426
  isExposureState: false,
1427
1427
  moduleId: '',
1428
1428
  entrance: '',
1429
1429
  dataType: BUSINESS_TYPE.ONLINE,
1430
1430
  floorExposureInfo: {},
1431
1431
  floorVideInfo: {},
1432
1432
  productVideInfo: {},
1433
1433
  tabsLoadAllDataInfo: {
1434
1434
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
1435
1435
  },
1436
1436
  updateShopInfosAllState: false,
1437
1437
  isVipShop: false,
1438
1438
  isJdShowNativeImmersivePlayer: false,
1439
1439
  ...shopConfig,
1440
1440
  pageScrollTop: 0,
1441
1441
  pageIdxHeightInfo: {
1442
1442
  list: [],
1443
1443
  },
1444
1444
  shopNavBarHeight: 0,
1445
1445
  },
1446
1446
  defaultQueryLogInfo: {
1447
1447
  sourceType: 'JDshop',
1448
1448
  sourceValue: '',
1449
1449
  moduleId: 'none',
1450
1450
  entrance: 'none',
1451
1451
  },
1452
1452
  sysInfo: {
1453
1453
  windowWidth: isPc ? 375 : 0,
1454
1454
  containerWidth: isPc ? 375 : 0,
1455
1455
  windowHeight: 0,
1456
1456
  netWorkType: '4g',
1457
1457
  jdBottomBarHeight: 0,
1458
1458
  jdNativeHeaderHeight: 0,
1459
1459
  isJdTabletDevice: false,
1460
1460
  isJdTabletLandscape: false,
1461
1461
  },
1462
1462
  queryInfo: {},
1463
1463
  shopInfo: {},
1464
1464
  openAppData: {},
1465
1465
  public info: CommonInterFace.BaseConfigInfo;
1466
1466
  public config: {
1467
1467
  [key: string]: any;
1468
1468
  };
1469
1469
  public lazyContainer: CommonInterFace.lazyContainer;
1470
1470
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
1471
1471
  public rootEleNode: HTMLElement | null;
1472
1472
  public checkStatusAndLoginPromise: object | null;
1473
1473
  private jmfeRegisterStatePromise: Promise<any> | null;
1474
1474
  private jdScreenSizeInfoPromise: Promise<any> | null;
1475
1475
  private rootEleWidthRegisterPromise: Promise<any> | null;
1476
1476
  private jmfeRegisterState: boolean;
1477
1477
  public loadJsSdkList: Array<any>;
1478
1478
  public loadJsSdkListCachePromise: any;
1479
1479
  public rootEleInitWidth: number;
1480
1480
  constructor(opt) {
1481
1481
  this.info = this._getConfig(opt);
1482
1482
  this.config = {};
1483
1483
  this.loadJsSdkList = [];
1484
1484
  this.loadJsSdkListCachePromise = {};
1485
1485
  this.lazyContainer = {
1486
1486
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
1487
1487
  appLazyContainerList: [],
1488
1488
  appLazyFinishContainerList: [],
1489
1489
  },
1490
1490
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
1491
1491
  appLazyContainerList: [],
1492
1492
  appLazyFinishContainerList: [],
1493
1493
  },
1494
1494
  };
1495
1495
  this.renderedIsvComponents = {};
1496
1496
  this.rootEleNode = document.querySelector('body');
1497
1497
  this.checkStatusAndLoginPromise = null;
1498
1498
  this.jmfeRegisterStatePromise = null;
1499
1499
  this.jdScreenSizeInfoPromise = null;
1500
1500
  this.rootEleWidthRegisterPromise = null;
1501
1501
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
1502
1502
  this.loadOtherSdk();
1503
1503
  if (isJdApp) {
1504
1504
  this.jmfeReayPromise();
1505
1505
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
1506
1506
  }
1507
1507
  }
1508
1508
  _getConfig(opt) {
1509
1509
  return Object.assign({}, DefaultConfig, opt);
1510
1510
  }
1511
1511
  _getJdPadMinWidthForListen() {
1512
1512
  return (
1513
1513
  isJdApp &&
1514
1514
  Math.min(window.screen.width, window.screen.height) >
1515
1515
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
1516
1516
  );
1517
1517
  }
1518
1518
 
1519
1519
  jmfeReayPromise(): Promise<any> {
1520
1520
  if (isJdApp) {
1521
1521
  if (this.jmfeRegisterState) {
1522
1522
  return Promise.resolve(true);
1523
1523
  } else {
1524
1524
  !this.jmfeRegisterStatePromise &&
1525
1525
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
1526
1526
  ready('jmfe', 3000)
1527
1527
  .then(() => {
1528
1528
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
1529
1529
  this.jmfeRegisterState = true;
1530
1530
  resolve(true);
1531
1531
  console.log('松果app内初始化注册jmfe认证完成');
1532
1532
  })
1533
1533
  .catch((err) => {
1534
1534
  console.error('jmfe ready error', err);
1535
1535
  reject(false);
1536
1536
  });
1537
1537
  }));
1538
1538
  return this.jmfeRegisterStatePromise;
1539
1539
  }
1540
1540
  } else {
1541
1541
  return Promise.reject(false);
1542
1542
  }
1543
1543
  }
1544
1544
 
1545
1545
  getJdScreenSizeInfoPromise() {
1546
1546
  !this.jdScreenSizeInfoPromise &&
1547
1547
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
1548
1548
  const getThisTime = Date.now();
1549
1549
  this.jmfeReayPromise().then(() => {
1550
1550
  return Promise.race([
1551
1551
  window.jmfe.getScreenSize(),
1552
1552
  this.taskTimeoutPromise(() => {
1553
1553
  return {
1554
1554
  status: '-10',
1555
1555
  msg: '获取大屏信息2s超时',
1556
1556
  };
1557
1557
  }),
1558
1558
  ])
1559
1559
  .then((res) => {
1560
1560
  console.warn('===获取app大屏信息====', res);
1561
1561
  const { status, data } = res;
1562
1562
  if (status === '0' && data) {
1563
1563
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
1564
1564
  const getPageInfo = dealNativePixelToCssPixel({
1565
1565
  pageWidth,
1566
1566
  pageHeight,
1567
1567
  });
1568
1568
  this.info.sysInfo.jdScreenSizeType = sizeType;
1569
1569
  const getUseTime = Date.now() - getThisTime;
1570
1570
  console.warn(
1571
1571
  '===计算是否是app大屏信息,需满足宽度最新720===',
1572
1572
  getPageInfo,
1573
1573
  '原始数据',
1574
1574
  data,
1575
1575
  '是否是横屏isLandscape为1=',
1576
1576
  isLandscape,
1577
1577
  '用时',
1578
1578
  getUseTime,
1579
1579
  );
1580
1580
  if (getPageInfo?.pageWidth > 0) {
1581
1581
  this.rootEleInitWidth = getPageInfo?.pageWidth;
1582
1582
  draBusinessCustomReport({
1583
1583
  type: 'rootEle_width_getJdScreenSizeInfo',
1584
1584
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
1585
1585
  originReqDataStr: JSON.stringify({
1586
1586
  isJdApp,
1587
1587
  getPageInfo,
1588
1588
  originData: res,
1589
1589
  }),
1590
1590
  });
1591
1591
  resolve(getPageInfo);
1592
1592
  } else {
1593
1593
  resolve({
1594
1594
  pageWidth: 0,
1595
1595
  pageHeight: 0,
1596
1596
  msg: '转换异常',
1597
1597
  });
1598
1598
  }
1599
1599
  } else {
1600
1600
  resolve({
1601
1601
  pageWidth: 0,
1602
1602
  pageHeight: 0,
1603
1603
  msg: '获取大屏信息异常或者超时',
1604
1604
  });
1605
1605
  }
1606
1606
  })
1607
1607
  .catch((err) => {
1608
1608
  console.log('获取大屏信息异常', err);
1609
1609
  resolve({
1610
1610
  pageWidth: 0,
1611
1611
  pageHeight: 0,
1612
1612
  msg: '获取大屏信息异常',
1613
1613
  });
1614
1614
  });
1615
1615
  });
1616
1616
  }));
1617
1617
  return this.jdScreenSizeInfoPromise;
1618
1618
  }
1619
1619
 
1620
1620
  listenJdTabletScreenChange() {
1621
1621
  this.jmfeReayPromise().then(() => {
1622
1622
  try {
1623
1623
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
1624
1624
  window.jmfe.listenDeviceScreenChange((event) => {
1625
1625
  console.log(
1626
1626
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
1627
1627
  event,
1628
1628
  '通过前端判断是不是横屏',
1629
1629
  window.matchMedia('(orientation: landscape)')?.matches,
1630
1630
  );
1631
1631
  const { orientation } = event?.data;
1632
1632
  if (orientation) {
1633
1633
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
1634
1634
  Taro.eventCenter.trigger(
1635
1635
  TaroEventType.TABLE_SCREEN_CHANGE,
1636
1636
  this.info.sysInfo.isJdTabletLandscape,
1637
1637
  orientation,
1638
1638
  );
1639
1639
  }
1640
1640
  });
1641
1641
  } catch (error) {
1642
1642
  console.log('listenScreenChange的打印error:', error);
1643
1643
  }
1644
1644
  });
1645
1645
  }
1646
1646
 
1647
1647
  updateBusinessDomainAndApi(domain, api) {
1648
1648
  }
1649
1649
 
1650
1650
  formatNativeScreenPageData(action) {
1651
1651
  let getChangePageInfo: any = null;
1652
1652
  try {
1653
1653
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
1654
1654
  JSON.stringify({
1655
1655
  plugin: 'JDHybridScreenPlugin',
1656
1656
  action,
1657
1657
  sync: '1',
1658
1658
  }),
1659
1659
  );
1660
1660
  const getChangePageInfoData =
1661
1661
  typeof getNativeScreenPageInfoStr === 'string'
1662
1662
  ? JSON.parse(getNativeScreenPageInfoStr)
1663
1663
  : null;
1664
1664
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
1665
1665
  const { code, data } = getChangePageInfoData;
1666
1666
  getChangePageInfo = code && code === '0' ? data : null;
1667
1667
  }
1668
1668
  } catch (e) {
1669
1669
  console.log('JDHybridScreenPlugin转换异常', e);
1670
1670
  }
1671
1671
  return getChangePageInfo;
1672
1672
  }
1673
1673
 
1674
1674
  isAndroidFoldScreen() {
1675
1675
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
1676
1676
  }
1677
1677
 
1678
1678
  getJdAndroidPageChangeScreenInfo() {
1679
1679
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
1680
1680
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
1681
1681
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1682
1682
  pageWidth: getPageScreenInfo.pageWidth,
1683
1683
  pageHeight: getPageScreenInfo.pageHeight,
1684
1684
  });
1685
1685
  getPageScreenInfo.pageWidth = pageWidth;
1686
1686
  getPageScreenInfo.pageHeight = pageHeight;
1687
1687
  }
1688
1688
  return getPageScreenInfo;
1689
1689
  }
1690
1690
 
1691
1691
  getRootEleWindowWidthInfo() {
1692
1692
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
1693
1693
  const getWindowWidth = window.innerWidth;
1694
1694
  const getScreenWidth = window.screen.width;
1695
1695
  return {
1696
1696
  getRootEleWidth,
1697
1697
  getWindowWidth,
1698
1698
  getScreenWidth,
1699
1699
  };
1700
1700
  }
1701
1701
 
1702
1702
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
1703
1703
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
1704
1704
  console.log(
1705
1705
  '当前获取根元素的宽度',
1706
1706
  getRootEleWidth,
1707
1707
  'getWindowWidth',
1708
1708
  getWindowWidth,
1709
1709
  'getScreenWidth',
1710
1710
  getScreenWidth,
1711
1711
  );
1712
1712
  const getLastWidth =
1713
1713
  getRootEleWidth > 0
1714
1714
  ? Math.round(getRootEleWidth)
1715
1715
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
1716
1716
  console.warn(
1717
1717
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1718
1718
  );
1719
1719
  timeout > 0 &&
1720
1720
  draBusinessCustomReport({
1721
1721
  type: 'rootEle_width_timeout_getJdScreenSizeInfo',
1722
1722
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1723
1723
  originReqDataStr: JSON.stringify({
1724
1724
  isJdApp,
1725
1725
  getRootEleWidth,
1726
1726
  getWindowWidth,
1727
1727
  getScreenWidth,
1728
1728
  ...reportParam,
1729
1729
  }),
1730
1730
  });
1731
1731
  return getLastWidth;
1732
1732
  }
1733
1733
 
1734
1734
  getPadWindowRootEleWidthPromise() {
1735
1735
  if (this.rootEleInitWidth > 0) {
1736
1736
  return Promise.resolve(this.rootEleInitWidth);
1737
1737
  } else {
1738
1738
  !this.rootEleWidthRegisterPromise &&
1739
1739
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
1740
1740
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
1741
1741
  if (getRootEleInitWidth > 0) {
1742
1742
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
1743
1743
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
1744
1744
  resolve(this.rootEleInitWidth);
1745
1745
  } else {
1746
1746
  const timerPromise = () => {
1747
1747
  return new Promise((resolve2) => {
1748
1748
  window.setTimeout(() => {
1749
1749
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
1750
1750
  this.getRootEleWindowWidthInfo();
1751
1751
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
1752
1752
  console.warn(
1753
1753
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
1754
1754
  );
1755
1755
  draBusinessCustomReport({
1756
1756
  type: 'rootEle_width_200_timeout_info',
1757
1757
  errMsg: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
1758
1758
  originReqDataStr: JSON.stringify({
1759
1759
  isJdApp,
1760
1760
  getRootEleWidth,
1761
1761
  getWindowWidth,
1762
1762
  getScreenWidth,
1763
1763
  }),
1764
1764
  });
1765
1765
  const getRes =
1766
1766
  getRootEleWidth > 0 && getWindowWidth > 0
1767
1767
  ? Math.min(getRootEleWidth, getWindowWidth)
1768
1768
  : Math.max(getRootEleWidth, getWindowWidth);
1769
1769
  resolve2({
1770
1770
  pageWidth: Math.round(getRes),
1771
1771
  });
1772
1772
  }
1773
1773
  }, 200);
1774
1774
  });
1775
1775
  };
1776
1776
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
1777
1777
  const { pageWidth } = res;
1778
1778
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
1779
1779
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
1780
1780
  });
1781
1781
  }
1782
1782
  }));
1783
1783
  return this.rootEleWidthRegisterPromise;
1784
1784
  }
1785
1785
  }
1786
1786
 
1787
1787
  async getSystemInfo(params) {
1788
1788
  const getParams = Object.assign({}, params || {});
1789
1789
  if (this.rootEleInitWidth > 0) {
1790
1790
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
1791
1791
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
1792
1792
  } else {
1793
1793
  if (this._getJdPadMinWidthForListen()) {
1794
1794
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
1795
1795
  getParams['replaceSystemWidth'] = true;
1796
1796
  }
1797
1797
  }
1798
1798
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
1799
1799
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
1800
1800
  let _isfoldScreen = false;
1801
1801
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
1802
1802
  console.info(
1803
1803
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
1804
1804
  getStorageData,
1805
1805
  '通过缓存值第一次判断是否是折叠屏',
1806
1806
  getStorageData === 'true',
1807
1807
  );
1808
1808
  if (!getStorageData) {
1809
1809
  _isfoldScreen = this.isAndroidFoldScreen();
1810
1810
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
1811
1811
  } else {
1812
1812
  _isfoldScreen = getStorageData === 'true';
1813
1813
  }
1814
1814
  if (_isfoldScreen) {
1815
1815
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
1816
1816
  if (getJdAndroidPageInfo) {
1817
1817
  info = getSystemInfos(getJdAndroidPageInfo);
1818
1818
  console.warn(
1819
1819
  '当前为松果安卓折叠屏app,获取折叠屏信息',
1820
1820
  getJdAndroidPageInfo,
1821
1821
  '获取转换后的系统信息',
1822
1822
  info,
1823
1823
  );
1824
1824
  sgmCustomReport({
1825
1825
  type: 2,
1826
1826
  code: 'android_jdapp_foldScreen_info',
1827
1827
  msg: {
1828
1828
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
1829
1829
  androidPageInfo: getJdAndroidPageInfo,
1830
1830
  jdAppVersionStr,
1831
1831
  taroSysInfo: info,
1832
1832
  },
1833
1833
  });
1834
1834
  }
1835
1835
  }
1836
1836
  }
1837
1837
  if (isJdApp) {
1838
1838
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
1839
1839
  }
1840
1840
  this.info.sysInfo = {
1841
1841
  actualNavBarHeight: 0,
1842
1842
  ...this.info.sysInfo,
1843
1843
  ...info,
1844
1844
  safeContentHeight: info?.screenHeight,
1845
1845
  headerHeight: 0,
1846
1846
  tabBarHeight: 0,
1847
1847
  };
1848
1848
  if (isJdApp) {
1849
1849
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
1850
1850
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
1851
1851
  this.getAddressCachePromise();
1852
1852
  this.getElderModePromise();
1853
1853
  this.getJDAppearanceStatePromise();
1854
1854
  this.createJdAndroidRquestEventForTouchStart();
1855
1855
  }
1856
1856
  this.getWifiVideoAutoPlayAsync();
1857
1857
  this.getMPaasConfigAsync();
1858
1858
  this.getNetWorkType();
1859
1859
  }
1860
1860
 
1861
1861
  taskTimeoutPromise(callBack, timeout = 2000) {
1862
1862
  return new Promise((resolve) => {
1863
1863
  setTimeout(() => {
1864
1864
  const getCallBackRes = typeof callBack === 'function' && callBack();
1865
1865
  return resolve(getCallBackRes || false);
1866
1866
  }, timeout);
1867
1867
  });
1868
1868
  }
1869
1869
 
1870
1870
  getElderModePromise() {
1871
1871
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1872
1872
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1873
1873
  } else {
1874
1874
  if (isJdAndAndroidDevice) {
1875
1875
  this.info.sysInfo.jdAppModeType = '0';
1876
1876
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1877
1877
  } else {
1878
1878
  return Promise.race([
1879
1879
  this.taskTimeoutPromise(() => {
1880
1880
  this.info.sysInfo.jdAppModeType = '0';
1881
1881
  return this.info.sysInfo.jdAppModeType;
1882
1882
  }),
1883
1883
  new Promise((resolve) => {
1884
1884
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
1885
1885
  if (!window[getCallBackName]) {
1886
1886
  window[getCallBackName] = (res) => {
1887
1887
  try {
1888
1888
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1889
1889
  const { status, data, msg } = getResJson;
1890
1890
  console.log(`获取松果app展示模式成功,返回结果${data}`);
1891
1891
  if (status === '0') {
1892
1892
  this.info.sysInfo.jdAppModeType = data;
1893
1893
  resolve(data);
1894
1894
  } else {
1895
1895
  resolve('0');
1896
1896
  }
1897
1897
  } catch (e) {
1898
1898
  resolve('0');
1899
1899
  }
1900
1900
  window[getCallBackName] = null;
1901
1901
  };
1902
1902
  }
1903
1903
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1904
1904
  method: 'callSyncRouterModuleWithParams',
1905
1905
  params: JSON.stringify({
1906
1906
  routerURL: 'router://JDBModeModule/getCurrentMode',
1907
1907
  routerParam: {},
1908
1908
  callBackName: `window.${getCallBackName}`,
1909
1909
  callBackId: `${getCallBackName}Ios`,
1910
1910
  }),
1911
1911
  });
1912
1912
  }),
1913
1913
  ]);
1914
1914
  }
1915
1915
  }
1916
1916
  }
1917
1917
  getAPPUseStraightCorner() {
1918
1918
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
1919
1919
  const params = {
1920
1920
  routerURL,
1921
1921
  routerParam: {},
1922
1922
  jdRouter: '1',
1923
1923
  };
1924
1924
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
1925
1925
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
1926
1926
  } else {
1927
1927
  return this.jmfeReayPromise()
1928
1928
  .then(() => {
1929
1929
  if (isJdAndHarmonyDevice || !isJdApp) {
1930
1930
  console.log('not APP or is Harmony');
1931
1931
  return Promise.resolve(false);
1932
1932
  }
1933
1933
  console.log('jmfe setShareInfo', params);
1934
1934
  return Promise.race([
1935
1935
  window.jmfe.callRouter(params),
1936
1936
  this.taskTimeoutPromise(() => {
1937
1937
  return false;
1938
1938
  }),
1939
1939
  ]).then(({ status, data }) => {
1940
1940
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
1941
1941
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
1942
1942
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
1943
1943
  return Promise.resolve(status === '0' && Number(data) === 1);
1944
1944
  });
1945
1945
  })
1946
1946
  .catch((e) => {
1947
1947
  console.log('jmfe error', e);
1948
1948
  return Promise.resolve(false);
1949
1949
  });
1950
1950
  }
1951
1951
  }
1952
1952
 
1953
1953
  getJDAppearanceStatePromise() {
1954
1954
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1955
1955
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
1956
1956
  } else {
1957
1957
  return Promise.race([
1958
1958
  this.taskTimeoutPromise(() => {
1959
1959
  this.info.sysInfo.jdAppearanceState = '0';
1960
1960
  return this.info.sysInfo.jdAppearanceState;
1961
1961
  }),
1962
1962
  new Promise((resolve) => {
1963
1963
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
1964
1964
  if (!window[getCallBackName]) {
1965
1965
  window[getCallBackName] = (res) => {
1966
1966
  try {
1967
1967
  console.log('getJDAppearanceStatePromise', res);
1968
1968
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1969
1969
  const { status, data, msg } = getResJson;
1970
1970
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
1971
1971
  if (status === '0') {
1972
1972
  this.info.sysInfo.jdAppearanceState = data;
1973
1973
  resolve(data);
1974
1974
  } else {
1975
1975
  resolve('0');
1976
1976
  }
1977
1977
  } catch (e) {
1978
1978
  resolve('0');
1979
1979
  }
1980
1980
  window[getCallBackName] = null;
1981
1981
  };
1982
1982
  }
1983
1983
  if (isAndroidDevice) {
1984
1984
  const jsonString = JSON.stringify({
1985
1985
  callBackName: `window.${getCallBackName}`,
1986
1986
  });
1987
1987
  console.log('window.JDAppearance', window?.JDAppearance);
1988
1988
  window?.JDAppearance &&
1989
1989
  window?.JDAppearance?.getUiState &&
1990
1990
  window.JDAppearance.getUiState(jsonString);
1991
1991
  } else {
1992
1992
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1993
1993
  method: 'callSyncRouterModuleWithParams',
1994
1994
  params: JSON.stringify({
1995
1995
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
1996
1996
  routerParam: {},
1997
1997
  callBackName: `window.${getCallBackName}`,
1998
1998
  callBackId: `${getCallBackName}Ios`,
1999
1999
  }),
2000
2000
  });
2001
2001
  }
2002
2002
  }),
2003
2003
  ]);
2004
2004
  }
2005
2005
  }
2006
2006
 
2007
2007
  createJdAndroidRquestEventForTouchStart() {
2008
2008
  if (isJdAndAndroidDevice && window?.JdAndroid) {
2009
2009
  const rootEleNode = document.querySelector('body');
2010
2010
  if (rootEleNode) {
2011
2011
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
2012
2012
  }
2013
2013
  }
2014
2014
  }
2015
2015
  jdAndroidAddEventListenerTouchStart(e) {
2016
2016
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
2017
2017
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
2018
2018
  const hasCustomEle = e
2019
2019
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
2020
2020
  : false;
2021
2021
  if (!hasCustomEle) {
2022
2022
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
2023
2023
  console.log(
2024
2024
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
2025
2025
  );
2026
2026
  }
2027
2027
  }
2028
2028
  }
2029
2029
  removeJdAndroidRquestEventForTouchStart() {
2030
2030
  if (isJdAndAndroidDevice && window.JdAndroid) {
2031
2031
  const rootEleNode = document.querySelector('body');
2032
2032
  if (rootEleNode) {
2033
2033
  rootEleNode.removeEventListener(
2034
2034
  'touchstart',
2035
2035
  this.jdAndroidAddEventListenerTouchStart,
2036
2036
  false,
2037
2037
  );
2038
2038
  }
2039
2039
  }
2040
2040
  }
2041
2041
 
2042
2042
  getNetWorkType() {
2043
2043
  if (isJdApp) {
2044
2044
  this.jmfeReayPromise().then(() => {
2045
2045
  window.jmfe
2046
2046
  .getNetworkStatus()
2047
2047
  .then(({ status, data }) => {
2048
2048
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
2049
2049
  if (status === '0') {
2050
2050
  this.info.sysInfo['netWorkType'] = data;
2051
2051
  } else {
2052
2052
  this._taroGetNetworkType();
2053
2053
  }
2054
2054
  })
2055
2055
  .catch((err) => {
2056
2056
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
2057
2057
  this._taroGetNetworkType();
2058
2058
  });
2059
2059
  });
2060
2060
  } else {
2061
2061
  this._taroGetNetworkType();
2062
2062
  }
2063
2063
  }
2064
2064
  _taroGetNetworkType() {
2065
2065
  Taro.getNetworkType().then((getRes) => {
2066
2066
  if (getRes && getRes.networkType) {
2067
2067
  this.info.sysInfo['netWorkType'] = getRes.networkType;
2068
2068
  console.log(
2069
2069
  '在app内通过taro对象获取网络状态完成,当前网络状态',
2070
2070
  this.info.sysInfo['netWorkType'],
2071
2071
  );
2072
2072
  }
2073
2073
  });
2074
2074
  }
2075
2075
 
2076
2076
  getCacheAddressRouter() {
2077
2077
  if (window.jmfe && isJdApp) {
2078
2078
  if (!isJdAndHarmonyDevice) {
2079
2079
  return Promise.race([
2080
2080
  window.jmfe.callRouter({
2081
2081
  jdRouter: '1',
2082
2082
  routerURL: isAndroidDevice
2083
2083
  ? 'router://JDAddressModule/getCacheAddress'
2084
2084
  : 'router://JDBAddressCacheManagerModule/getCacheAddress',
2085
2085
  routerParam: { sceneId: 'basicShoppingProcess' },
2086
2086
  }),
2087
2087
  this.taskTimeoutPromise(() => {
2088
2088
  return {
2089
2089
  status: '-1000',
2090
2090
  msg: '原生router协议获取地址信息超时',
2091
2091
  };
2092
2092
  }, 3000),
2093
2093
  ]);
2094
2094
  } else {
2095
2095
  return Promise.resolve({
2096
2096
  status: '-1001',
2097
2097
  msg: '鸿蒙系统调用jmfe异常,获取失败',
2098
2098
  });
2099
2099
  }
2100
2100
  } else {
2101
2101
  return Promise.resolve({
2102
2102
  status: '-1002',
2103
2103
  msg: 'jmfe不存在,获取失败',
2104
2104
  });
2105
2105
  }
2106
2106
  }
2107
2107
 
2108
2108
  getAddressCachePromise() {
2109
2109
  return new Promise((resolve) => {
2110
2110
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
2111
2111
  resolve({
2112
2112
  lat: this.info.sysInfo.lat,
2113
2113
  lng: this.info.sysInfo.lng,
2114
2114
  area: this?.info?.sysInfo?.area,
2115
2115
  });
2116
2116
  } else {
2117
2117
  this.jmfeReayPromise()
2118
2118
  .then(() => {
2119
2119
  this.getCacheAddressRouter()
2120
2120
  .then((res) => {
2121
2121
  const { status, data } = res;
2122
2122
  console.log('原生端获取经纬度原始数据结果', status, data);
2123
2123
  if (status === '0' && data) {
2124
2124
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
2125
2125
  data || {};
2126
2126
  let area = '';
2127
2127
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
2128
2128
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
2129
2129
  if (provinceId) {
2130
2130
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
2131
2131
  this.info.pageInfo['address'] = area;
2132
2132
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
2133
2133
  Taro.eventCenter.trigger(
2134
2134
  TaroEventType.USER_AREA_UPDATE,
2135
2135
  this.info.pageInfo.address,
2136
2136
  );
2137
2137
  }
2138
2138
  resolve({
2139
2139
  lat: this.info.sysInfo['lat'],
2140
2140
  lng: this.info.sysInfo['lng'],
2141
2141
  area: area,
2142
2142
  });
2143
2143
  } else {
2144
2144
  if (typeof res === 'object') {
2145
2145
  sgmCustomReport({
2146
2146
  type: 3,
2147
2147
  code: 'jdapp_getCacheAddress_info',
2148
2148
  msg: {
2149
2149
  title: '松果app内通过router协议获取用户地址及经纬度信息异常',
2150
2150
  jdAppVersion: jdAppVersionStr,
2151
2151
  ...res,
2152
2152
  },
2153
2153
  });
2154
2154
  draBusinessCustomReport({
2155
2155
  type: 'jdapp_getCacheAddress_info_err',
2156
2156
  errMsg: '松果app内通过router协议获取用户地址及经纬度信息异常',
2157
2157
  originReqDataStr: JSON.stringify({
2158
2158
  isJdApp,
2159
2159
  jdAppVersion: jdAppVersionStr,
2160
2160
  ...res,
2161
2161
  }),
2162
2162
  });
2163
2163
  }
2164
2164
  resolve({ lat: '', lng: '', area: '' });
2165
2165
  }
2166
2166
  })
2167
2167
  .catch((e) => {
2168
2168
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
2169
2169
  draBusinessCustomReport({
2170
2170
  type: 'jdapp_getCacheAddress_info_catch_err',
2171
2171
  errMsg: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
2172
2172
  originReqDataStr: JSON.stringify({
2173
2173
  isJdApp,
2174
2174
  jdAppVersion: jdAppVersionStr,
2175
2175
  }),
2176
2176
  });
2177
2177
  resolve({ lat: '', lng: '', area: '' });
2178
2178
  });
2179
2179
  })
2180
2180
  .catch((e) => {
2181
2181
  resolve({ lat: '', lng: '', area: '' });
2182
2182
  console.log('判断jmfe不存在,获取经纬度信息异常e', e);
2183
2183
  });
2184
2184
  }
2185
2185
  });
2186
2186
  }
2187
2187
 
2188
2188
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
2189
2189
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
2190
2190
  if (!isJdApp) {
2191
2191
  return;
2192
2192
  }
2193
2193
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
2194
2194
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
2195
2195
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
2196
2196
  'hybridHttpSwitch',
2197
2197
  isBeforePageReady,
2198
2198
  );
2199
2199
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
2200
2200
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
2201
2201
  'isFollowAppVideoPlayStatus',
2202
2202
  isBeforePageReady,
2203
2203
  );
2204
2204
  console.log(
2205
2205
  'isBeforePageReady:',
2206
2206
  isBeforePageReady,
2207
2207
  'isFollowAppVideoPlayStatus:',
2208
2208
  isFollowAppVideoPlayStatus,
2209
2209
  );
2210
2210
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
2211
2211
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
2212
2212
  }
2213
2213
  }
2214
2214
 
2215
2215
  async getWifiVideoAutoPlayAsync() {
2216
2216
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
2217
2217
  if (!isJdApp) {
2218
2218
  return;
2219
2219
  }
2220
2220
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
2221
2221
  return 0;
2222
2222
  });
2223
2223
  if (Number(videoPlayStatus) === 1) {
2224
2224
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
2225
2225
  }
2226
2226
  }
2227
2227
 
2228
2228
  async getMPaasConfigAsync() {
2229
2229
  this.info.sysInfo.dynamicConfig = {};
2230
2230
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
2231
2231
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
2232
2232
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
2233
2233
  return this.updateMPaasConfigAsync(true);
2234
2234
  }
2235
2235
 
2236
2236
  getDynamicConfig(key: string) {
2237
2237
  return this.info.sysInfo?.dynamicConfig?.[key];
2238
2238
  }
2239
2239
  async updateMPaasConfig() {
2240
2240
  console.log('updateMPaasConfig');
2241
2241
  if (
2242
2242
  isIosDevice &&
2243
2243
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
2244
2244
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
2245
2245
  ) {
2246
2246
  try {
2247
2247
  await this.updateMPaasConfigAsync(false);
2248
2248
  } catch (e) {
2249
2249
  console.log('updateMPaasConfigAsync:', e);
2250
2250
  }
2251
2251
  }
2252
2252
  }
2253
2253
 
2254
2254
  toLogin(options) {
2255
2255
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
2256
2256
  ? this.toWxAppLogin(options)
2257
2257
  : this.toWebLogin(options);
2258
2258
  }
2259
2259
 
2260
2260
  doLogin(options) {
2261
2261
  return this.toLogin(options);
2262
2262
  }
2263
2263
 
2264
2264
  doLoginForJdPin(options = {}) {
2265
2265
  return this.doLogin({
2266
2266
  loginColor: {
2267
2267
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2268
2268
  dpin: 0,
2269
2269
  },
2270
2270
  ...options,
2271
2271
  });
2272
2272
  }
2273
2273
 
2274
2274
  toWebLogin(options) {
2275
2275
  let params: {
2276
2276
  returnurl: string;
2277
2277
  } = {
2278
2278
  returnurl: '',
2279
2279
  };
2280
2280
  const loginUrl = isPc
2281
2281
  ? `//passport.jd.com/new/login.aspx`
2282
2282
  : `${domain.mobileLogin}/user/login.action`;
2283
2283
  const defaultParams = {
2284
2284
  appid: '100',
2285
2285
  returnurl: window.location.href,
2286
2286
  };
2287
2287
  if (isString(options)) {
2288
2288
  params = Object.assign({}, defaultParams, {
2289
2289
  returnurl: options,
2290
2290
  });
2291
2291
  } else if (isObject(options)) {
2292
2292
  const { loginColor, ...otherOptions } = options;
2293
2293
  params = Object.assign({}, defaultParams, otherOptions);
2294
2294
  } else {
2295
2295
  params = defaultParams;
2296
2296
  }
2297
2297
  params.returnurl = encodeURIComponent(params.returnurl);
2298
2298
  let getFullUrl = loginUrl + '?' + serialize(params);
2299
2299
  if (isPc) {
2300
2300
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
2301
2301
  }
2302
2302
  return Promise.resolve({
2303
2303
  h5ToUrl: true,
2304
2304
  url: getFullUrl,
2305
2305
  }).then(() => {
2306
2306
  window.location.href = getFullUrl;
2307
2307
  });
2308
2308
  }
2309
2309
 
2310
2310
  toWxAppLogin(options = {}) {
2311
2311
  console.log('微信京购小程序中h5登录跳转', options);
2312
2312
  return Promise.resolve(true).then(() => {
2313
2313
  const { loginColor } = Object.assign(
2314
2314
  {},
2315
2315
  {
2316
2316
  loginColor: {
2317
2317
  biz: WXAPP_BIZ_KEY,
2318
2318
  dpin: 1,
2319
2319
  },
2320
2320
  },
2321
2321
  options,
2322
2322
  );
2323
2323
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
2324
2324
  loginColor.biz
2325
2325
  }&url=${encodeURIComponent(window.location.href)}`;
2326
2326
  });
2327
2327
  }
2328
2328
 
2329
2329
  getLoginCookie() {
2330
2330
  return Promise.resolve({
2331
2331
  pin: cookie.get('pin') || '',
2332
2332
  });
2333
2333
  }
2334
2334
 
2335
2335
  clearLoginCookie() {
2336
2336
  cookie.remove('pin');
2337
2337
  }
2338
2338
 
2339
2339
  checkStatusAndLogin(options = {}) {
2340
2340
  if (!this.checkStatusAndLoginPromise) {
2341
2341
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
2342
2342
  try {
2343
2343
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2344
2344
  if (getLoginState) {
2345
2345
  resolve(true);
2346
2346
  } else {
2347
2347
  this.toLogin(options);
2348
2348
  reject(false);
2349
2349
  }
2350
2350
  } catch (e) {
2351
2351
  this.toLogin(options);
2352
2352
  reject(false);
2353
2353
  }
2354
2354
  });
2355
2355
  return this.checkStatusAndLoginPromise;
2356
2356
  } else {
2357
2357
  return this.checkStatusAndLoginPromise
2358
2358
  .then(() => {
2359
2359
  return Promise.resolve(true);
2360
2360
  })
2361
2361
  .catch(() => {
2362
2362
  this.toLogin(options);
2363
2363
  return Promise.reject(true);
2364
2364
  });
2365
2365
  }
2366
2366
  }
2367
2367
 
2368
2368
  checkJdStatusAndLogin(
2369
2369
  options = {
2370
2370
  loginColor: {
2371
2371
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2372
2372
  dpin: 0,
2373
2373
  },
2374
2374
  },
2375
2375
  ) {
2376
2376
  return this.checkStatusAndLogin(options);
2377
2377
  }
2378
2378
 
2379
2379
  doCheckLoginStateAndForApiCheck(options) {
2380
2380
  if (this.info.loginState) {
2381
2381
  return Promise.resolve(true);
2382
2382
  } else {
2383
2383
  return new Promise((resolve, reject) => {
2384
2384
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
2385
2385
  const getWqAuthToken = cookie.get('wq_auth_token');
2386
2386
  const getWqSkey = cookie.get('wq_skey');
2387
2387
  const getWqUin = cookie.get('wq_uin');
2388
2388
  const isLoginState =
2389
2389
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
2390
2390
  if (isLoginState) {
2391
2391
  this.info.loginState = true;
2392
2392
  resolve(true);
2393
2393
  } else {
2394
2394
  reject(false);
2395
2395
  }
2396
2396
  } else {
2397
2397
  Taro.request({
2398
2398
  url: api.isLogin,
2399
2399
  jsonp: true,
2400
2400
  timeout: 3000,
2401
2401
  success: (res) => {
2402
2402
  const { statusCode, data } = res;
2403
2403
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
2404
2404
  this.info.loginState = true;
2405
2405
  resolve(true);
2406
2406
  } else {
2407
2407
  reject(false);
2408
2408
  }
2409
2409
  },
2410
2410
  fail: (err) => {
2411
2411
  console.log('登录检查异常', err);
2412
2412
  reject(false);
2413
2413
  },
2414
2414
  });
2415
2415
  }
2416
2416
  });
2417
2417
  }
2418
2418
  }
2419
2419
 
2420
2420
  checkLoginStatus(options) {
2421
2421
  return new Promise(async (resolve, reject) => {
2422
2422
  try {
2423
2423
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2424
2424
  if (getLoginState) {
2425
2425
  const { pin } = await this.getLoginCookie();
2426
2426
  this.info.userInfo = {
2427
2427
  pin,
2428
2428
  encodePin: encodeURIComponent(pin),
2429
2429
  ptkey: '',
2430
2430
  };
2431
2431
  resolve(true);
2432
2432
  } else {
2433
2433
  reject(false);
2434
2434
  }
2435
2435
  } catch (e) {
2436
2436
  reject(false);
2437
2437
  }
2438
2438
  });
2439
2439
  }
2440
2440
 
2441
2441
  updatePageAndLogInfo(updateQuery = {}) {
2442
2442
  const createUpdateQueryInfo: {
2443
2443
  query: {
2444
2444
  shopId?: string | number;
2445
2445
  venderId?: string | number;
2446
2446
  };
2447
2447
  updateShopInfoState: boolean;
2448
2448
  } = Object.assign(
2449
2449
  {},
2450
2450
  {
2451
2451
  query: {},
2452
2452
  updateShopInfoState: false,
2453
2453
  },
2454
2454
  updateQuery,
2455
2455
  );
2456
2456
  console.log(
2457
2457
  '获取当前下发的店铺查询参数',
2458
2458
  updateQuery,
2459
2459
  '获取之前保存的shopInfo店铺查询参数',
2460
2460
  this.info?.shopInfo,
2461
2461
  );
2462
2462
  const { query, updateShopInfoState } = createUpdateQueryInfo;
2463
2463
  const { shopId, venderId, un_area } = query;
2464
2464
  if (updateShopInfoState) {
2465
2465
  this.info.queryInfo = {
2466
2466
  ...this.info.queryInfo,
2467
2467
  ...query,
2468
2468
  };
2469
2469
  if (shopId && venderId) {
2470
2470
  this.info.shopInfo = {
2471
2471
  shopId: `${shopId}`,
2472
2472
  venderId: `${venderId}`,
2473
2473
  };
2474
2474
  }
2475
2475
  } else {
2476
2476
  this.info.queryInfo = {
2477
2477
  ...query,
2478
2478
  };
2479
2479
  if (
2480
2480
  this.info.shopInfo?.shopId &&
2481
2481
  this.info.shopInfo?.venderId &&
2482
2482
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
2483
2483
  ) {
2484
2484
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
2485
2485
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
2486
2486
  console.log(
2487
2487
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
2488
2488
  this.info.queryInfo,
2489
2489
  );
2490
2490
  }
2491
2491
  }
2492
2492
  this.info.queryInfo['shopId'] &&
2493
2493
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
2494
2494
  this.info.queryInfo['venderId'] &&
2495
2495
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
2496
2496
  console.log(
2497
2497
  'h5==获取店铺下发查询参数\n',
2498
2498
  query,
2499
2499
  '\n获取店铺最后查询参数\n',
2500
2500
  this.info.queryInfo,
2501
2501
  '\n是否为更新店铺状态\n',
2502
2502
  updateShopInfoState,
2503
2503
  );
2504
2504
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
2505
2505
  if (changeArea) {
2506
2506
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
2507
2507
  this.info.pageInfo.address = getBottomAreaStr;
2508
2508
  this.info.pageInfo.un_area = getBottomAreaStr;
2509
2509
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
2510
2510
  }
2511
2511
  }
2512
2512
 
2513
2513
  dealLoadSdkList() {
2514
2514
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
2515
2515
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
2516
2516
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
2517
2517
  let mergeLoadJsList = globalLoadJsList;
2518
2518
  try {
2519
2519
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
2520
2520
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
2521
2521
  getFindIndex !== -1
2522
2522
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
2523
2523
  : accArr.push(current);
2524
2524
  return accArr;
2525
2525
  }, []);
2526
2526
  } catch (e) {
2527
2527
  console.log('LoadJsList合并错误', e);
2528
2528
  }
2529
2529
  console.log(
2530
2530
  'globalLoadJsList',
2531
2531
  globalLoadJsList,
2532
2532
  'businessLoadJsList',
2533
2533
  businessLoadJsList,
2534
2534
  '两个加载jsList集合合并完成',
2535
2535
  mergeLoadJsList,
2536
2536
  );
2537
2537
  this.loadJsSdkList = mergeLoadJsList;
2538
2538
  return this.loadJsSdkList;
2539
2539
  }
2540
2540
 
2541
2541
  renderNextTickLoadSdk() {
2542
2542
  Taro.nextTick(() => {
2543
2543
  console.log(
2544
2544
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
2545
2545
  );
2546
2546
  setTimeout(() => {
2547
2547
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
2548
2548
  }, 1000);
2549
2549
  });
2550
2550
  }
2551
2551
 
2552
2552
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
2553
2553
  const getLoadJsList =
2554
2554
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
2555
2555
  const getLoadFilterList = getLoadJsList.filter((item) => {
2556
2556
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
2557
2557
  let getLoastLoadEventState = true;
2558
2558
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
2559
2559
  getLoastLoadEventState = isJdApp;
2560
2560
  }
2561
2561
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
2562
2562
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
2563
2563
  }
2564
2564
  const getInitTriggerType =
2565
2565
  isJdApp && item?.initJdAppTriggerType
2566
2566
  ? item?.initTriggerType
2567
2567
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
2568
2568
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
2569
2569
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
2570
2570
  });
2571
2571
  console.log(
2572
2572
  '获取当前触发方式',
2573
2573
  triggerType,
2574
2574
  '获取当前最后加载的js集合',
2575
2575
  getLoadFilterList,
2576
2576
  '过滤前的加载集合',
2577
2577
  getLoadJsList,
2578
2578
  );
2579
2579
  getLoadFilterList.length > 0 &&
2580
2580
  getLoadFilterList.forEach((item) => {
2581
2581
  const isLoadState = /sgm/.test(item?.fileName)
2582
2582
  ? window?.shopGlobalSwitch?.openSgm === 'true'
2583
2583
  : true;
2584
2584
  isLoadState &&
2585
2585
  this.loadItemSdkPromise(item)
2586
2586
  .then((res) => {
2587
2587
  console.info('当前js地址' + item?.src, '加载状态', res);
2588
2588
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
2589
2589
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
2590
2590
  window.dra.run('init', { aid: res?.aid });
2591
2591
  window.dra.run('start');
2592
2592
  }
2593
2593
  })
2594
2594
  .catch((err) => {
2595
2595
  console.info('当前js地址加载异常', item?.src);
2596
2596
  window?.fetchErrorData &&
2597
2597
  window.fetchErrorData({
2598
2598
  title: '公共js加载异常',
2599
2599
  type: 'jsLoad',
2600
2600
  data: err,
2601
2601
  });
2602
2602
  });
2603
2603
  });
2604
2604
  }
2605
2605
  loadScriptEle(jsInfo, resolve, reject) {
2606
2606
  const getFileName = jsInfo?.fileName;
2607
2607
  if (getFileName) {
2608
2608
  const getEleId = `J_loadJs_${getFileName}`;
2609
2609
  const getEle = document.getElementById(getEleId);
2610
2610
  if (!getEle) {
2611
2611
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2612
2612
  const _sgmEle = document.createElement('script');
2613
2613
  _sgmEle.id = getEleId;
2614
2614
  _sgmEle.onload = function () {
2615
2615
  resolve({
2616
2616
  ...jsInfo,
2617
2617
  jsTip: 'js加载成功',
2618
2618
  });
2619
2619
  };
2620
2620
  _sgmEle.onerror = function () {
2621
2621
  reject({
2622
2622
  ...jsInfo,
2623
2623
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2624
2624
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
2625
2625
  });
2626
2626
  };
2627
2627
  const dataAttrList = ['timeout', 'fileName', 'env'];
2628
2628
  const getJsInfoKeyList = Object.keys(jsInfo);
2629
2629
  getJsInfoKeyList.forEach((key) => {
2630
2630
  if (key === 'async') {
2631
2631
  _sgmEle.async = jsInfo[key];
2632
2632
  } else if (key === 'crossOrigin') {
2633
2633
  _sgmEle.crossOrigin = jsInfo[key];
2634
2634
  } else if (key === 'src') {
2635
2635
  _sgmEle.src = `${jsInfo[key]}`;
2636
2636
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
2637
2637
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
2638
2638
  } else {
2639
2639
  _sgmEle.setAttribute(key, jsInfo[key]);
2640
2640
  }
2641
2641
  });
2642
2642
  document.head.appendChild(_sgmEle);
2643
2643
  } else {
2644
2644
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
2645
2645
  resolve({
2646
2646
  ...jsInfo,
2647
2647
  jsTip: 'js本身已存在页面中',
2648
2648
  });
2649
2649
  }
2650
2650
  } else {
2651
2651
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
2652
2652
  }
2653
2653
  }
2654
2654
 
2655
2655
  loadItemSdkPromise(jsInfo = {}) {
2656
2656
  if (jsInfo?.src) {
2657
2657
  const getInitLoadType =
2658
2658
  isJdApp && jsInfo?.initJdAppLoadType
2659
2659
  ? jsInfo?.initJdAppLoadType
2660
2660
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
2661
2661
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
2662
2662
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
2663
2663
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
2664
2664
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
2665
2665
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2666
2666
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2667
2667
  try {
2668
2668
  const jsXhrRequest = new XMLHttpRequest();
2669
2669
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
2670
2670
  const jsUrl = `${jsInfo?.src}`;
2671
2671
  jsXhrRequest.open('GET', jsUrl, true);
2672
2672
  jsXhrRequest.onreadystatechange = () => {
2673
2673
  if (jsXhrRequest.readyState === 4) {
2674
2674
  const getReqStatus = jsXhrRequest.status;
2675
2675
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
2676
2676
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
2677
2677
  if (getInsetHeadState) {
2678
2678
  this.loadScriptEle(jsInfo, resolve, reject);
2679
2679
  } else {
2680
2680
  resolve({
2681
2681
  ...jsInfo,
2682
2682
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
2683
2683
  });
2684
2684
  }
2685
2685
  getReqStatus !== 200 &&
2686
2686
  sgmCustomReport({
2687
2687
  type: 3,
2688
2688
  code: 'js_load_special_code',
2689
2689
  msg: {
2690
2690
  msg: '当前js加载成功,状态非200,特殊上报观察',
2691
2691
  jsReqState: getReqStatus,
2692
2692
  env: getSgmCustomCode('js_load_special_code'),
2693
2693
  data: jsInfo,
2694
2694
  },
2695
2695
  });
2696
2696
  } else {
2697
2697
  const getRes = {
2698
2698
  ...jsInfo,
2699
2699
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2700
2700
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
2701
2701
  jsReqState: getReqStatus,
2702
2702
  };
2703
2703
  console.log('当前js请求状态异常,具体信息见', getRes);
2704
2704
  reject(getRes);
2705
2705
  }
2706
2706
  }
2707
2707
  };
2708
2708
  jsXhrRequest.onerror = () => {
2709
2709
  const getRes = {
2710
2710
  ...jsInfo,
2711
2711
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2712
2712
  jsReqError: '请求错误',
2713
2713
  };
2714
2714
  console.log('当前js请求错误', getRes);
2715
2715
  jsXhrRequest.abort();
2716
2716
  reject(getRes);
2717
2717
  };
2718
2718
  jsXhrRequest.ontimeout = () => {
2719
2719
  const getRes = {
2720
2720
  ...jsInfo,
2721
2721
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2722
2722
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
2723
2723
  jsReqState: jsXhrRequest.status,
2724
2724
  };
2725
2725
  console.log('当前js请求超时异常', getRes);
2726
2726
  jsXhrRequest.abort();
2727
2727
  reject(getRes);
2728
2728
  };
2729
2729
  jsXhrRequest.send();
2730
2730
  } catch (e) {
2731
2731
  console.log('执行js请求异常', e);
2732
2732
  reject({
2733
2733
  ...jsInfo,
2734
2734
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2735
2735
  jsReqError: '未知异常',
2736
2736
  error: e,
2737
2737
  });
2738
2738
  }
2739
2739
  });
2740
2740
  } else {
2741
2741
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2742
2742
  return this.loadScriptEle(jsInfo, resolve, reject);
2743
2743
  });
2744
2744
  }
2745
2745
  }
2746
2746
  return this.loadJsSdkListCachePromise[getFileKeyName];
2747
2747
  } else {
2748
2748
  return Promise.resolve({
2749
2749
  ...jsInfo,
2750
2750
  jsTip: 'js加载方式设置为不加载,当前不做处理',
2751
2751
  });
2752
2752
  }
2753
2753
  } else {
2754
2754
  return Promise.reject(jsInfo);
2755
2755
  }
2756
2756
  }