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

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.
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro';
2
1
  isIosDevice,
3
2
  isAndroidDevice,
4
3
  isJdAndHarmonyDevice,
5
4
  isJdAndAndroidDevice,
6
5
  jdAppVersion,
7
6
  jdAppVersionStr,
8
7
  isString,
9
8
  isObject,
10
9
  serialize,
11
10
  dealNativePixelToCssPixel,
12
11
  isPc,
13
12
  BUSINESS_TYPE,
14
13
  JSSDK_APP_WEBVIEW_CODE,
15
14
  SECTION_HOME_TAB_NAME_TYPE,
16
15
  SECTION_HOME_TAB_TYPE,
17
16
  WXAPP_BIZ_KEY,
18
17
  WX_BUSINESS_TYPE,
19
18
  MPAAS_CONFIG_APP_VERSION,
20
19
  MPAAS_CONFIG_APP_LOW_VERSION,
21
20
  WXAPP_BIZ_SHOP_LIGHT_KEY,
22
21
  LoadJsInitLoadEnvType,
23
22
  LoadJsInitLoadType,
24
23
  LoadJsInitTriggerType,
25
24
  TaroEventType,
26
25
  getSystemInfos,
27
26
  ipLoc_djd,
28
27
  sgmCustomReport,
29
28
  getTaroStorageKeyValue,
30
29
  setTaroStorage,
31
30
  abTestLabels: {},
32
31
  loginState: false,
33
32
  cookiesStr: '',
34
33
  userInfo: userPinKey,
35
34
  isJingGouMiniViewState: false,
36
35
  isJingxiMiniViewState: false,
37
36
  pageInfo: {
38
37
  wxBusinessType: WX_BUSINESS_TYPE.NO,
39
38
  address: '',
40
39
  addressCommaStr: '',
41
40
  un_area: '',
42
41
  vapptype: '1',
43
42
  pageType: 'home',
44
43
  isExposureState: false,
45
44
  moduleId: '',
46
45
  entrance: '',
47
46
  dataType: BUSINESS_TYPE.ONLINE,
48
47
  floorExposureInfo: {},
49
48
  floorVideInfo: {},
50
49
  productVideInfo: {},
51
50
  tabsLoadAllDataInfo: {
52
51
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
53
52
  },
54
53
  updateShopInfosAllState: false,
55
54
  isVipShop: false,
56
55
  isJdShowNativeImmersivePlayer: false,
57
56
  ...shopConfig,
58
57
  pageScrollTop: 0,
59
58
  pageIdxHeightInfo: {
60
59
  list: [],
61
60
  },
62
61
  shopNavBarHeight: 0,
63
62
  },
64
63
  defaultQueryLogInfo: {
65
64
  sourceType: 'JDshop',
66
65
  sourceValue: '',
67
66
  moduleId: 'none',
68
67
  entrance: 'none',
69
68
  },
70
69
  sysInfo: {
71
70
  windowWidth: isPc ? 375 : 0,
72
71
  containerWidth: isPc ? 375 : 0,
73
72
  windowHeight: 0,
74
73
  netWorkType: '4g',
75
74
  jdBottomBarHeight: 0,
76
75
  jdNativeHeaderHeight: 0,
77
76
  isJdTabletDevice: false,
78
77
  isJdTabletLandscape: false,
79
78
  },
80
79
  queryInfo: {},
81
80
  shopInfo: {},
82
81
  openAppData: {},
83
82
  public info: CommonInterFace.BaseConfigInfo;
84
83
  public config: {
85
84
  [key: string]: any;
86
85
  };
87
86
  public lazyContainer: CommonInterFace.lazyContainer;
88
87
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
89
88
  public rootEleNode: HTMLElement | null;
90
89
  public checkStatusAndLoginPromise: object | null;
91
90
  private jmfeRegisterStatePromise: Promise<any> | null;
92
91
  private jmfeRegisterState: boolean;
93
92
  public loadJsSdkList: Array<any>;
94
93
  public loadJsSdkListCachePromise: any;
95
94
  constructor(opt) {
96
95
  this.info = this._getConfig(opt);
97
96
  this.config = {};
98
97
  this.loadJsSdkList = [];
99
98
  this.loadJsSdkListCachePromise = {};
100
99
  this.lazyContainer = {
101
100
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
102
101
  appLazyContainerList: [],
103
102
  appLazyFinishContainerList: [],
104
103
  },
105
104
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
106
105
  appLazyContainerList: [],
107
106
  appLazyFinishContainerList: [],
108
107
  },
109
108
  };
110
109
  this.renderedIsvComponents = {};
111
110
  this.rootEleNode = document.querySelector('body');
112
111
  this.checkStatusAndLoginPromise = null;
113
112
  this.jmfeRegisterStatePromise = null;
114
113
  this.loadOtherSdk();
115
114
  isJdApp && this.jmfeReayPromise();
116
115
  }
117
116
  _getConfig(opt) {
118
117
  return Object.assign({}, DefaultConfig, opt);
119
118
  }
120
119
 
121
120
  jmfeReayPromise(): Promise<any> {
122
121
  if (isJdApp) {
123
122
  if (this.jmfeRegisterState) {
124
123
  return Promise.resolve(true);
125
124
  } else {
126
125
  !this.jmfeRegisterStatePromise &&
127
126
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
128
127
  ready('jmfe', 3000)
129
128
  .then(() => {
130
129
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
131
130
  this.jmfeRegisterState = true;
132
131
  resolve(true);
133
132
  console.log('松果app内初始化注册jmfe认证完成');
134
133
  })
135
134
  .catch((err) => {
136
135
  console.error('jmfe ready error', err);
137
136
  reject(false);
138
137
  });
139
138
  }));
140
139
  return this.jmfeRegisterStatePromise;
141
140
  }
142
141
  } else {
143
142
  return Promise.reject(false);
144
143
  }
145
144
  }
146
145
 
147
146
  getJdScreenSizeInfo() {
148
147
  return new Promise((resolve) => {
149
148
  this.jmfeReayPromise().then(() => {
150
149
  return Promise.race([
151
150
  window.jmfe.getScreenSize(),
152
151
  this.taskTimeoutPromise(() => {
153
152
  return {
154
153
  status: '-10',
155
154
  msg: '获取大屏信息2s超时',
156
155
  };
157
156
  }),
158
157
  ])
159
158
  .then((res) => {
160
159
  console.log('===获取app大屏信息====', res);
161
160
  const { status, data } = res;
162
161
  if (status === '0' && data) {
163
162
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
164
163
  const getPageInfo = dealNativePixelToCssPixel({
165
164
  pageWidth,
166
165
  pageHeight,
167
166
  });
168
167
  this.info.sysInfo.jdScreenSizeType = sizeType;
169
168
  this.info.sysInfo.isJdTabletDevice = window.screen?.width >= 720;
170
169
  this.info.sysInfo.isJdTabletLandscape = isLandscape === '1';
171
170
  console.log(
172
171
  '===计算是否是app大屏信息,需满足宽度最新720===',
173
172
  getPageInfo,
174
173
  '原始数据',
175
174
  data,
176
175
  );
177
176
  resolve(getPageInfo);
178
177
  } else {
179
178
  resolve(false);
180
179
  }
181
180
  })
182
181
  .catch((err) => {
183
182
  console.log('获取大屏信息异常', err);
184
183
  resolve(false);
185
184
  });
186
185
  });
187
186
  });
188
187
  }
189
188
 
190
189
  listenJdTabletScreenChange() {
191
190
  this.jmfeReayPromise().then(() => {
192
191
  try {
193
192
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
194
193
  window.jmfe.listenDeviceScreenChange((event) => {
195
194
  console.log(
196
195
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
197
196
  event,
198
197
  '通过前端判断是不是横屏',
199
198
  window.matchMedia('(orientation: landscape)')?.matches,
200
199
  );
201
200
  const { orientation } = event?.data;
202
201
  if (orientation) {
203
202
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
204
203
  Taro.eventCenter.trigger(
205
204
  TaroEventType.TABLE_SCREEN_CHANGE,
206
205
  this.info.sysInfo.isJdTabletLandscape,
207
206
  orientation,
208
207
  );
209
208
  }
210
209
  });
211
210
  } catch (error) {
212
211
  console.log('listenScreenChange的打印error:', error);
213
212
  }
214
213
  });
215
214
  }
216
215
 
217
216
  updateBusinessDomainAndApi(domain, api) {
218
217
  }
219
218
 
220
219
  formatNativeScreenPageData(action) {
221
220
  let getChangePageInfo: any = null;
222
221
  try {
223
222
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
224
223
  JSON.stringify({
225
224
  plugin: 'JDHybridScreenPlugin',
226
225
  action,
227
226
  sync: '1',
228
227
  }),
229
228
  );
230
229
  const getChangePageInfoData =
231
230
  typeof getNativeScreenPageInfoStr === 'string'
232
231
  ? JSON.parse(getNativeScreenPageInfoStr)
233
232
  : null;
234
233
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
235
234
  const { code, data } = getChangePageInfoData;
236
235
  getChangePageInfo = code && code === '0' ? data : null;
237
236
  }
238
237
  } catch (e) {
239
238
  console.log('JDHybridScreenPlugin转换异常', e);
240
239
  }
241
240
  return getChangePageInfo;
242
241
  }
243
242
 
244
243
  isAndroidFoldScreen() {
245
244
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
246
245
  }
247
246
 
248
247
  getJdAndroidPageChangeScreenInfo() {
249
248
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
250
249
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
251
250
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
252
251
  pageWidth: getPageScreenInfo.pageWidth,
253
252
  pageHeight: getPageScreenInfo.pageHeight,
254
253
  });
255
254
  getPageScreenInfo.pageWidth = pageWidth;
256
255
  getPageScreenInfo.pageHeight = pageHeight;
257
256
  }
258
257
  return getPageScreenInfo;
259
258
  }
260
259
 
261
260
  async getSystemInfo(params) {
262
261
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(params);
263
262
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
264
263
  let _isfoldScreen = false;
265
264
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
266
265
  console.info(
267
266
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
268
267
  getStorageData,
269
268
  '通过缓存值第一次判断是否是折叠屏',
270
269
  getStorageData === 'true',
271
270
  );
272
271
  if (!getStorageData) {
273
272
  _isfoldScreen = this.isAndroidFoldScreen();
274
273
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
275
274
  } else {
276
275
  _isfoldScreen = getStorageData === 'true';
277
276
  }
278
277
  if (_isfoldScreen) {
279
278
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
280
279
  if (getJdAndroidPageInfo) {
281
280
  info = getSystemInfos(getJdAndroidPageInfo);
282
281
  console.warn(
283
282
  '当前为松果安卓折叠屏app,获取折叠屏信息',
284
283
  getJdAndroidPageInfo,
285
284
  '获取转换后的系统信息',
286
285
  info,
287
286
  );
288
287
  sgmCustomReport({
289
288
  type: 2,
290
289
  code: 'android_jdapp_foldScreen_info',
291
290
  msg: {
292
291
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
293
292
  androidPageInfo: getJdAndroidPageInfo,
294
293
  jdAppVersionStr,
295
294
  taroSysInfo: info,
296
295
  },
297
296
  });
298
297
  }
299
298
  }
300
299
  }
