@conecli/cone-render 0.10.1-shop3.9 → 0.10.1-shop3.90

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 (114) 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.ascf.ts +1 -0
  17. package/dist/common/wxappApi.ts +1 -1
  18. package/dist/components/ErrorBoundary.tsx +1 -1
  19. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  20. package/dist/components/base/CountDown/index.tsx +1 -1
  21. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  22. package/dist/components/base/CustomVideo/index.tsx +1 -1
  23. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  24. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  25. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  26. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  27. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  28. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  29. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  30. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  31. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  32. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  33. package/dist/components/base/NetworkDataError/const.ts +1 -1
  34. package/dist/components/base/NetworkDataError/index.module.scss +118 -72
  35. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  36. package/dist/components/base/Price/Base/index.module.scss +12 -0
  37. package/dist/components/base/Price/Base/index.tsx +1 -1
  38. package/dist/components/base/Price/Double/index.module.scss +25 -1
  39. package/dist/components/base/Price/Double/index.tsx +1 -1
  40. package/dist/components/base/ShopLeGaoTag/index.h5.module.scss +35 -0
  41. package/dist/components/base/ShopLeGaoTag/index.h5.tsx +1 -0
  42. package/dist/components/base/ShopLeGaoTag/index.module.scss +33 -0
  43. package/dist/components/base/ShopLeGaoTag/index.tsx +1 -0
  44. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  45. package/dist/components/floorItem.tsx +1 -1
  46. package/dist/components/isv/Floor/index.tsx +1 -1
  47. package/dist/components/remoteFloorItem.tsx +1 -1
  48. package/dist/config/env.ts +1 -1
  49. package/dist/interface/common.ts +1 -1
  50. package/dist/interface/component.ts +1 -1
  51. package/dist/interface/jumpEventReport.ts +1 -1
  52. package/dist/interface/service.ts +1 -1
  53. package/dist/jumpEventReport/base.ts +1 -1
  54. package/dist/jumpEventReport/const.ts +1 -1
  55. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  56. package/dist/jumpEventReport/index.h5.ts +1 -1
  57. package/dist/jumpEventReport/index.jd.ts +1 -1
  58. package/dist/jumpEventReport/index.weapp.ts +1 -1
  59. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  60. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  61. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  62. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  63. package/dist/jumpEventReport/web/report.ts +1 -1
  64. package/dist/jumpEventReport/web.base.ts +1 -1
  65. package/dist/jumpEventReport/web.jd.ts +1 -1
  66. package/dist/jumpEventReport/web.pc.ts +1 -1
  67. package/dist/jumpEventReport/web.tjm.ts +1 -1
  68. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  69. package/dist/language/en_US.json +309 -0
  70. package/dist/language/zh_CN.json +309 -0
  71. package/dist/language/zh_HK.json +309 -0
  72. package/dist/libs/openShopBridge.js +161 -0
  73. package/dist/libs/openShopBridge.min.js +1 -0
  74. package/dist/libs/taroAppReport.js +2 -2
  75. package/dist/modules/ContainerFloorList/index.h5.module.scss +16 -2
  76. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  77. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  78. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  79. package/dist/open/api/environment.ts +1 -1
  80. package/dist/open/api/shopMember.ts +1 -1
  81. package/dist/open/api/shopMember.weapp.ts +1 -0
  82. package/dist/open/api/track.ts +1 -1
  83. package/dist/open/api/util.ts +1 -1
  84. package/dist/open/components/index.ts +1 -1
  85. package/dist/open/index.ts +1 -1
  86. package/dist/sass/app.h5.scss +27 -1
  87. package/dist/sass/base.scss +8 -4
  88. package/dist/service/fetchGateway.ts +1 -1
  89. package/dist/service/fetchGateway.weapp.ts +1 -1
  90. package/dist/service/fetchJsonp.weapp.ts +1 -0
  91. package/dist/service/http/const.ts +1 -1
  92. package/dist/service/http/h5Http.ts +1 -1
  93. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  94. package/dist/service/requestServer.h5.ts +1 -1
  95. package/dist/service/requestServer.ts +1 -1
  96. package/dist/service/requestServer.weapp.ts +1 -1
  97. package/dist/utils/connectNativeJsBridge.ts +1 -1
  98. package/dist/utils/h5Utils.ts +1 -1
  99. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  100. package/dist/utils/harmonyCallRouter.ts +0 -0
  101. package/dist/utils/index.h5.ts +1 -1
  102. package/dist/utils/index.ts +1 -1
  103. package/dist/utils/index.weapp.ts +1 -1
  104. package/dist/utils/jumpExtMapUtil.ts +1 -0
  105. package/dist/utils/log.ts +1 -0
  106. package/dist/utils/{sColor.js → sColor.ts} +1 -1
  107. package/dist/utils/sColor.weapp.ts +1 -0
  108. package/dist/utils/utils.ts +1 -1
  109. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  110. package/dist/wxapp/common/user_info.js +1 -1
  111. package/package.json +162 -141
  112. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  113. package/dist/utils/priceUtils.js +0 -1
  114. /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
  isAscfApp,
1243
1243
  jdAppVersionCompare,
1244
1244
  abTestLabels: {},
1245
1245
  nonSellableSkuids: {},
1246
1246
  loginState: false,
1247
1247
  cookiesStr: '',
1248
1248
  userInfo: userPinKey,
1249
1249
  isImmersive:
1250
1250
  !window?.shopGlobalSwitch?.disableImmersive &&
1251
1251
  isJdApp &&
1252
1252
  window.location?.search.includes('immersive=1'),
1253
1253
  isJingGouMiniViewState: false,
1254
1254
  isJingxiMiniViewState: false,
1255
1255
  baseAddCartSwitch: true,
1256
1256
  pageInfo: {
1257
1257
  wxBusinessType: WX_BUSINESS_TYPE.NO,
1258
1258
  address: '',
1259
1259
  addressCommaStr: '',
1260
1260
  un_area: '',
1261
1261
  userLbsAddress: '',
1262
1262
  vapptype: '1',
1263
1263
  pageType: 'home',
1264
1264
  isExposureState: false,
1265
1265
  moduleId: '',
1266
1266
  entrance: '',
1267
1267
  dataType: BUSINESS_TYPE.ONLINE,
1268
1268
  floorExposureInfo: {},
1269
1269
  floorVideInfo: {},
1270
1270
  productVideInfo: {},
1271
1271
  tabsLoadAllDataInfo: {
1272
1272
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
1273
1273
  },
1274
1274
  updateShopInfosAllState: false,
1275
1275
  isVipShop: false,
1276
1276
  isJdShowNativeImmersivePlayer: false,
1277
1277
  isSuperBrandShop: false,
1278
1278
  ...shopConfig,
1279
1279
  pageScrollTop: 0,
1280
1280
  pageIdxHeightInfo: {
1281
1281
  list: [],
1282
1282
  },
1283
1283
  shopNavBarHeight: 0,
1284
1284
  },
1285
1285
  defaultQueryLogInfo: {
1286
1286
  sourceType: 'JDshop',
1287
1287
  sourceValue: '',
1288
1288
  moduleId: 'none',
1289
1289
  entrance: 'none',
1290
1290
  },
1291
1291
  sysInfo: {
1292
1292
  windowWidth: isPc ? 375 : 0,
1293
1293
  containerWidth: isPc ? 375 : 0,
1294
1294
  windowHeight: 0,
1295
1295
  netWorkType: '4g',
1296
1296
  jdBottomBarHeight: 0,
1297
1297
  jdNativeHeaderHeight: 0,
1298
1298
  isJdTabletDevice: false,
1299
1299
  isJdTabletLandscape: false,
1300
1300
  },
1301
1301
  queryInfo: {},
1302
1302
  shopInfo: {},
1303
1303
  openAppData: {},
1304
1304
  public info: CommonInterFace.BaseConfigInfo;
1305
1305
  public config: {
1306
1306
  [key: string]: any;
1307
1307
  };
1308
1308
  public lazyContainer: CommonInterFace.lazyContainer;
1309
1309
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
1310
1310
  public rootEleNode: HTMLElement | null;
1311
1311
  public checkStatusAndLoginPromise: object | null;
1312
1312
  private jmfeRegisterStatePromise: Promise<any> | null;
1313
1313
  private jdScreenSizeInfoPromise: Promise<any> | null;
1314
1314
  private rootEleWidthRegisterPromise: Promise<any> | null;
1315
1315
  private loadJsH5tagStatePromise: Promise<any> | null;
1316
1316
  private loadJsApiRequestStatePromise: Promise<any> | null;
1317
1317
  private jmfeRegisterState: boolean;
1318
1318
  public loadJsSdkList: {
1319
1319
  src: string;
1320
1320
  timeout: number;
1321
1321
  fileName: string;
1322
1322
  initTriggerType: typeof LoadJsInitTriggerType;
1323
1323
  initLinkTriggerWay:
1324
1324
  | 'asyncLoadAppSdkJs'
1325
1325
  | 'asyncLoadHandlerJs'
1326
1326
  | 'asyncLoadReportJs'
1327
1327
  | 'asyncLoadMtkJs'
1328
1328
  | 'asyncLoadSecurityJs'
1329
1329
  | 'asyncLoadSgmJs'
1330
1330
  | 'asyncLoadCartJs'
1331
1331
  | 'asyncLoadNewDraSdkJs'
1332
1332
  | 'asyncLoadH5TagJs';
1333
1333
  initLoadEnvType: typeof LoadJsInitLoadEnvType;
1334
1334
  defer?: 'true';
1335
1335
  async?: 'true';
1336
1336
  crossOrigin: 'anonymous' | '';
1337
1337
  }[];
1338
1338
  public loadJsSdkListCachePromise: any;
1339
1339
  public rootEleInitWidth: number;
1340
1340
  public lbsAddressCachePromise: Promise<any> | null;
1341
1341
  public languageCacheProimse: Promise<any> | null;
1342
1342
  public languageJsonData: any | null;
1343
1343
  public businessWorkerReady: boolean;
1344
1344
  public businessWorkerReadyPromise: Promise<any> | null;
1345
1345
  public workerPreRequestData = new Map<string, any>();
1346
1346
  constructor(opt) {
1347
1347
  this.info = this._getConfig(opt);
1348
1348
  this.config = {};
1349
1349
  this.loadJsSdkList = [];
1350
1350
  this.loadJsSdkListCachePromise = {};
1351
1351
  this.lazyContainer = {
1352
1352
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
1353
1353
  appLazyContainerList: [],
1354
1354
  appLazyFinishContainerList: [],
1355
1355
  },
1356
1356
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
1357
1357
  appLazyContainerList: [],
1358
1358
  appLazyFinishContainerList: [],
1359
1359
  },
1360
1360
  };
1361
1361
  this.renderedIsvComponents = {};
1362
1362
  this.rootEleNode = document.querySelector('body');
1363
1363
  this.checkStatusAndLoginPromise = null;
1364
1364
  this.jmfeRegisterStatePromise = null;
1365
1365
  this.jdScreenSizeInfoPromise = null;
1366
1366
  this.rootEleWidthRegisterPromise = null;
1367
1367
  this.lbsAddressCachePromise = null;
1368
1368
  this.languageCacheProimse = null;
1369
1369
  this.businessWorkerReady = false;
