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

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