@pisell/pisellos 2.2.89 → 2.2.91

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.
@@ -7,11 +7,11 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
7
7
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
8
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
9
9
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
12
  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; } } }; }
11
13
  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); }
12
14
  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; }
13
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
15
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
17
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -31,7 +31,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
31
31
  import { BaseModule } from "../../../modules/BaseModule";
32
32
  import { RequestModeENUM } from "../../../plugins";
33
33
  import { ProductsHooks } from "./types";
34
- import { applyDetailValueToProducts, applyPriceDataToProducts, perfMark } from "../../utils/product";
34
+ import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
35
35
 
36
36
  /**
37
37
  * IndexDB 存储名称
@@ -249,7 +249,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
249
249
  duration: "".concat(_duration, "ms"),
250
250
  error: errorMessage
251
251
  });
252
- throw _context2.t0;
252
+ return _context2.abrupt("return", []);
253
253
  case 18:
254
254
  case "end":
255
255
  return _context2.stop();
@@ -267,24 +267,112 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
267
267
  * 缓存的是已经应用了价格的完整商品列表,避免重复转换
268
268
  * @param schedule_date 日期
269
269
  * @param extraContext 额外的上下文数据(可选,由 Server 层传入)
270
+ * @param options 可选参数
271
+ * @param options.changedIds 变更的商品 IDs,非空时仅对这些商品增量执行 prepare 并更新缓存
270
272
  * @returns 应用了价格的商品列表
271
273
  */
272
274
  )
273
275
  }, {
274
276
  key: "getProductsWithPrice",
275
277
  value: (function () {
276
- var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext) {
277
- var t0, cacheKey, cachedProducts, result;
278
+ var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext, options) {
279
+ var t0, cacheKey, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator, _step, p, _iterator2, _step2, _p, errorMessage, result;
278
280
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
279
281
  while (1) switch (_context3.prev = _context3.next) {
280
282
  case 0:
281
283
  t0 = performance.now();
282
284
  cacheKey = schedule_date;
285
+ changedIds = options === null || options === void 0 ? void 0 : options.changedIds;
283
286
  if (!this.productsPriceCache.has(cacheKey)) {
284
- _context3.next = 7;
287
+ _context3.next = 33;
288
+ break;
289
+ }
290
+ cachedProducts = this.productsPriceCache.get(cacheKey); // 有变更的商品 → 增量 prepare 后 merge 回缓存
291
+ if (!(changedIds && changedIds.length > 0)) {
292
+ _context3.next = 30;
293
+ break;
294
+ }
295
+ this.logInfo('商品价格缓存命中,增量更新变更商品', {
296
+ cacheKey: cacheKey,
297
+ changedIds: changedIds,
298
+ cachedProductCount: cachedProducts.length
299
+ });
300
+ _context3.prev = 7;
301
+ _context3.next = 10;
302
+ return this.prepareProductsWithPrice(schedule_date, extraContext, {
303
+ productIds: changedIds
304
+ });
305
+ case 10:
306
+ updatedProducts = _context3.sent;
307
+ if (!(updatedProducts.length > 0)) {
308
+ _context3.next = 22;
285
309
  break;
286
310
  }
287
- cachedProducts = this.productsPriceCache.get(cacheKey);
311
+ // merge:用更新结果替换缓存中对应的商品,新增的追加
312
+ updatedMap = new Map(updatedProducts.map(function (p) {
313
+ return [p.id, p];
314
+ }));
315
+ mergedCache = [];
316
+ _iterator = _createForOfIteratorHelper(cachedProducts);
317
+ try {
318
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
319
+ p = _step.value;
320
+ if (updatedMap.has(p.id)) {
321
+ mergedCache.push(updatedMap.get(p.id));
322
+ updatedMap.delete(p.id);
323
+ } else {
324
+ mergedCache.push(p);
325
+ }
326
+ }
327
+ // 剩余的是新增商品(create 场景)
328
+ } catch (err) {
329
+ _iterator.e(err);
330
+ } finally {
331
+ _iterator.f();
332
+ }
333
+ _iterator2 = _createForOfIteratorHelper(updatedMap.values());
334
+ try {
335
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
336
+ _p = _step2.value;
337
+ mergedCache.push(_p);
338
+ }
339
+ } catch (err) {
340
+ _iterator2.e(err);
341
+ } finally {
342
+ _iterator2.f();
343
+ }
344
+ this.productsPriceCache.set(cacheKey, mergedCache);
345
+ this.logInfo('增量更新完成', {
346
+ cacheKey: cacheKey,
347
+ changedCount: updatedProducts.length,
348
+ totalCount: mergedCache.length
349
+ });
350
+ perfMark('getProductsWithPrice(incrementalUpdate)', performance.now() - t0, {
351
+ cacheKey: cacheKey,
352
+ changedCount: changedIds.length,
353
+ count: mergedCache.length
354
+ });
355
+ return _context3.abrupt("return", mergedCache);
356
+ case 22:
357
+ _context3.next = 28;
358
+ break;
359
+ case 24:
360
+ _context3.prev = 24;
361
+ _context3.t0 = _context3["catch"](7);
362
+ errorMessage = _context3.t0 instanceof Error ? _context3.t0.message : String(_context3.t0);
363
+ this.logError('增量更新失败,返回现有缓存', {
364
+ cacheKey: cacheKey,
365
+ changedIds: changedIds,
366
+ error: errorMessage
367
+ });
368
+ case 28:
369
+ perfMark('getProductsWithPrice(incrementalUpdate)', performance.now() - t0, {
370
+ cacheKey: cacheKey,
371
+ changedCount: changedIds.length,
372
+ count: cachedProducts.length
373
+ });
374
+ return _context3.abrupt("return", cachedProducts);
375
+ case 30:
288
376
  perfMark('getProductsWithPrice(cacheHit)', performance.now() - t0, {
289
377
  cacheKey: cacheKey,
290
378
  count: cachedProducts.length
@@ -294,13 +382,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
294
382
  productCount: cachedProducts.length
295
383
  });
296
384
  return _context3.abrupt("return", cachedProducts);
297
- case 7:
385
+ case 33:
298
386
  this.logInfo('商品价格缓存未命中,准备获取', {
299
387
  cacheKey: cacheKey
300
388
  });
301
- _context3.next = 10;
389
+ _context3.next = 36;
302
390
  return this.prepareProductsWithPrice(schedule_date, extraContext);
303
- case 10:
391
+ case 36:
304
392
  result = _context3.sent;
305
393
  this.productsPriceCache.set(cacheKey, result);
306
394
  this.logInfo('商品价格已缓存', {
@@ -313,13 +401,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
313
401
  count: result.length
314
402
  });
315
403
  return _context3.abrupt("return", result);
316
- case 16:
404
+ case 42:
317
405
  case "end":
318
406
  return _context3.stop();
319
407
  }
320
- }, _callee3, this);
408
+ }, _callee3, this, [[7, 24]]);
321
409
  }));
