@conecli/cone-render 0.10.1-shop3.68 → 0.10.1-shop3.69

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