@conecli/cone-render 0.9.1-shop2.19 → 0.9.1-shop2.20

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