1370
1370
  this.businessWorkerReadyPromise = null;
1371
1371
  this.loadJsH5tagStatePromise = null;
1372
1372
  this.loadJsApiRequestStatePromise = null;
1373
1373
  this.workerPreRequestData = new Map<string, any>();
1374
1374
  this.languageJsonData = langeJsonDataForCn;
1375
1375
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
1376
1376
  this._init();
1377
1377
  if (isJdApp) {
1378
1378
  this.jmfeReayPromise().then(() => {
1379
1379
  this.jdWorkerReadyPromise();
1380
1380
  });
1381
1381
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
1382
1382
  }
1383
1383
  }
1384
1384
  _getConfig(opt) {
1385
1385
  return Object.assign({}, DefaultConfig, opt);
1386
1386
  }
1387
1387
  _init() {
1388
1388
  this.loadOtherSdk();
1389
1389
  this.checkJdAddCartState();
1390
1390
  }
1391
1391
 
1392
1392
  checkJdAddCartState() {
1393
1393
  const getJdAppForNotMainRemoveCartUaList = isJdApp
1394
1394
  ? window?.PAGE_DATA?.businessData?.jdAppForNotMainRemoveCartUaList
1395
1395
  : undefined;
1396
1396
  if (
1397
1397
  getJdAppForNotMainRemoveCartUaList &&
1398
1398
  Array.isArray(getJdAppForNotMainRemoveCartUaList) &&
1399
1399
  getJdAppForNotMainRemoveCartUaList.length > 0
1400
1400
  ) {
1401
1401
  const setFilterReg = new RegExp(getJdAppForNotMainRemoveCartUaList.join('|'), 'i');
1402
1402
  this.info.baseAddCartSwitch = !setFilterReg.test(window.navigator.userAgent);
1403
1403
  }
1404
1404
  }
1405
1405
 
1406
1406
  loadApiSafeSteadyReayPromise() {
1407
1407
  if (!this.loadJsApiRequestStatePromise) {
1408
1408
  this.loadJsApiRequestStatePromise = this.loadOtherSdk(LoadJsInitTriggerType.API_REQUEST);
1409
1409
  }
1410
1410
  return this.loadJsApiRequestStatePromise;
1411
1411
  }
1412
1412
 
1413
1413
  loadH5tagReayPromise() {
1414
1414
  if (!this.loadJsH5tagStatePromise) {
1415
1415
  const h5TagJs = this.loadJsSdkList.find((e) => e.fileName === 'h5TagJs');
1416
1416
  this.loadJsH5tagStatePromise = !h5TagJs
1417
1417
  ? Promise.resolve(true)
1418
1418
  : this.loadOtherSdk(LoadJsInitTriggerType.NOW, [
1419
1419
  Object.assign({}, h5TagJs, {
1420
1420
  initTriggerType: LoadJsInitTriggerType.NOW,
1421
1421
  }),
1422
1422
  ]);
1423
1423
  }
1424
1424
  return this.loadJsH5tagStatePromise;
1425
1425
  }
1426
1426
 
1427
1427
  jmfeReayPromise(): Promise<any> {
1428
1428
  if (isJdApp) {
1429
1429
  if (this.jmfeRegisterState) {
1430
1430
  return Promise.resolve(true);
1431
1431
  } else {
1432
1432
  !this.jmfeRegisterStatePromise &&
1433
1433
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
1434
1434
  ready('jmfe', 3000)
1435
1435
  .then(() => {
1436
1436
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
1437
1437
  this.jmfeRegisterState = true;
1438
1438
  resolve(true);
1439
1439
  console.log(
1440
1440
  '松果app内初始化注册jmfe认证完成',
1441
1441
  window?.jmfe,
1442
1442
  '当前版本',
1443
1443
  window?.jmfe?.VERSION,
1444
1444
  );
1445
1445
  })
1446
1446
  .catch((err) => {
1447
1447
  console.error('jmfe ready error', err);
1448
1448
  reject(false);
1449
1449
  });
1450
1450
  }));
1451
1451
  return this.jmfeRegisterStatePromise;
1452
1452
  }
1453
1453
  } else {
1454
1454
  return Promise.reject(false);
1455
1455
  }
1456
1456
  }
1457
1457
 
1458
1458
  jdWorkerReadyPromise(): Promise<any> {
1459
1459
  if (isJdApp) {
1460
1460
  if (this.businessWorkerReady) {
1461
1461
  return Promise.resolve(true);
1462
1462
  } else {
1463
1463
  const getOpenJdWorkerState =
1464
1464
  window?.PAGE_DATA?.businessData?.businessWorkerVersion &&
1465
1465
  versionCompare(
1466
1466
  jdAppVersionStr,
1467
1467
  window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10',
1468
1468
  ) >= 0;
1469
1469
  !this.businessWorkerReadyPromise &&
1470
1470
  (this.businessWorkerReadyPromise = getOpenJdWorkerState
1471
1471
  ? new Promise((resolve) => {
1472
1472
  this.jmfeReayPromise()
1473
1473
  .then(() => {
1474
1474
  window.jmfe
1475
1475
  .onMsgForWorker(
1476
1476
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
1477
1477
  (workerData) => {
1478
1478
  console.log('收到业务jd worker消息结果:', workerData);
1479
1479
  if (workerData && workerData?.workerType) {
1480
1480
  const getWorkerType = workerData?.workerType;
1481
1481
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
1482
1482
  this.workerPreRequestData.set(workerData?.functionId, workerData);
1483
1483
  Taro.eventCenter.trigger(getWorkerType, workerData);
1484
1484
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
1485
1485
  Taro.eventCenter.trigger(getWorkerType, workerData);
1486
1486
  }
1487
1487
  }
1488
1488
  },
1489
1489
  )
1490
1490
  .then(() => {
1491
1491
  console.log('jd worker注册成功');
1492
1492
  this.businessWorkerReady = true;
1493
1493
  resolve(true);
1494
1494
  })
1495
1495
  .catch((error) => {
1496
1496
  console.log(
1497
1497
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
1498
1498
  error,
1499
1499
  );
1500
1500
  draBusinessCustomReport({
1501
1501
  eventName: 'business',
1502
1502
  errorName: 'jmfe_onMsgForWorker_error',
1503
1503
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
1504
1504
  extraData: JSON.stringify({
1505
1505
  businessWorkerVersion:
1506
1506
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
1507
1507
  error,
1508
1508
  }),
1509
1509
  });
1510
1510
  resolve(false);
1511
1511
  });
1512
1512
  })
1513
1513
  .catch((err) => {
1514
1514
  console.log('jmfe超时异常,worker注册失败', err);
1515
1515
  resolve(false);
1516
1516
  });
1517
1517
  })
1518
1518
  : Promise.resolve(false));
1519
1519
  }
1520
1520
  return this.businessWorkerReadyPromise;
1521
1521
  } else {
1522
1522
  return Promise.resolve(false);
1523
1523
  }
1524
1524
  }
1525
1525
 
1526
1526
  taskTimeoutPromise(callBack, timeout = 2000) {
1527
1527
  return new Promise((resolve) => {
1528
1528
  setTimeout(
1529
1529
  () => {
1530
1530
  const getCallBackRes = typeof callBack === 'function' && callBack();
1531
1531
  return resolve(getCallBackRes || false);
1532
1532
  },
1533
1533
  isInJdAppH5DebugMode ? 0 : timeout,
1534
1534
  );
1535
1535
  });
1536
1536
  }
1537
1537
  _getJdPadMinWidthForListen() {
1538
1538
  return (
1539
1539
  isJdApp &&
1540
1540
  Math.min(window.screen.width, window.screen.height) >
1541
1541
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
1542
1542
  );
1543
1543
  }
1544
1544
 
1545
1545
  getJdScreenSizeInfoPromise() {
1546
1546
  !this.jdScreenSizeInfoPromise &&
1547
1547
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
1548
1548
  const getThisTime = Date.now();
1549
1549
  this.jmfeReayPromise().then(() => {
1550
1550
  return Promise.race([
1551
1551
  window.jmfe.getScreenSize(),
1552
1552
  this.taskTimeoutPromise(() => {
1553
1553
  return {
1554
1554
  status: '-10',
1555
1555
  msg: '获取大屏信息2s超时',
1556
1556
  };
1557
1557
  }),
1558
1558
  ])
1559
1559
  .then((res) => {
1560
1560
  console.warn('===获取app大屏信息====', res);
1561
1561
  const { status, data } = res;
1562
1562
  if (status === '0' && data) {
1563
1563
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
1564
1564
  const getPageInfo = dealNativePixelToCssPixel({
1565
1565
  pageWidth,
1566
1566
  pageHeight,
1567
1567
  });
1568
1568
  this.info.sysInfo.jdScreenSizeType = sizeType;
1569
1569
  const getUseTime = Date.now() - getThisTime;
1570
1570
  console.warn(
1571
1571
  '===计算是否是app大屏信息,需满足宽度最新720===',
1572
1572
  getPageInfo,
1573
1573
  '原始数据',
1574
1574
  data,
1575
1575
  '是否是横屏isLandscape为1=',
1576
1576
  isLandscape,
1577
1577
  '用时',
1578
1578
  getUseTime,
1579
1579
  );
1580
1580
  if (getPageInfo?.pageWidth > 0) {
1581
1581
  this.rootEleInitWidth = getPageInfo?.pageWidth;
1582
1582
  draBusinessCustomReport({
1583
1583
  eventName: 'UIInteract',
1584
1584
  errorName: 'rootEle_width_getJdScreenSizeInfo',
1585
1585
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
1586
1586
  extraData: JSON.stringify({
1587
1587
  isJdApp,
1588
1588
  getPageInfo,
1589
1589
  originData: res,
1590
1590
  }),
1591
1591
  });
1592
1592
  resolve(getPageInfo);
1593
1593
  } else {
1594
1594
  resolve({
1595
1595
  pageWidth: 0,
1596
1596
  pageHeight: 0,
1597
1597
  msg: '转换异常',
1598
1598
  });
1599
1599
  }
1600
1600
  } else {
1601
1601
  resolve({
1602
1602
  pageWidth: 0,
1603
1603
  pageHeight: 0,
1604
1604
  msg: '获取大屏信息异常或者超时',
1605
1605
  });
1606
1606
  }
1607
1607
  })
1608
1608
  .catch((err) => {
1609
1609
  console.log('获取大屏信息异常', err);
1610
1610
  resolve({
1611
1611
  pageWidth: 0,
1612
1612
  pageHeight: 0,
1613
1613
  msg: '获取大屏信息异常',
1614
1614
  });
1615
1615
  });
1616
1616
  });
1617
1617
  }));
1618
1618
  return this.jdScreenSizeInfoPromise;
1619
1619
  }
1620
1620
 
