@pisell/pisellos 3.0.36 → 3.0.38

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.
@@ -122,7 +122,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
122
122
  return this.request.post("/order/prepare/config", params);
123
123
  case 2:
124
124
  prepareConfig = _context3.sent;
125
- goodPassList = this.uniqueByProductId(this.filterEnabledDiscountList((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []) || []) || [];
125
+ goodPassList = this.filterEnabledDiscountList((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []) || [];
126
126
  return _context3.abrupt("return", goodPassList);
127
127
  case 5:
128
128
  case "end":
@@ -153,7 +153,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
153
153
  });
154
154
  case 2:
155
155
  result = _context4.sent;
156
- resultDiscountList = this.uniqueByProductId(this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || []) || [];
156
+ resultDiscountList = this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || [];
157
157
  return _context4.abrupt("return", resultDiscountList);
158
158
  case 5:
159
159
  case "end":
@@ -272,8 +272,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
272
272
  key: "loadProductByScheduleDate",
273
273
  value: function () {
274
274
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
275
- var _product_ids;
276
- var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, _schedule$product_ids, schedule, otherProductsIds, allProductIds;
275
+ var _schedule$product_ids;
276
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
277
277
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
278
278
  while (1) switch (_context3.prev = _context3.next) {
279
279
  case 0:
@@ -296,29 +296,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
296
296
  // .filter((n) => n !== null && n !== undefined);
297
297
 
298
298
  // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
299
- if (!((_product_ids = product_ids) !== null && _product_ids !== void 0 && _product_ids.length)) {
300
- schedule = scheduleList.find(function (n) {
301
- return n.date === date;
302
- });
303
- if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
304
- product_ids = schedule.product_ids;
305
- }
299
+ // if (!product_ids?.length) {
300
+ // const schedule = scheduleList.find((n) => n.date === date);
301
+ // if (schedule && schedule.product_ids?.length) {
302
+ // product_ids = schedule.product_ids;
303
+ // }
304
+ // }
305
+ // V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
306
+ schedule = scheduleList.find(function (n) {
307
+ return n.date === date;
308
+ });
309
+ if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
310
+ product_ids = schedule.product_ids;
306
311
  }
307
312
  // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
308
313
  otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
309
314
  allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
310
315
  return self.indexOf(n) === index;
311
316
  });
312
- _context3.next = 8;
317
+ _context3.next = 9;
313
318
  return this.loadProducts({
314
319
  // schedule_ids: scheduleIds,
315
320
  product_ids: allProductIds,
316
321
  category_ids: category_ids
317
322
  // schedule_date: date,
318
323
  });
319
- case 8:
320
- return _context3.abrupt("return", _context3.sent);
321
324
  case 9:
325
+ return _context3.abrupt("return", _context3.sent);
326
+ case 10:
322
327
  case "end":
323
328
  return _context3.stop();
324
329
  }
@@ -341,7 +346,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
341
346
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
342
347
  cartItems = this.store.cart.getItems();
343
348
  if (!cartItems.length) {
344
- _context5.next = 24;
349
+ _context5.next = 25;
345
350
  break;
346
351
  }
347
352
  userPlugin = this.core.getPlugin('user');
@@ -433,6 +438,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
433
438
  _iterator.f();
434
439
  return _context5.finish(21);
435
440
  case 24:
441
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
442
+ case 25:
436
443
  case "end":
437
444
  return _context5.stop();
438
445
  }
@@ -2460,8 +2467,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2460
2467
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2461
2468
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2462
2469
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2470
+
2471
+ // n.start_at 是 2025-06-30 15:00 end_at 2025-06-30 17:00
2472
+ // item.start 是 2025-06-30 16:00 item.end 是 2025-06-30 19:00
2473
+ // 需要判断 n.start_at 和 n.end_at 是否在 item.start 和 item.end 之间
2474
+ // 如果 n.start_at 和 n.end_at 在 item.start 和 item.end 有交集,则此时间需要计算
2463
2475
  var mTimes = m.times.filter(function (n) {
2464
- return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2476
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2465
2477
  });
2466
2478
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2467
2479
  if (mTimes.length === 0) {
@@ -2889,6 +2901,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2889
2901
  var params,
2890
2902
  startDate,
2891
2903
  endDate,
2904
+ endDateAfterMonth,
2892
2905
  tempProducts,
2893
2906
  schedule,
2894
2907
  filteredSchedule,
@@ -2913,13 +2926,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2913
2926
  startDate = dayjs().format('YYYY-MM-DD');
2914
2927
  }
