@conecli/cone-render 0.9.1-shop2.22 → 0.9.1-shop2.23

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
  appEid,
3
2
  userPinKey,
4
3
  jdUserLoginState,
5
4
  WXAPP_LOGIN,
6
5
  WXAPP_BIZ,
7
6
  WXAPP_USER_INFO,
8
7
  WXAPP_NAVIGATOR,
9
8
  WXAPP_REPORT_GDT,
10
9
  WXAPP_PARAMS_SIGN,
11
10
  WXAPP_FINGER_REPORT,
12
11
  WXAPP_REPORT_MANAGE,
13
12
  BUSINESS_TYPE,
14
13
  SHOP_MENU_ID_TYPE,
15
14
  SHOP_MENU_ID_NAME,
16
15
  SECTION_HOME_TAB_NAME_TYPE,
17
16
  SECTION_HOME_TAB_TYPE,
18
17
  TaroEventType,
19
18
  WX_BUSINESS_TYPE,
20
19
  WXAPP_BIZ_KEY,
21
20
  getSystemInfos,
22
21
  getTaroStorageKeyValue,
23
22
  getWxAppCookieStr,
24
23
  objectToUrlEncode,
25
24
  loginState: jdUserLoginState,
26
25
  cookiesStr: "",
27
26
  userInfo: userPinKey,
28
27
  pageInfo: {
29
28
  wxBusinessType: WX_BUSINESS_TYPE.SHOP,
30
29
  address: "",
31
30
  addressCommaStr: "",
32
31
  un_area: "",
33
32
  vapptype: "1",
34
33
  pageType: "home",
35
34
  dataType: BUSINESS_TYPE.ONLINE,
36
35
  floorExposureInfo: {},
37
36
  floorVideInfo: {},
38
37
  productVideInfo: {},
39
38
  tabsLoadAllDataInfo: {
40
39
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]:
41
40
  false,
42
41
  [SHOP_MENU_ID_NAME[SHOP_MENU_ID_TYPE.CLASSIFY]]: true,
43
42
  },
44
43
  updateShopInfosAllState: false,
45
44
  isVipShop: false,
46
45
  isJdShowNativeImmersivePlayer: false,
47
46
  ...shopConfig,
48
47
  pageScrollTop: 0,
49
48
  pageIdxHeightInfo: {
50
49
  list: [],
51
50
  },
52
51
  shopNavBarHeight: 0,
53
52
  },
54
53
  defaultQueryLogInfo: {
55
54
  sourceType: "JDshop",
56
55
  sourceValue: "",
57
56
  moduleId: "none",
58
57
  entrance: "none",
59
58
  },
60
59
  originQueryInfo: {},
61
60
  sysInfo: {
62
61
  windowWidth: 0,
63
62
  windowHeight: 0,
64
63
  eid: appEid,
65
64
  netWorkType: "4g",
66
65
  jdBottomBarHeight: 0,
67
66
  jdNativeHeaderHeight: 0,
68
67
  },
69
68
  queryInfo: {},
70
69
  shopInfo: {},
71
70
  openAppData: {},
72
71
  public info: CommonInterFace.BaseConfigInfo;
73
72
  public config: {
74
73
  [key: string]: any;
75
74
  };
76
75
  public lazyContainer: CommonInterFace.lazyContainer;
77
76
  public rootEleNode: HTMLElement | null;
78
77
  public miniApplogUtil: CommonInterFace.MiniApplogUtil;
79
78
  public miniAppLogInstance: CommonInterFace.MiniAppLog | null;
80
79
  public checkStatusAndLoginPromise: object | null;
81
80
  public wxAppLoginInstance: CommonInterFace.WxAppLogin;
82
81
  public wxAppBizInstance: CommonInterFace.WxAppUserInfo;
83
82
  public wxAppUserInfoInstance: CommonInterFace.WxAppUserInfo;
84
83
  public wxAppReportManageInstance: CommonInterFace.wxAppReportManage;
85
84
  public wxAppReportGDTInstance: CommonInterFace.WxAppReportGDT;
86
85
  public wxAppNavigatorInstance: CommonInterFace.WxAppNavigator;
87
86
  public wxAppParamsSignInstance: CommonInterFace.wxAppParamsSign;
88
87
  public wxAppFingerReportInstance: CommonInterFace.wxAppParamsSign;
89
88
  public wxAppSubsGuider: CommonInterFace.wxAppParamsSign;
90
89
  public loadJsSdkList: Array<any>
91
90
  public loadJsSdkListCachePromise: any
92
91
  constructor(opt) {
93
92
  this.info = this._getConfig(opt);
94
93
  this.config = {};
95
94
  this.lazyContainer = {
96
95
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
97
96
  appLazyContainerList: [],
98
97
  appLazyFinishContainerList: [],
99
98
  },
100
99
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
101
100
  appLazyContainerList: [],
102
101
  appLazyFinishContainerList: [],
103
102
  },
104
103
  };
105
104
  this.loadJsSdkList = []
106
105
  this.loadJsSdkListCachePromise = {}
