@pisell/pisellos 2.3.62 → 2.3.63

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 (34) hide show
  1. package/dist/core/index.d.ts +0 -7
  2. package/dist/core/index.js +66 -109
  3. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  4. package/dist/modules/Quotation/index.d.ts +0 -6
  5. package/dist/modules/Quotation/index.js +19 -75
  6. package/dist/plugins/request.d.ts +0 -1
  7. package/dist/server/index.d.ts +2 -6
  8. package/dist/server/index.js +91 -132
  9. package/dist/server/modules/floor-plan/index.d.ts +0 -4
  10. package/dist/server/modules/floor-plan/index.js +98 -240
  11. package/dist/server/modules/menu/index.js +23 -48
  12. package/dist/server/modules/order/index.d.ts +7 -12
  13. package/dist/server/modules/order/index.js +96 -248
  14. package/dist/server/modules/products/index.d.ts +2 -8
  15. package/dist/server/modules/products/index.js +75 -167
  16. package/dist/server/modules/resource/index.js +13 -21
  17. package/dist/solution/BookingByStep/index.d.ts +1 -1
  18. package/lib/core/index.d.ts +0 -7
  19. package/lib/core/index.js +3 -20
  20. package/lib/modules/Quotation/index.d.ts +0 -6
  21. package/lib/modules/Quotation/index.js +5 -49
  22. package/lib/plugins/request.d.ts +0 -1
  23. package/lib/server/index.d.ts +2 -6
  24. package/lib/server/index.js +11 -33
  25. package/lib/server/modules/floor-plan/index.d.ts +0 -4
  26. package/lib/server/modules/floor-plan/index.js +6 -54
  27. package/lib/server/modules/menu/index.js +5 -31
  28. package/lib/server/modules/order/index.d.ts +7 -12
  29. package/lib/server/modules/order/index.js +28 -143
  30. package/lib/server/modules/products/index.d.ts +2 -8
  31. package/lib/server/modules/products/index.js +24 -97
  32. package/lib/server/modules/resource/index.js +2 -7
  33. package/lib/solution/BookingByStep/index.d.ts +1 -1
  34. package/package.json +1 -1
@@ -40,7 +40,6 @@ var import_types = require("./types");
40
40
  var import_payment_utils = require("../../../modules/Order/payment-utils");
41
41
  var INDEXDB_STORE_NAME = "orders";
42
42
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = "server_order_last_full_fetch_at";
43
- var ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY = "server_order_last_full_fetch_shop_id";
44
43
  var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = "order_sync_throttle_ms";
45
44
  var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2e3;
46
45
  var ORDER_SQLITE_DEDUPE_MS = 15e3;
@@ -525,47 +524,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
525
524
  return DEFAULT_ORDER_SYNC_THROTTLE_MS;
526
525
  }
527
526
  async preload() {
528
- const preloadStartedAt = Date.now();
529
- let cachedOrders = null;
530
- if (this.dbManager) {
531
- try {
532
- cachedOrders = await this.loadOrdersFromSQLite({ throwOnError: true });
533
- } catch (error) {
534
- this.logWarning("preload-SQLite读取失败,回退远端全量拉取", {
535
- error: error instanceof Error ? error.message : String(error)
536
- });
537
- }
538
- }
539
- if (cachedOrders !== null && this.hasPulledOrdersToday()) {
540
- const memoryOrders = this.normalizeOrdersForMemoryList(
541
- cachedOrders,
542
- "preload.sqliteMemory"
543
- );
544
- this.store.list = (0, import_lodash_es.cloneDeep)(memoryOrders);
545
- this.syncOrdersMap();
546
- await this.core.effects.emit(import_types.OrderHooks.onOrdersLoaded, this.store.list);
547
- await this.emitOrdersChanged([], "preload.sqlite");
548
- this.logInfo("预加载完成", {
549
- trigger: "preload",
550
- source: "SQLite",
551
- orderCount: this.store.list.length,
552
- duration: `${Date.now() - preloadStartedAt}ms`
553
- });
554
- return;
555
- }
556
- const orders = await this.loadOrdersByServer({
557
- trigger: "preload"
558
- });
527
+ const orders = await this.loadOrdersByServer();
559
528
  this.store.list = (0, import_lodash_es.cloneDeep)(orders);
560
529
  this.syncOrdersMap();
561
530
  await this.emitOrdersChanged([], "preload");
562
531
  await this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
563
- this.logInfo("预加载完成", {
564
- trigger: "preload",
565
- source: "Server",
566
- orderCount: this.store.list.length,
567
- duration: `${Date.now() - preloadStartedAt}ms`
568
- });
569
532
  }
