@pisell/pisellos 2.1.36 → 2.2.1

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 (133) hide show
  1. package/dist/core/index.d.ts +8 -1
  2. package/dist/core/index.js +116 -42
  3. package/dist/effects/index.d.ts +1 -0
  4. package/dist/effects/index.js +29 -6
  5. package/dist/modules/Account/index.js +2 -3
  6. package/dist/modules/BaseModule.d.ts +3 -0
  7. package/dist/modules/BaseModule.js +15 -0
  8. package/dist/modules/Customer/index.js +9 -10
  9. package/dist/modules/Customer/types.d.ts +2 -2
  10. package/dist/modules/Customer/types.js +2 -2
  11. package/dist/modules/Discount/index.js +1 -1
  12. package/dist/modules/Guests/index.js +9 -9
  13. package/dist/modules/Order/index.js +1 -1
  14. package/dist/modules/Payment/index.js +63 -73
  15. package/dist/modules/Payment/walletpass.js +4 -1
  16. package/dist/modules/Product/types.d.ts +19 -0
  17. package/dist/modules/ProductList/index.js +5 -14
  18. package/dist/modules/Resource/index.js +1 -1
  19. package/dist/modules/Rules/index.js +2 -3
  20. package/dist/modules/Schedule/types.d.ts +2 -0
  21. package/dist/plugins/request.d.ts +1 -0
  22. package/dist/server/index.d.ts +152 -0
  23. package/dist/server/index.js +946 -0
  24. package/dist/server/modules/index.d.ts +16 -0
  25. package/dist/server/modules/index.js +21 -0
  26. package/dist/server/modules/menu/index.d.ts +63 -0
  27. package/dist/server/modules/menu/index.js +476 -0
  28. package/dist/server/modules/menu/types.d.ts +68 -0
  29. package/dist/server/modules/menu/types.js +16 -0
  30. package/dist/server/modules/products/index.d.ts +141 -0
  31. package/dist/server/modules/products/index.js +768 -0
  32. package/dist/server/modules/products/types.d.ts +94 -0
  33. package/dist/server/modules/products/types.js +43 -0
  34. package/dist/server/modules/quotation/index.d.ts +47 -0
  35. package/dist/server/modules/quotation/index.js +367 -0
  36. package/dist/server/modules/quotation/types.d.ts +50 -0
  37. package/dist/server/modules/quotation/types.js +20 -0
  38. package/dist/server/modules/schedule/index.d.ts +62 -0
  39. package/dist/server/modules/schedule/index.js +431 -0
  40. package/dist/server/modules/schedule/types.d.ts +1 -0
  41. package/dist/server/modules/schedule/types.js +2 -0
  42. package/dist/server/modules/schedule/utils.d.ts +32 -0
  43. package/dist/server/modules/schedule/utils.js +747 -0
  44. package/dist/server/types.d.ts +64 -0
  45. package/dist/server/types.js +1 -0
  46. package/dist/server/utils/index.d.ts +5 -0
  47. package/dist/server/utils/index.js +6 -0
  48. package/dist/server/utils/product.d.ts +18 -0
  49. package/dist/server/utils/product.js +339 -0
  50. package/dist/server/utils/schedule.d.ts +14 -0
  51. package/dist/server/utils/schedule.js +108 -0
  52. package/dist/server/utils/time.d.ts +18 -0
  53. package/dist/server/utils/time.js +53 -0
  54. package/dist/solution/BookingByStep/index.d.ts +0 -16
  55. package/dist/solution/BookingByStep/index.js +57 -508
  56. package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
  57. package/dist/solution/BookingByStep/utils/capacity.js +8 -24
  58. package/dist/solution/BookingTicket/index.d.ts +12 -0
  59. package/dist/solution/BookingTicket/index.js +122 -79
  60. package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  61. package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
  62. package/dist/solution/BuyTickets/index.js +7 -8
  63. package/dist/solution/Checkout/index.d.ts +1 -46
  64. package/dist/solution/Checkout/index.js +530 -850
  65. package/dist/solution/ShopDiscount/index.js +9 -10
  66. package/dist/types/index.d.ts +27 -0
  67. package/lib/core/index.d.ts +8 -1
  68. package/lib/core/index.js +48 -1
  69. package/lib/effects/index.d.ts +1 -0
  70. package/lib/effects/index.js +13 -0
  71. package/lib/modules/Account/index.js +2 -3
  72. package/lib/modules/BaseModule.d.ts +3 -0
  73. package/lib/modules/BaseModule.js +9 -0
  74. package/lib/modules/Customer/index.js +9 -10
  75. package/lib/modules/Customer/types.d.ts +2 -2
  76. package/lib/modules/Customer/types.js +2 -2
  77. package/lib/modules/Discount/index.js +1 -1
  78. package/lib/modules/Guests/index.js +9 -9
  79. package/lib/modules/Order/index.js +1 -1
  80. package/lib/modules/Payment/index.js +56 -43
  81. package/lib/modules/Payment/walletpass.js +3 -1
  82. package/lib/modules/Product/types.d.ts +19 -0
  83. package/lib/modules/ProductList/index.js +4 -13
  84. package/lib/modules/Resource/index.js +1 -1
  85. package/lib/modules/Rules/index.js +2 -3
  86. package/lib/modules/Schedule/types.d.ts +2 -0
  87. package/lib/plugins/request.d.ts +1 -0
  88. package/lib/server/index.d.ts +152 -0
  89. package/lib/server/index.js +555 -0
  90. package/lib/server/modules/index.d.ts +16 -0
  91. package/lib/server/modules/index.js +47 -0
  92. package/lib/server/modules/menu/index.d.ts +63 -0
  93. package/lib/server/modules/menu/index.js +234 -0
  94. package/lib/server/modules/menu/types.d.ts +68 -0
  95. package/lib/server/modules/menu/types.js +33 -0
  96. package/lib/server/modules/products/index.d.ts +141 -0
  97. package/lib/server/modules/products/index.js +434 -0
  98. package/lib/server/modules/products/types.d.ts +94 -0
  99. package/lib/server/modules/products/types.js +35 -0
  100. package/lib/server/modules/quotation/index.d.ts +47 -0
  101. package/lib/server/modules/quotation/index.js +177 -0
  102. package/lib/server/modules/quotation/types.d.ts +50 -0
  103. package/lib/server/modules/quotation/types.js +33 -0
  104. package/lib/server/modules/schedule/index.d.ts +62 -0
  105. package/lib/server/modules/schedule/index.js +231 -0
  106. package/lib/server/modules/schedule/types.d.ts +1 -0
  107. package/lib/server/modules/schedule/types.js +23 -0
  108. package/lib/server/modules/schedule/utils.d.ts +32 -0
  109. package/lib/server/modules/schedule/utils.js +451 -0
  110. package/lib/server/types.d.ts +64 -0
  111. package/lib/server/types.js +17 -0
  112. package/lib/server/utils/index.d.ts +5 -0
  113. package/lib/server/utils/index.js +25 -0
  114. package/lib/server/utils/product.d.ts +18 -0
  115. package/lib/server/utils/product.js +262 -0
  116. package/lib/server/utils/schedule.d.ts +14 -0
  117. package/lib/server/utils/schedule.js +88 -0
  118. package/lib/server/utils/time.d.ts +18 -0
  119. package/lib/server/utils/time.js +70 -0
  120. package/lib/solution/BookingByStep/index.d.ts +0 -16
  121. package/lib/solution/BookingByStep/index.js +44 -316
  122. package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
  123. package/lib/solution/BookingByStep/utils/capacity.js +8 -21
  124. package/lib/solution/BookingTicket/index.d.ts +12 -0
  125. package/lib/solution/BookingTicket/index.js +25 -6
  126. package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  127. package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
  128. package/lib/solution/BuyTickets/index.js +7 -8
  129. package/lib/solution/Checkout/index.d.ts +1 -46
  130. package/lib/solution/Checkout/index.js +92 -289
  131. package/lib/solution/ShopDiscount/index.js +10 -11
  132. package/lib/types/index.d.ts +27 -0
  133. package/package.json +2 -2