107
106
  this.rootEleNode = null;
108
107
  this.miniApplogUtil = MiniAppLogUtil;
109
108
  this.miniAppLogInstance = null;
110
109
  this.checkStatusAndLoginPromise = null;
111
110
  this.wxAppLoginInstance = WXAPP_LOGIN;
112
111
  this.wxAppBizInstance = WXAPP_BIZ;
113
112
  this.wxAppUserInfoInstance = WXAPP_USER_INFO;
114
113
  this.wxAppReportManageInstance = WXAPP_REPORT_MANAGE;
115
114
  this.wxAppReportGDTInstance = WXAPP_REPORT_GDT;
116
115
  this.wxAppNavigatorInstance = WXAPP_NAVIGATOR;
117
116
  this.wxAppParamsSignInstance = WXAPP_PARAMS_SIGN;
118
117
  this.wxAppFingerReportInstance = WXAPP_FINGER_REPORT
119
118
  ? new WXAPP_FINGER_REPORT()
120
119
  : {};
121
120
  this.wxAppSubsGuider = null;
122
121
  }
123
122
  _getConfig(opt) {
124
123
  return Object.assign({}, DefaultConfig, opt);
125
124
  }
126
125
 
127
126
  taskTimeoutPromise(callBack, timeout = 2000) {
128
127
  return new Promise((resolve) => {
129
128
  setTimeout(() => {
130
129
  const getCallBackRes = typeof callBack === "function" && callBack();
131
130
  return resolve(getCallBackRes || false);
132
131
  }, timeout);
133
132
  });
134
133
  }
135
134
 
136
135
  updateBusinessDomainAndApi(domain, api) {
137
136
  }
138
137
 
139
138
  getFullScreenHeight(systemInfo) {
140
139
  const { screenHeight, statusBarHeight, isAndroid } = systemInfo;
141
140
  let result = screenHeight;
142
141
  if (statusBarHeight > 20 && isAndroid) {
143
142
  result = screenHeight + statusBarHeight;
144
143
  }
145
144
  return result;
146
145
  }
147
146
 
148
147
  getTabBarHeight(systemInfo) {
149
148
  const { statusBarHeight, isAndroid, isIOS } = systemInfo;
150
149
  let result = 50;
151
150
  if (statusBarHeight > 20) {
152
151
  if (isIOS) {
153
152
  result = 84;
154
153
  } else if (isAndroid) {
155
154
  result = 53;
156
155
  }
157
156
  }
158
157
  return result;
159
158
  }
160
159
 
161
160
  getSystemInfo() {
162
161
  const info: UtilsInterFace.taroGetSystemInfoSyncRes =
163
162
  getSystemInfos() || {};
164
163
  const actualNavBarHeight =
165
164
  (info?.navBarHeight || 0) + (info?.navBarExtendHeight || 0);
166
165
  const headerHeight = actualNavBarHeight + (info?.statusBarHeight || 0);
167
166
  const fullScreenHeight = this.getFullScreenHeight(info);
168
167
  const tabBarHeight = this.getTabBarHeight(info);
169
168
  const safeContentHeight = fullScreenHeight - headerHeight;
170
169
  this.info.sysInfo = {
171
170
  ...this.info.sysInfo,
172
171
  ...info,
173
172
  actualNavBarHeight,
174
173
  headerHeight,
175
174
  fullScreenHeight,
176
175
  tabBarHeight,
177
176
  safeContentHeight,
178
177
  };
179
178
  this.getEid().then((res: { eid: string }) => {
180
179
  res && res.eid && (this.info.sysInfo["eid"] = res.eid);
181
180
  });
182
181
  if (this.info.sysInfo["hostVersionName"]) {
183
182
  this.info.sysInfo["hostAppVersion"] = Number(
184
183
  this.info.sysInfo["hostVersionName"].replace(/\./g, "")
185
184
  );
186
185
  }
187
186
  console.log("获取系统信息", this.info.sysInfo);
188
187
  this.getNetWorkType();
189
188
  }
190
189
  async updateMPaasConfig() {}
191
190
 
192
191
  getNetWorkType() {
193
192
  Taro.getNetworkType().then((getRes) => {
194
193
  getRes &&
195
194
  getRes.networkType &&
196
195
  (this.info.sysInfo["netWorkType"] = getRes.networkType);
197
196
  });
198
197
  }
199
198
 
200
199
  checkStatusAndLogin(options = {}) {
201
200
  this.checkStatusAndLoginPromise = new Promise((resolve, reject) => {
202
201
  console.log(
203
202
  "微信小程序登录状态及获取cookie状态的promise,之前登录状态",
204
203
  this.info.loginState
205
204
  );
206
205
  this.toLogin(options)
207
206
  .then((res) => {
208
207
  console.log("微信小程序登录状态结果,成功", res);
209
208
  this.info.loginState = true;
210
209
  resolve(res);
211
210
  })
212
211
  .catch((err) => {
213
212
  console.log("微信小程序登录异常状态结果", err);
214
213
  this.doLogin(options)
215
214
  .then((res2) => {
216
215
  console.log("微信小程序wxDoLogin强制登陆成功:", res2);
217
216
  this.info.loginState = true;
218
217
  resolve(res2);
219
218
  })
220
219
  .catch((err2) => {
221
220
  console.log("微信小程序wxDoLogin强制登陆失败:", err2);
222
221
  this.checkStatusAndLoginPromise = null;
223
222
  reject(err2);
224
223
  });
225
224
  });
226
225
  });
227
226
  return this.checkStatusAndLoginPromise;
228
227
  }