322
- function getProductsWithPrice(_x4, _x5) {
410
+ function getProductsWithPrice(_x4, _x5, _x6) {
323
411
  return _getProductsWithPrice.apply(this, arguments);
324
412
  }
325
413
  return getProductsWithPrice;
@@ -328,47 +416,62 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
328
416
  * 准备带价格的商品数据(通过格式化器流程处理)
329
417
  * @param schedule_date 日期
330
418
  * @param extraContext 额外的上下文数据(可选)
331
- * @returns 完整处理后的商品列表
419
+ * @param options 可选参数
420
+ * @param options.productIds 指定商品 IDs,仅处理这些商品;不传则处理全量
421
+ * @returns 处理后的商品列表
332
422
  * @private
333
423
  */
334
424
  )
335
425
  }, {
336
426
  key: "prepareProductsWithPrice",
337
427
  value: (function () {
338
- var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext) {
339
- var tTotal, _priceData$length, allProducts, tIds, ids, i, tPrice, priceData, context, tFormat, processedProducts, errorMessage;
428
+ var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext, options) {
429
+ var tTotal, targetIds, isIncremental, _priceData$length, _this$core, products, ids, idSet, tIds, i, tPrice, priceData, context, tFormat, processedProducts, errorMessage;
340
430
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
341
431
  while (1) switch (_context4.prev = _context4.next) {
342
432
  case 0:
343
433
  tTotal = performance.now();
434
+ targetIds = options === null || options === void 0 ? void 0 : options.productIds;
435
+ isIncremental = targetIds && targetIds.length > 0;
344
436
  this.logInfo('prepareProductsWithPrice 开始处理', {
345
- schedule_date: schedule_date
346
- });
347
- _context4.prev = 2;
348
- // 1. 获取商品列表(内部引用,无拷贝 — formatter 会创建新对象)
349
- allProducts = this.getProductsRef();
350
- this.logInfo('获取到商品列表', {
351
- productCount: allProducts.length
437
+ schedule_date: schedule_date,
438
+ mode: isIncremental ? 'incremental' : 'full',
439
+ targetIdsCount: targetIds === null || targetIds === void 0 ? void 0 : targetIds.length
352
440
  });
441
+ _context4.prev = 4;
442
+ // 1. 获取商品列表:指定 IDs 时从 store 取子集,否则取全量
353
443
 
354
- // 2. 提取 IDs(预分配数组,避免 sort 开销)
355
- tIds = performance.now();
356
- ids = new Array(allProducts.length);
357
- for (i = 0; i < allProducts.length; i++) {
358
- ids[i] = allProducts[i].id;
444
+ if (isIncremental) {
445
+ idSet = new Set(targetIds);
446
+ products = this.getProductsRef().filter(function (p) {
447
+ return idSet.has(p.id);
448
+ });
449
+ ids = products.map(function (p) {
450
+ return p.id;
451
+ });
452
+ } else {
453
+ products = this.getProductsRef();
454
+ tIds = performance.now();
455
+ ids = new Array(products.length);
456
+ for (i = 0; i < products.length; i++) {
457
+ ids[i] = products[i].id;
458
+ }
459
+ perfMark('prepareProducts.extractIds', performance.now() - tIds, {
460
+ count: ids.length
461
+ });
359
462
  }
360
- perfMark('prepareProducts.extractIds', performance.now() - tIds, {
361
- count: ids.length
463
+ this.logInfo('获取到商品列表', {
464
+ productCount: products.length
362
465
  });
363
466
 
364
- // 3. 获取价格数据(网络请求)
467
+ // 2. 获取价格数据(网络请求)
365
468
  tPrice = performance.now();
366
- _context4.next = 12;
469
+ _context4.next = 10;
367
470
  return this.loadProductsPrice({
368
471
  ids: ids,
369
472
  schedule_date: schedule_date
370
473
  });
371
- case 12:
474
+ case 10:
372
475
  priceData = _context4.sent;
373
476
  perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
374
477
  count: ids.length
@@ -378,48 +481,55 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
378
481
  });
379
482
  context = _objectSpread({
380
483
  schedule_date: schedule_date,
381
- priceData: priceData
382
- }, extraContext); // 4. 通过格式化器流程处理商品
484
+ priceData: priceData,
485
+ locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale
486
+ }, extraContext); // 3. 通过格式化器流程处理商品
383
487
  tFormat = performance.now();
384
- _context4.next = 19;
385
- return this.applyFormatters(allProducts, context);
386
- case 19:
488
+ _context4.next = 17;
489
+ return this.applyFormatters(products, context);
490
+ case 17:
387
491
  processedProducts = _context4.sent;
388
492
  perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
389
- count: allProducts.length,
493
+ count: products.length,
390
494
  formatterCount: this.formatters.length
391
495
  });
392
496
  this.logInfo('prepareProductsWithPrice 处理完成', {
393
- originalProductCount: allProducts.length,
497
+ mode: isIncremental ? 'incremental' : 'full',
498
+ originalProductCount: products.length,
394
499
  processedProductCount: processedProducts.length,
395
500
  formatterCount: this.formatters.length
396
501
  });
397
- _context4.next = 24;
502
+ if (isIncremental) {
503
+ _context4.next = 23;
504
+ break;
505
+ }
506
+ _context4.next = 23;
398
507
  return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
399
- case 24:
508
+ case 23:
400
509
  perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
401
- productCount: allProducts.length,
402
- formatterCount: this.formatters.length
510
+ productCount: products.length,
511
+ formatterCount: this.formatters.length,
512
+ mode: isIncremental ? 'incremental' : 'full'
403
513
  });
404
514
  return _context4.abrupt("return", processedProducts);
405
- case 28:
406
- _context4.prev = 28;
407
- _context4.t0 = _context4["catch"](2);
515
+ case 27:
516
+ _context4.prev = 27;
517
+ _context4.t0 = _context4["catch"](4);
408
518
  errorMessage = _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0);
409
519
  console.log("[ProductsModule] \uD83C\uDF10 ERROR", _context4.t0);
410
520
  this.logError('prepareProductsWithPrice 处理失败', {
411
521
  schedule_date: schedule_date,
412
522
  error: errorMessage
413
523
  });
414
- case 33:
524
+ case 32:
415
525
  return _context4.abrupt("return", []);
416
- case 34:
526
+ case 33:
417
527
  case "end":
418
528
  return _context4.stop();
419
529
  }
420
- }, _callee4, this, [[2, 28]]);
530
+ }, _callee4, this, [[4, 27]]);
421
531
  }));
422
- function prepareProductsWithPrice(_x6, _x7) {
532
+ function prepareProductsWithPrice(_x7, _x8, _x9) {
423
533
  return _prepareProductsWithPrice.apply(this, arguments);
424
534
  }
425
535
  return prepareProductsWithPrice;
@@ -501,7 +611,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
501
611
  }
