@pisell/pisellos 2.2.30 → 2.2.32

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.
@@ -11,7 +11,26 @@ export declare class ScheduleModuleEx extends BaseModule implements Module, Sche
11
11
  private request;
12
12
  private store;
13
13
  private dbManager;
14
+ private logger;
14
15
  constructor(name?: string, version?: string);
16
+ /**
17
+ * 记录信息日志
18
+ * @param title 日志标题
19
+ * @param metadata 日志元数据
20
+ */
21
+ private logInfo;
22
+ /**
23
+ * 记录警告日志
24
+ * @param title 日志标题
25
+ * @param metadata 日志元数据
26
+ */
27
+ private logWarning;
28
+ /**
29
+ * 记录错误日志
30
+ * @param title 日志标题
31
+ * @param metadata 日志元数据
32
+ */
33
+ private logError;
15
34
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
16
35
  /**
17
36
  * 加载当前店铺下所有 schedule(从服务器)
@@ -42,13 +42,64 @@ import_dayjs.default.extend(import_isSameOrBefore.default);
42
42
  import_dayjs.default.extend(import_isSameOrAfter.default);
43
43
  var INDEXDB_STORE_NAME = "schedule";
44
44
  var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
45
- // IndexDBManager 实例
45
+ // LoggerManager 实例
46
46
  constructor(name, version) {
47
47
  super(name, version);
48
48
  this.defaultName = "schedule";
49
49
  this.defaultVersion = "1.1.0";
50
50
  this.store = {};
51
51
  }
52
+ /**
53
+ * 记录信息日志
54
+ * @param title 日志标题
55
+ * @param metadata 日志元数据
56
+ */
57
+ logInfo(title, metadata) {
58
+ try {
59
+ if (this.logger) {
60
+ this.logger.addLog({
61
+ type: "info",
62
+ title: `[ScheduleModule] ${title}`,
63
+ metadata: metadata || {}
64
+ });
65
+ }
66
+ } catch {
67
+ }
68
+ }
69
+ /**
70
+ * 记录警告日志
71
+ * @param title 日志标题
72
+ * @param metadata 日志元数据
73
+ */
74
+ logWarning(title, metadata) {
75
+ try {
76
+ if (this.logger) {
77
+ this.logger.addLog({
78
+ type: "warning",
79
+ title: `[ScheduleModule] ${title}`,
80
+ metadata: metadata || {}
81
+ });
82
+ }
83
+ } catch {
84
+ }
85
+ }
86
+ /**
87
+ * 记录错误日志
88
+ * @param title 日志标题
89
+ * @param metadata 日志元数据
90
+ */
91
+ logError(title, metadata) {
92
+ try {
93
+ if (this.logger) {
94
+ this.logger.addLog({
95
+ type: "error",
96
+ title: `[ScheduleModule] ${title}`,
97
+ metadata: metadata || {}
98
+ });
99
+ }
100
+ } catch {
101
+ }
102
+ }
52
103
  async initialize(core, options) {
53
104
  this.core = core;
54
105
  this.request = core.getPlugin("request");
@@ -67,27 +118,50 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
67
118
  if (appPlugin) {
68
119
  const app = appPlugin.getApp();
69
120
  this.dbManager = app.dbManager;
121
+ this.logger = app.logger;
70
122
  if (this.dbManager) {
71
123
  console.log("[Schedule] IndexDB Manager 已初始化");
72
124
  } else {
73
125
  console.warn("[Schedule] IndexDB Manager 未找到");
74
126
  }
75
127
  }
128
+ this.logInfo("模块初始化完成", {
129
+ hasDbManager: !!this.dbManager,
130
+ hasLogger: !!this.logger,
131
+ initialScheduleCount: this.store.scheduleList.length
132
+ });
76
133
  }
77
134
  /**
78
135
  * 加载当前店铺下所有 schedule(从服务器)
79
136
  */
80
137
  async loadAllSchedule() {
81
138
  var _a;
82
- const scheduleList = await this.request.get(
83
- `/schedule`,
84
- { num: 999 },
85
- { cache: void 0 }
86
- );
87
- const list = ((_a = scheduleList.data) == null ? void 0 : _a.list) || [];
88
- await this.saveScheduleToIndexDB(list);
89
- this.setScheduleList(list);
90
- return list;
139
+ this.logInfo("开始从服务器加载日程列表");
140
+ const startTime = Date.now();
141
+ try {
142
+ const scheduleList = await this.request.get(
143
+ `/schedule`,
144
+ { num: 999 },
145
+ { cache: void 0 }
146
+ );
147
+ const list = ((_a = scheduleList.data) == null ? void 0 : _a.list) || [];
148
+ const duration = Date.now() - startTime;
149
+ this.logInfo("从服务器加载日程列表成功", {
150
+ scheduleCount: list.length,
151
+ duration: `${duration}ms`
152
+ });
153
+ await this.saveScheduleToIndexDB(list);
154
+ this.setScheduleList(list);
155
+ return list;
156
+ } catch (error) {
157
+ const duration = Date.now() - startTime;
158
+ const errorMessage = error instanceof Error ? error.message : String(error);
159
+ this.logError("从服务器加载日程列表失败", {
160
+ duration: `${duration}ms`,
161
+ error: errorMessage
162
+ });
163
+ throw error;
164
+ }
91
165
  }