1621
1621
  listenJdTabletScreenChange() {
1622
1622
  this.jmfeReayPromise().then(() => {
1623
1623
  try {
1624
1624
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
1625
1625
  window.jmfe.listenDeviceScreenChange((event) => {
1626
1626
  console.log(
1627
1627
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
1628
1628
  event,
1629
1629
  '通过前端判断是不是横屏',
1630
1630
  window.matchMedia('(orientation: landscape)')?.matches,
1631
1631
  );
1632
1632
  const { orientation } = event?.data;
1633
1633
  if (orientation) {
1634
1634
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
1635
1635
  Taro.eventCenter.trigger(
1636
1636
  TaroEventType.TABLE_SCREEN_CHANGE,
1637
1637
  this.info.sysInfo.isJdTabletLandscape,
1638
1638
  orientation,
1639
1639
  );
1640
1640
  }
1641
1641
  });
1642
1642
  } catch (error) {
1643
1643
  console.log('listenScreenChange的打印error:', error);
1644
1644
  }
1645
1645
  });
1646
1646
  }
1647
1647
 
1648
1648
  updateBusinessDomainAndApi(domain, api) {
1649
1649
  }
1650
1650
 
1651
1651
  formatNativeScreenPageData(action) {
1652
1652
  let getChangePageInfo: any = null;
1653
1653
  try {
1654
1654
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
1655
1655
  JSON.stringify({
1656
1656
  plugin: 'JDHybridScreenPlugin',
1657
1657
  action,
1658
1658
  sync: '1',
1659
1659
  }),
1660
1660
  );
1661
1661
  const getChangePageInfoData =
1662
1662
  typeof getNativeScreenPageInfoStr === 'string'
1663
1663
  ? JSON.parse(getNativeScreenPageInfoStr)
1664
1664
  : null;
1665
1665
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
1666
1666
  const { code, data } = getChangePageInfoData;
1667
1667
  getChangePageInfo = code && code === '0' ? data : null;
1668
1668
  }
1669
1669
  } catch (e) {
1670
1670
  console.log('JDHybridScreenPlugin转换异常', e);
1671
1671
  }
1672
1672
  return getChangePageInfo;
1673
1673
  }
1674
1674
 
1675
1675
  isAndroidFoldScreen() {
1676
1676
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
1677
1677
  }
1678
1678
 
1679
1679
  isHarmonyFoldScreenPromise(): Promise<{
1680
1680
  isFoldScreen: boolean;
1681
1681
  getFoldDisplayMode?: number;
1682
1682
  }> {
1683
1683
  return new Promise((resolve) => {
1684
1684
  this.jmfeReayPromise()
1685
1685
  .then(() => {
1686
1686
  if (window.jmfe?.callNative) {
1687
1687
  Promise.all([
1688
1688
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
1689
1689
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
1690
1690
  ])
1691
1691
  .then((res) => {
1692
1692
  resolve({
1693
1693
  isFoldScreen: res?.[0]?.data === '1',
1694
1694
  getFoldDisplayMode: res?.[1]?.data,
1695
1695
  });
1696
1696
  })
1697
1697
  .catch(() => {
1698
1698
  resolve({
1699
1699
  isFoldScreen: false,
1700
1700
  getFoldDisplayMode: undefined,
1701
1701
  });
1702
1702
  });
1703
1703
  } else {
1704
1704
  resolve({
1705
1705
  isFoldScreen: false,
1706
1706
  getFoldDisplayMode: undefined,
1707
1707
  });
1708
1708
  }
1709
1709
  })
1710
1710
  .catch(() => {
1711
1711
  resolve({
1712
1712
  isFoldScreen: false,
1713
1713
  getFoldDisplayMode: undefined,
1714
1714
  });
1715
1715
  });
1716
1716
  });
1717
1717
  }
1718
1718
 
1719
1719
  getJdAndroidPageChangeScreenInfo() {
1720
1720
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
1721
1721
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
1722
1722
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1723
1723
  pageWidth: getPageScreenInfo.pageWidth,
1724
1724
  pageHeight: getPageScreenInfo.pageHeight,
1725
1725
  });
1726
1726
  getPageScreenInfo.pageWidth = pageWidth;
1727
1727
  getPageScreenInfo.pageHeight = pageHeight;
1728
1728
  }
1729
1729
  return getPageScreenInfo;
1730
1730
  }
1731
1731
 
1732
1732
  getRootEleWindowWidthInfo() {
1733
1733
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
1734
1734
  const getWindowWidth = window.innerWidth;
1735
1735
  const getScreenWidth = window.screen.width;
1736
1736
  return {
1737
1737
  getRootEleWidth,
1738
1738
  getWindowWidth,
1739
1739
  getScreenWidth,
1740
1740
  };
1741
1741
  }
1742
1742
 
1743
1743
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
1744
1744
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
1745
1745
  console.log(
1746
1746
  '当前获取根元素的宽度',
1747
1747
  getRootEleWidth,
1748
1748
  'getWindowWidth',
1749
1749
  getWindowWidth,
1750
1750
  'getScreenWidth',
1751
1751
  getScreenWidth,
1752
1752
  );
1753
1753
  const getLastWidth =
1754
1754
  getRootEleWidth > 0
1755
1755
  ? Math.round(getRootEleWidth)
1756
1756
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
1757
1757
  console.warn(
1758
1758
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1759
1759
  );
1760
1760
  timeout > 0 &&
1761
1761
  draBusinessCustomReport({
1762
1762
  eventName: 'UIInteract',
1763
1763
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
1764
1764
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1765
1765
  extraData: JSON.stringify({
1766
1766
  isJdApp,
1767
1767
  getRootEleWidth,
1768
1768
  getWindowWidth,
1769
1769
  getScreenWidth,
1770
1770
  ...reportParam,
1771
1771
  }),
1772
1772
  });
1773
1773
  return getLastWidth;
1774
1774
  }
1775
1775
 
1776
1776
  getPadWindowRootEleWidthPromise() {
1777
1777
  if (this.rootEleInitWidth > 0) {
1778
1778
  return Promise.resolve(this.rootEleInitWidth);
1779
1779
  } else {
1780
1780
  !this.rootEleWidthRegisterPromise &&
1781
1781
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
1782
1782
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
1783
1783
  if (getRootEleInitWidth > 0) {
1784
1784
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
1785
1785
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
1786
1786
  resolve(this.rootEleInitWidth);
1787
1787
  } else {
1788
1788
  const timerPromise = () => {
1789
1789
  return new Promise((resolve2) => {
1790
1790
  window.setTimeout(() => {
1791
1791
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
1792
1792
  this.getRootEleWindowWidthInfo();
1793
1793
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
1794
1794
  console.warn(
1795
1795
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
1796
1796
  );
1797
1797
  draBusinessCustomReport({
1798
1798
  eventName: 'UIInteract',
1799
1799
  errorName: 'rootEle_width_200_timeout_info',
1800
1800
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
1801
1801
  extraData: JSON.stringify({
1802
1802
  isJdApp,
1803
1803
  getRootEleWidth,
1804
1804
  getWindowWidth,
1805
1805
  getScreenWidth,
1806
1806
  }),
1807
1807
  });
1808
1808
  const getRes =
1809
1809
  getRootEleWidth > 0 && getWindowWidth > 0
1810
1810
  ? Math.min(getRootEleWidth, getWindowWidth)
1811
1811
  : Math.max(getRootEleWidth, getWindowWidth);
1812
1812
  resolve2({
1813
1813
  pageWidth: Math.round(getRes),
1814
1814
  });
1815
1815
  }
1816
1816
  }, 200);
1817
1817
  });
1818
1818
  };
1819
1819
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
1820
1820
  const { pageWidth } = res;
1821
1821
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
1822
1822
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
1823
1823
  });
1824
1824
  }
1825
1825
  }));
1826
1826
  return this.rootEleWidthRegisterPromise;
1827
1827
  }
1828
1828
  }
1829
1829
 
1830
1830
  async getSystemInfo(params) {
1831
1831
  const getParams = Object.assign({}, params || {});
1832
1832
  if (this.rootEleInitWidth > 0) {
1833
1833
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
1834
1834
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
1835
1835
  } else {
1836
1836
  if (this._getJdPadMinWidthForListen()) {
1837
1837
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
1838
1838
  getParams['replaceSystemWidth'] = true;
1839
1839
  }
1840
1840
  }
1841
1841
  isJdApp && this.createLanguagePromise();
1842
1842
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
1843
1843
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
1844
1844
  let _isfoldScreen = false;
1845
1845
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
1846
1846
  console.info(
1847
1847
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
1848
1848
  getStorageData,
1849
1849
  '通过缓存值第一次判断是否是折叠屏',
1850
1850
  getStorageData === 'true',
1851
1851
  );
1852
1852
  if (!getStorageData) {
1853
1853
  _isfoldScreen = this.isAndroidFoldScreen();
1854
1854
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
1855
1855
  } else {
1856
1856
  _isfoldScreen = getStorageData === 'true';
1857
1857
  }
1858
1858
  if (_isfoldScreen) {
1859
1859
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
1860
1860
  if (getJdAndroidPageInfo) {
1861
1861
  info = getSystemInfos(getJdAndroidPageInfo);
1862
1862
  console.warn(
1863
1863
  '当前为松果安卓折叠屏app,获取折叠屏信息',
1864
1864
  getJdAndroidPageInfo,
1865
1865
  '获取转换后的系统信息',
1866
1866
  info,
1867
1867
  );
1868
1868
  draBusinessCustomReport({
1869
1869
  eventName: 'UIInteract',
1870
1870
  errorName: 'android_jdapp_foldScreen_info',
1871
1871
  errorMessage:
1872
1872
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
1873
1873
  extraData: JSON.stringify({
1874
1874
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
1875
1875
  androidPageInfo: getJdAndroidPageInfo,
1876
1876
  jdAppVersionStr,
1877
1877
  taroSysInfo: info,
1878
1878
  }),
1879
1879
  });
1880
1880
  }
1881
1881
  }
1882
1882
  }
1883
1883
  if (isJdApp) {
1884
1884
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
1885
1885
  }
1886
1886
  this.info.sysInfo = {
1887
1887
  actualNavBarHeight: 0,
1888
1888
  ...this.info.sysInfo,
1889
1889
  ...info,
1890
1890
  safeContentHeight: info?.screenHeight,
1891
1891
  headerHeight: 0,
1892
1892
  tabBarHeight: 0,
1893
1893
  languageType: languageNowType,
1894
1894
  };
1895
1895
  if (isJdApp || isH5AndJingGouMini) {
1896
1896
  this.getLbsAddressCachePromise();
1897
1897
  }
1898
1898
  if (isJdApp) {
1899
1899
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
1900
1900
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
1901
1901
  this.getJdAppBaseInfo();
1902
1902
  this.getAddressCachePromise();
1903
1903
  this.getElderModePromise();
1904
1904
  this.getJDAppearanceStatePromise();
1905
1905
  this.createJdAndroidRquestEventForTouchStart();
1906
1906
  }
1907
1907
  this.getWifiVideoAutoPlayAsync();
1908
1908
  this.getMPaasConfigAsync();
1909
1909
  this.getNetWorkType();
1910
1910
  }
1911
1911
 
