@conecli/cone-render 0.8.20-shop.97 → 0.8.20-shop.99

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
  isJdApp,
3
2
  isIosDevice,
4
3
  isAndroidDevice,
5
4
  isJdAndHarmonyDevice,
6
5
  isJdAndAndroidDevice,
7
6
  jdAppVersion,
8
7
  jdAppVersionStr,
9
8
  isString,
10
9
  isObject,
11
10
  serialize,
12
11
  dealNativePixelToCssPixel,
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
  const designWidth = 750;
23
22
  return (
24
23
  Math.ceil(
25
24
  (((parseInt(String(size), 10) / 40) * 750) / designWidth) * 10000
26
25
  ) /
27
26
  10000 +
28
27
  "rem"
29
28
  );
30
29
  loginState: false,
31
30
  cookiesStr: "",
32
31
  userInfo: userPinKey,
33
32
  isJingGouMiniViewState: false,
34
33
  isJingxiMiniViewState: false,
35
34
  pageInfo: {
36
35
  wxBusinessType: WX_BUSINESS_TYPE.NO,
37
36
  address: "",
38
37
  addressCommaStr: "",
39
38
  un_area: "",
40
39
  vapptype: "1",
41
40
  pageType: "home",
42
41
  isExposureState: false,
43
42
  moduleId: "",
44
43
  entrance: "",
45
44
  dataType: BUSINESS_TYPE.ONLINE,
46
45
  floorExposureInfo: {},
47
46
  floorVideInfo: {},
48
47
  productVideInfo: {},
49
48
  tabsLoadAllDataInfo: {
50
49
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]:
51
50
  false,
52
51
  },
53
52
  updateShopInfosAllState: false,
54
53
  isVipShop: false,
55
54
  isJdShowNativeImmersivePlayer: false,
56
55
  ...shopConfig,
57
56
  pageScrollTop: 0,
58
57
  pageIdxHeightInfo: {
59
58
  list: [],
60
59
  },
61
60
  shopNavBarHeight: 0,
62
61
  },
63
62
  defaultQueryLogInfo: {
64
63
  sourceType: "JDshop",
65
64
  sourceValue: "",
66
65
  moduleId: "none",
67
66
  entrance: "none",
68
67
  },
69
68
  sysInfo: {
70
69
  windowWidth: isPc ? 375 : 0,
71
70
  containerWidth: isPc ? 375 : 0,
72
71
  windowHeight: 0,
73
72
  netWorkType: "4g",
74
73
  jdBottomBarHeight: 0,
75
74
  jdNativeHeaderHeight: 0,
76
75
  },
77
76
  queryInfo: {},
78
77
  shopInfo: {},
79
78
  openAppData: {},
80
79
  public info: CommonInterFace.BaseConfigInfo;
81
80
  public config: {
82
81
  [key: string]: any;
83
82
  };
84
83
  public lazyContainer: CommonInterFace.lazyContainer;
85
84
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
86
85
  public rootEleNode: HTMLElement | null;
87
86
  public checkStatusAndLoginPromise: object | null;
88
87
  private jmfeRegisterStatePromise: Promise<any> | null;
89
88
  private jmfeRegisterState: boolean;
90
89
  constructor(opt) {
91
90
  this.info = this._getConfig(opt);
92
91
  this.config = {};
93
92
  this.lazyContainer = {
94
93
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
95
94
  appLazyContainerList: [],
96
95
  appLazyFinishContainerList: [],
97
96
  },
98
97
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
99
98
  appLazyContainerList: [],
100
99
  appLazyFinishContainerList: [],
101
100
  },
102
101
  };
103
102
  this.renderedIsvComponents = {};
104
103
  this.rootEleNode = document.querySelector("body");
105
104
  this.checkStatusAndLoginPromise = null;
106
105
  this.jmfeRegisterStatePromise = null;
107
106
  isJdApp && this.jmfeReayPromise();
108
107
  }
109
108
  _getConfig(opt) {
110
109
  return Object.assign({}, DefaultConfig, opt);
111
110
  }
112
111
 
113
112
  jmfeReayPromise(): Promise<any> {
114
113
  if (isJdApp) {
115
114
  if (this.jmfeRegisterState) {
116
115
  return Promise.resolve(true);
117
116
  } else {
118
117
  !this.jmfeRegisterStatePromise &&
119
118
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
120
119
  ready("jmfe", 3000)
121
120
  .then(() => {
122
121
  window?.jmfe &&
123
122
  window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
124
123
  this.jmfeRegisterState = true;
125
124
  resolve(true);
126
125
  console.log("松果app内初始化注册jmfe认证完成");
127
126
  })
128
127
  .catch(() => {
129
128
  reject(false);
130
129
  });
131
130
  }));
132
131
  return this.jmfeRegisterStatePromise;
133
132
  }
134
133
  } else {
135
134
  return Promise.reject(false);
136
135
  }
137
136
  }
138
137
 
139
138
  updateBusinessDomainAndApi(domain, api) {
140
139
  }
141
140
 
142
141
  formatNativeScreenPageData(action) {
143
142
  let getChangePageInfo: any = null;
144
143
  try {
145
144
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
146
145
  JSON.stringify({
147
146
  plugin: "JDHybridScreenPlugin",
148
147
  action,
149
148
  sync: "1",
150
149
  })
151
150
  );
152
151
  const getChangePageInfoData =
153
152
  typeof getNativeScreenPageInfoStr === "string"
154
153
  ? JSON.parse(getNativeScreenPageInfoStr)
155
154
  : null;
156
155
  if (getChangePageInfoData && typeof getChangePageInfoData === "object") {
157
156
  const { code, data } = getChangePageInfoData;
158
157
  getChangePageInfo = code && code === "0" ? data : null;
159
158
  }
160
159
  } catch (e) {
161
160
  console.log("JDHybridScreenPlugin转换异常", e);
162
161
  }
163
162
  return getChangePageInfo;
164
163
  }
165
164
 
166
165
  isAndroidFoldScreen() {
167
166
  return this.formatNativeScreenPageData("isFoldScreen") === "1";
168
167
  }
169
168
 
170
169
  getJdAndroidPageChangeScreenInfo() {
171
170
  const getPageScreenInfo = this.formatNativeScreenPageData("getScreenSize");
172
171
  if (
173
172
  getPageScreenInfo &&
174
173
  getPageScreenInfo?.pageWidth &&
175
174
  getPageScreenInfo?.pageHeight
176
175
  ) {
177
176
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
178
177
  pageWidth: getPageScreenInfo.pageWidth,
179
178
  pageHeight: getPageScreenInfo.pageHeight,
180
179
  });
181
180
  getPageScreenInfo.pageWidth = pageWidth;
182
181
  getPageScreenInfo.pageHeight = pageHeight;
183
182
  }
184
183
  return getPageScreenInfo;
185
184
  }
186
185
 
187
186
  getSystemInfo(params) {
188
187
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
189
188
  ? {}
190
189
  : getSystemInfos(params);
191
190
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
192
191
  const isfoldScreen = this.isAndroidFoldScreen();
193
192
  if (isfoldScreen) {
194
193
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
195
194
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo));
196
195
  console.info(
197
196
  "安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取",
198
197
  getJdAndroidPageInfo
199
198
  );
200
199
  }
201
200
  }
202
201
  this.info.sysInfo = {
203
202
  actualNavBarHeight: 0,
204
203
  ...this.info.sysInfo,
205
204
  ...info,
206
205
  safeContentHeight: info?.screenHeight,
207
206
  headerHeight: 0,
208
207
  tabBarHeight: 0,
209
208
  };
