@conecli/cone-render 0.10.1-shop-beta.38 → 0.10.1-shop-beta.40

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
  initAccessibility();
2419
2419
  });
2420
2420
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
2421
2421
  }
2422
2422
  }
2423
2423
  _getConfig(opt) {
2424
2424
  return Object.assign({}, DefaultConfig, opt);
2425
2425
  }
2426
2426
  _init() {
2427
2427
  this.loadOtherSdk();
2428
2428
  this.checkJdAddCartState();
2429
2429
  this.checkPageDomHeightToReport();
2430
2430
  }
2431
2431
  checkPageDomHeightToReport() {
2432
2432
  Taro.nextTick(() => {
2433
2433
  setTimeout(() => {
2434
2434
  const getReportData = {
2435
2435
  containerFloorLisHeight: -1,
2436
2436
  appHeight: -1,
2437
2437
  };
2438
2438
  const getAppEle = document.getElementById('app');
2439
2439
  const getFloorContainerEle = document.getElementById('J_shopContainerFloorList');
2440
2440
  const getNetWorkEle = document.querySelector('.J_shopNetwork');
2441
2441
  getFloorContainerEle &&
2442
2442
  (getReportData.containerFloorLisHeight =
2443
2443
  getFloorContainerEle?.getBoundingClientRect()?.height ?? -1);
2444
2444
  getAppEle && (getReportData.appHeight = getAppEle?.getBoundingClientRect()?.height ?? -1);
2445
2445
  const getMaxHeight = Math.max(
2446
2446
  getReportData.appHeight,
2447
2447
  getReportData.containerFloorLisHeight,
2448
2448
  );
2449
2449
  if (!getNetWorkEle && getMaxHeight > -1 && getMaxHeight < 80) {
2450
2450
  draBusinessCustomReport({
2451
2451
  eventName: 'business',
2452
2452
  errorName: 'pageDomHeightErrorCheck',
2453
2453
  errorMessage:
2454
2454
  '当前页面总高度异常小于80px,没有兜底network组件,可能空窗,请检查核对详细信息',
2455
2455
  extraData: JSON.stringify({
2456
2456
  data: getReportData,
2457
2457
  isJdApp,
2458
2458
  }),
2459
2459
  });
2460
2460
  }
2461
2461
  }, window?.shopGlobalSwitch?.checkPageDomHeightTime || 4000);
2462
2462
  });
2463
2463
  }
2464
2464
 
2465
2465
  checkJdAddCartState() {
2466
2466
  const getJdAppForNotMainRemoveCartUaList = isJdApp
2467
2467
  ? window?.PAGE_DATA?.businessData?.jdAppForNotMainRemoveCartUaList
2468
2468
  : undefined;
2469
2469
  if (
2470
2470
  getJdAppForNotMainRemoveCartUaList &&
2471
2471
  Array.isArray(getJdAppForNotMainRemoveCartUaList) &&
2472
2472
  getJdAppForNotMainRemoveCartUaList.length > 0
2473
2473
  ) {
2474
2474
  const setFilterReg = new RegExp(getJdAppForNotMainRemoveCartUaList.join('|'), 'i');
2475
2475
  this.info.baseAddCartSwitch = !setFilterReg.test(window.navigator.userAgent);
2476
2476
  }
2477
2477
  }
2478
2478
 
2479
2479
  loadApiSafeSteadyReayPromise() {
2480
2480
  if (!this.loadJsApiRequestStatePromise) {
2481
2481
  this.loadJsApiRequestStatePromise = this.loadOtherSdk(LoadJsInitTriggerType.API_REQUEST);
2482
2482
  }
2483
2483
  return this.loadJsApiRequestStatePromise;
2484
2484
  }
2485
2485
 
2486
2486
  loadH5tagReayPromise() {
2487
2487
  if (!this.loadJsH5tagStatePromise) {
2488
2488
  const h5TagJs = this.loadJsSdkList.find((e) => e.fileName === 'h5TagJs');
2489
2489
  this.loadJsH5tagStatePromise = !h5TagJs
2490
2490
  ? Promise.resolve(true)
2491
2491
  : this.loadOtherSdk(LoadJsInitTriggerType.NOW, [
2492
2492
  Object.assign({}, h5TagJs, {
2493
2493
  initTriggerType: LoadJsInitTriggerType.NOW,
2494
2494
  }),
2495
2495
  ]);
2496
2496
  }
2497
2497
  return this.loadJsH5tagStatePromise;
2498
2498
  }
2499
2499
 
2500
2500
  jmfeReayPromise(): Promise<any> {
2501
2501
  if (isJdApp) {
2502
2502
  if (this.jmfeRegisterState) {
2503
2503
  return Promise.resolve(true);
2504
2504
  } else {
2505
2505
  !this.jmfeRegisterStatePromise &&
2506
2506
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
2507
2507
  ready('jmfe', 3000)
2508
2508
  .then(() => {
2509
2509
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
2510
2510
  this.jmfeRegisterState = true;
2511
2511
  resolve(true);
2512
2512
  console.log(
2513
2513
  '松果app内初始化注册jmfe认证完成',
2514
2514
  window?.jmfe,
2515
2515
  '当前版本',
2516
2516
  window?.jmfe?.VERSION,
2517
2517
  );
2518
2518
  })
2519
2519
  .catch((err) => {
2520
2520
  console.error('jmfe ready error', err);
2521
2521
  reject(false);
2522
2522
  });
2523
2523
  }));
2524
2524
  return this.jmfeRegisterStatePromise;
2525
2525
  }
2526
2526
  } else {
2527
2527
  return Promise.reject(false);
2528
2528
  }
2529
2529
  }
2530
2530
 
2531
2531
  jdWorkerReadyPromise(): Promise<any> {
2532
2532
  if (isJdApp) {
2533
2533
  if (this.businessWorkerReady) {
2534
2534
  return Promise.resolve(true);
2535
2535
  } else {
2536
2536
  const getOpenJdWorkerState =
2537
2537
  window?.PAGE_DATA?.businessData?.businessWorkerVersion &&
2538
2538
  versionCompare(
2539
2539
  jdAppVersionStr,
2540
2540
  window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10',
2541
2541
  ) >= 0;
2542
2542
  !this.businessWorkerReadyPromise &&
2543
2543
  (this.businessWorkerReadyPromise = getOpenJdWorkerState
2544
2544
  ? new Promise((resolve) => {
2545
2545
  this.jmfeReayPromise()
2546
2546
  .then(() => {
2547
2547
  window.jmfe
2548
2548
  .onMsgForWorker(
2549
2549
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
2550
2550
  (workerData) => {
2551
2551
  console.log('收到业务jd worker消息结果:', workerData);
2552
2552
  if (workerData && workerData?.workerType) {
2553
2553
  const getWorkerType = workerData?.workerType;
2554
2554
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
2555
2555
  this.workerPreRequestData.set(workerData?.functionId, workerData);
2556
2556
  Taro.eventCenter.trigger(getWorkerType, workerData);
2557
2557
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
2558
2558
  Taro.eventCenter.trigger(getWorkerType, workerData);
2559
2559
  }
2560
2560
  }
2561
2561
  },
2562
2562
  )
2563
2563
  .then(() => {
2564
2564
  console.log('jd worker注册成功');
2565
2565
  this.businessWorkerReady = true;
2566
2566
  resolve(true);
2567
2567
  })
2568
2568
  .catch((error) => {
2569
2569
  console.log(
2570
2570
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
2571
2571
  error,
2572
2572
  );
2573
2573
  draBusinessCustomReport({
2574
2574
  eventName: 'business',
2575
2575
  errorName: 'jmfe_onMsgForWorker_error',
2576
2576
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
2577
2577
  extraData: JSON.stringify({
2578
2578
  businessWorkerVersion:
2579
2579
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
2580
2580
  error,
2581
2581
  }),
2582
2582
  });
2583
2583
  resolve(false);
2584
2584
  });
2585
2585
  })
2586
2586
  .catch((err) => {
2587
2587
  console.log('jmfe超时异常,worker注册失败', err);
2588
2588
  resolve(false);
2589
2589
  });
2590
2590
  })
2591
2591
  : Promise.resolve(false));
2592
2592
  }
2593
2593
  return this.businessWorkerReadyPromise;
2594
2594
  } else {
2595
2595
  return Promise.resolve(false);
2596
2596
  }
2597
2597
  }
2598
2598
 
2599
2599
  taskTimeoutPromise(callBack, timeout = 2000) {
2600
2600
  return new Promise((resolve) => {
2601
2601
  setTimeout(
2602
2602
  () => {
2603
2603
  const getCallBackRes = typeof callBack === 'function' && callBack();
2604
2604
  return resolve(getCallBackRes || false);
2605
2605
  },
2606
2606
  isInJdAppH5DebugMode ? 0 : timeout,
2607
2607
  );
2608
2608
  });
2609
2609
  }
2610
2610
  _getJdPadMinWidthForListen() {
2611
2611
  return (
2612
2612
  isJdApp &&
2613
2613
  Math.min(window.screen.width, window.screen.height) >
2614
2614
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
2615
2615
  );
2616
2616
  }
2617
2617
 
2618
2618
  getJdScreenSizeInfoPromise() {
2619
2619
  !this.jdScreenSizeInfoPromise &&
2620
2620
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
2621
2621
  const getThisTime = Date.now();
2622
2622
  this.jmfeReayPromise().then(() => {
2623
2623
  return Promise.race([
2624
2624
  window.jmfe.getScreenSize(),
2625
2625
  this.taskTimeoutPromise(() => {
2626
2626
  return {
2627
2627
  status: '-10',
2628
2628
  msg: '获取大屏信息2s超时',
2629
2629
  };
2630
2630
  }),
2631
2631
  ])
2632
2632
  .then((res) => {
2633
2633
  console.warn('===获取app大屏信息====', res);
2634
2634
  const { status, data } = res;
2635
2635
  if (status === '0' && data) {
2636
2636
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
2637
2637
  const getPageInfo = dealNativePixelToCssPixel({
2638
2638
  pageWidth,
2639
2639
  pageHeight,
2640
2640
  });
2641
2641
  this.info.sysInfo.jdScreenSizeType = sizeType;
2642
2642
  const getUseTime = Date.now() - getThisTime;
2643
2643
  console.warn(
2644
2644
  '===计算是否是app大屏信息,需满足宽度最新720===',
2645
2645
  getPageInfo,
2646
2646
  '原始数据',
2647
2647
  data,
2648
2648
  '是否是横屏isLandscape为1=',
2649
2649
  isLandscape,
2650
2650
  '用时',
2651
2651
  getUseTime,
2652
2652
  );
2653
2653
  if (getPageInfo?.pageWidth > 0) {
2654
2654
  this.rootEleInitWidth = getPageInfo?.pageWidth;
2655
2655
  draBusinessCustomReport({
2656
2656
  eventName: 'UIInteract',
2657
2657
  errorName: 'rootEle_width_getJdScreenSizeInfo',
2658
2658
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
2659
2659
  extraData: JSON.stringify({
2660
2660
  isJdApp,
2661
2661
  getPageInfo,
2662
2662
  originData: res,
2663
2663
  }),
2664
2664
  });
2665
2665
  resolve(getPageInfo);
2666
2666
  } else {
2667
2667
  resolve({
2668
2668
  pageWidth: 0,
2669
2669
  pageHeight: 0,
2670
2670
  msg: '转换异常',
2671
2671
  });
2672
2672
  }
2673
2673
  } else {
2674
2674
  resolve({
2675
2675
  pageWidth: 0,
2676
2676
  pageHeight: 0,
2677
2677
  msg: '获取大屏信息异常或者超时',
2678
2678
  });
2679
2679
  }
2680
2680
  })
2681
2681
  .catch((err) => {
2682
2682
  console.log('获取大屏信息异常', err);
2683
2683
  resolve({
2684
2684
  pageWidth: 0,
2685
2685
  pageHeight: 0,
2686
2686
  msg: '获取大屏信息异常',
2687
2687
  });
2688
2688
  });
2689
2689
  });
2690
2690
  }));