502
612
  }, _callee5, this, [[9, 17]]);
503
613
  }));
504
- function applyFormatters(_x8, _x9) {
614
+ function applyFormatters(_x10, _x11) {
505
615
  return _applyFormatters.apply(this, arguments);
506
616
  }
507
617
  return applyFormatters;
@@ -529,12 +639,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
529
639
  console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528\u4EF7\u683C\u6570\u636E\u5230 ".concat(products.length, " \u4E2A\u5546\u54C1"));
530
640
  return applyPriceDataToProducts(products, context.priceData);
531
641
  };
642
+ var i18nFormatter = function i18nFormatter(products, context) {
643
+ return applyI18nToProducts(products, context.locale);
644
+ };
532
645
  var detailValueFormatter = function detailValueFormatter(products, context) {
533
646
  return applyDetailValueToProducts(products, context);
534
647
  };
535
648
 
536
649
  // 将价格格式化器注册为第一个格式化器
537
650
  this.formatters.unshift(priceFormatter);
651
+ this.formatters.push(i18nFormatter);
538
652
  this.formatters.push(detailValueFormatter);
539
653
  this.isPriceFormatterRegistered = true;
540
654
  console.log('[ProductsModule] ✅ 内置价格格式化器已注册(第 1 个)');
@@ -755,7 +869,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
755
869
  }
756
870
  }, _callee7, this, [[3, 13]]);
757
871
  }));
758
- function fetchProductsByHttp(_x10) {
872
+ function fetchProductsByHttp(_x12) {
759
873
  return _fetchProductsByHttp.apply(this, arguments);
760
874
  }
761
875
  return fetchProductsByHttp;
@@ -795,7 +909,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
795
909
  }
796
910
  }, _callee8, this);
797
911
  }));
798
- function loadProductsByServerHttp(_x11) {
912
+ function loadProductsByServerHttp(_x13) {
799
913
  return _loadProductsByServerHttp.apply(this, arguments);
800
914
  }
801
915
  return loadProductsByServerHttp;
@@ -860,7 +974,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
860
974
  }
861
975
  }, _callee10, this);
862
976
  }));
863
- function getProductById(_x12) {
977
+ function getProductById(_x14) {
864
978
  return _getProductById.apply(this, arguments);
865
979
  }
866
980
  return getProductById;
@@ -874,7 +988,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
874
988
  key: "removeProductsByIds",
875
989
  value: (function () {
876
990
  var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(ids) {
877
- var idSet, _iterator, _step, _id, _iterator2, _step2, id, errorMessage, _iterator3, _step3, _step3$value, dateKey, cachedProducts;
991
+ var idSet, _iterator3, _step3, _id, _iterator4, _step4, id, errorMessage, _iterator5, _step5, _step5$value, dateKey, cachedProducts;
878
992
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
879
993
  while (1) switch (_context11.prev = _context11.next) {
880
994
  case 0:
@@ -886,31 +1000,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
886
1000
  this.store.list = this.store.list.filter(function (p) {
887
1001
  return !idSet.has(p.id);
888
1002
  });
889
- _iterator = _createForOfIteratorHelper(ids);
1003
+ _iterator3 = _createForOfIteratorHelper(ids);
890
1004
  try {
891
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
892
- _id = _step.value;
1005
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1006
+ _id = _step3.value;
893
1007
  this.store.map.delete(_id);
894
1008
  }
895
1009
  } catch (err) {
896
- _iterator.e(err);
1010
+ _iterator3.e(err);
897
1011
  } finally {
898
- _iterator.f();
1012
+ _iterator3.f();
899
1013
  }
900
1014
  if (!this.dbManager) {
901
1015
  _context11.next = 30;
902
1016
  break;
903
1017
  }
904
1018
  _context11.prev = 6;
905
- _iterator2 = _createForOfIteratorHelper(ids);
1019
+ _iterator4 = _createForOfIteratorHelper(ids);
906
1020
  _context11.prev = 8;
907
- _iterator2.s();
1021
+ _iterator4.s();
908
1022
  case 10:
909
- if ((_step2 = _iterator2.n()).done) {
1023
+ if ((_step4 = _iterator4.n()).done) {
910
1024
  _context11.next = 16;
911
1025
  break;
912
1026
  }
913
- id = _step2.value;
1027
+ id = _step4.value;
914
1028
  _context11.next = 14;
915
1029
  return this.dbManager.delete(INDEXDB_STORE_NAME, id);
916
1030
  case 14:
@@ -922,10 +1036,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
922
1036
  case 18:
923
1037
  _context11.prev = 18;
924
1038
  _context11.t0 = _context11["catch"](8);
925
- _iterator2.e(_context11.t0);
1039
+ _iterator4.e(_context11.t0);
926
1040
  case 21:
927
1041
  _context11.prev = 21;
928
- _iterator2.f();
1042
+ _iterator4.f();
929
1043
  return _context11.finish(21);
930
1044
  case 24:
931
1045
  _context11.next = 30;
@@ -939,18 +1053,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
939
1053
  error: errorMessage
940
1054
  });
941
1055
  case 30:
942
- _iterator3 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1056
+ _iterator5 = _createForOfIteratorHelper(this.productsPriceCache.entries());
943
1057
  try {
944
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
945
- _step3$value = _slicedToArray(_step3.value, 2), dateKey = _step3$value[0], cachedProducts = _step3$value[1];
1058
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1059
+ _step5$value = _slicedToArray(_step5.value, 2), dateKey = _step5$value[0], cachedProducts = _step5$value[1];
946
1060
  this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
947
1061
  return !idSet.has(p.id);
948
1062
  }));
949
1063
  }
950
1064
  } catch (err) {
951
- _iterator3.e(err);
1065
+ _iterator5.e(err);
952
1066
  } finally {
953
- _iterator3.f();
1067
+ _iterator5.f();
954
1068
  }
955
1069
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
956
1070
  this.logInfo('removeProductsByIds 完成', {
@@ -962,7 +1076,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
962
1076
  }
963
1077
  }, _callee11, this, [[6, 26], [8, 18, 21, 24]]);
964
1078
  }));
965
- function removeProductsByIds(_x13) {
1079
+ function removeProductsByIds(_x15) {
966
1080
  return _removeProductsByIds.apply(this, arguments);
967
1081
  }
968
1082
  return removeProductsByIds;
@@ -1012,33 +1126,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1012
1126
  }
1013
1127
  return refreshProducts;
1014
1128
  }()
1015
- /**
1016
- * 指定商品的报价单价格变更时,清除价格缓存
1017
- * 后续查询会走完整的 formatter 管道重建缓存
1018
- */
1019
- )
1020
- }, {
1021
- key: "updateProductPriceByIds",
1022
- value: (function () {
1023
- var _updateProductPriceByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1024
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1025
- while (1) switch (_context13.prev = _context13.next) {
1026
- case 0:
1027
- this.logInfo('updateProductPriceByIds: 清除价格缓存', {
1028
- ids: ids
1029
- });
1030
- this.clearPriceCache();
1031
- case 2:
1032
- case "end":
1033
- return _context13.stop();
1034
- }
1035
- }, _callee13, this);
1036
- }));
1037
- function updateProductPriceByIds(_x14) {
1038
- return _updateProductPriceByIds.apply(this, arguments);
1039
- }
1040
- return updateProductPriceByIds;
1041
- }()
1042
1129
  /**
1043
1130
  * 清空缓存
1044
1131
  */
