@conecli/cone-render 0.8.41 → 0.8.42

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