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

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
  sgmCustomReport,
2049
2049
  isInJdAppH5DebugMode
2050
2050
  callRouterAndroid,
2051
2051
  callRouterIOS,
2052
2052
  getMPaasConfigByBussinessKey,
2053
2053
  dealNativePixelToCssPixel,
2054
2054
  draBusinessCustomReport,
2055
2055
  isAndroidDevice,
2056
2056
  isH5AndJingGouMini,
2057
2057
  isIosDevice,
2058
2058
  isJdAndAndroidDevice,
2059
2059
  isObject,
2060
2060
  isPc,
2061
2061
  isString,
2062
2062
  jdAppVersion,
2063
2063
  jdAppVersionStr,
2064
2064
  serialize,
2065
2065
  languageNowType,
2066
2066
  urlCookie,
2067
2067
  jdAppVersionCompare
2068
2068
  abTestLabels: {},
2069
2069
  nonSellableSkuids: {},
2070
2070
  loginState: false,
2071
2071
  cookiesStr: '',
2072
2072
  userInfo: userPinKey,
2073
2073
  isImmersive: false,
2074
2074
  isJingGouMiniViewState: false,
2075
2075
  isJingxiMiniViewState: false,
2076
2076
  pageInfo: {
2077
2077
  wxBusinessType: WX_BUSINESS_TYPE.NO,
2078
2078
  address: '',
2079
2079
  addressCommaStr: '',
2080
2080
  un_area: '',
2081
2081
  userLbsAddress: '',
2082
2082
  vapptype: '1',
2083
2083
  pageType: 'home',
2084
2084
  isExposureState: false,
2085
2085
  moduleId: '',
2086
2086
  entrance: '',
2087
2087
  dataType: BUSINESS_TYPE.ONLINE,
2088
2088
  floorExposureInfo: {},
2089
2089
  floorVideInfo: {},
2090
2090
  productVideInfo: {},
2091
2091
  tabsLoadAllDataInfo: {
2092
2092
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
2093
2093
  },
2094
2094
  updateShopInfosAllState: false,
2095
2095
  isVipShop: false,
2096
2096
  isJdShowNativeImmersivePlayer: false,
2097
2097
  ...shopConfig,
2098
2098
  pageScrollTop: 0,
2099
2099
  pageIdxHeightInfo: {
2100
2100
  list: [],
2101
2101
  },
2102
2102
  shopNavBarHeight: 0,
2103
2103
  },
2104
2104
  defaultQueryLogInfo: {
2105
2105
  sourceType: 'JDshop',
2106
2106
  sourceValue: '',
2107
2107
  moduleId: 'none',
2108
2108
  entrance: 'none',
2109
2109
  },
2110
2110
  sysInfo: {
2111
2111
  windowWidth: isPc ? 375 : 0,
2112
2112
  containerWidth: isPc ? 375 : 0,
2113
2113
  windowHeight: 0,
2114
2114
  netWorkType: '4g',
2115
2115
  jdBottomBarHeight: 0,
2116
2116
  jdNativeHeaderHeight: 0,
2117
2117
  isJdTabletDevice: false,
2118
2118
  isJdTabletLandscape: false,
2119
2119
  },
2120
2120
  queryInfo: {},
2121
2121
  shopInfo: {},
2122
2122
  openAppData: {},
2123
2123
  public info: CommonInterFace.BaseConfigInfo;
2124
2124
  public config: {
2125
2125
  [key: string]: any;
2126
2126
  };
2127
2127
  public lazyContainer: CommonInterFace.lazyContainer;
2128
2128
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
2129
2129
  public rootEleNode: HTMLElement | null;
2130
2130
  public checkStatusAndLoginPromise: object | null;
2131
2131
  private jmfeRegisterStatePromise: Promise<any> | null;
2132
2132
  private jdScreenSizeInfoPromise: Promise<any> | null;
2133
2133
  private rootEleWidthRegisterPromise: Promise<any> | null;
2134
2134
  private jmfeRegisterState: boolean;
2135
2135
  public loadJsSdkList: Array<any>;
2136
2136
  public loadJsSdkListCachePromise: any;
2137
2137
  public rootEleInitWidth: number;
2138
2138
  public lbsAddressCachePromise: Promise<any> | null;
2139
2139
  public languageCacheProimse: Promise<any> | null;
2140
2140
  public languageJsonData: any | null;
2141
2141
  public businessWorkerReady: boolean;
2142
2142
  public businessWorkerReadyPromise: Promise<any> | null;
2143
2143
  public workerPreRequestData = new Map<string, any>();
2144
2144
  constructor(opt) {
2145
2145
  this.info = this._getConfig(opt);
2146
2146
  this.config = {};
2147
2147
  this.loadJsSdkList = [];
2148
2148
  this.loadJsSdkListCachePromise = {};
2149
2149
  this.lazyContainer = {
2150
2150
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
2151
2151
  appLazyContainerList: [],
2152
2152
  appLazyFinishContainerList: [],
2153
2153
  },
2154
2154
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
2155
2155
  appLazyContainerList: [],
2156
2156
  appLazyFinishContainerList: [],
2157
2157
  },
2158
2158
  };
2159
2159
  this.renderedIsvComponents = {};
2160
2160
  this.rootEleNode = document.querySelector('body');
2161
2161
  this.checkStatusAndLoginPromise = null;
2162
2162
  this.jmfeRegisterStatePromise = null;
2163
2163
  this.jdScreenSizeInfoPromise = null;
2164
2164
  this.rootEleWidthRegisterPromise = null;
2165
2165
  this.lbsAddressCachePromise = null;
2166
2166
  this.languageCacheProimse = null;
2167
2167
  this.businessWorkerReady = false;
2168
2168
  this.businessWorkerReadyPromise = null;
2169
2169
  this.workerPreRequestData = new Map<string, any>();
2170
2170
  this.languageJsonData = langeJsonDataForCn;
2171
2171
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
2172
2172
  this.loadOtherSdk();
2173
2173
  if (isJdApp) {
2174
2174
  this.jmfeReayPromise().then(() => {
2175
2175
  this.jdWorkerReadyPromise()
2176
2176
  })
2177
2177
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
2178
2178
  if (isJdAndHarmonyDevice) {
2179
2179
  this.renderNextTickLoadSdk(2000);
2180
2180
  }
2181
2181
  }
2182
2182
  }
2183
2183
  _getConfig(opt) {
2184
2184
  return Object.assign({}, DefaultConfig, opt);
2185
2185
  }
2186
2186
 
2187
2187
  jmfeReayPromise(): Promise<any> {
2188
2188
  if (isJdApp) {
2189
2189
  if (this.jmfeRegisterState) {
2190
2190
  return Promise.resolve(true);
2191
2191
  } else {
2192
2192
  !this.jmfeRegisterStatePromise &&
2193
2193
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
2194
2194
  ready('jmfe', 3000)
2195
2195
  .then(() => {
2196
2196
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
2197
2197
  this.jmfeRegisterState = true;
2198
2198
  resolve(true);
2199
2199
  console.log(
2200
2200
  '松果app内初始化注册jmfe认证完成',
2201
2201
  window?.jmfe,
2202
2202
  '当前版本',
2203
2203
  window?.jmfe?.VERSION,
2204
2204
  );
2205
2205
  })
2206
2206
  .catch((err) => {
2207
2207
  console.error('jmfe ready error', err);
2208
2208
  reject(false);
2209
2209
  });
2210
2210
  }));
2211
2211
  return this.jmfeRegisterStatePromise;
2212
2212
  }
2213
2213
  } else {
2214
2214
  return Promise.reject(false);
2215
2215
  }
2216
2216
  }
2217
2217
 
2218
2218
  jdWorkerReadyPromise(): Promise<any> {
2219
2219
  if (isJdApp) {
2220
2220
  if (this.businessWorkerReady) {
2221
2221
  return Promise.resolve(true);
2222
2222
  } else {
2223
2223
  const getOpenJdWorkerState = window?.PAGE_DATA?.businessData?.businessWorkerVersion && versionCompare(jdAppVersionStr, window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10') >= 0;
2224
2224
  !this.businessWorkerReadyPromise && (this.businessWorkerReadyPromise = getOpenJdWorkerState ?
2225
2225
  new Promise((resolve) => {
2226
2226
  this.jmfeReayPromise().then(() => {
2227
2227
  window.jmfe
2228
2228
  .onMsgForWorker(
2229
2229
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
2230
2230
  (workerData) => {
2231
2231
  console.log(
2232
2232
  '收到业务jd worker消息结果:',
2233
2233
  workerData,
2234
2234
  );
2235
2235
  if (workerData && workerData?.workerType) {
2236
2236
  const getWorkerType = workerData?.workerType
2237
2237
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
2238
2238
  this.workerPreRequestData.set(workerData?.functionId, workerData);
2239
2239
  Taro.eventCenter.trigger(
2240
2240
  getWorkerType,
2241
2241
  workerData);
2242
2242
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
2243
2243
  Taro.eventCenter.trigger(
2244
2244
  getWorkerType,
2245
2245
  workerData);
2246
2246
  }
2247
2247
  }
2248
2248
  },
2249
2249
  )
2250
2250
  .then(() => {
2251
2251
  console.log('jd worker注册成功');
2252
2252
  this.businessWorkerReady = true;
2253
2253
  resolve(true);
2254
2254
  })
2255
2255
  .catch((error) => {
2256
2256
  console.log('jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑', error);
2257
2257
  draBusinessCustomReport({
2258
2258
  eventName:'business',
2259
2259
  errorName: 'jmfe_onMsgForWorker_error',
2260
2260
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
2261
2261
  extraData: JSON.stringify({
2262
2262
  businessWorkerVersion:window?.PAGE_DATA?.businessData?.businessWorkerVersion,
2263
2263
  error,
2264
2264
  }),
2265
2265
  });
2266
2266
  resolve(false);
2267
2267
  });
2268
2268
  }).catch((err) => {
2269
2269
  console.log('jmfe超时异常,worker注册失败', err);
2270
2270
  resolve(false);
2271
2271
  })
2272
2272
  }) : Promise.resolve(false))
2273
2273
  }
2274
2274
  return this.businessWorkerReadyPromise
2275
2275
  } else {
2276
2276
  return Promise.resolve(false);
2277
2277
  }
2278
2278
  }