229
228
 
230
229
  checkJdStatusAndLogin(options) {
231
230
  return this.checkStatusAndLogin(options);
232
231
  }
233
232
 
234
233
 
235
234
  doLoginForJdPin(options = {}) {
236
235
  return this.doLogin(options);
237
236
  }
238
237
 
239
238
  getEid() {
240
239
  if (typeof jd !== "undefined" && jd.getEid) {
241
240
  return new Promise((resolve, reject) => {
242
241
  jd.getEid({
243
242
  success: (res: { eid: string }) => {
244
243
  resolve(res);
245
244
  },
246
245
  fail: (err: any) => {
247
246
  reject(err);
248
247
  },
249
248
  });
250
249
  });
251
250
  } else {
252
251
  return Promise.resolve(false);
253
252
  }
254
253
  }
255
254
 
256
255
  toLogin(options = {}): Promise<any> {
257
256
  return this.wxAppLoginInstance
258
257
  .getLoginPromise({
259
258
  mode: "silent",
260
259
  loginColor: {
261
260
  biz: WXAPP_BIZ_KEY,
262
261
  dpin: 0,
263
262
  },
264
263
  ...options,
265
264
  })
266
265
  .then((res) => {
267
266
  console.log("微信app登录返回信息,微信侧返回code为0表示成功", res);
268
267
  setTimeout(() => {
269
268
  console.log(
270
269
  "微信app登录返回成功后,后台会写入cookie,有延迟,这里延迟500ms去获取最新cookie"
271
270
  );
272
271
  this.getLoginCookie(`${Date.now()}`);
273
272
  }, 500);
274
273
  })
275
274
  .catch((err) => {
276
275
  console.log("微信app登录异常返回信息,也获取cookie", err);
277
276
  this.getLoginCookie(`${Date.now()}`);
278
277
  });
279
278
  }
280
279
 
281
280
  doLogin(options) {
282
281
  console.log("触发松果小程序 doLogin() new new");
283
282
  return new Promise((resolve, reject) => {
284
283
  jd.login({
285
284
  success: (res) => {
286
285
  if (res.code) {
287
286
  console.log("[common]松果小程序登录成功", res.code);
288
287
  jd.redirectTo({
289
288
  url: `/pages/shopx/pages/index/index?${objectToUrlEncode({
290
289
  ...this.info.originQueryInfo,
291
290
  })}`,
292
291
  });
293
292
  resolve(res);
294
293
  } else {
295
294
  console.error("[common]松果小程序登录失败", res.errMsg);
296
295
  reject();
297
296
  }
298
297
  },
299
298
  fail: (res) => {
300
299
  console.error("[common]松果小程序登录失败", res.errMsg);
301
300
  reject();
302
301
  },
303
302
  });
304
303
  });
305
304
  }
306
305
 
307
306
  getLoginCookie(updateKey = "wxapp") {
308
307
  return new Promise((resolve) => {
309
308
  console.log("开始获取更新wxapp中的cookie信息", updateKey);
310
309
  if (
311
310
  this.config.wqCookie &&
312
311
  this.config.wqCookieStr &&
313
312
  this.config.getWqCookieKey === updateKey
314
313
  ) {
315
314
  console.log("已有存储wxapp中的cookie信息,直接返回", this.config);
316
315
  resolve({
317
316
  wqCookie: this.config.wqCookie,
318
317
  wqCookieStr: this.config.wqCookieStr,
319
318
  });
320
319
  } else {
321
320
  if (isPublishToWxapp) {
322
321
  const getWxappCookieObj = getTaroStorageKeyValue("cookies") || null;
323
322
  if (getWxappCookieObj) {
324
323
  const getCookieObj = getWxappCookieObj["_data"];
325
324
  const { wqCookie, wqCookieStr } = getWxAppCookieStr(getCookieObj);
326
325
  const {
327
326
  pin = "",
328
327
  visitkey = "-1",
329
328
  wq_unionid = "",
330
329
  wxapp_openid = "",
331
330
  } = wqCookie;
332
331
  this.info.loginState = true;
333
332
  this.info.userInfo.wqCookie = wqCookieStr;
334
333
  this.info.userInfo.wqVisitkey = visitkey;
335
334
  console.log("获取用户完整cookie信息", getCookieObj);
336
335
  const getUserAddress = this.wxAppUserInfoInstance.getAddress();
337
336
  console.log("获取微信用户地址信息", getUserAddress);
338
337
  if (getUserAddress) {
339
338
  this.info.pageInfo.address = getUserAddress?.areaId;
340
339
  this.info.pageInfo.addressCommaStr = this.info.pageInfo.address
341
340
  ? this.info.pageInfo.address.replace(/_/g, ",")
342
341
  : "";
343
342
  this.info.pageInfo.un_area = this.info.pageInfo.address;
344
343
  Taro.eventCenter.trigger(
345
344
  TaroEventType.USER_AREA_UPDATE,
346
345
  this.info.pageInfo.address
347
346
  );
348
347
  }
349
348
  if (this.miniAppLogInstance) {
350
349
  this.miniAppLogInstance.set({
351
350
  account: pin,
352
351
  unionid: wq_unionid,
353
352
  openid: wxapp_openid,
354
353
  });
355
354
  }
356
355
  this.config.wqCookie = wqCookie;
357
356
  this.config.wqCookieStr = wqCookieStr;
358
357
  this.config.getWqCookieKey = updateKey;
359
358
  console.log("解析wxapp中的cookie信息成功,返回后存储", this.config);
360
359
  resolve({
361
360
  wqCookie,
362
361
  wqCookieStr,
363
362
  });
364
363
  } else {
365
364
  console.log(
366
365
  "解析wxapp中的cookie信息异常,返回异常结果",
367
366
  this.config
368
367
  );
369
368
  resolve({
370
369
  wqCookie: false,
371
370
  wqCookieStr: false,
372
371
  });
373
372
  }
374
373
  } else {
375
374
  resolve({
376
375
  wqCookie: false,
377
376
  wqCookieStr: false,
378
377
  });
379
378
  }
380
379
  }
381
380
  });
382
381
  }