1912
1912
  getElderModePromise() {
1913
1913
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1914
1914
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1915
1915
  } else {
1916
1916
  if (isJdAndAndroidDevice) {
1917
1917
  this.info.sysInfo.jdAppModeType = '0';
1918
1918
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1919
1919
  } else {
1920
1920
  return Promise.race([
1921
1921
  this.taskTimeoutPromise(() => {
1922
1922
  this.info.sysInfo.jdAppModeType = '0';
1923
1923
  return this.info.sysInfo.jdAppModeType;
1924
1924
  }),
1925
1925
  new Promise((resolve) => {
1926
1926
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
1927
1927
  if (!window[getCallBackName]) {
1928
1928
  window[getCallBackName] = (res) => {
1929
1929
  try {
1930
1930
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1931
1931
  const { status, data, msg } = getResJson;
1932
1932
  console.log(`获取松果app展示模式成功,返回结果${data}`);
1933
1933
  if (status === '0') {
1934
1934
  this.info.sysInfo.jdAppModeType = data;
1935
1935
  resolve(data);
1936
1936
  } else {
1937
1937
  resolve('0');
1938
1938
  }
1939
1939
  } catch (e) {
1940
1940
  resolve('0');
1941
1941
  }
1942
1942
  window[getCallBackName] = null;
1943
1943
  };
1944
1944
  }
1945
1945
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1946
1946
  method: 'callSyncRouterModuleWithParams',
1947
1947
  params: JSON.stringify({
1948
1948
  routerURL: 'router://JDBModeModule/getCurrentMode',
1949
1949
  routerParam: {},
1950
1950
  callBackName: `window.${getCallBackName}`,
1951
1951
  callBackId: `${getCallBackName}Ios`,
1952
1952
  }),
1953
1953
  });
1954
1954
  }),
1955
1955
  ]);
1956
1956
  }
1957
1957
  }
1958
1958
  }
1959
1959
  getAPPUseStraightCorner() {
1960
1960
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
1961
1961
  const params = {
1962
1962
  routerURL,
1963
1963
  routerParam: {},
1964
1964
  jdRouter: '1',
1965
1965
  };
1966
1966
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
1967
1967
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
1968
1968
  } else {
1969
1969
  return this.jmfeReayPromise()
1970
1970
  .then(() => {
1971
1971
  if (isJdAndHarmonyDevice || !isJdApp) {
1972
1972
  console.log('not APP or is Harmony');
1973
1973
  return Promise.resolve(false);
1974
1974
  }
1975
1975
  console.log('jmfe setShareInfo', params);
1976
1976
  return Promise.race([
1977
1977
  window.jmfe.callRouter(params),
1978
1978
  this.taskTimeoutPromise(() => {
1979
1979
  return false;
1980
1980
  }),
1981
1981
  ]).then(({ status, data }) => {
1982
1982
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
1983
1983
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
1984
1984
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
1985
1985
  return Promise.resolve(status === '0' && Number(data) === 1);
1986
1986
  });
1987
1987
  })
1988
1988
  .catch((e) => {
1989
1989
  console.log('jmfe error', e);
1990
1990
  return Promise.resolve(false);
1991
1991
  });
1992
1992
  }
1993
1993
  }
1994
1994
 
1995
1995
  getJDAppearanceStatePromise() {
1996
1996
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1997
1997
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
1998
1998
  } else {
1999
1999
  return Promise.race([
2000
2000
  this.taskTimeoutPromise(() => {
2001
2001
  this.info.sysInfo.jdAppearanceState = '0';
2002
2002
  return this.info.sysInfo.jdAppearanceState;
2003
2003
  }),
2004
2004
  new Promise((resolve) => {
2005
2005
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
2006
2006
  if (!window[getCallBackName]) {
2007
2007
  window[getCallBackName] = (res) => {
2008
2008
  try {
2009
2009
  console.log('getJDAppearanceStatePromise', res);
2010
2010
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2011
2011
  const { status, data, msg } = getResJson;
2012
2012
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
2013
2013
  if (status === '0') {
2014
2014
  this.info.sysInfo.jdAppearanceState = data;
2015
2015
  resolve(data);
2016
2016
  } else {
2017
2017
  resolve('0');
2018
2018
  }
2019
2019
  } catch (e) {
2020
2020
  resolve('0');
2021
2021
  }
2022
2022
  window[getCallBackName] = null;
2023
2023
  };
2024
2024
  }
2025
2025
  if (isAndroidDevice) {
2026
2026
  const jsonString = JSON.stringify({
2027
2027
  callBackName: `window.${getCallBackName}`,
2028
2028
  });
2029
2029
  console.log('window.JDAppearance', window?.JDAppearance);
2030
2030
  window?.JDAppearance &&
2031
2031
  window?.JDAppearance?.getUiState &&
2032
2032
  window.JDAppearance.getUiState(jsonString);
2033
2033
  } else {
2034
2034
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
2035
2035
  method: 'callSyncRouterModuleWithParams',
2036
2036
  params: JSON.stringify({
2037
2037
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
2038
2038
  routerParam: {},
2039
2039
  callBackName: `window.${getCallBackName}`,
2040
2040
  callBackId: `${getCallBackName}Ios`,
2041
2041
  }),
2042
2042
  });
2043
2043
  }
2044
2044
  }),
2045
2045
  ]);
2046
2046
  }
2047
2047
  }
2048
2048
 
2049
2049
  createJdAndroidRquestEventForTouchStart() {
2050
2050
  if (isJdAndAndroidDevice && window?.JdAndroid) {
2051
2051
  const rootEleNode = document.querySelector('body');
2052
2052
  if (rootEleNode) {
2053
2053
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
2054
2054
  }
2055
2055
  }
2056
2056
  }
2057
2057
  jdAndroidAddEventListenerTouchStart(e) {
2058
2058
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
2059
2059
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
2060
2060
  const hasCustomEle = e
2061
2061
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
2062
2062
  : false;
2063
2063
  if (!hasCustomEle) {
2064
2064
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
2065
2065
  console.log(
2066
2066
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
2067
2067
  );
2068
2068
  }
2069
2069
  }
2070
2070
  }
2071
2071
  removeJdAndroidRquestEventForTouchStart() {
2072
2072
  if (isJdAndAndroidDevice && window.JdAndroid) {
2073
2073
  const rootEleNode = document.querySelector('body');
2074
2074
  if (rootEleNode) {
2075
2075
  rootEleNode.removeEventListener(
2076
2076
  'touchstart',
2077
2077
  this.jdAndroidAddEventListenerTouchStart,
2078
2078
  false,
2079
2079
  );
2080
2080
  }
2081
2081
  }
2082
2082
  }
2083
2083
 
2084
2084
  getNetWorkType() {
2085
2085
  if (isJdApp) {
2086
2086
  this.jmfeReayPromise().then(() => {
2087
2087
  window.jmfe
2088
2088
  .getNetworkStatus()
2089
2089
  .then(({ status, data }) => {
2090
2090
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
2091
2091
  if (status === '0') {
2092
2092
  this.info.sysInfo['netWorkType'] = data;
2093
2093
  } else {
2094
2094
  this._taroGetNetworkType();
2095
2095
  }
2096
2096
  })
2097
2097
  .catch((err) => {
2098
2098
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
2099
2099
  this._taroGetNetworkType();
2100
2100
  });
2101
2101
  });
2102
2102
  } else {
2103
2103
  this._taroGetNetworkType();
2104
2104
  }
2105
2105
  }
2106
2106
  _taroGetNetworkType() {
2107
2107
  Taro.getNetworkType().then((getRes) => {
2108
2108
  if (getRes && getRes.networkType) {
2109
2109
  this.info.sysInfo['netWorkType'] = getRes.networkType;
2110
2110
  console.log(
2111
2111
  '在app内通过taro对象获取网络状态完成,当前网络状态',
2112
2112
  this.info.sysInfo['netWorkType'],
2113
2113
  );
2114
2114
  }
2115
2115
  });
2116
2116
  }
2117
2117
 
2118
2118
  getJdAppBaseInfo() {
2119
2119
  const appKeyCacheToCookieMinuteTime =
2120
2120
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
2121
2121
  appUuidCacheToCookieMinuteTime =
2122
2122
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
2123
2123
  getAppKey = cookie.get(cacheAppKey),
2124
2124
  getAppUuidKey = cookie.get(cacheAppUuidKey);
2125
2125
  console.log(
2126
2126
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
2127
2127
  cacheAppKey,
2128
2128
  getAppKey,
2129
2129
  cacheAppUuidKey,
2130
2130
  getAppUuidKey,
2131
2131
  );
2132
2132
  if (
2133
2133
  appKeyCacheToCookieMinuteTime &&
2134
2134
  appUuidCacheToCookieMinuteTime &&
2135
2135
  getAppKey &&
2136
2136
  getAppUuidKey
2137
2137
  ) {
2138
2138
  const [uuid, eufv] = getAppUuidKey.split('@');
2139
2139
  const baseApiKeyParam = {
2140
2140
  uuid,
2141
2141
  };
2142
2142
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
2143
2143
  if (eufv === '1' && /-/.test(uuid)) {
2144
2144
  const [eu, fv] = uuid.split('-');
2145
2145
  baseApiKeyParam['eu'] = eu;
2146
2146
  baseApiKeyParam['fv'] = fv;
2147
2147
  }
2148
2148
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
2149
2149
  this.jmfeReayPromise().then(() => {
2150
2150
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
2151
2151
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
2152
2152
  });
2153
2153
  } else {
2154
2154
  const checkGetJdAppKeyState =
2155
2155
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
2156
2156
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
2157
2157
  this.jmfeReayPromise().then(() => {
2158
2158
  Promise.all([
2159
2159
  checkGetJdAppKeyState && window.jmfe?.callNative
2160
2160
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
2161
2161
  : Promise.resolve({
2162
2162
  status: '-1000',
2163
2163
  msg: '当前版本不支持获取松果app中的getAppKey',
2164
2164
  data: '-1000',
2165
2165
  }),
2166
2166
  window.jmfe.getDeviceInfo(),
2167
2167
  ]).then((resList) => {
2168
2168
  const [getAppKeyRes, deviceInfoRes] = resList;
2169
2169
  console.log(
2170
2170
  '在app内初始化通过jmfe获取getAppKey结果',
2171
2171
  getAppKeyRes,
2172
2172
  '通过jmfe获取getDeviceInfo获取结果',
2173
2173
  deviceInfoRes,
2174
2174
  );
2175
2175
  const baseApiKeyParam = {};
2176
2176
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
2177
2177
  const getJmfeAppKey = getAppKeyRes?.data;
2178
2178
  if (getJmfeAppKey && getJmfeAppKey !== '') {
2179
2179
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
2180
2180
  const getJdAppKeyCacheToCookieMinuteTime =
2181
2181
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
2182
2182
  if (getJdAppKeyCacheToCookieMinuteTime) {
2183
2183
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
2184
2184
  cookie.set(cacheAppKey, getJmfeAppKey, {
2185
2185
  path: '/',
2186
2186
  expires,
2187
2187
  });
2188
2188
  }
2189
2189
  }
2190
2190
  }
2191
2191
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
2192
2192
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
2193
2193
  if (uuid && uuid !== '') {
2194
2194
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
2195
2195
  baseApiKeyParam['uuid'] = uuid;
2196
2196
  if (eufv === '1' && /-/.test(uuid)) {
2197
2197
  const [eu, fv] = uuid.split('-');
2198
2198
  baseApiKeyParam['eu'] = eu;
2199
2199
  baseApiKeyParam['fv'] = fv;
2200
2200
  }
2201
2201
  const getAppUuidCacheToCookieMinuteTime =
2202
2202
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
2203
2203
  if (getAppUuidCacheToCookieMinuteTime) {
2204
2204
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
2205
2205
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
2206
2206
  path: '/',
2207
2207
  expires,
2208
2208
  });
2209
2209
  }
2210
2210
  }
2211
2211
  }
2212
2212
  console.log(
2213
2213
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
2214
2214
  baseApiKeyParam,
2215
2215
  );
2216
2216
  if (Object.keys(baseApiKeyParam).length > 0) {
2217
2217
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
2218
2218
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
2219
2219
  }
2220
2220
  });
