@pisell/pisellos 0.0.320 → 0.0.324

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 (86) hide show
  1. package/dist/effects/index.d.ts +2 -2
  2. package/dist/modules/Customer/types.d.ts +1 -1
  3. package/dist/modules/Discount/index.d.ts +2 -0
  4. package/dist/modules/Discount/index.js +67 -35
  5. package/dist/modules/Discount/types.d.ts +5 -0
  6. package/dist/modules/Payment/types.d.ts +7 -7
  7. package/dist/modules/ProductList/index.js +2 -1
  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 -1
  12. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  13. package/dist/solution/BookingTicket/index.d.ts +1 -1
  14. package/dist/solution/ShopDiscount/index.d.ts +4 -0
  15. package/dist/solution/ShopDiscount/index.js +190 -101
  16. package/dist/solution/ShopDiscount/types.d.ts +5 -2
  17. package/dist/solution/ShopDiscount/utils.d.ts +48 -0
  18. package/dist/solution/ShopDiscount/utils.js +281 -0
  19. package/dist/types/index.d.ts +1 -1
  20. package/dist/utils/task.d.ts +2 -2
  21. package/dist/utils/watch.d.ts +2 -2
  22. package/lib/core/index.js +27 -28
  23. package/lib/effects/index.d.ts +2 -2
  24. package/lib/effects/index.js +3 -7
  25. package/lib/modules/Account/index.js +9 -10
  26. package/lib/modules/AccountList/index.js +14 -11
  27. package/lib/modules/BaseModule.js +6 -3
  28. package/lib/modules/Cart/index.js +14 -9
  29. package/lib/modules/Cart/utils/cartProduct.js +3 -6
  30. package/lib/modules/Customer/constants.js +1 -1
  31. package/lib/modules/Customer/index.js +18 -15
  32. package/lib/modules/Customer/types.d.ts +1 -1
  33. package/lib/modules/Date/index.js +10 -6
  34. package/lib/modules/Date/types.js +1 -0
  35. package/lib/modules/Discount/index.d.ts +2 -0
  36. package/lib/modules/Discount/index.js +28 -9
  37. package/lib/modules/Discount/types.d.ts +5 -0
  38. package/lib/modules/Guests/index.js +10 -15
  39. package/lib/modules/Order/index.js +11 -9
  40. package/lib/modules/Payment/cash.js +1 -1
  41. package/lib/modules/Payment/cashRecommendationAlgorithm.js +1 -1
  42. package/lib/modules/Payment/eftpos.js +1 -1
  43. package/lib/modules/Payment/index.js +80 -69
  44. package/lib/modules/Payment/types.d.ts +7 -7
  45. package/lib/modules/Payment/utils.js +3 -6
  46. package/lib/modules/Payment/walletpass.js +31 -31
  47. package/lib/modules/Product/index.js +6 -5
  48. package/lib/modules/ProductList/index.js +7 -4
  49. package/lib/modules/Resource/index.js +8 -12
  50. package/lib/modules/Rules/index.js +12 -17
  51. package/lib/modules/Rules/types.d.ts +1 -1
  52. package/lib/modules/Schedule/index.js +8 -5
  53. package/lib/modules/Schedule/type.d.ts +7 -7
  54. package/lib/modules/Schedule/types.d.ts +9 -9
  55. package/lib/modules/Schedule/utils.js +2 -4
  56. package/lib/modules/Step/index.js +7 -4
  57. package/lib/modules/Summary/index.js +9 -4
  58. package/lib/plugins/request.js +34 -33
  59. package/lib/plugins/window.js +101 -113
  60. package/lib/solution/BookingByStep/index.d.ts +1 -1
  61. package/lib/solution/BookingByStep/index.js +70 -104
  62. package/lib/solution/BookingByStep/utils/capacity.js +10 -15
  63. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  64. package/lib/solution/BookingByStep/utils/resources.js +4 -8
  65. package/lib/solution/BookingByStep/utils/stock.js +3 -6
  66. package/lib/solution/BookingByStep/utils/timeslots.js +24 -27
  67. package/lib/solution/BookingTicket/index.d.ts +1 -1
  68. package/lib/solution/BookingTicket/index.js +19 -14
  69. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +3 -3
  70. package/lib/solution/BookingTicket/utils/scan/handleScan.js +6 -6
  71. package/lib/solution/BookingTicket/utils/scan/index.js +3 -1
  72. package/lib/solution/BookingTicket/utils/scan/scanCache.js +10 -9
  73. package/lib/solution/BuyTickets/index.js +15 -15
  74. package/lib/solution/Checkout/index.js +206 -199
  75. package/lib/solution/Checkout/utils/index.js +18 -22
  76. package/lib/solution/ShopDiscount/index.d.ts +4 -0
  77. package/lib/solution/ShopDiscount/index.js +59 -16
  78. package/lib/solution/ShopDiscount/types.d.ts +5 -2
  79. package/lib/solution/ShopDiscount/utils.d.ts +48 -0
  80. package/lib/solution/ShopDiscount/utils.js +172 -0
  81. package/lib/types/index.d.ts +1 -1
  82. package/lib/utils/task.d.ts +2 -2
  83. package/lib/utils/task.js +3 -3
  84. package/lib/utils/watch.d.ts +2 -2
  85. package/lib/utils/watch.js +5 -7
  86. package/package.json +1 -1
