@pisell/pisellos 0.0.207 → 0.0.209

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 (58) hide show
  1. package/dist/effects/index.d.ts +1 -1
  2. package/dist/modules/Cart/index.d.ts +1 -0
  3. package/dist/modules/Cart/index.js +42 -14
  4. package/dist/modules/Cart/utils/changePrice.d.ts +1 -1
  5. package/dist/modules/Cart/utils/changePrice.js +8 -3
  6. package/dist/modules/Order/index.js +2 -2
  7. package/dist/modules/Rules/index.js +5 -5
  8. package/dist/modules/Rules/types.d.ts +1 -1
  9. package/dist/modules/Schedule/type.d.ts +7 -7
  10. package/dist/modules/Schedule/types.d.ts +9 -9
  11. package/dist/solution/BookingByStep/index.d.ts +1 -0
  12. package/dist/solution/BookingByStep/index.js +10 -5
  13. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  14. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  15. package/dist/types/index.d.ts +1 -1
  16. package/lib/core/index.js +28 -27
  17. package/lib/effects/index.d.ts +1 -1
  18. package/lib/effects/index.js +7 -3
  19. package/lib/modules/Account/index.js +10 -9
  20. package/lib/modules/AccountList/index.js +11 -14
  21. package/lib/modules/BaseModule.js +3 -6
  22. package/lib/modules/Cart/index.d.ts +1 -0
  23. package/lib/modules/Cart/index.js +19 -14
  24. package/lib/modules/Cart/utils/cartProduct.js +6 -3
  25. package/lib/modules/Cart/utils/changePrice.d.ts +1 -1
  26. package/lib/modules/Cart/utils/changePrice.js +5 -1
  27. package/lib/modules/Date/index.js +4 -8
  28. package/lib/modules/Date/types.js +0 -1
  29. package/lib/modules/Discount/index.js +6 -11
  30. package/lib/modules/Guests/index.js +15 -10
  31. package/lib/modules/Order/index.js +4 -6
  32. package/lib/modules/Payment/cash.js +1 -1
  33. package/lib/modules/Payment/eftpos.js +1 -1
  34. package/lib/modules/Payment/index.js +86 -98
  35. package/lib/modules/Payment/wallet.js +1 -1
  36. package/lib/modules/Product/index.js +5 -6
  37. package/lib/modules/ProductList/index.js +4 -5
  38. package/lib/modules/Resource/index.js +12 -8
  39. package/lib/modules/Rules/index.js +17 -14
  40. package/lib/modules/Rules/types.d.ts +1 -1
  41. package/lib/modules/Schedule/index.js +5 -8
  42. package/lib/modules/Schedule/type.d.ts +7 -7
  43. package/lib/modules/Schedule/types.d.ts +9 -9
  44. package/lib/modules/Schedule/utils.js +4 -2
  45. package/lib/modules/Step/index.js +4 -7
  46. package/lib/modules/Summary/index.js +4 -9
  47. package/lib/plugins/request.js +33 -34
  48. package/lib/plugins/window.js +113 -101
  49. package/lib/solution/BookingByStep/index.d.ts +1 -0
  50. package/lib/solution/BookingByStep/index.js +79 -53
  51. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  52. package/lib/solution/BookingByStep/utils/resources.js +8 -4
  53. package/lib/solution/BookingByStep/utils/timeslots.js +12 -6
  54. package/lib/solution/BuyTickets/index.js +15 -15
  55. package/lib/solution/ShopDiscount/index.js +11 -15
  56. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  57. package/lib/types/index.d.ts +1 -1
  58. package/package.json +1 -1
@@ -444,8 +444,10 @@ var getTimeSlicesByResources = ({
444
444
  var _a, _b, _c, _d;
445
445
  const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
446
446
  const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
447
- if (aIsCombined && !bIsCombined) return 1;
448
- if (!aIsCombined && bIsCombined) return -1;
447
+ if (aIsCombined && !bIsCombined)
448
+ return 1;
449
+ if (!aIsCombined && bIsCombined)
450
+ return -1;
449
451
  return 0;
450
452
  });