210
209
  if (isJdApp) {
211
210
  this.info.sysInfo["hostVersionName"] = jdAppVersionStr;
212
211
  this.info.sysInfo["hostAppVersion"] = jdAppVersion;
213
212
  this.getAddressCachePromise();
214
213
  this.getElderModePromise();
215
214
  this.getJDAppearanceStatePromise();
216
215
  this.createJdAndroidRquestEventForTouchStart();
217
216
  }
218
217
  this.getWifiVideoAutoPlayAsync();
219
218
  this.getMPaasConfigAsync();
220
219
  this.getNetWorkType();
221
220
  }
222
221
 
223
222
  taskTimeoutPromise(callBack, timeout = 2000) {
224
223
  return new Promise((resolve) => {
225
224
  setTimeout(() => {
226
225
  const getCallBackRes = typeof callBack === "function" && callBack();
227
226
  return resolve(getCallBackRes || false);
228
227
  }, timeout);
229
228
  });
230
229
  }
231
230
 
232
231
  getElderModePromise() {
233
232
  if (this.info.sysInfo.hasOwnProperty("jdAppModeType")) {
234
233
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
235
234
  } else {
236
235
  if (isJdAndAndroidDevice) {
237
236
  this.info.sysInfo.jdAppModeType = "0";
238
237
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
239
238
  } else {
240
239
  return Promise.race([
241
240
  this.taskTimeoutPromise(() => {
242
241
  this.info.sysInfo.jdAppModeType = "0";
243
242
  return this.info.sysInfo.jdAppModeType;
244
243
  }),
245
244
  new Promise((resolve) => {
246
245
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
247
246
  if (!window[getCallBackName]) {
248
247
  window[getCallBackName] = (res) => {
249
248
  try {
250
249
  const getResJson =
251
250
  typeof res === "string" ? JSON.parse(res) : res;
252
251
  const { status, data, msg } = getResJson;
253
252
  console.log(`获取松果app展示模式成功,返回结果${data}`);
254
253
  if (status === "0") {
255
254
  this.info.sysInfo.jdAppModeType = data;
256
255
  resolve(data);
257
256
  } else {
258
257
  resolve("0");
259
258
  }
260
259
  } catch (e) {
261
260
  resolve("0");
262
261
  }
263
262
  window[getCallBackName] = null;
264
263
  };
265
264
  }
266
265
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
267
266
  method: "callSyncRouterModuleWithParams",
268
267
  params: JSON.stringify({
269
268
  routerURL: "router://JDBModeModule/getCurrentMode",
270
269
  routerParam: {},
271
270
  callBackName: `window.${getCallBackName}`,
272
271
  callBackId: `${getCallBackName}Ios`,
273
272
  }),
274
273
  });
275
274
  }),
276
275
  ]);
277
276
  }
278
277
  }
279
278
  }
280
279
 
281
280
  getJDAppearanceStatePromise() {
282
281
  if (this.info.sysInfo.hasOwnProperty("jdAppearanceState")) {
283
282
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
284
283
  } else {
285
284
  return Promise.race([
286
285
  this.taskTimeoutPromise(() => {
287
286
  this.info.sysInfo.jdAppearanceState = "0";
288
287
  return this.info.sysInfo.jdAppearanceState;
289
288
  }),
290
289
  new Promise((resolve) => {
291
290
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
292
291
  if (!window[getCallBackName]) {
293
292
  window[getCallBackName] = (res) => {
294
293
  try {
295
294
  console.log("getJDAppearanceStatePromise", res);
296
295
  const getResJson =
297
296
  typeof res === "string" ? JSON.parse(res) : res;
298
297
  const { status, data, msg } = getResJson;
299
298
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
300
299
  if (status === "0") {
301
300
  this.info.sysInfo.jdAppearanceState = data;
302
301
  resolve(data);
303
302
  } else {
304
303
  resolve("0");
305
304
  }
306
305
  } catch (e) {
307
306
  resolve("0");
308
307
  }
309
308
  window[getCallBackName] = null;
310
309
  };
311
310
  }
312
311
  if (isAndroidDevice) {
313
312
  const jsonString = JSON.stringify({
314
313
  callBackName: `window.${getCallBackName}`,
315
314
  });
316
315
  console.log("window.JDAppearance", window.JDAppearance);
317
316
  window.JDAppearance && window.JDAppearance.getUiState(jsonString);
318
317
  } else {
319
318
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
320
319
  method: "callSyncRouterModuleWithParams",
321
320
  params: JSON.stringify({
322
321
  routerURL:
323
322
  "router://JDWebViewBusinessModule/getJDAppearanceState",
324
323
  routerParam: {},
325
324
  callBackName: `window.${getCallBackName}`,
326
325
  callBackId: `${getCallBackName}Ios`,
327
326
  }),
328
327
  });
329
328
  }
330
329
  }),
331
330
  ]);
332
331
  }
333
332
  }
334
333
 
335
334
  createJdAndroidRquestEventForTouchStart() {
336
335
  if (isJdAndAndroidDevice && window.JdAndroid) {
337
336
  const rootEleNode = document.querySelector("body");
338
337
  if (rootEleNode) {
339
338
  rootEleNode.addEventListener(
340
339
  "touchstart",
341
340
  this.jdAndroidAddEventListenerTouchStart,
342
341
  false
343
342
  );
344
343
  }
345
344
  }
346
345
  }
347
346
  jdAndroidAddEventListenerTouchStart(e) {
348
347
  const isH5SwiperCustomEle = e?.target?.closest(".J_h5SwiperCustom");
349
348
  if (!isH5SwiperCustomEle) {
350
349
  const hasCustomEle = e
351
350
  ? e?.target?.closest(".J_customScroll") ||
352
351
  e?.target?.closest(".J_customLayout")
353
352
  : false;
354
353
  if (!hasCustomEle) {
355
354
  window.JdAndroid.requestEvent(false);
356
355
  console.log(
357
356
  "createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false"
358
357
  );
359
358
  }
360
359
  }
361
360
  }
362
361
  removeJdAndroidRquestEventForTouchStart() {
363
362
  if (isJdAndAndroidDevice && window.JdAndroid) {
364
363
  const rootEleNode = document.querySelector("body");
365
364
  if (rootEleNode) {
366
365
  rootEleNode.removeEventListener(
367
366
  "touchstart",
368
367
  this.jdAndroidAddEventListenerTouchStart,
369
368
  false
370
369
  );
371
370
  }
372
371
  }
373
372
  }
374
373
 
375
374
  getNetWorkType() {
376
375
  if (isJdApp) {
377
376
  this.jmfeReayPromise().then(() => {
378
377
  window.jmfe
379
378
  .getNetworkStatus()
380
379
  .then(({ status, data }) => {
381
380
  console.log(
382
381
  "在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====",
383
382
  data
384
383
  );
385
384
  if (status === "0") {
386
385
  this.info.sysInfo["netWorkType"] = data;
387
386
  } else {
388
387
  this._taroGetNetworkType();
389
388
  }
390
389
  })
391
390
  .catch((err) => {
392
391
  console.log("在app内初始化通过jmfe对象获取网络状态异常====", err);
393
392
  this._taroGetNetworkType();
394
393
  });
395
394
  });
396
395
  } else {
397
396
  this._taroGetNetworkType();
398
397
  }
399
398
  }
400
399
  _taroGetNetworkType() {
401
400
  Taro.getNetworkType().then((getRes) => {
402
401
  if (getRes && getRes.networkType) {
403
402
  this.info.sysInfo["netWorkType"] = getRes.networkType;
404
403
  console.log(
405
404
  "在app内通过taro对象获取网络状态完成,当前网络状态",
406
405
  this.info.sysInfo["netWorkType"]
407
406
  );
408
407
  }
409
408
  });
410
409
  }
411
410
 
