@conecli/cone-render 0.10.1-shop3.96 → 0.10.1-shop3.97

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