@conecli/cone-render 0.10.1-shop3.10 → 0.10.1-shop3.100

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