@conecli/cone-render 0.10.1-shop-beta.24 → 0.10.1-shop-beta.26

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