2279
2279
 
2280
2280
  taskTimeoutPromise(callBack, timeout = 2000) {
2281
2281
  return new Promise((resolve) => {
2282
2282
  setTimeout(() => {
2283
2283
  const getCallBackRes = typeof callBack === 'function' && callBack();
2284
2284
  return resolve(getCallBackRes || false);
2285
2285
  }, isInJdAppH5DebugMode ? 0 : timeout);
2286
2286
  });
2287
2287
  }
2288
2288
  _getJdPadMinWidthForListen() {
2289
2289
  return (
2290
2290
  isJdApp &&
2291
2291
  Math.min(window.screen.width, window.screen.height) >
2292
2292
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
2293
2293
  );
2294
2294
  }
2295
2295
 
2296
2296
  getJdScreenSizeInfoPromise() {
2297
2297
  !this.jdScreenSizeInfoPromise &&
2298
2298
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
2299
2299
  const getThisTime = Date.now();
2300
2300
  this.jmfeReayPromise().then(() => {
2301
2301
  return Promise.race([
2302
2302
  window.jmfe.getScreenSize(),
2303
2303
  this.taskTimeoutPromise(() => {
2304
2304
  return {
2305
2305
  status: '-10',
2306
2306
  msg: '获取大屏信息2s超时',
2307
2307
  };
2308
2308
  }),
2309
2309
  ])
2310
2310
  .then((res) => {
2311
2311
  console.warn('===获取app大屏信息====', res);
2312
2312
  const { status, data } = res;
2313
2313
  if (status === '0' && data) {
2314
2314
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
2315
2315
  const getPageInfo = dealNativePixelToCssPixel({
2316
2316
  pageWidth,
2317
2317
  pageHeight,
2318
2318
  });
2319
2319
  this.info.sysInfo.jdScreenSizeType = sizeType;
2320
2320
  const getUseTime = Date.now() - getThisTime;
2321
2321
  console.warn(
2322
2322
  '===计算是否是app大屏信息,需满足宽度最新720===',
2323
2323
  getPageInfo,
2324
2324
  '原始数据',
2325
2325
  data,
2326
2326
  '是否是横屏isLandscape为1=',
2327
2327
  isLandscape,
2328
2328
  '用时',
2329
2329
  getUseTime,
2330
2330
  );
2331
2331
  if (getPageInfo?.pageWidth > 0) {
2332
2332
  this.rootEleInitWidth = getPageInfo?.pageWidth;
2333
2333
  draBusinessCustomReport({
2334
2334
  eventName: 'UIInteract',
2335
2335
  errorName: 'rootEle_width_getJdScreenSizeInfo',
2336
2336
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
2337
2337
  extraData: JSON.stringify({
2338
2338
  isJdApp,
2339
2339
  getPageInfo,
2340
2340
  originData: res,
2341
2341
  }),
2342
2342
  });
2343
2343
  resolve(getPageInfo);
2344
2344
  } else {
2345
2345
  resolve({
2346
2346
  pageWidth: 0,
2347
2347
  pageHeight: 0,
2348
2348
  msg: '转换异常',
2349
2349
  });
2350
2350
  }
2351
2351
  } else {
2352
2352
  resolve({
2353
2353
  pageWidth: 0,
2354
2354
  pageHeight: 0,
2355
2355
  msg: '获取大屏信息异常或者超时',
2356
2356
  });
2357
2357
  }
2358
2358
  })
2359
2359
  .catch((err) => {
2360
2360
  console.log('获取大屏信息异常', err);
2361
2361
  resolve({
2362
2362
  pageWidth: 0,
2363
2363
  pageHeight: 0,
2364
2364
  msg: '获取大屏信息异常',
2365
2365
  });
2366
2366
  });
2367
2367
  });
2368
2368
  }));
2369
2369
  return this.jdScreenSizeInfoPromise;
2370
2370
  }
2371
2371
 
2372
2372
  listenJdTabletScreenChange() {
2373
2373
  this.jmfeReayPromise().then(() => {
2374
2374
  try {
2375
2375
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
2376
2376
  window.jmfe.listenDeviceScreenChange((event) => {
2377
2377
  console.log(
2378
2378
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
2379
2379
  event,
2380
2380
  '通过前端判断是不是横屏',
2381
2381
  window.matchMedia('(orientation: landscape)')?.matches,
2382
2382
  );
2383
2383
  const { orientation } = event?.data;
2384
2384
  if (orientation) {
2385
2385
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
2386
2386
  Taro.eventCenter.trigger(
2387
2387
  TaroEventType.TABLE_SCREEN_CHANGE,
2388
2388
  this.info.sysInfo.isJdTabletLandscape,
2389
2389
  orientation,
2390
2390
  );
2391
2391
  }
2392
2392
  });
2393
2393
  } catch (error) {
2394
2394
  console.log('listenScreenChange的打印error:', error);
2395
2395
  }
2396
2396
  });
2397
2397
  }
2398
2398
 
2399
2399
  updateBusinessDomainAndApi(domain, api) {
2400
2400
  }
2401
2401
 
2402
2402
  formatNativeScreenPageData(action) {
2403
2403
  let getChangePageInfo: any = null;
2404
2404
  try {
2405
2405
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
2406
2406
  JSON.stringify({
2407
2407
  plugin: 'JDHybridScreenPlugin',
2408
2408
  action,
2409
2409
  sync: '1',
2410
2410
  }),
2411
2411
  );
2412
2412
  const getChangePageInfoData =
2413
2413
  typeof getNativeScreenPageInfoStr === 'string'
2414
2414
  ? JSON.parse(getNativeScreenPageInfoStr)
2415
2415
  : null;
2416
2416
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
2417
2417
  const { code, data } = getChangePageInfoData;
2418
2418
  getChangePageInfo = code && code === '0' ? data : null;
2419
2419
  }
2420
2420
  } catch (e) {
2421
2421
  console.log('JDHybridScreenPlugin转换异常', e);
2422
2422
  }
2423
2423
  return getChangePageInfo;
2424
2424
  }
2425
2425
 
2426
2426
  isAndroidFoldScreen() {
2427
2427
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
2428
2428
  }
2429
2429
 
2430
2430
  isHarmonyFoldScreenPromise(): Promise<{
2431
2431
  isFoldScreen: boolean,
2432
2432
  getFoldDisplayMode?: number,
2433
2433
  }> {
2434
2434
  return new Promise(resolve => {
2435
2435
  this.jmfeReayPromise().then(() => {
2436
2436
  if (window.jmfe?.callNative) {
2437
2437
  Promise.all([
2438
2438
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
2439
2439
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {})
2440
2440
  ]).then(res => {
2441
2441
  resolve({
2442
2442
  isFoldScreen: res?.[0]?.data === '1',
2443
2443
  getFoldDisplayMode: res?.[1]?.data,
2444
2444
  })
2445
2445
  }).catch(() => {
2446
2446
  resolve({
2447
2447
  isFoldScreen: false,
2448
2448
  getFoldDisplayMode: undefined,
2449
2449
  });
2450
2450
  });
2451
2451
  } else {
2452
2452
  resolve({
2453
2453
  isFoldScreen: false,
2454
2454
  getFoldDisplayMode: undefined,
2455
2455
  });
2456
2456
  }
2457
2457
  }).catch(() => {
2458
2458
  resolve({
2459
2459
  isFoldScreen: false,
2460
2460
  getFoldDisplayMode: undefined,
2461
2461
  });
2462
2462
  });
2463
2463
  })
2464
2464
  }
2465
2465
 
2466
2466
  getJdAndroidPageChangeScreenInfo() {
2467
2467
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
2468
2468
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
2469
2469
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
2470
2470
  pageWidth: getPageScreenInfo.pageWidth,
2471
2471
  pageHeight: getPageScreenInfo.pageHeight,
2472
2472
  });
2473
2473
  getPageScreenInfo.pageWidth = pageWidth;
2474
2474
  getPageScreenInfo.pageHeight = pageHeight;
2475
2475
  }
2476
2476
  return getPageScreenInfo;
2477
2477
  }
2478
2478
 
2479
2479
  getRootEleWindowWidthInfo() {
2480
2480
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
2481
2481
  const getWindowWidth = window.innerWidth;
2482
2482
  const getScreenWidth = window.screen.width;
2483
2483
  return {
2484
2484
  getRootEleWidth,
2485
2485
  getWindowWidth,
2486
2486
  getScreenWidth,
2487
2487
  };
2488
2488
  }
2489
2489
 
2490
2490
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
2491
2491
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
2492
2492
  console.log(
2493
2493
  '当前获取根元素的宽度',
2494
2494
  getRootEleWidth,
2495
2495
  'getWindowWidth',
2496
2496
  getWindowWidth,
2497
2497
  'getScreenWidth',
2498
2498
  getScreenWidth,
2499
2499
  );
2500
2500
  const getLastWidth =
2501
2501
  getRootEleWidth > 0
2502
2502
  ? Math.round(getRootEleWidth)
2503
2503
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
2504
2504
  console.warn(
2505
2505
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2506
2506
  );
2507
2507
  timeout > 0 &&
2508
2508
  draBusinessCustomReport({
2509
2509
  eventName: 'UIInteract',
2510
2510
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
2511
2511
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2512
2512
  extraData: JSON.stringify({
2513
2513
  isJdApp,
2514
2514
  getRootEleWidth,
2515
2515
  getWindowWidth,
2516
2516
  getScreenWidth,
2517
2517
  ...reportParam,
2518
2518
  }),
2519
2519
  });
2520
2520
  return getLastWidth;
2521
2521
  }
2522
2522
 