570
533
  getOrders() {
571
534
  return this.store.list;
@@ -786,16 +749,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
786
749
  this.logInfo("updateLocalPayment-变更事件完成", paymentContext);
787
750
  return { order: nextOrder, payment: nextPayment, previousPayment };
788
751
  }
789
- async loadOrdersByServer(options = {}) {
752
+ async loadOrdersByServer() {
790
753
  var _a;
791
754
  let orderList = [];
792
- let hasFetchedRemoteSnapshot = false;
793
- const trigger = options.trigger || "unknown";
794
755
  const protectedOrdersBeforeRemoteFetch = (await this.loadOrdersFromSQLite()).filter(
795
756
  (order) => this.shouldProtectLocalOrderFromRemoteSnapshot(order)
796
757
  );
797
758
  this.logInfo("loadOrdersByServer-开始", {
798
- trigger,
799
759
  hasOrderDataSource: !!this.orderDataSource,
800
760
  query: ((_a = this.store) == null ? void 0 : _a.createdAtQuery) || null,
801
761
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
@@ -813,36 +773,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
813
773
  });
814
774
  orderList = data || [];
815
775
  this.logInfo("loadOrdersByServer-SSE拉取成功", {
816
- trigger,
817
776
  count: orderList.length
818
777
  });
819
- hasFetchedRemoteSnapshot = true;
778
+ this.markOrderPulledAtNow();
820
779
  this.lastServerFullFetchAtMs = Date.now();
821
780
  } catch {
822
781
  this.logInfo("loadOrdersByServer-SSE拉取失败,保持当前内存订单");
823
782
  return this.store.list;
824
783
  }
825
784
  }
826
- if (hasFetchedRemoteSnapshot) {
827
- this.clearOrderSnapshotMarker();
828
- }
829
- const {
830
- orders: mergedOrders,
831
- persisted: isRemoteSnapshotPersisted
832
- } = await this.replaceOrdersSnapshotInSQLite(
785
+ const mergedOrders = await this.replaceOrdersSnapshotInSQLite(
833
786
  orderList,
834
787
  "loadOrdersByServer",
835
788
  protectedOrdersBeforeRemoteFetch
836
789
  );
837
- if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
838
- this.markOrderPulledAtNow();
839
- }
840
790
  const memoryOrders = this.normalizeOrdersForMemoryList(
841
791
  mergedOrders,
842
792
  "loadOrdersByServer.memory"
843
793
  );