@@ -1046,10 +1133,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1046
1133
  }, {
1047
1134
  key: "clear",
1048
1135
  value: (function () {
1049
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1136
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1050
1137
  var errorMessage;
1051
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1052
- while (1) switch (_context14.prev = _context14.next) {
1138
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1139
+ while (1) switch (_context13.prev = _context13.next) {
1053
1140
  case 0:
1054
1141
  this.logInfo('开始清空缓存', {
1055
1142
  currentProductCount: this.store.list.length,
@@ -1060,22 +1147,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1060
1147
 
1061
1148
  // 同时清空 IndexDB 中的所有数据(包括商品和元数据)
1062
1149
  if (!this.dbManager) {
1063
- _context14.next = 16;
1150
+ _context13.next = 16;
1064
1151
  break;
1065
1152
  }
1066
- _context14.prev = 4;
1067
- _context14.next = 7;
1153
+ _context13.prev = 4;
1154
+ _context13.next = 7;
1068
1155
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1069
1156
  case 7:
1070
1157
  console.log('[Products] IndexDB 缓存已清空');
1071
1158
  this.logInfo('IndexDB 缓存已清空');
1072
- _context14.next = 16;
1159
+ _context13.next = 16;
1073
1160
  break;
1074
1161
  case 11:
1075
- _context14.prev = 11;
1076
- _context14.t0 = _context14["catch"](4);
1077
- errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
1078
- console.error('[Products] 清空 IndexDB 缓存失败:', _context14.t0);
1162
+ _context13.prev = 11;
1163
+ _context13.t0 = _context13["catch"](4);
1164
+ errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1165
+ console.error('[Products] 清空 IndexDB 缓存失败:', _context13.t0);
1079
1166
  this.logError('清空 IndexDB 缓存失败', {
1080
1167
  error: errorMessage
1081
1168
  });
@@ -1084,9 +1171,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1084
1171
  this.logInfo('缓存清空完成');
1085
1172
  case 18:
1086
1173
  case "end":
1087
- return _context14.stop();
1174
+ return _context13.stop();
1088
1175
  }
1089
- }, _callee14, this, [[4, 11]]);
1176
+ }, _callee13, this, [[4, 11]]);
1090
1177
  }));
1091
1178
  function clear() {
1092
1179
  return _clear.apply(this, arguments);
@@ -1101,45 +1188,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1101
1188
  }, {
1102
1189
  key: "loadProductsFromIndexDB",
1103
1190
  value: (function () {
1104
- var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1191
+ var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1105
1192
  var _products$length, _products$length2, t0, products, errorMessage;
1106
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1107
- while (1) switch (_context15.prev = _context15.next) {
1193
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1194
+ while (1) switch (_context14.prev = _context14.next) {
1108
1195
  case 0:
1109
1196
  if (this.dbManager) {
1110
- _context15.next = 3;
1197
+ _context14.next = 3;
1111
1198
  break;
1112
1199
  }
1113
1200
  this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
1114
- return _context15.abrupt("return", []);
1201
+ return _context14.abrupt("return", []);
1115
1202
  case 3:
1116
- _context15.prev = 3;
1203
+ _context14.prev = 3;
1117
1204
  t0 = performance.now();
1118
- _context15.next = 7;
1205
+ _context14.next = 7;
1119
1206
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
1120
1207
  case 7:
1121
- products = _context15.sent;
1208
+ products = _context14.sent;
1122
1209
  perfMark('loadProductsFromIndexDB', performance.now() - t0, {
1123
1210
  count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
1124
1211
  });
1125
1212
  this.logInfo('从 IndexDB 加载商品数据', {
1126
1213
  productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
1127
1214
  });
1128
- return _context15.abrupt("return", products || []);
1215
+ return _context14.abrupt("return", products || []);
1129
1216
  case 13:
1130
- _context15.prev = 13;
1131
- _context15.t0 = _context15["catch"](3);
1132
- errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
1133
- console.error('[Products] 从 IndexDB 读取数据失败:', _context15.t0);
1217
+ _context14.prev = 13;
1218
+ _context14.t0 = _context14["catch"](3);
1219
+ errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
1220
+ console.error('[Products] 从 IndexDB 读取数据失败:', _context14.t0);
1134
1221
  this.logError('从 IndexDB 读取数据失败', {
1135
1222
  error: errorMessage
1136
1223
  });
1137
- return _context15.abrupt("return", []);
1224
+ return _context14.abrupt("return", []);
1138
1225
  case 19:
1139
1226
  case "end":
1140
- return _context15.stop();
1227
+ return _context14.stop();
1141
1228
  }
1142
- }, _callee15, this, [[3, 13]]);
1229
+ }, _callee14, this, [[3, 13]]);
1143
1230
  }));