412
411
  getCacheAddressRouter() {
413
412
  if (!window.jmfe) return;
414
413
  if (isAndroidDevice) {
415
414
  return window.jmfe.callRouter({
416
415
  jdRouter: "1",
417
416
  routerURL: "router://JDAddressModule/getCacheAddress",
418
417
  routerParam: { sceneId: "basicShoppingProcess" },
419
418
  });
420
419
  } else if (isIosDevice) {
421
420
  return window.jmfe.callRouter({
422
421
  jdRouter: "1",
423
422
  routerURL: "router://JDBAddressCacheManagerModule/getCacheAddress",
424
423
  routerParam: { sceneId: "basicShoppingProcess" },
425
424
  });
426
425
  } else if (isJdAndHarmonyDevice) {
427
426
  return new Promise((resolve) => {
428
427
  resolve({});
429
428
  });
430
429
  } else {
431
430
  throw Error(
432
431
  "Unknown device type cannot obtain the address information through the route!"
433
432
  );
434
433
  }
435
434
  }
436
435
 
437
436
  getAddressCachePromise() {
438
437
  return new Promise((resolve) => {
439
438
  if (
440
439
  this?.info?.sysInfo?.lat &&
441
440
  this?.info?.sysInfo?.lng &&
442
441
  this?.info?.sysInfo?.area
443
442
  ) {
444
443
  resolve({
445
444
  lat: this.info.sysInfo.lat,
446
445
  lng: this.info.sysInfo.lng,
447
446
  area: this?.info?.sysInfo?.area,
448
447
  });
449
448
  } else {
450
449
  this.jmfeReayPromise()
451
450
  .then(() => {
452
451
  this.getCacheAddressRouter()
453
452
  .then(({ status, data }) => {
454
453
  if (status === "0" && data) {
455
454
  const {
456
455
  lat,
457
456
  latitude,
458
457
  lng,
459
458
  longitude,
460
459
  provinceId,
461
460
  cityId,
462
461
  countyId,
463
462
  townId,
464
463
  } = data || {};
465
464
  let area = "";
466
465
  this.info.sysInfo["lat"] = lat || latitude || "";
467
466
  this.info.sysInfo["lng"] = lng || longitude || "";
468
467
  if (provinceId) {
469
468
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${
470
469
  townId || 0
471
470
  }`;
472
471
  this.info.pageInfo["address"] = area;
473
472
  this.info.pageInfo["addressCommaStr"] = area.replace(
474
473
  /_/g,
475
474
  ","
476
475
  );
477
476
  }
478
477
  resolve({
479
478
  lat: lat,
480
479
  lng: lng,
481
480
  area: area,
482
481
  });
483
482
  } else {
484
483
  resolve({ lat: "", lng: "", area: "" });
485
484
  }
486
485
  })
487
486
  .catch((e) => {
488
487
  console.log(" ~~ file: index.h5.ts:514 ~~ .catch ~~ e:", e);
489
488
  resolve({ lat: "", lng: "", area: "" });
490
489
  });
491
490
  })
492
491
  .catch((e) => {
493
492
  console.log(" ~~ file: index.h5.ts:518 ~~ .catch ~~ e:", e);
494
493
  resolve({ lat: "", lng: "", area: "" });
495
494
  console.log("判断jmfe不存在,获取经纬度信息异常");
496
495
  });
497
496
  }
498
497
  });
499
498
  if (Number(videoPlayStatus) === 1) {
500
499
  this.info.sysInfo["wifiVideoAutoPlay"] = true;
501
500
  }
502
501
  }
503
502
 
504
503
  async getMPaasConfigAsync() {
505
504
  this.info.sysInfo["avifSwitch"] = {};
506
505
  this.info.sysInfo["isFollowAppVideoPlayStatus"] = false;
507
506
  return this.updateMPaasConfigAsync(true);
508
507
  }
509
508
  async updateMPaasConfig() {
510
509
  console.log("updateMPaasConfig");
511
510
  if (
512
511
  isIosDevice &&
513
512
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
514
513
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
515
514
  ) {
516
515
  await this.updateMPaasConfigAsync(false).catch((e) => {
517
516
  console.log("updateMPaasConfigAsync:", e);
518
517
  });
519
518
  }
520
519
  }
521
520
 
522
521
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
523
522
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady);
524
523
  if (!isJdApp) {
525
524
  return;
526
525
  }
527
526
  const avifSwitch = await getMPaasConfigByBussinessKey(
528
527
  "avifSwitch",
529
528
  isBeforePageReady
530
529
  );
531
530
  this.info.sysInfo["avifSwitch"] = avifSwitch;
532
531
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
533
532
  "isFollowAppVideoPlayStatus",
534
533
  isBeforePageReady
535
534
  );
536
535
  console.log(
537
536
  "isBeforePageReady:",
538
537
  isBeforePageReady,
539
538
  "isFollowAppVideoPlayStatus:",
540
539
  isFollowAppVideoPlayStatus
541
540
  );
542
541
  if (
543
542
  isFollowAppVideoPlayStatus === true ||
544
543
  isFollowAppVideoPlayStatus === "true"
545
544
  ) {
546
545
  this.info.sysInfo["isFollowAppVideoPlayStatus"] = true;
547
546
  }
548
547
  }
549
548
 
550
549
  toLogin(options) {
551
550
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
552
551
  ? this.toWxAppLogin(options)
553
552
  : this.toWebLogin(options);
554
553
  }
555
554
 
556
555
  doLogin(options) {
557
556
  return this.toLogin(options);
558
557
  }
559
558
 
560
559
  doLoginForJdPin(options = {}) {
561
560
  return this.doLogin({
562
561
  loginColor: {
563
562
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
564
563
  dpin: 0,
565
564
  },
566
565
  ...options,
567
566
  });
568
567
  }
569
568
 
570
569
  toWebLogin(options) {
571
570
  let params: {
572
571
  returnurl: string;
573
572
  } = {
574
573
  returnurl: "",
575
574
  };
576
575
  const loginUrl = isPc
577
576
  ? `//passport.jd.com/new/login.aspx`
578
577
  : `${domain.mobileLogin}/user/login.action`;
579
578
  const defaultParams = {
580
579
  appid: "100",
581
580
  returnurl: window.location.href,
582
581
  };
583
582
  if (isString(options)) {
584
583
  params = Object.assign({}, defaultParams, {
585
584
  returnurl: options,
586
585
  });
587
586
  } else if (isObject(options)) {
588
587
  const { loginColor, ...otherOptions } = options;
589
588
  params = Object.assign({}, defaultParams, otherOptions);
590
589
  } else {
591
590
  params = defaultParams;
592
591
  }
593
592
  params.returnurl = encodeURIComponent(params.returnurl);
594
593
  let getFullUrl = loginUrl + "?" + serialize(params);
595
594
  if (isPc) {
596
595
  getFullUrl = getFullUrl.replace(/returnurl/, "ReturnUrl");
597
596
  }
598
597
  return Promise.resolve({
599
598
  h5ToUrl: true,
600
599
  url: getFullUrl,
601
600
  }).then(() => {
602
601
  window.location.href = getFullUrl;
603
602
  });
604
603
  }
605
604
 
606
605
  toWxAppLogin(options = {}) {
607
606
  console.log("微信京购小程序中h5登录跳转", options);
608
607
  return Promise.resolve(true).then(() => {
609
608
  const { loginColor } = Object.assign(
610
609
  {},
611
610
  {
612
611
  loginColor: {
613
612
  bzi: WXAPP_BIZ_KEY,
614
613
  dpin: 1,
615
614
  },
616
615
  },
617
616
  options
618
617
  );
619
618
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
620
619
  loginColor.bzi
621
620
  }&url=${encodeURIComponent(window.location.href)}`;
622
621
  });
623
622
  }
624
623
 
625
624
  getLoginCookie() {
626
625
  return Promise.resolve({
627
626
  pin: cookie.get("pin") || "",
628
627
  });
629
628
  }
630
629
 
631
630
  clearLoginCookie() {
632
631
  cookie.remove("pin");
633
632
  }
634
633
 
635
634
  checkStatusAndLogin(options = {}) {
636
635
  if (!this.checkStatusAndLoginPromise) {
637
636
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
638
637
  try {
639
638
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
640
639
  options
641
640
  );
642
641
  if (getLoginState) {
643
642
  resolve(true);
644
643
  } else {
645
644
  this.toLogin(options);
646
645
  reject(false);
647
646
  }
648
647
  } catch (e) {
649
648
  this.toLogin(options);
650
649
  reject(false);
651
650
  }
652
651
  });
653
652
  return this.checkStatusAndLoginPromise;
654
653
  } else {
655
654
  return this.checkStatusAndLoginPromise
656
655
  .then(() => {
657
656
  return Promise.resolve(true);
658
657
  })
659
658
  .catch(() => {
660
659
  this.toLogin(options);
661
660
  return Promise.reject(true);
662
661
  });
663
662
  }
664
663
  }
665
664
 
666
665
  checkJdStatusAndLogin(
667
666
  options = {
668
667
  loginColor: {
669
668
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
670
669
  dpin: 0,
671
670
  },
672
671
  }
673
672
  ) {
674
673
  return this.checkStatusAndLogin(options);
675
674
  }
676
675
 
677
676
  doCheckLoginStateAndForApiCheck(options) {
678
677
  if (this.info.loginState) {
679
678
  return Promise.resolve(true);
680
679
  } else {
681
680
  return new Promise((resolve, reject) => {
682
681
  if (
683
682
  this.info.isJingGouMiniViewState ||
684
683
  this.info.isJingxiMiniViewState
685
684
  ) {
686
685
  const getWqAuthToken = cookie.get("wq_auth_token");
687
686
  const getWqSkey = cookie.get("wq_skey");
688
687
  const getWqUin = cookie.get("wq_uin");
689
688
  const isLoginState =
690
689
  options?.loginColor?.dpin === 0
691
690
  ? getWqAuthToken
692
691
  : getWqSkey && getWqUin;
693
692
  if (isLoginState) {
694
693
  this.info.loginState = true;
695
694
  resolve(true);
696
695
  } else {
697
696
  reject(false);
698
697
  }
699
698
  } else {
700
699
  Taro.request({
701
700
  url: api.isLogin,
702
701
  jsonp: true,
703
702
  timeout: 3000,
704
703
  success: (res) => {
705
704
  const { statusCode, data } = res;
706
705
  if (
707
706
  statusCode === 200 &&
708
707
  data?.islogin &&
709
708
  Number(data.islogin) === 1
710
709
  ) {
711
710
  this.info.loginState = true;
712
711
  resolve(true);
713
712
  } else {
714
713
  reject(false);
715
714
  }
716
715
  },
717
716
  fail: (err) => {
718
717
  console.log("登录检查异常", err);
719
718
  reject(false);
720
719
  },
721
720
  });
722
721
  }
723
722
  });
724
723
  }
725
724
  }
726
725
 
727
726
  checkLoginStatus(options) {
728
727
  return new Promise(async (resolve, reject) => {
729
728
  try {
730
729
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
731
730
  options
732
731
  );
733
732
  if (getLoginState) {
734
733
  const { pin } = await this.getLoginCookie();
735
734
  this.info.userInfo = {
736
735
  pin,
737
736
  encodePin: encodeURIComponent(pin),
738
737
  ptkey: "",
739
738
  };
740
739
  resolve(true);
741
740
  } else {
742
741
  reject(false);
743
742
  }
744
743
  } catch (e) {
745
744
  reject(false);
746
745
  }
747
746
  });
748
747
  }
749
748
 
750
749
  updatePageAndLogInfo(updateQuery = {}) {
751
750
  const createUpdateQueryInfo: {
752
751
  query: {
753
752
  shopId?: string | number;
754
753
  venderId?: string | number;
755
754
  };
756
755
  updateShopInfoState: boolean;
757
756
  } = Object.assign(
758
757
  {},
759
758
  {
760
759
  query: {},
761
760
  updateShopInfoState: false,
762
761
  },
763
762
  updateQuery
764
763
  );
765
764
  console.log(
766
765
  "获取当前下发的店铺查询参数",
767
766
  updateQuery,
768
767
  "获取之前保存的shopInfo店铺查询参数",
769
768
  this.info?.shopInfo
770
769
  );
771
770
  const { query, updateShopInfoState } = createUpdateQueryInfo;
772
771
  const { shopId, venderId, un_area } = query;
773
772
  if (updateShopInfoState) {
774
773
  this.info.queryInfo = {
775
774
  ...this.info.queryInfo,
776
775
  ...query,
777
776
  };
778
777
  if (shopId && venderId) {
779
778
  this.info.shopInfo = {
780
779
  shopId: `${shopId}`,
781
780
  venderId: `${venderId}`,
782
781
  };
783
782
  }
784
783
  } else {
785
784
  this.info.queryInfo = {
786
785
  ...query,
787
786
  };
788
787
  if (
789
788
  this.info.shopInfo?.shopId &&
790
789
  this.info.shopInfo?.venderId &&
791
790
  (this.info.shopInfo.shopId == shopId ||
792
791
  this.info.shopInfo.venderId == venderId)
793
792
  ) {
794
793
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
795
794
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
796
795
  console.log(
797
796
  "当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数",
798
797
  this.info.queryInfo
799
798
  );
800
799
  }
801
800
  }
802
801
  this.info.queryInfo["shopId"] &&
803
802
  (this.info.queryInfo["shopId"] = `${this.info.queryInfo["shopId"]}`);
804
803
  this.info.queryInfo["venderId"] &&
805
804
  (this.info.queryInfo["venderId"] = `${this.info.queryInfo["venderId"]}`);
806
805
  console.log(
807
806
  "h5==获取店铺下发查询参数\n",
808
807
  query,
809
808
  "\n获取店铺最后查询参数\n",
810
809
  this.info.queryInfo,
811
810
  "\n是否为更新店铺状态\n",
812
811
  updateShopInfoState
813
812
  );
814
813
  const changeArea =
815
814
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : "";
816
815
  if (changeArea) {
817
816
  this.info.pageInfo.address = changeArea;
818
817
  this.info.pageInfo.un_area = changeArea;
819
818
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ",");
820
819
  }
821
820
  }
821
+ import Taro from '@tarojs/taro'
822
822
  isJdApp,
823
823
  isIosDevice,
824
824
  isAndroidDevice,
825
825
  isJdAndHarmonyDevice,
826
826
  isJdAndAndroidDevice,
827
827
  jdAppVersion,
828
828
  jdAppVersionStr,
829
829
  isString,
830
830
  isObject,
831
831
  serialize,
832
832
  dealNativePixelToCssPixel,
833
833
  BUSINESS_TYPE,
834
834
  JSSDK_APP_WEBVIEW_CODE,
835
835
  SECTION_HOME_TAB_NAME_TYPE,
836
836
  SECTION_HOME_TAB_TYPE,
837
837
  WXAPP_BIZ_KEY,
838
838
  WX_BUSINESS_TYPE,
839
839
  MPAAS_CONFIG_APP_VERSION,
840
840
  MPAAS_CONFIG_APP_LOW_VERSION,
841
841
  WXAPP_BIZ_SHOP_LIGHT_KEY,
842
842
  const designWidth = 750
843
843
  return (
844
844
  Math.ceil(
845
845
  (((parseInt(String(size), 10) / 40) * 750) / designWidth) * 10000,
846
846
  ) /
847
847
  10000 +
848
848
  'rem'
849
849
  )
850
850
  loginState: false,
851
851
  cookiesStr: '',
852
852
  userInfo: userPinKey,
853
853
  isJingGouMiniViewState: false,
854
854
  isJingxiMiniViewState: false,
855
855
  pageInfo: {
856
856
  wxBusinessType: WX_BUSINESS_TYPE.NO,
857
857
  address: '',
858
858
  addressCommaStr: '',
859
859
  un_area: '',
860
860
  vapptype: '1',
861
861
  pageType: 'home',
862
862
  isExposureState: false,
863
863
  moduleId: '',
864
864
  entrance: '',
865
865
  dataType: BUSINESS_TYPE.ONLINE,
866
866
  floorExposureInfo: {},
867
867
  floorVideInfo: {},
868
868
  productVideInfo: {},
869
869
  tabsLoadAllDataInfo: {
870
870
  [SECTION_HOME_TAB_NAME_TYPE[
871
871
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
872
872
  ]]: false,
873
873
  },
874
874
  updateShopInfosAllState: false,
875
875
  isVipShop: false,
876
876
  isJdShowNativeImmersivePlayer: false,
877
877
  ...shopConfig,
878
878
  pageScrollTop: 0,
879
879
  pageIdxHeightInfo: {
880
880
  list: [],
881
881
  },
882
882
  shopNavBarHeight: 0,
883
883
  },
884
884
  defaultQueryLogInfo: {
885
885
  sourceType: 'JDshop',
886
886
  sourceValue: '',
887
887
  moduleId: 'none',
888
888
  entrance: 'none',
889
889
  },
890
890
  sysInfo: {
891
891
  windowWidth: isPc ? 375 : 0,
892
892
  containerWidth: isPc ? 375 : 0,
893
893
  windowHeight: 0,
894
894
  netWorkType: '4g',
895
895
  jdBottomBarHeight: 0,
896
896
  jdNativeHeaderHeight: 0,
897
897
  },
898
898
  queryInfo: {},
899
899
  shopInfo: {},
900
900
  openAppData: {},
901
901
  public info: CommonInterFace.BaseConfigInfo
902
902
  public config: {
903
903
  [key: string]: any
904
904
  }
905
905
  public lazyContainer: CommonInterFace.lazyContainer
906
906
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
907
907
  public rootEleNode: HTMLElement | null
908
908
  public checkStatusAndLoginPromise: object | null
909
909
  private jmfeRegisterStatePromise: Promise<any> | null
910
910
  private jmfeRegisterState: boolean
911
911
  constructor(opt) {
912
912
  this.info = this._getConfig(opt)
913
913
  this.config = {}
914
914
  this.lazyContainer = {
915
915
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
916
916
  appLazyContainerList: [],
917
917
  appLazyFinishContainerList: [],
918
918
  },
919
919
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
920
920
  appLazyContainerList: [],
921
921
  appLazyFinishContainerList: [],
922
922
  },
923
923
  }
924
924
  this.renderedIsvComponents = {}
925
925
  this.rootEleNode = document.querySelector('body')
926
926
  this.checkStatusAndLoginPromise = null
927
927
  this.jmfeRegisterStatePromise = null
928
928
  isJdApp && this.jmfeReayPromise()
929
929
  }
930
930
  _getConfig(opt) {
931
931
  return Object.assign({}, DefaultConfig, opt)
932
932
  }
933
933
 
934
934
  jmfeReayPromise(): Promise<any> {
935
935
  if (isJdApp) {
936
936
  if (this.jmfeRegisterState) {
937
937
  return Promise.resolve(true)
938
938
  } else {
939
939
  !this.jmfeRegisterStatePromise &&
940
940
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
941
941
  ready('jmfe', 3000)
942
942
  .then(() => {
943
943
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
944
944
  this.jmfeRegisterState = true
945
945
  resolve(true)
946
946
  console.log('松果app内初始化注册jmfe认证完成')
947
947
  })
948
948
  .catch(() => {
949
949
  reject(false)
950
950
  })
951
951
  }))
952
952
  return this.jmfeRegisterStatePromise
953
953
  }
954
954
  } else {
955
955
  return Promise.reject(false)
956
956
  }
957
957
  }
958
958
 
959
959
  updateBusinessDomainAndApi(domain, api) {
960
960
  }
961
961
 
962
962
  formatNativeScreenPageData(action) {
963
963
  let getChangePageInfo: any = null
964
964
  try {
965
965
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
966
966
  JSON.stringify({
967
967
  plugin: 'JDHybridScreenPlugin',
968
968
  action,
969
969
  sync: '1',
970
970
  }),
971
971
  )
972
972
  const getChangePageInfoData =
973
973
  typeof getNativeScreenPageInfoStr === 'string'
974
974
  ? JSON.parse(getNativeScreenPageInfoStr)
975
975
  : null
976
976
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
977
977
  const { code, data } = getChangePageInfoData
978
978
  getChangePageInfo = code && code === '0' ? data : null
979
979
  }
980
980
  } catch (e) {
981
981
  console.log('JDHybridScreenPlugin转换异常', e)
982
982
  }
983
983
  return getChangePageInfo
984
984
  }
985
985
 
986
986
  isAndroidFoldScreen() {
987
987
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
988
988
  }
989
989
 
990
990
  getJdAndroidPageChangeScreenInfo() {
991
991
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
992
992
  if (
993
993
  getPageScreenInfo &&
994
994
  getPageScreenInfo?.pageWidth &&
995
995
  getPageScreenInfo?.pageHeight
996
996
  ) {
997
997
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
998
998
  pageWidth: getPageScreenInfo.pageWidth,
999
999
  pageHeight: getPageScreenInfo.pageHeight,
1000
1000
  })
1001
1001
  getPageScreenInfo.pageWidth = pageWidth
1002
1002
  getPageScreenInfo.pageHeight = pageHeight
1003
1003
  }
1004
1004
  return getPageScreenInfo
1005
1005
  }
1006
1006
 
1007
1007
  getSystemInfo(params) {
1008
1008
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
1009
1009
  ? {}
1010
1010
  : getSystemInfos(params)
1011
1011
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
1012
1012
  const isfoldScreen = this.isAndroidFoldScreen()
1013
1013
  if (isfoldScreen) {
1014
1014
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
1015
1015
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
1016
1016
  console.info(
1017
1017
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
1018
1018
  getJdAndroidPageInfo,
1019
1019
  )
1020
1020
  }
1021
1021
  }
1022
1022
  this.info.sysInfo = {
1023
1023
  actualNavBarHeight: 0,
1024
1024
  ...this.info.sysInfo,
1025
1025
  ...info,
1026
1026
  safeContentHeight: info?.screenHeight,
1027
1027
  headerHeight: 0,
1028
1028
  tabBarHeight: 0,
1029
1029
  }
1030
1030
  if (isJdApp) {
1031
1031
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
1032
1032
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
1033
1033
  this.getAddressCachePromise()
1034
1034
  this.getElderModePromise()
1035
1035
  this.getJDAppearanceStatePromise()
1036
1036
  this.createJdAndroidRquestEventForTouchStart()
1037
1037
  }
1038
1038
  this.getWifiVideoAutoPlayAsync()
1039
1039
  this.getMPaasConfigAsync()
1040
1040
  this.getNetWorkType()
1041
1041
  }
1042
1042
 
1043
1043
  taskTimeoutPromise(callBack, timeout = 2000) {
1044
1044
  return new Promise(resolve => {
1045
1045
  setTimeout(() => {
1046
1046
  const getCallBackRes = typeof callBack === 'function' && callBack()
1047
1047
  return resolve(getCallBackRes || false)
1048
1048
  }, timeout)
1049
1049
  })
1050
1050
  }
1051
1051
 
1052
1052
  getElderModePromise() {
1053
1053
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1054
1054
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1055
1055
  } else {
1056
1056
  if (isJdAndAndroidDevice) {
1057
1057
  this.info.sysInfo.jdAppModeType = '0'
1058
1058
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
1059
1059
  } else {
1060
1060
  return Promise.race([
1061
1061
  this.taskTimeoutPromise(() => {
1062
1062
  this.info.sysInfo.jdAppModeType = '0'
1063
1063
  return this.info.sysInfo.jdAppModeType
1064
1064
  }),
1065
1065
  new Promise(resolve => {
1066
1066
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
1067
1067
  if (!window[getCallBackName]) {
1068
1068
  window[getCallBackName] = res => {
1069
1069
  try {
1070
1070
  const getResJson =
1071
1071
  typeof res === 'string' ? JSON.parse(res) : res
1072
1072
  const { status, data, msg } = getResJson
1073
1073
  console.log(`获取松果app展示模式成功,返回结果${data}`)
1074
1074
  if (status === '0') {
1075
1075
  this.info.sysInfo.jdAppModeType = data
1076
1076
  resolve(data)
1077
1077
  } else {
1078
1078
  resolve('0')
1079
1079
  }
1080
1080
  } catch (e) {
1081
1081
  resolve('0')
1082
1082
  }
1083
1083
  window[getCallBackName] = null
1084
1084
  }
1085
1085
  }
1086
1086
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1087
1087
  method: 'callSyncRouterModuleWithParams',
1088
1088
  params: JSON.stringify({
1089
1089
  routerURL: 'router://JDBModeModule/getCurrentMode',
1090
1090
  routerParam: {},
1091
1091
  callBackName: `window.${getCallBackName}`,
1092
1092
  callBackId: `${getCallBackName}Ios`,
1093
1093
  }),
1094
1094
  })
1095
1095
  }),
1096
1096
  ])
1097
1097
  }
1098
1098
  }
1099
1099
  }
1100
1100
 
1101
1101
  getJDAppearanceStatePromise() {
1102
1102
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1103
1103
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
1104
1104
  } else {
1105
1105
  return Promise.race([
1106
1106
  this.taskTimeoutPromise(() => {
1107
1107
  this.info.sysInfo.jdAppearanceState = '0'
1108
1108
  return this.info.sysInfo.jdAppearanceState
1109
1109
  }),
1110
1110
  new Promise(resolve => {
1111
1111
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
1112
1112
  if (!window[getCallBackName]) {
1113
1113
  window[getCallBackName] = res => {
1114
1114
  try {
1115
1115
  console.log('getJDAppearanceStatePromise', res)
1116
1116
  const getResJson =
1117
1117
  typeof res === 'string' ? JSON.parse(res) : res
1118
1118
  const { status, data, msg } = getResJson
1119
1119
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
1120
1120
  if (status === '0') {
1121
1121
  this.info.sysInfo.jdAppearanceState = data
1122
1122
  resolve(data)
1123
1123
  } else {
1124
1124
  resolve('0')
1125
1125
  }
1126
1126
  } catch (e) {
1127
1127
  resolve('0')
1128
1128
  }
1129
1129
  window[getCallBackName] = null
1130
1130
  }
1131
1131
  }
1132
1132
  if (isAndroidDevice) {
1133
1133
  const jsonString = JSON.stringify({
1134
1134
  callBackName: `window.${getCallBackName}`,
1135
1135
  })
1136
1136
  console.log('window.JDAppearance', window.JDAppearance)
1137
1137
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
1138
1138
  } else {
1139
1139
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1140
1140
  method: 'callSyncRouterModuleWithParams',
1141
1141
  params: JSON.stringify({
1142
1142
  routerURL:
1143
1143
  'router://JDWebViewBusinessModule/getJDAppearanceState',
1144
1144
  routerParam: {},
1145
1145
  callBackName: `window.${getCallBackName}`,
1146
1146
  callBackId: `${getCallBackName}Ios`,
1147
1147
  }),
1148
1148
  })
1149
1149
  }
1150
1150
  }),
1151
1151
  ])
1152
1152
  }
1153
1153
  }
1154
1154
 
1155
1155
  createJdAndroidRquestEventForTouchStart() {
1156
1156
  if (isJdAndAndroidDevice && window.JdAndroid) {
1157
1157
  const rootEleNode = document.querySelector('body')
1158
1158
  if (rootEleNode) {
1159
1159
  rootEleNode.addEventListener(
1160
1160
  'touchstart',
1161
1161
  this.jdAndroidAddEventListenerTouchStart,
1162
1162
  false,
1163
1163
  )
1164
1164
  }
1165
1165
  }
1166
1166
  }
1167
1167
  jdAndroidAddEventListenerTouchStart(e) {
1168
1168
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
1169
1169
  if (!isH5SwiperCustomEle) {
1170
1170
  const hasCustomEle = e
1171
1171
  ? e?.target?.closest('.J_customScroll') ||
1172
1172
  e?.target?.closest('.J_customLayout')
1173
1173
  : false
1174
1174
  if (!hasCustomEle) {
1175
1175
  window.JdAndroid.requestEvent(false)
1176
1176
  console.log(
1177
1177
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
1178
1178
  )
1179
1179
  }
1180
1180
  }
1181
1181
  }
1182
1182
  removeJdAndroidRquestEventForTouchStart() {
1183
1183
  if (isJdAndAndroidDevice && window.JdAndroid) {
1184
1184
  const rootEleNode = document.querySelector('body')
1185
1185
  if (rootEleNode) {
1186
1186
  rootEleNode.removeEventListener(
1187
1187
  'touchstart',
1188
1188
  this.jdAndroidAddEventListenerTouchStart,
1189
1189
  false,
1190
1190
  )
1191
1191
  }
1192
1192
  }
1193
1193
  }
1194
1194
 
1195
1195
  getNetWorkType() {
1196
1196
  if (isJdApp) {
1197
1197
  this.jmfeReayPromise().then(() => {
1198
1198
  window.jmfe
1199
1199
  .getNetworkStatus()
1200
1200
  .then(({ status, data }) => {
1201
1201
  console.log(
1202
1202
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
1203
1203
  data,
1204
1204
  )
1205
1205
  if (status === '0') {
1206
1206
  this.info.sysInfo['netWorkType'] = data
1207
1207
  } else {
1208
1208
  this._taroGetNetworkType()
1209
1209
  }
1210
1210
  })
1211
1211
  .catch(err => {
1212
1212
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
1213
1213
  this._taroGetNetworkType()
1214
1214
  })
1215
1215
  })
1216
1216
  } else {
1217
1217
  this._taroGetNetworkType()
1218
1218
  }
1219
1219
  }
1220
1220
  _taroGetNetworkType() {
1221
1221
  Taro.getNetworkType().then(getRes => {
1222
1222
  if (getRes && getRes.networkType) {
1223
1223
  this.info.sysInfo['netWorkType'] = getRes.networkType
1224
1224
  console.log(
1225
1225
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1226
1226
  this.info.sysInfo['netWorkType'],
1227
1227
  )
1228
1228
  }
1229
1229
  })
1230
1230
  }
1231
1231
 
1232
1232
  getCacheAddressRouter() {
1233
1233
  if (!window.jmfe) return
1234
1234
  if (isAndroidDevice) {
1235
1235
  return window.jmfe.callRouter({
1236
1236
  jdRouter: '1',
1237
1237
  routerURL: 'router://JDAddressModule/getCacheAddress',
1238
1238
  routerParam: { sceneId: 'basicShoppingProcess' },
1239
1239
  })
1240
1240
  } else if (isIosDevice) {
1241
1241
  return window.jmfe.callRouter({
1242
1242
  jdRouter: '1',
1243
1243
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1244
1244
  routerParam: { sceneId: 'basicShoppingProcess' },
1245
1245
  })
1246
1246
  } else if (isJdAndHarmonyDevice) {
1247
1247
  return new Promise(resolve => {
1248
1248
  resolve({})
1249
1249
  })
1250
1250
  } else {
1251
1251
  throw Error(
1252
1252
  'Unknown device type cannot obtain the address information through the route!',
1253
1253
  )
1254
1254
  }
1255
1255
  }
1256
1256
 
1257
1257
  getAddressCachePromise() {
1258
1258
  return new Promise(resolve => {
1259
1259
  if (
1260
1260
  this?.info?.sysInfo?.lat &&
1261
1261
  this?.info?.sysInfo?.lng &&
1262
1262
  this?.info?.sysInfo?.area
1263
1263
  ) {
1264
1264
  resolve({
1265
1265
  lat: this.info.sysInfo.lat,
1266
1266
  lng: this.info.sysInfo.lng,
1267
1267
  area: this?.info?.sysInfo?.area,
1268
1268
  })
1269
1269
  } else {
1270
1270
  this.jmfeReayPromise()
1271
1271
  .then(() => {
1272
1272
  this.getCacheAddressRouter()
1273
1273
  .then(({ status, data }) => {
1274
1274
  if (status === '0' && data) {
1275
1275
  const {
1276
1276
  lat,
1277
1277
  latitude,
1278
1278
  lng,
1279
1279
  longitude,
1280
1280
  provinceId,
1281
1281
  cityId,
1282
1282
  countyId,
1283
1283
  townId,
1284
1284
  } = data || {}
1285
1285
  let area = ''
1286
1286
  this.info.sysInfo['lat'] = lat || latitude || ''
1287
1287
  this.info.sysInfo['lng'] = lng || longitude || ''
1288
1288
  if (provinceId) {
1289
1289
  area = `${provinceId}_${cityId || 0}_${countyId ||
1290
1290
  0}_${townId || 0}`
1291
1291
  this.info.pageInfo['address'] = area
1292
1292
  this.info.pageInfo['addressCommaStr'] = area.replace(
1293
1293
  /_/g,
1294
1294
  ',',
1295
1295
  )
1296
1296
  }
1297
1297
  resolve({
1298
1298
  lat: lat,
1299
1299
  lng: lng,
1300
1300
  area: area,
1301
1301
  })
1302
1302
  } else {
1303
1303
  resolve({ lat: '', lng: '', area: '' })
1304
1304
  }
1305
1305
  })
1306
1306
  .catch(e => {
1307
1307
  console.log(' ~~ file: index.h5.ts:514 ~~ .catch ~~ e:', e)
1308
1308
  resolve({ lat: '', lng: '', area: '' })
1309
1309
  })
1310
1310
  })
1311
1311
  .catch(e => {
1312
1312
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
1313
1313
  resolve({ lat: '', lng: '', area: '' })
1314
1314
  console.log('判断jmfe不存在,获取经纬度信息异常')
1315
1315
  })
1316
1316
  }
1317
1317
  })
1318
1318
  }
1319
1319
 
1320
1320
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1321
1321
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
1322
1322
  if (!isJdApp) {
1323
1323
  return
1324
1324
  }
1325
1325
  const avifSwitch = await getMPaasConfigByBussinessKey(
1326
1326
  'avifSwitch',
1327
1327
  isBeforePageReady,
1328
1328
  )
1329
1329
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
1330
1330
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1331
1331
  'isFollowAppVideoPlayStatus',
1332
1332
  isBeforePageReady,
1333
1333
  )
1334
1334
  console.log(
1335
1335
  'isBeforePageReady:',
1336
1336
  isBeforePageReady,
1337
1337
  'isFollowAppVideoPlayStatus:',
1338
1338
  isFollowAppVideoPlayStatus,
1339
1339
  )
1340
1340
  if (
1341
1341
  isFollowAppVideoPlayStatus === true ||
1342
1342
  isFollowAppVideoPlayStatus === 'true'
1343
1343
  ) {
1344
1344
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
1345
1345
  }
1346
1346
  }
1347
1347
 
1348
1348
  async getWifiVideoAutoPlayAsync() {
1349
1349
  this.info.sysInfo['wifiVideoAutoPlay'] = false
1350
1350
  if (!isJdApp) {
1351
1351
  return
1352
1352
  }
1353
1353
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
1354
1354
  return 0
1355
1355
  })
1356
1356
  if (Number(videoPlayStatus) === 1) {
1357
1357
  this.info.sysInfo['wifiVideoAutoPlay'] = true
1358
1358
  }
1359
1359
  }
1360
1360
 
1361
1361
  async getMPaasConfigAsync() {
1362
1362
  this.info.sysInfo.dynamicConfig = {}
1363
1363
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
1364
1364
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
1365
1365
  return this.updateMPaasConfigAsync(true)
1366
1366
  }
1367
1367
 
1368
1368
  getDynamicConfig(key: string){
1369
1369
  return this.info.sysInfo.dynamicConfig[key]
1370
1370
  }
1371
1371
  async updateMPaasConfig() {
1372
1372
  console.log('updateMPaasConfig')
1373
1373
 
1374
1374
  if (
1375
1375
  isIosDevice &&
1376
1376
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1377
1377
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1378
1378
  ) {
1379
1379
  try {
1380
1380
  await this.updateMPaasConfigAsync(false)
1381
1381
  } catch (e) {
1382
1382
  console.log('updateMPaasConfigAsync:', e)
1383
1383
  }
1384
1384
  }
1385
1385
  }
1386
1386
 
1387
1387
  toLogin(options) {
1388
1388
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1389
1389
  ? this.toWxAppLogin(options)
1390
1390
  : this.toWebLogin(options)
1391
1391
  }
1392
1392
 
1393
1393
  doLogin(options) {
1394
1394
  return this.toLogin(options)
1395
1395
  }
1396
1396
 
1397
1397
  doLoginForJdPin(options = {}) {
1398
1398
  return this.doLogin({
1399
1399
  loginColor: {
1400
1400
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1401
1401
  dpin: 0,
1402
1402
  },
1403
1403
  ...options,
1404
1404
  })
1405
1405
  }
1406
1406
 
1407
1407
  toWebLogin(options) {
1408
1408
  let params: {
1409
1409
  returnurl: string
1410
1410
  } = {
1411
1411
  returnurl: '',
1412
1412
  }
1413
1413
  const loginUrl = isPc
1414
1414
  ? `//passport.jd.com/new/login.aspx`
1415
1415
  : `${domain.mobileLogin}/user/login.action`
1416
1416
  const defaultParams = {
1417
1417
  appid: '100',
1418
1418
  returnurl: window.location.href,
1419
1419
  }
1420
1420
  if (isString(options)) {
1421
1421
  params = Object.assign({}, defaultParams, {
1422
1422
  returnurl: options,
1423
1423
  })
1424
1424
  } else if (isObject(options)) {
1425
1425
  const { loginColor, ...otherOptions } = options
1426
1426
  params = Object.assign({}, defaultParams, otherOptions)
1427
1427
  } else {
1428
1428
  params = defaultParams
1429
1429
  }
1430
1430
  params.returnurl = encodeURIComponent(params.returnurl)
1431
1431
  let getFullUrl = loginUrl + '?' + serialize(params)
1432
1432
  if (isPc) {
1433
1433
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1434
1434
  }
1435
1435
  return Promise.resolve({
1436
1436
  h5ToUrl: true,
1437
1437
  url: getFullUrl,
1438
1438
  }).then(() => {
1439
1439
  window.location.href = getFullUrl
1440
1440
  })
1441
1441
  }
1442
1442
 
1443
1443
  toWxAppLogin(options = {}) {
1444
1444
  console.log('微信京购小程序中h5登录跳转', options)
1445
1445
  return Promise.resolve(true).then(() => {
1446
1446
  const { loginColor } = Object.assign(
1447
1447
  {},
1448
1448
  {
1449
1449
  loginColor: {
1450
1450
  bzi: WXAPP_BIZ_KEY,
1451
1451
  dpin: 1,
1452
1452
  },
1453
1453
  },
1454
1454
  options,
1455
1455
  )
1456
1456
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1457
1457
  loginColor.bzi
1458
1458
  }&url=${encodeURIComponent(window.location.href)}`
1459
1459
  })
1460
1460
  }
1461
1461
 
1462
1462
  getLoginCookie() {
1463
1463
  return Promise.resolve({
1464
1464
  pin: cookie.get('pin') || '',
1465
1465
  })
1466
1466
  }
1467
1467
 
1468
1468
  clearLoginCookie() {
1469
1469
  cookie.remove('pin')
1470
1470
  }
1471
1471
 
1472
1472
  checkStatusAndLogin(options = {}) {
1473
1473
  if (!this.checkStatusAndLoginPromise) {
1474
1474
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1475
1475
  try {
1476
1476
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1477
1477
  options,
1478
1478
  )
1479
1479
  if (getLoginState) {
1480
1480
  resolve(true)
1481
1481
  } else {
1482
1482
  this.toLogin(options)
1483
1483
  reject(false)
1484
1484
  }
1485
1485
  } catch (e) {
1486
1486
  this.toLogin(options)
1487
1487
  reject(false)
1488
1488
  }
1489
1489
  })
1490
1490
  return this.checkStatusAndLoginPromise
1491
1491
  } else {
1492
1492
  return this.checkStatusAndLoginPromise
1493
1493
  .then(() => {
1494
1494
  return Promise.resolve(true)
1495
1495
  })
1496
1496
  .catch(() => {
1497
1497
  this.toLogin(options)
1498
1498
  return Promise.reject(true)
1499
1499
  })
1500
1500
  }
1501
1501
  }
1502
1502
 
1503
1503
  checkJdStatusAndLogin(
1504
1504
  options = {
1505
1505
  loginColor: {
1506
1506
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
1507
1507
  dpin: 0,
1508
1508
  },
1509
1509
  },
1510
1510
  ) {
1511
1511
  return this.checkStatusAndLogin(options)
1512
1512
  }
1513
1513
 
1514
1514
  doCheckLoginStateAndForApiCheck(options) {
1515
1515
  if (this.info.loginState) {
1516
1516
  return Promise.resolve(true)
1517
1517
  } else {
1518
1518
  return new Promise((resolve, reject) => {
1519
1519
  if (
1520
1520
  this.info.isJingGouMiniViewState ||
1521
1521
  this.info.isJingxiMiniViewState
1522
1522
  ) {
1523
1523
  const getWqAuthToken = cookie.get('wq_auth_token')
1524
1524
  const getWqSkey = cookie.get('wq_skey')
1525
1525
  const getWqUin = cookie.get('wq_uin')
1526
1526
  const isLoginState =
1527
1527
  options?.loginColor?.dpin === 0
1528
1528
  ? getWqAuthToken
1529
1529
  : getWqSkey && getWqUin
1530
1530
  if (isLoginState) {
1531
1531
  this.info.loginState = true
1532
1532
  resolve(true)
1533
1533
  } else {
1534
1534
  reject(false)
1535
1535
  }
1536
1536
  } else {
1537
1537
  Taro.request({
1538
1538
  url: api.isLogin,
1539
1539
  jsonp: true,
1540
1540
  timeout: 3000,
1541
1541
  success: res => {
1542
1542
  const { statusCode, data } = res
1543
1543
  if (
1544
1544
  statusCode === 200 &&
1545
1545
  data?.islogin &&
1546
1546
  Number(data.islogin) === 1
1547
1547
  ) {
1548
1548
  this.info.loginState = true
1549
1549
  resolve(true)
1550
1550
  } else {
1551
1551
  reject(false)
1552
1552
  }
1553
1553
  },
1554
1554
  fail: err => {
1555
1555
  console.log('登录检查异常', err)
1556
1556
  reject(false)
1557
1557
  },
1558
1558
  })
1559
1559
  }
1560
1560
  })
1561
1561
  }
1562
1562
  }
1563
1563
 
1564
1564
  checkLoginStatus(options) {
1565
1565
  return new Promise(async (resolve, reject) => {
1566
1566
  try {
1567
1567
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1568
1568
  options,
1569
1569
  )
1570
1570
  if (getLoginState) {
1571
1571
  const { pin } = await this.getLoginCookie()
1572
1572
  this.info.userInfo = {
1573
1573
  pin,
1574
1574
  encodePin: encodeURIComponent(pin),
1575
1575
  ptkey: '',
1576
1576
  }
1577
1577
  resolve(true)
1578
1578
  } else {
1579
1579
  reject(false)
1580
1580
  }
1581
1581
  } catch (e) {
1582
1582
  reject(false)
1583
1583
  }
1584
1584
  })
1585
1585
  }
1586
1586
 
1587
1587
  updatePageAndLogInfo(updateQuery = {}) {
1588
1588
  const createUpdateQueryInfo: {
1589
1589
  query: {
1590
1590
  shopId?: string | number
1591
1591
  venderId?: string | number
1592
1592
  }
1593
1593
  updateShopInfoState: boolean
1594
1594
  } = Object.assign(
1595
1595
  {},
1596
1596
  {
1597
1597
  query: {},
1598
1598
  updateShopInfoState: false,
1599
1599
  },
1600
1600
  updateQuery,
1601
1601
  )
1602
1602
  console.log(
1603
1603
  '获取当前下发的店铺查询参数',
1604
1604
  updateQuery,
1605
1605
  '获取之前保存的shopInfo店铺查询参数',
1606
1606
  this.info?.shopInfo,
1607
1607
  )
1608
1608
  const { query, updateShopInfoState } = createUpdateQueryInfo
1609
1609
  const { shopId, venderId, un_area } = query
1610
1610
  if (updateShopInfoState) {
1611
1611
  this.info.queryInfo = {
1612
1612
  ...this.info.queryInfo,
1613
1613
  ...query,
1614
1614
  }
1615
1615
  if (shopId && venderId) {
1616
1616
  this.info.shopInfo = {
1617
1617
  shopId: `${shopId}`,
1618
1618
  venderId: `${venderId}`,
1619
1619
  }
1620
1620
  }
1621
1621
  } else {
1622
1622
  this.info.queryInfo = {
1623
1623
  ...query,
1624
1624
  }
1625
1625
  if (
1626
1626
  this.info.shopInfo?.shopId &&
1627
1627
  this.info.shopInfo?.venderId &&
1628
1628
  (this.info.shopInfo.shopId == shopId ||
1629
1629
  this.info.shopInfo.venderId == venderId)
1630
1630
  ) {
1631
1631
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1632
1632
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1633
1633
  console.log(
1634
1634
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1635
1635
  this.info.queryInfo,
1636
1636
  )
1637
1637
  }
1638
1638
  }
1639
1639
  this.info.queryInfo['shopId'] &&
1640
1640
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1641
1641
  this.info.queryInfo['venderId'] &&
1642
1642
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1643
1643
  console.log(
1644
1644
  'h5==获取店铺下发查询参数\n',
1645
1645
  query,
1646
1646
  '\n获取店铺最后查询参数\n',
1647
1647
  this.info.queryInfo,
1648
1648
  '\n是否为更新店铺状态\n',
1649
1649
  updateShopInfoState,
1650
1650
  )
1651
1651
  const changeArea =
1652
1652
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1653
1653
  if (changeArea) {
1654
1654
  this.info.pageInfo.address = changeArea
1655
1655
  this.info.pageInfo.un_area = changeArea
1656
1656
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1657
1657
  }
1658
1658
  }