@conecli/cone-render 0.10.1-shop3.23 → 0.10.1-shop3.25

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