1144
1231
  function loadProductsFromIndexDB() {
1145
1232
  return _loadProductsFromIndexDB.apply(this, arguments);
@@ -1154,27 +1241,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1154
1241
  }, {
1155
1242
  key: "saveProductsToIndexDB",
1156
1243
  value: (function () {
1157
- var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(products) {
1244
+ var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(products) {
1158
1245
  var t0, errorMessage;
1159
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1160
- while (1) switch (_context16.prev = _context16.next) {
1246
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1247
+ while (1) switch (_context15.prev = _context15.next) {
1161
1248
  case 0:
1162
1249
  if (this.dbManager) {
1163
- _context16.next = 3;
1250
+ _context15.next = 3;
1164
1251
  break;
1165
1252
  }
1166
1253
  this.logWarning('saveProductsToIndexDB: dbManager 不可用');
1167
- return _context16.abrupt("return");
1254
+ return _context15.abrupt("return");
1168
1255
  case 3:
1169
1256
  this.logInfo('开始保存商品数据到 IndexDB', {
1170
1257
  productCount: products.length
1171
1258
  });
1172
- _context16.prev = 4;
1259
+ _context15.prev = 4;
1173
1260
  t0 = performance.now();
1174
- _context16.next = 8;
1261
+ _context15.next = 8;
1175
1262
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1176
1263
  case 8:
1177
- _context16.next = 10;
1264
+ _context15.next = 10;
1178
1265
  return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1179
1266
  case 10:
1180
1267
  perfMark('saveProductsToIndexDB', performance.now() - t0, {
@@ -1184,24 +1271,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1184
1271
  this.logInfo('商品数据已保存到 IndexDB', {
1185
1272
  productCount: products.length
1186
1273
  });
1187
- _context16.next = 20;
1274
+ _context15.next = 20;
1188
1275
  break;
1189
1276
  case 15:
1190
- _context16.prev = 15;
1191
- _context16.t0 = _context16["catch"](4);
1192
- errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
1193
- console.error('[Products] 保存数据到 IndexDB 失败:', _context16.t0);
1277
+ _context15.prev = 15;
1278
+ _context15.t0 = _context15["catch"](4);
1279
+ errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
1280
+ console.error('[Products] 保存数据到 IndexDB 失败:', _context15.t0);
1194
1281
  this.logError('保存数据到 IndexDB 失败', {
1195
1282
  productCount: products.length,
1196
1283
  error: errorMessage
1197
1284
  });
1198
1285
  case 20:
1199
1286
  case "end":
1200
- return _context16.stop();
1287
+ return _context15.stop();
1201
1288
  }
1202
- }, _callee16, this, [[4, 15]]);
1289
+ }, _callee15, this, [[4, 15]]);
1203
1290
  }));
1204
- function saveProductsToIndexDB(_x15) {
1291
+ function saveProductsToIndexDB(_x16) {
1205
1292
  return _saveProductsToIndexDB.apply(this, arguments);
1206
1293
  }
1207
1294
  return saveProductsToIndexDB;
@@ -1217,17 +1304,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1217
1304
  value: function syncProductsMap() {
1218
1305
  var t0 = performance.now();
1219
1306
  this.store.map.clear();
1220
- var _iterator4 = _createForOfIteratorHelper(this.store.list),
1221
- _step4;
1307
+ var _iterator6 = _createForOfIteratorHelper(this.store.list),
1308
+ _step6;
1222
1309
  try {
1223
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1224
- var product = _step4.value;
1310
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1311
+ var product = _step6.value;
1225
1312
  this.store.map.set(product.id, product);
1226
1313
  }
1227
1314
  } catch (err) {
1228
- _iterator4.e(err);
1315
+ _iterator6.e(err);
1229
1316
  } finally {
1230
- _iterator4.f();
1317
+ _iterator6.f();
1231
1318
  }
1232
1319
  perfMark('syncProductsMap', performance.now() - t0, {
1233
1320
  count: this.store.map.size
@@ -1241,26 +1328,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1241
1328
  }, {
1242
1329
  key: "preload",
1243
1330
  value: (function () {
1244
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1331
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1245
1332
  var _products$length3;
1246
1333
  var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
1247
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1248
- while (1) switch (_context17.prev = _context17.next) {
1334
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1335
+ while (1) switch (_context16.prev = _context16.next) {
1249
1336
  case 0:
1250
1337
  console.log('[Products] 开始预加载数据...');
1251
1338
  tTotal = performance.now();
1252
1339
  this.logInfo('开始预加载数据');
1253
- _context17.prev = 3;
1340
+ _context16.prev = 3;
1254
1341
  tIndexDB = performance.now();
1255
- _context17.next = 7;
1342
+ _context16.next = 7;
1256
1343
  return this.loadProductsFromIndexDB();
1257
1344
  case 7:
1258
- cachedData = _context17.sent;
1345
+ cachedData = _context16.sent;
1259
1346
  perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1260
1347
  count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
1261
1348
  });
1262
1349
  if (!(cachedData && cachedData.length > 0)) {
1263
- _context17.next = 19;
1350
+ _context16.next = 19;
1264
1351
  break;
1265
1352
  }
1266
1353
  console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
@@ -1281,26 +1368,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1281
1368
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1282
1369
  source: 'IndexDB'
1283
1370
  });
1284
- return _context17.abrupt("return");
1371
+ return _context16.abrupt("return");
1285
1372
  case 19:
1286
1373
  console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
1287
1374
  this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
1288
- _context17.next = 28;
1375
+ _context16.next = 28;
1289
1376
  break;
1290
1377
  case 23:
1291
- _context17.prev = 23;
1292
- _context17.t0 = _context17["catch"](3);
1293
- errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
1294
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context17.t0);
1378
+ _context16.prev = 23;
1379
+ _context16.t0 = _context16["catch"](3);
1380
+ errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
1381
+ console.warn('[Products] 从 IndexDB 加载数据失败:', _context16.t0);
1295
1382
  this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
1296
1383
  error: errorMessage
1297
1384
  });
1298
1385
  case 28:
1299
1386
  tServer = performance.now();
1300
- _context17.next = 31;
1387
+ _context16.next = 31;
1301
1388
  return this.loadProductsByServer();
1302
1389
  case 31:
1303
- products = _context17.sent;
1390
+ products = _context16.sent;
1304
1391
  perfMark('preload.loadFromServer', performance.now() - tServer, {
1305
1392
  count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
1306
1393
  });
@@ -1332,9 +1419,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1332
1419
  }
1333
1420
  case 34:
1334
1421
  case "end":
1335
- return _context17.stop();
1422
+ return _context16.stop();
1336
1423
  }
1337
- }, _callee17, this, [[3, 23]]);
1424
+ }, _callee16, this, [[3, 23]]);
1338
1425
  }));