92
166
  setScheduleList(list) {
93
167
  this.store.scheduleList = list;
@@ -105,6 +179,7 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
105
179
  */
106
180
  getScheduleByIds(ids) {
107
181
  if (!ids || ids.length === 0) {
182
+ this.logWarning("getScheduleByIds: 未提供有效的 ids", { idsCount: 0 });
108
183
  return [];
109
184
  }
110
185
  const result = [];
@@ -114,6 +189,11 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
114
189
  result.push(schedule);
115
190
  }
116
191
  }
192
+ this.logInfo("getScheduleByIds: 查询完成", {
193
+ requestedCount: ids.length,
194
+ foundCount: result.length,
195
+ notFoundCount: ids.length - result.length
196
+ });
117
197
  return result;
118
198
  }
119
199
  /**
@@ -132,16 +212,23 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
132
212
  * 清除缓存
133
213
  */
134
214
  async clear() {
215
+ this.logInfo("开始清空缓存", {
216
+ currentScheduleCount: this.store.scheduleList.length
217
+ });
135
218
  this.store.scheduleList = [];
136
219
  this.store.map.clear();
137
220
  if (this.dbManager) {
138
221
  try {
139
222
  await this.dbManager.clear(INDEXDB_STORE_NAME);
140
223
  console.log("[Schedule] IndexDB 缓存已清空");
224
+ this.logInfo("IndexDB 缓存已清空");
141
225
  } catch (error) {
226
+ const errorMessage = error instanceof Error ? error.message : String(error);
142
227
  console.error("[Schedule] 清空 IndexDB 缓存失败:", error);
228
+ this.logError("清空 IndexDB 缓存失败", { error: errorMessage });
143
229
  }
144
230
  }
231
+ this.logInfo("缓存清空完成");
145
232
  }
146
233
  /**
147
234
  * 判断日期是否在日程范围内
@@ -158,7 +245,13 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
158
245
  scheduleListData.push(item);
159
246
  }
160
247
  });
161
- return (0, import_utils.getDateIsInSchedule)(date, scheduleListData);
248
+ const result = (0, import_utils.getDateIsInSchedule)(date, scheduleListData);
249
+ this.logInfo("getDateIsInSchedule: 判断日期是否在日程范围内", {
250
+ date,
251
+ scheduleCount: scheduleListData.length,
252
+ isInSchedule: result
253
+ });
254
+ return result;
162
255
  }
163
256
  /**
164
257
  * 从 IndexDB 加载日程数据
@@ -166,13 +259,19 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
166
259
  */
167
260
  async loadScheduleFromIndexDB() {
168
261
  if (!this.dbManager) {
262
+ this.logWarning("loadScheduleFromIndexDB: dbManager 不可用");
169
263
  return [];
170
264
  }
171
265
  try {
172
266
  const scheduleList = await this.dbManager.getAll(INDEXDB_STORE_NAME);
267
+ this.logInfo("从 IndexDB 加载日程数据", {
268
+ scheduleCount: (scheduleList == null ? void 0 : scheduleList.length) ?? 0
269
+ });
173
270
  return scheduleList || [];
174
271
  } catch (error) {
272
+ const errorMessage = error instanceof Error ? error.message : String(error);
175
273
  console.error("[Schedule] 从 IndexDB 读取数据失败:", error);
274
+ this.logError("从 IndexDB 读取数据失败", { error: errorMessage });
176
275
  return [];
177
276
  }
178
277
  }
@@ -182,8 +281,10 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
182
281
  */
