@conecli/cone-render 0.10.1-shop3.17 → 0.10.1-shop3.18

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