@conecli/cone-render 0.10.1-shop3.115 → 0.10.1-shop3.116

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