383
382
 
384
383
 
385
384
  checkLoginStatus() {
386
385
  return this.getLoginCookie();
387
386
  }
388
387
 
389
388
  getAddressCachePromise = () => {
390
389
  return Promise.reject("该方法只在APP内适用");
391
390
  };
392
391
 
393
392
  getDynamicConfig(key: string){
394
393
  console.warn('调用松果小程序的 getDynamicConfig(),注意,此方法还未实现!')
395
394
  return null
396
395
  }
397
396
 
398
397
  updatePageAndLogInfo(updateQuery = {}) {
399
398
  const createUpdateQueryInfo: {
400
399
  query: {
401
400
  shopId?: string | number;
402
401
  venderId?: string | number;
403
402
  };
404
403
  updateShopInfoState: boolean;
405
404
  } = Object.assign(
406
405
  {},
407
406
  {
408
407
  query: {},
409
408
  updateShopInfoState: false,
410
409
  },
411
410
  updateQuery
412
411
  );
413
412
  console.log(
414
413
  "获取当前下发的店铺查询参数",
415
414
  updateQuery,
416
415
  "获取之前保存的shopInfo店铺查询参数",
417
416
  this.info?.shopInfo
418
417
  );
419
418
  const { query, updateShopInfoState } = createUpdateQueryInfo;
420
419
  const { shopId, venderId } = query;
421
420
  if (updateShopInfoState) {
422
421
  this.info.queryInfo = {
423
422
  ...this.info.queryInfo,
424
423
  ...query,
425
424
  };
426
425
  if (shopId && venderId) {
427
426
  this.info.shopInfo = {
428
427
  shopId: `${shopId}`,
429
428
  venderId: `${venderId}`,
430
429
  };
431
430
  }
432
431
  } else {
433
432
  this.info.queryInfo = {
434
433
  ...query,
435
434
  };
436
435
  this.info.originQueryInfo = {
437
436
  ...query,
438
437
  };
439
438
  if (
440
439
  this.info.shopInfo?.shopId &&
441
440
  this.info.shopInfo?.venderId &&
442
441
  (this.info.shopInfo.shopId == shopId ||
443
442
  this.info.shopInfo.venderId == venderId)
444
443
  ) {
445
444
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
446
445
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
447
446
  console.log(
448
447
  "当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数",
449
448
  this.info.queryInfo
450
449
  );
451
450
  }
452
451
  }
453
452
  this.info.queryInfo["shopId"] &&
454
453
  (this.info.queryInfo["shopId"] = `${this.info.queryInfo["shopId"]}`);
455
454
  this.info.queryInfo["venderId"] &&
456
455
  (this.info.queryInfo["venderId"] = `${this.info.queryInfo["venderId"]}`);
457
456
  console.log(
458
457
  "weapp===获取店铺下发查询参数\n",
459
458
  query,
460
459
  "\n获取店铺最后查询参数\n",
461
460
  this.info.queryInfo,
462
461
  "\n是否为更新店铺状态\n",
463
462
  updateShopInfoState
464
463
  );
465
464
  }
466
465
  renderNextTickLoadSdk(){
467
466
  console.warn("暂未实现 index.jd.ts")
468
467
  }
469
468
  loadOtherSdk(){
470
469
  console.warn("暂未实现 index.jd.ts")
471
470
  }
472
471
  loadItemSdkPromise() {
473
472
  console.warn('暂未实现 index.jd.ts')
474
473
  }