@@ -0,0 +1,177 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/server/modules/quotation/index.ts
20
+ var quotation_exports = {};
21
+ __export(quotation_exports, {
22
+ QuotationModule: () => QuotationModule
23
+ });
24
+ module.exports = __toCommonJS(quotation_exports);
25
+ var import_lodash_es = require("lodash-es");
26
+ var import_BaseModule = require("../../../modules/BaseModule");
27
+ var import_types = require("./types");
28
+ var INDEXDB_STORE_NAME = "quotation";
29
+ var QuotationModule = class extends import_BaseModule.BaseModule {
30
+ // IndexDBManager 实例
31
+ constructor(name, version) {
32
+ super(name, version);
33
+ this.defaultName = "quotation";
34
+ this.defaultVersion = "1.0.0";
35
+ }
36
+ async initialize(core, options) {
37
+ var _a;
38
+ this.core = core;
39
+ this.store = options == null ? void 0 : options.store;
40
+ if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.quotationList)) {
41
+ this.store.quotationList = options == null ? void 0 : options.initialState.quotationList;
42
+ this.core.effects.emit(import_types.QuotationHooks.onQuotationChanged, this.store.quotationList);
43
+ } else {
44
+ this.store.quotationList = [];
45
+ }
46
+ this.request = core.getPlugin("request");
47
+ if (!this.request) {
48
+ throw new Error("QuotationModule 需要 request 插件支持");
49
+ }
50
+ const appPlugin = core.getPlugin("app");
51
+ if (appPlugin) {
52
+ const app = appPlugin.getApp();
53
+ this.dbManager = app.dbManager;
54
+ if (this.dbManager) {
55
+ console.log("[Quotation] IndexDB Manager 已初始化");
56
+ } else {
57
+ console.warn("[Quotation] IndexDB Manager 未找到");
58
+ }
59
+ }
60
+ }
61
+ /**
62
+ * 加载报价单列表(从服务器)
63
+ * TODO: 接口地址待定
64
+ */
65
+ async loadQuotationList() {
66
+ var _a;
67
+ try {
68
+ const response = await this.request.get(
69
+ `/quotation`,
70
+ {
71
+ num: 999,
72
+ skip: 1,
73
+ status: "published"
74
+ }
75
+ );
76
+ const quotationList = ((_a = response.data) == null ? void 0 : _a.list) || [];
77
+ await this.saveQuotationToIndexDB(quotationList);
78
+ await this.setQuotationList(quotationList);
79
+ return quotationList;
80
+ } catch (error) {
81
+ console.error("[Quotation] 加载报价单数据失败:", error);
82
+ return [];
83
+ }
84
+ }
85
+ /**
86
+ * 设置报价单列表
87
+ */
88
+ async setQuotationList(quotationList) {
89
+ this.store.quotationList = quotationList;
90
+ await this.core.effects.emit(import_types.QuotationHooks.onQuotationLoaded, quotationList);
91
+ }
92
+ /**
93
+ * 获取报价单列表
94
+ */
95
+ getQuotationList() {
96
+ return this.store.quotationList;
97
+ }
98
+ /**
99
+ * 清空缓存
100
+ */
101
+ async clear() {
102
+ this.store.quotationList = [];
103
+ if (this.dbManager) {
104
+ try {
105
+ await this.dbManager.clear(INDEXDB_STORE_NAME);
106
+ console.log("[Quotation] IndexDB 缓存已清空");
107
+ } catch (error) {
108
+ console.error("[Quotation] 清空 IndexDB 缓存失败:", error);
109
+ }
110
+ }
111
+ console.log("[Quotation] 缓存已清空");
112
+ }
113
+ /**
114
+ * 从 IndexDB 加载报价单数据
115
+ * @private
116
+ */
117
+ async loadQuotationFromIndexDB() {
118
+ if (!this.dbManager) {
119
+ return [];
120
+ }
121
+ try {
122
+ const quotationList = await this.dbManager.getAll(INDEXDB_STORE_NAME);
123
+ return quotationList || [];
124
+ } catch (error) {
125
+ console.error("[Quotation] 从 IndexDB 读取数据失败:", error);
126
+ return [];
127
+ }
128
+ }
129
+ /**
130
+ * 保存报价单数据到 IndexDB
131
+ * @private
132
+ */
133
+ async saveQuotationToIndexDB(quotationList) {
134
+ if (!this.dbManager) {
135
+ return;
136
+ }
137
+ try {
138
+ await this.dbManager.clear(INDEXDB_STORE_NAME);
139
+ const savePromises = quotationList.map(
140
+ (quotation) => this.dbManager.add(INDEXDB_STORE_NAME, quotation)
141
+ );
142
+ await Promise.all(savePromises);
143
+ console.log(`[Quotation] 已将 ${quotationList.length} 条报价单数据保存到 IndexDB`);
144
+ } catch (error) {
145
+ console.error("[Quotation] 保存数据到 IndexDB 失败:", error);
146
+ }
147
+ }
148
+ /**
149
+ * 预加载模块数据(统一接口)
150
+ * 在模块注册后自动调用
151
+ */
152
+ async preload() {
153
+ console.log("[Quotation] 开始预加载数据...");
154
+ try {
155
+ const cachedData = await this.loadQuotationFromIndexDB();
156
+ if (cachedData && cachedData.length > 0) {
157
+ console.log(`[Quotation] 从 IndexDB 加载了 ${cachedData.length} 条报价单数据`);
158
+ this.store.quotationList = (0, import_lodash_es.cloneDeep)(cachedData);
159
+ this.core.effects.emit(import_types.QuotationHooks.onQuotationChanged, this.store.quotationList);
160
+ return;
161
+ }
162
+ console.log("[Quotation] IndexDB 中没有缓存数据,从服务器加载...");
163
+ } catch (error) {
164
+ console.warn("[Quotation] 从 IndexDB 加载数据失败:", error);
165
+ }
166
+ const quotationList = await this.loadQuotationList();
167
+ if (quotationList && quotationList.length > 0) {
168
+ await this.saveQuotationToIndexDB(quotationList);
169
+ this.store.quotationList = (0, import_lodash_es.cloneDeep)(quotationList);
170
+ this.core.effects.emit(import_types.QuotationHooks.onQuotationChanged, this.store.quotationList);
171
+ }
172
+ }
173
+ };
174
+ // Annotate the CommonJS export names for ESM import in node:
175
+ 0 && (module.exports = {
176
+ QuotationModule
177
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 报价单模块状态
3
+ */
4
+ export interface QuotationState {
5
+ /** 报价单列表 */
6
+ quotationList: QuotationData[];
7
+ }
8
+ /**
9
+ * 报价单数据结构
10
+ */
11
+ export interface QuotationData {
12
+ /** 报价单 ID */
13
+ id: number;
14
+ /** 报价单名称 */
15
+ name: string;
16
+ /** 绑定的日程 ID 列表 */
17
+ schedule_ids: number[];
18
+ /** 商品价格配置列表 */
19
+ product_prices: QuotationProductPrice[];
20
+ /** 状态 */
21
+ status: 'active' | 'inactive';
22
+ /** 优先级(多个报价单同时生效时使用) */
23
+ priority: number;
24
+ /** 创建时间 */
25
+ created_at: string;
26
+ /** 更新时间 */
27
+ updated_at: string;
28
+ }
29
+ /**
30
+ * 报价单商品价格配置
31
+ */
32
+ export interface QuotationProductPrice {
33
+ /** 商品 ID */
34
+ product_id: number;
35
+ /** 规格 ID(可选,针对有规格的商品) */
36
+ variant_id?: number;
37
+ /** 折扣类型:fixed 固定价格,percentage 百分比折扣 */
38
+ discount_type: 'fixed' | 'percentage';
39
+ /** 折扣价格或百分比 */
40
+ discount_value: string;
41
+ /** 最终价格(仅当 discount_type 为 fixed 时) */
42
+ final_price?: string;
43
+ }
44
+ /**
45
+ * 报价单模块钩子
46
+ */
47
+ export declare enum QuotationHooks {
48
+ onQuotationLoaded = "quotation:onQuotationLoaded",
49
+ onQuotationChanged = "quotation:onQuotationChanged"
50
+ }
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/server/modules/quotation/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ QuotationHooks: () => QuotationHooks
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ var QuotationHooks = /* @__PURE__ */ ((QuotationHooks2) => {
26
+ QuotationHooks2["onQuotationLoaded"] = "quotation:onQuotationLoaded";
27
+ QuotationHooks2["onQuotationChanged"] = "quotation:onQuotationChanged";
28
+ return QuotationHooks2;
29
+ })(QuotationHooks || {});
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ QuotationHooks
33
+ });
@@ -0,0 +1,62 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../../types';
2
+ import { BaseModule } from '../../../modules/BaseModule';
3
+ import { ScheduleModuleAPI, ScheduleItem } from '../../../modules/Schedule/types';
4
+ /**
5
+ * Schedule 模块(扩展版本)
6
+ * 在原有基础上添加了 getAvailableScheduleIds 方法
7
+ */
8
+ export declare class ScheduleModuleEx extends BaseModule implements Module, ScheduleModuleAPI {
9
+ protected defaultName: string;
10
+ protected defaultVersion: string;
11
+ private request;
12
+ private store;
13
+ private dbManager;
14
+ constructor(name?: string, version?: string);
15
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
16
+ /**
17
+ * 加载当前店铺下所有 schedule(从服务器)
18
+ */
19
+ loadAllSchedule(): Promise<any>;
20
+ setScheduleList(list: ScheduleItem[]): void;
21
+ /**
22
+ * 获取所有日程列表
23
+ */
24
+ getScheduleList(): ScheduleItem[];
25
+ /**
26
+ * 根据 schedule IDs 获取日程数据
27
+ * 使用 Map 快速查询,时间复杂度 O(m),m 为 ids 数量
28
+ */
29
+ getScheduleByIds(ids: number[]): ScheduleItem[];
30
+ /**
31
+ * 同步更新日程 Map 缓存
32
+ * 将 scheduleList 中的日程同步到 map,以 id 为 key
33
+ * @private
34
+ */
35
+ private syncScheduleMap;
36
+ /**
37
+ * 清除缓存
38
+ */
39
+ clear(): Promise<void>;
40
+ /**
41
+ * 判断日期是否在日程范围内
42
+ * @param date 日期
43
+ * @param scheduleList 日程列表
44
+ * @returns 是否在日程范围内
45
+ */
46
+ getDateIsInSchedule(date: string, scheduleList: (ScheduleItem | number)[]): boolean;
47
+ /**
48
+ * 从 IndexDB 加载日程数据
49
+ * @private
50
+ */
51
+ private loadScheduleFromIndexDB;
52
+ /**
53
+ * 保存日程数据到 IndexDB
54
+ * @private
55
+ */
56
+ private saveScheduleToIndexDB;
57
+ /**
58
+ * 预加载模块数据(统一接口)
59
+ * 在模块注册后自动调用
60
+ */
61
+ preload(): Promise<void>;
62
+ }
@@ -0,0 +1,231 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/server/modules/schedule/index.ts
30
+ var schedule_exports = {};
31
+ __export(schedule_exports, {
32
+ ScheduleModuleEx: () => ScheduleModuleEx
33
+ });
34
+ module.exports = __toCommonJS(schedule_exports);
35
+ var import_lodash_es = require("lodash-es");
36
+ var import_BaseModule = require("../../../modules/BaseModule");
37
+ var import_dayjs = __toESM(require("dayjs"));
38
+ var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
39
+ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
40
+ var import_utils = require("./utils");
41
+ import_dayjs.default.extend(import_isSameOrBefore.default);
42
+ import_dayjs.default.extend(import_isSameOrAfter.default);
43
+ var INDEXDB_STORE_NAME = "schedule";
44
+ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
45
+ // IndexDBManager 实例
46
+ constructor(name, version) {
47
+ super(name, version);
48
+ this.defaultName = "schedule";
49
+ this.defaultVersion = "1.1.0";
50
+ this.store = {};
51
+ }
52
+ async initialize(core, options) {
53
+ this.core = core;
54
+ this.request = core.getPlugin("request");
55
+ if (!this.request) {
56
+ throw new Error("ScheduleModule 需要 request 插件支持");
57
+ }
58
+ this.store = options == null ? void 0 : options.store;
59
+ if (options.initialState) {
60
+ this.store.scheduleList = options.initialState.scheduleList;
61
+ this.syncScheduleMap();
62
+ } else {
63
+ this.store.scheduleList = [];
64
+ this.store.map = /* @__PURE__ */ new Map();
65
+ }
66
+ const appPlugin = core.getPlugin("app");
67
+ if (appPlugin) {
68
+ const app = appPlugin.getApp();
69
+ this.dbManager = app.dbManager;
70
+ if (this.dbManager) {
71
+ console.log("[Schedule] IndexDB Manager 已初始化");
72
+ } else {
73
+ console.warn("[Schedule] IndexDB Manager 未找到");
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * 加载当前店铺下所有 schedule(从服务器)
79
+ */
80
+ async loadAllSchedule() {
81
+ var _a;
82
+ const scheduleList = await this.request.get(
83
+ `/schedule`,
84
+ { num: 999 },
85
+ { useCache: true }
86
+ );
87
+ const list = ((_a = scheduleList.data) == null ? void 0 : _a.list) || [];
88
+ await this.saveScheduleToIndexDB(list);
89
+ this.setScheduleList(list);
90
+ return list;
91
+ }
92
+ setScheduleList(list) {
93
+ this.store.scheduleList = list;
94
+ this.syncScheduleMap();
95
+ }
96
+ /**
97
+ * 获取所有日程列表
98
+ */
99
+ getScheduleList() {
100
+ return this.store.scheduleList;
101
+ }
102
+ /**
103
+ * 根据 schedule IDs 获取日程数据
104
+ * 使用 Map 快速查询,时间复杂度 O(m),m 为 ids 数量
105
+ */
106
+ getScheduleByIds(ids) {
107
+ if (!ids || ids.length === 0) {
108
+ return [];
109
+ }
110
+ const result = [];
111
+ for (const id of ids) {
112
+ const schedule = this.store.map.get(id);
113
+ if (schedule) {
114
+ result.push(schedule);
115
+ }
116
+ }
117
+ return result;
118
+ }
119
+ /**
120
+ * 同步更新日程 Map 缓存
121
+ * 将 scheduleList 中的日程同步到 map,以 id 为 key
122
+ * @private
123
+ */
124
+ syncScheduleMap() {
125
+ this.store.map.clear();
126
+ for (const schedule of this.store.scheduleList) {
127
+ this.store.map.set(schedule.id, schedule);
128
+ }
129
+ console.log(`[Schedule] Map 缓存已同步,共 ${this.store.map.size} 个日程`);
130
+ }
131
+ /**
132
+ * 清除缓存
133
+ */
134
+ async clear() {
135
+ this.store.scheduleList = [];
136
+ this.store.map.clear();
137
+ if (this.dbManager) {
138
+ try {
139
+ await this.dbManager.clear(INDEXDB_STORE_NAME);
140
+ console.log("[Schedule] IndexDB 缓存已清空");
141
+ } catch (error) {
142
+ console.error("[Schedule] 清空 IndexDB 缓存失败:", error);
143
+ }
144
+ }
145
+ }
146
+ /**
147
+ * 判断日期是否在日程范围内
148
+ * @param date 日期
149
+ * @param scheduleList 日程列表
150
+ * @returns 是否在日程范围内
151
+ */
152
+ getDateIsInSchedule(date, scheduleList) {
153
+ const scheduleListData = [];
154
+ scheduleList.forEach((item) => {
155
+ if (typeof item === "number") {
156
+ scheduleListData.push(...this.getScheduleByIds([item]));
157
+ } else {
158
+ scheduleListData.push(item);
159
+ }
160
+ });
161
+ return (0, import_utils.getDateIsInSchedule)(date, scheduleListData);
162
+ }
163
+ /**
164
+ * 从 IndexDB 加载日程数据
165
+ * @private
166
+ */
167
+ async loadScheduleFromIndexDB() {
168
+ if (!this.dbManager) {
169
+ return [];
170
+ }
171
+ try {
172
+ const scheduleList = await this.dbManager.getAll(INDEXDB_STORE_NAME);
173
+ return scheduleList || [];
174
+ } catch (error) {
175
+ console.error("[Schedule] 从 IndexDB 读取数据失败:", error);
176
+ return [];
177
+ }
178
+ }
179
+ /**
180
+ * 保存日程数据到 IndexDB
181
+ * @private
182
+ */
183
+ async saveScheduleToIndexDB(scheduleList) {
184
+ if (!this.dbManager) {
185
+ return;
186
+ }
187
+ try {
188
+ await this.dbManager.clear(INDEXDB_STORE_NAME);
189
+ const savePromises = scheduleList.map(
190
+ (schedule) => this.dbManager.add(INDEXDB_STORE_NAME, schedule)
191
+ );
192
+ await Promise.all(savePromises);
193
+ console.log(
194
+ `[Schedule] 已将 ${scheduleList.length} 条日程数据保存到 IndexDB`
195
+ );
196
+ } catch (error) {
197
+ console.error("[Schedule] 保存数据到 IndexDB 失败:", error);
198
+ }
199
+ }
200
+ /**
201
+ * 预加载模块数据(统一接口)
202
+ * 在模块注册后自动调用
203
+ */
204
+ async preload() {
205
+ console.log("[Schedule] 开始预加载数据...");
206
+ try {
207
+ const cachedData = await this.loadScheduleFromIndexDB();
208
+ if (cachedData && cachedData.length > 0) {
209
+ console.log(
210
+ `[Schedule] 从 IndexDB 加载了 ${cachedData.length} 条日程数据`
211
+ );
212
+ this.store.scheduleList = (0, import_lodash_es.cloneDeep)(cachedData);
213
+ this.syncScheduleMap();
214
+ return;
215
+ }
216
+ console.log("[Schedule] IndexDB 中没有缓存数据,从服务器加载...");
217
+ } catch (error) {
218
+ console.warn("[Schedule] 从 IndexDB 加载数据失败:", error);
219
+ }
220
+ const scheduleList = await this.loadAllSchedule();
221
+ if (scheduleList && scheduleList.length > 0) {
222
+ await this.saveScheduleToIndexDB(scheduleList);
223
+ this.store.scheduleList = (0, import_lodash_es.cloneDeep)(scheduleList);
224
+ this.syncScheduleMap();
225
+ }
226
+ }
227
+ };
228
+ // Annotate the CommonJS export names for ESM import in node:
229
+ 0 && (module.exports = {
230
+ ScheduleModuleEx
231
+ });
@@ -0,0 +1 @@
1
+ export * from '../../../modules/Schedule/types';
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/server/modules/schedule/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
19
+ __reExport(types_exports, require("../../../modules/Schedule/types"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("../../../modules/Schedule/types")
23
+ });
@@ -0,0 +1,32 @@
1
+ import dayjs from "dayjs";
2
+ import { ScheduleItem } from "../../../modules/Schedule/types";
3
+ export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
4
+ export type ScheduleTimeSlot = {
5
+ /** 开始时间 HH:mm */
6
+ start_time: string;
7
+ /** 结束时间 HH:mm */
8
+ end_time: string;
9
+ /** 开始日期时间 YYYY-MM-DD HH:mm:ss */
10
+ start_at: dayjs.Dayjs;
11
+ /** 结束日期时间 YYYY-MM-DD HH:mm:ss */
12
+ end_at: dayjs.Dayjs;
13
+ };
14
+ /**
15
+ * 获取当前日期日程时间点
16
+ * @param date 日期 YYYY-MM-DD
17
+ * @param scheduleList 日程列表
18
+ * @returns 当前日期日程时间点 结构,数组 [{
19
+ *
20
+ * // HH:mm
21
+ * end_time: string,
22
+ * // HH:mm
23
+ * start_time: string,
24
+ * // 日期时间
25
+ * // YYYY-MM-DD HH:mm:ss
26
+ * end_at: Dayjs,
27
+ * // YYYY-MM-DD HH:mm:ss
28
+ * start_at: Dayjs,
29
+ *
30
+ * }]
31
+ */
32
+ export declare const getScheduleStartEndTimePoints: (date: string, scheduleList: ScheduleItem[]) => ScheduleTimeSlot[];