2691
2691
  return this.jdScreenSizeInfoPromise;
2692
2692
  }
2693
2693
 
2694
2694
  listenJdTabletScreenChange() {
2695
2695
  this.jmfeReayPromise().then(() => {
2696
2696
  try {
2697
2697
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
2698
2698
  window.jmfe.listenDeviceScreenChange((event) => {
2699
2699
  console.log(
2700
2700
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
2701
2701
  event,
2702
2702
  '通过前端判断是不是横屏',
2703
2703
  window.matchMedia('(orientation: landscape)')?.matches,
2704
2704
  );
2705
2705
  const { orientation } = event?.data;
2706
2706
  if (orientation) {
2707
2707
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
2708
2708
  Taro.eventCenter.trigger(
2709
2709
  TaroEventType.TABLE_SCREEN_CHANGE,
2710
2710
  this.info.sysInfo.isJdTabletLandscape,
2711
2711
  orientation,
2712
2712
  );
2713
2713
  }
2714
2714
  });
2715
2715
  } catch (error) {
2716
2716
  console.log('listenScreenChange的打印error:', error);
2717
2717
  }
2718
2718
  });
2719
2719
  }
2720
2720
 
2721
2721
  updateBusinessDomainAndApi(domain, api) {
2722
2722
  }
2723
2723
 
2724
2724
  formatNativeScreenPageData(action) {
2725
2725
  let getChangePageInfo: any = null;
2726
2726
  try {
2727
2727
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
2728
2728
  JSON.stringify({
2729
2729
  plugin: 'JDHybridScreenPlugin',
2730
2730
  action,
2731
2731
  sync: '1',
2732
2732
  }),
2733
2733
  );
2734
2734
  const getChangePageInfoData =
2735
2735
  typeof getNativeScreenPageInfoStr === 'string'
2736
2736
  ? JSON.parse(getNativeScreenPageInfoStr)
2737
2737
  : null;
2738
2738
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
2739
2739
  const { code, data } = getChangePageInfoData;
2740
2740
  getChangePageInfo = code && code === '0' ? data : null;
2741
2741
  }
2742
2742
  } catch (e) {
2743
2743
  console.log('JDHybridScreenPlugin转换异常', e);
2744
2744
  }
2745
2745
  return getChangePageInfo;
2746
2746
  }
2747
2747
 
2748
2748
  isAndroidFoldScreen() {
2749
2749
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
2750
2750
  }
2751
2751
 
2752
2752
  isHarmonyFoldScreenPromise(): Promise<{
2753
2753
  isFoldScreen: boolean;
2754
2754
  getFoldDisplayMode?: number;
2755
2755
  }> {
2756
2756
  return new Promise((resolve) => {
2757
2757
  this.jmfeReayPromise()
2758
2758
  .then(() => {
2759
2759
  if (window.jmfe?.callNative) {
2760
2760
  Promise.all([
2761
2761
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
2762
2762
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
2763
2763
  ])
2764
2764
  .then((res) => {
2765
2765
  resolve({
2766
2766
  isFoldScreen: res?.[0]?.data === '1',
2767
2767
  getFoldDisplayMode: res?.[1]?.data,
2768
2768
  });
2769
2769
  })
2770
2770
  .catch(() => {
2771
2771
  resolve({
2772
2772
  isFoldScreen: false,
2773
2773
  getFoldDisplayMode: undefined,
2774
2774
  });
2775
2775
  });
2776
2776
  } else {
2777
2777
  resolve({
2778
2778
  isFoldScreen: false,
2779
2779
  getFoldDisplayMode: undefined,
2780
2780
  });
2781
2781
  }
2782
2782
  })
2783
2783
  .catch(() => {
2784
2784
  resolve({
2785
2785
  isFoldScreen: false,
2786
2786
  getFoldDisplayMode: undefined,
2787
2787
  });
2788
2788
  });
2789
2789
  });
2790
2790
  }
2791
2791
 
2792
2792
  getJdAndroidPageChangeScreenInfo() {
2793
2793
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
2794
2794
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
2795
2795
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
2796
2796
  pageWidth: getPageScreenInfo.pageWidth,
2797
2797
  pageHeight: getPageScreenInfo.pageHeight,
2798
2798
  });
2799
2799
  getPageScreenInfo.pageWidth = pageWidth;
2800
2800
  getPageScreenInfo.pageHeight = pageHeight;
2801
2801
  }
2802
2802
  return getPageScreenInfo;
2803
2803
  }
2804
2804
 
2805
2805
  getRootEleWindowWidthInfo() {
2806
2806
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
2807
2807
  const getWindowWidth = window.innerWidth;
2808
2808
  const getScreenWidth = window.screen.width;
2809
2809
  return {
2810
2810
  getRootEleWidth,
2811
2811
  getWindowWidth,
2812
2812
  getScreenWidth,
2813
2813
  };
2814
2814
  }
2815
2815
 
2816
2816
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
2817
2817
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
2818
2818
  console.log(
2819
2819
  '当前获取根元素的宽度',
2820
2820
  getRootEleWidth,
2821
2821
  'getWindowWidth',
2822
2822
  getWindowWidth,
2823
2823
  'getScreenWidth',
2824
2824
  getScreenWidth,
2825
2825
  );
2826
2826
  const getLastWidth =
2827
2827
  getRootEleWidth > 0
2828
2828
  ? Math.round(getRootEleWidth)
2829
2829
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
2830
2830
  console.warn(
2831
2831
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2832
2832
  );
2833
2833
  timeout > 0 &&
2834
2834
  draBusinessCustomReport({
2835
2835
  eventName: 'UIInteract',
2836
2836
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
2837
2837
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
2838
2838
  extraData: JSON.stringify({
2839
2839
  isJdApp,
2840
2840
  getRootEleWidth,
2841
2841
  getWindowWidth,
2842
2842
  getScreenWidth,
2843
2843
  ...reportParam,
2844
2844
  }),
2845
2845
  });
2846
2846
  return getLastWidth;
2847
2847
  }
2848
2848
 
2849
2849
  getPadWindowRootEleWidthPromise() {
2850
2850
  if (this.rootEleInitWidth > 0) {
2851
2851
  return Promise.resolve(this.rootEleInitWidth);
2852
2852
  } else {
2853
2853
  !this.rootEleWidthRegisterPromise &&
2854
2854
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
2855
2855
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
2856
2856
  if (getRootEleInitWidth > 0) {
2857
2857
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
2858
2858
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
2859
2859
  resolve(this.rootEleInitWidth);
2860
2860
  } else {
2861
2861
  const timerPromise = () => {
2862
2862
  return new Promise((resolve2) => {
2863
2863
  window.setTimeout(() => {
2864
2864
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
2865
2865
  this.getRootEleWindowWidthInfo();
2866
2866
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
2867
2867
  console.warn(
2868
2868
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
2869
2869
  );
2870
2870
  draBusinessCustomReport({
2871
2871
  eventName: 'UIInteract',
2872
2872
  errorName: 'rootEle_width_200_timeout_info',
2873
2873
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
2874
2874
  extraData: JSON.stringify({
2875
2875
  isJdApp,
2876
2876
  getRootEleWidth,
2877
2877
  getWindowWidth,
2878
2878
  getScreenWidth,
2879
2879
  }),
2880
2880
  });
2881
2881
  const getRes =
2882
2882
  getRootEleWidth > 0 && getWindowWidth > 0
2883
2883
  ? Math.min(getRootEleWidth, getWindowWidth)
2884
2884
  : Math.max(getRootEleWidth, getWindowWidth);
2885
2885
  resolve2({
2886
2886
  pageWidth: Math.round(getRes),
2887
2887
  });
2888
2888
  }
2889
2889
  }, 200);
2890
2890
  });
2891
2891
  };
2892
2892
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
2893
2893
  const { pageWidth } = res;
2894
2894
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
2895
2895
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
2896
2896
  });
2897
2897
  }
2898
2898
  }));
2899
2899
  return this.rootEleWidthRegisterPromise;
2900
2900
  }
2901
2901
  }
2902
2902
 
2903
2903
  async getSystemInfo(params) {
2904
2904
  const getParams = Object.assign({}, params || {});
2905
2905
  if (this.rootEleInitWidth > 0) {
2906
2906
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
2907
2907
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
2908
2908
  } else {
2909
2909
  if (this._getJdPadMinWidthForListen()) {
2910
2910
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
2911
2911
  getParams['replaceSystemWidth'] = true;
2912
2912
  }
2913
2913
  }
2914
2914
  isJdApp && this.createLanguagePromise();
2915
2915
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
2916
2916
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
2917
2917
  let _isfoldScreen = false;
2918
2918
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
2919
2919
  console.info(
2920
2920
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
2921
2921
  getStorageData,
2922
2922
  '通过缓存值第一次判断是否是折叠屏',
2923
2923
  getStorageData === 'true',
2924
2924
  );
2925
2925
  if (!getStorageData) {
2926
2926
  _isfoldScreen = this.isAndroidFoldScreen();
2927
2927
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
2928
2928
  } else {
2929
2929
  _isfoldScreen = getStorageData === 'true';
2930
2930
  }
2931
2931
  if (_isfoldScreen) {
2932
2932
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
2933
2933
  if (getJdAndroidPageInfo) {
2934
2934
  info = getSystemInfos(getJdAndroidPageInfo);
2935
2935
  console.warn(
2936
2936
  '当前为松果安卓折叠屏app,获取折叠屏信息',
2937
2937
  getJdAndroidPageInfo,
2938
2938
  '获取转换后的系统信息',
2939
2939
  info,
2940
2940
  );
2941
2941
  draBusinessCustomReport({
2942
2942
  eventName: 'UIInteract',
2943
2943
  errorName: 'android_jdapp_foldScreen_info',
2944
2944
  errorMessage:
2945
2945
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
2946
2946
  extraData: JSON.stringify({
2947
2947
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
2948
2948
  androidPageInfo: getJdAndroidPageInfo,
2949
2949
  jdAppVersionStr,
2950
2950
  taroSysInfo: info,
2951
2951
  }),
2952
2952
  });
2953
2953
  }
2954
2954
  }
2955
2955
  }
