@conecli/cone-render 0.10.1-shop-beta.11 → 0.10.1-shop-beta.13

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