@conecli/cone-render 0.10.1-isv2.4 → 0.10.1-isv3.1

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