2956
2956
  if (isJdApp) {
2957
2957
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
2958
2958
  }
2959
2959
  this.info.sysInfo = {
2960
2960
  actualNavBarHeight: 0,
2961
2961
  ...this.info.sysInfo,
2962
2962
  ...info,
2963
2963
  safeContentHeight: info?.screenHeight,
2964
2964
  headerHeight: 0,
2965
2965
  tabBarHeight: 0,
2966
2966
  languageType: languageNowType,
2967
2967
  };
2968
2968
  if (isJdApp || isH5AndJingGouMini) {
2969
2969
  this.getAddressCachePromise();
2970
2970
  this.getLbsAddressCachePromise();
2971
2971
  }
2972
2972
  if (isJdApp) {
2973
2973
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
2974
2974
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
2975
2975
  this.getJdAppBaseInfo();
2976
2976
  this.getElderModePromise();
2977
2977
  this.getJDAppearanceStatePromise();
2978
2978
  this.createJdAndroidRquestEventForTouchStart();
2979
2979
  }
2980
2980
  this.getWifiVideoAutoPlayAsync();
2981
2981
  this.getMPaasConfigAsync();
2982
2982
  this.getNetWorkType();
2983
2983
  }
2984
2984
 
2985
2985
  getElderModePromise() {
2986
2986
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
2987
2987
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
2988
2988
  } else {
2989
2989
  if (isJdAndAndroidDevice) {
2990
2990
  this.info.sysInfo.jdAppModeType = '0';
2991
2991
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
2992
2992
  } else {
2993
2993
  return Promise.race([
2994
2994
  this.taskTimeoutPromise(() => {
2995
2995
  this.info.sysInfo.jdAppModeType = '0';
2996
2996
  return this.info.sysInfo.jdAppModeType;
2997
2997
  }),
2998
2998
  new Promise((resolve) => {
2999
2999
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
3000
3000
  if (!window[getCallBackName]) {
3001
3001
  window[getCallBackName] = (res) => {
3002
3002
  try {
3003
3003
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3004
3004
  const { status, data, msg } = getResJson;
3005
3005
  console.log(`获取松果app展示模式成功,返回结果${data}`);
3006
3006
  if (status === '0') {
3007
3007
  this.info.sysInfo.jdAppModeType = data;
3008
3008
  resolve(data);
3009
3009
  } else {
3010
3010
  resolve('0');
3011
3011
  }
3012
3012
  } catch (e) {
3013
3013
  resolve('0');
3014
3014
  }
3015
3015
  window[getCallBackName] = null;
3016
3016
  };
3017
3017
  }
3018
3018
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
3019
3019
  method: 'callSyncRouterModuleWithParams',
3020
3020
  params: JSON.stringify({
3021
3021
  routerURL: 'router://JDBModeModule/getCurrentMode',
3022
3022
  routerParam: {},
3023
3023
  callBackName: `window.${getCallBackName}`,
3024
3024
  callBackId: `${getCallBackName}Ios`,
3025
3025
  }),
3026
3026
  });
3027
3027
  }),
3028
3028
  ]);
3029
3029
  }
3030
3030
  }
3031
3031
  }
3032
3032
  getAPPUseStraightCorner() {
3033
3033
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
3034
3034
  const params = {
3035
3035
  routerURL,
3036
3036
  routerParam: {},
3037
3037
  jdRouter: '1',
3038
3038
  };
3039
3039
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
3040
3040
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
3041
3041
  } else {
3042
3042
  return this.jmfeReayPromise()
3043
3043
  .then(() => {
3044
3044
  if (isJdAndHarmonyDevice || !isJdApp) {
3045
3045
  console.log('not APP or is Harmony');
3046
3046
  return Promise.resolve(false);
3047
3047
  }
3048
3048
  console.log('jmfe setShareInfo', params);
3049
3049
  return Promise.race([
3050
3050
  window.jmfe.callRouter(params),
3051
3051
  this.taskTimeoutPromise(() => {
3052
3052
  return false;
3053
3053
  }),
3054
3054
  ]).then(({ status, data }) => {
3055
3055
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
3056
3056
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
3057
3057
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
3058
3058
  return Promise.resolve(status === '0' && Number(data) === 1);
3059
3059
  });
3060
3060
  })
3061
3061
  .catch((e) => {
3062
3062
  console.log('jmfe error', e);
3063
3063
  return Promise.resolve(false);
3064
3064
  });
3065
3065
  }
3066
3066
  }
3067
3067
 
3068
3068
  getJDAppearanceStatePromise() {
3069
3069
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
3070
3070
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
3071
3071
  } else {
3072
3072
  return Promise.race([
3073
3073
  this.taskTimeoutPromise(() => {
3074
3074
  this.info.sysInfo.jdAppearanceState = '0';
3075
3075
  return this.info.sysInfo.jdAppearanceState;
3076
3076
  }),
3077
3077
  new Promise((resolve) => {
3078
3078
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
3079
3079
  if (!window[getCallBackName]) {
3080
3080
  window[getCallBackName] = (res) => {
3081
3081
  try {
3082
3082
  console.log('getJDAppearanceStatePromise', res);
3083
3083
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3084
3084
  const { status, data, msg } = getResJson;
3085
3085
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
3086
3086
  if (status === '0') {
3087
3087
  this.info.sysInfo.jdAppearanceState = data;
3088
3088
  resolve(data);
3089
3089
  } else {
3090
3090
  resolve('0');
3091
3091
  }
3092
3092
  } catch (e) {
3093
3093
  resolve('0');
3094
3094
  }
3095
3095
  window[getCallBackName] = null;
3096
3096
  };
3097
3097
  }
3098
3098
  if (isAndroidDevice) {
3099
3099
  const jsonString = JSON.stringify({
3100
3100
  callBackName: `window.${getCallBackName}`,
3101
3101
  });
3102
3102
  console.log('window.JDAppearance', window?.JDAppearance);
3103
3103
  window?.JDAppearance &&
3104
3104
  window?.JDAppearance?.getUiState &&
3105
3105
  window.JDAppearance.getUiState(jsonString);
3106
3106
  } else {
3107
3107
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
3108
3108
  method: 'callSyncRouterModuleWithParams',
3109
3109
  params: JSON.stringify({
3110
3110
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
3111
3111
  routerParam: {},
3112
3112
  callBackName: `window.${getCallBackName}`,
3113
3113
  callBackId: `${getCallBackName}Ios`,
3114
3114
  }),
3115
3115
  });
3116
3116
  }
3117
3117
  }),
3118
3118
  ]);
3119
3119
  }
3120
3120
  }
3121
3121
 
3122
3122
  createJdAndroidRquestEventForTouchStart() {
3123
3123
  if (isJdAndAndroidDevice && window?.JdAndroid) {
3124
3124
  const rootEleNode = document.querySelector('body');
3125
3125
  if (rootEleNode) {
3126
3126
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
3127
3127
  }
3128
3128
  }
3129
3129
  }
3130
3130
  jdAndroidAddEventListenerTouchStart(e) {
3131
3131
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
3132
3132
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
3133
3133
  const hasCustomEle = e
3134
3134
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
3135
3135
  : false;
3136
3136
  if (!hasCustomEle) {
3137
3137
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
3138
3138
  console.log(
3139
3139
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
3140
3140
  );
3141
3141
  }
3142
3142
  }
3143
3143
  }
3144
3144
  removeJdAndroidRquestEventForTouchStart() {
3145
3145
  if (isJdAndAndroidDevice && window.JdAndroid) {
3146
3146
  const rootEleNode = document.querySelector('body');
3147
3147
  if (rootEleNode) {
3148
3148
  rootEleNode.removeEventListener(
3149
3149
  'touchstart',
3150
3150
  this.jdAndroidAddEventListenerTouchStart,
3151
3151
  false,
3152
3152
  );
3153
3153
  }
3154
3154
  }
3155
3155
  }
3156
3156
 
3157
3157
  getNetWorkType() {
3158
3158
  if (isJdApp) {
3159
3159
  this.jmfeReayPromise().then(() => {
3160
3160
  window.jmfe
3161
3161
  .getNetworkStatus()
3162
3162
  .then(({ status, data }) => {
3163
3163
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
3164
3164
  if (status === '0') {
3165
3165
  this.info.sysInfo['netWorkType'] = data;
3166
3166
  } else {
3167
3167
  this._taroGetNetworkType();
3168
3168
  }
3169
3169
  })
3170
3170
  .catch((err) => {
3171
3171
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
3172
3172
  this._taroGetNetworkType();
3173
3173
  });
3174
3174
  });
3175
3175
  } else {
3176
3176
  this._taroGetNetworkType();
3177
3177
  }
3178
3178
  }
3179
3179
  _taroGetNetworkType() {
3180
3180
  Taro.getNetworkType().then((getRes) => {
3181
3181
  if (getRes && getRes.networkType) {
3182
3182
  this.info.sysInfo['netWorkType'] = getRes.networkType;
3183
3183
  console.log(
3184
3184
  '在app内通过taro对象获取网络状态完成,当前网络状态',
3185
3185
  this.info.sysInfo['netWorkType'],
3186
3186
  );
3187
3187
  }
3188
3188
  });
3189
3189
  }
3190
3190
 