2221
2221
  });
2222
2222
  }
2223
2223
  }
2224
2224
 
2225
2225
  getCacheAddressRouter() {
2226
2226
  if (isJdApp) {
2227
2227
  if (!isJdAndHarmonyDevice) {
2228
2228
  return Promise.race([
2229
2229
  new Promise((resolve) => {
2230
2230
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
2231
2231
  if (!window[getCallBackName]) {
2232
2232
  window[getCallBackName] = (res) => {
2233
2233
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
2234
2234
  try {
2235
2235
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2236
2236
  resolve(getResJson);
2237
2237
  } catch (e) {
2238
2238
  resolve({
2239
2239
  status: '-1002',
2240
2240
  msg: '地址信息解析json异常',
2241
2241
  res,
2242
2242
  });
2243
2243
  }
2244
2244
  window[getCallBackName] = null;
2245
2245
  };
2246
2246
  }
2247
2247
  const getRouterParam = {
2248
2248
  sceneId: 'basicShoppingProcess',
2249
2249
  };
2250
2250
  if (isAndroidDevice) {
2251
2251
  return callRouterAndroid({
2252
2252
  routerURL: 'router://JDAddressModule/getCacheAddress',
2253
2253
  routerParam: getRouterParam,
2254
2254
  callBackName: getCallBackName,
2255
2255
  isSync: true,
2256
2256
  });
2257
2257
  } else {
2258
2258
  return callRouterIOS({
2259
2259
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
2260
2260
  routerParam: getRouterParam,
2261
2261
  callBackName: getCallBackName,
2262
2262
  });
2263
2263
  }
2264
2264
  }),
2265
2265
  this.taskTimeoutPromise(() => {
2266
2266
  return {
2267
2267
  status: '-1000',
2268
2268
  msg: '原生router协议获取地址信息超时',
2269
2269
  };
2270
2270
  }, 3000),
2271
2271
  ]);
2272
2272
  } else {
2273
2273
  return Promise.race([
2274
2274
  new Promise((resolve) => {
2275
2275
  this.jmfeReayPromise()
2276
2276
  .then(() => {
2277
2277
  const plugin = 'JDHybridRouterPlugin';
2278
2278
  const action = 'callSyncRouterModuleWithParams';
2279
2279
  const params = {
2280
2280
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
2281
2281
  routerParam: '',
2282
2282
  };
2283
2283
  const sync = '1';
2284
2284
  try {
2285
2285
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
2286
2286
  resolve(res);
2287
2287
  });
2288
2288
  } catch (error) {
2289
2289
  resolve({
2290
2290
  status: '-1001',
2291
2291
  msg: '判断jmfe不存在,获取经纬度信息异常',
2292
2292
  });
2293
2293
  }
2294
2294
  })
2295
2295
  .catch(() => {
2296
2296
  resolve({
2297
2297
  status: '-1002',
2298
2298
  msg: '鸿蒙系统调用jmfe异常,获取失败',
2299
2299
  });
2300
2300
  });
2301
2301
  }),
2302
2302
  this.taskTimeoutPromise(() => {
2303
2303
  return {
2304
2304
  status: '-1000',
2305
2305
  msg: '原生router协议获取地址信息超时',
2306
2306
  };
2307
2307
  }, 3000),
2308
2308
  ]);
2309
2309
  }
2310
2310
  } else if (isH5AndJingGouMini) {
2311
2311
  return Promise.resolve({
2312
2312
  status: '-1002',
2313
2313
  msg: '普通h5暂无业务需要,未实现,获取失败',
2314
2314
  });
2315
2315
  } else {
2316
2316
  return Promise.resolve({
2317
2317
  status: '-1002',
2318
2318
  msg: '普通h5暂无业务需要,未实现,获取失败',
2319
2319
  });
2320
2320
  }
2321
2321
  }
2322
2322
 
2323
2323
  getAddressCachePromise() {
2324
2324
  return new Promise((resolve) => {
2325
2325
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
2326
2326
  resolve({
2327
2327
  lat: this.info.sysInfo.lat,
2328
2328
  lng: this.info.sysInfo.lng,
2329
2329
  area: this?.info?.sysInfo?.area,
2330
2330
  });
2331
2331
  } else {
2332
2332
  this.getCacheAddressRouter()
2333
2333
  .then((res) => {
2334
2334
  const { status, data } = res;
2335
2335
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
2336
2336
  if (status === '0' && data) {
2337
2337
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
2338
2338
  data || {};
2339
2339
  let area = '';
2340
2340
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
2341
2341
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
2342
2342
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
2343
2343
  if (getProvinceIdNum && getProvinceIdNum > 0) {
2344
2344
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
2345
2345
  this.info.pageInfo['address'] = area;
2346
2346
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
2347
2347
  this.info.sysInfo['area'] = area;
2348
2348
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
2349
2349
  area: this.info.pageInfo.address,
2350
2350
  });
2351
2351
  }
2352
2352
  resolve({
2353
2353
  lat: this.info.sysInfo['lat'],
2354
2354
  lng: this.info.sysInfo['lng'],
2355
2355
  area: area,
2356
2356
  });
2357
2357
  } else {
2358
2358
  if (typeof res === 'object') {
2359
2359
  draBusinessCustomReport({
2360
2360
  eventName: 'business',
2361
2361
  errorName: 'jdapp_getCacheAddress_info_err',
2362
2362
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
2363
2363
  extraData: JSON.stringify({
2364
2364
  isJdApp,
2365
2365
  jdAppVersion: jdAppVersionStr,
2366
2366
  ...res,
2367
2367
  }),
2368
2368
  });
2369
2369
  }
2370
2370
  resolve({ lat: '', lng: '', area: '' });
2371
2371
  }
2372
2372
  })
2373
2373
  .catch((e) => {
2374
2374
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
2375
2375
  draBusinessCustomReport({
2376
2376
  eventName: 'business',
2377
2377
  errorName: 'jdapp_getCacheAddress_info_catch_err',
2378
2378
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
2379
2379
  extraData: JSON.stringify({
2380
2380
  isJdApp,
2381
2381
  jdAppVersion: jdAppVersionStr,
2382
2382
  }),
2383
2383
  });
2384
2384
  resolve({ lat: '', lng: '', area: '' });
2385
2385
  });
2386
2386
  }
2387
2387
  });
2388
2388
  }
2389
2389
 
2390
2390
  getLbsCacheAddressRouter() {
2391
2391
  if (isJdApp) {
2392
2392
  if (!isJdAndHarmonyDevice) {
2393
2393
  return Promise.race([
2394
2394
  new Promise((resolve) => {
2395
2395
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
2396
2396
  if (!window[getCallBackName]) {
2397
2397
  window[getCallBackName] = (res) => {
2398
2398
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
2399
2399
  try {
2400
2400
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2401
2401
  resolve(getResJson);
2402
2402
  } catch (e) {
2403
2403
  resolve({
2404
2404
  status: '-1002',
2405
2405
  msg: '地址信息解析json异常',
2406
2406
  res,
2407
2407
  });
2408
2408
  }
2409
2409
  window[getCallBackName] = null;
2410
2410
  };
2411
2411
  }
2412
2412
  const getRouterParam = {
2413
2413
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
2414
2414
  sceneId: 'basicShoppingProcess',
2415
2415
  };
2416
2416
  if (isAndroidDevice) {
2417
2417
  return callRouterAndroid({
2418
2418
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
2419
2419
  routerParam: getRouterParam,
2420
2420
  callBackName: getCallBackName,
2421
2421
  isSync: true,
2422
2422
  hasJdRouter: false,
2423
2423
  });
2424
2424
  } else {
2425
2425
  return callRouterIOS({
2426
2426
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
2427
2427
  routerParam: getRouterParam,
2428
2428
  callBackName: getCallBackName,
2429
2429
  isSync: true,
2430
2430
  });
2431
2431
  }
2432
2432
  }),
2433
2433
  this.taskTimeoutPromise(() => {
2434
2434
  return {
2435
2435
  status: '-1000',
2436
2436
  msg: '原生router协议获取lbs地址信息3s超时',
2437
2437
  };
2438
2438
  }, 3000),
2439
2439
  ]);
2440
2440
  } else {
2441
2441
  return Promise.resolve({
2442
2442
  status: '-1001',
2443
2443
  msg: '鸿蒙系统调用未实现,获取失败',
2444
2444
  });
2445
2445
  }
2446
2446
  } else if (isH5AndJingGouMini) {
2447
2447
  return this.getLocationForGpsPromise();
2448
2448
  } else {
2449
2449
  return Promise.resolve({
2450
2450
  status: '-1002',
2451
2451
  msg: '普通h5暂无业务需要,未实现,获取失败',
2452
2452
  });
2453
2453
  }
2454
2454
  }
2455
2455
  getLocationForGpsPromise() {
2456
2456
  return new Promise((resolve) => {
2457
2457
  let hasGetLocationForGps = true;
2458
2458
  if (urlCookie && urlCookie['loc']) {
2459
2459
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
2460
2460
  urlCookie['loc'].split('_');
2461
2461
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
2462
2462
  if (getProvinceIdNum && getProvinceIdNum > 0) {
2463
2463
  hasGetLocationForGps = false;
2464
2464
  resolve({
2465
2465
  status: '0',
2466
2466
  data: {
2467
2467
  provinceid,
2468
2468
  cityid,
2469
2469
  districtid,
2470
2470
  townid,
2471
2471
  origin: 'wxapp',
2472
2472
  },
2473
2473
  });
2474
2474
  }
2475
2475
  }
2476
2476
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
2477
2477
  window.navigator.geolocation.getCurrentPosition(
2478
2478
  (position) => {
2479
2479
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
2480
2480
  if (position?.coords) {
2481
2481
  resolve({
2482
2482
  status: '0',
2483
2483
  data: {
2484
2484
  srclat: position.coords?.latitude,
2485
2485
  srclng: position.coords.longitude,
2486
2486
  origin: 'h5',
2487
2487
  },
2488
2488
  });
2489
2489
  } else {
2490
2490
  resolve({
2491
2491
  status: '-1001',
2492
2492
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
2493
2493
  position,
2494
2494
  });
2495
2495
  }
2496
2496
  },
2497
2497
  (error) => {
2498
2498
  resolve({
2499
2499
  status: '-1001',
2500
2500
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
2501
2501
  error,
2502
2502
  });
2503
2503
  },
2504
2504
  {
2505
2505
  enableHighAccuracy: false,
2506
2506
  timeout: 3 * 1000,
2507
2507
  maximumAge: 10 * 60 * 1000,
2508
2508
  },
2509
2509
  );
2510
2510
  } else {
2511
2511
  resolve({
2512
2512
  status: '-1001',
2513
2513
  msg: '您的浏览器不支持地理定位',
2514
2514
  });
2515
2515
  }
2516
2516
  });
