@conecli/cone-render 0.10.1-shop3.56 → 0.10.1-shop3.57

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