3191
3191
  getJdAppBaseInfo() {
3192
3192
  const appKeyCacheToCookieMinuteTime =
3193
3193
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
3194
3194
  appUuidCacheToCookieMinuteTime =
3195
3195
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
3196
3196
  getAppKey = cookie.get(cacheAppKey),
3197
3197
  getAppUuidKey = cookie.get(cacheAppUuidKey);
3198
3198
  console.log(
3199
3199
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
3200
3200
  cacheAppKey,
3201
3201
  getAppKey,
3202
3202
  cacheAppUuidKey,
3203
3203
  getAppUuidKey,
3204
3204
  );
3205
3205
  if (
3206
3206
  appKeyCacheToCookieMinuteTime &&
3207
3207
  appUuidCacheToCookieMinuteTime &&
3208
3208
  getAppKey &&
3209
3209
  getAppUuidKey
3210
3210
  ) {
3211
3211
  const [uuid, eufv] = getAppUuidKey.split('@');
3212
3212
  const baseApiKeyParam = {
3213
3213
  uuid,
3214
3214
  };
3215
3215
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
3216
3216
  if (eufv === '1' && /-/.test(uuid)) {
3217
3217
  const [eu, fv] = uuid.split('-');
3218
3218
  baseApiKeyParam['eu'] = eu;
3219
3219
  baseApiKeyParam['fv'] = fv;
3220
3220
  }
3221
3221
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3222
3222
  this.jmfeReayPromise().then(() => {
3223
3223
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
3224
3224
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3225
3225
  });
3226
3226
  } else {
3227
3227
  const checkGetJdAppKeyState =
3228
3228
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
3229
3229
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
3230
3230
  this.jmfeReayPromise().then(() => {
3231
3231
  Promise.all([
3232
3232
  checkGetJdAppKeyState && window.jmfe?.callNative
3233
3233
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
3234
3234
  : Promise.resolve({
3235
3235
  status: '-1000',
3236
3236
  msg: '当前版本不支持获取松果app中的getAppKey',
3237
3237
  data: '-1000',
3238
3238
  }),
3239
3239
  window.jmfe.getDeviceInfo(),
3240
3240
  ]).then((resList) => {
3241
3241
  const [getAppKeyRes, deviceInfoRes] = resList;
3242
3242
  console.log(
3243
3243
  '在app内初始化通过jmfe获取getAppKey结果',
3244
3244
  getAppKeyRes,
3245
3245
  '通过jmfe获取getDeviceInfo获取结果',
3246
3246
  deviceInfoRes,
3247
3247
  );
3248
3248
  const baseApiKeyParam = {};
3249
3249
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
3250
3250
  const getJmfeAppKey = getAppKeyRes?.data;
3251
3251
  if (getJmfeAppKey && getJmfeAppKey !== '') {
3252
3252
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
3253
3253
  const getJdAppKeyCacheToCookieMinuteTime =
3254
3254
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
3255
3255
  if (getJdAppKeyCacheToCookieMinuteTime) {
3256
3256
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
3257
3257
  cookie.set(cacheAppKey, getJmfeAppKey, {
3258
3258
  path: '/',
3259
3259
  expires,
3260
3260
  });
3261
3261
  }
3262
3262
  }
3263
3263
  }
3264
3264
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
3265
3265
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
3266
3266
  if (uuid && uuid !== '') {
3267
3267
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
3268
3268
  baseApiKeyParam['uuid'] = uuid;
3269
3269
  if (eufv === '1' && /-/.test(uuid)) {
3270
3270
  const [eu, fv] = uuid.split('-');
3271
3271
  baseApiKeyParam['eu'] = eu;
3272
3272
  baseApiKeyParam['fv'] = fv;
3273
3273
  }
3274
3274
  const getAppUuidCacheToCookieMinuteTime =
3275
3275
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
3276
3276
  if (getAppUuidCacheToCookieMinuteTime) {
3277
3277
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
3278
3278
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
3279
3279
  path: '/',
3280
3280
  expires,
3281
3281
  });
3282
3282
  }
3283
3283
  }
3284
3284
  }
3285
3285
  console.log(
3286
3286
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
3287
3287
  baseApiKeyParam,
3288
3288
  );
3289
3289
  if (Object.keys(baseApiKeyParam).length > 0) {
3290
3290
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
3291
3291
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
3292
3292
  }
3293
3293
  });
3294
3294
  });
3295
3295
  }
3296
3296
  }
3297
3297
 
3298
3298
  getCacheAddressRouter() {
3299
3299
  if (isJdApp) {
3300
3300
  if (!isJdAndHarmonyDevice) {
3301
3301
  return Promise.race([
3302
3302
  new Promise((resolve) => {
3303
3303
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
3304
3304
  if (!window[getCallBackName]) {
3305
3305
  window[getCallBackName] = (res) => {
3306
3306
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
3307
3307
  try {
3308
3308
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3309
3309
  resolve(getResJson);
3310
3310
  } catch (e) {
3311
3311
  resolve({
3312
3312
  status: '-1002',
3313
3313
  msg: '地址信息解析json异常',
3314
3314
  res,
3315
3315
  });
3316
3316
  }
3317
3317
  window[getCallBackName] = null;
3318
3318
  };
3319
3319
  }
3320
3320
  const getRouterParam = {
3321
3321
  sceneId: 'basicShoppingProcess',
3322
3322
  };
3323
3323
  if (isAndroidDevice) {
3324
3324
  return callRouterAndroid({
3325
3325
  routerURL: 'router://JDAddressModule/getCacheAddress',
3326
3326
  routerParam: getRouterParam,
3327
3327
  callBackName: getCallBackName,
3328
3328
  isSync: true,
3329
3329
  });
3330
3330
  } else {
3331
3331
  return callRouterIOS({
3332
3332
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
3333
3333
  routerParam: getRouterParam,
3334
3334
  callBackName: getCallBackName,
3335
3335
  });
3336
3336
  }
3337
3337
  }),
3338
3338
  this.taskTimeoutPromise(() => {
3339
3339
  return {
3340
3340
  status: '-1000',
3341
3341
  msg: '原生router协议获取地址信息超时',
3342
3342
  };
3343
3343
  }, 3000),
3344
3344
  ]);
3345
3345
  } else {
3346
3346
  return Promise.race([
3347
3347
  new Promise((resolve) => {
3348
3348
  this.jmfeReayPromise()
3349
3349
  .then(() => {
3350
3350
  const plugin = 'JDHybridRouterPlugin';
3351
3351
  const action = 'callSyncRouterModuleWithParams';
3352
3352
  const params = {
3353
3353
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
3354
3354
  routerParam: '',
3355
3355
  };
3356
3356
  const sync = '1';
3357
3357
  try {
3358
3358
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
3359
3359
  resolve(res);
3360
3360
  });
3361
3361
  } catch (error) {
3362
3362
  resolve({
3363
3363
  status: '-1001',
3364
3364
  msg: '判断jmfe不存在,获取经纬度信息异常',
3365
3365
  });
3366
3366
  }
3367
3367
  })
3368
3368
  .catch(() => {
3369
3369
  resolve({
3370
3370
  status: '-1002',
3371
3371
  msg: '鸿蒙系统调用jmfe异常,获取失败',
3372
3372
  });
3373
3373
  });
3374
3374
  }),
3375
3375
  this.taskTimeoutPromise(() => {
3376
3376
  return {
3377
3377
  status: '-1000',
3378
3378
  msg: '原生router协议获取地址信息超时',
3379
3379
  };
3380
3380
  }, 3000),
3381
3381
  ]);
3382
3382
  }
3383
3383
  } else if (isH5AndJingGouMini) {
3384
3384
  const { areaId, addressName } = this.getJingGouMiniInh5Address();
3385
3385
  if (areaId && areaId !== '' && addressName && addressName !== '') {
3386
3386
  return Promise.resolve({
3387
3387
  status: '0',
3388
3388
  data: {
3389
3389
  areaId,
3390
3390
  fullAddress: addressName,
3391
3391
  },
3392
3392
  });
3393
3393
  } else {
3394
3394
  return Promise.resolve({
3395
3395
  status: '-1002',
3396
3396
  msg: '京购内嵌h5h5暂无业务需要,未实现,获取失败',
3397
3397
  });
3398
3398
  }
3399
3399
  } else {
3400
3400
  return Promise.resolve({
3401
3401
  status: '-1002',
3402
3402
  msg: '普通h5暂无业务需要,未实现,获取失败',
3403
3403
  });
3404
3404
  }
3405
3405
  }
3406
3406
 
3407
3407
  getJingGouMiniInh5Address() {
3408
3408
  let getRes: any = {
3409
3409
  areaId: '',
3410
3410
  addressName: '',
3411
3411
  };
3412
3412
  try {
3413
3413
  const getUrlHast = decodeURIComponent(window.location.hash || '');
3414
3414
  const sensMatch = getUrlHast ? getUrlHast.match(/sens=({.*?})/) : null;
3415
3415
  if (sensMatch && sensMatch[1]) {
3416
3416
  const sensData = JSON.parse(sensMatch[1]);
3417
3417
  const getWqAddr = sensData?.wq_addr || '';
3418
3418
  if (getWqAddr && /\|/.test(getWqAddr)) {
3419
3419
  const addressList = getWqAddr.split(/\|/);
3420
3420
  const [addressId, areaId, areaName, addressName, coordinate] = addressList;
3421
3421
  getRes = {
3422
3422
  addressId,
3423
3423
  areaId,
3424
3424
  areaName,
3425
3425
  addressName,
3426
3426
  coordinate,
3427
3427
  };
3428
3428
  }
3429
3429
  }
3430
3430
  } catch (e) {
3431
3431
  console.log('获取hash转换异常', e);
3432
3432
  }
3433
3433
  return getRes;
3434
3434
  }
3435
3435
 
