@pisell/pisellos 0.0.14 → 0.0.16

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.
Files changed (51) hide show
  1. package/dist/modules/AccountList/index.d.ts +5 -1
  2. package/dist/modules/AccountList/index.js +82 -36
  3. package/dist/modules/AccountList/types.d.ts +1 -0
  4. package/dist/modules/BaseModule.d.ts +6 -0
  5. package/dist/modules/BaseModule.js +41 -0
  6. package/dist/modules/Cart/index.d.ts +10 -2
  7. package/dist/modules/Cart/index.js +71 -34
  8. package/dist/modules/Cart/types.d.ts +2 -2
  9. package/dist/modules/Cart/utils.d.ts +12 -0
  10. package/dist/modules/Cart/utils.js +49 -0
  11. package/dist/modules/Date/index.d.ts +5 -0
  12. package/dist/modules/Date/index.js +35 -2
  13. package/dist/modules/Discount/index.d.ts +4 -0
  14. package/dist/modules/Discount/index.js +32 -4
  15. package/dist/modules/Discount/types.d.ts +3 -0
  16. package/dist/modules/Rules/index.js +7 -4
  17. package/dist/modules/Step/index.d.ts +4 -0
  18. package/dist/modules/Step/index.js +29 -1
  19. package/dist/modules/Summary/index.d.ts +4 -0
  20. package/dist/modules/Summary/index.js +28 -2
  21. package/dist/modules/Summary/utils.js +4 -5
  22. package/dist/solution/BookingByStep/index.d.ts +23 -4
  23. package/dist/solution/BookingByStep/index.js +152 -31
  24. package/dist/solution/BookingByStep/types.js +0 -3
  25. package/dist/solution/ShopDiscount/index.js +24 -3
  26. package/lib/modules/AccountList/index.d.ts +5 -1
  27. package/lib/modules/AccountList/index.js +33 -1
  28. package/lib/modules/AccountList/types.d.ts +1 -0
  29. package/lib/modules/BaseModule.d.ts +6 -0
  30. package/lib/modules/BaseModule.js +37 -0
  31. package/lib/modules/Cart/index.d.ts +10 -2
  32. package/lib/modules/Cart/index.js +42 -14
  33. package/lib/modules/Cart/types.d.ts +2 -2
  34. package/lib/modules/Cart/utils.d.ts +12 -0
  35. package/lib/modules/Cart/utils.js +33 -0
  36. package/lib/modules/Date/index.d.ts +5 -0
  37. package/lib/modules/Date/index.js +21 -0
  38. package/lib/modules/Discount/index.d.ts +4 -0
  39. package/lib/modules/Discount/index.js +19 -0
  40. package/lib/modules/Discount/types.d.ts +3 -0
  41. package/lib/modules/Rules/index.js +9 -4
  42. package/lib/modules/Step/index.d.ts +4 -0
  43. package/lib/modules/Step/index.js +19 -0
  44. package/lib/modules/Summary/index.d.ts +4 -0
  45. package/lib/modules/Summary/index.js +17 -0
  46. package/lib/modules/Summary/utils.js +4 -5
  47. package/lib/solution/BookingByStep/index.d.ts +23 -4
  48. package/lib/solution/BookingByStep/index.js +82 -21
  49. package/lib/solution/BookingByStep/types.js +0 -3
  50. package/lib/solution/ShopDiscount/index.js +21 -3
  51. package/package.json +1 -1
@@ -48,6 +48,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
48
48
  this.otherParams = {};
49
49
  }
50
50
  async initialize(core, options) {
51
+ var _a;
51
52
  this.core = core;
52
53
  this.store = options.store || {};
53
54
  this.otherParams = options.otherParams || {};
@@ -58,22 +59,35 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
58
59
  if (!this.request) {
59
60
  throw new Error("bookingByStep解决方案需要 request 插件支持");
60
61
  }
62
+ let targetCacheData = {};
63
+ if ((_a = this.otherParams) == null ? void 0 : _a.cacheId) {
64
+ const sessionData = this.window.sessionStorage.getItem(this.name);
65
+ if (sessionData) {
66
+ const data = JSON.parse(sessionData);
67
+ targetCacheData = data[this.otherParams.cacheId];
68
+ }
69
+ }
61
70
  const moduleArr = [
62
71
  "cart",
63
72
  "summary",
64
73
  "step",
65
74
  "products",
66
- "guests",
67
75
  "date",
68
76
  "accountList",
69
77
  "order",
70
78
  "payment"
71
79
  ];
72
80
  moduleArr.forEach((step) => {
81
+ var _a2, _b;
73
82
  const targetModule = (0, import_types.createModule)(step, this.name);
74
83
  if (targetModule) {
75
84
  this.store[step] = targetModule;
76
- this.core.registerModule(targetModule);
85
+ this.core.registerModule(targetModule, { initialState: targetCacheData[targetModule.name], otherParams: {
86
+ ...this.otherParams,
87
+ fatherModule: this.name,
88
+ openCache: ((_a2 = this.otherParams) == null ? void 0 : _a2.cacheId) ? true : false,
89
+ cacheId: (_b = this.otherParams) == null ? void 0 : _b.cacheId
90
+ } });
77
91
  } else {
78
92
  throw new Error(`模块 ${step} 不存在`);
79
93
  }
@@ -126,7 +140,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
126
140
  category_ids,
127
141
  ids: product_ids,
128
142
  collection
129
- });
143
+ }, { useCache: true });
130
144
  this.store.products.addProduct(productsData.data.list);