474
+ import Taro from "@tarojs/taro";
475
475
  appEid,
476
476
  userPinKey,
477
477
  jdUserLoginState,
478
478
  WXAPP_LOGIN,
479
479
  WXAPP_BIZ,
480
480
  WXAPP_USER_INFO,
481
481
  WXAPP_NAVIGATOR,
482
482
  WXAPP_REPORT_GDT,
483
483
  WXAPP_PARAMS_SIGN,
484
484
  WXAPP_FINGER_REPORT,
485
485
  WXAPP_REPORT_MANAGE,
486
486
  BUSINESS_TYPE,
487
487
  SHOP_MENU_ID_TYPE,
488
488
  SHOP_MENU_ID_NAME,
489
489
  SECTION_HOME_TAB_NAME_TYPE,
490
490
  SECTION_HOME_TAB_TYPE,
491
491
  TaroEventType,
492
492
  WX_BUSINESS_TYPE,
493
493
  WXAPP_BIZ_KEY,
494
494
  getSystemInfos,
495
495
  getTaroStorageKeyValue,
496
496
  getWxAppCookieStr,
497
497
  objectToUrlEncode,
498
498
  loginState: jdUserLoginState,
499
499
  cookiesStr: "",
500
500
  userInfo: userPinKey,
501
501
  pageInfo: {
502
502
  wxBusinessType: WX_BUSINESS_TYPE.SHOP,
503
503
  address: "",
504
504
  addressCommaStr: "",
505
505
  un_area: "",
506
506
  vapptype: "1",
507
507
  pageType: "home",
508
508
  dataType: BUSINESS_TYPE.ONLINE,
509
509
  floorExposureInfo: {},
510
510
  floorVideInfo: {},
511
511
  productVideInfo: {},
512
512
  tabsLoadAllDataInfo: {
513
513
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]:
514
514
  false,
515
515
  [SHOP_MENU_ID_NAME[SHOP_MENU_ID_TYPE.CLASSIFY]]: true,
516
516
  },
517
517
  updateShopInfosAllState: false,
518
518
  isVipShop: false,
519
519
  isJdShowNativeImmersivePlayer: false,
520
520
  ...shopConfig,
521
521
  pageScrollTop: 0,
522
522
  pageIdxHeightInfo: {
523
523
  list: [],
524
524
  },
525
525
  shopNavBarHeight: 0,
526
526
  },
527
527
  defaultQueryLogInfo: {
528
528
  sourceType: "JDshop",
529
529
  sourceValue: "",
530
530
  moduleId: "none",
531
531
  entrance: "none",
532
532
  },
533
533
  originQueryInfo: {},
534
534
  sysInfo: {
535
535
  windowWidth: 0,
536
536
  windowHeight: 0,
537
537
  eid: appEid,
538
538
  netWorkType: "4g",
539
539
  jdBottomBarHeight: 0,
540
540
  jdNativeHeaderHeight: 0,
541
541
  },
542
542
  queryInfo: {},
543
543
  shopInfo: {},
544
544
  openAppData: {},
545
545
  public info: CommonInterFace.BaseConfigInfo;
546
546
  public config: {
547
547
  [key: string]: any;
548
548
  };
549
549
  public lazyContainer: CommonInterFace.lazyContainer;
550
550
  public rootEleNode: HTMLElement | null;
551
551
  public miniApplogUtil: CommonInterFace.MiniApplogUtil;
552
552
  public miniAppLogInstance: CommonInterFace.MiniAppLog | null;
553
553
  public checkStatusAndLoginPromise: object | null;
554
554
  public wxAppLoginInstance: CommonInterFace.WxAppLogin;
555
555
  public wxAppBizInstance: CommonInterFace.WxAppUserInfo;
556
556
  public wxAppUserInfoInstance: CommonInterFace.WxAppUserInfo;
557
557
  public wxAppReportManageInstance: CommonInterFace.wxAppReportManage;
558
558
  public wxAppReportGDTInstance: CommonInterFace.WxAppReportGDT;
559
559
  public wxAppNavigatorInstance: CommonInterFace.WxAppNavigator;
560
560
  public wxAppParamsSignInstance: CommonInterFace.wxAppParamsSign;
561
561
  public wxAppFingerReportInstance: CommonInterFace.wxAppParamsSign;
562
562
  public wxAppSubsGuider: CommonInterFace.wxAppParamsSign;
563
563
  public loadJsSdkList: Array<any>
564
564
  public loadJsSdkListCachePromise: any
565
565
  constructor(opt) {
566
566
  this.info = this._getConfig(opt);
567
567
  this.config = {};
568
568
  this.lazyContainer = {
569
569
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
570
570
  appLazyContainerList: [],
571
571
  appLazyFinishContainerList: [],
572
572
  },
573
573
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
574
574
  appLazyContainerList: [],
575
575
  appLazyFinishContainerList: [],
576
576
  },
577
577
  };
578
578
  this.loadJsSdkList = []
579
579
  this.loadJsSdkListCachePromise = {}
580
580
  this.rootEleNode = null;
581
581
  this.miniApplogUtil = MiniAppLogUtil;
