@conecli/cone-render 0.10.1-shop3.73 → 0.10.1-shop3.75

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