2523
2523
  getPadWindowRootEleWidthPromise() {
2524
2524
  if (this.rootEleInitWidth > 0) {
2525
2525
  return Promise.resolve(this.rootEleInitWidth);
2526
2526
  } else {
2527
2527
  !this.rootEleWidthRegisterPromise &&
2528
2528
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
2529
2529
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
2530
2530
  if (getRootEleInitWidth > 0) {
2531
2531
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
2532
2532
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
2533
2533
  resolve(this.rootEleInitWidth);
2534
2534
  } else {
2535
2535
  const timerPromise = () => {
2536
2536
  return new Promise((resolve2) => {
2537
2537
  window.setTimeout(() => {
2538
2538
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
2539
2539
  this.getRootEleWindowWidthInfo();
2540
2540
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
2541
2541
  console.warn(
2542
2542
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
2543
2543
  );
2544
2544
  draBusinessCustomReport({
2545
2545
  eventName: 'UIInteract',
2546
2546
  errorName: 'rootEle_width_200_timeout_info',
2547
2547
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
2548
2548
  extraData: JSON.stringify({
2549
2549
  isJdApp,
2550
2550
  getRootEleWidth,
2551
2551
  getWindowWidth,
2552
2552
  getScreenWidth,
2553
2553
  }),
2554
2554
  });
2555
2555
  const getRes =
2556
2556
  getRootEleWidth > 0 && getWindowWidth > 0
2557
2557
  ? Math.min(getRootEleWidth, getWindowWidth)
2558
2558
  : Math.max(getRootEleWidth, getWindowWidth);
2559
2559
  resolve2({
2560
2560
  pageWidth: Math.round(getRes),
2561
2561
  });
2562
2562
  }
2563
2563
  }, 200);
2564
2564
  });
2565
2565
  };
2566
2566
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
2567
2567
  const { pageWidth } = res;
2568
2568
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
2569
2569
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
2570
2570
  });
2571
2571
  }
2572
2572
  }));
2573
2573
  return this.rootEleWidthRegisterPromise;
2574
2574
  }
2575
2575
  }
2576
2576
 
2577
2577
  async getSystemInfo(params) {
2578
2578
  const getParams = Object.assign({}, params || {});
2579
2579
  if (this.rootEleInitWidth > 0) {
2580
2580
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
2581
2581
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
2582
2582
  } else {
2583
2583
  if (this._getJdPadMinWidthForListen()) {
2584
2584
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
2585
2585
  getParams['replaceSystemWidth'] = true;
2586
2586
  }
2587
2587
  }
2588
2588
  isJdApp && this.createLanguagePromise();
2589
2589
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
2590
2590
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
2591
2591
  let _isfoldScreen = false;
2592
2592
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
2593
2593
  console.info(
2594
2594
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
2595
2595
  getStorageData,
2596
2596
  '通过缓存值第一次判断是否是折叠屏',
2597
2597
  getStorageData === 'true',
2598
2598
  );
2599
2599
  if (!getStorageData) {
2600
2600
  _isfoldScreen = this.isAndroidFoldScreen();
2601
2601
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
2602
2602
  } else {
2603
2603
  _isfoldScreen = getStorageData === 'true';
2604
2604
  }
2605
2605
  if (_isfoldScreen) {
2606
2606
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
2607
2607
  if (getJdAndroidPageInfo) {
2608
2608
  info = getSystemInfos(getJdAndroidPageInfo);
2609
2609
  console.warn(
2610
2610
  '当前为松果安卓折叠屏app,获取折叠屏信息',
2611
2611
  getJdAndroidPageInfo,
2612
2612
  '获取转换后的系统信息',
2613
2613
  info,
2614
2614
  );
2615
2615
  draBusinessCustomReport({
2616
2616
  eventName: 'UIInteract',
2617
2617
  errorName: 'android_jdapp_foldScreen_info',
2618
2618
  errorMessage: '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
2619
2619
  extraData: JSON.stringify({
2620
2620
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
2621
2621
  androidPageInfo: getJdAndroidPageInfo,
2622
2622
  jdAppVersionStr,
2623
2623
  taroSysInfo: info,
2624
2624
  }),
2625
2625
  });
2626
2626
  }
2627
2627
  }
2628
2628
  }
2629
2629
  if (isJdApp) {
2630
2630
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
2631
2631
  }
2632
2632
  this.info.sysInfo = {
2633
2633
  actualNavBarHeight: 0,
2634
2634
  ...this.info.sysInfo,
2635
2635
  ...info,
2636
2636
  safeContentHeight: info?.screenHeight,
2637
2637
  headerHeight: 0,
2638
2638
  tabBarHeight: 0,
2639
2639
  languageType: languageNowType,
2640
2640
  };
2641
2641
  if (isJdApp || isH5AndJingGouMini) {
2642
2642
  this.getLbsAddressCachePromise();
2643
2643
  }
2644
2644
  if (isJdApp) {
2645
2645
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
2646
2646
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
2647
2647
  this.getJdAppBaseInfo();
2648
2648
  this.getAddressCachePromise();
2649
2649
  this.getElderModePromise();
2650
2650
  this.getJDAppearanceStatePromise();
2651
2651
  this.createJdAndroidRquestEventForTouchStart();
2652
2652
  }
2653
2653
  this.getWifiVideoAutoPlayAsync();
2654
2654
  this.getMPaasConfigAsync();
2655
2655
  this.getNetWorkType();
2656
2656
  }
2657
2657
 
2658
2658
  getElderModePromise() {
2659
2659
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
2660
2660
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
2661
2661
  } else {
2662
2662
  if (isJdAndAndroidDevice) {
2663
2663
  this.info.sysInfo.jdAppModeType = '0';
2664
2664
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
2665
2665
  } else {
2666
2666
  return Promise.race([
2667
2667
  this.taskTimeoutPromise(() => {
2668
2668
  this.info.sysInfo.jdAppModeType = '0';
2669
2669
  return this.info.sysInfo.jdAppModeType;
2670
2670
  }),
2671
2671
  new Promise((resolve) => {
2672
2672
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
2673
2673
  if (!window[getCallBackName]) {
2674
2674
  window[getCallBackName] = (res) => {
2675
2675
  try {
2676
2676
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2677
2677
  const { status, data, msg } = getResJson;
2678
2678
  console.log(`获取松果app展示模式成功,返回结果${data}`);
2679
2679
  if (status === '0') {
2680
2680
  this.info.sysInfo.jdAppModeType = data;
2681
2681
  resolve(data);
2682
2682
  } else {
2683
2683
  resolve('0');
2684
2684
  }
2685
2685
  } catch (e) {
2686
2686
  resolve('0');
2687
2687
  }
2688
2688
  window[getCallBackName] = null;
2689
2689
  };
2690
2690
  }
2691
2691
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
2692
2692
  method: 'callSyncRouterModuleWithParams',
2693
2693
  params: JSON.stringify({
2694
2694
  routerURL: 'router://JDBModeModule/getCurrentMode',
2695
2695
  routerParam: {},
2696
2696
  callBackName: `window.${getCallBackName}`,
2697
2697
  callBackId: `${getCallBackName}Ios`,
2698
2698
  }),
2699
2699
  });
2700
2700
  }),
2701
2701
  ]);
2702
2702
  }
2703
2703
  }
2704
2704
  }
2705
2705
  getAPPUseStraightCorner() {
2706
2706
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
2707
2707
  const params = {
2708
2708
  routerURL,
2709
2709
  routerParam: {},
2710
2710
  jdRouter: '1',
2711
2711
  };
2712
2712
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
2713
2713
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
2714
2714
  } else {
2715
2715
  return this.jmfeReayPromise()
2716
2716
  .then(() => {
2717
2717
  if (isJdAndHarmonyDevice || !isJdApp) {
2718
2718
  console.log('not APP or is Harmony');
2719
2719
  return Promise.resolve(false);
2720
2720
  }
2721
2721
  console.log('jmfe setShareInfo', params);
2722
2722
  return Promise.race([
2723
2723
  window.jmfe.callRouter(params),
2724
2724
  this.taskTimeoutPromise(() => {
2725
2725
  return false;
2726
2726
  }),
2727
2727
  ]).then(({ status, data }) => {
2728
2728
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
2729
2729
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
2730
2730
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
2731
2731
  return Promise.resolve(status === '0' && Number(data) === 1);
2732
2732
  });
2733
2733
  })
2734
2734
  .catch((e) => {
2735
2735
  console.log('jmfe error', e);
2736
2736
  return Promise.resolve(false);
2737
2737
  });
2738
2738
  }
2739
2739
  }
2740
2740
 
2741
2741
  getJDAppearanceStatePromise() {
2742
2742
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
2743
2743
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
2744
2744
  } else {
2745
2745
  return Promise.race([
2746
2746
  this.taskTimeoutPromise(() => {
2747
2747
  this.info.sysInfo.jdAppearanceState = '0';
2748
2748
  return this.info.sysInfo.jdAppearanceState;
2749
2749
  }),
2750
2750
  new Promise((resolve) => {
2751
2751
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
2752
2752
  if (!window[getCallBackName]) {
2753
2753
  window[getCallBackName] = (res) => {
2754
2754
  try {
2755
2755
  console.log('getJDAppearanceStatePromise', res);
2756
2756
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2757
2757
  const { status, data, msg } = getResJson;
2758
2758
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
2759
2759
  if (status === '0') {
2760
2760
  this.info.sysInfo.jdAppearanceState = data;
2761
2761
  resolve(data);
2762
2762
  } else {
2763
2763
  resolve('0');
2764
2764
  }
2765
2765
  } catch (e) {
2766
2766
  resolve('0');
2767
2767
  }
2768
2768
  window[getCallBackName] = null;
2769
2769
  };
2770
2770
  }
2771
2771
  if (isAndroidDevice) {
2772
2772
  const jsonString = JSON.stringify({
2773
2773
  callBackName: `window.${getCallBackName}`,
2774
2774
  });
2775
2775
  console.log('window.JDAppearance', window?.JDAppearance);
2776
2776
  window?.JDAppearance &&
2777
2777
  window?.JDAppearance?.getUiState &&
2778
2778
  window.JDAppearance.getUiState(jsonString);
2779
2779
  } else {
2780
2780
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
2781
2781
  method: 'callSyncRouterModuleWithParams',
2782
2782
  params: JSON.stringify({
2783
2783
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
2784
2784
  routerParam: {},
2785
2785
  callBackName: `window.${getCallBackName}`,
2786
2786
  callBackId: `${getCallBackName}Ios`,
2787
2787
  }),
2788
2788
  });
2789
2789
  }
2790
2790
  }),
2791
2791
  ]);