@@ -1,4 +1,8 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
4
  import Decimal from "decimal.js";
5
+ import dayjs from "dayjs";
2
6
  export var uniqueById = function uniqueById(arr) {
3
7
  var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
4
8
  var seen = new Set();
@@ -7,6 +11,19 @@ export var uniqueById = function uniqueById(arr) {
7
11
  });
8
12
  };
9
13
 
14
+ // 非预约商品 通过时长和日程判断是否是普通商品
15
+ export var isNormalProductByDurationSchedule = function isNormalProductByDurationSchedule(item) {
16
+ var _item$schedules, _item$scheduleIds;
17
+ return !(item !== null && item !== void 0 && item.duration) && !(item !== null && item !== void 0 && (_item$schedules = item.schedules) !== null && _item$schedules !== void 0 && _item$schedules.length) && !(item !== null && item !== void 0 && (_item$scheduleIds = item['schedule.ids']) !== null && _item$scheduleIds !== void 0 && _item$scheduleIds.length);
18
+ };
19
+
20
+ // 是否全部是普通商品
21
+ export var isAllNormalProduct = function isAllNormalProduct(items) {
22
+ return items.every(function (item) {
23
+ return isNormalProductByDurationSchedule(item);
24
+ });
25
+ };
26
+
10
27
  /**
11
28
  * 获取折扣金额 基于折扣卡类型计算
12
29
  * 商品券:直接返回商品价格
@@ -33,4 +50,268 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
33
50
 
34
51
  // 百分比:根据折扣卡金额计算
35
52
  return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
53
+ };
54
+
55
+ // 日程项接口定义
56
+
57
+ // 获取时间是否在日程范围内
58
+ export var getDateIsInSchedule = function getDateIsInSchedule(dateTime, scheduleList) {
59
+ if (!dateTime || !scheduleList || scheduleList.length === 0) {
60
+ return false;
61
+ }
62
+ var targetDate = dayjs(dateTime);
63
+ if (!targetDate.isValid()) {
64
+ return false;
65
+ }
66
+
67
+ // 遍历所有日程项
68
+ var _iterator = _createForOfIteratorHelper(scheduleList),
69
+ _step;
70
+ try {
71
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
72
+ var schedule = _step.value;
73
+ if (isTimeInScheduleItem(dateTime, schedule)) {
74
+ return true;
75
+ }
76
+ }
77
+ } catch (err) {
78
+ _iterator.e(err);
79
+ } finally {
80
+ _iterator.f();
81
+ }
82
+ return false;
83
+ };
84
+
85
+ // 判断时间是否在单个日程项范围内
86
+ var isTimeInScheduleItem = function isTimeInScheduleItem(dateTime, schedule) {
87
+ var targetDate = dayjs(dateTime);
88
+ var targetDateString = dateTime.split(' ')[0]; // YYYY-MM-DD
89
+ var targetTimeString = dateTime.split(' ')[1] || '00:00:00'; // HH:mm:ss
90
+
91
+ switch (schedule.type) {
92
+ case 'standard':
93
+ return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
94
+ case 'time-slots':
95
+ return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
96
+ case 'designation':
97
+ return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
98
+ default:
99
+ return false;
100
+ }
101
+ };
102
+
103
+ // 处理标准类型日程
104
+ var isInStandardSchedule = function isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule) {
105
+ if (!schedule.start_time || !schedule.end_time) {
106
+ return false;
107
+ }
108
+ var startDate = dayjs(schedule.start_time);
109
+ var endDate = dayjs(schedule.end_time);
110
+
111
+ // 先检查是否在基础时间范围内(不考虑重复)
112
+ var isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
113
+ if (schedule.repeat_type === 'none') {
114
+ return isInBasicRange;
115
+ }
116
+
117
+ // 处理重复日程
118
+ return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
119
+ };
120
+
121
+ // 处理时间段类型日程
122
+ var isInTimeSlotsSchedule = function isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule) {
123
+ if (!schedule.start_time) {
124
+ return false;
125
+ }
126
+ var scheduleDate = schedule.start_time.split(' ')[0];
127
+
128
+ // 检查日期是否匹配
129
+ if (targetDateString !== scheduleDate) {
130
+ return false;
131
+ }
132
+
133
+ // 检查是否在任一时间段内
134
+ var _iterator2 = _createForOfIteratorHelper(schedule.time_slot),
135
+ _step2;
136
+ try {
137
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
138
+ var timeSlot = _step2.value;
139
+ var slotStart = "".concat(scheduleDate, " ").concat(timeSlot.start_time, ":00");
140
+ var slotEnd = "".concat(scheduleDate, " ").concat(timeSlot.end_time, ":00");
141
+ var slotStartDate = dayjs(slotStart);
142
+ var slotEndDate = dayjs(slotEnd);
143
+ if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
144
+ return true;
145
+ }
146
+ }
147
+ } catch (err) {
148
+ _iterator2.e(err);
149
+ } finally {
150
+ _iterator2.f();
151
+ }
152
+ return false;
153
+ };
154
+
155
+ // 处理指定类型日程
156
+ var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule) {
157
+ if (!schedule.designation) {
158
+ return false;
159
+ }
160
+ var _iterator3 = _createForOfIteratorHelper(schedule.designation),
161
+ _step3;
162
+ try {
163
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
164
+ var designation = _step3.value;
165
+ var startDateTime = "".concat(designation.start_date, " ").concat(designation.start_time, ":00");
166
+ var endDateTime = "".concat(designation.end_date, " ").concat(designation.end_time, ":00");
167
+ var startDate = dayjs(startDateTime);
168
+ var endDate = dayjs(endDateTime);
169
+ if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
170
+ return true;
171
+ }
172
+ }
173
+ } catch (err) {
174
+ _iterator3.e(err);
175
+ } finally {
176
+ _iterator3.f();
177
+ }
178
+ return false;
179
+ };
180
+
181
+ // 处理重复日程逻辑
182
+ var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) {
183
+ if (!schedule.repeat_rule) {
184
+ return false;
185
+ }
186
+ var repeat_rule = schedule.repeat_rule,
187
+ repeat_type = schedule.repeat_type;
188
+ var targetDateOnly = dayjs(targetDateString); // 只取日期部分
189
+
190
+ // 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
191
+ if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
192
+ var _iterator4 = _createForOfIteratorHelper(repeat_rule.included_date),
193
+ _step4;
194
+ try {
195
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
196
+ var includedDate = _step4.value;
197
+ var includeStartDate = dayjs(includedDate.start);
198
+ var includeEndDate = dayjs(includedDate.end);
199
+ if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
200
+ // 在包含日期中,直接返回true,无需检查其他条件
201
+ return true;
202
+ }
203
+ }
204
+ } catch (err) {
205
+ _iterator4.e(err);
206
+ } finally {
207
+ _iterator4.f();
208
+ }
209
+ }
210
+
211
+ // 检查是否在排除日期中
212
+ var _iterator5 = _createForOfIteratorHelper(repeat_rule.excluded_date),
213
+ _step5;
214
+ try {
215
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
216
+ var excludedDate = _step5.value;
217
+ var excludeStartDate = dayjs(excludedDate.start);
218
+ var excludeEndDate = dayjs(excludedDate.end);
219
+ // 检查目标日期是否在排除范围内(包含边界)
220
+ if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
221
+ return false;
222
+ }
223
+ }
224
+
225
+ // 检查重复规则的结束条件
226
+ } catch (err) {
227
+ _iterator5.e(err);
228
+ } finally {
229
+ _iterator5.f();
230
+ }
231
+ if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
232
+ var ruleEndDate = dayjs(repeat_rule.end.end_date);
233
+ if (targetDate.isAfter(ruleEndDate)) {
234
+ return false;
235
+ }
236
+ }
237
+
238
+ // 根据重复类型检查
239
+ switch (repeat_type) {
240
+ case 'daily':
241
+ return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
242
+ case 'weekly':
243
+ return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
244
+ default:
245
+ return false;
246
+ // 不支持月和年重复
247
+ }
248
+ };
249
+
250
+ // 每日重复逻辑
251
+ var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, repeatRule) {
252
+ var daysDiff = targetDate.diff(startDate, 'day');
253
+ if (daysDiff < 0) {
254
+ return false;
255
+ }
256
+
257
+ // 检查频率
258
+ if (daysDiff % repeatRule.frequency !== 0) {
259
+ return false;
260
+ }
261
+
262
+ // 检查时间是否在日程的时间范围内
263
+ var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
264
+ var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
265
+ var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
266
+
267
+ // 每日重复:每天都在相同的时间段内有效
268
+ // 例如:01:00:00 - 16:00:00,每天都是这个时间段
269
+ return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
270
+ };
271
+
272
+ // 每周重复逻辑
273
+ var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate, repeatRule) {
274
+ var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
275
+
276
+ // 检查是否在指定的星期几内
277
+ if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
278
+ return false;
279
+ }
280
+
281
+ // 计算周差
282
+ var weeksDiff = targetDate.diff(startDate, 'week');
283
+ if (weeksDiff < 0) {
284
+ return false;
285
+ }
286
+
287
+ // 检查频率
288
+ if (weeksDiff % repeatRule.frequency !== 0) {
289
+ return false;
290
+ }
291
+
292
+ // 检查时间是否在日程的时间范围内
293
+ var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
294
+ var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
295
+ var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
296
+ return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
297
+ };
298
+
299
+ /**
300
+ * 根据预约时间过滤优惠券列表
301
+ * @param discountList 优惠券列表
302
+ * @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
303
+ * @returns 过滤后的优惠券列表
304
+ */
305
+ export var filterDiscountListByBookingTime = function filterDiscountListByBookingTime(discountList, bookingTime) {
306
+ if (!bookingTime) {
307
+ return discountList;
308
+ }
309
+ return discountList.filter(function (discount) {
310
+ var _discount$metadata2, _discount$metadata3, _discount$custom_sche;
311
+ debugger;
312
+ if (!(discount !== null && discount !== void 0 && (_discount$metadata2 = discount.metadata) !== null && _discount$metadata2 !== void 0 && _discount$metadata2.validity_type) || (discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.validity_type) === "fixed_validity") {
313
+ return true;
314
+ }
315
+ return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
316
+ });
36
317
  };
