@conecli/cone-render 0.8.20-shop.194 → 0.8.20-shop.196

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