2792
2792
  }
2793
2793
  }
2794
2794
 
2795
2795
  createJdAndroidRquestEventForTouchStart() {
2796
2796
  if (isJdAndAndroidDevice && window?.JdAndroid) {
2797
2797
  const rootEleNode = document.querySelector('body');
2798
2798
  if (rootEleNode) {
2799
2799
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
2800
2800
  }
2801
2801
  }
2802
2802
  }
2803
2803
  jdAndroidAddEventListenerTouchStart(e) {
2804
2804
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
2805
2805
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
2806
2806
  const hasCustomEle = e
2807
2807
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
2808
2808
  : false;
2809
2809
  if (!hasCustomEle) {
2810
2810
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
2811
2811
  console.log(
2812
2812
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
2813
2813
  );
2814
2814
  }
2815
2815
  }
2816
2816
  }
2817
2817
  removeJdAndroidRquestEventForTouchStart() {
2818
2818
  if (isJdAndAndroidDevice && window.JdAndroid) {
2819
2819
  const rootEleNode = document.querySelector('body');
2820
2820
  if (rootEleNode) {
2821
2821
  rootEleNode.removeEventListener(
2822
2822
  'touchstart',
2823
2823
  this.jdAndroidAddEventListenerTouchStart,
2824
2824
  false,
2825
2825
  );
2826
2826
  }
2827
2827
  }
2828
2828
  }
2829
2829
 
2830
2830
  getNetWorkType() {
2831
2831
  if (isJdApp) {
2832
2832
  this.jmfeReayPromise().then(() => {
2833
2833
  window.jmfe
2834
2834
  .getNetworkStatus()
2835
2835
  .then(({ status, data }) => {
2836
2836
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
2837
2837
  if (status === '0') {
2838
2838
  this.info.sysInfo['netWorkType'] = data;
2839
2839
  } else {
2840
2840
  this._taroGetNetworkType();
2841
2841
  }
2842
2842
  })
2843
2843
  .catch((err) => {
2844
2844
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
2845
2845
  this._taroGetNetworkType();
2846
2846
  });
2847
2847
  });
2848
2848
  } else {
2849
2849
  this._taroGetNetworkType();
2850
2850
  }
2851
2851
  }
2852
2852
  _taroGetNetworkType() {
2853
2853
  Taro.getNetworkType().then((getRes) => {
2854
2854
  if (getRes && getRes.networkType) {
2855
2855
  this.info.sysInfo['netWorkType'] = getRes.networkType;
2856
2856
  console.log(
2857
2857
  '在app内通过taro对象获取网络状态完成,当前网络状态',
2858
2858
  this.info.sysInfo['netWorkType'],
2859
2859
  );
2860
2860
  }
2861
2861
  });
2862
2862
  }
2863
2863
 
2864
2864
  getJdAppBaseInfo(){
2865
2865
  const appKeyCacheToCookieMinuteTime = window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
2866
2866
  appUuidCacheToCookieMinuteTime = window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
2867
2867
  getAppKey = cookie.get(cacheAppKey),getAppUuidKey = cookie.get(cacheAppUuidKey);
2868
2868
  console.log("在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam",cacheAppKey,getAppKey,cacheAppUuidKey,getAppUuidKey)
2869
2869
  if(appKeyCacheToCookieMinuteTime && appUuidCacheToCookieMinuteTime && getAppKey && getAppUuidKey){
2870
2870
  const [ uuid, eufv] = getAppUuidKey.split("@")
2871
2871
  const baseApiKeyParam = {
2872
2872
  uuid,
2873
2873
  }
2874
2874
  getAppKey !== "-1000" && (baseApiKeyParam['x_app_key'] = getAppKey)
2875
2875
  if(eufv === "1" && /-/.test(uuid)){
2876
2876
  const [eu, fv] = uuid.split('-');
2877
2877
  baseApiKeyParam['eu'] = eu;
2878
2878
  baseApiKeyParam['fv'] = fv;
2879
2879
  }
2880
2880
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam
2881
2881
  this.jmfeReayPromise().then(() => {
2882
2882
  console.log("在app内初始化通过cookie获取api请求参数集合baseApiKeyParam",baseApiKeyParam)
2883
2883
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam)
2884
2884
  })
2885
2885
  }else {
2886
2886
  const checkGetJdAppKeyState = window?.shopGlobalSwitch?.getJdAppKeyVersion && jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0
2887
2887
  this.jmfeReayPromise().then(() => {
2888
2888
  Promise.all([
2889
2889
  checkGetJdAppKeyState && window.jmfe?.callNative ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0') : Promise.resolve({
2890
2890
  status: "-1000",
2891
2891
  msg: "当前版本不支持获取松果app中的getAppKey",
2892
2892
  data: "-1000"
2893
2893
  }),
2894
2894
  window.jmfe.getDeviceInfo()
2895
2895
  ]).then(resList => {
2896
2896
  const [getAppKeyRes, deviceInfoRes] = resList;
2897
2897
  console.log("在app内初始化通过jmfe获取getAppKey结果", getAppKeyRes, "通过jmfe获取getDeviceInfo获取结果", deviceInfoRes)
2898
2898
  const baseApiKeyParam = {}
2899
2899
  if (["0","-1000"].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
2900
2900
  const getJmfeAppKey = getAppKeyRes?.data
2901
2901
  if(getJmfeAppKey && getJmfeAppKey !== ""){
2902
2902
  getJmfeAppKey !== "-1000" && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
2903
2903
  const getJdAppKeyCacheToCookieMinuteTime = (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
2904
2904
  if(getJdAppKeyCacheToCookieMinuteTime){
2905
2905
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
2906
2906
  cookie.set(cacheAppKey, getJmfeAppKey, {
2907
2907
  path: '/',
2908
2908
  expires,
2909
2909
  })
2910
2910
  }
2911
2911
  }
2912
2912
  }
2913
2913
  if (deviceInfoRes?.status === "0" && deviceInfoRes?.data) {
2914
2914
  const { uuid, eufv = "0", networkType } = deviceInfoRes?.data
2915
2915
  if( uuid && uuid !== "" ){
2916
2916
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
2917
2917
  baseApiKeyParam['uuid'] = uuid;
2918
2918
  if (eufv === "1" && /-/.test(uuid)) {
2919
2919
  const [eu, fv] = uuid.split('-');
2920
2920
  baseApiKeyParam['eu'] = eu;
2921
2921
  baseApiKeyParam['fv'] = fv;
2922
2922
  }
2923
2923
  const getAppUuidCacheToCookieMinuteTime = (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
2924
2924
  if(getAppUuidCacheToCookieMinuteTime){
2925
2925
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
2926
2926
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
2927
2927
  path: '/',
2928
2928
  expires,
2929
2929
  })
2930
2930
  }
2931
2931
  }
2932
2932
  }
2933
2933
  console.log("在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam", baseApiKeyParam)
2934
2934
  if(Object.keys(baseApiKeyParam).length > 0){
2935
2935
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam
2936
2936
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
2937
2937
  }
2938
2938
  })
2939
2939
  })
2940
2940
  }
2941
2941
  }
2942
2942
 
2943
2943
  getCacheAddressRouter() {
2944
2944
  if (isJdApp) {
2945
2945
  if (!isJdAndHarmonyDevice) {
2946
2946
  return Promise.race([
2947
2947
  new Promise((resolve) => {
2948
2948
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
2949
2949
  if (!window[getCallBackName]) {
2950
2950
  window[getCallBackName] = (res) => {
2951
2951
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
2952
2952
  try {
2953
2953
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2954
2954
  resolve(getResJson);
2955
2955
  } catch (e) {
2956
2956
  resolve({
2957
2957
  status: '-1002',
2958
2958
  msg: '地址信息解析json异常',
2959
2959
  res,
2960
2960
  });
2961
2961
  }
2962
2962
  window[getCallBackName] = null;
2963
2963
  };
2964
2964
  }
2965
2965
  const getRouterParam = {
2966
2966
  sceneId: 'basicShoppingProcess',
2967
2967
  };
2968
2968
  if (isAndroidDevice) {
2969
2969
  return callRouterAndroid({
2970
2970
  routerURL: 'router://JDAddressModule/getCacheAddress',
2971
2971
  routerParam: getRouterParam,
2972
2972
  callBackName: getCallBackName,
2973
2973
  isSync: true,
2974
2974
  });
2975
2975
  } else {
2976
2976
  return callRouterIOS({
2977
2977
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
2978
2978
  routerParam: getRouterParam,
2979
2979
  callBackName: getCallBackName,
2980
2980
  });
2981
2981
  }
2982
2982
  }),
2983
2983
  this.taskTimeoutPromise(() => {
2984
2984
  return {
2985
2985
  status: '-1000',
2986
2986
  msg: '原生router协议获取地址信息超时',
2987
2987
  };
2988
2988
  }, 3000),
2989
2989
  ]);
2990
2990
  } else {
2991
2991
  return Promise.race([
2992
2992
  new Promise((resolve) => {
2993
2993
  this.jmfeReayPromise()
2994
2994
  .then(() => {
2995
2995
  const plugin = 'JDHybridRouterPlugin';
2996
2996
  const action = 'callSyncRouterModuleWithParams';
2997
2997
  const params = {
2998
2998
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
2999
2999
  routerParam: '',
3000
3000
  };
3001
3001
  const sync = '1';
3002
3002
  try {
3003
3003
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
3004
3004
  resolve(res);
3005
3005
  });
3006
3006
  } catch (error) {
3007
3007
  resolve({
3008
3008
  status: '-1001',
3009
3009
  msg: '判断jmfe不存在,获取经纬度信息异常',
3010
3010
  });
3011
3011
  }
3012
3012
  })
3013
3013
  .catch(() => {
3014
3014
  resolve({
3015
3015
  status: '-1002',
3016
3016
  msg: '鸿蒙系统调用jmfe异常,获取失败',
3017
3017
  });
3018
3018
  });
3019
3019
  }),
3020
3020
  this.taskTimeoutPromise(() => {
3021
3021
  return {
3022
3022
  status: '-1000',
3023
3023
  msg: '原生router协议获取地址信息超时',
3024
3024
  };
3025
3025
  }, 3000),
3026
3026
  ]);
3027
3027
  }
