@conecli/cone-render 0.10.1-shop3.14 → 0.10.1-shop3.140

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