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