@pisell/pisellos 2.0.30 → 2.0.32

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.
@@ -210,7 +210,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
210
210
  }): void;
211
211
  setOtherData(key: string, value: any): void;
212
212
  getOtherData(key: string): any;
213
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
213
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
214
214
  /**
215
215
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
216
216
  *
@@ -2802,7 +2802,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2802
2802
  var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2803
2803
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2804
2804
  var params,
2805
- cache,
2806
2805
  startDate,
2807
2806
  endDate,
2808
2807
  tempProducts,
@@ -2810,6 +2809,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2810
2809
  filteredSchedule,
2811
2810
  tempResourceIds,
2812
2811
  res,
2812
+ cache,
2813
2813
  dates,
2814
2814
  currentDate,
2815
2815
  firstAvailableDate,
@@ -2822,21 +2822,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2822
2822
  while (1) switch (_context32.prev = _context32.next) {
2823
2823
  case 0:
2824
2824
  params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2825
- // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2826
- cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2827
- if (!cache) {
2828
- _context32.next = 5;
2829
- break;
2830
- }
2831
- if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2832
- _context32.next = 5;
2833
- break;
2834
- }
2835
- return _context32.abrupt("return", {
2836
- dateList: cache.dateList,
2837
- firstAvailableDate: cache.firstAvailableDate
2838
- });
2839
- case 5:
2840
2825
  // 开始日期如果小于今天,直接以今天当做开始日期
2841
2826
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2842
2827
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2845,11 +2830,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2845
2830
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2846
2831
  endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2847
2832
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2848
- tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2849
- schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2833
+ tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2834
+ schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2850
2835
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2851
2836
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2852
- _context32.next = 14;
2837
+ _context32.next = 10;
2853
2838
  return this.store.date.fetchResourceDates({
2854
2839
  query: {
2855
2840
  start_date: startDate || '',
@@ -2857,8 +2842,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2857
2842
  resource_ids: tempResourceIds
2858
2843
  }
2859
2844
  });
2860
- case 14:
2845
+ case 10:
2861
2846
  res = _context32.sent;
2847
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2848
+ // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2849
+ cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2850
+ if (!cache) {
2851
+ _context32.next = 16;
2852
+ break;
2853
+ }
2854
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2855
+ _context32.next = 16;
2856
+ break;
2857
+ }
2858
+ this.store.date.setDateList(cache.dateList);
2859
+ return _context32.abrupt("return", {
2860
+ dateList: cache.dateList,
2861
+ firstAvailableDate: cache.firstAvailableDate
2862
+ });
2863
+ case 16:
2862
2864
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2863
2865
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2864
2866
  dates = [];
@@ -2985,22 +2987,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2985
2987
  }
2986
2988
  }, _loop3);
2987
2989
  });
2988
- case 23:
2990
+ case 24:
2989
2991
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2990
- _context32.next = 29;
2992
+ _context32.next = 30;
2991
2993
  break;
2992
2994
  }
2993
- return _context32.delegateYield(_loop3(), "t0", 25);
2994
- case 25:
2995
+ return _context32.delegateYield(_loop3(), "t0", 26);
2996
+ case 26:
2995
2997
  if (!_context32.t0) {
2996
- _context32.next = 27;
2998
+ _context32.next = 28;
2997
2999
  break;
2998
3000
  }
2999
- return _context32.abrupt("break", 29);
3000
- case 27:
3001
- _context32.next = 23;
3001
+ return _context32.abrupt("break", 30);
3002
+ case 28:
3003
+ _context32.next = 24;
3002
3004
  break;
3003
- case 29:
3005
+ case 30:
3004
3006
  // 最终把资源数据也加到日期内
3005
3007
  dates = handleAvailableDateByResource(res.data, dates);
3006
3008
  this.store.date.setDateList(dates);
@@ -3016,7 +3018,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3016
3018
  dateList: dates,
3017
3019
  firstAvailableDate: firstAvailableDate
3018
3020
  });
3019
- case 33:
3021
+ case 34:
3020
3022
  case "end":
3021
3023
  return _context32.stop();
3022
3024
  }
@@ -210,7 +210,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
210
210
  }): void;
211
211
  setOtherData(key: string, value: any): void;
212
212
  getOtherData(key: string): any;
213
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
213
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
214
214
  /**
215
215
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
216
216
  *
@@ -1986,23 +1986,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1986
1986
  }
1987
1987
  async getAvailableDateForSessionOptimize(params = {}) {
1988
1988
  var _a, _b, _c, _d, _e, _f;
1989
- const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1990
- if (cache) {
1991
- if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
1992
- return {
1993
- dateList: cache.dateList,
1994
- firstAvailableDate: cache.firstAvailableDate
1995
- };
1996
- }
1997
- }
1998
1989
  let { startDate, endDate } = params;
1999
1990
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
2000
1991
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2001
1992
  }
2002
1993
  endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2003
1994
  let tempProducts;
2004
- tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
2005
- const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
1995
+ tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
1996
+ const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
2006
1997
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2007
1998
  schedule,
2008
1999
  startDate || "",
@@ -2016,6 +2007,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2016
2007
  resource_ids: tempResourceIds
2017
2008
  }
2018
2009
  });
2010
+ const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
2011
+ if (cache) {
2012
+ if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
2013
+ this.store.date.setDateList(cache.dateList);
2014
+ return {
2015
+ dateList: cache.dateList,
2016
+ firstAvailableDate: cache.firstAvailableDate
2017
+ };
2018
+ }
2019
+ }
2019
2020
  let dates = [];
2020
2021
  let currentDate = (0, import_dayjs.default)(startDate);
2021
2022
  let firstAvailableDate = "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.30",
4
+ "version": "2.0.32",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",