301
300
  if (isJdApp) {
302
301
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
303
302
  }
304
303
  this.info.sysInfo = {
305
304
  actualNavBarHeight: 0,
306
305
  ...this.info.sysInfo,
307
306
  ...info,
308
307
  safeContentHeight: info?.screenHeight,
309
308
  headerHeight: 0,
310
309
  tabBarHeight: 0,
311
310
  };
312
311
  if (isJdApp) {
313
312
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
314
313
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
315
314
  this.getAddressCachePromise();
316
315
  this.getElderModePromise();
317
316
  this.getJDAppearanceStatePromise();
318
317
  this.createJdAndroidRquestEventForTouchStart();
319
318
  }
320
319
  this.getWifiVideoAutoPlayAsync();
321
320
  this.getMPaasConfigAsync();
322
321
  this.getNetWorkType();
323
322
  }
324
323
 
325
324
  taskTimeoutPromise(callBack, timeout = 2000) {
326
325
  return new Promise((resolve) => {
327
326
  setTimeout(() => {
328
327
  const getCallBackRes = typeof callBack === 'function' && callBack();
329
328
  return resolve(getCallBackRes || false);
330
329
  }, timeout);
331
330
  });
332
331
  }
333
332
 
334
333
  getElderModePromise() {
335
334
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
336
335
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
337
336
  } else {
338
337
  if (isJdAndAndroidDevice) {
339
338
  this.info.sysInfo.jdAppModeType = '0';
340
339
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
341
340
  } else {
342
341
  return Promise.race([
343
342
  this.taskTimeoutPromise(() => {
344
343
  this.info.sysInfo.jdAppModeType = '0';
345
344
  return this.info.sysInfo.jdAppModeType;
346
345
  }),
347
346
  new Promise((resolve) => {
348
347
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
349
348
  if (!window[getCallBackName]) {
350
349
  window[getCallBackName] = (res) => {
351
350
  try {
352
351
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
353
352
  const { status, data, msg } = getResJson;
354
353
  console.log(`获取松果app展示模式成功,返回结果${data}`);
355
354
  if (status === '0') {
356
355
  this.info.sysInfo.jdAppModeType = data;
357
356
  resolve(data);
358
357
  } else {
359
358
  resolve('0');
360
359
  }
361
360
  } catch (e) {
362
361
  resolve('0');
363
362
  }
364
363
  window[getCallBackName] = null;
365
364
  };
366
365
  }
367
366
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
368
367
  method: 'callSyncRouterModuleWithParams',
369
368
  params: JSON.stringify({
370
369
  routerURL: 'router://JDBModeModule/getCurrentMode',
371
370
  routerParam: {},
372
371
  callBackName: `window.${getCallBackName}`,
373
372
  callBackId: `${getCallBackName}Ios`,
374
373
  }),
375
374
  });
376
375
  }),
377
376
  ]);
378
377
  }
379
378
  }
380
379
  }
381
380
  getAPPUseStraightCorner() {
382
381
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
383
382
  const params = {
384
383
  routerURL,
385
384
  routerParam: {},
386
385
  jdRouter: '1',
387
386
  };
388
387
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
389
388
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
390
389
  } else {
391
390
  return this.jmfeReayPromise()
392
391
  .then(() => {
393
392
  if (isJdAndHarmonyDevice || !isJdApp) {
394
393
  console.log('not APP or is Harmony');
395
394
  return Promise.resolve(false);
396
395
  }
397
396
  console.log('jmfe setShareInfo', params);
398
397
  return Promise.race([
399
398
  window.jmfe.callRouter(params),
400
399
  this.taskTimeoutPromise(() => {
401
400
  return false;
402
401
  }),
403
402
  ]).then(({ status, data }) => {
404
403
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
405
404
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
406
405
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
407
406
  return Promise.resolve(status === '0' && Number(data) === 1);
408
407
  });
409
408
  })
410
409
  .catch((e) => {
411
410
  console.log('jmfe error', e);
412
411
  return Promise.resolve(false);
413
412
  });
414
413
  }
415
414
  }
416
415
 
417
416
  getJDAppearanceStatePromise() {
418
417
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
419
418
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
420
419
  } else {
421
420
  return Promise.race([
422
421
  this.taskTimeoutPromise(() => {
423
422
  this.info.sysInfo.jdAppearanceState = '0';
424
423
  return this.info.sysInfo.jdAppearanceState;
425
424
  }),
426
425
  new Promise((resolve) => {
427
426
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
428
427
  if (!window[getCallBackName]) {
429
428
  window[getCallBackName] = (res) => {
430
429
  try {
431
430
  console.log('getJDAppearanceStatePromise', res);
432
431
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
433
432
  const { status, data, msg } = getResJson;
434
433
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
435
434
  if (status === '0') {
436
435
  this.info.sysInfo.jdAppearanceState = data;
437
436
  resolve(data);
438
437
  } else {
439
438
  resolve('0');
440
439
  }
441
440
  } catch (e) {
442
441
  resolve('0');
443
442
  }
444
443
  window[getCallBackName] = null;
445
444
  };
446
445
  }
447
446
  if (isAndroidDevice) {
448
447
  const jsonString = JSON.stringify({
449
448
  callBackName: `window.${getCallBackName}`,
450
449
  });
451
450
  console.log('window.JDAppearance', window.JDAppearance);
452
451
  window.JDAppearance && window.JDAppearance.getUiState(jsonString);
453
452
  } else {
454
453
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
455
454
  method: 'callSyncRouterModuleWithParams',
456
455
  params: JSON.stringify({
457
456
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
458
457
  routerParam: {},
459
458
  callBackName: `window.${getCallBackName}`,
460
459
  callBackId: `${getCallBackName}Ios`,
461
460
  }),
462
461
  });
463
462
  }
464
463
  }),
465
464
  ]);
466
465
  }
467
466
  }
468
467
 
469
468
  createJdAndroidRquestEventForTouchStart() {
470
469
  if (isJdAndAndroidDevice && window.JdAndroid) {
471
470
  const rootEleNode = document.querySelector('body');
472
471
  if (rootEleNode) {
473
472
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
474
473
  }
475
474
  }
476
475
  }
477
476
  jdAndroidAddEventListenerTouchStart(e) {
478
477
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
479
478
  if (!isH5SwiperCustomEle) {
480
479
  const hasCustomEle = e
481
480
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
482
481
  : false;
483
482
  if (!hasCustomEle) {
484
483
  window.JdAndroid.requestEvent(false);
485
484
  console.log(
486
485
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
487
486
  );
488
487
  }
489
488
  }
490
489
  }
491
490
  removeJdAndroidRquestEventForTouchStart() {
492
491
  if (isJdAndAndroidDevice && window.JdAndroid) {
493
492
  const rootEleNode = document.querySelector('body');
494
493
  if (rootEleNode) {
495
494
  rootEleNode.removeEventListener(
496
495
  'touchstart',
497
496
  this.jdAndroidAddEventListenerTouchStart,
498
497
  false,
499
498
  );
500
499
  }
501
500
  }
502
501
  }
503
502
 
504
503
  getNetWorkType() {
505
504
  if (isJdApp) {
506
505
  this.jmfeReayPromise().then(() => {
507
506
  window.jmfe
508
507
  .getNetworkStatus()
509
508
  .then(({ status, data }) => {
510
509
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
511
510
  if (status === '0') {
512
511
  this.info.sysInfo['netWorkType'] = data;
513
512
  } else {
514
513
  this._taroGetNetworkType();
515
514
  }
516
515
  })
517
516
  .catch((err) => {
518
517
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
519
518
  this._taroGetNetworkType();
520
519
  });
521
520
  });
522
521
  } else {
523
522
  this._taroGetNetworkType();
524
523
  }
525
524
  }
526
525
  _taroGetNetworkType() {
527
526
  Taro.getNetworkType().then((getRes) => {
528
527
  if (getRes && getRes.networkType) {
529
528
  this.info.sysInfo['netWorkType'] = getRes.networkType;
530
529
  console.log(
531
530
  '在app内通过taro对象获取网络状态完成,当前网络状态',
532
531
  this.info.sysInfo['netWorkType'],
533
532
  );
534
533
  }
535
534
  });
536
535
  }
537
536
 
538
537
  getCacheAddressRouter() {
539
538
  if (window.jmfe && isJdApp) {
540
539
  if (!isJdAndHarmonyDevice) {
541
540
  return Promise.race([
542
541
  window.jmfe.callRouter({
543
542
  jdRouter: '1',
544
543
  routerURL: isAndroidDevice
545
544
  ? 'router://JDAddressModule/getCacheAddress'
546
545
  : 'router://JDBAddressCacheManagerModule/getCacheAddress',
547
546
  routerParam: { sceneId: 'basicShoppingProcess' },
548
547
  }),
549
548
  this.taskTimeoutPromise(() => {
550
549
  return {
551
550
  status: '-1000',
552
551
  msg: '原生router协议获取地址信息超时',
553
552
  };
554
553
  }, 3000),
555
554
  ]);
556
555
  } else {
557
556
  return Promise.resolve({
558
557
  status: '-1001',
559
558
  msg: '鸿蒙系统调用jmfe异常,获取失败',
560
559
  });
561
560
  }
562
561
  } else {
563
562
  return Promise.resolve({
564
563
  status: '-1002',
565
564
  msg: 'jmfe不存在,获取失败',
566
565
  });
567
566
  }
568
567
  }
569
568
 
570
569
  getAddressCachePromise() {
571
570
  return new Promise((resolve) => {
572
571
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
573
572
  resolve({
574
573
  lat: this.info.sysInfo.lat,
575
574
  lng: this.info.sysInfo.lng,
576
575
  area: this?.info?.sysInfo?.area,
577
576
  });
578
577
  } else {
579
578
  this.jmfeReayPromise()
580
579
  .then(() => {
581
580
  this.getCacheAddressRouter()
582
581
  .then((res) => {
583
582
  const { status, data } = res;
584
583
  console.log('原生端获取经纬度原始数据结果', status, data);
585
584
  if (status === '0' && data) {
586
585
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
587
586
  data || {};
588
587
  let area = '';
589
588
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
590
589
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
591
590
  if (provinceId) {
592
591
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
593
592
  this.info.pageInfo['address'] = area;
594
593
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
595
594
  Taro.eventCenter.trigger(
596
595
  TaroEventType.USER_AREA_UPDATE,
597
596
  this.info.pageInfo.address,
598
597
  );
599
598
  }
600
599
  resolve({
601
600
  lat: this.info.sysInfo['lat'],
602
601
  lng: this.info.sysInfo['lng'],
603
602
  area: area,
604
603
  });
605
604
  } else {
606
605
  typeof res === 'object' &&
607
606
  sgmCustomReport({
608
607
  type: 3,
609
608
  code: 'jdapp_getCacheAddress_info',
610
609
  msg: {
611
610
  title: '松果app内通过router协议获取用户地址及经纬度信息异常',
612
611
  jdAppVersion: jdAppVersionStr,
613
612
  ...res,
614
613
  },
615
614
  });
616
615
  resolve({ lat: '', lng: '', area: '' });
617
616
  }
618
617
  })
619
618
  .catch((e) => {
620
619
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e);
621
620
  resolve({ lat: '', lng: '', area: '' });
622
621
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
623
622
  });
624
623
  })
625
624
  .catch((e) => {
626
625
  resolve({ lat: '', lng: '', area: '' });
627
626
  console.log('判断jmfe不存在,获取经纬度信息异常e', e);
628
627
  });
629
628
  }
630
629
  });