2517
2517
  }
2518
2518
 
2519
2519
  createLbsCacheAddress(realTimeArea) {
2520
2520
  const getLbsAddressCacheMinuteTime = Number(
2521
2521
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
2522
2522
  );
2523
2523
  console.log(
2524
2524
  '获取lbs缓存到cookie的时间,分钟',
2525
2525
  getLbsAddressCacheMinuteTime,
2526
2526
  'lbsAddressCacheToCookieMinuteTime',
2527
2527
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
2528
2528
  );
2529
2529
  if (getLbsAddressCacheMinuteTime > 0) {
2530
2530
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
2531
2531
  realTimeArea &&
2532
2532
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
2533
2533
  path: '/',
2534
2534
  expires,
2535
2535
  });
2536
2536
  }
2537
2537
  }
2538
2538
 
2539
2539
  getLbsAddressCachePromise() {
2540
2540
  if (!this.lbsAddressCachePromise) {
2541
2541
  this.lbsAddressCachePromise = new Promise((resolve) => {
2542
2542
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
2543
2543
  ? cookie.get(cacheH5LbsAddressKey)
2544
2544
  : '';
2545
2545
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
2546
2546
  if (getUserLbsAddress && getUserLbsAddress !== '') {
2547
2547
  resolve({
2548
2548
  ok: true,
2549
2549
  realTimeArea: getUserLbsAddress,
2550
2550
  });
2551
2551
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
2552
2552
  console.info(
2553
2553
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
2554
2554
  getCookieForLbsAddress,
2555
2555
  );
2556
2556
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
2557
2557
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
2558
2558
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
2559
2559
  realTimeArea: getCookieForLbsAddress,
2560
2560
  });
2561
2561
  resolve({
2562
2562
  ok: true,
2563
2563
  realTimeArea: getCookieForLbsAddress,
2564
2564
  });
2565
2565
  } else {
2566
2566
  this.getLbsCacheAddressRouter()
2567
2567
  .then((res) => {
2568
2568
  const { status, data } = res;
2569
2569
  console.log(
2570
2570
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
2571
2571
  status,
2572
2572
  data,
2573
2573
  res,
2574
2574
  );
2575
2575
  if (status === '0' && data) {
2576
2576
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
2577
2577
  data || {};
2578
2578
  let realTimeArea = '';
2579
2579
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
2580
2580
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
2581
2581
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
2582
2582
  if (getProvinceIdNum && getProvinceIdNum > 0) {
2583
2583
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
2584
2584
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
2585
2585
  this.info.sysInfo['realTimeArea'] = realTimeArea;
2586
2586
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
2587
2587
  realTimeArea: this.info.pageInfo.userLbsAddress,
2588
2588
  });
2589
2589
  this.createLbsCacheAddress(realTimeArea);
2590
2590
  } else {
2591
2591
  !origin && (this.lbsAddressCachePromise = null);
2592
2592
  }
2593
2593
  const getValidRealTimeArea = realTimeArea !== '';
2594
2594
  resolve({
2595
2595
  lat: this.info.sysInfo['srclat'],
2596
2596
  lng: this.info.sysInfo['srclng'],
2597
2597
  realTimeArea: realTimeArea,
2598
2598
  ok: getValidRealTimeArea,
2599
2599
  msg: getValidRealTimeArea
2600
2600
  ? '成功'
2601
2601
  : origin
2602
2602
  ? origin
2603
2603
  : '根据router底层获取lbs地址信息异常,详情见data',
2604
2604
  data: getValidRealTimeArea ? null : res,
2605
2605
  });
2606
2606
  if (!getValidRealTimeArea && !origin) {
2607
2607
  draBusinessCustomReport({
2608
2608
  eventName: 'business',
2609
2609
  errorName: 'h5_getLbsCacheAddress_info_err',
2610
2610
  errorMessage:
2611
2611
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
2612
2612
  extraData: JSON.stringify({
2613
2613
  isJdApp,
2614
2614
  jdAppVersion: jdAppVersionStr,
2615
2615
  }),
2616
2616
  });
2617
2617
  }
2618
2618
  } else {
2619
2619
  typeof res === 'object' &&
2620
2620
  draBusinessCustomReport({
2621
2621
  eventName: 'business',
2622
2622
  errorName: 'h5_getLbsCacheAddress_info_err',
2623
2623
  errorMessage:
2624
2624
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
2625
2625
  extraData: JSON.stringify({
2626
2626
  isJdApp,
2627
2627
  jdAppVersion: jdAppVersionStr,
2628
2628
  ...res,
2629
2629
  }),
2630
2630
  });
2631
2631
  this.lbsAddressCachePromise = null;
2632
2632
  resolve({ realTimeArea: '', ok: false });
2633
2633
  }
2634
2634
  })
2635
2635
  .catch((e) => {
2636
2636
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
2637
2637
  this.lbsAddressCachePromise = null;
2638
2638
  draBusinessCustomReport({
2639
2639
  eventName: 'business',
2640
2640
  errorName: 'h5_getLbsCacheAddress_info_err',
2641
2641
  errorMessage:
2642
2642
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
2643
2643
  extraData: JSON.stringify({
2644
2644
  isJdApp,
2645
2645
  jdAppVersion: jdAppVersionStr,
2646
2646
  }),
2647
2647
  });
2648
2648
  resolve({ realTimeArea: '', ok: false });
2649
2649
  });
2650
2650
  }
2651
2651
  });
2652
2652
  }
2653
2653
  return this.lbsAddressCachePromise;
2654
2654
  }
2655
2655
 
2656
2656
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
2657
2657
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
2658
2658
  if (!isJdApp) {
2659
2659
  return;
2660
2660
  }
2661
2661
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
2662
2662
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
2663
2663
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
2664
2664
  'hybridHttpSwitch',
2665
2665
  isBeforePageReady,
2666
2666
  );
2667
2667
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
2668
2668
  'jshopIsVipShop',
2669
2669
  isBeforePageReady,
2670
2670
  );
2671
2671
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
2672
2672
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
2673
2673
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
2674
2674
  'isFollowAppVideoPlayStatus',
2675
2675
  isBeforePageReady,
2676
2676
  );
2677
2677
  console.log(
2678
2678
  'isBeforePageReady:',
2679
2679
  isBeforePageReady,
2680
2680
  'isFollowAppVideoPlayStatus:',
2681
2681
  isFollowAppVideoPlayStatus,
2682
2682
  );
2683
2683
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
2684
2684
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
2685
2685
  }
2686
2686
  }
2687
2687
 
2688
2688
  async getWifiVideoAutoPlayAsync() {
2689
2689
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
2690
2690
  if (!isJdApp) {
2691
2691
  return;
2692
2692
  }
2693
2693
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
2694
2694
  return 0;
2695
2695
  });
2696
2696
  if (Number(videoPlayStatus) === 1) {
2697
2697
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
2698
2698
  }
2699
2699
  }
2700
2700
 
2701
2701
  async getMPaasConfigAsync() {
2702
2702
  this.info.sysInfo.dynamicConfig = {};
2703
2703
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
2704
2704
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
2705
2705
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
2706
2706
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
2707
2707
  return this.updateMPaasConfigAsync(true);
2708
2708
  }
2709
2709
 
2710
2710
  getDynamicConfig(key: string) {
2711
2711
  return this.info.sysInfo?.dynamicConfig?.[key];
2712
2712
  }
2713
2713
  async updateMPaasConfig() {
2714
2714
  console.log('updateMPaasConfig');
2715
2715
  if (
2716
2716
  isIosDevice &&
2717
2717
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
2718
2718
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
2719
2719
  ) {
2720
2720
  try {
2721
2721
  await this.updateMPaasConfigAsync(false);
2722
2722
  } catch (e) {
2723
2723
  console.log('updateMPaasConfigAsync:', e);
2724
2724
  }
2725
2725
  }
2726
2726
  }
2727
2727
 
2728
2728
  toLogin(options) {
2729
2729
  if (isAscfApp) {
2730
2730
  return this.toAscfAppLogin(options);
2731
2731
  }
2732
2732
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
2733
2733
  ? this.toWxAppLogin(options)
2734
2734
  : this.toWebLogin(options);
2735
2735
  }
2736
2736
 
2737
2737
  doLogin(options) {
2738
2738
  return this.toLogin(options);
2739
2739
  }
2740
2740
 
2741
2741
  doLoginForJdPin(options = {}) {
2742
2742
  return this.doLogin({
2743
2743
  loginColor: {
2744
2744
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2745
2745
  dpin: 0,
2746
2746
  },
2747
2747
  ...options,
2748
2748
  });
2749
2749
  }
2750
2750
 
2751
2751
  toWebLogin(options) {
2752
2752
  let params: {
2753
2753
  returnurl: string;
2754
2754
  } = {
2755
2755
  returnurl: '',
2756
2756
  };
2757
2757
  const checkToPcLogin = options ? options?.isPc : isPc;
2758
2758
  const loginUrl = checkToPcLogin
2759
2759
  ? `//passport.jd.com/new/login.aspx`
2760
2760
  : `${domain.mobileLogin}/user/login.action`;
2761
2761
  const defaultParams = {
2762
2762
  appid: '100',
2763
2763
  returnurl: window.location.href,
2764
2764
  };
2765
2765
  if (isString(options)) {
2766
2766
  params = Object.assign({}, defaultParams, {
2767
2767
  returnurl: options,
2768
2768
  });
2769
2769
  } else if (isObject(options)) {
2770
2770
  const { loginColor, ...otherOptions } = options;
2771
2771
  params = Object.assign({}, defaultParams, otherOptions);
2772
2772
  } else {
2773
2773
  params = defaultParams;
2774
2774
  }
2775
2775
  params.returnurl = encodeURIComponent(params.returnurl);
2776
2776
  let getFullUrl = loginUrl + '?' + serialize(params);
2777
2777
  if (checkToPcLogin) {
2778
2778
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
2779
2779
  }
2780
2780
  return Promise.resolve({
2781
2781
  h5ToUrl: true,
2782
2782
  url: getFullUrl,
2783
2783
  }).then(() => {
2784
2784
  window.location.href = getFullUrl;
2785
2785
  });
2786
2786
  }
2787
2787
 
2788
2788
  toAscfAppLogin(options = {}) {
2789
2789
  console.log('华为元服务中h5登录跳转', options);
2790
2790
  return Promise.resolve(true).then(() => {
2791
2791
  const returnPage = encodeURIComponent(window.location.href);
2792
2792
  if (has && has.ascfweb) {
2793
2793
  has.ascfweb.redirectTo({
2794
2794
  url: `/pages/login/index/index?isH5=1&returnPage=${returnPage}&pageType=h5&source=shopx`,
2795
2795
  });
2796
2796
  }
2797
2797
  });
2798
2798
  }
2799
2799
 