582
582
  this.miniAppLogInstance = null;
583
583
  this.checkStatusAndLoginPromise = null;
584
584
  this.wxAppLoginInstance = WXAPP_LOGIN;
585
585
  this.wxAppBizInstance = WXAPP_BIZ;
586
586
  this.wxAppUserInfoInstance = WXAPP_USER_INFO;
587
587
  this.wxAppReportManageInstance = WXAPP_REPORT_MANAGE;
588
588
  this.wxAppReportGDTInstance = WXAPP_REPORT_GDT;
589
589
  this.wxAppNavigatorInstance = WXAPP_NAVIGATOR;
590
590
  this.wxAppParamsSignInstance = WXAPP_PARAMS_SIGN;
591
591
  this.wxAppFingerReportInstance = WXAPP_FINGER_REPORT
592
592
  ? new WXAPP_FINGER_REPORT()
593
593
  : {};
594
594
  this.wxAppSubsGuider = null;
595
595
  }
596
596
  _getConfig(opt) {
597
597
  return Object.assign({}, DefaultConfig, opt);
598
598
  }
599
599
 
600
600
  taskTimeoutPromise(callBack, timeout = 2000) {
601
601
  return new Promise((resolve) => {
602
602
  setTimeout(() => {
603
603
  const getCallBackRes = typeof callBack === "function" && callBack();
604
604
  return resolve(getCallBackRes || false);
605
605
  }, timeout);
606
606
  });
607
607
  }
608
608
 
609
609
  updateBusinessDomainAndApi(domain, api) {
610
610
  }
611
611
 
612
612
  getFullScreenHeight(systemInfo) {
613
613
  const { screenHeight, statusBarHeight, isAndroid } = systemInfo;
614
614
  let result = screenHeight;
615
615
  if (statusBarHeight > 20 && isAndroid) {
616
616
  result = screenHeight + statusBarHeight;
617
617
  }
618
618
  return result;
619
619
  }
620
620
 
621
621
  getTabBarHeight(systemInfo) {
622
622
  const { statusBarHeight, isAndroid, isIOS } = systemInfo;
623
623
  let result = 50;
624
624
  if (statusBarHeight > 20) {
625
625
  if (isIOS) {
626
626
  result = 84;
627
627
  } else if (isAndroid) {
628
628
  result = 53;
629
629
  }
630
630
  }
631
631
  return result;
632
632
  }
633
633
 
634
634
  getSystemInfo() {
635
635
  const info: UtilsInterFace.taroGetSystemInfoSyncRes =
636
636
  getSystemInfos() || {};
637
637
  const actualNavBarHeight =
638
638
  (info?.navBarHeight || 0) + (info?.navBarExtendHeight || 0);
639
639
  const headerHeight = actualNavBarHeight + (info?.statusBarHeight || 0);
640
640
  const fullScreenHeight = this.getFullScreenHeight(info);
641
641
  const tabBarHeight = this.getTabBarHeight(info);
642
642
  const safeContentHeight = fullScreenHeight - headerHeight;
643
643
  this.info.sysInfo = {
644
644
  ...this.info.sysInfo,
645
645
  ...info,
646
646
  actualNavBarHeight,
647
647
  headerHeight,
648
648
  fullScreenHeight,
649
649
  tabBarHeight,
650
650
  safeContentHeight,
651
651
  };
652
652
  this.getEid().then((res: { eid: string }) => {
653
653
  res && res.eid && (this.info.sysInfo["eid"] = res.eid);
654
654
  });
655
655
  if (this.info.sysInfo["hostVersionName"]) {
656
656
  this.info.sysInfo["hostAppVersion"] = Number(
657
657
  this.info.sysInfo["hostVersionName"].replace(/\./g, "")
658
658
  );
659
659
  }
660
660
  console.log("获取系统信息", this.info.sysInfo);
661
661
  this.getNetWorkType();
662
662
  }
663
663
  async updateMPaasConfig() {}
664
664
 
665
665
  getNetWorkType() {
666
666
  Taro.getNetworkType().then((getRes) => {
667
667
  getRes &&
668
668
  getRes.networkType &&
669
669
  (this.info.sysInfo["netWorkType"] = getRes.networkType);
670
670
  });
671
671
  }
672
672
  getAPPUseStraightCorner () {
673
673
  return Promise.resolve(false)
674
674
  }
675
675
 
676
676
  checkStatusAndLogin(options = {}) {
677
677
  this.checkStatusAndLoginPromise = new Promise((resolve, reject) => {
678
678
  console.log(
679
679
  "微信小程序登录状态及获取cookie状态的promise,之前登录状态",
680
680
  this.info.loginState
681
681
  );
682
682
  this.toLogin(options)
683
683
  .then((res) => {
684
684
  console.log("微信小程序登录状态结果,成功", res);
685
685
  this.info.loginState = true;
686
686
  resolve(res);
687
687
  })
688
688
  .catch((err) => {
689
689
  console.log("微信小程序登录异常状态结果", err);
690
690
  this.doLogin(options)
691
691
  .then((res2) => {
692
692
  console.log("微信小程序wxDoLogin强制登陆成功:", res2);
693
693
  this.info.loginState = true;
694
694
  resolve(res2);
695
695
  })
696
696
  .catch((err2) => {
697
697
  console.log("微信小程序wxDoLogin强制登陆失败:", err2);
698
698
  this.checkStatusAndLoginPromise = null;
699
699
  reject(err2);
700
700
  });
701
701
  });
702
702
  });
703
703
  return this.checkStatusAndLoginPromise;
704
704
  }