3028
3028
  } else if (isH5AndJingGouMini) {
3029
3029
  return Promise.resolve({
3030
3030
  status: '-1002',
3031
3031
  msg: '普通h5暂无业务需要,未实现,获取失败',
3032
3032
  });
3033
3033
  } else {
3034
3034
  return Promise.resolve({
3035
3035
  status: '-1002',
3036
3036
  msg: '普通h5暂无业务需要,未实现,获取失败',
3037
3037
  });
3038
3038
  }
3039
3039
  }
3040
3040
 
3041
3041
  getAddressCachePromise() {
3042
3042
  return new Promise((resolve) => {
3043
3043
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
3044
3044
  resolve({
3045
3045
  lat: this.info.sysInfo.lat,
3046
3046
  lng: this.info.sysInfo.lng,
3047
3047
  area: this?.info?.sysInfo?.area,
3048
3048
  });
3049
3049
  } else {
3050
3050
  this.getCacheAddressRouter()
3051
3051
  .then((res) => {
3052
3052
  const { status, data } = res;
3053
3053
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
3054
3054
  if (status === '0' && data) {
3055
3055
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
3056
3056
  data || {};
3057
3057
  let area = '';
3058
3058
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
3059
3059
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
3060
3060
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
3061
3061
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3062
3062
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
3063
3063
  this.info.pageInfo['address'] = area;
3064
3064
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
3065
3065
  this.info.sysInfo['area'] = area;
3066
3066
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3067
3067
  area: this.info.pageInfo.address,
3068
3068
  });
3069
3069
  }
3070
3070
  resolve({
3071
3071
  lat: this.info.sysInfo['lat'],
3072
3072
  lng: this.info.sysInfo['lng'],
3073
3073
  area: area,
3074
3074
  });
3075
3075
  } else {
3076
3076
  if (typeof res === 'object') {
3077
3077
  draBusinessCustomReport({
3078
3078
  eventName: 'business',
3079
3079
  errorName: 'jdapp_getCacheAddress_info_err',
3080
3080
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
3081
3081
  extraData: JSON.stringify({
3082
3082
  isJdApp,
3083
3083
  jdAppVersion: jdAppVersionStr,
3084
3084
  ...res,
3085
3085
  }),
3086
3086
  });
3087
3087
  }
3088
3088
  resolve({ lat: '', lng: '', area: '' });
3089
3089
  }
3090
3090
  })
3091
3091
  .catch((e) => {
3092
3092
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
3093
3093
  draBusinessCustomReport({
3094
3094
  eventName: 'business',
3095
3095
  errorName: 'jdapp_getCacheAddress_info_catch_err',
3096
3096
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
3097
3097
  extraData: JSON.stringify({
3098
3098
  isJdApp,
3099
3099
  jdAppVersion: jdAppVersionStr,
3100
3100
  }),
3101
3101
  });
3102
3102
  resolve({ lat: '', lng: '', area: '' });
3103
3103
  });
3104
3104
  }
3105
3105
  });
3106
3106
  }
3107
3107
 
3108
3108
  getLbsCacheAddressRouter() {
3109
3109
  if (isJdApp) {
3110
3110
  if (!isJdAndHarmonyDevice) {
3111
3111
  return Promise.race([
3112
3112
  new Promise((resolve) => {
3113
3113
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
3114
3114
  if (!window[getCallBackName]) {
3115
3115
  window[getCallBackName] = (res) => {
3116
3116
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
3117
3117
  try {
3118
3118
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3119
3119
  resolve(getResJson);
3120
3120
  } catch (e) {
3121
3121
  resolve({
3122
3122
  status: '-1002',
3123
3123
  msg: '地址信息解析json异常',
3124
3124
  res,
3125
3125
  });
3126
3126
  }
3127
3127
  window[getCallBackName] = null;
3128
3128
  };
3129
3129
  }
3130
3130
  const getRouterParam = {
3131
3131
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
3132
3132
  sceneId: 'basicShoppingProcess',
3133
3133
  };
3134
3134
  if (isAndroidDevice) {
3135
3135
  return callRouterAndroid({
3136
3136
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
3137
3137
  routerParam: getRouterParam,
3138
3138
  callBackName: getCallBackName,
3139
3139
  isSync: true,
3140
3140
  hasJdRouter: false,
3141
3141
  });
3142
3142
  } else {
3143
3143
  return callRouterIOS({
3144
3144
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
3145
3145
  routerParam: getRouterParam,
3146
3146
  callBackName: getCallBackName,
3147
3147
  isSync: true,
3148
3148
  });
3149
3149
  }
3150
3150
  }),
3151
3151
  this.taskTimeoutPromise(() => {
3152
3152
  return {
3153
3153
  status: '-1000',
3154
3154
  msg: '原生router协议获取lbs地址信息3s超时',
3155
3155
  };
3156
3156
  }, 3000),
3157
3157
  ]);
3158
3158
  } else {
3159
3159
  return Promise.resolve({
3160
3160
  status: '-1001',
3161
3161
  msg: '鸿蒙系统调用未实现,获取失败',
3162
3162
  });
3163
3163
  }
3164
3164
  } else if (isH5AndJingGouMini) {
3165
3165
  return this.getLocationForGpsPromise();
3166
3166
  } else {
3167
3167
  return Promise.resolve({
3168
3168
  status: '-1002',
3169
3169
  msg: '普通h5暂无业务需要,未实现,获取失败',
3170
3170
  });
3171
3171
  }
3172
3172
  }
3173
3173
  getLocationForGpsPromise() {
3174
3174
  return new Promise((resolve) => {
3175
3175
  let hasGetLocationForGps = true;
3176
3176
  if (urlCookie && urlCookie['loc']) {
3177
3177
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
3178
3178
  urlCookie['loc'].split('_');
3179
3179
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3180
3180
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3181
3181
  hasGetLocationForGps = false;
3182
3182
  resolve({
3183
3183
  status: '0',
3184
3184
  data: {
3185
3185
  provinceid,
3186
3186
  cityid,
3187
3187
  districtid,
3188
3188
  townid,
3189
3189
  origin: 'wxapp',
3190
3190
  },
3191
3191
  });
3192
3192
  }
3193
3193
  }
3194
3194
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
3195
3195
  window.navigator.geolocation.getCurrentPosition(
3196
3196
  (position) => {
3197
3197
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
3198
3198
  if (position?.coords) {
3199
3199
  resolve({
3200
3200
  status: '0',
3201
3201
  data: {
3202
3202
  srclat: position.coords?.latitude,
3203
3203
  srclng: position.coords.longitude,
3204
3204
  origin: 'h5',
3205
3205
  },
3206
3206
  });
3207
3207
  } else {
3208
3208
  resolve({
3209
3209
  status: '-1001',
3210
3210
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
3211
3211
  position,
3212
3212
  });
3213
3213
  }
3214
3214
  },
3215
3215
  (error) => {
3216
3216
  resolve({
3217
3217
  status: '-1001',
3218
3218
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
3219
3219
  error,
3220
3220
  });
3221
3221
  },
3222
3222
  {
3223
3223
  enableHighAccuracy: false,
3224
3224
  timeout: 3 * 1000,
3225
3225
  maximumAge: 10 * 60 * 1000,
3226
3226
  },
3227
3227
  );
3228
3228
  } else {
3229
3229
  resolve({
3230
3230
  status: '-1001',
3231
3231
  msg: '您的浏览器不支持地理定位',
3232
3232
  });
3233
3233
  }
3234
3234
  });
3235
3235
  }
3236
3236
 
3237
3237
  createLbsCacheAddress(realTimeArea) {
3238
3238
  const getLbsAddressCacheMinuteTime = Number(
3239
3239
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
3240
3240
  );
3241
3241
  console.log(
3242
3242
  '获取lbs缓存到cookie的时间,分钟',
3243
3243
  getLbsAddressCacheMinuteTime,
3244
3244
  'lbsAddressCacheToCookieMinuteTime',
3245
3245
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
3246
3246
  );
3247
3247
  if (getLbsAddressCacheMinuteTime > 0) {
3248
3248
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
3249
3249
  realTimeArea &&
3250
3250
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
3251
3251
  path: '/',
3252
3252
  expires,
3253
3253
  });
3254
3254
  }
3255
3255
  }
3256
3256
 