1339
1426
  function preload() {
1340
1427
  return _preload.apply(this, arguments);
@@ -1422,30 +1509,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1422
1509
  *
1423
1510
  * product 模块:
1424
1511
  * - operation === 'delete' → 本地删除
1425
- * - change_types 包含 price → SSE 增量拉取
1512
+ * - change_types 包含 price → 仅收集变更 IDs(不拉商品数据)
1426
1513
  * - 有 body → body 完整数据直接覆盖本地
1514
+ * - 其他 → SSE 增量拉取
1427
1515
  *
1428
- * product_collection / product_category / product_quotation
1516
+ * product_collection / product_category:
1429
1517
  * - 按 relation_product_ids SSE 拉取受影响商品
1430
1518
  *
1431
- * 处理完成后清除价格缓存并 emit onProductsSyncCompleted,
1432
- * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
1519
+ * product_quotation:
1520
+ * - 报价单变更影响范围大,直接清除价格缓存走全量重建
1521
+ *
1522
+ * 处理完成后 emit onProductsSyncCompleted(携带 changedIds),
1523
+ * Server 层监听该事件后对变更商品增量执行 prepareProductsWithPrice 并更新缓存
1433
1524
  */
1434
1525
  }, {
1435
1526
  key: "processProductSyncMessages",
1436
1527
  value: (function () {
1437
- var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1438
- var messages, deleteIds, bodyUpdates, sseRefreshIds, _iterator5, _step5, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _msg$relation_product2, uniqueDeleteIds, uniqueSSEIds, freshProducts;
1439
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1440
- while (1) switch (_context18.prev = _context18.next) {
1528
+ var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1529
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator7, _step7, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _msg$relation_product2, _msg$relation_product3, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, freshProducts, allChangedIds, hasChanges;
1530
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1531
+ while (1) switch (_context17.prev = _context17.next) {
1441
1532
  case 0:
1442
1533
  messages = _toConsumableArray(this.pendingSyncMessages);
1443
1534
  this.pendingSyncMessages = [];
1444
1535
  if (!(messages.length === 0)) {
1445
- _context18.next = 4;
1536
+ _context17.next = 4;
1446
1537
  break;
1447
1538
  }
1448
- return _context18.abrupt("return");
1539
+ return _context17.abrupt("return");
1449
1540
  case 4:
1450
1541
  this.logInfo('processProductSyncMessages: 开始处理', {
1451
1542
  count: messages.length
@@ -1453,18 +1544,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1453
1544
  deleteIds = [];
1454
1545
  bodyUpdates = new Map();
1455
1546
  sseRefreshIds = [];
1456
- _iterator5 = _createForOfIteratorHelper(messages);
1457
- _context18.prev = 9;
1458
- _iterator5.s();
1459
- case 11:
1460
- if ((_step5 = _iterator5.n()).done) {
1461
- _context18.next = 33;
1547
+ priceRefreshIds = [];
1548
+ shouldClearPriceCache = false;
1549
+ _iterator7 = _createForOfIteratorHelper(messages);
1550
+ _context17.prev = 11;
1551
+ _iterator7.s();
1552
+ case 13:
1553
+ if ((_step7 = _iterator7.n()).done) {
1554
+ _context17.next = 35;
1462
1555
  break;
1463
1556
  }
1464
- msg = _step5.value;
1557
+ msg = _step7.value;
1465
1558
  channelKey = msg._channelKey || msg.module || 'product';
1466
1559
  if (!(channelKey === 'product')) {
1467
- _context18.next = 30;
1560
+ _context17.next = 32;
1468
1561
  break;
1469
1562
  }
1470
1563
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
@@ -1472,116 +1565,131 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1472
1565
  }
1473
1566
  // 1. 删除场景:operation === 'delete' 或 action === 'delete'
1474
1567
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
1475
- _context18.next = 19;
1568
+ _context17.next = 21;
1476
1569
  break;
1477
1570
  }
1478
1571
  if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
1479
- return _context18.abrupt("continue", 31);
1480
- case 19:
1572
+ return _context17.abrupt("continue", 33);
1573
+ case 21:
1481
1574
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
1482
- _context18.next = 23;
1575
+ _context17.next = 25;
1483
1576
  break;
1484
1577
  }
1485
1578
  ids = msg.ids || (msg.id ? [msg.id] : []);
1486
- sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(ids));
1487
- return _context18.abrupt("continue", 31);
1488
- case 23:
1579
+ priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(ids));
1580
+ return _context17.abrupt("continue", 33);
1581
+ case 25:
1489
1582
  if (!msg.body) {
1490
- _context18.next = 27;
1583
+ _context17.next = 29;
1491
1584
  break;
1492
1585
  }
1493
1586
  bodyId = msg.body.id || msg.id;
1494
1587
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
1495
- return _context18.abrupt("continue", 31);
1496
- case 27:
1497
- // 5. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1588
+ return _context17.abrupt("continue", 33);
1589
+ case 29:
1590
+ // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1498
1591
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
1499
1592
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
1500
1593
  } else if (msg.id) {
1501
1594
  sseRefreshIds.push(msg.id);
1502
1595
  }
1503
- _context18.next = 31;
1596
+ _context17.next = 33;
1504
1597
  break;
1505
- case 30:
1506
- if (['product_collection', 'product_category', 'product_quotation'].includes(channelKey)) {
1598
+ case 32:
1599
+ if (channelKey === 'product_quotation') {
1600
+ // 报价单变更影响范围大,标记清除全量价格缓存
1601
+ shouldClearPriceCache = true;
1507
1602
  if ((_msg$relation_product2 = msg.relation_product_ids) !== null && _msg$relation_product2 !== void 0 && _msg$relation_product2.length) {
1508
1603
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1509
1604
  }
1605
+ } else if (['product_collection', 'product_category'].includes(channelKey)) {
1606
+ if ((_msg$relation_product3 = msg.relation_product_ids) !== null && _msg$relation_product3 !== void 0 && _msg$relation_product3.length) {
1607
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1608
+ }
1510
1609
  }
1511
- case 31:
1512
- _context18.next = 11;
1513
- break;
1514
1610
  case 33:
1515
- _context18.next = 38;
1611
+ _context17.next = 13;
1516
1612
  break;
1517
1613
  case 35:
1518
- _context18.prev = 35;
1519
- _context18.t0 = _context18["catch"](9);
1520
- _iterator5.e(_context18.t0);
1521
- case 38:
1522
- _context18.prev = 38;
1523
- _iterator5.f();
1524
- return _context18.finish(38);
1525
- case 41:
1614
+ _context17.next = 40;
1615
+ break;
1616
+ case 37:
1617
+ _context17.prev = 37;
1618
+ _context17.t0 = _context17["catch"](11);
1619
+ _iterator7.e(_context17.t0);
1620
+ case 40:
1621
+ _context17.prev = 40;
1622
+ _iterator7.f();
1623
+ return _context17.finish(40);
1624
+ case 43:
1526
1625
  uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
1527
- uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds)); // 1. 处理删除
1626
+ uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
1627
+ uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
1528
1628
  if (!(uniqueDeleteIds.length > 0)) {
1529
- _context18.next = 46;
1629
+ _context17.next = 49;
1530
1630
  break;
1531
1631
  }
1532
- _context18.next = 46;
1632
+ _context17.next = 49;
1533
1633
  return this.removeProductsByIds(uniqueDeleteIds);
1534
- case 46:
1634
+ case 49:
1535
1635
  if (!(bodyUpdates.size > 0)) {
1536
- _context18.next = 49;
1636
+ _context17.next = 52;
1537
1637
  break;
1538
1638
  }
1539
- _context18.next = 49;
1639
+ _context17.next = 52;
1540
1640
  return this.applyBodyUpdatesToStore(bodyUpdates);
1541
- case 49:
1641
+ case 52:
1542
1642
  if (!(uniqueSSEIds.length > 0)) {
1543
- _context18.next = 57;
1643
+ _context17.next = 60;
1544
1644
  break;
1545
1645
  }
1546
- _context18.next = 52;
1646
+ _context17.next = 55;
1547
1647
  return this.fetchProductsBySSE(uniqueSSEIds);
1548
- case 52:
1549
- freshProducts = _context18.sent;
1648
+ case 55:
1649
+ freshProducts = _context17.sent;
1550
1650
  if (!(freshProducts.length > 0)) {
1551
- _context18.next = 56;
1651
+ _context17.next = 59;
1552
1652
  break;
1553
1653
  }
1554
- _context18.next = 56;
1654
+ _context17.next = 59;
1555
1655
  return this.mergeProductsToStore(freshProducts);
1556
- case 56:
1656
+ case 59:
1557
1657
  this.logInfo('processProductSyncMessages: SSE 增量更新完成', {
1558
1658
  requestedCount: uniqueSSEIds.length,
1559
1659
  receivedCount: freshProducts.length
1560
1660
  });
1561
- case 57:
1661
+ case 60:
1662
+ // 收集所有非 delete 的变更 IDs(body + SSE + price),用于增量更新价格缓存
1663
+ allChangedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(Array.from(bodyUpdates.keys())), _toConsumableArray(uniqueSSEIds), _toConsumableArray(uniquePriceIds))));
1562
1664
  this.logInfo('processProductSyncMessages: 处理完成', {
1563
1665
  deleteCount: uniqueDeleteIds.length,
1564
1666
  bodyUpdateCount: bodyUpdates.size,
1565
- sseRefreshCount: uniqueSSEIds.length
1566
- });
1567
-
1568
- // 如果都没有变更,则不触发 onProductsSyncCompleted
1569
- if (!(uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0)) {
1570
- _context18.next = 61;
1667
+ sseRefreshCount: uniqueSSEIds.length,
1668
+ priceRefreshCount: uniquePriceIds.length,
1669
+ allChangedIdsCount: allChangedIds.length,
1670
+ shouldClearPriceCache: shouldClearPriceCache
1671
+ });
1672
+ hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
1673
+ if (hasChanges) {
1674
+ _context17.next = 66;
1571
1675
  break;
1572
1676
  }
