@conecli/cone-render 0.10.1-shop3.24 → 0.10.1-shop3.25

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