3257
3257
  getLbsAddressCachePromise() {
3258
3258
  if (!this.lbsAddressCachePromise) {
3259
3259
  this.lbsAddressCachePromise = new Promise((resolve) => {
3260
3260
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
3261
3261
  ? cookie.get(cacheH5LbsAddressKey)
3262
3262
  : '';
3263
3263
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
3264
3264
  if (getUserLbsAddress && getUserLbsAddress !== '') {
3265
3265
  resolve({
3266
3266
  ok: true,
3267
3267
  realTimeArea: getUserLbsAddress,
3268
3268
  });
3269
3269
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
3270
3270
  console.info(
3271
3271
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
3272
3272
  getCookieForLbsAddress,
3273
3273
  );
3274
3274
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
3275
3275
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
3276
3276
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3277
3277
  realTimeArea: getCookieForLbsAddress,
3278
3278
  });
3279
3279
  resolve({
3280
3280
  ok: true,
3281
3281
  realTimeArea: getCookieForLbsAddress,
3282
3282
  });
3283
3283
  } else {
3284
3284
  this.getLbsCacheAddressRouter()
3285
3285
  .then((res) => {
3286
3286
  const { status, data } = res;
3287
3287
  console.log(
3288
3288
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
3289
3289
  status,
3290
3290
  data,
3291
3291
  res,
3292
3292
  );
3293
3293
  if (status === '0' && data) {
3294
3294
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
3295
3295
  data || {};
3296
3296
  let realTimeArea = '';
3297
3297
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
3298
3298
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
3299
3299
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3300
3300
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3301
3301
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
3302
3302
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
3303
3303
  this.info.sysInfo['realTimeArea'] = realTimeArea;
3304
3304
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3305
3305
  realTimeArea: this.info.pageInfo.userLbsAddress,
3306
3306
  });
3307
3307
  this.createLbsCacheAddress(realTimeArea);
3308
3308
  } else {
3309
3309
  !origin && (this.lbsAddressCachePromise = null);
3310
3310
  }
3311
3311
  const getValidRealTimeArea = realTimeArea !== '';
3312
3312
  resolve({
3313
3313
  lat: this.info.sysInfo['srclat'],
3314
3314
  lng: this.info.sysInfo['srclng'],
3315
3315
  realTimeArea: realTimeArea,
3316
3316
  ok: getValidRealTimeArea,
3317
3317
  msg: getValidRealTimeArea
3318
3318
  ? '成功'
3319
3319
  : origin
3320
3320
  ? origin
3321
3321
  : '根据router底层获取lbs地址信息异常,详情见data',
3322
3322
  data: getValidRealTimeArea ? null : res,
3323
3323
  });
3324
3324
  if (!getValidRealTimeArea && !origin) {
3325
3325
  draBusinessCustomReport({
3326
3326
  eventName: 'business',
3327
3327
  errorName: 'h5_getLbsCacheAddress_info_err',
3328
3328
  errorMessage: '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
3329
3329
  extraData: JSON.stringify({
3330
3330
  isJdApp,
3331
3331
  jdAppVersion: jdAppVersionStr,
3332
3332
  }),
3333
3333
  });
3334
3334
  }
3335
3335
  } else {
3336
3336
  typeof res === 'object' &&
3337
3337
  draBusinessCustomReport({
3338
3338
  eventName: 'business',
3339
3339
  errorName: 'h5_getLbsCacheAddress_info_err',
3340
3340
  errorMessage: 'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
3341
3341
  extraData: JSON.stringify({
3342
3342
  isJdApp,
3343
3343
  jdAppVersion: jdAppVersionStr,
3344
3344
  ...res,
3345
3345
  }),
3346
3346
  });
3347
3347
  this.lbsAddressCachePromise = null;
3348
3348
  resolve({ realTimeArea: '', ok: false });
3349
3349
  }
3350
3350
  })
3351
3351
  .catch((e) => {
3352
3352
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
3353
3353
  this.lbsAddressCachePromise = null;
3354
3354
  draBusinessCustomReport({
3355
3355
  eventName: 'business',
3356
3356
  errorName: 'h5_getLbsCacheAddress_info_err',
3357
3357
  errorMessage: 'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
3358
3358
  extraData: JSON.stringify({
3359
3359
  isJdApp,
3360
3360
  jdAppVersion: jdAppVersionStr,
3361
3361
  }),
3362
3362
  });
3363
3363
  resolve({ realTimeArea: '', ok: false });
3364
3364
  });
3365
3365
  }
3366
3366
  });
3367
3367
  }
3368
3368
  return this.lbsAddressCachePromise;
3369
3369
  }
3370
3370
 
3371
3371
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
3372
3372
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
3373
3373
  if (!isJdApp) {
3374
3374
  return;
3375
3375
  }
3376
3376
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
3377
3377
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
3378
3378
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
3379
3379
  'hybridHttpSwitch',
3380
3380
  isBeforePageReady,
3381
3381
  );
3382
3382
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
3383
3383
  'jshopIsVipShop',
3384
3384
  isBeforePageReady,
3385
3385
  );
3386
3386
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
3387
3387
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
3388
3388
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
3389
3389
  'isFollowAppVideoPlayStatus',
3390
3390
  isBeforePageReady,
3391
3391
  );
3392
3392
  console.log(
3393
3393
  'isBeforePageReady:',
3394
3394
  isBeforePageReady,
3395
3395
  'isFollowAppVideoPlayStatus:',
3396
3396
  isFollowAppVideoPlayStatus,
3397
3397
  );
3398
3398
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
3399
3399
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
3400
3400
  }
3401
3401
  }
3402
3402
 
3403
3403
  async getWifiVideoAutoPlayAsync() {
3404
3404
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
3405
3405
  if (!isJdApp) {
3406
3406
  return;
3407
3407
  }
3408
3408
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
3409
3409
  return 0;
3410
3410
  });
3411
3411
  if (Number(videoPlayStatus) === 1) {
3412
3412
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
3413
3413
  }
3414
3414
  }
3415
3415
 
3416
3416
  async getMPaasConfigAsync() {
3417
3417
  this.info.sysInfo.dynamicConfig = {};
3418
3418
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
3419
3419
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
3420
3420
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
3421
3421
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
3422
3422
  return this.updateMPaasConfigAsync(true);
3423
3423
  }
3424
3424
 
3425
3425
  getDynamicConfig(key: string) {
3426
3426
  return this.info.sysInfo?.dynamicConfig?.[key];
3427
3427
  }
3428
3428
  async updateMPaasConfig() {
3429
3429
  console.log('updateMPaasConfig');
3430
3430
  if (
3431
3431
  isIosDevice &&
3432
3432
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
3433
3433
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
3434
3434
  ) {
3435
3435
  try {
3436
3436
  await this.updateMPaasConfigAsync(false);
3437
3437
  } catch (e) {
3438
3438
  console.log('updateMPaasConfigAsync:', e);
3439
3439
  }
3440
3440
  }
3441
3441
  }
3442
3442
 
3443
3443
  toLogin(options) {
3444
3444
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
3445
3445
  ? this.toWxAppLogin(options)
3446
3446
  : this.toWebLogin(options);
3447
3447
  }
3448
3448
 
3449
3449
  doLogin(options) {
3450
3450
  return this.toLogin(options);
3451
3451
  }
3452
3452
 
3453
3453
  doLoginForJdPin(options = {}) {
3454
3454
  return this.doLogin({
3455
3455
  loginColor: {
3456
3456
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
3457
3457
  dpin: 0,
3458
3458
  },
3459
3459
  ...options,
3460
3460
  });
3461
3461
  }
3462
3462
 
3463
3463
  toWebLogin(options) {
3464
3464
  let params: {
3465
3465
  returnurl: string;
3466
3466
  } = {
3467
3467
  returnurl: '',
3468
3468
  };
3469
3469
  const checkToPcLogin = options ? options?.isPc : isPc;
3470
3470
  const loginUrl = checkToPcLogin
3471
3471
  ? `//passport.jd.com/new/login.aspx`
3472
3472
  : `${domain.mobileLogin}/user/login.action`;
3473
3473
  const defaultParams = {
3474
3474
  appid: '100',
3475
3475
  returnurl: window.location.href,
3476
3476
  };
3477
3477
  if (isString(options)) {
3478
3478
  params = Object.assign({}, defaultParams, {
3479
3479
  returnurl: options,
3480
3480
  });
3481
3481
  } else if (isObject(options)) {
3482
3482
  const { loginColor, ...otherOptions } = options;
3483
3483
  params = Object.assign({}, defaultParams, otherOptions);
3484
3484
  } else {
3485
3485
  params = defaultParams;
3486
3486
  }
3487
3487
  params.returnurl = encodeURIComponent(params.returnurl);
3488
3488
  let getFullUrl = loginUrl + '?' + serialize(params);
3489
3489
  if (checkToPcLogin) {
3490
3490
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
3491
3491
  }
3492
3492
  return Promise.resolve({
3493
3493
  h5ToUrl: true,
3494
3494
  url: getFullUrl,
3495
3495
  }).then(() => {
3496
3496
  window.location.href = getFullUrl;
3497
3497
  });
3498
3498
  }
3499
3499
 