705
705
 
706
706
  checkJdStatusAndLogin(options) {
707
707
  return this.checkStatusAndLogin(options);
708
708
  }
709
709
 
710
710
 
711
711
  doLoginForJdPin(options = {}) {
712
712
  return this.doLogin(options);
713
713
  }
714
714
 
715
715
  getEid() {
716
716
  if (typeof jd !== "undefined" && jd.getEid) {
717
717
  return new Promise((resolve, reject) => {
718
718
  jd.getEid({
719
719
  success: (res: { eid: string }) => {
720
720
  resolve(res);
721
721
  },
722
722
  fail: (err: any) => {
723
723
  reject(err);
724
724
  },
725
725
  });
726
726
  });
727
727
  } else {
728
728
  return Promise.resolve(false);
729
729
  }
730
730
  }
731
731
 
732
732
  toLogin(options = {}): Promise<any> {
733
733
  return this.wxAppLoginInstance
734
734
  .getLoginPromise({
735
735
  mode: "silent",
736
736
  loginColor: {
737
737
  biz: WXAPP_BIZ_KEY,
738
738
  dpin: 0,
739
739
  },
740
740
  ...options,
741
741
  })
742
742
  .then((res) => {
743
743
  console.log("微信app登录返回信息,微信侧返回code为0表示成功", res);
744
744
  setTimeout(() => {
745
745
  console.log(
746
746
  "微信app登录返回成功后,后台会写入cookie,有延迟,这里延迟500ms去获取最新cookie"
747
747
  );
748
748
  this.getLoginCookie(`${Date.now()}`);
749
749
  }, 500);
750
750
  })
751
751
  .catch((err) => {
752
752
  console.log("微信app登录异常返回信息,也获取cookie", err);
753
753
  this.getLoginCookie(`${Date.now()}`);
754
754
  });
755
755
  }
756
756
 
757
757
  doLogin(options) {
758
758
  console.log("触发松果小程序 doLogin() new new");
759
759
  return new Promise((resolve, reject) => {
760
760
  jd.login({
761
761
  success: (res) => {
762
762
  if (res.code) {
763
763
  console.log("[common]松果小程序登录成功", res.code);
764
764
  jd.redirectTo({
765
765
  url: `/pages/shopx/pages/index/index?${objectToUrlEncode({
766
766
  ...this.info.originQueryInfo,
767
767
  })}`,
768
768
  });
769
769
  resolve(res);
770
770
  } else {
771
771
  console.error("[common]松果小程序登录失败", res.errMsg);
772
772
  reject();
773
773
  }
774
774
  },
775
775
  fail: (res) => {
776
776
  console.error("[common]松果小程序登录失败", res.errMsg);
777
777
  reject();
778
778
  },
779
779
  });
780
780
  });
781
781
  }
782
782
 
783
783
  getLoginCookie(updateKey = "wxapp") {
784
784
  return new Promise((resolve) => {
785
785
  console.log("开始获取更新wxapp中的cookie信息", updateKey);
786
786
  if (
787
787
  this.config.wqCookie &&
788
788
  this.config.wqCookieStr &&
789
789
  this.config.getWqCookieKey === updateKey
790
790
  ) {
791
791
  console.log("已有存储wxapp中的cookie信息,直接返回", this.config);
792
792
  resolve({
793
793
  wqCookie: this.config.wqCookie,
794
794
  wqCookieStr: this.config.wqCookieStr,
795
795
  });
796
796
  } else {
797
797
  if (isPublishToWxapp) {
798
798
  const getWxappCookieObj = getTaroStorageKeyValue("cookies") || null;
799
799
  if (getWxappCookieObj) {
800
800
  const getCookieObj = getWxappCookieObj["_data"];
801
801
  const { wqCookie, wqCookieStr } = getWxAppCookieStr(getCookieObj);
802
802
  const {
803
803
  pin = "",
804
804
  visitkey = "-1",
805
805
  wq_unionid = "",
806
806
  wxapp_openid = "",
807
807
  } = wqCookie;
808
808
  this.info.loginState = true;
809
809
  this.info.userInfo.wqCookie = wqCookieStr;
810
810
  this.info.userInfo.wqVisitkey = visitkey;
811
811
  console.log("获取用户完整cookie信息", getCookieObj);
812
812
  const getUserAddress = this.wxAppUserInfoInstance.getAddress();
813
813
  console.log("获取微信用户地址信息", getUserAddress);
814
814
  if (getUserAddress) {
815
815
  this.info.pageInfo.address = getUserAddress?.areaId;
816
816
  this.info.pageInfo.addressCommaStr = this.info.pageInfo.address
817
817
  ? this.info.pageInfo.address.replace(/_/g, ",")
818
818
  : "";
819
819
  this.info.pageInfo.un_area = this.info.pageInfo.address;
820
820
  Taro.eventCenter.trigger(
821
821
  TaroEventType.USER_AREA_UPDATE,
822
822
  this.info.pageInfo.address
823
823
  );
824
824
  }
825
825
  if (this.miniAppLogInstance) {
826
826
  this.miniAppLogInstance.set({
827
827
  account: pin,
828
828
  unionid: wq_unionid,
829
829
  openid: wxapp_openid,
830
830
  });
831
831
  }
832
832
  this.config.wqCookie = wqCookie;
833
833
  this.config.wqCookieStr = wqCookieStr;
834
834
  this.config.getWqCookieKey = updateKey;
835
835
  console.log("解析wxapp中的cookie信息成功,返回后存储", this.config);
836
836
  resolve({
837
837
  wqCookie,
838
838
  wqCookieStr,
839
839
  });
840
840
  } else {
841
841
  console.log(
842
842
  "解析wxapp中的cookie信息异常,返回异常结果",
843
843
  this.config
844
844
  );
845
845
  resolve({
846
846
  wqCookie: false,
847
847
  wqCookieStr: false,
848
848
  });
849
849
  }
850
850
  } else {
851
851
  resolve({
852
852
  wqCookie: false,
853
853
  wqCookieStr: false,
854
854
  });
855
855
  }
856
856
  }
857
857
  });
858
858
  }
