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