@@ -27,7 +27,7 @@ export interface ModuleOptions {
27
27
  initialState?: Record<string, any>;
28
28
  otherParams?: Record<string, any>;
29
29
  }
30
- export type EventHandler = (data?: any) => void;
30
+ export declare 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;
@@ -1,5 +1,5 @@
1
- type Action = (...args: any[]) => Promise<any>;
2
- type Task = {
1
+ declare type Action = (...args: any[]) => Promise<any>;
2
+ declare type Task = {
3
3
  uuid: string;
4
4
  type: string;
5
5
  actionParams?: Record<string, any>;
@@ -2,8 +2,8 @@
2
2
  * 监听模块
3
3
  *
4
4
  */
5
- export type WatchEventCallback = (...args: any[]) => void;
6
- export type WatchEventItem = {
5
+ export declare type WatchEventCallback = (...args: any[]) => void;
6
+ export declare type WatchEventItem = {
7
7
  key: string;
8
8
  callback: WatchEventCallback;
9
9
  };
package/lib/core/index.js CHANGED
@@ -26,13 +26,13 @@ module.exports = __toCommonJS(core_exports);
26
26
  var import_createStore = require("../store/createStore");
27
27
  var import_effects = require("../effects");
28
28
  var PisellOSCore = class {
29
+ plugins = /* @__PURE__ */ new Map();
30
+ modules = /* @__PURE__ */ new Map();
31
+ stores = /* @__PURE__ */ new Map();
32
+ effects = new import_effects.EffectsManager();
33
+ debug = false;
34
+ context = {};
29
35
  constructor(options) {
30
- this.plugins = /* @__PURE__ */ new Map();
31
- this.modules = /* @__PURE__ */ new Map();
32
- this.stores = /* @__PURE__ */ new Map();
33
- this.effects = new import_effects.EffectsManager();
34
- this.debug = false;
35
- this.context = {};
36
36
  this.debug = (options == null ? void 0 : options.debug) || false;
37
37
  this.context = (options == null ? void 0 : options.context) || {};
38
38
  this.initialize(options);
@@ -48,7 +48,7 @@ var PisellOSCore = class {
48
48
  this.registerModule(item.module, item.options);
49
49
  });
50
50
  }
51
- this.log("PisellOS 核心初始化完成");
51
+ this.log("PisellOS \u6838\u5FC3\u521D\u59CB\u5316\u5B8C\u6210");
52
52
  }
53
53
  // 日志方法
54
54
  log(message, level = "info") {
@@ -71,12 +71,12 @@ var PisellOSCore = class {
71
71
  // 插件相关方法
72
72
  registerPlugin(plugin, options) {
73
73
  if (this.plugins.has(plugin.name)) {
74
- this.log(`插件 ${plugin.name} 已经注册过,将被覆盖`, "warn");
74
+ this.log(`\u63D2\u4EF6 ${plugin.name} \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6`, "warn");
75
75
  }
76
76
  if (options == null ? void 0 : options.dependencies) {
77
77
  for (const dep of options.dependencies) {
78
78
  if (!this.plugins.has(dep)) {
79
- throw new Error(`注册插件 ${plugin.name} 失败:缺少依赖插件 ${dep}`);
79
+ throw new Error(`\u6CE8\u518C\u63D2\u4EF6 ${plugin.name} \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u63D2\u4EF6 ${dep}`);
80
80
  }
81
81
  }
82
82
  }
@@ -84,14 +84,14 @@ var PisellOSCore = class {
84
84
  const result = plugin.initialize();
85
85
  if (result instanceof Promise) {
86
86
  result.catch((err) => {
87
- this.log(`插件 ${plugin.name} 初始化失败: ${err.message}`, "error");
87
+ this.log(`\u63D2\u4EF6 ${plugin.name} \u521D\u59CB\u5316\u5931\u8D25: ${err.message}`, "error");
88
88
  throw err;
89
89
  });
90
90
  }
91
91
  this.plugins.set(plugin.name, plugin);
92
- this.log(`插件 ${plugin.name} v${plugin.version} 注册成功`);
92
+ this.log(`\u63D2\u4EF6 ${plugin.name} v${plugin.version} \u6CE8\u518C\u6210\u529F`);
93
93
  } catch (error) {
94
- this.log(`插件 ${plugin.name} 初始化过程中出错: ${error}`, "error");
94
+ this.log(`\u63D2\u4EF6 ${plugin.name} \u521D\u59CB\u5316\u8FC7\u7A0B\u4E2D\u51FA\u9519: ${error}`, "error");
95
95
  throw error;
96
96
  }
97
97
  }
@@ -104,12 +104,12 @@ var PisellOSCore = class {
104
104
  // 模块相关方法
105
105
  registerModule(module2, options) {
106
106
  if (this.modules.has(module2.name)) {
107
- this.log(`模块 ${module2.name} 已经注册过,将被覆盖`, "warn");
107
+ this.log(`\u6A21\u5757 ${module2.name} \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6`, "warn");
108
108
  }
109
109
  if (options == null ? void 0 : options.dependencies) {
110
110
  for (const dep of options.dependencies) {
111
111
  if (!this.modules.has(dep)) {
112
- throw new Error(`注册模块 ${module2.name} 失败:缺少依赖模块 ${dep}`);
112
+ throw new Error(`\u6CE8\u518C\u6A21\u5757 ${module2.name} \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u6A21\u5757 ${dep}`);
113
113
  }
114
114
  }
115
115
  }
@@ -117,7 +117,7 @@ var PisellOSCore = class {
117
117
  for (const plugin of options.plugins) {
118
118
  if (!this.plugins.has(plugin)) {
119
119
  throw new Error(
120
- `注册模块 ${module2.name} 失败:缺少依赖插件 ${plugin}`
120
+ `\u6CE8\u518C\u6A21\u5757 ${module2.name} \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u63D2\u4EF6 ${plugin}`
121
121
  );
122
122
  }
123
123
  }
@@ -126,10 +126,9 @@ var PisellOSCore = class {
126
126
  (options == null ? void 0 : options.initialState) || {},
127
127
  module2.name,
128
128
  (path, value) => {
129
- console.log("core 检测到模块值更新", module2.name, path, value);
129
+ console.log("core \u68C0\u6D4B\u5230\u6A21\u5757\u503C\u66F4\u65B0", module2.name, path, value);
130
130
  this.effects.emit(`${module2.name}:changed`, { path, value });
131
- if (module2.storeChange)
132
- module2.storeChange(path, value);
131
+ if (module2.storeChange) module2.storeChange(path, value);
133
132
  }
134
133
  );
135
134
  this.stores.set(module2.name, proxy);
@@ -137,14 +136,14 @@ var PisellOSCore = class {
137
136
  const result = module2.initialize(this, { store: proxy, ...options });
138
137
  if (result instanceof Promise) {
139
138
  result.catch((err) => {
140
- this.log(`模块 ${module2.name} 初始化失败: ${err.message}`, "error");
139
+ this.log(`\u6A21\u5757 ${module2.name} \u521D\u59CB\u5316\u5931\u8D25: ${err.message}`, "error");
141
140
  throw err;
142
141
  });
143
142
  }
144
143
  this.modules.set(module2.name, module2);
145
- this.log(`模块 ${module2.name} v${module2.version} 注册成功`);
144
+ this.log(`\u6A21\u5757 ${module2.name} v${module2.version} \u6CE8\u518C\u6210\u529F`);
146
145
  } catch (error) {
147
- this.log(`模块 ${module2.name} 初始化过程中出错: ${error}`, "error");
146
+ this.log(`\u6A21\u5757 ${module2.name} \u521D\u59CB\u5316\u8FC7\u7A0B\u4E2D\u51FA\u9519: ${error}`, "error");
148
147
  throw error;
149
148
  }
150
149
  }
@@ -168,9 +167,9 @@ var PisellOSCore = class {
168
167
  if (module2.destroy) {
169
168
  try {
170
169
  await Promise.resolve(module2.destroy());
171
- this.log(`模块 ${name} 已销毁`);
170
+ this.log(`\u6A21\u5757 ${name} \u5DF2\u9500\u6BC1`);
172
171
  } catch (error) {
173
- this.log(`销毁模块 ${name} 时出错: ${error}`, "error");
172
+ this.log(`\u9500\u6BC1\u6A21\u5757 ${name} \u65F6\u51FA\u9519: ${error}`, "error");
174
173
  }
175
174
  }
176
175
  }
@@ -179,14 +178,14 @@ var PisellOSCore = class {
179
178
  if (plugin.destroy) {
180
179
  try {
181
180
  await Promise.resolve(plugin.destroy());
182
- this.log(`插件 ${name} 已销毁`);
181
+ this.log(`\u63D2\u4EF6 ${name} \u5DF2\u9500\u6BC1`);
183
182
  } catch (error) {
184
- this.log(`销毁插件 ${name} 时出错: ${error}`, "error");
183
+ this.log(`\u9500\u6BC1\u63D2\u4EF6 ${name} \u65F6\u51FA\u9519: ${error}`, "error");
185
184
  }
186
185
  }
187
186
  }
188
187
  this.plugins.clear();
189
- this.log("PisellOS 核心已销毁");
188
+ this.log("PisellOS \u6838\u5FC3\u5DF2\u9500\u6BC1");
190
189
  }
191
190
  /**
192
191
  * 验证上下文参数
@@ -196,7 +195,7 @@ var PisellOSCore = class {
196
195
  const value = this.context[rule.name];
197
196
  if (rule.required && (value === void 0 || value === null)) {
198
197
  this.log(
199
- `模块 ${config.name} 缺少必需的上下文参数: ${rule.name}`,
198
+ `\u6A21\u5757 ${config.name} \u7F3A\u5C11\u5FC5\u9700\u7684\u4E0A\u4E0B\u6587\u53C2\u6570: ${rule.name}`,
200
199
  "error"
201
200
  );
202
201
  return false;
@@ -204,7 +203,7 @@ var PisellOSCore = class {
204
203
  if (rule.validate && value !== void 0 && value !== null) {
205
204
  if (!rule.validate(value)) {
206
205
  this.log(
207
- `模块 ${config.name} 上下文参数验证失败: ${rule.name} - ${rule.message || "验证失败"}`,
206
+ `\u6A21\u5757 ${config.name} \u4E0A\u4E0B\u6587\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25: ${rule.name} - ${rule.message || "\u9A8C\u8BC1\u5931\u8D25"}`,
208
207
  "error"
209
208
  );
210
209
  return false;
@@ -1,8 +1,8 @@
1
- type EffectCallback = (payload: any) => void | Promise<void | {
1
+ declare type EffectCallback = (payload: any) => void | Promise<void | {
2
2
  status: boolean;
3
3
  message?: string;
4
4
  }>;
5
- type UnsubscribeFunction = () => void;
5
+ declare type UnsubscribeFunction = () => void;
6
6
  declare class EffectsManager {
7
7
  private listeners;
8
8
  on(event: string, callback: EffectCallback): UnsubscribeFunction;
@@ -23,13 +23,10 @@ __export(effects_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(effects_exports);
25
25
  var EffectsManager = class {
26
- constructor() {
27
- this.listeners = /* @__PURE__ */ new Map();
28
- }
26
+ listeners = /* @__PURE__ */ new Map();
29
27
  on(event, callback) {
30
28
  var _a;
31
- if (!this.listeners.has(event))
32
- this.listeners.set(event, /* @__PURE__ */ new Set());
29
+ if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
33
30
  (_a = this.listeners.get(event)) == null ? void 0 : _a.add(callback);
34
31
  return () => {
35
32
  this.off(event, callback);
@@ -56,8 +53,7 @@ var EffectsManager = class {
56
53
  }
57
54
  async emit(event, payload) {
58
55
  const callbacks = this.listeners.get(event);
59
- if (!callbacks)
60
- return { status: true, data: [] };
56
+ if (!callbacks) return { status: true, data: [] };
61
57
  return new Promise(async (resolve) => {
62
58
  const res = [];
63
59
  for (const cb of callbacks) {
@@ -27,16 +27,16 @@ var import_BaseModule = require("../BaseModule");
27
27
  var import_types = require("./types");
28
28
  __reExport(Account_exports, require("./types"), module.exports);
29
29
  var AccountModule = class extends import_BaseModule.BaseModule {
30
+ defaultName = "account";
31
+ defaultVersion = "1.0.0";
32
+ isGuest = false;
33
+ store = {
34
+ accountInfo: null,
35
+ isLoggedIn: false,
36
+ active: false
37
+ };
30
38
  constructor(name, version) {
31
39
  super(name, version);
32
- this.defaultName = "account";
33
- this.defaultVersion = "1.0.0";
34
- this.isGuest = false;
35
- this.store = {
36
- accountInfo: null,
37
- isLoggedIn: false,
38
- active: false
39
- };
40
40
  }
41
41
  async initialize(core, options) {
42
42
  this.core = core;
@@ -65,8 +65,7 @@ var AccountModule = class extends import_BaseModule.BaseModule {
65
65
  return this.store.accountInfo;
66
66
  }
67
67
  async updateProfile(updates) {
68
- if (!this.store.accountInfo)
69
- return;
68
+ if (!this.store.accountInfo) return;
70
69
  this.store.accountInfo = {
71
70
  ...this.store.accountInfo,
72
71
  ...updates
@@ -28,19 +28,22 @@ var import_BaseModule = require("../BaseModule");
28
28
  var import_types = require("./types");
29
29
  var import_utils = require("./utils");
30
30
  var AccountListModule = class extends import_BaseModule.BaseModule {
31
+ defaultName = "accountList";
32
+ defaultVersion = "1.0.0";
33
+ store = {
34
+ accountList: [],
35
+ // 账号的纯数据列表
36
+ accounts: [],
37
+ // 账号的 module 列表
38
+ isLoading: false,
39
+ error: null
40
+ };
41
+ request;
42
+ cacheId;
43
+ openCache = false;
44
+ fatherModule;
31
45
  constructor(name, version) {
32
46
  super(name, version);
33
- this.defaultName = "accountList";
34
- this.defaultVersion = "1.0.0";
35
- this.store = {
36
- accountList: [],
37
- // 账号的纯数据列表
38
- accounts: [],
39
- // 账号的 module 列表
40
- isLoading: false,
41
- error: null
42
- };
43
- this.openCache = false;
44
47
  }
45
48
  async initialize(core, options) {
46
49
  var _a, _b, _c;
@@ -23,10 +23,13 @@ __export(BaseModule_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(BaseModule_exports);
25
25
  var BaseModule = class {
26
+ defaultName = "baseModule";
27
+ defaultVersion = "1.0.0";
28
+ name;
29
+ version;
30
+ isSolution = false;
31
+ core;
26
32
  constructor(name, version) {
27
- this.defaultName = "baseModule";
28
- this.defaultVersion = "1.0.0";
29
- this.isSolution = false;
30
33
  this.name = name || this.defaultName;
31
34
  this.version = version || this.defaultVersion;
32
35
  }
@@ -32,12 +32,17 @@ var import_utils2 = require("../Product/utils");
32
32
  __reExport(Cart_exports, require("./types"), module.exports);
33
33
  var import_utils3 = require("./utils");
34
34
  var CartModule = class extends import_BaseModule.BaseModule {
35
+ // 提供给 baseModule 用的默认名称 和 默认版本
36
+ defaultName = "cart";
37
+ defaultVersion = "1.0.0";
38
+ request;
39
+ window;
40
+ store;
41
+ cacheId;
42
+ openCache = false;
43
+ fatherModule;
35
44
  constructor(name, version) {
36
45
  super(name || "cart", version || "1.0.0");
37
- // 提供给 baseModule 用的默认名称 和 默认版本
38
- this.defaultName = "cart";
39
- this.defaultVersion = "1.0.0";
40
- this.openCache = false;
41
46
  }
42
47
  /**
43
48
  * 初始化购物车模块
@@ -62,12 +67,12 @@ var CartModule = class extends import_BaseModule.BaseModule {
62
67
  this.request = core.getPlugin("request");
63
68
  this.window = core.getPlugin("window");
64
69
  if (!this.request) {
65
- throw new Error("购物车模块需要 request 插件支持");
70
+ throw new Error("\u8D2D\u7269\u8F66\u6A21\u5757\u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
66
71
  }
67
72
  if (!this.window) {
68
- throw new Error("购物车模块需要 window 插件支持");
73
+ throw new Error("\u8D2D\u7269\u8F66\u6A21\u5757\u9700\u8981 window \u63D2\u4EF6\u652F\u6301");
69
74
  }
70
- console.log("[CartModule] 初始化完成");
75
+ console.log("[CartModule] \u521D\u59CB\u5316\u5B8C\u6210");
71
76
  }
72
77
  /**
73
78
  * 添加商品到购物车
@@ -118,7 +123,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
118
123
  this.store.list = [...items];
119
124
  await this.core.effects.emit(`${this.name}:onUpdateItem`, tempCartItem);
120
125
  } catch (error) {
121
- console.error("[CartModule] 更新购物车商品失败", error);
126
+ console.error("[CartModule] \u66F4\u65B0\u8D2D\u7269\u8F66\u5546\u54C1\u5931\u8D25", error);
122
127
  }
123
128
  }
124
129
  // 更新购物车中商品的初始信息
@@ -155,7 +160,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
155
160
  quantity = (tempCartItem == null ? void 0 : tempCartItem.num) || 1;
156
161
  }
157
162
  if (!tempCartItem) {
158
- throw new Error("[CartModule] 格式化数据到购物车失败,商品不存在");
163
+ throw new Error("[CartModule] \u683C\u5F0F\u5316\u6570\u636E\u5230\u8D2D\u7269\u8F66\u5931\u8D25\uFF0C\u5546\u54C1\u4E0D\u5B58\u5728");
159
164
  }
160
165
  if (cartItem) {
161
166
  tempCartItem = cartItem;