3500
3500
  toWxAppLogin(options = {}) {
3501
3501
  console.log('微信京购小程序中h5登录跳转', options);
3502
3502
  return Promise.resolve(true).then(() => {
3503
3503
  const { loginColor } = Object.assign(
3504
3504
  {},
3505
3505
  {
3506
3506
  loginColor: {
3507
3507
  biz: WXAPP_BIZ_KEY,
3508
3508
  dpin: 1,
3509
3509
  },
3510
3510
  },
3511
3511
  options,
3512
3512
  );
3513
3513
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${loginColor.biz
3514
3514
  }&url=${encodeURIComponent(window.location.href)}`;
3515
3515
  });
3516
3516
  }
3517
3517
 
3518
3518
  getLoginCookie() {
3519
3519
  return Promise.resolve({
3520
3520
  pin: cookie.get('pin') || '',
3521
3521
  });
3522
3522
  }
3523
3523
 
3524
3524
  clearLoginCookie() {
3525
3525
  cookie.remove('pin');
3526
3526
  }
3527
3527
 
3528
3528
  checkStatusAndLogin(options = {}) {
3529
3529
  if (!this.checkStatusAndLoginPromise) {
3530
3530
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
3531
3531
  try {
3532
3532
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
3533
3533
  if (getLoginState) {
3534
3534
  resolve(true);
3535
3535
  } else {
3536
3536
  this.toLogin(options);
3537
3537
  reject(false);
3538
3538
  }
3539
3539
  } catch (e) {
3540
3540
  this.toLogin(options);
3541
3541
  reject(false);
3542
3542
  }
3543
3543
  });
3544
3544
  return this.checkStatusAndLoginPromise;
3545
3545
  } else {
3546
3546
  return this.checkStatusAndLoginPromise
3547
3547
  .then(() => {
3548
3548
  return Promise.resolve(true);
3549
3549
  })
3550
3550
  .catch(() => {
3551
3551
  this.toLogin(options);
3552
3552
  return Promise.reject(true);
3553
3553
  });
3554
3554
  }
3555
3555
  }
3556
3556
 
3557
3557
  checkJdStatusAndLogin(
3558
3558
  options = {
3559
3559
  loginColor: {
3560
3560
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
3561
3561
  dpin: 0,
3562
3562
  },
3563
3563
  },
3564
3564
  ) {
3565
3565
  return this.checkStatusAndLogin(options);
3566
3566
  }
3567
3567
 
3568
3568
  doCheckLoginStateAndForApiCheck(options) {
3569
3569
  if (this.info.loginState) {
3570
3570
  return Promise.resolve(true);
3571
3571
  } else {
3572
3572
  return new Promise((resolve, reject) => {
3573
3573
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
3574
3574
  const getWqAuthToken = cookie.get('wq_auth_token');
3575
3575
  const getWqSkey = cookie.get('wq_skey');
3576
3576
  const getWqUin = cookie.get('wq_uin');
3577
3577
  const isLoginState =
3578
3578
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
3579
3579
  if (isLoginState) {
3580
3580
  this.info.loginState = true;
3581
3581
  resolve(true);
3582
3582
  } else {
3583
3583
  reject(false);
3584
3584
  }
3585
3585
  } else {
3586
3586
  Taro.request({
3587
3587
  url: api.isLogin,
3588
3588
  jsonp: true,
3589
3589
  timeout: 3000,
3590
3590
  success: (res) => {
3591
3591
  const { statusCode, data } = res;
3592
3592
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
3593
3593
  this.info.loginState = true;
3594
3594
  resolve(true);
3595
3595
  } else {
3596
3596
  reject(false);
3597
3597
  }
3598
3598
  },
3599
3599
  fail: (err) => {
3600
3600
  console.log('登录检查异常', err);
3601
3601
  reject(false);
3602
3602
  },
3603
3603
  });
3604
3604
  }
3605
3605
  });
3606
3606
  }
3607
3607
  }
3608
3608
 
3609
3609
  checkLoginStatus(options) {
3610
3610
  return new Promise(async (resolve, reject) => {
3611
3611
  try {
3612
3612
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
3613
3613
  if (getLoginState) {
3614
3614
  const { pin } = await this.getLoginCookie();
3615
3615
  this.info.userInfo = {
3616
3616
  pin,
3617
3617
  encodePin: encodeURIComponent(pin),
3618
3618
  ptkey: '',
3619
3619
  };
3620
3620
  resolve(true);
3621
3621
  } else {
3622
3622
  reject(false);
3623
3623
  }
3624
3624
  } catch (e) {
3625
3625
  reject(false);
3626
3626
  }
3627
3627
  });
3628
3628
  }
3629
3629
 
3630
3630
  updatePageAndLogInfo(updateQuery = {}) {
3631
3631
  const createUpdateQueryInfo: {
3632
3632
  query: {
3633
3633
  shopId?: string | number;
3634
3634
  venderId?: string | number;
3635
3635
  };
3636
3636
  updateShopInfoState: boolean;
3637
3637
  } = Object.assign(
3638
3638
  {},
3639
3639
  {
3640
3640
  query: {},
3641
3641
  updateShopInfoState: false,
3642
3642
  },
3643
3643
  updateQuery,
3644
3644
  );
3645
3645
  console.log(
3646
3646
  '获取当前下发的店铺查询参数',
3647
3647
  updateQuery,
3648
3648
  '获取之前保存的shopInfo店铺查询参数',
3649
3649
  this.info?.shopInfo,
3650
3650
  );
3651
3651
  const { query, updateShopInfoState } = createUpdateQueryInfo;
3652
3652
  const { shopId, venderId, un_area } = query;
3653
3653
  if (updateShopInfoState) {
3654
3654
  this.info.queryInfo = {
3655
3655
  ...this.info.queryInfo,
3656
3656
  ...query,
3657
3657
  };
3658
3658
  if (shopId && venderId) {
3659
3659
  this.info.shopInfo = {
3660
3660
  shopId: `${shopId}`,
3661
3661
  venderId: `${venderId}`,
3662
3662
  };
3663
3663
  }
3664
3664
  } else {
3665
3665
  this.info.queryInfo = {
3666
3666
  ...query,
3667
3667
  };
3668
3668
  if (
3669
3669
  this.info.shopInfo?.shopId &&
3670
3670
  this.info.shopInfo?.venderId &&
3671
3671
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
3672
3672
  ) {
3673
3673
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
3674
3674
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
3675
3675
  console.log(
3676
3676
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
3677
3677
  this.info.queryInfo,
3678
3678
  );
3679
3679
  }
3680
3680
  }
3681
3681
  this.info.queryInfo['shopId'] &&
3682
3682
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
3683
3683
  this.info.queryInfo['venderId'] &&
3684
3684
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
3685
3685
  console.log(
3686
3686
  'h5==获取店铺下发查询参数\n',
3687
3687
  query,
3688
3688
  '\n获取店铺最后查询参数\n',
3689
3689
  this.info.queryInfo,
3690
3690
  '\n是否为更新店铺状态\n',
3691
3691
  updateShopInfoState,
3692
3692
  );
3693
3693
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
3694
3694
  if (changeArea) {
3695
3695
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
3696
3696
  this.info.pageInfo.address = getBottomAreaStr;
3697
3697
  this.info.pageInfo.un_area = getBottomAreaStr;
3698
3698
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
3699
3699
  }
3700
3700
  }
3701
3701
 
3702
3702
  dealLoadSdkList() {
3703
3703
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
3704
3704
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
3705
3705
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
3706
3706
  let mergeLoadJsList = globalLoadJsList;
3707
3707
  try {
3708
3708
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
3709
3709
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
3710
3710
  getFindIndex !== -1
3711
3711
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
3712
3712
  : accArr.push(current);
3713
3713
  return accArr;
3714
3714
  }, []);
3715
3715
  } catch (e) {
3716
3716
  console.log('LoadJsList合并错误', e);
3717
3717
  }
3718
3718
  console.log(
3719
3719
  'globalLoadJsList',
3720
3720
  globalLoadJsList,
3721
3721
  'businessLoadJsList',
3722
3722
  businessLoadJsList,
3723
3723
  '两个加载jsList集合合并完成',
3724
3724
  mergeLoadJsList,
3725
3725
  );
3726
3726
  this.loadJsSdkList = mergeLoadJsList;
3727
3727
  return this.loadJsSdkList;
3728
3728
  }
3729
3729
 
3730
3730
  renderNextTickLoadSdk(delayTime = 1000) {
3731
3731
  Taro.nextTick(() => {
3732
3732
  console.log(
3733
3733
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
3734
3734
  );
3735
3735
  setTimeout(() => {
3736
3736
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
3737
3737
  }, delayTime);
3738
3738
  });
3739
3739
  }
3740
3740
 
3741
3741
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
3742
3742
  const getLoadJsList =
3743
3743
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
3744
3744
  const getLoadFilterList = getLoadJsList.filter((item) => {
3745
3745
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
3746
3746
  item.initLoadType = undefined;
3747
3747
  }
3748
3748
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
3749
3749
  let getLoastLoadEventState = true;
3750
3750
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
3751
3751
  getLoastLoadEventState = isJdApp;
3752
3752
  }
3753
3753
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
3754
3754
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
3755
3755
  }
3756
3756
  const getInitTriggerType =
3757
3757
  isJdApp && item?.initJdAppTriggerType
3758
3758
  ? item?.initTriggerType
3759
3759
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
3760
3760
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
3761
3761
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
3762
3762
  });
3763
3763
  console.log(
3764
3764
  '获取当前触发方式',
3765
3765
  triggerType,
3766
3766
  '获取当前最后加载的js集合',
3767
3767
  getLoadFilterList,
3768
3768
  '过滤前的加载集合',
3769
3769
  getLoadJsList,
3770
3770
  );
3771
3771
  getLoadFilterList.length > 0 &&
3772
3772
  getLoadFilterList.forEach((item) => {
3773
3773
  const isLoadState = /sgm/.test(item?.fileName)
3774
3774
  ? window?.shopGlobalSwitch?.openSgm === 'true'
3775
3775
  : true;
3776
3776
  isLoadState &&
3777
3777
  this.loadItemSdkPromise(item)
3778
3778
  .then((res) => {
3779
3779
  console.info('当前js地址' + item?.src, '加载状态', res);
3780
3780
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
3781
3781
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
3782
3782
  window.dra.run('init', { aid: res?.aid });
3783
3783
  window.dra.run('start');
3784
3784
  }
3785
3785
  })
3786
3786
  .catch((err) => {
3787
3787
  console.info('当前js地址加载异常', item?.src);
3788
3788
  window?.fetchErrorData &&
3789
3789
  window.fetchErrorData({
3790
3790
  title: '公共js加载异常',
3791
3791
  type: 'jsLoad',
3792
3792
  data: err,
3793
3793
  });
3794
3794
  });
3795
3795
  });
3796
3796
  }
3797
3797
  loadScriptEle(jsInfo, resolve, reject) {
3798
3798
  const getFileName = jsInfo?.fileName;
3799
3799
  if (getFileName) {
3800
3800
  const getEleId = `J_loadJs_${getFileName}`;
3801
3801
  const getEle = document.getElementById(getEleId);
3802
3802
  if (!getEle) {
3803
3803
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3804
3804
  const _sgmEle = document.createElement('script');
3805
3805
  _sgmEle.id = getEleId;
3806
3806
  _sgmEle.onload = function () {
3807
3807
  resolve({
3808
3808
  ...jsInfo,
3809
3809
  jsTip: 'js加载成功',
3810
3810
  });
3811
3811
  };
3812
3812
  _sgmEle.onerror = function () {
3813
3813
  reject({
3814
3814
  ...jsInfo,
3815
3815
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3816
3816
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
3817
3817
  });
3818
3818
  };
3819
3819
  const dataAttrList = ['timeout', 'fileName', 'env'];
3820
3820
  const getJsInfoKeyList = Object.keys(jsInfo);
3821
3821
  getJsInfoKeyList.forEach((key) => {
3822
3822
  if (key === 'async') {
3823
3823
  _sgmEle.async = jsInfo[key];
3824
3824
  } else if (key === 'crossOrigin') {
3825
3825
  _sgmEle.crossOrigin = jsInfo[key];
3826
3826
  } else if (key === 'src') {
3827
3827
  _sgmEle.src = `${jsInfo[key]}`;
3828
3828
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
3829
3829
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
3830
3830
  } else {
3831
3831
  _sgmEle.setAttribute(key, jsInfo[key]);
3832
3832
  }
3833
3833
  });
3834
3834
  document.head.appendChild(_sgmEle);
3835
3835
  } else {
3836
3836
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
3837
3837
  resolve({
3838
3838
  ...jsInfo,
3839
3839
  jsTip: 'js本身已存在页面中',
3840
3840
  });
3841
3841
  }
3842
3842
  } else {
3843
3843
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
3844
3844
  }
3845
3845
  }
3846
3846
 
3847
3847
  loadItemSdkPromise(jsInfo = {}) {
3848
3848
  if (jsInfo?.src) {
3849
3849
  const getInitLoadType =
3850
3850
  isJdApp && jsInfo?.initJdAppLoadType
3851
3851
  ? jsInfo?.initJdAppLoadType
3852
3852
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
3853
3853
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
3854
3854
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
3855
3855
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
3856
3856
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
3857
3857
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
3858
3858
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3859
3859
  try {
3860
3860
  const jsXhrRequest = new XMLHttpRequest();
3861
3861
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
3862
3862
  const jsUrl = `${jsInfo?.src}`;
3863
3863
  jsXhrRequest.open('GET', jsUrl, true);
3864
3864
  jsXhrRequest.onreadystatechange = () => {
3865
3865
  if (jsXhrRequest.readyState === 4) {
3866
3866
  const getReqStatus = jsXhrRequest.status;
3867
3867
  const statusText = jsXhrRequest.statusText;
3868
3868
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
3869
3869
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
3870
3870
  if (getInsetHeadState) {
3871
3871
  this.loadScriptEle(jsInfo, resolve, reject);
3872
3872
  } else {
3873
3873
  resolve({
3874
3874
  ...jsInfo,
3875
3875
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
3876
3876
  });
3877
3877
  }
3878
3878
  getReqStatus !== 200 &&
3879
3879
  draBusinessCustomReport({
3880
3880
  eventName: 'business',
3881
3881
  errorName: 'js_load_special_code',
3882
3882
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
3883
3883
  extraData: JSON.stringify({
3884
3884
  msg: '当前js加载成功,状态非200,特殊上报观察',
3885
3885
  jsReqState: getReqStatus,
3886
3886
  env: getSgmCustomCode('js_load_special_code'),
3887
3887
  data: jsInfo,
3888
3888
  }),
3889
3889
  });
3890
3890
  } else {
3891
3891
  const getRes = {
3892
3892
  ...jsInfo,
3893
3893
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3894
3894
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
3895
3895
  jsReqState: getReqStatus,
3896
3896
  };
3897
3897
  console.log('当前js请求状态异常,具体信息见', getRes);
3898
3898
  reject(getRes);
3899
3899
  }
3900
3900
  }
3901
3901
  };
3902
3902
  jsXhrRequest.onerror = () => {
3903
3903
  const getRes = {
3904
3904
  ...jsInfo,
3905
3905
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3906
3906
  jsReqError: '请求错误',
3907
3907
  };
3908
3908
  console.log('当前js请求错误', getRes);
3909
3909
  jsXhrRequest.abort();
3910
3910
  reject(getRes);
3911
3911
  };
3912
3912
  jsXhrRequest.ontimeout = () => {
3913
3913
  const getRes = {
3914
3914
  ...jsInfo,
3915
3915
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3916
3916
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
3917
3917
  jsReqState: jsXhrRequest.status,
3918
3918
  };
3919
3919
  console.log('当前js请求超时异常', getRes);
3920
3920
  jsXhrRequest.abort();
3921
3921
  reject(getRes);
3922
3922
  };
3923
3923
  jsXhrRequest.send();
3924
3924
  } catch (e) {
3925
3925
  console.log('执行js请求异常', e);
3926
3926
  reject({
3927
3927
  ...jsInfo,
3928
3928
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3929
3929
  jsReqError: '未知异常',
3930
3930
  error: e,
3931
3931
  });
3932
3932
  }
3933
3933
  });
3934
3934
  } else {
3935
3935
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
3936
3936
  return this.loadScriptEle(jsInfo, resolve, reject);
3937
3937
  });
3938
3938
  }
3939
3939
  }
3940
3940
  return this.loadJsSdkListCachePromise[getFileKeyName];
3941
3941
  } else {
3942
3942
  return Promise.resolve({
3943
3943
  ...jsInfo,
3944
3944
  jsTip: 'js加载方式设置为不加载,当前不做处理',
3945
3945
  });
3946
3946
  }
3947
3947
  } else {
3948
3948
  return Promise.reject(jsInfo);
3949
3949
  }
3950
3950
  }
3951
3951
 
3952
3952
  createLanguagePromise() {
3953
3953
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
3954
3954
  if (!this.languageCacheProimse) {
3955
3955
  this.languageCacheProimse = new Promise((resolve, reject) => {
3956
3956
  const { fileName, prefixUrl } = getLanguageConfig;
3957
3957
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
3958
3958
  const dealLanguageFile = () => {
3959
3959
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
3960
3960
  .then((res) => {
3961
3961
  if (res && res?.data) {
3962
3962
  this.languageJsonData = res.data;
3963
3963
 
3964
3964
  setTimeout(() => {
3965
3965
  const getOtherLanguageList = languageTypeList.filter(
3966
3966
  (item) => item !== languageNowType,
3967
3967
  );
3968
3968
  getOtherLanguageList.length > 0 &&
3969
3969
  getOtherLanguageList.map((languageTypeKey) => {
3970
3970
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
3971
3971
  });
3972
3972
  }, 3000);
3973
3973
  resolve(res);
3974
3974
  } else {
3975
3975
  reject(res);
3976
3976
  }
3977
3977
  })
3978
3978
  .catch((err) => {
3979
3979
  reject(err);
3980
3980
  });
3981
3981
  };
3982
3982
  if (fileName && prefixUrl) {
3983
3983
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
3984
3984
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
3985
3985
  if (getLocalLangRes) {
3986
3986
  try {
3987
3987
  const getLocalLangJsonData =
3988
3988
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
3989
3989
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
3990
3990
  if (getLocalLangJsonData?.fileName === fileName) {
3991
3991
  const geThisLangData = getLocalLangJsonData.data;
3992
3992
  this.languageJsonData = geThisLangData;
3993
3993
  return resolve({
3994
3994
  ...getLanguageConfig,
3995
3995
  languageNowType,
3996
3996
  data: geThisLangData,
3997
3997
  });
3998
3998
  } else {
3999
3999
  dealLanguageFile();
4000
4000
  }
4001
4001
  } else {
4002
4002
  dealLanguageFile();
4003
4003
  }
4004
4004
  } catch (e) {
4005
4005
  return reject({
4006
4006
  languageNowType,
4007
4007
  msg: '转换错误',
4008
4008
  ...getLanguageConfig,
4009
4009
  });
4010
4010
  }
4011
4011
  } else {
4012
4012
  dealLanguageFile();
4013
4013
  }
4014
4014
  } else {
4015
4015
  return reject({
4016
4016
  languageNowType,
4017
4017
  msg: '文件对象下发异常',
4018
4018
  ...getLanguageConfig,
4019
4019
  });
4020
4020
  }
4021
4021
  });
4022
4022
  }
4023
4023
  return this.languageCacheProimse;
4024
4024
  }
4025
4025
 
4026
4026
  getLanguageFilePromise(info, languageTypeKey) {
4027
4027
  const { fileName, prefixUrl, timeout } = info || {};
4028
4028
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
4029
4029
  return new Promise((resolve, reject) => {
4030
4030
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
4031
4031
  try {
4032
4032
  const langXhrRequest = new XMLHttpRequest();
4033
4033
  langXhrRequest.timeout = timeout || 2000;
4034
4034
  langXhrRequest.open('GET', getUrl, true);
4035
4035
  langXhrRequest.responseType = 'json';
4036
4036
  langXhrRequest.onreadystatechange = () => {
4037
4037
  if (langXhrRequest.readyState === 4) {
4038
4038
  const getReqStatus = langXhrRequest.status;
4039
4039
  const statusText = langXhrRequest.statusText;
4040
4040
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4041
4041
  const getData = langXhrRequest?.response || false;
4042
4042
  if (getData) {
4043
4043
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
4044
4044
  fileName,
4045
4045
  data: getData,
4046
4046
  });
4047
4047
  resolve({
4048
4048
  ...info,
4049
4049
  languageTypeKey,
4050
4050
  data: getData,
4051
4051
  });
4052
4052
  } else {
4053
4053
  reject({
4054
4054
  ...info,
4055
4055
  languageTypeKey,
4056
4056
  msg: '数据获取异常',
4057
4057
  });
4058
4058
  }
4059
4059
  } else {
4060
4060
  const getRes = {
4061
4061
  ...info,
4062
4062
  languageTypeKey,
4063
4063
  env: getSgmCustomCode(langLoadErrorSgmCode),
4064
4064
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4065
4065
  };
4066
4066
  console.log('当前lang请求状态异常,具体信息见', getRes);
4067
4067
  reject(getRes);
4068
4068
  }
4069
4069
  }
4070
4070
  };
4071
4071
  langXhrRequest.onerror = () => {
4072
4072
  const getRes = {
4073
4073
  ...info,
4074
4074
  env: getSgmCustomCode(langLoadErrorSgmCode),
4075
4075
  msg: '请求错误',
4076
4076
  };
4077
4077
  console.log('当前lang请求错误', getRes);
4078
4078
  langXhrRequest.abort();
4079
4079
  reject(getRes);
4080
4080
  };
4081
4081
  langXhrRequest.ontimeout = () => {
4082
4082
  const getRes = {
4083
4083
  ...info,
4084
4084
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
4085
4085
  };
4086
4086
  console.log('执行lang多语言请求超时异常', getRes);
4087
4087
  langXhrRequest.abort();
4088
4088
  reject(getRes);
4089
4089
  };
4090
4090
  langXhrRequest.send();
4091
4091
  } catch (e) {
4092
4092
  console.log('执行lang多语言请求异常', e);
4093
4093
  reject({
4094
4094
  ...info,
4095
4095
  env: getSgmCustomCode(langLoadErrorSgmCode),
4096
4096
  msg: '未知异常',
4097
4097
  error: e,
4098
4098
  });
4099
4099
  }
4100
4100
  });
4101
4101
  }