@conecli/cone-render 0.10.1-shop3.21 → 0.10.1-shop3.22

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