1573
1677
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
1574
- return _context18.abrupt("return");
1575
- case 61:
1576
- // 清除价格缓存,让后续查询走完整的 formatter 管道重建(含 detailValueFormatter)
1577
- this.clearPriceCache();
1578
- _context18.next = 64;
1579
- return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1580
- case 64:
1678
+ return _context17.abrupt("return");
1679
+ case 66:
1680
+ // 报价单变更 清除全量价格缓存,后续走全量重建
1681
+ if (shouldClearPriceCache) {
1682
+ this.clearPriceCache();
1683
+ }
1684
+ _context17.next = 69;
1685
+ return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
1686
+ changedIds: allChangedIds
1687
+ });
1688
+ case 69:
1581
1689
  case "end":
1582
- return _context18.stop();
1690
+ return _context17.stop();
1583
1691
  }
1584
- }, _callee18, this, [[9, 35, 38, 41]]);
1692
+ }, _callee17, this, [[11, 37, 40, 43]]);
1585
1693
  }));
1586
1694
  function processProductSyncMessages() {
1587
1695
  return _processProductSyncMessages.apply(this, arguments);
@@ -1596,25 +1704,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1596
1704
  }, {
1597
1705
  key: "fetchProductsBySSE",
1598
1706
  value: (function () {
1599
- var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(ids) {
1707
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
1600
1708
  var t0, productList, list, errorMessage;
1601
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1602
- while (1) switch (_context19.prev = _context19.next) {
1709
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1710
+ while (1) switch (_context18.prev = _context18.next) {
1603
1711
  case 0:
1604
1712
  if (this.productDataSource) {
1605
- _context19.next = 3;
1713
+ _context18.next = 3;
1606
1714
  break;
1607
1715
  }
1608
1716
  this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
1609
- return _context19.abrupt("return", []);
1717
+ return _context18.abrupt("return", []);
1610
1718
  case 3:
1611
1719
  this.logInfo('fetchProductsBySSE: 开始', {
1612
1720
  ids: ids,
1613
1721
  count: ids.length
1614
1722
  });
1615
1723
  t0 = performance.now();
1616
- _context19.prev = 5;
1617
- _context19.next = 8;
1724
+ _context18.prev = 5;
1725
+ _context18.next = 8;
1618
1726
  return this.productDataSource.run({
1619
1727
  sse: {
1620
1728
  query: {
@@ -1624,7 +1732,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1624
1732
  }
1625
1733
  });
1626
1734
  case 8:
1627
- productList = _context19.sent;
1735
+ productList = _context18.sent;
1628
1736
  list = productList || [];
1629
1737
  perfMark('fetchProductsBySSE', performance.now() - t0, {
1630
1738
  count: list.length
@@ -1634,23 +1742,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1634
1742
  receivedCount: list.length,
1635
1743
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1636
1744
  });
1637
- return _context19.abrupt("return", list);
1745
+ return _context18.abrupt("return", list);
1638
1746
  case 15:
1639
- _context19.prev = 15;
1640
- _context19.t0 = _context19["catch"](5);
1641
- errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0);
1747
+ _context18.prev = 15;
1748
+ _context18.t0 = _context18["catch"](5);
1749
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1642
1750
  this.logError('fetchProductsBySSE: 失败', {
1643
1751
  ids: ids,
1644
1752
  error: errorMessage
1645
1753
  });
1646
- return _context19.abrupt("return", []);
1754
+ return _context18.abrupt("return", []);
1647
1755
  case 20:
1648
1756
  case "end":
1649
- return _context19.stop();
1757
+ return _context18.stop();
1650
1758
  }
1651
- }, _callee19, this, [[5, 15]]);
1759
+ }, _callee18, this, [[5, 15]]);
1652
1760
  }));
1653
- function fetchProductsBySSE(_x16) {
1761
+ function fetchProductsBySSE(_x17) {
1654
1762
  return _fetchProductsBySSE.apply(this, arguments);
1655
1763
  }
1656
1764
  return fetchProductsBySSE;
@@ -1665,10 +1773,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1665
1773
  }, {
1666
1774
  key: "applyBodyUpdatesToStore",
1667
1775
  value: (function () {
1668
- var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(bodyUpdates) {
1669
- var updatedCount, newCount, appliedIds, _iterator6, _step6, _step6$value, id, body;
1670
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1671
- while (1) switch (_context20.prev = _context20.next) {
1776
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(bodyUpdates) {
1777
+ var updatedCount, newCount, appliedIds, _iterator8, _step8, _step8$value, id, body;
1778
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1779
+ while (1) switch (_context19.prev = _context19.next) {
1672
1780
  case 0:
1673
1781
  this.logInfo('applyBodyUpdatesToStore: 开始', {
1674
1782
  count: bodyUpdates.size
@@ -1684,22 +1792,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1684
1792
  }
1685
1793
  return p;
1686
1794
  });
1687
- _iterator6 = _createForOfIteratorHelper(bodyUpdates);
1795
+ _iterator8 = _createForOfIteratorHelper(bodyUpdates);
1688
1796
  try {
1689
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1690
- _step6$value = _slicedToArray(_step6.value, 2), id = _step6$value[0], body = _step6$value[1];
1797
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1798
+ _step8$value = _slicedToArray(_step8.value, 2), id = _step8$value[0], body = _step8$value[1];
1691
1799
  if (!appliedIds.has(id)) {
1692
1800
  this.store.list.push(body);
1693
1801
  newCount++;
1694
1802
  }
1695
1803
  }
1696
1804
  } catch (err) {
1697
- _iterator6.e(err);
1805
+ _iterator8.e(err);
1698
1806
  } finally {
1699
- _iterator6.f();
1807
+ _iterator8.f();
1700
1808
  }
1701
1809
  this.syncProductsMap();
1702
- _context20.next = 10;
1810
+ _context19.next = 10;
1703
1811
  return this.saveProductsToIndexDB(this.store.list);
1704
1812
  case 10:
1705
1813
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
@@ -1710,11 +1818,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1710
1818
  });
1711
1819
  case 12:
1712
1820
  case "end":
1713
- return _context20.stop();
1821
+ return _context19.stop();
1714
1822
  }
1715
- }, _callee20, this);
1823
+ }, _callee19, this);
1716
1824
  }));