2800
2800
  toWxAppLogin(options = {}) {
2801
2801
  console.log('微信京购小程序中h5登录跳转', options);
2802
2802
  return Promise.resolve(true).then(() => {
2803
2803
  const { loginColor } = Object.assign(
2804
2804
  {},
2805
2805
  {
2806
2806
  loginColor: {
2807
2807
  biz: WXAPP_BIZ_KEY,
2808
2808
  dpin: 1,
2809
2809
  },
2810
2810
  },
2811
2811
  options,
2812
2812
  );
2813
2813
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
2814
2814
  loginColor.biz
2815
2815
  }&url=${encodeURIComponent(window.location.href)}`;
2816
2816
  });
2817
2817
  }
2818
2818
 
2819
2819
  getLoginCookie() {
2820
2820
  return Promise.resolve({
2821
2821
  pin: cookie.get('pin') || '',
2822
2822
  });
2823
2823
  }
2824
2824
 
2825
2825
  clearLoginCookie() {
2826
2826
  cookie.remove('pin');
2827
2827
  }
2828
2828
 
2829
2829
  checkStatusAndLogin(options = {}) {
2830
2830
  if (!this.checkStatusAndLoginPromise) {
2831
2831
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
2832
2832
  try {
2833
2833
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2834
2834
  if (getLoginState) {
2835
2835
  resolve(true);
2836
2836
  } else {
2837
2837
  this.toLogin(options);
2838
2838
  reject(false);
2839
2839
  }
2840
2840
  } catch (e) {
2841
2841
  this.toLogin(options);
2842
2842
  reject(false);
2843
2843
  }
2844
2844
  });
2845
2845
  return this.checkStatusAndLoginPromise;
2846
2846
  } else {
2847
2847
  return this.checkStatusAndLoginPromise
2848
2848
  .then(() => {
2849
2849
  return Promise.resolve(true);
2850
2850
  })
2851
2851
  .catch(() => {
2852
2852
  this.toLogin(options);
2853
2853
  return Promise.reject(true);
2854
2854
  });
2855
2855
  }
2856
2856
  }
2857
2857
 
2858
2858
  checkJdStatusAndLogin(
2859
2859
  options = {
2860
2860
  loginColor: {
2861
2861
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2862
2862
  dpin: 0,
2863
2863
  },
2864
2864
  },
2865
2865
  ) {
2866
2866
  return this.checkStatusAndLogin(options);
2867
2867
  }
2868
2868
 
2869
2869
  doCheckLoginStateAndForApiCheck(options) {
2870
2870
  if (this.info.loginState) {
2871
2871
  return Promise.resolve(true);
2872
2872
  } else {
2873
2873
  return new Promise((resolve, reject) => {
2874
2874
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
2875
2875
  const getWqAuthToken = cookie.get('wq_auth_token');
2876
2876
  const getWqSkey = cookie.get('wq_skey');
2877
2877
  const getWqUin = cookie.get('wq_uin');
2878
2878
  const isLoginState =
2879
2879
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
2880
2880
  if (isLoginState) {
2881
2881
  this.info.loginState = true;
2882
2882
  resolve(true);
2883
2883
  } else {
2884
2884
  reject(false);
2885
2885
  }
2886
2886
  } else {
2887
2887
  Taro.request({
2888
2888
  url: api.isLogin,
2889
2889
  jsonp: true,
2890
2890
  timeout: 3000,
2891
2891
  success: (res) => {
2892
2892
  const { statusCode, data } = res;
2893
2893
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
2894
2894
  this.info.loginState = true;
2895
2895
  resolve(true);
2896
2896
  } else {
2897
2897
  reject(false);
2898
2898
  }
2899
2899
  },
2900
2900
  fail: (err) => {
2901
2901
  console.log('登录检查异常', err);
2902
2902
  reject(false);
2903
2903
  },
2904
2904
  });
2905
2905
  }
2906
2906
  });
2907
2907
  }
2908
2908
  }
2909
2909
 
2910
2910
  checkLoginStatus(options) {
2911
2911
  return new Promise(async (resolve, reject) => {
2912
2912
  try {
2913
2913
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2914
2914
  if (getLoginState) {
2915
2915
  const { pin } = await this.getLoginCookie();
2916
2916
  this.info.userInfo = {
2917
2917
  pin,
2918
2918
  encodePin: encodeURIComponent(pin),
2919
2919
  ptkey: '',
2920
2920
  };
2921
2921
  resolve(true);
2922
2922
  } else {
2923
2923
  reject(false);
2924
2924
  }
2925
2925
  } catch (e) {
2926
2926
  reject(false);
2927
2927
  }
2928
2928
  });
2929
2929
  }
2930
2930
 
2931
2931
  updatePageAndLogInfo(updateQuery = {}) {
2932
2932
  const createUpdateQueryInfo: {
2933
2933
  query: {
2934
2934
  shopId?: string | number;
2935
2935
  venderId?: string | number;
2936
2936
  };
2937
2937
  updateShopInfoState: boolean;
2938
2938
  } = Object.assign(
2939
2939
  {},
2940
2940
  {
2941
2941
  query: {},
2942
2942
  updateShopInfoState: false,
2943
2943
  },
2944
2944
  updateQuery,
2945
2945
  );
2946
2946
  console.log(
2947
2947
  '获取当前下发的店铺查询参数',
2948
2948
  updateQuery,
2949
2949
  '获取之前保存的shopInfo店铺查询参数',
2950
2950
  this.info?.shopInfo,
2951
2951
  );
2952
2952
  const { query, updateShopInfoState } = createUpdateQueryInfo;
2953
2953
  const { shopId, venderId, un_area } = query;
2954
2954
  if (updateShopInfoState) {
2955
2955
  this.info.queryInfo = {
2956
2956
  ...this.info.queryInfo,
2957
2957
  ...query,
2958
2958
  };
2959
2959
  if (shopId && venderId) {
2960
2960
  this.info.shopInfo = {
2961
2961
  shopId: `${shopId}`,
2962
2962
  venderId: `${venderId}`,
2963
2963
  };
2964
2964
  }
2965
2965
  } else {
2966
2966
  this.info.queryInfo = {
2967
2967
  ...query,
2968
2968
  };
2969
2969
  if (
2970
2970
  this.info.shopInfo?.shopId &&
2971
2971
  this.info.shopInfo?.venderId &&
2972
2972
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
2973
2973
  ) {
2974
2974
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
2975
2975
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
2976
2976
  console.log(
2977
2977
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
2978
2978
  this.info.queryInfo,
2979
2979
  );
2980
2980
  }
2981
2981
  }
2982
2982
  this.info.queryInfo['shopId'] &&
2983
2983
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
2984
2984
  this.info.queryInfo['venderId'] &&
2985
2985
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
2986
2986
  console.log(
2987
2987
  'h5==获取店铺下发查询参数\n',
2988
2988
  query,
2989
2989
  '\n获取店铺最后查询参数\n',
2990
2990
  this.info.queryInfo,
2991
2991
  '\n是否为更新店铺状态\n',
2992
2992
  updateShopInfoState,
2993
2993
  );
2994
2994
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
2995
2995
  if (changeArea) {
2996
2996
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
2997
2997
  this.info.pageInfo.address = getBottomAreaStr;
2998
2998
  this.info.pageInfo.un_area = getBottomAreaStr;
2999
2999
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
3000
3000
  }
3001
3001
  }
3002
3002
 
3003
3003
  dealLoadSdkList() {
3004
3004
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
3005
3005
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
3006
3006
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
3007
3007
  let mergeLoadJsList = globalLoadJsList;
3008
3008
  try {
3009
3009
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
3010
3010
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
3011
3011
  getFindIndex !== -1
3012
3012
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
3013
3013
  : accArr.push(current);
3014
3014
  return accArr;
3015
3015
  }, []);
3016
3016
  } catch (e) {
3017
3017
  console.log('LoadJsList合并错误', e);
3018
3018
  }
3019
3019
  console.log(
3020
3020
  'globalLoadJsList',
3021
3021
  globalLoadJsList,
3022
3022
  'businessLoadJsList',
3023
3023
  businessLoadJsList,
3024
3024
  '两个加载jsList集合合并完成',
3025
3025
  mergeLoadJsList,
3026
3026
  );
3027
3027
  this.loadJsSdkList = mergeLoadJsList;
3028
3028
  return this.loadJsSdkList;
3029
3029
  }
3030
3030
 
3031
3031
  renderNextTickLoadSdk(delayTime = 1000) {
3032
3032
  Taro.nextTick(() => {
3033
3033
  console.log(
3034
3034
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
3035
3035
  );
3036
3036
  setTimeout(() => {
3037
3037
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
3038
3038
  }, delayTime);
3039
3039
  });
3040
3040
  }
3041
3041
 
3042
3042
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
3043
3043
  const getLoadJsList =
3044
3044
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
3045
3045
  const getLoadFilterList = getLoadJsList.filter((item) => {
3046
3046
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
3047
3047
  item.initLoadType = undefined;
3048
3048
  }
3049
3049
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
3050
3050
  let getLoastLoadEventState = true;
3051
3051
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
3052
3052
  getLoastLoadEventState = isJdApp;
3053
3053
  }
3054
3054
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
3055
3055
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
3056
3056
  }
3057
3057
  const getInitTriggerType =
3058
3058
  isJdApp && item?.initJdAppTriggerType
3059
3059
  ? item?.initTriggerType
3060
3060
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
3061
3061
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
3062
3062
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
3063
3063
  });
3064
3064
  console.log(
3065
3065
  '获取当前触发方式',
3066
3066
  triggerType,
3067
3067
  '获取当前最后加载的js集合',
3068
3068
  getLoadFilterList,
3069
3069
  '过滤前的加载集合',
3070
3070
  getLoadJsList,
3071
3071
  );
3072
3072
  const loadTasks =
3073
3073
  getLoadFilterList.length > 0
3074
3074
  ? getLoadFilterList.map((item) => {
3075
3075
  const isLoadState = /sgm/.test(item?.fileName)
3076
3076
  ? window?.shopGlobalSwitch?.openSgm === 'true'
3077
3077
  : true;
3078
3078
  if (!isLoadState) {
3079
3079
  return Promise.resolve(true);
3080
3080
  }
3081
3081
  return this.loadItemSdkPromise(item)
3082
3082
  .then((res) => {
3083
3083
  console.info('当前js地址' + item?.src, '加载状态', res);
3084
3084
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
3085
3085
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
3086
3086
  window.dra.run('init', { aid: res?.aid });
3087
3087
  window.dra.run('start');
3088
3088
  }
3089
3089
  return true;
3090
3090
  })
3091
3091
  .catch((err) => {
3092
3092
  console.info('当前js地址加载异常', item?.src);
3093
3093
  window?.fetchErrorData &&
3094
3094
  window.fetchErrorData({
3095
3095
  title: '公共js加载异常',
3096
3096
  type: 'jsLoad',
3097
3097
  data: err,
3098
3098
  });
3099
3099
  return true;
3100
3100
  });
3101
3101
  })
3102
3102
  : [];
3103
3103
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
3104
3104
  }
3105
3105
  loadScriptEle(jsInfo, resolve, reject) {
3106
3106
  const getFileName = jsInfo?.fileName;
3107
3107
  if (getFileName) {
3108
3108
  const getEleId = `J_loadJs_${getFileName}`;
3109
3109
  const getEle = document.getElementById(getEleId);
3110
3110
  if (!getEle) {
3111
3111
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3112
3112
  const _sgmEle = document.createElement('script');
3113
3113
  _sgmEle.id = getEleId;
3114
3114
  _sgmEle.onload = function () {
3115
3115
  resolve({
3116
3116
  ...jsInfo,
3117
3117
  jsTip: 'js加载成功',
3118
3118
  });
3119
3119
  };
3120
3120
  _sgmEle.onerror = function () {
3121
3121
  reject({
3122
3122
  ...jsInfo,
3123
3123
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3124
3124
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
3125
3125
  });
3126
3126
  };
3127
3127
  const dataAttrList = ['timeout', 'fileName', 'env'];
3128
3128
  const getJsInfoKeyList = Object.keys(jsInfo);
3129
3129
  getJsInfoKeyList.forEach((key) => {
3130
3130
  if (key === 'async') {
3131
3131
  _sgmEle.async = jsInfo[key];
3132
3132
  } else if (key === 'crossOrigin') {
3133
3133
  _sgmEle.crossOrigin = jsInfo[key];
3134
3134
  } else if (key === 'src') {
3135
3135
  _sgmEle.src = `${jsInfo[key]}`;
3136
3136
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
3137
3137
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
3138
3138
  } else {
3139
3139
  _sgmEle.setAttribute(key, jsInfo[key]);
3140
3140
  }
3141
3141
  });
3142
3142
  document.head.appendChild(_sgmEle);
3143
3143
  } else {
3144
3144
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
3145
3145
  resolve({
3146
3146
  ...jsInfo,
3147
3147
  jsTip: 'js本身已存在页面中',
3148
3148
  });
3149
3149
  }
3150
3150
  } else {
3151
3151
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
3152
3152
  }
3153
3153
  }
3154
3154
 
3155
3155
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
3156
3156
  if (jsInfo?.src) {
3157
3157
  const getInitLoadType =
3158
3158
  isJdApp && jsInfo?.initJdAppLoadType
3159
3159
  ? jsInfo?.initJdAppLoadType
3160
3160
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
3161
3161
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
3162
3162
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
3163
3163
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
3164
3164
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
3165
3165
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
3166
3166
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3167
3167
  try {
3168
3168
  const jsXhrRequest = new XMLHttpRequest();
3169
3169
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
3170
3170
  const jsUrl = `${jsInfo?.src}`;
3171
3171
  jsXhrRequest.open('GET', jsUrl, true);
3172
3172
  jsXhrRequest.onreadystatechange = () => {
3173
3173
  if (jsXhrRequest.readyState === 4) {
3174
3174
  const getReqStatus = jsXhrRequest.status;
3175
3175
  const statusText = jsXhrRequest.statusText;
3176
3176
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
3177
3177
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
3178
3178
  if (getInsetHeadState) {
3179
3179
  this.loadScriptEle(jsInfo, resolve, reject);
3180
3180
  } else {
3181
3181
  resolve({
3182
3182
  ...jsInfo,
3183
3183
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
3184
3184
  });
3185
3185
  }
3186
3186
  getReqStatus !== 200 &&
3187
3187
  draBusinessCustomReport({
3188
3188
  eventName: 'business',
3189
3189
  errorName: 'js_load_special_code',
3190
3190
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
3191
3191
  extraData: JSON.stringify({
3192
3192
  msg: '当前js加载成功,状态非200,特殊上报观察',
3193
3193
  jsReqState: getReqStatus,
3194
3194
  env: getSgmCustomCode('js_load_special_code'),
3195
3195
  data: jsInfo,
3196
3196
  }),
3197
3197
  });
3198
3198
  } else {
3199
3199
  const getRes = {
3200
3200
  ...jsInfo,
3201
3201
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3202
3202
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
3203
3203
  jsReqState: getReqStatus,
3204
3204
  };
3205
3205
  console.log('当前js请求状态异常,具体信息见', getRes);
3206
3206
  reject(getRes);
3207
3207
  }
3208
3208
  }
3209
3209
  };
3210
3210
  jsXhrRequest.onerror = () => {
3211
3211
  const getRes = {
3212
3212
  ...jsInfo,
3213
3213
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3214
3214
  jsReqError: '请求错误',
3215
3215
  };
3216
3216
  console.log('当前js请求错误', getRes);
3217
3217
  jsXhrRequest.abort();
3218
3218
  reject(getRes);
3219
3219
  };
3220
3220
  jsXhrRequest.ontimeout = () => {
3221
3221
  const getRes = {
3222
3222
  ...jsInfo,
3223
3223
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3224
3224
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
3225
3225
  jsReqState: jsXhrRequest.status,
3226
3226
  };
3227
3227
  console.log('当前js请求超时异常', getRes);
3228
3228
  jsXhrRequest.abort();
3229
3229
  reject(getRes);
3230
3230
  };
3231
3231
  jsXhrRequest.send();
3232
3232
  } catch (e) {
3233
3233
  console.log('执行js请求异常', e);
3234
3234
  reject({
3235
3235
  ...jsInfo,
3236
3236
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3237
3237
  jsReqError: '未知异常',
3238
3238
  error: e,
3239
3239
  });
3240
3240
  }
3241
3241
  });
3242
3242
  } else {
3243
3243
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
3244
3244
  return this.loadScriptEle(jsInfo, resolve, reject);
3245
3245
  });
3246
3246
  }
3247
3247
  }
3248
3248
  return this.loadJsSdkListCachePromise[getFileKeyName];
3249
3249
  } else {
3250
3250
  return Promise.resolve({
3251
3251
  ...jsInfo,
3252
3252
  jsTip: 'js加载方式设置为不加载,当前不做处理',
3253
3253
  });
3254
3254
  }
3255
3255
  } else {
3256
3256
  return Promise.reject(jsInfo);
3257
3257
  }
3258
3258
  }
3259
3259
 
3260
3260
  createLanguagePromise() {
3261
3261
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
3262
3262
  if (!this.languageCacheProimse) {
3263
3263
  this.languageCacheProimse = new Promise((resolve, reject) => {
3264
3264
  const { fileName, prefixUrl } = getLanguageConfig;
3265
3265
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
3266
3266
  const dealLanguageFile = () => {
3267
3267
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
3268
3268
  .then((res: any) => {
3269
3269
  if (res && res?.data) {
3270
3270
  this.languageJsonData = res.data;
3271
3271
 
3272
3272
  setTimeout(() => {
3273
3273
  const getOtherLanguageList = languageTypeList.filter(
3274
3274
  (item) => item !== languageNowType,
3275
3275
  );
3276
3276
  getOtherLanguageList.length > 0 &&
3277
3277
  getOtherLanguageList.map((languageTypeKey) => {
3278
3278
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
3279
3279
  });
3280
3280
  }, 3000);
3281
3281
  resolve(res);
3282
3282
  } else {
3283
3283
  reject(res);
3284
3284
  }
3285
3285
  })
3286
3286
  .catch((err) => {
3287
3287
  reject(err);
3288
3288
  });
3289
3289
  };
3290
3290
  if (fileName && prefixUrl) {
3291
3291
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
3292
3292
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
3293
3293
  if (getLocalLangRes) {
3294
3294
  try {
3295
3295
  const getLocalLangJsonData =
3296
3296
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
3297
3297
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
3298
3298
  if (getLocalLangJsonData?.fileName === fileName) {
3299
3299
  const geThisLangData = getLocalLangJsonData.data;
3300
3300
  this.languageJsonData = geThisLangData;
3301
3301
  return resolve({
3302
3302
  ...getLanguageConfig,
3303
3303
  languageNowType,
3304
3304
  data: geThisLangData,
3305
3305
  });
3306
3306
  } else {
3307
3307
  dealLanguageFile();
3308
3308
  }
3309
3309
  } else {
3310
3310
  dealLanguageFile();
3311
3311
  }
3312
3312
  } catch (e) {
3313
3313
  return reject({
3314
3314
  languageNowType,
3315
3315
  msg: '转换错误',
3316
3316
  ...getLanguageConfig,
3317
3317
  });
3318
3318
  }
3319
3319
  } else {
3320
3320
  dealLanguageFile();
3321
3321
  }
3322
3322
  } else {
3323
3323
  return reject({
3324
3324
  languageNowType,
3325
3325
  msg: '文件对象下发异常',
3326
3326
  ...getLanguageConfig,
3327
3327
  });
3328
3328
  }
3329
3329
  });
3330
3330
  }
3331
3331
  return this.languageCacheProimse;
3332
3332
  }
3333
3333
 
3334
3334
  getLanguageFilePromise(info, languageTypeKey) {
3335
3335
  const { fileName, prefixUrl, timeout } = info || {};
3336
3336
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
3337
3337
  return new Promise((resolve, reject) => {
3338
3338
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
3339
3339
  try {
3340
3340
  const langXhrRequest = new XMLHttpRequest();
3341
3341
  langXhrRequest.timeout = timeout || 2000;
3342
3342
  langXhrRequest.open('GET', getUrl, true);
3343
3343
  langXhrRequest.responseType = 'json';
3344
3344
  langXhrRequest.onreadystatechange = () => {
3345
3345
  if (langXhrRequest.readyState === 4) {
3346
3346
  const getReqStatus = langXhrRequest.status;
3347
3347
  const statusText = langXhrRequest.statusText;
3348
3348
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
3349
3349
  const getData = langXhrRequest?.response || false;
3350
3350
  if (getData) {
3351
3351
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
3352
3352
  fileName,
3353
3353
  data: getData,
3354
3354
  });
3355
3355
  resolve({
3356
3356
  ...info,
3357
3357
  languageTypeKey,
3358
3358
  data: getData,
3359
3359
  });
3360
3360
  } else {
3361
3361
  reject({
3362
3362
  ...info,
3363
3363
  languageTypeKey,
3364
3364
  msg: '数据获取异常',
3365
3365
  });
3366
3366
  }
3367
3367
  } else {
3368
3368
  const getRes = {
3369
3369
  ...info,
3370
3370
  languageTypeKey,
3371
3371
  env: getSgmCustomCode(langLoadErrorSgmCode),
3372
3372
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
3373
3373
  };
3374
3374
  console.log('当前lang请求状态异常,具体信息见', getRes);
3375
3375
  reject(getRes);
3376
3376
  }
3377
3377
  }
3378
3378
  };
3379
3379
  langXhrRequest.onerror = () => {
3380
3380
  const getRes = {
3381
3381
  ...info,
3382
3382
  env: getSgmCustomCode(langLoadErrorSgmCode),
3383
3383
  msg: '请求错误',
3384
3384
  };
3385
3385
  console.log('当前lang请求错误', getRes);
3386
3386
  langXhrRequest.abort();
3387
3387
  reject(getRes);
3388
3388
  };
3389
3389
  langXhrRequest.ontimeout = () => {
3390
3390
  const getRes = {
3391
3391
  ...info,
3392
3392
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
3393
3393
  };
3394
3394
  console.log('执行lang多语言请求超时异常', getRes);
3395
3395
  langXhrRequest.abort();
3396
3396
  reject(getRes);
3397
3397
  };
3398
3398
  langXhrRequest.send();
3399
3399
  } catch (e) {
3400
3400
  console.log('执行lang多语言请求异常', e);
3401
3401
  reject({
3402
3402
  ...info,
3403
3403
  env: getSgmCustomCode(langLoadErrorSgmCode),
3404
3404
  msg: '未知异常',
3405
3405
  error: e,
3406
3406
  });
3407
3407
  }
3408
3408
  });
3409
3409
  }