2915
2928
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2916
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2929
+ // 优化策略:
2930
+ // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2931
+ endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2932
+ if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2933
+ endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2934
+ } else {
2935
+ endDate = endDateAfterMonth;
2936
+ }
2917
2937
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2918
2938
  tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2919
2939
  schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2920
2940
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2921
2941
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2922
- _context32.next = 10;
2942
+ _context32.next = 11;
2923
2943
  return this.store.date.fetchResourceDates({
2924
2944
  query: {
2925
2945
  start_date: startDate || '',
@@ -2927,17 +2947,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2927
2947
  resource_ids: tempResourceIds
2928
2948
  }
2929
2949
  });
2930
- case 10:
2950
+ case 11:
2931
2951
  res = _context32.sent;
2932
2952
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2933
2953
  // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2934
2954
  cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2935
2955
  if (!cache) {
2936
- _context32.next = 16;
2956
+ _context32.next = 17;
2937
2957
  break;
2938
2958
  }
2939
2959
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2940
- _context32.next = 16;
2960
+ _context32.next = 17;
2941
2961
  break;
2942
2962
  }
2943
2963
  this.store.date.setDateList(cache.dateList);
@@ -2945,7 +2965,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2945
2965
  dateList: cache.dateList,
2946
2966
  firstAvailableDate: cache.firstAvailableDate
2947
2967
  });
2948
- case 16:
2968
+ case 17:
2949
2969
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2950
2970
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2951
2971
  dates = [];
@@ -3072,22 +3092,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3072
3092
  }
3073
3093
  }, _loop3);
3074
3094
  });
3075
- case 24:
3095
+ case 25:
3076
3096
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3077
- _context32.next = 30;
3097
+ _context32.next = 31;
3078
3098
  break;
3079
3099
  }
3080
- return _context32.delegateYield(_loop3(), "t0", 26);
3081
- case 26:
3100
+ return _context32.delegateYield(_loop3(), "t0", 27);
3101
+ case 27:
3082
3102
  if (!_context32.t0) {
3083
- _context32.next = 28;
3103
+ _context32.next = 29;
3084
3104
  break;
3085
3105
  }
3086
- return _context32.abrupt("break", 30);
3087
- case 28:
3088
- _context32.next = 24;
3106
+ return _context32.abrupt("break", 31);
3107
+ case 29:
3108
+ _context32.next = 25;
3089
3109
  break;
3090
- case 30:
3110
+ case 31:
3091
3111
  // 最终把资源数据也加到日期内
3092
3112
  dates = handleAvailableDateByResource(res.data, dates);
3093
3113
  this.store.date.setDateList(dates);
@@ -3097,13 +3117,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3097
3117
  dateList: dates,
3098
3118
  firstAvailableDate: firstAvailableDate,
3099
3119
  startDate: startDate,
3100
- endDate: endDate
3120
+ endDate: dayjs(currentDate).format('YYYY-MM-DD')
3101
3121
  });
3102
3122
  return _context32.abrupt("return", {
3103
3123
  dateList: dates,
3104
3124
  firstAvailableDate: firstAvailableDate
3105
3125
  });
3106
- case 34:
3126
+ case 35:
3107
3127
  case "end":
3108
3128
  return _context32.stop();
3109
3129
  }
@@ -30,7 +30,6 @@ import { BaseModule } from "../../modules/BaseModule";
30
30
  import { ShopDiscountHooks } from "./types";
31
31
  import { DiscountModule } from "../../modules/Discount";
32
32
  import { RulesModule } from "../../modules/Rules";
33
- import { uniqueById } from "./utils";
34
33
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
35
34
  _inherits(ShopDiscountImpl, _BaseModule);
36
35
  var _super = _createSuper(ShopDiscountImpl);
@@ -278,7 +277,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
278
277
  isManualSelect: !isSelected
279
278
  });
280
279
  }
281
- return discount;
280
+ return _objectSpread(_objectSpread({}, discount), {}, {
281
+ isManualSelect: !(discount !== null && discount !== void 0 && discount.isSelected)
282
+ });
282
283
  });
283
284
 
284
285
  // 更新优惠券列表
@@ -451,9 +452,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
451
452
  });
452
453
  }
453
454
  });
454
- var newDiscountList = uniqueById([].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
455
+ var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
455
456
  return !item.isDisabled;
456
- }))), 'product_id');
457
+ })));
457
458
  (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
458
459
  this.emitDiscountListChange(newDiscountList);
459
460
  return newDiscountList;
@@ -73,10 +73,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
73
73
  `/order/prepare/config`,
74
74
  params
75
75
  );