3436
3436
  getAddressCachePromise() {
3437
3437
  return new Promise((resolve) => {
3438
3438
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
3439
3439
  resolve({
3440
3440
  lat: this.info.sysInfo.lat,
3441
3441
  lng: this.info.sysInfo.lng,
3442
3442
  area: this?.info?.sysInfo?.area,
3443
3443
  fullAddress: this?.info?.pageInfo?.fullAddress,
3444
3444
  });
3445
3445
  } else {
3446
3446
  this.getCacheAddressRouter()
3447
3447
  .then((res) => {
3448
3448
  const { status, data } = res;
3449
3449
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
3450
3450
  if (status === '0' && data) {
3451
3451
  const {
3452
3452
  lat,
3453
3453
  latitude,
3454
3454
  lng,
3455
3455
  longitude,
3456
3456
  provinceId,
3457
3457
  cityId,
3458
3458
  countyId,
3459
3459
  townId,
3460
3460
  fullAddress,
3461
3461
  areaId,
3462
3462
  } = data || {};
3463
3463
  const getAreaIdsEnable = areaId && areaId !== '';
3464
3464
  const getEncodeFullAddress = fullAddress ? encodeURIComponent(fullAddress) : '';
3465
3465
  let area = getAreaIdsEnable ? areaId : '';
3466
3466
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
3467
3467
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
3468
3468
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
3469
3469
  if ((getProvinceIdNum && getProvinceIdNum > 0) || getAreaIdsEnable) {
3470
3470
  area = getAreaIdsEnable
3471
3471
  ? areaId
3472
3472
  : `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
3473
3473
  this.info.pageInfo['address'] = area;
3474
3474
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
3475
3475
  this.info.sysInfo['area'] = area;
3476
3476
  const getUpdateData = {
3477
3477
  area: this.info.pageInfo.address,
3478
3478
  };
3479
3479
  if (fullAddress && fullAddress.length > 0) {
3480
3480
  getUpdateData['fullAddress'] = getEncodeFullAddress;
3481
3481
  this.info.pageInfo['fullAddress'] = getEncodeFullAddress;
3482
3482
  }
3483
3483
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, getUpdateData);
3484
3484
  }
3485
3485
  resolve({
3486
3486
  lat: this.info.sysInfo['lat'],
3487
3487
  lng: this.info.sysInfo['lng'],
3488
3488
  fullAddress: getEncodeFullAddress,
3489
3489
  area: area,
3490
3490
  });
3491
3491
  } else {
3492
3492
  if (typeof res === 'object') {
3493
3493
  draBusinessCustomReport({
3494
3494
  eventName: 'business',
3495
3495
  errorName: 'jdapp_getCacheAddress_info_err',
3496
3496
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
3497
3497
  extraData: JSON.stringify({
3498
3498
  isJdApp,
3499
3499
  jdAppVersion: jdAppVersionStr,
3500
3500
  ...res,
3501
3501
  }),
3502
3502
  });
3503
3503
  }
3504
3504
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
3505
3505
  }
3506
3506
  })
3507
3507
  .catch((e) => {
3508
3508
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
3509
3509
  draBusinessCustomReport({
3510
3510
  eventName: 'business',
3511
3511
  errorName: 'jdapp_getCacheAddress_info_catch_err',
3512
3512
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
3513
3513
  extraData: JSON.stringify({
3514
3514
  isJdApp,
3515
3515
  jdAppVersion: jdAppVersionStr,
3516
3516
  }),
3517
3517
  });
3518
3518
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
3519
3519
  });
3520
3520
  }
3521
3521
  });
3522
3522
  }
3523
3523
 
3524
3524
  getLbsCacheAddressRouter() {
3525
3525
  if (isJdApp) {
3526
3526
  if (!isJdAndHarmonyDevice) {
3527
3527
  return Promise.race([
3528
3528
  new Promise((resolve) => {
3529
3529
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
3530
3530
  if (!window[getCallBackName]) {
3531
3531
  window[getCallBackName] = (res) => {
3532
3532
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
3533
3533
  try {
3534
3534
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
3535
3535
  resolve(getResJson);
3536
3536
  } catch (e) {
3537
3537
  resolve({
3538
3538
  status: '-1002',
3539
3539
  msg: '地址信息解析json异常',
3540
3540
  res,
3541
3541
  });
3542
3542
  }
3543
3543
  window[getCallBackName] = null;
3544
3544
  };
3545
3545
  }
3546
3546
  const getRouterParam = {
3547
3547
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
3548
3548
  sceneId: 'basicShoppingProcess',
3549
3549
  };
3550
3550
  if (isAndroidDevice) {
3551
3551
  return callRouterAndroid({
3552
3552
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
3553
3553
  routerParam: getRouterParam,
3554
3554
  callBackName: getCallBackName,
3555
3555
  isSync: true,
3556
3556
  hasJdRouter: false,
3557
3557
  });
3558
3558
  } else {
3559
3559
  return callRouterIOS({
3560
3560
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
3561
3561
  routerParam: getRouterParam,
3562
3562
  callBackName: getCallBackName,
3563
3563
  isSync: true,
3564
3564
  });
3565
3565
  }
3566
3566
  }),
3567
3567
  this.taskTimeoutPromise(() => {
3568
3568
  return {
3569
3569
  status: '-1000',
3570
3570
  msg: '原生router协议获取lbs地址信息3s超时',
3571
3571
  };
3572
3572
  }, 3000),
3573
3573
  ]);
3574
3574
  } else {
3575
3575
  return Promise.resolve({
3576
3576
  status: '-1001',
3577
3577
  msg: '鸿蒙系统调用未实现,获取失败',
3578
3578
  });
3579
3579
  }
3580
3580
  } else if (isH5AndJingGouMini) {
3581
3581
  return this.getLocationForGpsPromise();
3582
3582
  } else {
3583
3583
  return Promise.resolve({
3584
3584
  status: '-1002',
3585
3585
  msg: '普通h5暂无业务需要,未实现,获取失败',
3586
3586
  });
3587
3587
  }
3588
3588
  }
3589
3589
  getLocationForGpsPromise() {
3590
3590
  return new Promise((resolve) => {
3591
3591
  let hasGetLocationForGps = true;
3592
3592
  if (urlCookie && urlCookie['loc']) {
3593
3593
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
3594
3594
  urlCookie['loc'].split('_');
3595
3595
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3596
3596
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3597
3597
  hasGetLocationForGps = false;
3598
3598
  resolve({
3599
3599
  status: '0',
3600
3600
  data: {
3601
3601
  provinceid,
3602
3602
  cityid,
3603
3603
  districtid,
3604
3604
  townid,
3605
3605
  origin: 'wxapp',
3606
3606
  },
3607
3607
  });
3608
3608
  }
3609
3609
  }
3610
3610
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
3611
3611
  window.navigator.geolocation.getCurrentPosition(
3612
3612
  (position) => {
3613
3613
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
3614
3614
  if (position?.coords) {
3615
3615
  resolve({
3616
3616
  status: '0',
3617
3617
  data: {
3618
3618
  srclat: position.coords?.latitude,
3619
3619
  srclng: position.coords.longitude,
3620
3620
  origin: 'h5',
3621
3621
  },
3622
3622
  });
3623
3623
  } else {
3624
3624
  resolve({
3625
3625
  status: '-1001',
3626
3626
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
3627
3627
  position,
3628
3628
  });
3629
3629
  }
3630
3630
  },
3631
3631
  (error) => {
3632
3632
  resolve({
3633
3633
  status: '-1001',
3634
3634
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
3635
3635
  error,
3636
3636
  });
3637
3637
  },
3638
3638
  {
3639
3639
  enableHighAccuracy: false,
3640
3640
  timeout: 3 * 1000,
3641
3641
  maximumAge: 10 * 60 * 1000,
3642
3642
  },
3643
3643
  );
3644
3644
  } else {
3645
3645
  resolve({
3646
3646
  status: '-1001',
3647
3647
  msg: '您的浏览器不支持地理定位',
3648
3648
  });
3649
3649
  }
3650
3650
  });
3651
3651
  }
3652
3652
 
3653
3653
  createLbsCacheAddress(realTimeArea) {
3654
3654
  const getLbsAddressCacheMinuteTime = Number(
3655
3655
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
3656
3656
  );
3657
3657
  console.log(
3658
3658
  '获取lbs缓存到cookie的时间,分钟',
3659
3659
  getLbsAddressCacheMinuteTime,
3660
3660
  'lbsAddressCacheToCookieMinuteTime',
3661
3661
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
3662
3662
  );
3663
3663
  if (getLbsAddressCacheMinuteTime > 0) {
3664
3664
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
3665
3665
  realTimeArea &&
3666
3666
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
3667
3667
  path: '/',
3668
3668
  expires,
3669
3669
  });
3670
3670
  }
3671
3671
  }
3672
3672
 
3673
3673
  getLbsAddressCachePromise() {
3674
3674
  if (!this.lbsAddressCachePromise) {
3675
3675
  this.lbsAddressCachePromise = new Promise((resolve) => {
3676
3676
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
3677
3677
  ? cookie.get(cacheH5LbsAddressKey)
3678
3678
  : '';
3679
3679
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
3680
3680
  if (getUserLbsAddress && getUserLbsAddress !== '') {
3681
3681
  resolve({
3682
3682
  ok: true,
3683
3683
  realTimeArea: getUserLbsAddress,
3684
3684
  });
3685
3685
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
3686
3686
  console.info(
3687
3687
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
3688
3688
  getCookieForLbsAddress,
3689
3689
  );
3690
3690
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
3691
3691
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
3692
3692
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3693
3693
  realTimeArea: getCookieForLbsAddress,
3694
3694
  });
3695
3695
  resolve({
3696
3696
  ok: true,
3697
3697
  realTimeArea: getCookieForLbsAddress,
3698
3698
  });
3699
3699
  } else {
3700
3700
  this.getLbsCacheAddressRouter()
3701
3701
  .then((res) => {
3702
3702
  const { status, data } = res;
3703
3703
  console.log(
3704
3704
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
3705
3705
  status,
3706
3706
  data,
3707
3707
  res,
3708
3708
  );
3709
3709
  if (status === '0' && data) {
3710
3710
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
3711
3711
  data || {};
3712
3712
  let realTimeArea = '';
3713
3713
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
3714
3714
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
3715
3715
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
3716
3716
  if (getProvinceIdNum && getProvinceIdNum > 0) {
3717
3717
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
3718
3718
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
3719
3719
  this.info.sysInfo['realTimeArea'] = realTimeArea;
3720
3720
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
3721
3721
  realTimeArea: this.info.pageInfo.userLbsAddress,
3722
3722
  });
3723
3723
  this.createLbsCacheAddress(realTimeArea);
3724
3724
  } else {
3725
3725
  !origin && (this.lbsAddressCachePromise = null);
3726
3726
  }
3727
3727
  const getValidRealTimeArea = realTimeArea !== '';
3728
3728
  resolve({
3729
3729
  lat: this.info.sysInfo['srclat'],
3730
3730
  lng: this.info.sysInfo['srclng'],
3731
3731
  realTimeArea: realTimeArea,
3732
3732
  ok: getValidRealTimeArea,
3733
3733
  msg: getValidRealTimeArea
3734
3734
  ? '成功'
3735
3735
  : origin
3736
3736
  ? origin
3737
3737
  : '根据router底层获取lbs地址信息异常,详情见data',
3738
3738
  data: getValidRealTimeArea ? null : res,
3739
3739
  });
3740
3740
  if (!getValidRealTimeArea && !origin) {
3741
3741
  draBusinessCustomReport({
3742
3742
  eventName: 'business',
3743
3743
  errorName: 'h5_getLbsCacheAddress_info_err',
3744
3744
  errorMessage:
3745
3745
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
3746
3746
  extraData: JSON.stringify({
3747
3747
  isJdApp,
3748
3748
  jdAppVersion: jdAppVersionStr,
3749
3749
  }),
3750
3750
  });
3751
3751
  }
3752
3752
  } else {
3753
3753
  typeof res === 'object' &&
3754
3754
  draBusinessCustomReport({
3755
3755
  eventName: 'business',
3756
3756
  errorName: 'h5_getLbsCacheAddress_info_err',
3757
3757
  errorMessage:
3758
3758
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
3759
3759
  extraData: JSON.stringify({
3760
3760
  isJdApp,
3761
3761
  jdAppVersion: jdAppVersionStr,
3762
3762
  ...res,
3763
3763
  }),
3764
3764
  });
3765
3765
  this.lbsAddressCachePromise = null;
3766
3766
  resolve({ realTimeArea: '', ok: false });
3767
3767
  }
3768
3768
  })
3769
3769
  .catch((e) => {
3770
3770
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
3771
3771
  this.lbsAddressCachePromise = null;
3772
3772
  draBusinessCustomReport({
3773
3773
  eventName: 'business',
3774
3774
  errorName: 'h5_getLbsCacheAddress_info_err',
3775
3775
  errorMessage:
3776
3776
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
3777
3777
  extraData: JSON.stringify({
3778
3778
  isJdApp,
3779
3779
  jdAppVersion: jdAppVersionStr,
3780
3780
  }),
3781
3781
  });
3782
3782
  resolve({ realTimeArea: '', ok: false });
3783
3783
  });
3784
3784
  }
3785
3785
  });
3786
3786
  }
3787
3787
  return this.lbsAddressCachePromise;
3788
3788
  }
3789
3789
 
3790
3790
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
3791
3791
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
3792
3792
  if (!isJdApp) {
3793
3793
  return;
3794
3794
  }
3795
3795
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
3796
3796
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
3797
3797
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
3798
3798
  'hybridHttpSwitch',
3799
3799
  isBeforePageReady,
3800
3800
  );
3801
3801
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
3802
3802
  'jshopIsVipShop',
3803
3803
  isBeforePageReady,
3804
3804
  );
3805
3805
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
3806
3806
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
3807
3807
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
3808
3808
  'isFollowAppVideoPlayStatus',
3809
3809
  isBeforePageReady,
3810
3810
  );
3811
3811
  console.log(
3812
3812
  'isBeforePageReady:',
3813
3813
  isBeforePageReady,
3814
3814
  'isFollowAppVideoPlayStatus:',
3815
3815
  isFollowAppVideoPlayStatus,
3816
3816
  );
3817
3817
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
3818
3818
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
3819
3819
  }
3820
3820
  }
3821
3821
 
3822
3822
  async getWifiVideoAutoPlayAsync() {
3823
3823
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
3824
3824
  if (!isJdApp) {
3825
3825
  return;
3826
3826
  }
3827
3827
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
3828
3828
  return 0;
3829
3829
  });
3830
3830
  if (Number(videoPlayStatus) === 1) {
3831
3831
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
3832
3832
  }
3833
3833
  }
3834
3834
 
3835
3835
  async getMPaasConfigAsync() {
3836
3836
  this.info.sysInfo.dynamicConfig = {};
3837
3837
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
3838
3838
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
3839
3839
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
3840
3840
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
3841
3841
  return this.updateMPaasConfigAsync(true);
3842
3842
  }
3843
3843
 
3844
3844
  getDynamicConfig(key: string) {
3845
3845
  return this.info.sysInfo?.dynamicConfig?.[key];
3846
3846
  }
3847
3847
  async updateMPaasConfig() {
3848
3848
  console.log('updateMPaasConfig');
3849
3849
  if (
3850
3850
  isIosDevice &&
3851
3851
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
3852
3852
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
3853
3853
  ) {
3854
3854
  try {
3855
3855
  await this.updateMPaasConfigAsync(false);
3856
3856
  } catch (e) {
3857
3857
  console.log('updateMPaasConfigAsync:', e);
3858
3858
  }
3859
3859
  }
3860
3860
  }
3861
3861
 
3862
3862
  toLogin(options) {
3863
3863
  if (isAscfApp) {
3864
3864
  return this.toAscfAppLogin(options);
3865
3865
  }
3866
3866
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
3867
3867
  ? this.toWxAppLogin(options)
3868
3868
  : this.toWebLogin(options);
3869
3869
  }
3870
3870
 
3871
3871
  doLogin(options) {
3872
3872
  return this.toLogin(options);
3873
3873
  }
3874
3874
 
3875
3875
  doLoginForJdPin(options = {}) {
3876
3876
  return this.doLogin({
3877
3877
  loginColor: {
3878
3878
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
3879
3879
  dpin: 0,
3880
3880
  },
3881
3881
  ...options,
3882
3882
  });
3883
3883
  }
3884
3884
 
3885
3885
  toWebLogin(options) {
3886
3886
  let params: {
3887
3887
  returnurl: string;
3888
3888
  } = {
3889
3889
  returnurl: '',
3890
3890
  };
3891
3891
  const checkToPcLogin = options ? options?.isPc : isPc;
3892
3892
  const loginUrl = checkToPcLogin
3893
3893
  ? `//passport.jd.com/new/login.aspx`
3894
3894
  : `${domain.mobileLogin}/user/login.action`;
3895
3895
  const defaultParams = {
3896
3896
  appid: '100',
3897
3897
  returnurl: window.location.href,
3898
3898
  };
3899
3899
  if (isString(options)) {
3900
3900
  params = Object.assign({}, defaultParams, {
3901
3901
  returnurl: options,
3902
3902
  });
3903
3903
  } else if (isObject(options)) {
3904
3904
  const { loginColor, ...otherOptions } = options;
3905
3905
  params = Object.assign({}, defaultParams, otherOptions);
3906
3906
  } else {
3907
3907
  params = defaultParams;
3908
3908
  }
3909
3909
  params.returnurl = encodeURIComponent(params.returnurl);
3910
3910
  let getFullUrl = loginUrl + '?' + serialize(params);
3911
3911
  if (checkToPcLogin) {
3912
3912
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
3913
3913
  }
3914
3914
  return Promise.resolve({
3915
3915
  h5ToUrl: true,
3916
3916
  url: getFullUrl,
3917
3917
  }).then(() => {
3918
3918
  window.location.href = getFullUrl;
3919
3919
  });
3920
3920
  }
3921
3921
 
3922
3922
  toAscfAppLogin(options = {}) {
3923
3923
  console.log('华为元服务中h5登录跳转', options);
3924
3924
  return Promise.resolve(true).then(() => {
3925
3925
  const returnPage = encodeURIComponent(window.location.href);
3926
3926
  if (has && has.ascfweb) {
3927
3927
  has.ascfweb.redirectTo({
3928
3928
  url: `/pages/login/index/index?isH5=1&returnPage=${returnPage}&pageType=h5&source=shopx`,
3929
3929
  });
3930
3930
  }
3931
3931
  });
3932
3932
  }
3933
3933
 
3934
3934
  toWxAppLogin(options = {}) {
3935
3935
  console.log('微信京购小程序中h5登录跳转', options);
3936
3936
  return Promise.resolve(true).then(() => {
3937
3937
  const { loginColor } = Object.assign(
3938
3938
  {},
3939
3939
  {
3940
3940
  loginColor: {
3941
3941
  biz: WXAPP_BIZ_KEY,
3942
3942
  dpin: 1,
3943
3943
  },
3944
3944
  },
3945
3945
  options,
3946
3946
  );
3947
3947
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
3948
3948
  loginColor.biz
3949
3949
  }&url=${encodeURIComponent(window.location.href)}`;
3950
3950
  });
3951
3951
  }
3952
3952
 
3953
3953
  getLoginCookie() {
3954
3954
  return Promise.resolve({
3955
3955
  pin: cookie.get('pin') || '',
3956
3956
  });
3957
3957
  }
3958
3958
 
3959
3959
  clearLoginCookie() {
3960
3960
  cookie.remove('pin');
3961
3961
  }
3962
3962
 
3963
3963
  checkStatusAndLogin(options = {}) {
3964
3964
  if (!this.checkStatusAndLoginPromise) {
3965
3965
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
3966
3966
  try {
3967
3967
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
3968
3968
  if (getLoginState) {
3969
3969
  resolve(true);
3970
3970
  } else {
3971
3971
  this.toLogin(options);
3972
3972
  reject(false);
3973
3973
  }
3974
3974
  } catch (e) {
3975
3975
  this.toLogin(options);
3976
3976
  reject(false);
3977
3977
  }
3978
3978
  });
3979
3979
  return this.checkStatusAndLoginPromise;
3980
3980
  } else {
3981
3981
  return this.checkStatusAndLoginPromise
3982
3982
  .then(() => {
3983
3983
  return Promise.resolve(true);
3984
3984
  })
3985
3985
  .catch(() => {
3986
3986
  this.toLogin(options);
3987
3987
  return Promise.reject(true);
3988
3988
  });
3989
3989
  }
3990
3990
  }
3991
3991
 
3992
3992
  checkJdStatusAndLogin(
3993
3993
  options = {
3994
3994
  loginColor: {
3995
3995
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
3996
3996
  dpin: 0,
3997
3997
  },
3998
3998
  },
3999
3999
  ) {
4000
4000
  return this.checkStatusAndLogin(options);
4001
4001
  }
4002
4002
 
4003
4003
  doCheckLoginStateAndForApiCheck(options) {
4004
4004
  if (this.info.loginState) {
4005
4005
  return Promise.resolve(true);
4006
4006
  } else {
4007
4007
  return new Promise((resolve, reject) => {
4008
4008
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
4009
4009
  const getWqAuthToken = cookie.get('wq_auth_token');
4010
4010
  const getWqSkey = cookie.get('wq_skey');
4011
4011
  const getWqUin = cookie.get('wq_uin');
4012
4012
  const isLoginState =
4013
4013
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
4014
4014
  if (isLoginState) {
4015
4015
  this.info.loginState = true;
4016
4016
  resolve(true);
4017
4017
  } else {
4018
4018
  reject(false);
4019
4019
  }
4020
4020
  } else {
4021
4021
  Taro.request({
4022
4022
  url: api.isLogin,
4023
4023
  jsonp: true,
4024
4024
  timeout: 3000,
4025
4025
  success: (res) => {
4026
4026
  const { statusCode, data } = res;
4027
4027
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
4028
4028
  this.info.loginState = true;
4029
4029
  resolve(true);
4030
4030
  } else {
4031
4031
  reject(false);
4032
4032
  }
4033
4033
  },
4034
4034
  fail: (err) => {
4035
4035
  console.log('登录检查异常', err);
4036
4036
  reject(false);
4037
4037
  },
4038
4038
  });
4039
4039
  }
4040
4040
  });
4041
4041
  }
4042
4042
  }
4043
4043
 
4044
4044
  checkLoginStatus(options) {
4045
4045
  return new Promise(async (resolve, reject) => {
4046
4046
  try {
4047
4047
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
4048
4048
  if (getLoginState) {
4049
4049
  const { pin } = await this.getLoginCookie();
4050
4050
  this.info.userInfo = {
4051
4051
  pin,
4052
4052
  encodePin: encodeURIComponent(pin),
4053
4053
  ptkey: '',
4054
4054
  };
4055
4055
  resolve(true);
4056
4056
  } else {
4057
4057
  reject(false);
4058
4058
  }
4059
4059
  } catch (e) {
4060
4060
  reject(false);
4061
4061
  }
4062
4062
  });
4063
4063
  }
4064
4064
 
4065
4065
  updatePageAndLogInfo(updateQuery = {}) {
4066
4066
  const createUpdateQueryInfo: {
4067
4067
  query: {
4068
4068
  shopId?: string | number;
4069
4069
  venderId?: string | number;
4070
4070
  };
4071
4071
  updateShopInfoState: boolean;
4072
4072
  } = Object.assign(
4073
4073
  {},
4074
4074
  {
4075
4075
  query: {},
4076
4076
  updateShopInfoState: false,
4077
4077
  },
4078
4078
  updateQuery,
4079
4079
  );
4080
4080
  console.log(
4081
4081
  '获取当前下发的店铺查询参数',
4082
4082
  updateQuery,
4083
4083
  '获取之前保存的shopInfo店铺查询参数',
4084
4084
  this.info?.shopInfo,
4085
4085
  );
4086
4086
  const { query, updateShopInfoState } = createUpdateQueryInfo;
4087
4087
  const { shopId, venderId, un_area } = query;
4088
4088
  if (updateShopInfoState) {
4089
4089
  this.info.queryInfo = {
4090
4090
  ...this.info.queryInfo,
4091
4091
  ...query,
4092
4092
  };
4093
4093
  if (shopId && venderId) {
4094
4094
  this.info.shopInfo = {
4095
4095
  shopId: `${shopId}`,
4096
4096
  venderId: `${venderId}`,
4097
4097
  };
4098
4098
  }
4099
4099
  } else {
4100
4100
  this.info.queryInfo = {
4101
4101
  ...query,
4102
4102
  };
4103
4103
  if (
4104
4104
  this.info.shopInfo?.shopId &&
4105
4105
  this.info.shopInfo?.venderId &&
4106
4106
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
4107
4107
  ) {
4108
4108
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
4109
4109
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
4110
4110
  console.log(
4111
4111
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
4112
4112
  this.info.queryInfo,
4113
4113
  );
4114
4114
  }
4115
4115
  }
4116
4116
  this.info.queryInfo['shopId'] &&
4117
4117
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
4118
4118
  this.info.queryInfo['venderId'] &&
4119
4119
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
4120
4120
  console.log(
4121
4121
  'h5==获取店铺下发查询参数\n',
4122
4122
  query,
4123
4123
  '\n获取店铺最后查询参数\n',
4124
4124
  this.info.queryInfo,
4125
4125
  '\n是否为更新店铺状态\n',
4126
4126
  updateShopInfoState,
4127
4127
  );
4128
4128
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
4129
4129
  if (changeArea) {
4130
4130
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
4131
4131
  this.info.pageInfo.address = getBottomAreaStr;
4132
4132
  this.info.pageInfo.un_area = getBottomAreaStr;
4133
4133
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
4134
4134
  }
4135
4135
  }
4136
4136
 
4137
4137
  dealLoadSdkList() {
4138
4138
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
4139
4139
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
4140
4140
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
4141
4141
  let mergeLoadJsList = globalLoadJsList;
4142
4142
  try {
4143
4143
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
4144
4144
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
4145
4145
  getFindIndex !== -1
4146
4146
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
4147
4147
  : accArr.push(current);
4148
4148
  return accArr;
4149
4149
  }, []);
4150
4150
  } catch (e) {
4151
4151
  console.log('LoadJsList合并错误', e);
4152
4152
  }
4153
4153
  console.log(
4154
4154
  'globalLoadJsList',
4155
4155
  globalLoadJsList,
4156
4156
  'businessLoadJsList',
4157
4157
  businessLoadJsList,
4158
4158
  '两个加载jsList集合合并完成',
4159
4159
  mergeLoadJsList,
4160
4160
  );
4161
4161
  this.loadJsSdkList = mergeLoadJsList;
4162
4162
  return this.loadJsSdkList;
4163
4163
  }
4164
4164
 
4165
4165
  renderNextTickLoadSdk(delayTime = 1000) {
4166
4166
  Taro.nextTick(() => {
4167
4167
  console.log(
4168
4168
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
4169
4169
  );
4170
4170
  setTimeout(() => {
4171
4171
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
4172
4172
  }, delayTime);
4173
4173
  });
4174
4174
  }
4175
4175
 
4176
4176
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
4177
4177
  const getLoadJsList =
4178
4178
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
4179
4179
  const getLoadFilterList = getLoadJsList.filter((item) => {
4180
4180
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
4181
4181
  item.initLoadType = undefined;
4182
4182
  }
4183
4183
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
4184
4184
  let getLoastLoadEventState = true;
4185
4185
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
4186
4186
  getLoastLoadEventState = isJdApp;
4187
4187
  }
4188
4188
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
4189
4189
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
4190
4190
  }
4191
4191
  const getInitTriggerType =
4192
4192
  isJdApp && item?.initJdAppTriggerType
4193
4193
  ? item?.initTriggerType
4194
4194
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
4195
4195
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
4196
4196
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
4197
4197
  });
4198
4198
  console.log(
4199
4199
  '获取当前触发方式',
4200
4200
  triggerType,
4201
4201
  '获取当前最后加载的js集合',
4202
4202
  getLoadFilterList,
4203
4203
  '过滤前的加载集合',
4204
4204
  getLoadJsList,
4205
4205
  );
4206
4206
  const loadTasks =
4207
4207
  getLoadFilterList.length > 0
4208
4208
  ? getLoadFilterList.map((item) => {
4209
4209
  const isLoadState = /sgm/.test(item?.fileName)
4210
4210
  ? window?.shopGlobalSwitch?.openSgm === 'true'
4211
4211
  : true;
4212
4212
  if (!isLoadState) {
4213
4213
  return Promise.resolve(true);
4214
4214
  }
4215
4215
  return this.loadItemSdkPromise(item)
4216
4216
  .then((res) => {
4217
4217
  console.info('当前js地址' + item?.src, '加载状态', res);
4218
4218
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
4219
4219
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
4220
4220
  const getNewdraEnableShopIdPercentObj =
4221
4221
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || null;
4222
4222
  const getNewdraEnableVenderIdPercentObj =
4223
4223
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || null;
4224
4224
  let canInitDraRun = true;
4225
4225
  if (getNewdraEnableShopIdPercentObj || getNewdraEnableVenderIdPercentObj) {
4226
4226
  canInitDraRun = this.shouldPercentExecuteNewDra(
4227
4227
  this.getNewDraEnablePercentNum(),
4228
4228
  );
4229
4229
  }
4230
4230
  if (canInitDraRun) {
4231
4231
  window.dra.run('init', { aid: res?.aid });
4232
4232
  window.dra.run('start');
4233
4233
  }
4234
4234
  }
4235
4235
  return true;
4236
4236
  })
4237
4237
  .catch((err) => {
4238
4238
  console.info('当前js地址加载异常', item?.src);
4239
4239
  window?.fetchErrorData &&
4240
4240
  window.fetchErrorData({
4241
4241
  title: '公共js加载异常',
4242
4242
  type: 'jsLoad',
4243
4243
  data: err,
4244
4244
  });
4245
4245
  return true;
4246
4246
  });
4247
4247
  })
4248
4248
  : [];
4249
4249
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
4250
4250
  }
4251
4251
 
4252
4252
  shouldPercentExecuteNewDra(percent) {
4253
4253
  if (percent <= 0) return false;
4254
4254
  if (percent >= 100) return true;
4255
4255
  const getRes = Math.random() < percent / 100;
4256
4256
  console.log('获取dra初始化执行的概率为', percent, '执行结果', getRes);
4257
4257
  return getRes;
4258
4258
  }
4259
4259
 
4260
4260
  getNewDraEnablePercentNum() {
4261
4261
  const getNewdraEnableShopIdPercent =
4262
4262
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || {};
4263
4263
  const getNewdraEnableVenderIdPercent =
4264
4264
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || {};
4265
4265
  const getShopId = parseQueryUrlObj?.shopId || '';
4266
4266
  const getVenderId = parseQueryUrlObj?.venderId || '';
4267
4267
  const getShopIdDraEnablePercent = getNewdraEnableShopIdPercent[getShopId]
4268
4268
  ? getNewdraEnableShopIdPercent[getShopId]
4269
4269
  : getNewdraEnableShopIdPercent?.ids?.includes(getShopId)
4270
4270
  ? getNewdraEnableShopIdPercent?.idsNumber
4271
4271
  : -1;
4272
4272
  const getVenderIdDraEnablePercent = getNewdraEnableVenderIdPercent[getVenderId]
4273
4273
  ? getNewdraEnableVenderIdPercent[getVenderId]
4274
4274
  : getNewdraEnableVenderIdPercent?.ids?.includes(getVenderId)
4275
4275
  ? getNewdraEnableVenderIdPercent?.idsNumber
4276
4276
  : -1;
4277
4277
  if (getShopIdDraEnablePercent > -1 || getVenderIdDraEnablePercent > -1) {
4278
4278
  return getShopIdDraEnablePercent || getVenderIdDraEnablePercent;
4279
4279
  }
4280
4280
  return 100;
4281
4281
  }
4282
4282
  loadScriptEle(jsInfo, resolve, reject) {
4283
4283
  const getFileName = jsInfo?.fileName;
4284
4284
  if (getFileName) {
4285
4285
  const getEleId = `J_loadJs_${getFileName}`;
4286
4286
  const getEle = document.getElementById(getEleId);
4287
4287
  if (!getEle) {
4288
4288
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4289
4289
  const _sgmEle = document.createElement('script');
4290
4290
  _sgmEle.id = getEleId;
4291
4291
  _sgmEle.onload = function () {
4292
4292
  resolve({
4293
4293
  ...jsInfo,
4294
4294
  jsTip: 'js加载成功',
4295
4295
  });
4296
4296
  };
4297
4297
  _sgmEle.onerror = function () {
4298
4298
  reject({
4299
4299
  ...jsInfo,
4300
4300
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4301
4301
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
4302
4302
  });
4303
4303
  };
4304
4304
  const dataAttrList = ['timeout', 'fileName', 'env'];
4305
4305
  const getJsInfoKeyList = Object.keys(jsInfo);
4306
4306
  getJsInfoKeyList.forEach((key) => {
4307
4307
  if (key === 'async') {
4308
4308
  _sgmEle.async = jsInfo[key];
4309
4309
  } else if (key === 'crossOrigin') {
4310
4310
  _sgmEle.crossOrigin = jsInfo[key];
4311
4311
  } else if (key === 'src') {
4312
4312
  _sgmEle.src = `${jsInfo[key]}`;
4313
4313
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
4314
4314
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
4315
4315
  } else {
4316
4316
  _sgmEle.setAttribute(key, jsInfo[key]);
4317
4317
  }
4318
4318
  });
4319
4319
  document.head.appendChild(_sgmEle);
4320
4320
  } else {
4321
4321
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
4322
4322
  resolve({
4323
4323
  ...jsInfo,
4324
4324
  jsTip: 'js本身已存在页面中',
4325
4325
  });
4326
4326
  }
4327
4327
  } else {
4328
4328
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
4329
4329
  }
4330
4330
  }
4331
4331
 
4332
4332
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
4333
4333
  if (jsInfo?.src) {
4334
4334
  const getInitLoadType =
4335
4335
  isJdApp && jsInfo?.initJdAppLoadType
4336
4336
  ? jsInfo?.initJdAppLoadType
4337
4337
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
4338
4338
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
4339
4339
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
4340
4340
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
4341
4341
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
4342
4342
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4343
4343
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
4344
4344
  try {
4345
4345
  const jsXhrRequest = new XMLHttpRequest();
4346
4346
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
4347
4347
  const jsUrl = `${jsInfo?.src}`;
4348
4348
  jsXhrRequest.open('GET', jsUrl, true);
4349
4349
  jsXhrRequest.onreadystatechange = () => {
4350
4350
  if (jsXhrRequest.readyState === 4) {
4351
4351
  const getReqStatus = jsXhrRequest.status;
4352
4352
  const statusText = jsXhrRequest.statusText;
4353
4353
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4354
4354
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
4355
4355
  if (getInsetHeadState) {
4356
4356
  this.loadScriptEle(jsInfo, resolve, reject);
4357
4357
  } else {
4358
4358
  resolve({
4359
4359
  ...jsInfo,
4360
4360
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
4361
4361
  });
4362
4362
  }
4363
4363
  getReqStatus !== 200 &&
4364
4364
  draBusinessCustomReport({
4365
4365
  eventName: 'business',
4366
4366
  errorName: 'js_load_special_code',
4367
4367
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
4368
4368
  extraData: JSON.stringify({
4369
4369
  msg: '当前js加载成功,状态非200,特殊上报观察',
4370
4370
  jsReqState: getReqStatus,
4371
4371
  env: getSgmCustomCode('js_load_special_code'),
4372
4372
  data: jsInfo,
4373
4373
  }),
4374
4374
  });
4375
4375
  } else {
4376
4376
  const getRes = {
4377
4377
  ...jsInfo,
4378
4378
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4379
4379
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4380
4380
  jsReqState: getReqStatus,
4381
4381
  };
4382
4382
  console.log('当前js请求状态异常,具体信息见', getRes);
4383
4383
  reject(getRes);
4384
4384
  }
4385
4385
  }
4386
4386
  };
4387
4387
  jsXhrRequest.onerror = () => {
4388
4388
  const getRes = {
4389
4389
  ...jsInfo,
4390
4390
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4391
4391
  jsReqError: '请求错误',
4392
4392
  };
4393
4393
  console.log('当前js请求错误', getRes);
4394
4394
  jsXhrRequest.abort();
4395
4395
  reject(getRes);
4396
4396
  };
4397
4397
  jsXhrRequest.ontimeout = () => {
4398
4398
  const getRes = {
4399
4399
  ...jsInfo,
4400
4400
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4401
4401
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
4402
4402
  jsReqState: jsXhrRequest.status,
4403
4403
  };
4404
4404
  console.log('当前js请求超时异常', getRes);
4405
4405
  jsXhrRequest.abort();
4406
4406
  reject(getRes);
4407
4407
  };
4408
4408
  jsXhrRequest.send();
4409
4409
  } catch (e) {
4410
4410
  console.log('执行js请求异常', e);
4411
4411
  reject({
4412
4412
  ...jsInfo,
4413
4413
  env: getSgmCustomCode(jsLoadErrorSgmCode),
4414
4414
  jsReqError: '未知异常',
4415
4415
  error: e,
4416
4416
  });
4417
4417
  }
4418
4418
  });
4419
4419
  } else {
4420
4420
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
4421
4421
  return this.loadScriptEle(jsInfo, resolve, reject);
4422
4422
  });
4423
4423
  }
4424
4424
  }
4425
4425
  return this.loadJsSdkListCachePromise[getFileKeyName];
4426
4426
  } else {
4427
4427
  return Promise.resolve({
4428
4428
  ...jsInfo,
4429
4429
  jsTip: 'js加载方式设置为不加载,当前不做处理',
4430
4430
  });
4431
4431
  }
4432
4432
  } else {
4433
4433
  return Promise.reject(jsInfo);
4434
4434
  }
4435
4435
  }
4436
4436
 
4437
4437
  createLanguagePromise() {
4438
4438
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
4439
4439
  if (!this.languageCacheProimse) {
4440
4440
  this.languageCacheProimse = new Promise((resolve, reject) => {
4441
4441
  const { fileName, prefixUrl } = getLanguageConfig;
4442
4442
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
4443
4443
  const dealLanguageFile = () => {
4444
4444
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
4445
4445
  .then((res: any) => {
4446
4446
  if (res && res?.data) {
4447
4447
  this.languageJsonData = res.data;
4448
4448
 
4449
4449
  setTimeout(() => {
4450
4450
  const getOtherLanguageList = languageTypeList.filter(
4451
4451
  (item) => item !== languageNowType,
4452
4452
  );
4453
4453
  getOtherLanguageList.length > 0 &&
4454
4454
  getOtherLanguageList.map((languageTypeKey) => {
4455
4455
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
4456
4456
  });
4457
4457
  }, 3000);
4458
4458
  resolve(res);
4459
4459
  } else {
4460
4460
  reject(res);
4461
4461
  }
4462
4462
  })
4463
4463
  .catch((err) => {
4464
4464
  reject(err);
4465
4465
  });
4466
4466
  };
4467
4467
  if (fileName && prefixUrl) {
4468
4468
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
4469
4469
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
4470
4470
  if (getLocalLangRes) {
4471
4471
  try {
4472
4472
  const getLocalLangJsonData =
4473
4473
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
4474
4474
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
4475
4475
  if (getLocalLangJsonData?.fileName === fileName) {
4476
4476
  const geThisLangData = getLocalLangJsonData.data;
4477
4477
  this.languageJsonData = geThisLangData;
4478
4478
  return resolve({
4479
4479
  ...getLanguageConfig,
4480
4480
  languageNowType,
4481
4481
  data: geThisLangData,
4482
4482
  });
4483
4483
  } else {
4484
4484
  dealLanguageFile();
4485
4485
  }
4486
4486
  } else {
4487
4487
  dealLanguageFile();
4488
4488
  }
4489
4489
  } catch (e) {
4490
4490
  return reject({
4491
4491
  languageNowType,
4492
4492
  msg: '转换错误',
4493
4493
  ...getLanguageConfig,
4494
4494
  });
4495
4495
  }
4496
4496
  } else {
4497
4497
  dealLanguageFile();
4498
4498
  }
4499
4499
  } else {
4500
4500
  return reject({
4501
4501
  languageNowType,
4502
4502
  msg: '文件对象下发异常',
4503
4503
  ...getLanguageConfig,
4504
4504
  });
4505
4505
  }
4506
4506
  });
4507
4507
  }
4508
4508
  return this.languageCacheProimse;
4509
4509
  }
4510
4510
 
4511
4511
  getLanguageFilePromise(info, languageTypeKey) {
4512
4512
  const { fileName, prefixUrl, timeout } = info || {};
4513
4513
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
4514
4514
  return new Promise((resolve, reject) => {
4515
4515
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
4516
4516
  try {
4517
4517
  const langXhrRequest = new XMLHttpRequest();
4518
4518
  langXhrRequest.timeout = timeout || 2000;
4519
4519
  langXhrRequest.open('GET', getUrl, true);
4520
4520
  langXhrRequest.responseType = 'json';
4521
4521
  langXhrRequest.onreadystatechange = () => {
4522
4522
  if (langXhrRequest.readyState === 4) {
4523
4523
  const getReqStatus = langXhrRequest.status;
4524
4524
  const statusText = langXhrRequest.statusText;
4525
4525
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
4526
4526
  const getData = langXhrRequest?.response || false;
4527
4527
  if (getData) {
4528
4528
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
4529
4529
  fileName,
4530
4530
  data: getData,
4531
4531
  });
4532
4532
  resolve({
4533
4533
  ...info,
4534
4534
  languageTypeKey,
4535
4535
  data: getData,
4536
4536
  });
4537
4537
  } else {
4538
4538
  reject({
4539
4539
  ...info,
4540
4540
  languageTypeKey,
4541
4541
  msg: '数据获取异常',
4542
4542
  });
4543
4543
  }
4544
4544
  } else {
4545
4545
  const getRes = {
4546
4546
  ...info,
4547
4547
  languageTypeKey,
4548
4548
  env: getSgmCustomCode(langLoadErrorSgmCode),
4549
4549
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
4550
4550
  };
4551
4551
  console.log('当前lang请求状态异常,具体信息见', getRes);
4552
4552
  reject(getRes);
4553
4553
  }
4554
4554
  }
4555
4555
  };
4556
4556
  langXhrRequest.onerror = () => {
4557
4557
  const getRes = {
4558
4558
  ...info,
4559
4559
  env: getSgmCustomCode(langLoadErrorSgmCode),
4560
4560
  msg: '请求错误',
4561
4561
  };
4562
4562
  console.log('当前lang请求错误', getRes);
4563
4563
  langXhrRequest.abort();
4564
4564
  reject(getRes);
4565
4565
  };
4566
4566
  langXhrRequest.ontimeout = () => {
4567
4567
  const getRes = {
4568
4568
  ...info,
4569
4569
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
4570
4570
  };
4571
4571
  console.log('执行lang多语言请求超时异常', getRes);
4572
4572
  langXhrRequest.abort();
4573
4573
  reject(getRes);
4574
4574
  };
4575
4575
  langXhrRequest.send();
4576
4576
  } catch (e) {
4577
4577
  console.log('执行lang多语言请求异常', e);
4578
4578
  reject({
4579
4579
  ...info,
4580
4580
  env: getSgmCustomCode(langLoadErrorSgmCode),
4581
4581
  msg: '未知异常',
4582
4582
  error: e,
4583
4583
  });
4584
4584
  }
4585
4585
  });
4586
4586
  }