183
282
  async saveScheduleToIndexDB(scheduleList) {
184
283
  if (!this.dbManager) {
284
+ this.logWarning("saveScheduleToIndexDB: dbManager 不可用");
185
285
  return;
186
286
  }
287
+ this.logInfo("开始保存日程数据到 IndexDB", { scheduleCount: scheduleList.length });
187
288
  try {
188
289
  await this.dbManager.clear(INDEXDB_STORE_NAME);
189
290
  const savePromises = scheduleList.map(
@@ -193,8 +294,14 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
193
294
  console.log(
194
295
  `[Schedule] 已将 ${scheduleList.length} 条日程数据保存到 IndexDB`
195
296
  );
297
+ this.logInfo("日程数据已保存到 IndexDB", { scheduleCount: scheduleList.length });
196
298
  } catch (error) {
299
+ const errorMessage = error instanceof Error ? error.message : String(error);
197
300
  console.error("[Schedule] 保存数据到 IndexDB 失败:", error);
301
+ this.logError("保存数据到 IndexDB 失败", {
302
+ scheduleCount: scheduleList.length,
303
+ error: errorMessage
304
+ });
198
305
  }
199
306
  }
200
307
  /**
@@ -203,6 +310,8 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
203
310
  */
204
311
  async preload() {
205
312
  console.log("[Schedule] 开始预加载数据...");
313
+ const startTime = Date.now();
314
+ this.logInfo("开始预加载数据");
206
315
  try {
207
316
  const cachedData = await this.loadScheduleFromIndexDB();
208
317
  if (cachedData && cachedData.length > 0) {
@@ -211,17 +320,37 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
211
320
  );
212
321
  this.store.scheduleList = (0, import_lodash_es.cloneDeep)(cachedData);
213
322
  this.syncScheduleMap();
323
+ const duration = Date.now() - startTime;
324
+ this.logInfo("预加载完成(从 IndexDB)", {
325
+ scheduleCount: cachedData.length,
326
+ duration: `${duration}ms`,
327
+ source: "IndexDB"
328
+ });
214
329
  return;
215
330
  }
216
331
  console.log("[Schedule] IndexDB 中没有缓存数据,从服务器加载...");
332
+ this.logInfo("IndexDB 中没有缓存数据,准备从服务器加载");
217
333
  } catch (error) {
334
+ const errorMessage = error instanceof Error ? error.message : String(error);
218
335
  console.warn("[Schedule] 从 IndexDB 加载数据失败:", error);
336
+ this.logWarning("从 IndexDB 加载数据失败,准备从服务器加载", { error: errorMessage });
219
337
  }
220
338
  const scheduleList = await this.loadAllSchedule();
221
339
  if (scheduleList && scheduleList.length > 0) {
222
340
  await this.saveScheduleToIndexDB(scheduleList);
223
341
  this.store.scheduleList = (0, import_lodash_es.cloneDeep)(scheduleList);
224
342
  this.syncScheduleMap();
343
+ const duration = Date.now() - startTime;
344
+ this.logInfo("预加载完成(从服务器)", {
345
+ scheduleCount: scheduleList.length,
346
+ duration: `${duration}ms`,
347
+ source: "Server"
348
+ });
349
+ } else {
350
+ const duration = Date.now() - startTime;
351
+ this.logWarning("预加载完成但未获取到数据", {
352
+ duration: `${duration}ms`
353
+ });
225
354
  }
226
355
  }
227
356
  };
@@ -1171,8 +1171,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1171
1171
  * @throws 支付项缺少 voucher_id 时抛出错误
1172
1172
  */
1173
1173
  async updateVoucherPaymentItemsAsync(voucherPaymentItems) {
1174
- var _a, _b;
1175
1174
  try {
1175
+ this.logInfo("updateVoucherPaymentItemsAsync called:", {
1176
+ voucherPaymentItems
1177
+ });
1176
1178
  if (!this.store.currentOrder) {
1177
1179
  throw (0, import_utils.createCheckoutError)(
1178
1180
  import_types.CheckoutErrorType.ValidationFailed,
@@ -1183,7 +1185,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1183
1185
  this.store.currentOrder.uuid
1184
1186
  );
1185
1187
  if (!voucherPaymentItems || (voucherPaymentItems == null ? void 0 : voucherPaymentItems.length) === 0) {
1186
- const savedVoucherPaymentItems = ((_b = (_a = this.store.currentOrder) == null ? void 0 : _a.payment) == null ? void 0 : _b.filter((item) => item.voucher_id && !item.isSynced)) || [];
1188
+ const savedVoucherPaymentItems = (paymentItems == null ? void 0 : paymentItems.filter((item) => item.voucher_id && !item.isSynced)) || [];
1189
+ this.logInfo("未传入 voucher 且本地订单无 voucher 记录,阻断updateVoucherPaymentItemsAsync", {
1190
+ voucherPaymentItems,
1191
+ savedVoucherPaymentItems
1192
+ });
1187
1193
  if ((savedVoucherPaymentItems == null ? void 0 : savedVoucherPaymentItems.length) === 0)
1188
1194
  return;
1189
1195
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.30",
4
+ "version": "2.2.32",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",