@conecli/cone-render 0.9.1-shop2.24 → 0.9.1-shop2.26

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