76
- const goodPassList = this.uniqueByProductId(
77
- this.filterEnabledDiscountList(
78
- ((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || []
79
- ) || []
76
+ const goodPassList = this.filterEnabledDiscountList(
77
+ ((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || []
80
78
  ) || [];
81
79
  return goodPassList;
82
80
  }
@@ -88,9 +86,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
88
86
  available: 1,
89
87
  relation_product: 1
90
88
  });
91
- const resultDiscountList = this.uniqueByProductId(
92
- this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || []
93
- ) || [];
89
+ const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
94
90
  return resultDiscountList;
95
91
  }
96
92
  filterEnabledDiscountList(discountList) {
@@ -216,11 +216,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
216
216
  { date, status: "available", week: "", weekNum: 0 },
217
217
  { date, status: "available", week: "", weekNum: 0 }
218
218
  ]);
219
- if (!(product_ids == null ? void 0 : product_ids.length)) {
220
- const schedule = scheduleList.find((n) => n.date === date);
221
- if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
222
- product_ids = schedule.product_ids;
223
- }
219
+ const schedule = scheduleList.find((n) => n.date === date);
220
+ if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
221
+ product_ids = schedule.product_ids;
224
222
  }
225
223
  const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
226
224
  const allProductIds = [...product_ids, ...otherProductsIds].filter(
@@ -283,6 +281,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
283
281
  bundle
284
282
  });
285
283
  }
284
+ this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
286
285
  }
287
286
  }
288
287
  // 加载当前店铺下所有 schedule
@@ -1703,7 +1702,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1703
1702
  let currentResourcesCount = 0;
1704
1703
  const currentResourcesTimeSlotCanUsedArr = [];
1705
1704
  const mTimes = m.times.filter((n) => {
1706
- return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute");
1705
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1707
1706
  });
1708
1707
  if (mTimes.length === 0) {
1709
1708
  return;
@@ -2037,7 +2036,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2037
2036
  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"))) {
2038
2037
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2039
2038
  }
2040
- endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2039
+ const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2040
+ if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
2041
+ endDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
2042
+ } else {
2043
+ endDate = endDateAfterMonth;
2044
+ }
2041
2045
  let tempProducts;
2042
2046
  tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2043
2047
  const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
@@ -2170,7 +2174,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2170
2174
  dateList: dates,
2171
2175
  firstAvailableDate,
2172
2176
  startDate,
2173
- endDate
2177
+ endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
2174
2178
  });
2175
2179
  return {
2176
2180
  dateList: dates,
@@ -27,7 +27,6 @@ var import_BaseModule = require("../../modules/BaseModule");
27
27
  var import_types = require("./types");
28
28
  var import_Discount = require("../../modules/Discount");
29
29
  var import_Rules = require("../../modules/Rules");
30
- var import_utils = require("./utils");
31
30
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
32
31
  constructor(name, version) {
33
32
  super(name, version);
@@ -173,7 +172,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
173
172
  isManualSelect: !isSelected
174
173
  };
175
174
  }
176
- return discount;
175
+ return { ...discount, isManualSelect: !(discount == null ? void 0 : discount.isSelected) };
177
176
  });
178
177
  this.setDiscountList(newDiscountList);
179
178
  return this.calcDiscount(this.store.productList || [], {
@@ -288,13 +287,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
288
287
  });
289
288
  }
290
289
  });
291
- const newDiscountList = (0, import_utils.uniqueById)(
292
- [
293
- ...editModeDiscountList,
294
- ...discountList.filter((item) => !item.isDisabled)
295
- ],
296
- "product_id"
297
- );
290
+ const newDiscountList = [
291
+ ...editModeDiscountList,
292
+ ...discountList.filter((item) => !item.isDisabled)
293
+ ];
298
294
  (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
299
295
  this.emitDiscountListChange(newDiscountList);
300
296
  return newDiscountList;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.36",
4
+ "version": "3.0.38",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "docs": "typedoc --out docs src/index.ts",
23
23
  "sync": "node sync.js",
24
24
  "prepublishOnly": "npm run build",
25
- "deploy": "yarn run build && yarn run changeset && yarn run version && npm run release"
25
+ "deploy": "npm run build && npm run changeset && npm run version && npm run release"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
@@ -67,4 +67,4 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  }
70
- }
70
+ }