844
794
  this.logInfo("loadOrdersByServer-结束", {
845
- trigger,
846
795
  count: memoryOrders.length,
847
796
  persistedCount: mergedOrders.length,
848
797
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
@@ -855,34 +804,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
855
804
  * 拿到完整数据后一次性替换 store,触发订单变更与同步完成事件
856
805
  * @returns 刷新后的订单列表
857
806
  */
858
- async silentRefresh(options = {}) {
807
+ async silentRefresh() {
859
808
  const startTime = Date.now();
860
- const trigger = options.trigger || "background";
861
809
  const elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
862
810
  if (this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS) {
863
- this.logInfo("silentRefresh 跳过全量 SSE", {
864
- trigger,
865
- reason: "within_min_interval",
866
- minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
867
- elapsedSinceFullFetchMs: elapsedSinceFullFetch,
868
- orderCount: this.store.list.length
869
- });
870
811
  return this.store.list;
871
812
  }
872
- this.logInfo("silentRefresh 开始", {
873
- trigger,
874
- elapsedSinceFullFetchMs: elapsedSinceFullFetch,
875
- orderCount: this.store.list.length
876
- });
813
+ this.logInfo("silentRefresh 开始");
877
814
  try {
878
815
  this.updateCreateStore();
879
- const orders = await this.loadOrdersByServer({ trigger });
816
+ const orders = await this.loadOrdersByServer();
880
817
  this.store.list = (0, import_lodash_es.cloneDeep)(orders);
881
818
  this.syncOrdersMap();
882
819
  await this.emitOrdersChanged([], "silentRefresh");
883
820
  await this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
884
821
  this.logInfo("silentRefresh 完成", {
885
- trigger,
886
822
  orderCount: orders.length,
887
823
  duration: `${Date.now() - startTime}ms`
888
824
  });
@@ -890,7 +826,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
890
826
  } catch (error) {
891
827
  const errorMessage = error instanceof Error ? error.message : String(error);
892
828
  this.logError("silentRefresh 失败", {
893
- trigger,
894
829
  duration: `${Date.now() - startTime}ms`,
895
830
  error: errorMessage
896
831
  });
@@ -2184,29 +2119,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2184
2119
  return { list, removedCount };
2185
2120
  }
2186
2121
  /**
2187
- * 当前订单缓存可复用窗口。
2188
- * start_time 模式使用精确的营业日起止时间;配置缺失或异常时退化为自然日。
2122
+ * 当前订单拉取窗口:
2123
+ * - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
2124
+ * - 无法解析时退化为自然日窗口
2189
2125
  */
2190
- getCurrentOrderCacheWindow() {
2191
- var _a;
2126
+ getCurrentPullWindow() {
2127
+ var _a, _b;
2192
2128
  const now = (0, import_dayjs.default)();
2193
- try {
2194
- const appPlugin = this.core.getPlugin("app");
2195
- const app = appPlugin == null ? void 0 : appPlugin.getApp();
2196
- const coreData = app == null ? void 0 : app.data.store.getStore().getDataByModel("core");
2197
- const boundary = (_a = coreData == null ? void 0 : coreData.core) == null ? void 0 : _a.operating_day_boundary;
2198
- if ((boundary == null ? void 0 : boundary.type) === "start_time") {
2199
- const boundaryTime = String(boundary.time || "").trim();
2200
- const todayBoundary = (0, import_dayjs.default)(`${now.format("YYYY-MM-DD")} ${boundaryTime}`);
2201
- if (todayBoundary.isValid()) {
2202
- const startAt2 = now.isBefore(todayBoundary) ? todayBoundary.subtract(1, "day") : todayBoundary;
2203
- return {
2204
- startAt: startAt2,
2205
- endExclusiveAt: startAt2.add(1, "day")
2206
- };
2207
- }
2129
+ const range = (_b = (_a = this.store) == null ? void 0 : _a.createdAtQuery) == null ? void 0 : _b.sales_time_between;
2130
+ if (Array.isArray(range) && range.length >= 2) {
2131
+ const startAt2 = (0, import_dayjs.default)(range[0]);
2132
+ const endExclusiveAt = (0, import_dayjs.default)(range[1]);
2133
+ if (startAt2.isValid() && endExclusiveAt.isValid() && endExclusiveAt.isAfter(startAt2)) {
2134
+ return { startAt: startAt2, endExclusiveAt };
2208
2135
  }
2209
- } catch {
2210
2136
  }
2211
2137
  const startAt = now.startOf("day");
2212
2138
  return { startAt, endExclusiveAt: startAt.add(1, "day") };
@@ -2215,51 +2141,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2215
2141
  const lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
2216
2142
  if (!lastFullFetchAt)
2217
2143
  return false;
2218
- const currentShopId = this.getCurrentShopId();
2219
- const lastFullFetchShopId = this.getStorageItem(
2220
- ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY
2221
- );
2222
- if (!currentShopId || !lastFullFetchShopId || currentShopId !== lastFullFetchShopId) {
2223
- return false;
2224
- }
2225
2144
  const parsed = (0, import_dayjs.default)(lastFullFetchAt);
2226
2145
  if (!parsed.isValid())
2227
2146
  return false;
2228
- const { startAt, endExclusiveAt } = this.getCurrentOrderCacheWindow();
2147
+ const { startAt, endExclusiveAt } = this.getCurrentPullWindow();
2229
2148
  return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
2230
2149
  }
2231
2150
  markOrderPulledAtNow() {
2232
- const currentShopId = this.getCurrentShopId();
2233
- if (!currentShopId)
2234
- return;
2235
2151
  this.setStorageItem(
2236
2152
  ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY,
2237
2153
  (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2238
2154
  );
2239
- this.setStorageItem(
2240
- ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY,
2241
- currentShopId
2242
- );
2243
- }
2244
- clearOrderSnapshotMarker() {
2245
- this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, "");
2246
- this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, "");
2247
- }
2248
- getCurrentShopId() {
2249
- var _a;
2250
- try {
2251
- const appPlugin = this.core.getPlugin("app");
2252
- const app = appPlugin == null ? void 0 : appPlugin.getApp();
2253
- if (!app)
2254
- return null;
2255
- const coreData = app.data.store.getStore().getDataByModel("core");
2256
- const shopId = (_a = coreData == null ? void 0 : coreData.core) == null ? void 0 : _a.id;
2257
- if (shopId === void 0 || shopId === null || shopId === "")
2258
- return null;
2259
- return String(shopId);
2260
- } catch {
2261
- return null;
2262
- }
2263
2155
  }
2264
2156
  getStorageItem(key) {
2265
2157
  var _a;
@@ -2286,7 +2178,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2286
2178
  } catch {
2287
2179
  }
2288
2180
  }
2289
- async loadOrdersFromSQLite(options = {}) {
2181
+ async loadOrdersFromSQLite() {
2290
2182
  if (!this.dbManager)
2291
2183
  return [];
2292
2184
  try {
@@ -2294,9 +2186,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2294
2186
  return (orders || []).map(
2295
2187
  (order) => this.normalizeOrderCollectionsForIngress(order, "loadOrdersFromSQLite")
2296
2188
  );
2297
- } catch (error) {
2298
- if (options.throwOnError)
2299
- throw error;
2189
+ } catch {
2300
2190
  return [];
2301
2191
  }
2302
2192
  }
@@ -2518,17 +2408,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2518
2408
  * 用于 SSE 全量拉取与营业日窗口裁剪。
2519
2409
  *
2520
2410
  * @example
2521
- * const { orders, persisted } = await this.replaceOrdersSnapshotInSQLite(orderList, 'refresh')
2411
+ * await this.replaceOrdersSnapshotInSQLite(orderList)
2522
2412
  */
2523
2413
  async replaceOrdersSnapshotInSQLite(orderList, source, protectedOrdersBeforeRemoteFetch = []) {
2524
2414
  if (!this.dbManager) {
2525
- return {
2526
- orders: this.compactOrderListByIdentity(
2527
- orderList.map((order) => this.normalizeRemoteSyncedOrder(order)),
2528
- `${source}.snapshotNoDb`
2529
- ).list,
2530
- persisted: false
2531
- };
2415
+ return this.compactOrderListByIdentity(
2416
+ orderList.map((order) => this.normalizeRemoteSyncedOrder(order)),
2417
+ `${source}.snapshotNoDb`
2418
+ ).list;
2532
2419
  }
2533
2420
  const remoteSnapshot = (0, import_lodash_es.cloneDeep)(orderList).map(
2534
2421
  (order) => this.normalizeOrderCollectionsForIngress(order, `${source}.remoteIngress`)
@@ -2537,7 +2424,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2537
2424
  remoteSnapshot.map((order) => this.normalizeRemoteSyncedOrder(order)),
2538
2425
  `${source}.remoteSnapshot`
2539
2426
  ).list;
2540
- let persisted = false;
2541
2427
  try {
2542
2428
  await this.runInOrderSQLiteSaveQueue(async () => {
2543
2429
  const existingOrders = typeof this.dbManager.getAll === "function" ? await this.dbManager.getAll(INDEXDB_STORE_NAME) : [];
@@ -2602,14 +2488,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2602
2488
  count: mergedSnapshot.length
2603
2489
  });
2604
2490
  });
2605
- persisted = true;
2606
2491
  } catch (error) {
2607
2492
  this.logError("全量保存订单到 SQLite 失败", {
2608
2493
  error: error instanceof Error ? error.message : String(error),
2609
2494
  orderList: remoteSnapshot.length
2610
2495
  });
2611
2496
  }
2612
- return { orders: mergedSnapshot, persisted };
2497
+ return mergedSnapshot;
2613
2498
  }
2614
2499
  /**
2615
2500
  * 清空订单模块的内存数据和本地 SQLite 订单表。
@@ -2625,7 +2510,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2625
2510
  await this.dbManager.clear(INDEXDB_STORE_NAME);
2626
2511
  });
2627
2512
  }
2628
- this.clearOrderSnapshotMarker();
2513
+ this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, "");
2629
2514
  this.emitOrdersChanged([], "clear");
2630
2515
  }
2631
2516
  };
@@ -25,7 +25,6 @@ export declare class ProductsModule extends BaseModule implements Module {
25
25
  private quotationBridgeLoadedKey?;
26
26
  private quotationBridgeRefreshPromise?;
27
27
  private quotationBridgeRefreshKey?;
28
- private quotationBridgeUpdatedCallback?;
29
28
  private quotationScheduleCache;
30
29
  private quotationScheduleCacheSource;
31
30
  private quotationScheduleCacheLoaded;
@@ -73,7 +72,6 @@ export declare class ProductsModule extends BaseModule implements Module {
73
72
  scheduleModule?: any;
74
73
  channel?: string;
75
74
  customer_id?: number | string;
76
- onQuotationUpdated?: () => void;
77
75
  }): Promise<void>;
78
76
  /**
79
77
  * 刷新桥接器内的报价单列表。
@@ -183,9 +181,7 @@ export declare class ProductsModule extends BaseModule implements Module {
183
181
  /**
184
182
  * 通过 ProductDataSource SSE 加载完整商品列表
185
183
  */
186
- loadProductsByServer(options?: {
187
- trigger?: string;
188
- }): Promise<any>;
184
+ loadProductsByServer(): Promise<any>;
189
185
  /**
190
186
  * 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
191
187
  * @param params 查询参数
@@ -335,9 +331,7 @@ export declare class ProductsModule extends BaseModule implements Module {
335
331
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
336
332
  * @returns 刷新后的商品列表
337
333
  */
338
- silentRefresh(options?: {
339
- trigger?: string;
340
- }): Promise<ProductData[]>;
334
+ silentRefresh(): Promise<ProductData[]>;
341
335
  /**
342
336
  * 销毁同步资源(取消 pubsub 订阅、清除定时器)
343
337
  */
@@ -192,7 +192,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
192
192
  * Server 层负责传入完整 schedule 模块,Products 只负责把报价单计算结果转成价格响应形状。
193
193
  */
194
194
  async setupQuotationPriceBridge(params) {
195
- var _a, _b, _c;
195
+ var _a;
196
196
  if (!this.core) {
197
197
  this.logWarning("setupQuotationPriceBridge: core 尚未初始化");
198
198
  return;
@@ -211,13 +211,13 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
211
211
  this.quotationScheduleCacheSource = params.scheduleModule;
212
212
  }
213
213
  this.quotationPriceBridge.setScheduleResolver((id) => {
214
- var _a2, _b2, _c2, _d, _e, _f;
214
+ var _a2, _b, _c, _d, _e, _f;
215
215
  const scheduleId = String(id);
216
216
  if (this.quotationScheduleCache.has(scheduleId)) {
217
217
  return this.quotationScheduleCache.get(scheduleId);
218
218
  }
219
219
  if (!this.quotationScheduleCacheLoaded) {
220
- const scheduleList = ((_b2 = (_a2 = params.scheduleModule).getScheduleList) == null ? void 0 : _b2.call(_a2)) || [];
220
+ const scheduleList = ((_b = (_a2 = params.scheduleModule).getScheduleList) == null ? void 0 : _b.call(_a2)) || [];
221
221
  for (const schedule of scheduleList) {
222
222
  this.quotationScheduleCache.set(String(schedule.id), schedule);
223
223
  }
@@ -226,21 +226,12 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
226
226
  if (this.quotationScheduleCache.has(scheduleId)) {
227
227
  return this.quotationScheduleCache.get(scheduleId);
228
228
  }
229
- const schedules = ((_d = (_c2 = params.scheduleModule).getScheduleListByIds) == null ? void 0 : _d.call(_c2, [id])) || ((_f = (_e = params.scheduleModule).getScheduleByIds) == null ? void 0 : _f.call(_e, [id])) || [];
229
+ const schedules = ((_d = (_c = params.scheduleModule).getScheduleListByIds) == null ? void 0 : _d.call(_c, [id])) || ((_f = (_e = params.scheduleModule).getScheduleByIds) == null ? void 0 : _f.call(_e, [id])) || [];
230
230
  if (schedules[0])
231
231
  this.quotationScheduleCache.set(scheduleId, schedules[0]);
232
232
  return schedules[0];
233
233
  });
234
234
  }
235
- if (params.onQuotationUpdated) {
236
- this.quotationBridgeUpdatedCallback = params.onQuotationUpdated;
237
- }
238
- (_c = (_b = this.quotationPriceBridge).setQuotationListUpdatedListener) == null ? void 0 : _c.call(_b, () => {
239
- var _a2;
240
- this.quotationBridgeLoadedKey = this.getQuotationBridgeScopeKey();
241
- this.clearPriceCache();
242
- (_a2 = this.quotationBridgeUpdatedCallback) == null ? void 0 : _a2.call(this);
243
- });
244
235
  await this.refreshQuotationPriceBridge({ customer_id: params.customer_id });
245
236
  }
246
237
  /**
@@ -807,20 +798,17 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
807
798
  */
808
799
  clearPriceCache() {
809
800
  this.productsPriceCache.clear();
810
- this.quotationScheduleCache.clear();
811
- this.quotationScheduleCacheLoaded = false;
812
801
  console.log("[ProductsModule] 🗑️ 商品价格缓存已清空");
813
802
  }
814
803
  /**
815
804
  * 通过 ProductDataSource SSE 加载完整商品列表
816
805
  */
817
- async loadProductsByServer(options = {}) {
806
+ async loadProductsByServer() {
818
807
  if (!this.productDataSource) {
819
808
  this.logWarning("loadProductsByServer: ProductDataSource 不可用");
820
809
  return [];
821
810
  }
822
- const trigger = options.trigger || "unknown";
823
- this.logInfo("开始通过 DataSource SSE 加载商品列表", { trigger });
811
+ this.logInfo("开始通过 DataSource SSE 加载商品列表");
824
812
  const t0 = performance.now();
825
813
  try {
826
814
  const tSSE = performance.now();
@@ -828,7 +816,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
828
816
  const list = productList || [];
829
817
  (0, import_product.perfMark)("loadProductsByServer.SSE", performance.now() - tSSE, { count: list.length });
830
818
  this.logInfo("通过 DataSource SSE 加载商品列表成功", {
831
- trigger,
832
819
  productCount: list.length,
833
820
  duration: `${Math.round(performance.now() - t0)}ms`
834
821
  });
@@ -842,7 +829,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
842
829
  const errorMessage = error instanceof Error ? error.message : String(error);
843
830
  console.error("[Products] 加载商品数据失败:", error);
844
831
  this.logError("通过 DataSource SSE 加载商品列表失败", {
845
- trigger,
846
832
  duration: `${duration}ms`,
847
833
  error: errorMessage
848
834
  });
@@ -1033,9 +1019,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1033
1019
  async refreshProducts() {
1034
1020
  const tTotal = performance.now();
1035
1021
  this.logInfo("refreshProducts 开始");
1036
- const products = await this.loadProductsByServer({
1037
- trigger: "product_sync"
1038
- });
1022
+ const products = await this.loadProductsByServer();
1039
1023
  if (products && products.length > 0) {
1040
1024
  this.store.list = products;
1041
1025
  this.syncProductsMap();
@@ -1080,23 +1064,18 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1080
1064
  this.logWarning("loadProductsFromIndexDB: dbManager 不可用");
1081
1065
  return [];
1082
1066
  }
1083
- const startedAt = performance.now();
1084
1067
  try {
1068
+ const t0 = performance.now();
1085
1069
  const products = await this.dbManager.getAll(INDEXDB_STORE_NAME);
1086
- const durationMs = +(performance.now() - startedAt).toFixed(2);
1087
- (0, import_product.perfMark)("loadProductsFromIndexDB", durationMs, { count: (products == null ? void 0 : products.length) ?? 0 });
1070
+ (0, import_product.perfMark)("loadProductsFromIndexDB", performance.now() - t0, { count: (products == null ? void 0 : products.length) ?? 0 });
1088
1071
  this.logInfo("从 IndexDB 加载商品数据", {
1089
- productCount: (products == null ? void 0 : products.length) ?? 0,
1090
- durationMs
1072
+ productCount: (products == null ? void 0 : products.length) ?? 0
1091
1073
  });
1092
1074
  return products || [];
1093
1075
  } catch (error) {
1094
1076
  const errorMessage = error instanceof Error ? error.message : String(error);
1095
1077
  console.error("[Products] 从 IndexDB 读取数据失败:", error);
1096
- this.logError("从 IndexDB 读取数据失败", {
1097
- durationMs: +(performance.now() - startedAt).toFixed(2),
1098
- error: errorMessage
1099
- });
1078
+ this.logError("从 IndexDB 读取数据失败", { error: errorMessage });
1100
1079
  return [];
1101
1080
  }
1102
1081
  }
@@ -1124,54 +1103,22 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1124
1103
  this.logWarning("replaceProductsSnapshotInIndexDB: dbManager 不可用");
1125
1104
  return;
1126
1105
  }
1127
- const enqueuedAt = performance.now();
1128
- let queueWaitMs = 0;
1129
- let clearDurationMs = 0;
1130
- let writeDurationMs = 0;
1131
1106
  try {
1132
1107
  await this.runInProductIndexDBSaveQueue(async () => {
1133
- const operationStartedAt = performance.now();
1134
- queueWaitMs = +(operationStartedAt - enqueuedAt).toFixed(2);
1135
- this.logInfo("replaceProductsSnapshotInIndexDB 开始", {
1136
- source,
1137
- productCount: products.length,
1138
- queueWaitMs
1139
- });
1140
- const clearStartedAt = performance.now();
1141
- try {
1142
- await this.dbManager.clear(INDEXDB_STORE_NAME);
1143
- } finally {
1144
- clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
1145
- }
1108
+ this.logInfo("replaceProductsSnapshotInIndexDB 开始", { source, productCount: products.length });
1109
+ const t0 = performance.now();
1110
+ await this.dbManager.clear(INDEXDB_STORE_NAME);
1146
1111
  if (products.length > 0) {
1147
- const writeStartedAt = performance.now();
1148
- try {
1149
- await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1150
- } finally {
1151
- writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
1152
- }
1112
+ await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1153
1113
  }
1154
- const executeDurationMs = +(performance.now() - operationStartedAt).toFixed(2);
1155
- (0, import_product.perfMark)("replaceProductsSnapshotInIndexDB", executeDurationMs, { count: products.length });
1156
- this.logInfo("replaceProductsSnapshotInIndexDB 完成", {
1157
- source,
1158
- productCount: products.length,
1159
- queueWaitMs,
1160
- clearDurationMs,
1161
- writeDurationMs,
1162
- executeDurationMs,
1163
- totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2)
1164
- });
1114
+ (0, import_product.perfMark)("replaceProductsSnapshotInIndexDB", performance.now() - t0, { count: products.length });
1115
+ this.logInfo("replaceProductsSnapshotInIndexDB 完成", { source, productCount: products.length });
1165
1116
  });
1166
1117
  } catch (error) {
1167
1118
  const errorMessage = error instanceof Error ? error.message : String(error);
1168
1119
  this.logError("全量保存商品到 IndexDB 失败", {
1169
1120
  source,
1170
1121
  productCount: products.length,
1171
- queueWaitMs,
1172
- clearDurationMs,
1173
- writeDurationMs,
1174
- totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2),
1175
1122
  error: errorMessage
1176
1123
  });
1177
1124
  }
@@ -1253,7 +1200,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1253
1200
  source: "IndexDB"
1254
1201
  });
1255
1202
  this.logInfo("预加载完成(从 IndexDB)", {
1256
- trigger: "preload",
1257
1203
  productCount: cachedData.length,
1258
1204
  duration: `${Math.round(performance.now() - tTotal)}ms`,
1259
1205
  source: "IndexDB"
@@ -1269,9 +1215,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1269
1215
  this.logWarning("从 IndexDB 加载数据失败,准备从服务器加载", { error: errorMessage });
1270
1216
  }
1271
1217
  const tServer = performance.now();
1272
- const products = await this.loadProductsByServer({
1273
- trigger: "preload"
1274
- });
1218
+ const products = await this.loadProductsByServer();
1275
1219
  (0, import_product.perfMark)("preload.loadFromServer", performance.now() - tServer, { count: (products == null ? void 0 : products.length) ?? 0 });
1276
1220
  if (products && products.length > 0) {
1277
1221
  this.store.list = products;
@@ -1284,7 +1228,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1284
1228
  source: "Server"
1285
1229
  });
1286
1230
  this.logInfo("预加载完成(从服务器)", {
1287
- trigger: "preload",
1288
1231
  productCount: products.length,
1289
1232
  duration: `${Math.round(performance.now() - tTotal)}ms`,
1290
1233
  source: "Server"
@@ -1649,31 +1592,17 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1649
1592
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
1650
1593
  * @returns 刷新后的商品列表
1651
1594
  */
1652
- async silentRefresh(options = {}) {
1595
+ async silentRefresh() {
1653
1596
  const t0 = performance.now();
1654
1597
  const now = Date.now();
1655
- const trigger = options.trigger || "background";
1656
- const elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
1657
- const elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
1658
- if (this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
1659
- this.logInfo("silentRefresh 跳过全量 SSE", {
1660
- trigger,
1661
- reason: "within_min_interval",
1662
- minIntervalMs: PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS,
1663
- elapsedSincePreloadMs,
1664
- elapsedSinceFullFetchMs,
1665
- productCount: this.store.list.length
1666
- });
1598
+ const elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
1599
+ const elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
1600
+ if (this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
1667
1601
  return this.store.list;
1668
1602
  }
1669
- this.logInfo("silentRefresh 开始", {
1670
- trigger,
1671
- elapsedSincePreloadMs,
1672
- elapsedSinceFullFetchMs,
1673
- productCount: this.store.list.length
1674
- });
1603
+ this.logInfo("silentRefresh 开始");
1675
1604
  try {
1676
- const products = await this.loadProductsByServer({ trigger });
1605
+ const products = await this.loadProductsByServer();
1677
1606
  if (products && products.length > 0) {
1678
1607
  this.store.list = products;
1679
1608
  this.syncProductsMap();
@@ -1681,7 +1610,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1681
1610
  this.core.effects.emit(import_types.ProductsHooks.onProductsChanged, this.store.list);
1682
1611
  await this.core.effects.emit(import_types.ProductsHooks.onProductsSyncCompleted, null);
1683
1612
  this.logInfo("silentRefresh 完成", {
1684
- trigger,
1685
1613
  productCount: products.length,
1686
1614
  duration: `${Math.round(performance.now() - t0)}ms`
1687
1615
  });
@@ -1693,7 +1621,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1693
1621
  } catch (error) {
1694
1622
  const errorMessage = error instanceof Error ? error.message : String(error);
1695
1623
  this.logError("silentRefresh 失败", {
1696
- trigger,
1697
1624
  duration: `${Math.round(performance.now() - t0)}ms`,
1698
1625
  error: errorMessage
1699
1626
  });
@@ -88,18 +88,13 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
88
88
  }
89
89
  }
90
90
  async preload() {
91
+ await this.setupResourceSync();
91
92
  const cachedResources = await this.loadResourcesFromSQLite();
92
93
  if (cachedResources.length > 0) {
93
94
  this.store.list = (0, import_lodash_es.cloneDeep)(cachedResources).map((item) => this.normalizeResource(item));
94
95
  this.syncResourcesMap();
95
96
  await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
96
- void this.setupResourceSync().catch((error) => {
97
- this.logError("后台初始化资源同步失败", error);
98
- });
99
- return;
100
- }
101
- await this.setupResourceSync();
102
- if (this.store.list.length === 0) {
97
+ } else {
103
98
  const resources = await this.loadResourcesByServer();
104
99
  if (resources.length > 0) {
105
100
  this.store.list = (0, import_lodash_es.cloneDeep)(resources).map((item) => this.normalizeResource(item));
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.62",
4
+ "version": "2.3.63",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",