1717
- function applyBodyUpdatesToStore(_x17) {
1825
+ function applyBodyUpdatesToStore(_x18) {
1718
1826
  return _applyBodyUpdatesToStore.apply(this, arguments);
1719
1827
  }
1720
1828
  return applyBodyUpdatesToStore;
@@ -1728,22 +1836,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1728
1836
  }, {
1729
1837
  key: "mergeProductsToStore",
1730
1838
  value: (function () {
1731
- var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(freshProducts) {
1732
- var freshMap, _iterator7, _step7, p, updatedList, newCount, _iterator8, _step8, _p, updatedCount;
1733
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1734
- while (1) switch (_context21.prev = _context21.next) {
1839
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshProducts) {
1840
+ var freshMap, _iterator9, _step9, p, updatedList, newCount, _iterator10, _step10, _p2, updatedCount;
1841
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1842
+ while (1) switch (_context20.prev = _context20.next) {
1735
1843
  case 0:
1736
1844
  freshMap = new Map();
1737
- _iterator7 = _createForOfIteratorHelper(freshProducts);
1845
+ _iterator9 = _createForOfIteratorHelper(freshProducts);
1738
1846
  try {
1739
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1740
- p = _step7.value;
1847
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1848
+ p = _step9.value;
1741
1849
  freshMap.set(p.id, p);
1742
1850
  }
1743
1851
  } catch (err) {
1744
- _iterator7.e(err);
1852
+ _iterator9.e(err);
1745
1853
  } finally {
1746
- _iterator7.f();
1854
+ _iterator9.f();
1747
1855
  }
1748
1856
  updatedList = this.store.list.map(function (p) {
1749
1857
  if (freshMap.has(p.id)) {
@@ -1754,21 +1862,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1754
1862
  return p;
1755
1863
  }); // freshMap 中剩余的是新商品(create 场景)
1756
1864
  newCount = freshMap.size;
1757
- _iterator8 = _createForOfIteratorHelper(freshMap.values());
1865
+ _iterator10 = _createForOfIteratorHelper(freshMap.values());
1758
1866
  try {
1759
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1760
- _p = _step8.value;
1761
- updatedList.push(_p);
1867
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1868
+ _p2 = _step10.value;
1869
+ updatedList.push(_p2);
1762
1870
  }
1763
1871
  } catch (err) {
1764
- _iterator8.e(err);
1872
+ _iterator10.e(err);
1765
1873
  } finally {
1766
- _iterator8.f();
1874
+ _iterator10.f();
1767
1875
  }
1768
1876
  updatedCount = freshProducts.length - newCount;
1769
1877
  this.store.list = updatedList;
1770
1878
  this.syncProductsMap();
1771
- _context21.next = 12;
1879
+ _context20.next = 12;
1772
1880
  return this.saveProductsToIndexDB(this.store.list);
1773
1881
  case 12:
1774
1882
  this.logInfo('mergeProductsToStore: 合并完成', {
@@ -1779,11 +1887,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1779
1887
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1780
1888
  case 14:
1781
1889
  case "end":
1782
- return _context21.stop();
1890
+ return _context20.stop();
1783
1891
  }
1784
- }, _callee21, this);
1892
+ }, _callee20, this);
1785
1893
  }));
1786
- function mergeProductsToStore(_x18) {
1894
+ function mergeProductsToStore(_x19) {
1787
1895
  return _mergeProductsToStore.apply(this, arguments);
1788
1896
  }
1789
1897
  return mergeProductsToStore;
@@ -1797,34 +1905,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1797
1905
  }, {
1798
1906
  key: "silentRefresh",
1799
1907
  value: (function () {
1800
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1908
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1801
1909
  var t0, products, errorMessage;
1802
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1803
- while (1) switch (_context22.prev = _context22.next) {
1910
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1911
+ while (1) switch (_context21.prev = _context21.next) {
1804
1912
  case 0:
1805
1913
  t0 = performance.now();
1806
1914
  this.logInfo('silentRefresh 开始');
1807
- _context22.prev = 2;
1808
- _context22.next = 5;
1915
+ _context21.prev = 2;
1916
+ _context21.next = 5;
1809
1917
  return this.loadProductsByServer();
1810
1918
  case 5:
1811
- products = _context22.sent;
1919
+ products = _context21.sent;
1812
1920
  if (!(products && products.length > 0)) {
1813
- _context22.next = 16;
1921
+ _context21.next = 16;
1814
1922
  break;
1815
1923
  }
1816
1924
  this.store.list = products;
1817
1925
  this.syncProductsMap();
1818
1926
  this.clearPriceCache();
1819
1927
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1820
- _context22.next = 13;
1928
+ _context21.next = 13;
1821
1929
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1822
1930
  case 13:
1823
1931
  this.logInfo('silentRefresh 完成', {
1824
1932
  productCount: products.length,
1825
1933
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1826
1934
  });
1827
- _context22.next = 17;
1935
+ _context21.next = 17;
1828
1936
  break;
1829
1937
  case 16:
1830
1938
  this.logWarning('silentRefresh: 服务器未返回数据');
@@ -1832,21 +1940,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1832
1940
  perfMark('silentRefresh', performance.now() - t0, {
1833
1941
  count: this.store.list.length
1834
1942
  });
1835
- return _context22.abrupt("return", this.store.list);
1943
+ return _context21.abrupt("return", this.store.list);
1836
1944
  case 21:
1837
- _context22.prev = 21;
1838
- _context22.t0 = _context22["catch"](2);
1839
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1945
+ _context21.prev = 21;
1946
+ _context21.t0 = _context21["catch"](2);
1947
+ errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
1840
1948
  this.logError('silentRefresh 失败', {
1841
1949
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
1842
1950
  error: errorMessage
1843
1951
  });
1844
- return _context22.abrupt("return", this.store.list);
1952
+ return _context21.abrupt("return", this.store.list);
1845
1953
  case 26:
1846
1954
  case "end":
1847
- return _context22.stop();
1955
+ return _context21.stop();
1848
1956
  }
1849
- }, _callee22, this, [[2, 21]]);
1957
+ }, _callee21, this, [[2, 21]]);
1850
1958
  }));
1851
1959
  function silentRefresh() {
1852
1960
  return _silentRefresh.apply(this, arguments);