859
859
 
860
860
 
861
861
  checkLoginStatus() {
862
862
  return this.getLoginCookie();
863
863
  }
864
864
 
865
865
  getAddressCachePromise = () => {
866
866
  return Promise.reject("该方法只在APP内适用");
867
867
  };
868
868
 
869
869
  getDynamicConfig(key: string){
870
870
  console.warn('调用松果小程序的 getDynamicConfig(),注意,此方法还未实现!')
871
871
  return null
872
872
  }
873
873
 
874
874
  updatePageAndLogInfo(updateQuery = {}) {
875
875
  const createUpdateQueryInfo: {
876
876
  query: {
877
877
  shopId?: string | number;
878
878
  venderId?: string | number;
879
879
  };
880
880
  updateShopInfoState: boolean;
881
881
  } = Object.assign(
882
882
  {},
883
883
  {
884
884
  query: {},
885
885
  updateShopInfoState: false,
886
886
  },
887
887
  updateQuery
888
888
  );
889
889
  console.log(
890
890
  "获取当前下发的店铺查询参数",
891
891
  updateQuery,
892
892
  "获取之前保存的shopInfo店铺查询参数",
893
893
  this.info?.shopInfo
894
894
  );
895
895
  const { query, updateShopInfoState } = createUpdateQueryInfo;
896
896
  const { shopId, venderId } = query;
897
897
  if (updateShopInfoState) {
898
898
  this.info.queryInfo = {
899
899
  ...this.info.queryInfo,
900
900
  ...query,
901
901
  };
902
902
  if (shopId && venderId) {
903
903
  this.info.shopInfo = {
904
904
  shopId: `${shopId}`,
905
905
  venderId: `${venderId}`,
906
906
  };
907
907
  }
908
908
  } else {
909
909
  this.info.queryInfo = {
910
910
  ...query,
911
911
  };
912
912
  this.info.originQueryInfo = {
913
913
  ...query,
914
914
  };
915
915
  if (
916
916
  this.info.shopInfo?.shopId &&
917
917
  this.info.shopInfo?.venderId &&
918
918
  (this.info.shopInfo.shopId == shopId ||
919
919
  this.info.shopInfo.venderId == venderId)
920
920
  ) {
921
921
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
922
922
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
923
923
  console.log(
924
924
  "当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数",
925
925
  this.info.queryInfo
926
926
  );
927
927
  }
928
928
  }
929
929
  this.info.queryInfo["shopId"] &&
930
930
  (this.info.queryInfo["shopId"] = `${this.info.queryInfo["shopId"]}`);
931
931
  this.info.queryInfo["venderId"] &&
932
932
  (this.info.queryInfo["venderId"] = `${this.info.queryInfo["venderId"]}`);
933
933
  console.log(
934
934
  "weapp===获取店铺下发查询参数\n",
935
935
  query,
936
936
  "\n获取店铺最后查询参数\n",
937
937
  this.info.queryInfo,
938
938
  "\n是否为更新店铺状态\n",
939
939
  updateShopInfoState
940
940
  );
941
941
  }
942
942
  renderNextTickLoadSdk(){
943
943
  console.warn("暂未实现 index.jd.ts")
944
944
  }
945
945
  loadOtherSdk(){
946
946
  console.warn("暂未实现 index.jd.ts")
947
947
  }
948
948
  loadItemSdkPromise() {
949
949
  console.warn('暂未实现 index.jd.ts')
950
950
  }