451
453
  let timeSliceList = resources.reduce(
@@ -528,7 +530,8 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
528
530
  }, []);
529
531
  };
530
532
  function filterScheduleByDateRange(schedule, startDate, endDate) {
531
- if (!(schedule == null ? void 0 : schedule.length)) return [];
533
+ if (!(schedule == null ? void 0 : schedule.length))
534
+ return [];
532
535
  const start = new Date(startDate);
533
536
  const end = new Date(endDate);
534
537
  return schedule.filter((item) => {
@@ -594,7 +597,8 @@ function filterResourcesByFormItem(resources, form_id) {
594
597
  }
595
598
  function checkTwoResourcesIntersection(resource1, resource2) {
596
599
  var _a, _b;
597
- if (resource1.id === resource2.id) return true;
600
+ if (resource1.id === resource2.id)
601
+ return true;
598
602
  if (((_a = resource1.metadata.combined_resource) == null ? void 0 : _a.status) === 1 && // 如果现在选择的是组合资源,需要判断
599
603
  // 1、当前其他购物车里是否选了当前组合资源的子资源
600
604
  // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
@@ -43,7 +43,8 @@ function calculateResourceAvailableTime({
43
43
  const matchingTimes = resource.times.filter((time) => {
44
44
  return (0, import_dayjs.default)(time.start_at).isSame((0, import_dayjs.default)(timeSlots.start_at), "day");
45
45
  });
46
- if (matchingTimes.length === 0) return 0;
46
+ if (matchingTimes.length === 0)
47
+ return 0;
47
48
  const overlaps = [];
48
49
  for (const time of matchingTimes) {
49
50
  const overlapStart = (0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) ? (0, import_dayjs.default)(time.start_at) : (0, import_dayjs.default)(timeSlots.start_at);
@@ -52,7 +53,8 @@ function calculateResourceAvailableTime({
52
53
  overlaps.push({ start: overlapStart, end: overlapEnd });
53
54
  }
54
55
  }
55
- if (overlaps.length === 0) return 0;
56
+ if (overlaps.length === 0)
57
+ return 0;
56
58
  overlaps.sort((a, b) => a.start.diff(b.start));
57
59
  const merged = [];
58
60
  let current = overlaps[0];
@@ -85,13 +87,15 @@ function findFastestAvailableResource({
85
87
  const todayTimes = resource.times.filter((time) => {
86
88
  return (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
87
89
  });
88
- if (todayTimes.length === 0) continue;
90
+ if (todayTimes.length === 0)
91
+ continue;
89
92
  todayTimes.sort((a, b) => {
90
93
  return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at));
91
94
  });
92
95
  for (const time of todayTimes) {
93
96
  const startTime = (0, import_dayjs.default)(time.start_at);
94
- if (startTime.isBefore(currentTime)) continue;
97
+ if (startTime.isBefore(currentTime))
98
+ continue;
95
99
  if (resource.resourceType === "single") {
96
100
  const hasBooking = (_a = time.event_list) == null ? void 0 : _a.some((event) => {
97
101
  return (0, import_dayjs.default)(event.start_at).isSame(startTime);
@@ -125,8 +129,10 @@ function findFastestAvailableResource({
125
129
  }
126
130
  }
127
131
  }
128
- if (!fastestTime || fastestResources.length === 0) return null;
129
- if (fastestResources.length === 1) return fastestResources[0];
132
+ if (!fastestTime || fastestResources.length === 0)
133
+ return null;
134
+ if (fastestResources.length === 1)
135
+ return fastestResources[0];
130
136
  let maxIdleTime = 0;
131
137
  let selectedResource = null;
132
138
  for (const resource of fastestResources) {
@@ -28,26 +28,23 @@ var import_types = require("./types");
28
28
  var import_BaseModule = require("../../modules/BaseModule");
29
29
  __reExport(BuyTickets_exports, require("./types"), module.exports);
30
30
  var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
31
- // 提供给 baseModule 用的默认名称 和 默认版本
32
- defaultName = "buyTickets";
33
- defaultVersion = "1.0.0";
34
- isSolution = true;
35
- request;
36
- window;
37
- store;
38
- otherParams = {};
39
31
  constructor(name, version) {
40
32
  super(name, version);
33
+ // 提供给 baseModule 用的默认名称 和 默认版本
34
+ this.defaultName = "buyTickets";
35
+ this.defaultVersion = "1.0.0";
36
+ this.isSolution = true;
37
+ this.otherParams = {};
41
38
  }
42
39
  async initialize(core, options) {
43
40
  this.core = core;
44
41
  this.store = options.store || {};
45
42
  this.otherParams = options.otherParams || {};
46
- console.log("[BuyTickets] \u521D\u59CB\u5316\u5B8C\u6210");
43
+ console.log("[BuyTickets] 初始化完成");
47
44
  this.request = core.getPlugin("request");
48
45
  this.window = core.getPlugin("window");
49
46
  if (!this.request) {
50
- throw new Error("\u8D2D\u7269\u8F66\u6A21\u5757\u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
47
+ throw new Error("购物车模块需要 request 插件支持");
51
48
  }
52
49
  if (this.otherParams.prodctIds) {
53
50
  await this.loadProductsByIds(this.otherParams.prodctIds);
@@ -79,7 +76,7 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
79
76
  }
80
77
  async destroy() {
81
78
  await this.core.effects.emit(import_types.BuyTicketsHooks.onDestroy, {});
82
- console.log("[BuyTickets] \u5DF2\u9500\u6BC1");
79
+ console.log("[BuyTickets] 已销毁");
83
80
  }
84
81
  // 获取当前绑定的所有商品
85
82
  async getProducts() {
@@ -97,8 +94,10 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
97
94
  var _a, _b;
98
95
  const mainProduct = await ((_a = this.store.mainProducts) == null ? void 0 : _a.getProduct(id));
99
96
  const otherProduct = await ((_b = this.store.otherProducts) == null ? void 0 : _b.getProduct(id));
100
- if (mainProduct) return mainProduct;
101
- if (otherProduct) return otherProduct;
97
+ if (mainProduct)
98
+ return mainProduct;
99
+ if (otherProduct)
100
+ return otherProduct;
102
101
  return Promise.reject("Not fund product for id: " + id);
103
102
  }
104
103
  // 商品列表页提交
@@ -107,12 +106,13 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
107
106
  ...data,
108
107
  products: this.getProducts()
109
108
  });
110
- if (res.status === false) return res;
109
+ if (res.status === false)
110
+ return res;
111
111
  this.window.localStorage.setItem(
112
112
  "buyTickets:listSubmit",
113
113
  JSON.stringify({ ...data, products: this.getProducts() })
114
114
  );
115
- console.log("listSubmit \u5E94\u8BE5\u8D70\u903B\u8F91\u5C42\u7684 API \u53D1\u8BF7\u6C42\u4E86");
115
+ console.log("listSubmit 应该走逻辑层的 API 发请求了");
116
116
  }
117
117
  // 购物车提交
118
118
  async cartSubmit(data) {
@@ -39,16 +39,12 @@ var import_Discount = require("../../modules/Discount");
39
39
  var import_Rules = require("../../modules/Rules");
40
40
  var import_decimal = __toESM(require("decimal.js"));
41
41
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
42
- defaultName = "shopDiscount";
43
- defaultVersion = "1.0.0";
44
- isSolution = true;
45
- request;
46
- window;
47
- store;
48
- options = {};
49
- hooks;
50
42
  constructor(name, version) {
51
43
  super(name, version);
44
+ this.defaultName = "shopDiscount";
45
+ this.defaultVersion = "1.0.0";
46
+ this.isSolution = true;
47
+ this.options = {};
52
48
  this.store = {
53
49
  customer: null,
54
50
  productList: [],
@@ -63,7 +59,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
63
59
  this.options = options;
64
60
  this.store = { ...this.store, ...options.store || {} };
65
61
  this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
66
- console.log("[ShopDiscount] \u521D\u59CB\u5316\u5B8C\u6210");
62
+ console.log("[ShopDiscount] 初始化完成");
67
63
  this.initializePlugins();
68
64
  this.registerDependentModules();
69
65
  this.registerEventListeners();
@@ -76,7 +72,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
76
72
  (_b = this.store.rules) == null ? void 0 : _b.destroy();
77
73
  this.core.effects.offByModuleDestroy(this.name);
78
74
  await this.core.effects.emit(import_types.ShopDiscountHooks.onDestroy, {});
79
- console.log("[ShopDiscount] \u5DF2\u9500\u6BC1");
75
+ console.log("[ShopDiscount] 已销毁");
80
76
  }
81
77
  async clear() {
82
78
  var _a, _b;
@@ -91,10 +87,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
91
87
  this.request = this.core.getPlugin("request");
92
88
  this.window = this.core.getPlugin("window");
93
89
  if (!this.request) {
94
- throw new Error("ShopDiscount\u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
90
+ throw new Error("ShopDiscount需要 request 插件支持");
95
91
  }
96
92
  if (!this.window) {
97
- throw new Error("ShopDiscount\u9700\u8981 window \u63D2\u4EF6\u652F\u6301");
93
+ throw new Error("ShopDiscount需要 window 插件支持");
98
94
  }
99
95
  }
100
96
  registerDependentModules() {
@@ -258,7 +254,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
258
254
  discountList: newDiscountList || this.getDiscountList()
259
255
  };
260
256
  } catch (error) {
261
- console.error("[ShopDiscount] \u626B\u7801\u51FA\u9519:", error);
257
+ console.error("[ShopDiscount] 扫码出错:", error);
262
258
  return {
263
259
  type: "clientCalc",
264
260
  isAvailable: false,
@@ -388,7 +384,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
388
384
  );
389
385
  }
390
386
  } catch (error) {
391
- console.error("[ShopDiscount] \u83B7\u53D6\u5BA2\u6237\u94B1\u5305\u4FE1\u606F\u51FA\u9519:", error);
387
+ console.error("[ShopDiscount] 获取客户钱包信息出错:", error);
392
388
  }
393
389
  }
394
390
  // 加载准备配置
@@ -421,7 +417,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
421
417
  newDiscountList
422
418
  );
423
419
  } catch (error) {
424
- console.error("[ShopDiscount] \u52A0\u8F7D\u51C6\u5907\u914D\u7F6E\u51FA\u9519:", error);
420
+ console.error("[ShopDiscount] 加载准备配置出错:", error);
425
421
  }
426
422
  }
427
423
  };
@@ -10,7 +10,7 @@ export declare enum ShopDiscountHooks {
10
10
  onRulesListChange = "shopDiscount:onRulesListChange",
11
11
  onLoadPrepareCalcResult = "shopDiscount:onLoadPrepareCalcResult"
12
12
  }
13
- export declare type Customer = {
13
+ export type Customer = {
14
14
  id: string | number;
15
15
  name: string;
16
16
  email: string;
@@ -27,7 +27,7 @@ export interface ModuleOptions {
27
27
  initialState?: Record<string, any>;
28
28
  otherParams?: Record<string, any>;
29
29
  }
30
- export declare type EventHandler = (data?: any) => void;
30
+ export type EventHandler = (data?: any) => void;
31
31
  export interface PisellCore {
32
32
  registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
33
33
  getPlugin: <T extends Plugin>(name: string) => T | null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.207",
4
+ "version": "0.0.209",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",