@conecli/cone-render 0.10.1-shop3.8 → 0.10.1-shop3.80

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