631
630
  }
632
631
 
633
632
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
634
633
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
635
634
  if (!isJdApp) {
636
635
  return;
637
636
  }
638
637
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
639
638
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
640
639
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
641
640
  'hybridHttpSwitch',
642
641
  isBeforePageReady,
643
642
  );
644
643
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
645
644
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
646
645
  'isFollowAppVideoPlayStatus',
647
646
  isBeforePageReady,
648
647
  );
649
648
  console.log(
650
649
  'isBeforePageReady:',
651
650
  isBeforePageReady,
652
651
  'isFollowAppVideoPlayStatus:',
653
652
  isFollowAppVideoPlayStatus,
654
653
  );
655
654
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
656
655
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
657
656
  }
658
657
  }
659
658
 
660
659
  async getWifiVideoAutoPlayAsync() {
661
660
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
662
661
  if (!isJdApp) {
663
662
  return;
664
663
  }
665
664
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
666
665
  return 0;
667
666
  });
668
667
  if (Number(videoPlayStatus) === 1) {
669
668
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
670
669
  }
671
670
  }
672
671
 
673
672
  async getMPaasConfigAsync() {
674
673
  this.info.sysInfo.dynamicConfig = {};
675
674
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
676
675
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
677
676
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
678
677
  return this.updateMPaasConfigAsync(true);
679
678
  }
680
679
 
681
680
  getDynamicConfig(key: string) {
682
681
  return this.info.sysInfo.dynamicConfig[key];
683
682
  }
684
683
  async updateMPaasConfig() {
685
684
  console.log('updateMPaasConfig');
686
685
  if (
687
686
  isIosDevice &&
688
687
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
689
688
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
690
689
  ) {
691
690
  try {
692
691
  await this.updateMPaasConfigAsync(false);
693
692
  } catch (e) {
694
693
  console.log('updateMPaasConfigAsync:', e);
695
694
  }
696
695
  }
697
696
  }
698
697
 
699
698
  toLogin(options) {
700
699
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
701
700
  ? this.toWxAppLogin(options)
702
701
  : this.toWebLogin(options);
703
702
  }
704
703
 
705
704
  doLogin(options) {
706
705
  return this.toLogin(options);
707
706
  }
708
707
 
709
708
  doLoginForJdPin(options = {}) {
710
709
  return this.doLogin({
711
710
  loginColor: {
712
711
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
713
712
  dpin: 0,
714
713
  },
715
714
  ...options,
716
715
  });
717
716
  }
718
717
 
719
718
  toWebLogin(options) {
720
719
  let params: {
721
720
  returnurl: string;
722
721
  } = {
723
722
  returnurl: '',
724
723
  };
725
724
  const loginUrl = isPc
726
725
  ? `//passport.jd.com/new/login.aspx`
727
726
  : `${domain.mobileLogin}/user/login.action`;
728
727
  const defaultParams = {
729
728
  appid: '100',
730
729
  returnurl: window.location.href,
731
730
  };
732
731
  if (isString(options)) {
733
732
  params = Object.assign({}, defaultParams, {
734
733
  returnurl: options,
735
734
  });
736
735
  } else if (isObject(options)) {
737
736
  const { loginColor, ...otherOptions } = options;
738
737
  params = Object.assign({}, defaultParams, otherOptions);
739
738
  } else {
740
739
  params = defaultParams;
741
740
  }
742
741
  params.returnurl = encodeURIComponent(params.returnurl);
743
742
  let getFullUrl = loginUrl + '?' + serialize(params);
744
743
  if (isPc) {
745
744
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
746
745
  }
747
746
  return Promise.resolve({
748
747
  h5ToUrl: true,
749
748
  url: getFullUrl,
750
749
  }).then(() => {
751
750
  window.location.href = getFullUrl;
752
751
  });
753
752
  }
754
753
 