131
145
  return productsData.data.list;
132
146
  }
@@ -174,9 +188,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
174
188
  async setDateRange(dateRange) {
175
189
  this.store.date.setDateRange(dateRange);
176
190
  }
191
+ clearDateRange() {
192
+ this.store.date.clearDateRange();
193
+ }
177
194
  // 获取日期模块里选中的日期
178
- async getRangeDate() {
179
- return "2024-01-01";
195
+ async getDateRange() {
196
+ return this.store.date.getDateRange();
180
197
  }
181
198
  async getCart() {
182
199
  return this.store.cart.getItems();
@@ -272,7 +289,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
272
289
  this.store.cart.updateItem(params);
273
290
  }
274
291
  // 删除购物车里某个商品
275
- deleteCart(product_id) {
292
+ deleteCart(cartItemId) {
293
+ this.store.cart.removeItem(cartItemId);
276
294
  }
277
295
  // 清空购物车
278
296
  clearCart() {
@@ -282,6 +300,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
282
300
  clearCartByAccount(account_id) {
283
301
  this.store.cart.clearCartByAccount(account_id);
284
302
  }
303
+ /**
304
+ * 批量更新购物车
305
+ */
306
+ batchUpdateCart(paramsList) {
307
+ const cartItems = [];
308
+ paramsList.forEach((params) => {
309
+ const cartItem = this.store.cart.formatCartItem(params);
310
+ cartItems.push(cartItem);
311
+ });
312
+ this.store.cart.batchSetItems(cartItems);
313
+ }
314
+ /**
315
+ * 从购物车中按类别删除信息
316
+ */
317
+ deleteCartItemInfo(types) {
318
+ this.store.cart.deleteCartItemInfo(types);
319
+ }
285
320
  destory() {
286
321
  var _a, _b, _c, _d, _e, _f;
287
322
  (_a = this.store.cart) == null ? void 0 : _a.destory();
@@ -305,11 +340,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
305
340
  const cartItems = this.store.cart.getItems();
306
341
  const arr = [];
307
342
  cartItems.forEach((cartItem) => {
308
- const productResources = (0, import_resources.getResourcesByProduct)(
309
- resourcesMap,
310
- cartItem,
311
- cartItems
312
- );
343
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, cartItem, cartItems);
313
344
  arr.push({
314
345
  id: cartItem.id,
315
346
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -323,6 +354,35 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
323
354
  });
324
355
  return arr;
325
356
  }
357
+ // 给单个购物车里的商品获取资源列表
358
+ getResourcesListByCartItem(id) {
359
+ const cartItems = this.store.cart.getItems();
360
+ const dateRange = this.store.date.getDateRange();
361
+ const resources = [];
362
+ dateRange.forEach((n) => {
363
+ if (n.resource)
364
+ resources.push(...n.resource);
365
+ });
366
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
367
+ const arr = [];
368
+ const targetCartItem = cartItems.find((n) => n._id === id);
369
+ if (!targetCartItem) {
370
+ throw new Error(`没有找到${id}购物车商品`);
371
+ }
372
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, targetCartItem, cartItems);
373
+ if (productResources) {
374
+ return {
375
+ id: targetCartItem.id,
376
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
377
+ _id: targetCartItem._id,
378
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
379
+ product: targetCartItem._productOrigin,
380
+ resources: productResources,
381
+ holder_id: targetCartItem.holder_id,
382
+ holder_name: targetCartItem.holder_title
383
+ };
384
+ }
385
+ }
326
386
  // 通过资源列表和指定的资源 id,获取指定资源的时间切片
327
387
  getResourceTimeSlot({
328
388
  product,
@@ -484,7 +544,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
484
544
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
485
545
  resources: [
486
546
  ...(item._origin.resources || []).filter(
487
- (existingRes) => existingRes.resourceType !== res.selectedResource.resourceType
547
+ (existingRes) => existingRes.form_id !== res.selectedResource.form_id
488
548
  ),
489
549
  res.selectedResource
490
550
  ]
@@ -494,14 +554,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
494
554
  errorList.push(item._id);
495
555
  }
496
556
  } else {
497
- const productResources = (0, import_resources.getResourcesByProduct)(
498
- resourcesMap,
499
- item,
500
- allCartItems
501
- );
502
- const targetRenderList = (_a = productResources.find(
503
- (n) => n.code === resources_code
504
- )) == null ? void 0 : _a.renderList;
557
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
558
+ const targetRenderList = (_a = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _a.renderList;
505
559
  if (targetRenderList && targetRenderList.length > 0) {
506
560
  this.store.cart.updateItem({
507
561
  _id: item._id,
@@ -592,7 +646,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
592
646
  newResources.forEach((n) => {
593
647
  var _a, _b, _c, _d;
594
648
  n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
595
- n.endTime = (0, import_dayjs.default)(n.startTime).add(((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0, ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes").format("YYYY-MM-DD HH:mm");
649
+ n.endTime = (0, import_dayjs.default)(n.startTime).add(
650
+ ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
651
+ ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
652
+ ).format("YYYY-MM-DD HH:mm");
596
653
  delete n.times;
597
654
  });
598
655
  this.store.cart.updateItem({
@@ -601,6 +658,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
601
658
  });
602
659
  });
603
660
  }
661
+ clearCache() {
662
+ }
663
+ clearCacheByModule(module2) {
664
+ }
604
665
  };
605
666
  // Annotate the CommonJS export names for ESM import in node:
606
667
  0 && (module.exports = {
@@ -26,7 +26,6 @@ module.exports = __toCommonJS(types_exports);
26
26
  var import_modules = require("../../modules");
27
27
  var import_AccountList = require("../../modules/AccountList");
28
28
  var import_Date = require("../../modules/Date");
29
- var import_Guests = require("../../modules/Guests");
30
29
  var import_Order = require("../../modules/Order");
31
30
  var import_Payment = require("../../modules/Payment");
32
31
  var import_Step = require("../../modules/Step");
@@ -41,8 +40,6 @@ function createModule(moduleName, solutionName, name, version) {
41
40
  return new import_Step.StepModule(`${solutionName}_${name || moduleName}`, version);
42
41
  case "products":
43
42
  return new import_modules.ProductList(`${solutionName}_${name || moduleName}`, version);
44
- case "guests":
45
- return new import_Guests.GuestListModule(`${solutionName}_${name || moduleName}`, version);
46
43
  case "date":
47
44
  return new import_Date.DateModule(`${solutionName}_${name || moduleName}`, version);
48
45
  case "accountList":
@@ -82,15 +82,29 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
82
82
  }
83
83
  }
84
84
  registerDependentModules() {
85
- var _a, _b, _c, _d;
85
+ var _a, _b, _c, _d, _e, _f, _g;
86
+ let targetCacheData = {};
87
+ if ((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) {
88
+ const sessionData = this.window.sessionStorage.getItem(this.name);
89
+ if (sessionData) {
90
+ const data = JSON.parse(sessionData);
91
+ targetCacheData = data[this.options.otherParams.cacheId];
92
+ }
93
+ }
86
94
  const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
87
95
  this.core.registerModule(discount, {
88
- hooks: (_b = (_a = this.options.otherParams) == null ? void 0 : _a.discount) == null ? void 0 : _b.hooks
96
+ initialState: targetCacheData[discount.name],
97
+ hooks: (_c = (_b = this.options.otherParams) == null ? void 0 : _b.discount) == null ? void 0 : _c.hooks,
98
+ otherParams: {
99
+ fatherModule: this.name,
100
+ openCache: ((_d = this.options.otherParams) == null ? void 0 : _d.cacheId) ? true : false,
101
+ cacheId: (_e = this.options.otherParams) == null ? void 0 : _e.cacheId
102
+ }
89
103
  });
90
104
  this.store.discount = discount;
91
105
  const rules = new import_Rules.RulesModule(`${this.name}_rules`);
92
106
  this.core.registerModule(rules, {
93
- hooks: (_d = (_c = this.options.otherParams) == null ? void 0 : _c.rules) == null ? void 0 : _d.hooks
107
+ hooks: (_g = (_f = this.options.otherParams) == null ? void 0 : _f.rules) == null ? void 0 : _g.hooks
94
108
  });
95
109
  this.store.rules = rules;
96
110
  }
@@ -98,6 +112,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
98
112
  this.core.effects.on(
99
113
  import_types.ShopDiscountHooks.onCustomerChange,
100
114
  (customer) => {
115
+ var _a;
116
+ if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
117
+ return;
118
+ }
101
119
  this.loadPrepareConfig({
102
120
  customerId: customer.id,
103
121
  action: "create",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",