755
754
  toWxAppLogin(options = {}) {
756
755
  console.log('微信京购小程序中h5登录跳转', options);
757
756
  return Promise.resolve(true).then(() => {
758
757
  const { loginColor } = Object.assign(
759
758
  {},
760
759
  {
761
760
  loginColor: {
762
761
  biz: WXAPP_BIZ_KEY,
763
762
  dpin: 1,
764
763
  },
765
764
  },
766
765
  options,
767
766
  );
768
767
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
769
768
  loginColor.biz
770
769
  }&url=${encodeURIComponent(window.location.href)}`;
771
770
  });
772
771
  }
773
772
 
774
773
  getLoginCookie() {
775
774
  return Promise.resolve({
776
775
  pin: cookie.get('pin') || '',
777
776
  });
778
777
  }
779
778
 
780
779
  clearLoginCookie() {
781
780
  cookie.remove('pin');
782
781
  }
783
782
 
784
783
  checkStatusAndLogin(options = {}) {
785
784
  if (!this.checkStatusAndLoginPromise) {
786
785
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
787
786
  try {
788
787
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
789
788
  if (getLoginState) {
790
789
  resolve(true);
791
790
  } else {
792
791
  this.toLogin(options);
793
792
  reject(false);
794
793
  }
795
794
  } catch (e) {
796
795
  this.toLogin(options);
797
796
  reject(false);
798
797
  }
799
798
  });
800
799
  return this.checkStatusAndLoginPromise;
801
800
  } else {
802
801
  return this.checkStatusAndLoginPromise
803
802
  .then(() => {
804
803
  return Promise.resolve(true);
805
804
  })
806
805
  .catch(() => {
807
806
  this.toLogin(options);
808
807
  return Promise.reject(true);
809
808
  });
810
809
  }
811
810
  }
812
811
 
813
812
  checkJdStatusAndLogin(
814
813
  options = {
815
814
  loginColor: {
816
815
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
817
816
  dpin: 0,
818
817
  },
819
818
  },
820
819
  ) {
821
820
  return this.checkStatusAndLogin(options);
822
821
  }
823
822
 
824
823
  doCheckLoginStateAndForApiCheck(options) {
825
824
  if (this.info.loginState) {
826
825
  return Promise.resolve(true);
827
826
  } else {
828
827
  return new Promise((resolve, reject) => {
829
828
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
830
829
  const getWqAuthToken = cookie.get('wq_auth_token');
831
830
  const getWqSkey = cookie.get('wq_skey');
832
831
  const getWqUin = cookie.get('wq_uin');
833
832
  const isLoginState =
834
833
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
835
834
  if (isLoginState) {
836
835
  this.info.loginState = true;
837
836
  resolve(true);
838
837
  } else {
839
838
  reject(false);
840
839
  }
841
840
  } else {
842
841
  Taro.request({
843
842
  url: api.isLogin,
844
843
  jsonp: true,
845
844
  timeout: 3000,
846
845
  success: (res) => {
847
846
  const { statusCode, data } = res;
848
847
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
849
848
  this.info.loginState = true;
850
849
  resolve(true);
851
850
  } else {
852
851
  reject(false);
853
852
  }
854
853
  },
855
854
  fail: (err) => {
856
855
  console.log('登录检查异常', err);
857
856
  reject(false);
858
857
  },
859
858
  });
860
859
  }
861
860
  });
862
861
  }
863
862
  }
864
863
 
865
864
  checkLoginStatus(options) {
866
865
  return new Promise(async (resolve, reject) => {
867
866
  try {
868
867
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
869
868
  if (getLoginState) {
870
869
  const { pin } = await this.getLoginCookie();
871
870
  this.info.userInfo = {
872
871
  pin,
873
872
  encodePin: encodeURIComponent(pin),
874
873
  ptkey: '',
875
874
  };
876
875
  resolve(true);
877
876
  } else {
878
877
  reject(false);
879
878
  }
880
879
  } catch (e) {
881
880
  reject(false);
882
881
  }
883
882
  });
884
883
  }
885
884
 
886
885
  updatePageAndLogInfo(updateQuery = {}) {
887
886
  const createUpdateQueryInfo: {
888
887
  query: {
889
888
  shopId?: string | number;
890
889
  venderId?: string | number;
891
890
  };
892
891
  updateShopInfoState: boolean;
893
892
  } = Object.assign(
894
893
  {},
895
894
  {
896
895
  query: {},
897
896
  updateShopInfoState: false,
898
897
  },
899
898
  updateQuery,
900
899
  );
901
900
  console.log(
902
901
  '获取当前下发的店铺查询参数',
903
902
  updateQuery,
904
903
  '获取之前保存的shopInfo店铺查询参数',
905
904
  this.info?.shopInfo,
906
905
  );
907
906
  const { query, updateShopInfoState } = createUpdateQueryInfo;
908
907
  const { shopId, venderId, un_area } = query;
909
908
  if (updateShopInfoState) {
910
909
  this.info.queryInfo = {
911
910
  ...this.info.queryInfo,
912
911
  ...query,
913
912
  };
914
913
  if (shopId && venderId) {
915
914
  this.info.shopInfo = {
916
915
  shopId: `${shopId}`,
917
916
  venderId: `${venderId}`,
918
917
  };
919
918
  }
920
919
  } else {
921
920
  this.info.queryInfo = {
922
921
  ...query,
923
922
  };
924
923
  if (
925
924
  this.info.shopInfo?.shopId &&
926
925
  this.info.shopInfo?.venderId &&
927
926
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
928
927
  ) {
929
928
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
930
929
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
931
930
  console.log(
932
931
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
933
932
  this.info.queryInfo,
934
933
  );
935
934
  }
936
935
  }
937
936
  this.info.queryInfo['shopId'] &&
938
937
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
939
938
  this.info.queryInfo['venderId'] &&
940
939
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
941
940
  console.log(
942
941
  'h5==获取店铺下发查询参数\n',
943
942
  query,
944
943
  '\n获取店铺最后查询参数\n',
945
944
  this.info.queryInfo,
946
945
  '\n是否为更新店铺状态\n',
947
946
  updateShopInfoState,
948
947
  );
949
948
  const changeArea = un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : '';
950
949
  if (changeArea) {
951
950
  this.info.pageInfo.address = changeArea;
952
951
  this.info.pageInfo.un_area = changeArea;
953
952
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',');
954
953
  }
955
954
  }
956
955
 
957
956
  dealLoadSdkList() {
958
957
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
959
958
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
960
959
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
961
960
  let mergeLoadJsList = globalLoadJsList;
962
961
  try {
963
962
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
964
963
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
965
964
  getFindIndex !== -1
966
965
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
967
966
  : accArr.push(current);
968
967
  return accArr;
969
968
  }, []);
970
969
  } catch (e) {
971
970
  console.log('LoadJsList合并错误', e);
972
971
  }
973
972
  console.log(
974
973
  'globalLoadJsList',
975
974
  globalLoadJsList,
976
975
  'businessLoadJsList',
977
976
  businessLoadJsList,
978
977
  '两个加载jsList集合合并完成',
979
978
  mergeLoadJsList,
980
979
  );
981
980
  this.loadJsSdkList = mergeLoadJsList;
982
981
  return this.loadJsSdkList;
983
982
  }
984
983
 
985
984
  renderNextTickLoadSdk() {
986
985
  Taro.nextTick(() => {
987
986
  console.log(
988
987
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
989
988
  );
990
989
  setTimeout(() => {
991
990
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
992
991
  }, 1000);
993
992
  });
994
993
  }
995
994
 
996
995
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
997
996
  const getLoadJsList =
998
997
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
999
998
  const getLoadFilterList = getLoadJsList.filter((item) => {
1000
999
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
1001
1000
  let getLoastLoadEventState = true;
1002
1001
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
1003
1002
  getLoastLoadEventState = isJdApp;
1004
1003
  }
1005
1004
  else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
1006
1005
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice
1007
1006
  }
1008
1007
  const getInitTriggerType =
1009
1008
  isJdApp && item?.initJdAppTriggerType
1010
1009
  ? item?.initTriggerType
1011
1010
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
1012
1011
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
1013
1012
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
1014
1013
  });
1015
1014
  console.log(
1016
1015
  '获取当前触发方式',
1017
1016
  triggerType,
1018
1017
  '获取当前最后加载的js集合',
1019
1018
  getLoadFilterList,
1020
1019
  '过滤前的加载集合',
1021
1020
  getLoadJsList,
1022
1021
  );
1023
1022
  getLoadFilterList.length > 0 &&
1024
1023
  getLoadFilterList.forEach((item) => {
1025
1024
  const isLoadState = /sgm/.test(item?.fileName)
1026
1025
  ? window?.shopGlobalSwitch?.openSgm === 'true'
1027
1026
  : true;
1028
1027
  isLoadState &&
1029
1028
  this.loadItemSdkPromise(item)
1030
1029
  .then((res) => {
1031
1030
  console.info('当前js地址' + item?.src, '加载状态', res);
1032
1031
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
1033
1032
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
1034
1033
  window.dra.run('init', { aid: res?.aid });
1035
1034
  window.dra.run('start');
1036
1035
  }
1037
1036
  })
1038
1037
  .catch((err) => {
1039
1038
  console.info('当前js地址加载异常', item?.src);
1040
1039
  window?.fetchErrorData &&
1041
1040
  window.fetchErrorData({
1042
1041
  title: '公共js加载异常',
1043
1042
  type: 'jsLoad',
1044
1043
  data: err,
1045
1044
  });
1046
1045
  });
1047
1046
  });
1048
1047
  }
1049
1048
  loadScriptEle(jsInfo, resolve, reject) {
1050
1049
  const getFileName = jsInfo?.fileName;
1051
1050
  if (getFileName) {
1052
1051
  const getEleId = `J_loadJs_${getFileName}`;
1053
1052
  const getEle = document.getElementById(getEleId);
1054
1053
  if (!getEle) {
1055
1054
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1056
1055
  const _sgmEle = document.createElement('script');
1057
1056
  _sgmEle.id = getEleId;
1058
1057
  _sgmEle.onload = function () {
1059
1058
  resolve({
1060
1059
  ...jsInfo,
1061
1060
  jsTip: 'js加载成功',
1062
1061
  });
1063
1062
  };
1064
1063
  _sgmEle.onerror = function () {
1065
1064
  reject({
1066
1065
  ...jsInfo,
1067
1066
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1068
1067
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
1069
1068
  });
1070
1069
  };
1071
1070
  const dataAttrList = ['timeout', 'fileName', 'env'];
1072
1071
  const getJsInfoKeyList = Object.keys(jsInfo);
1073
1072
  getJsInfoKeyList.forEach((key) => {
1074
1073
  if (key === 'async') {
1075
1074
  _sgmEle.async = jsInfo[key];
1076
1075
  } else if (key === 'crossOrigin') {
1077
1076
  _sgmEle.crossOrigin = jsInfo[key];
1078
1077
  } else if (key === 'src') {
1079
1078
  _sgmEle.src = `${jsInfo[key]}`;
1080
1079
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
1081
1080
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
1082
1081
  } else {
1083
1082
  _sgmEle.setAttribute(key, jsInfo[key]);
1084
1083
  }
1085
1084
  });
1086
1085
  document.head.appendChild(_sgmEle);
1087
1086
  } else {
1088
1087
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
1089
1088
  resolve({
1090
1089
  ...jsInfo,
1091
1090
  jsTip: 'js本身已存在页面中',
1092
1091
  });
1093
1092
  }
1094
1093
  } else {
1095
1094
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
1096
1095
  }
1097
1096
  }
1098
1097
 
1099
1098
  loadItemSdkPromise(jsInfo = {}) {
1100
1099
  if (jsInfo?.src) {
1101
1100
  const getInitLoadType =
1102
1101
  isJdApp && jsInfo?.initJdAppLoadType
1103
1102
  ? jsInfo?.initJdAppLoadType
1104
1103
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
1105
1104
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
1106
1105
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
1107
1106
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
1108
1107
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
1109
1108
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1110
1109
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1111
1110
  try {
1112
1111
  const jsXhrRequest = new XMLHttpRequest();
1113
1112
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
1114
1113
  const jsUrl = `${jsInfo?.src}`;
1115
1114
  jsXhrRequest.open('GET', jsUrl, true);
1116
1115
  jsXhrRequest.onreadystatechange = () => {
1117
1116
  if (jsXhrRequest.readyState === 4) {
1118
1117
  const getReqStatus = jsXhrRequest.status;
1119
1118
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
1120
1119
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
1121
1120
  if (getInsetHeadState) {
1122
1121
  this.loadScriptEle(jsInfo, resolve, reject);
1123
1122
  } else {
1124
1123
  resolve({
1125
1124
  ...jsInfo,
1126
1125
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
1127
1126
  });
1128
1127
  }
1129
1128
  getReqStatus !== 200 &&
1130
1129
  sgmCustomReport({
1131
1130
  type: 3,
1132
1131
  code: 'js_load_special_code',
1133
1132
  msg: {
1134
1133
  msg: '当前js加载成功,状态非200,特殊上报观察',
1135
1134
  jsReqState: getReqStatus,
1136
1135
  env: getSgmCustomCode('js_load_special_code'),
1137
1136
  data: jsInfo,
1138
1137
  },
1139
1138
  });
1140
1139
  } else {
1141
1140
  const getRes = {
1142
1141
  ...jsInfo,
1143
1142
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1144
1143
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
1145
1144
  jsReqState: getReqStatus,
1146
1145
  };
1147
1146
  console.log('当前js请求状态异常,具体信息见', getRes);
1148
1147
  reject(getRes);
1149
1148
  }
1150
1149
  }
1151
1150
  };
1152
1151
  jsXhrRequest.onerror = () => {
1153
1152
  const getRes = {
1154
1153
  ...jsInfo,
1155
1154
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1156
1155
  jsReqError: '请求错误',
1157
1156
  };
1158
1157
  console.log('当前js请求错误', getRes);
1159
1158
  jsXhrRequest.abort();
1160
1159
  reject(getRes);
1161
1160
  };
1162
1161
  jsXhrRequest.ontimeout = () => {
1163
1162
  const getRes = {
1164
1163
  ...jsInfo,
1165
1164
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1166
1165
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
1167
1166
  jsReqState: jsXhrRequest.status,
1168
1167
  };
1169
1168
  console.log('当前js请求超时异常', getRes);
1170
1169
  jsXhrRequest.abort();
1171
1170
  reject(getRes);
1172
1171
  };
1173
1172
  jsXhrRequest.send();
1174
1173
  } catch (e) {
1175
1174
  console.log('执行js请求异常', e);
1176
1175
  reject({
1177
1176
  ...jsInfo,
1178
1177
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1179
1178
  jsReqError: '未知异常',
1180
1179
  error: e,
1181
1180
  });
1182
1181
  }
1183
1182
  });
1184
1183
  } else {
1185
1184
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1186
1185
  return this.loadScriptEle(jsInfo, resolve, reject);
1187
1186
  });
1188
1187
  }
1189
1188
  }
1190
1189
  return this.loadJsSdkListCachePromise[getFileKeyName];
1191
1190
  } else {
1192
1191
  return Promise.resolve({
1193
1192
  ...jsInfo,
1194
1193
  jsTip: 'js加载方式设置为不加载,当前不做处理',
1195
1194
  });
1196
1195
  }
1197
1196
  } else {
1198
1197
  return Promise.reject(jsInfo);
1199
1198
  }
1200
1199
  }
1200
+ import Taro from '@tarojs/taro';
1201
1201
  isIosDevice,
1202
1202
  isAndroidDevice,
1203
1203
  isJdAndHarmonyDevice,
1204
1204
  isJdAndAndroidDevice,
1205
1205
  jdAppVersion,
1206
1206
  jdAppVersionStr,
1207
1207
  isString,
1208
1208
  isObject,
1209
1209
  serialize,
1210
1210
  dealNativePixelToCssPixel,
1211
1211
  isPc,
1212
1212
  BUSINESS_TYPE,
1213
1213
  JSSDK_APP_WEBVIEW_CODE,
1214
1214
  SECTION_HOME_TAB_NAME_TYPE,
1215
1215
  SECTION_HOME_TAB_TYPE,
1216
1216
  WXAPP_BIZ_KEY,
1217
1217
  WX_BUSINESS_TYPE,
1218
1218
  MPAAS_CONFIG_APP_VERSION,
1219
1219
  MPAAS_CONFIG_APP_LOW_VERSION,
1220
1220
  WXAPP_BIZ_SHOP_LIGHT_KEY,
1221
1221
  LoadJsInitLoadEnvType,
1222
1222
  LoadJsInitLoadType,
1223
1223
  LoadJsInitTriggerType,
1224
1224
  TaroEventType,
1225
1225
  getSystemInfos,
1226
1226
  ipLoc_djd,
1227
1227
  sgmCustomReport,
1228
1228
  getTaroStorageKeyValue,
1229
1229
  setTaroStorage,
1230
1230
  abTestLabels: {},
1231
1231
  loginState: false,
1232
1232
  cookiesStr: '',
1233
1233
  userInfo: userPinKey,
1234
1234
  isJingGouMiniViewState: false,
1235
1235
  isJingxiMiniViewState: false,
1236
1236
  pageInfo: {
1237
1237
  wxBusinessType: WX_BUSINESS_TYPE.NO,
1238
1238
  address: '',
1239
1239
  addressCommaStr: '',
1240
1240
  un_area: '',
1241
1241
  vapptype: '1',
1242
1242
  pageType: 'home',
1243
1243
  isExposureState: false,
1244
1244
  moduleId: '',
1245
1245
  entrance: '',
1246
1246
  dataType: BUSINESS_TYPE.ONLINE,
1247
1247
  floorExposureInfo: {},
1248
1248
  floorVideInfo: {},
1249
1249
  productVideInfo: {},
1250
1250
  tabsLoadAllDataInfo: {
1251
1251
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
1252
1252
  },
1253
1253
  updateShopInfosAllState: false,
1254
1254
  isVipShop: false,
1255
1255
  isJdShowNativeImmersivePlayer: false,
1256
1256
  ...shopConfig,
1257
1257
  pageScrollTop: 0,
1258
1258
  pageIdxHeightInfo: {
1259
1259
  list: [],
1260
1260
  },
1261
1261
  shopNavBarHeight: 0,
1262
1262
  },
1263
1263
  defaultQueryLogInfo: {
1264
1264
  sourceType: 'JDshop',
1265
1265
  sourceValue: '',
1266
1266
  moduleId: 'none',
1267
1267
  entrance: 'none',
1268
1268
  },
1269
1269
  sysInfo: {
1270
1270
  windowWidth: isPc ? 375 : 0,
1271
1271
  containerWidth: isPc ? 375 : 0,
1272
1272
  windowHeight: 0,
1273
1273
  netWorkType: '4g',
1274
1274
  jdBottomBarHeight: 0,
1275
1275
  jdNativeHeaderHeight: 0,
1276
1276
  isJdTabletDevice: false,
1277
1277
  isJdTabletLandscape: false,
1278
1278
  },
1279
1279
  queryInfo: {},
1280
1280
  shopInfo: {},
1281
1281
  openAppData: {},
1282
1282
  public info: CommonInterFace.BaseConfigInfo;
1283
1283
  public config: {
1284
1284
  [key: string]: any;
1285
1285
  };
1286
1286
  public lazyContainer: CommonInterFace.lazyContainer;
1287
1287
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
1288
1288
  public rootEleNode: HTMLElement | null;
1289
1289
  public checkStatusAndLoginPromise: object | null;
1290
1290
  private jmfeRegisterStatePromise: Promise<any> | null;
1291
1291
  private jmfeRegisterState: boolean;
1292
1292
  public loadJsSdkList: Array<any>;
1293
1293
  public loadJsSdkListCachePromise: any;
1294
1294
  constructor(opt) {
1295
1295
  this.info = this._getConfig(opt);
1296
1296
  this.config = {};
1297
1297
  this.loadJsSdkList = [];
1298
1298
  this.loadJsSdkListCachePromise = {};
1299
1299
  this.lazyContainer = {
1300
1300
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
1301
1301
  appLazyContainerList: [],
1302
1302
  appLazyFinishContainerList: [],
1303
1303
  },
1304
1304
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
1305
1305
  appLazyContainerList: [],
1306
1306
  appLazyFinishContainerList: [],
1307
1307
  },
1308
1308
  };
1309
1309
  this.renderedIsvComponents = {};
1310
1310
  this.rootEleNode = document.querySelector('body');
1311
1311
  this.checkStatusAndLoginPromise = null;
1312
1312
  this.jmfeRegisterStatePromise = null;
1313
1313
  this.loadOtherSdk();
1314
1314
  isJdApp && this.jmfeReayPromise();
1315
1315
  }
1316
1316
  _getConfig(opt) {
1317
1317
  return Object.assign({}, DefaultConfig, opt);
1318
1318
  }
1319
1319
 
1320
1320
  jmfeReayPromise(): Promise<any> {
1321
1321
  if (isJdApp) {
1322
1322
  if (this.jmfeRegisterState) {
1323
1323
  return Promise.resolve(true);
1324
1324
  } else {
1325
1325
  !this.jmfeRegisterStatePromise &&
1326
1326
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
1327
1327
  ready('jmfe', 3000)
1328
1328
  .then(() => {
1329
1329
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
1330
1330
  this.jmfeRegisterState = true;
1331
1331
  resolve(true);
1332
1332
  console.log('松果app内初始化注册jmfe认证完成');
1333
1333
  })
1334
1334
  .catch((err) => {
1335
1335
  console.error('jmfe ready error', err);
1336
1336
  reject(false);
1337
1337
  });
1338
1338
  }));
1339
1339
  return this.jmfeRegisterStatePromise;
1340
1340
  }
1341
1341
  } else {
1342
1342
  return Promise.reject(false);
1343
1343
  }
1344
1344
  }
1345
1345
 
1346
1346
  getJdScreenSizeInfo() {
1347
1347
  return new Promise((resolve) => {
1348
1348
  this.jmfeReayPromise().then(() => {
1349
1349
  return Promise.race([
1350
1350
  window.jmfe.getScreenSize(),
1351
1351
  this.taskTimeoutPromise(() => {
1352
1352
  return {
1353
1353
  status: '-10',
1354
1354
  msg: '获取大屏信息2s超时',
1355
1355
  };
1356
1356
  }),
1357
1357
  ])
1358
1358
  .then((res) => {
1359
1359
  console.log('===获取app大屏信息====', res);
1360
1360
  const { status, data } = res;
1361
1361
  if (status === '0' && data) {
1362
1362
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
1363
1363
  const getPageInfo = dealNativePixelToCssPixel({
1364
1364
  pageWidth,
1365
1365
  pageHeight,
1366
1366
  });
1367
1367
  this.info.sysInfo.jdScreenSizeType = sizeType;
1368
1368
  this.info.sysInfo.isJdTabletDevice = window.screen?.width >= 720;
1369
1369
  this.info.sysInfo.isJdTabletLandscape = isLandscape === '1';
1370
1370
  console.log(
1371
1371
  '===计算是否是app大屏信息,需满足宽度最新720===',
1372
1372
  getPageInfo,
1373
1373
  '原始数据',
1374
1374
  data,
1375
1375
  );
1376
1376
  resolve(getPageInfo);
1377
1377
  } else {
1378
1378
  resolve(false);
1379
1379
  }
1380
1380
  })
1381
1381
  .catch((err) => {
1382
1382
  console.log('获取大屏信息异常', err);
1383
1383
  resolve(false);
1384
1384
  });
1385
1385
  });
1386
1386
  });
1387
1387
  }
1388
1388
 
1389
1389
  listenJdTabletScreenChange() {
1390
1390
  this.jmfeReayPromise().then(() => {
1391
1391
  try {
1392
1392
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
1393
1393
  window.jmfe.listenDeviceScreenChange((event) => {
1394
1394
  console.log(
1395
1395
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
1396
1396
  event,
1397
1397
  '通过前端判断是不是横屏',
1398
1398
  window.matchMedia('(orientation: landscape)')?.matches,
1399
1399
  );
1400
1400
  const { orientation } = event?.data;
1401
1401
  if (orientation) {
1402
1402
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
1403
1403
  Taro.eventCenter.trigger(
1404
1404
  TaroEventType.TABLE_SCREEN_CHANGE,
1405
1405
  this.info.sysInfo.isJdTabletLandscape,
1406
1406
  orientation,
1407
1407
  );
1408
1408
  }
1409
1409
  });
1410
1410
  } catch (error) {
1411
1411
  console.log('listenScreenChange的打印error:', error);
1412
1412
  }
1413
1413
  });
1414
1414
  }
1415
1415
 
1416
1416
  updateBusinessDomainAndApi(domain, api) {
1417
1417
  }
1418
1418
 
1419
1419
  formatNativeScreenPageData(action) {
1420
1420
  let getChangePageInfo: any = null;
1421
1421
  try {
1422
1422
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
1423
1423
  JSON.stringify({
1424
1424
  plugin: 'JDHybridScreenPlugin',
1425
1425
  action,
1426
1426
  sync: '1',
1427
1427
  }),
1428
1428
  );
1429
1429
  const getChangePageInfoData =
1430
1430
  typeof getNativeScreenPageInfoStr === 'string'
1431
1431
  ? JSON.parse(getNativeScreenPageInfoStr)
1432
1432
  : null;
1433
1433
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
1434
1434
  const { code, data } = getChangePageInfoData;
1435
1435
  getChangePageInfo = code && code === '0' ? data : null;
1436
1436
  }
1437
1437
  } catch (e) {
1438
1438
  console.log('JDHybridScreenPlugin转换异常', e);
1439
1439
  }
1440
1440
  return getChangePageInfo;
1441
1441
  }
1442
1442
 
1443
1443
  isAndroidFoldScreen() {
1444
1444
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
1445
1445
  }
1446
1446
 
1447
1447
  getJdAndroidPageChangeScreenInfo() {
1448
1448
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
1449
1449
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
1450
1450
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1451
1451
  pageWidth: getPageScreenInfo.pageWidth,
1452
1452
  pageHeight: getPageScreenInfo.pageHeight,
1453
1453
  });
1454
1454
  getPageScreenInfo.pageWidth = pageWidth;
1455
1455
  getPageScreenInfo.pageHeight = pageHeight;
1456
1456
  }
1457
1457
  return getPageScreenInfo;
1458
1458
  }
1459
1459
 
1460
1460
  async getSystemInfo(params) {
1461
1461
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(params);
1462
1462
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
1463
1463
  let _isfoldScreen = false;
1464
1464
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
1465
1465
  console.info(
1466
1466
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
1467
1467
  getStorageData,
1468
1468
  '通过缓存值第一次判断是否是折叠屏',
1469
1469
  getStorageData === 'true',
1470
1470
  );
1471
1471
  if (!getStorageData) {
1472
1472
  _isfoldScreen = this.isAndroidFoldScreen();
1473
1473
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
1474
1474
  } else {
1475
1475
  _isfoldScreen = getStorageData === 'true';
1476
1476
  }
1477
1477
  if (_isfoldScreen) {
1478
1478
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
1479
1479
  if (getJdAndroidPageInfo) {
1480
1480
  info = getSystemInfos(getJdAndroidPageInfo);
1481
1481
  console.warn(
1482
1482
  '当前为松果安卓折叠屏app,获取折叠屏信息',
1483
1483
  getJdAndroidPageInfo,
1484
1484
  '获取转换后的系统信息',
1485
1485
  info,
1486
1486
  );
1487
1487
  sgmCustomReport({
1488
1488
  type: 2,
1489
1489
  code: 'android_jdapp_foldScreen_info',
1490
1490
  msg: {
1491
1491
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
1492
1492
  androidPageInfo: getJdAndroidPageInfo,
1493
1493
  jdAppVersionStr,
1494
1494
  taroSysInfo: info,
1495
1495
  },
1496
1496
  });
1497
1497
  }
1498
1498
  }
1499
1499
  }
1500
1500
  if (isJdApp) {
1501
1501
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
1502
1502
  }
1503
1503
  this.info.sysInfo = {
1504
1504
  actualNavBarHeight: 0,
1505
1505
  ...this.info.sysInfo,
1506
1506
  ...info,
1507
1507
  safeContentHeight: info?.screenHeight,
1508
1508
  headerHeight: 0,
1509
1509
  tabBarHeight: 0,
1510
1510
  };
1511
1511
  if (isJdApp) {
1512
1512
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
1513
1513
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
1514
1514
  this.getAddressCachePromise();
1515
1515
  this.getElderModePromise();
1516
1516
  this.getJDAppearanceStatePromise();
1517
1517
  this.createJdAndroidRquestEventForTouchStart();
1518
1518
  }
1519
1519
  this.getWifiVideoAutoPlayAsync();
1520
1520
  this.getMPaasConfigAsync();
1521
1521
  this.getNetWorkType();
1522
1522
  }
1523
1523
 
1524
1524
  taskTimeoutPromise(callBack, timeout = 2000) {
1525
1525
  return new Promise((resolve) => {
1526
1526
  setTimeout(() => {
1527
1527
  const getCallBackRes = typeof callBack === 'function' && callBack();
1528
1528
  return resolve(getCallBackRes || false);
1529
1529
  }, timeout);
1530
1530
  });
1531
1531
  }
1532
1532
 
1533
1533
  getElderModePromise() {
1534
1534
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1535
1535
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1536
1536
  } else {
1537
1537
  if (isJdAndAndroidDevice) {
1538
1538
  this.info.sysInfo.jdAppModeType = '0';
1539
1539
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1540
1540
  } else {
1541
1541
  return Promise.race([
1542
1542
  this.taskTimeoutPromise(() => {
1543
1543
  this.info.sysInfo.jdAppModeType = '0';
1544
1544
  return this.info.sysInfo.jdAppModeType;
1545
1545
  }),
1546
1546
  new Promise((resolve) => {
1547
1547
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
1548
1548
  if (!window[getCallBackName]) {
1549
1549
  window[getCallBackName] = (res) => {
1550
1550
  try {
1551
1551
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1552
1552
  const { status, data, msg } = getResJson;
1553
1553
  console.log(`获取松果app展示模式成功,返回结果${data}`);
1554
1554
  if (status === '0') {
1555
1555
  this.info.sysInfo.jdAppModeType = data;
1556
1556
  resolve(data);
1557
1557
  } else {
1558
1558
  resolve('0');
1559
1559
  }
1560
1560
  } catch (e) {
1561
1561
  resolve('0');
1562
1562
  }
1563
1563
  window[getCallBackName] = null;
1564
1564
  };
1565
1565
  }
1566
1566
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1567
1567
  method: 'callSyncRouterModuleWithParams',
1568
1568
  params: JSON.stringify({
1569
1569
  routerURL: 'router://JDBModeModule/getCurrentMode',
1570
1570
  routerParam: {},
1571
1571
  callBackName: `window.${getCallBackName}`,
1572
1572
  callBackId: `${getCallBackName}Ios`,
1573
1573
  }),
1574
1574
  });
1575
1575
  }),
1576
1576
  ]);
1577
1577
  }
1578
1578
  }
1579
1579
  }
1580
1580
  getAPPUseStraightCorner() {
1581
1581
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
1582
1582
  const params = {
1583
1583
  routerURL,
1584
1584
  routerParam: {},
1585
1585
  jdRouter: '1',
1586
1586
  };
1587
1587
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
1588
1588
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
1589
1589
  } else {
1590
1590
  return this.jmfeReayPromise()
1591
1591
  .then(() => {
1592
1592
  if (isJdAndHarmonyDevice || !isJdApp) {
1593
1593
  console.log('not APP or is Harmony');
1594
1594
  return Promise.resolve(false);
1595
1595
  }
1596
1596
  console.log('jmfe setShareInfo', params);
1597
1597
  return Promise.race([
1598
1598
  window.jmfe.callRouter(params),
1599
1599
  this.taskTimeoutPromise(() => {
1600
1600
  return false;
1601
1601
  }),
1602
1602
  ]).then(({ status, data }) => {
1603
1603
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
1604
1604
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
1605
1605
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
1606
1606
  return Promise.resolve(status === '0' && Number(data) === 1);
1607
1607
  });
1608
1608
  })
1609
1609
  .catch((e) => {
1610
1610
  console.log('jmfe error', e);
1611
1611
  return Promise.resolve(false);
1612
1612
  });
1613
1613
  }
1614
1614
  }
1615
1615
 
1616
1616
  getJDAppearanceStatePromise() {
1617
1617
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1618
1618
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
1619
1619
  } else {
1620
1620
  return Promise.race([
1621
1621
  this.taskTimeoutPromise(() => {
1622
1622
  this.info.sysInfo.jdAppearanceState = '0';
1623
1623
  return this.info.sysInfo.jdAppearanceState;
1624
1624
  }),
1625
1625
  new Promise((resolve) => {
1626
1626
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
1627
1627
  if (!window[getCallBackName]) {
1628
1628
  window[getCallBackName] = (res) => {
1629
1629
  try {
1630
1630
  console.log('getJDAppearanceStatePromise', res);
1631
1631
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1632
1632
  const { status, data, msg } = getResJson;
1633
1633
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
1634
1634
  if (status === '0') {
1635
1635
  this.info.sysInfo.jdAppearanceState = data;
1636
1636
  resolve(data);
1637
1637
  } else {
1638
1638
  resolve('0');
1639
1639
  }
1640
1640
  } catch (e) {
1641
1641
  resolve('0');
1642
1642
  }
1643
1643
  window[getCallBackName] = null;
1644
1644
  };
1645
1645
  }
1646
1646
  if (isAndroidDevice) {
1647
1647
  const jsonString = JSON.stringify({
1648
1648
  callBackName: `window.${getCallBackName}`,
1649
1649
  });
1650
1650
  console.log('window.JDAppearance', window?.JDAppearance);
1651
1651
  window?.JDAppearance &&
1652
1652
  window?.JDAppearance?.getUiState &&
1653
1653
  window.JDAppearance.getUiState(jsonString);
1654
1654
  } else {
1655
1655
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1656
1656
  method: 'callSyncRouterModuleWithParams',
1657
1657
  params: JSON.stringify({
1658
1658
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
1659
1659
  routerParam: {},
1660
1660
  callBackName: `window.${getCallBackName}`,
1661
1661
  callBackId: `${getCallBackName}Ios`,
1662
1662
  }),
1663
1663
  });
1664
1664
  }
1665
1665
  }),
1666
1666
  ]);
1667
1667
  }
1668
1668
  }
1669
1669
 
1670
1670
  createJdAndroidRquestEventForTouchStart() {
1671
1671
  if (isJdAndAndroidDevice && window?.JdAndroid) {
1672
1672
  const rootEleNode = document.querySelector('body');
1673
1673
  if (rootEleNode) {
1674
1674
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
1675
1675
  }
1676
1676
  }
1677
1677
  }
1678
1678
  jdAndroidAddEventListenerTouchStart(e) {
1679
1679
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
1680
1680
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
1681
1681
  const hasCustomEle = e
1682
1682
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
1683
1683
  : false;
1684
1684
  if (!hasCustomEle) {
1685
1685
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
1686
1686
  console.log(
1687
1687
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1688
1688
  );
1689
1689
  }
1690
1690
  }
1691
1691
  }
1692
1692
  removeJdAndroidRquestEventForTouchStart() {
1693
1693
  if (isJdAndAndroidDevice && window.JdAndroid) {
1694
1694
  const rootEleNode = document.querySelector('body');
1695
1695
  if (rootEleNode) {
1696
1696
  rootEleNode.removeEventListener(
1697
1697
  'touchstart',
1698
1698
  this.jdAndroidAddEventListenerTouchStart,
1699
1699
  false,
1700
1700
  );
1701
1701
  }
1702
1702
  }
1703
1703
  }
1704
1704
 
1705
1705
  getNetWorkType() {
1706
1706
  if (isJdApp) {
1707
1707
  this.jmfeReayPromise().then(() => {
1708
1708
  window.jmfe
1709
1709
  .getNetworkStatus()
1710
1710
  .then(({ status, data }) => {
1711
1711
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
1712
1712
  if (status === '0') {
1713
1713
  this.info.sysInfo['netWorkType'] = data;
1714
1714
  } else {
1715
1715
  this._taroGetNetworkType();
1716
1716
  }
1717
1717
  })
1718
1718
  .catch((err) => {
1719
1719
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
1720
1720
  this._taroGetNetworkType();
1721
1721
  });
1722
1722
  });
1723
1723
  } else {
1724
1724
  this._taroGetNetworkType();
1725
1725
  }
1726
1726
  }
1727
1727
  _taroGetNetworkType() {
1728
1728
  Taro.getNetworkType().then((getRes) => {
1729
1729
  if (getRes && getRes.networkType) {
1730
1730
  this.info.sysInfo['netWorkType'] = getRes.networkType;
1731
1731
  console.log(
1732
1732
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1733
1733
  this.info.sysInfo['netWorkType'],
1734
1734
  );
1735
1735
  }
1736
1736
  });
1737
1737
  }
1738
1738
 
1739
1739
  getCacheAddressRouter() {
1740
1740
  if (window.jmfe && isJdApp) {
1741
1741
  if (!isJdAndHarmonyDevice) {
1742
1742
  return Promise.race([
1743
1743
  window.jmfe.callRouter({
1744
1744
  jdRouter: '1',
1745
1745
  routerURL: isAndroidDevice
1746
1746
  ? 'router://JDAddressModule/getCacheAddress'
1747
1747
  : 'router://JDBAddressCacheManagerModule/getCacheAddress',
1748
1748
  routerParam: { sceneId: 'basicShoppingProcess' },
1749
1749
  }),
1750
1750
  this.taskTimeoutPromise(() => {
1751
1751
  return {
1752
1752
  status: '-1000',
1753
1753
  msg: '原生router协议获取地址信息超时',
1754
1754
  };
1755
1755
  }, 3000),
1756
1756
  ]);
1757
1757
  } else {
1758
1758
  return Promise.resolve({
1759
1759
  status: '-1001',
1760
1760
  msg: '鸿蒙系统调用jmfe异常,获取失败',
1761
1761
  });
1762
1762
  }
1763
1763
  } else {
1764
1764
  return Promise.resolve({
1765
1765
  status: '-1002',
1766
1766
  msg: 'jmfe不存在,获取失败',
1767
1767
  });
1768
1768
  }
1769
1769
  }
1770
1770
 
1771
1771
  getAddressCachePromise() {
1772
1772
  return new Promise((resolve) => {
1773
1773
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
1774
1774
  resolve({
1775
1775
  lat: this.info.sysInfo.lat,
1776
1776
  lng: this.info.sysInfo.lng,
1777
1777
  area: this?.info?.sysInfo?.area,
1778
1778
  });
1779
1779
  } else {
1780
1780
  this.jmfeReayPromise()
1781
1781
  .then(() => {
1782
1782
  this.getCacheAddressRouter()
1783
1783
  .then((res) => {
1784
1784
  const { status, data } = res;
1785
1785
  console.log('原生端获取经纬度原始数据结果', status, data);
1786
1786
  if (status === '0' && data) {
1787
1787
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
1788
1788
  data || {};
1789
1789
  let area = '';
1790
1790
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
1791
1791
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
1792
1792
  if (provinceId) {
1793
1793
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
1794
1794
  this.info.pageInfo['address'] = area;
1795
1795
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
1796
1796
  Taro.eventCenter.trigger(
1797
1797
  TaroEventType.USER_AREA_UPDATE,
1798
1798
  this.info.pageInfo.address,
1799
1799
  );
1800
1800
  }
1801
1801
  resolve({
1802
1802
  lat: this.info.sysInfo['lat'],
1803
1803
  lng: this.info.sysInfo['lng'],
1804
1804
  area: area,
1805
1805
  });
1806
1806
  } else {
1807
1807
  typeof res === 'object' &&
1808
1808
  sgmCustomReport({
1809
1809
  type: 3,
1810
1810
  code: 'jdapp_getCacheAddress_info',
1811
1811
  msg: {
1812
1812
  title: '松果app内通过router协议获取用户地址及经纬度信息异常',
1813
1813
  jdAppVersion: jdAppVersionStr,
1814
1814
  ...res,
1815
1815
  },
1816
1816
  });
1817
1817
  resolve({ lat: '', lng: '', area: '' });
1818
1818
  }
1819
1819
  })
1820
1820
  .catch((e) => {
1821
1821
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e);
1822
1822
  resolve({ lat: '', lng: '', area: '' });
1823
1823
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
1824
1824
  });
1825
1825
  })
1826
1826
  .catch((e) => {
1827
1827
  resolve({ lat: '', lng: '', area: '' });
1828
1828
  console.log('判断jmfe不存在,获取经纬度信息异常e', e);
1829
1829
  });
1830
1830
  }
1831
1831
  });
1832
1832
  }
1833
1833
 
1834
1834
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1835
1835
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
1836
1836
  if (!isJdApp) {
1837
1837
  return;
1838
1838
  }
1839
1839
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
1840
1840
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
1841
1841
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
1842
1842
  'hybridHttpSwitch',
1843
1843
  isBeforePageReady,
1844
1844
  );
1845
1845
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
1846
1846
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1847
1847
  'isFollowAppVideoPlayStatus',
1848
1848
  isBeforePageReady,
1849
1849
  );
1850
1850
  console.log(
1851
1851
  'isBeforePageReady:',
1852
1852
  isBeforePageReady,
1853
1853
  'isFollowAppVideoPlayStatus:',
1854
1854
  isFollowAppVideoPlayStatus,
1855
1855
  );
1856
1856
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
1857
1857
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
1858
1858
  }
1859
1859
  }
1860
1860
 
1861
1861
  async getWifiVideoAutoPlayAsync() {
1862
1862
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
1863
1863
  if (!isJdApp) {
1864
1864
  return;
1865
1865
  }
1866
1866
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
1867
1867
  return 0;
1868
1868
  });
1869
1869
  if (Number(videoPlayStatus) === 1) {
1870
1870
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
1871
1871
  }
1872
1872
  }
1873
1873
 
1874
1874
  async getMPaasConfigAsync() {
1875
1875
  this.info.sysInfo.dynamicConfig = {};
1876
1876
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
1877
1877
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
1878
1878
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
1879
1879
  return this.updateMPaasConfigAsync(true);
1880
1880
  }
1881
1881
 
1882
1882
  getDynamicConfig(key: string) {
1883
1883
  return this.info.sysInfo.dynamicConfig[key];
1884
1884
  }
1885
1885
  async updateMPaasConfig() {
1886
1886
  console.log('updateMPaasConfig');
1887
1887
  if (
1888
1888
  isIosDevice &&
1889
1889
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1890
1890
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1891
1891
  ) {
1892
1892
  try {
1893
1893
  await this.updateMPaasConfigAsync(false);
1894
1894
  } catch (e) {
1895
1895
  console.log('updateMPaasConfigAsync:', e);
1896
1896
  }
1897
1897
  }
1898
1898
  }
1899
1899
 
1900
1900
  toLogin(options) {
1901
1901
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1902
1902
  ? this.toWxAppLogin(options)
1903
1903
  : this.toWebLogin(options);
1904
1904
  }
1905
1905
 
1906
1906
  doLogin(options) {
1907
1907
  return this.toLogin(options);
1908
1908
  }
1909
1909
 
1910
1910
  doLoginForJdPin(options = {}) {
1911
1911
  return this.doLogin({
1912
1912
  loginColor: {
1913
1913
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1914
1914
  dpin: 0,
1915
1915
  },
1916
1916
  ...options,
1917
1917
  });
1918
1918
  }
1919
1919
 
1920
1920
  toWebLogin(options) {
1921
1921
  let params: {
1922
1922
  returnurl: string;
1923
1923
  } = {
1924
1924
  returnurl: '',
1925
1925
  };
1926
1926
  const loginUrl = isPc
1927
1927
  ? `//passport.jd.com/new/login.aspx`
1928
1928
  : `${domain.mobileLogin}/user/login.action`;
1929
1929
  const defaultParams = {
1930
1930
  appid: '100',
1931
1931
  returnurl: window.location.href,
1932
1932
  };
1933
1933
  if (isString(options)) {
1934
1934
  params = Object.assign({}, defaultParams, {
1935
1935
  returnurl: options,
1936
1936
  });
1937
1937
  } else if (isObject(options)) {
1938
1938
  const { loginColor, ...otherOptions } = options;
1939
1939
  params = Object.assign({}, defaultParams, otherOptions);
1940
1940
  } else {
1941
1941
  params = defaultParams;
1942
1942
  }
1943
1943
  params.returnurl = encodeURIComponent(params.returnurl);
1944
1944
  let getFullUrl = loginUrl + '?' + serialize(params);
1945
1945
  if (isPc) {
1946
1946
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
1947
1947
  }
1948
1948
  return Promise.resolve({
1949
1949
  h5ToUrl: true,
1950
1950
  url: getFullUrl,
1951
1951
  }).then(() => {
1952
1952
  window.location.href = getFullUrl;
1953
1953
  });
1954
1954
  }
1955
1955
 
1956
1956
  toWxAppLogin(options = {}) {
1957
1957
  console.log('微信京购小程序中h5登录跳转', options);
1958
1958
  return Promise.resolve(true).then(() => {
1959
1959
  const { loginColor } = Object.assign(
1960
1960
  {},
1961
1961
  {
1962
1962
  loginColor: {
1963
1963
  biz: WXAPP_BIZ_KEY,
1964
1964
  dpin: 1,
1965
1965
  },
1966
1966
  },
1967
1967
  options,
1968
1968
  );
1969
1969
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1970
1970
  loginColor.biz
1971
1971
  }&url=${encodeURIComponent(window.location.href)}`;
1972
1972
  });
1973
1973
  }
1974
1974
 
1975
1975
  getLoginCookie() {
1976
1976
  return Promise.resolve({
1977
1977
  pin: cookie.get('pin') || '',
1978
1978
  });
1979
1979
  }
1980
1980
 
1981
1981
  clearLoginCookie() {
1982
1982
  cookie.remove('pin');
1983
1983
  }
1984
1984
 
1985
1985
  checkStatusAndLogin(options = {}) {
1986
1986
  if (!this.checkStatusAndLoginPromise) {
1987
1987
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1988
1988
  try {
1989
1989
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
1990
1990
  if (getLoginState) {
1991
1991
  resolve(true);
1992
1992
  } else {
1993
1993
  this.toLogin(options);
1994
1994
  reject(false);
1995
1995
  }
1996
1996
  } catch (e) {
1997
1997
  this.toLogin(options);
1998
1998
  reject(false);
1999
1999
  }
2000
2000
  });
2001
2001
  return this.checkStatusAndLoginPromise;
2002
2002
  } else {
2003
2003
  return this.checkStatusAndLoginPromise
2004
2004
  .then(() => {
2005
2005
  return Promise.resolve(true);
2006
2006
  })
2007
2007
  .catch(() => {
2008
2008
  this.toLogin(options);
2009
2009
  return Promise.reject(true);
2010
2010
  });
2011
2011
  }
2012
2012
  }
2013
2013
 
2014
2014
  checkJdStatusAndLogin(
2015
2015
  options = {
2016
2016
  loginColor: {
2017
2017
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2018
2018
  dpin: 0,
2019
2019
  },
2020
2020
  },
2021
2021
  ) {
2022
2022
  return this.checkStatusAndLogin(options);
2023
2023
  }
2024
2024
 
2025
2025
  doCheckLoginStateAndForApiCheck(options) {
2026
2026
  if (this.info.loginState) {
2027
2027
  return Promise.resolve(true);
2028
2028
  } else {
2029
2029
  return new Promise((resolve, reject) => {
2030
2030
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
2031
2031
  const getWqAuthToken = cookie.get('wq_auth_token');
2032
2032
  const getWqSkey = cookie.get('wq_skey');
2033
2033
  const getWqUin = cookie.get('wq_uin');
2034
2034
  const isLoginState =
2035
2035
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
2036
2036
  if (isLoginState) {
2037
2037
  this.info.loginState = true;
2038
2038
  resolve(true);
2039
2039
  } else {
2040
2040
  reject(false);
2041
2041
  }
2042
2042
  } else {
2043
2043
  Taro.request({
2044
2044
  url: api.isLogin,
2045
2045
  jsonp: true,
2046
2046
  timeout: 3000,
2047
2047
  success: (res) => {
2048
2048
  const { statusCode, data } = res;
2049
2049
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
2050
2050
  this.info.loginState = true;
2051
2051
  resolve(true);
2052
2052
  } else {
2053
2053
  reject(false);
2054
2054
  }
2055
2055
  },
2056
2056
  fail: (err) => {
2057
2057
  console.log('登录检查异常', err);
2058
2058
  reject(false);
2059
2059
  },
2060
2060
  });
2061
2061
  }
2062
2062
  });
2063
2063
  }
2064
2064
  }
2065
2065
 
2066
2066
  checkLoginStatus(options) {
2067
2067
  return new Promise(async (resolve, reject) => {
2068
2068
  try {
2069
2069
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2070
2070
  if (getLoginState) {
2071
2071
  const { pin } = await this.getLoginCookie();
2072
2072
  this.info.userInfo = {
2073
2073
  pin,
2074
2074
  encodePin: encodeURIComponent(pin),
2075
2075
  ptkey: '',
2076
2076
  };
2077
2077
  resolve(true);
2078
2078
  } else {
2079
2079
  reject(false);
2080
2080
  }
2081
2081
  } catch (e) {
2082
2082
  reject(false);
2083
2083
  }
2084
2084
  });
2085
2085
  }
2086
2086
 
2087
2087
  updatePageAndLogInfo(updateQuery = {}) {
2088
2088
  const createUpdateQueryInfo: {
2089
2089
  query: {
2090
2090
  shopId?: string | number;
2091
2091
  venderId?: string | number;
2092
2092
  };
2093
2093
  updateShopInfoState: boolean;
2094
2094
  } = Object.assign(
2095
2095
  {},
2096
2096
  {
2097
2097
  query: {},
2098
2098
  updateShopInfoState: false,
2099
2099
  },
2100
2100
  updateQuery,
2101
2101
  );
2102
2102
  console.log(
2103
2103
  '获取当前下发的店铺查询参数',
2104
2104
  updateQuery,
2105
2105
  '获取之前保存的shopInfo店铺查询参数',
2106
2106
  this.info?.shopInfo,
2107
2107
  );
2108
2108
  const { query, updateShopInfoState } = createUpdateQueryInfo;
2109
2109
  const { shopId, venderId, un_area } = query;
2110
2110
  if (updateShopInfoState) {
2111
2111
  this.info.queryInfo = {
2112
2112
  ...this.info.queryInfo,
2113
2113
  ...query,
2114
2114
  };
2115
2115
  if (shopId && venderId) {
2116
2116
  this.info.shopInfo = {
2117
2117
  shopId: `${shopId}`,
2118
2118
  venderId: `${venderId}`,
2119
2119
  };
2120
2120
  }
2121
2121
  } else {
2122
2122
  this.info.queryInfo = {
2123
2123
  ...query,
2124
2124
  };
2125
2125
  if (
2126
2126
  this.info.shopInfo?.shopId &&
2127
2127
  this.info.shopInfo?.venderId &&
2128
2128
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
2129
2129
  ) {
2130
2130
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
2131
2131
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
2132
2132
  console.log(
2133
2133
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
2134
2134
  this.info.queryInfo,
2135
2135
  );
2136
2136
  }
2137
2137
  }
2138
2138
  this.info.queryInfo['shopId'] &&
2139
2139
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
2140
2140
  this.info.queryInfo['venderId'] &&
2141
2141
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
2142
2142
  console.log(
2143
2143
  'h5==获取店铺下发查询参数\n',
2144
2144
  query,
2145
2145
  '\n获取店铺最后查询参数\n',
2146
2146
  this.info.queryInfo,
2147
2147
  '\n是否为更新店铺状态\n',
2148
2148
  updateShopInfoState,
2149
2149
  );
2150
2150
  const changeArea = un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : '';
2151
2151
  if (changeArea) {
2152
2152
  this.info.pageInfo.address = changeArea;
2153
2153
  this.info.pageInfo.un_area = changeArea;
2154
2154
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',');
2155
2155
  }
2156
2156
  }
2157
2157
 
2158
2158
  dealLoadSdkList() {
2159
2159
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
2160
2160
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
2161
2161
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
2162
2162
  let mergeLoadJsList = globalLoadJsList;
2163
2163
  try {
2164
2164
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
2165
2165
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
2166
2166
  getFindIndex !== -1
2167
2167
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
2168
2168
  : accArr.push(current);
2169
2169
  return accArr;
2170
2170
  }, []);
2171
2171
  } catch (e) {
2172
2172
  console.log('LoadJsList合并错误', e);
2173
2173
  }
2174
2174
  console.log(
2175
2175
  'globalLoadJsList',
2176
2176
  globalLoadJsList,
2177
2177
  'businessLoadJsList',
2178
2178
  businessLoadJsList,
2179
2179
  '两个加载jsList集合合并完成',
2180
2180
  mergeLoadJsList,
2181
2181
  );
2182
2182
  this.loadJsSdkList = mergeLoadJsList;
2183
2183
  return this.loadJsSdkList;
2184
2184
  }
2185
2185
 
2186
2186
  renderNextTickLoadSdk() {
2187
2187
  Taro.nextTick(() => {
2188
2188
  console.log(
2189
2189
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
2190
2190
  );
2191
2191
  setTimeout(() => {
2192
2192
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
2193
2193
  }, 1000);
2194
2194
  });
2195
2195
  }
2196
2196
 
2197
2197
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
2198
2198
  const getLoadJsList =
2199
2199
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
2200
2200
  const getLoadFilterList = getLoadJsList.filter((item) => {
2201
2201
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
2202
2202
  let getLoastLoadEventState = true;
2203
2203
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
2204
2204
  getLoastLoadEventState = isJdApp;
2205
2205
  }
2206
2206
  else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
2207
2207
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice
2208
2208
  }
2209
2209
  const getInitTriggerType =
2210
2210
  isJdApp && item?.initJdAppTriggerType
2211
2211
  ? item?.initTriggerType
2212
2212
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
2213
2213
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
2214
2214
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
2215
2215
  });
2216
2216
  console.log(
2217
2217
  '获取当前触发方式',
2218
2218
  triggerType,
2219
2219
  '获取当前最后加载的js集合',
2220
2220
  getLoadFilterList,
2221
2221
  '过滤前的加载集合',
2222
2222
  getLoadJsList,
2223
2223
  );
2224
2224
  getLoadFilterList.length > 0 &&
2225
2225
  getLoadFilterList.forEach((item) => {
2226
2226
  const isLoadState = /sgm/.test(item?.fileName)
2227
2227
  ? window?.shopGlobalSwitch?.openSgm === 'true'
2228
2228
  : true;
2229
2229
  isLoadState &&
2230
2230
  this.loadItemSdkPromise(item)
2231
2231
  .then((res) => {
2232
2232
  console.info('当前js地址' + item?.src, '加载状态', res);
2233
2233
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
2234
2234
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
2235
2235
  window.dra.run('init', { aid: res?.aid });
2236
2236
  window.dra.run('start');
2237
2237
  }
2238
2238
  })
2239
2239
  .catch((err) => {
2240
2240
  console.info('当前js地址加载异常', item?.src);
2241
2241
  window?.fetchErrorData &&
2242
2242
  window.fetchErrorData({
2243
2243
  title: '公共js加载异常',
2244
2244
  type: 'jsLoad',
2245
2245
  data: err,
2246
2246
  });
2247
2247
  });
2248
2248
  });
2249
2249
  }
2250
2250
  loadScriptEle(jsInfo, resolve, reject) {
2251
2251
  const getFileName = jsInfo?.fileName;
2252
2252
  if (getFileName) {
2253
2253
  const getEleId = `J_loadJs_${getFileName}`;
2254
2254
  const getEle = document.getElementById(getEleId);
2255
2255
  if (!getEle) {
2256
2256
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2257
2257
  const _sgmEle = document.createElement('script');
2258
2258
  _sgmEle.id = getEleId;
2259
2259
  _sgmEle.onload = function () {
2260
2260
  resolve({
2261
2261
  ...jsInfo,
2262
2262
  jsTip: 'js加载成功',
2263
2263
  });
2264
2264
  };
2265
2265
  _sgmEle.onerror = function () {
2266
2266
  reject({
2267
2267
  ...jsInfo,
2268
2268
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2269
2269
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
2270
2270
  });
2271
2271
  };
2272
2272
  const dataAttrList = ['timeout', 'fileName', 'env'];
2273
2273
  const getJsInfoKeyList = Object.keys(jsInfo);
2274
2274
  getJsInfoKeyList.forEach((key) => {
2275
2275
  if (key === 'async') {
2276
2276
  _sgmEle.async = jsInfo[key];
2277
2277
  } else if (key === 'crossOrigin') {
2278
2278
  _sgmEle.crossOrigin = jsInfo[key];
2279
2279
  } else if (key === 'src') {
2280
2280
  _sgmEle.src = `${jsInfo[key]}`;
2281
2281
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
2282
2282
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
2283
2283
  } else {
2284
2284
  _sgmEle.setAttribute(key, jsInfo[key]);
2285
2285
  }
2286
2286
  });
2287
2287
  document.head.appendChild(_sgmEle);
2288
2288
  } else {
2289
2289
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
2290
2290
  resolve({
2291
2291
  ...jsInfo,
2292
2292
  jsTip: 'js本身已存在页面中',
2293
2293
  });
2294
2294
  }
2295
2295
  } else {
2296
2296
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
2297
2297
  }
2298
2298
  }
2299
2299
 
2300
2300
  loadItemSdkPromise(jsInfo = {}) {
2301
2301
  if (jsInfo?.src) {
2302
2302
  const getInitLoadType =
2303
2303
  isJdApp && jsInfo?.initJdAppLoadType
2304
2304
  ? jsInfo?.initJdAppLoadType
2305
2305
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
2306
2306
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
2307
2307
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
2308
2308
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
2309
2309
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
2310
2310
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2311
2311
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
2312
2312
  try {
2313
2313
  const jsXhrRequest = new XMLHttpRequest();
2314
2314
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
2315
2315
  const jsUrl = `${jsInfo?.src}`;
2316
2316
  jsXhrRequest.open('GET', jsUrl, true);
2317
2317
  jsXhrRequest.onreadystatechange = () => {
2318
2318
  if (jsXhrRequest.readyState === 4) {
2319
2319
  const getReqStatus = jsXhrRequest.status;
2320
2320
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
2321
2321
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
2322
2322
  if (getInsetHeadState) {
2323
2323
  this.loadScriptEle(jsInfo, resolve, reject);
2324
2324
  } else {
2325
2325
  resolve({
2326
2326
  ...jsInfo,
2327
2327
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
2328
2328
  });
2329
2329
  }
2330
2330
  getReqStatus !== 200 &&
2331
2331
  sgmCustomReport({
2332
2332
  type: 3,
2333
2333
  code: 'js_load_special_code',
2334
2334
  msg: {
2335
2335
  msg: '当前js加载成功,状态非200,特殊上报观察',
2336
2336
  jsReqState: getReqStatus,
2337
2337
  env: getSgmCustomCode('js_load_special_code'),
2338
2338
  data: jsInfo,
2339
2339
  },
2340
2340
  });
2341
2341
  } else {
2342
2342
  const getRes = {
2343
2343
  ...jsInfo,
2344
2344
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2345
2345
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
2346
2346
  jsReqState: getReqStatus,
2347
2347
  };
2348
2348
  console.log('当前js请求状态异常,具体信息见', getRes);
2349
2349
  reject(getRes);
2350
2350
  }
2351
2351
  }
2352
2352
  };
2353
2353
  jsXhrRequest.onerror = () => {
2354
2354
  const getRes = {
2355
2355
  ...jsInfo,
2356
2356
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2357
2357
  jsReqError: '请求错误',
2358
2358
  };
2359
2359
  console.log('当前js请求错误', getRes);
2360
2360
  jsXhrRequest.abort();
2361
2361
  reject(getRes);
2362
2362
  };
2363
2363
  jsXhrRequest.ontimeout = () => {
2364
2364
  const getRes = {
2365
2365
  ...jsInfo,
2366
2366
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2367
2367
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
2368
2368
  jsReqState: jsXhrRequest.status,
2369
2369
  };
2370
2370
  console.log('当前js请求超时异常', getRes);
2371
2371
  jsXhrRequest.abort();
2372
2372
  reject(getRes);
2373
2373
  };
2374
2374
  jsXhrRequest.send();
2375
2375
  } catch (e) {
2376
2376
  console.log('执行js请求异常', e);
2377
2377
  reject({
2378
2378
  ...jsInfo,
2379
2379
  env: getSgmCustomCode(jsLoadErrorSgmCode),
2380
2380
  jsReqError: '未知异常',
2381
2381
  error: e,
2382
2382
  });
2383
2383
  }
2384
2384
  });
2385
2385
  } else {
2386
2386
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
2387
2387
  return this.loadScriptEle(jsInfo, resolve, reject);
2388
2388
  });
2389
2389
  }
2390
2390
  }
2391
2391
  return this.loadJsSdkListCachePromise[getFileKeyName];
2392
2392
  } else {
2393
2393
  return Promise.resolve({
2394
2394
  ...jsInfo,
2395
2395
  jsTip: 'js加载方式设置为不加载,当前不做处理',
2396
2396
  });
2397
2397
  }
2398
2398
  } else {
2399
2399
  return Promise.reject(jsInfo);
2400
2400
  }
2401
2401
  }