@pisell/pisellos 0.0.479 → 0.0.481

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 (147) hide show
  1. package/dist/core/index.d.ts +3 -2
  2. package/dist/core/index.js +7 -0
  3. package/dist/effects/index.d.ts +2 -2
  4. package/dist/effects/index.js +34 -81
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
  7. package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  8. package/dist/model/strategy/adapter/walletPass/utils.js +111 -72
  9. package/dist/modules/Customer/index.js +1 -1
  10. package/dist/modules/Discount/index.d.ts +6 -2
  11. package/dist/modules/Discount/index.js +14 -8
  12. package/dist/modules/Order/index.d.ts +1 -1
  13. package/dist/modules/Order/index.js +18 -13
  14. package/dist/modules/Payment/index.d.ts +4 -0
  15. package/dist/modules/Payment/index.js +774 -649
  16. package/dist/modules/Payment/walletpass.js +44 -17
  17. package/dist/modules/Product/index.d.ts +1 -1
  18. package/dist/modules/Product/types.d.ts +2 -0
  19. package/dist/modules/ProductList/index.d.ts +3 -0
  20. package/dist/modules/ProductList/index.js +9 -7
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +37 -31
  23. package/dist/modules/Rules/types.d.ts +2 -2
  24. package/dist/modules/Schedule/index.d.ts +9 -0
  25. package/dist/modules/Schedule/index.js +15 -2
  26. package/dist/plugins/app-types/app/app.d.ts +1 -0
  27. package/dist/plugins/request.d.ts +2 -0
  28. package/dist/server/index.d.ts +107 -2
  29. package/dist/server/index.js +1507 -279
  30. package/dist/server/modules/index.d.ts +6 -0
  31. package/dist/server/modules/index.js +7 -0
  32. package/dist/server/modules/menu/index.d.ts +19 -0
  33. package/dist/server/modules/menu/index.js +221 -71
  34. package/dist/server/modules/order/index.d.ts +87 -0
  35. package/dist/server/modules/order/index.js +916 -0
  36. package/dist/server/modules/order/types.d.ts +530 -0
  37. package/dist/server/modules/order/types.js +141 -0
  38. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  39. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  40. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  41. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  42. package/dist/server/modules/products/index.d.ts +117 -5
  43. package/dist/server/modules/products/index.js +1450 -240
  44. package/dist/server/modules/products/types.d.ts +25 -1
  45. package/dist/server/modules/products/types.js +3 -0
  46. package/dist/server/modules/resource/index.d.ts +86 -0
  47. package/dist/server/modules/resource/index.js +1128 -0
  48. package/dist/server/modules/resource/types.d.ts +121 -0
  49. package/dist/server/modules/resource/types.js +47 -0
  50. package/dist/server/modules/schedule/index.d.ts +19 -0
  51. package/dist/server/modules/schedule/index.js +229 -68
  52. package/dist/server/utils/product.d.ts +5 -0
  53. package/dist/server/utils/product.js +71 -31
  54. package/dist/solution/BookingTicket/index.d.ts +10 -2
  55. package/dist/solution/BookingTicket/index.js +41 -28
  56. package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
  57. package/dist/solution/Checkout/index.d.ts +1 -0
  58. package/dist/solution/Checkout/index.js +286 -188
  59. package/dist/solution/Checkout/utils/index.d.ts +2 -1
  60. package/dist/solution/Checkout/utils/index.js +6 -4
  61. package/dist/solution/RegisterAndLogin/config.js +340 -1
  62. package/dist/solution/Sales/index.d.ts +96 -0
  63. package/dist/solution/Sales/index.js +566 -0
  64. package/dist/solution/Sales/types.d.ts +67 -0
  65. package/dist/solution/Sales/types.js +26 -0
  66. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/index.js +35 -22
  68. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  69. package/dist/solution/ShopDiscount/utils.d.ts +9 -0
  70. package/dist/solution/ShopDiscount/utils.js +21 -27
  71. package/dist/solution/index.d.ts +2 -1
  72. package/dist/solution/index.js +2 -1
  73. package/dist/types/index.d.ts +5 -0
  74. package/lib/core/index.d.ts +3 -2
  75. package/lib/core/index.js +4 -0
  76. package/lib/effects/index.d.ts +2 -2
  77. package/lib/effects/index.js +22 -31
  78. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  79. package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
  80. package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  81. package/lib/model/strategy/adapter/walletPass/utils.js +115 -48
  82. package/lib/modules/Customer/index.js +1 -1
  83. package/lib/modules/Discount/index.d.ts +6 -2
  84. package/lib/modules/Discount/index.js +3 -1
  85. package/lib/modules/Order/index.d.ts +1 -1
  86. package/lib/modules/Order/index.js +20 -18
  87. package/lib/modules/Payment/index.d.ts +4 -0
  88. package/lib/modules/Payment/index.js +134 -66
  89. package/lib/modules/Payment/walletpass.js +23 -4
  90. package/lib/modules/Product/index.d.ts +1 -1
  91. package/lib/modules/Product/types.d.ts +2 -0
  92. package/lib/modules/ProductList/index.d.ts +3 -0
  93. package/lib/modules/ProductList/index.js +2 -2
  94. package/lib/modules/Rules/index.d.ts +2 -2
  95. package/lib/modules/Rules/index.js +69 -73
  96. package/lib/modules/Rules/types.d.ts +2 -2
  97. package/lib/modules/Schedule/index.d.ts +9 -0
  98. package/lib/modules/Schedule/index.js +11 -0
  99. package/lib/plugins/app-types/app/app.d.ts +1 -0
  100. package/lib/plugins/request.d.ts +2 -0
  101. package/lib/server/index.d.ts +107 -2
  102. package/lib/server/index.js +773 -51
  103. package/lib/server/modules/index.d.ts +6 -0
  104. package/lib/server/modules/index.js +16 -2
  105. package/lib/server/modules/menu/index.d.ts +19 -0
  106. package/lib/server/modules/menu/index.js +121 -2
  107. package/lib/server/modules/order/index.d.ts +87 -0
  108. package/lib/server/modules/order/index.js +543 -0
  109. package/lib/server/modules/order/types.d.ts +530 -0
  110. package/lib/server/modules/order/types.js +34 -0
  111. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  112. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  113. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  114. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  115. package/lib/server/modules/products/index.d.ts +117 -5
  116. package/lib/server/modules/products/index.js +799 -62
  117. package/lib/server/modules/products/types.d.ts +25 -1
  118. package/lib/server/modules/products/types.js +1 -0
  119. package/lib/server/modules/resource/index.d.ts +86 -0
  120. package/lib/server/modules/resource/index.js +557 -0
  121. package/lib/server/modules/resource/types.d.ts +121 -0
  122. package/lib/server/modules/resource/types.js +35 -0
  123. package/lib/server/modules/schedule/index.d.ts +19 -0
  124. package/lib/server/modules/schedule/index.js +141 -12
  125. package/lib/server/utils/product.d.ts +5 -0
  126. package/lib/server/utils/product.js +56 -27
  127. package/lib/solution/BookingTicket/index.d.ts +10 -2
  128. package/lib/solution/BookingTicket/index.js +10 -2
  129. package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
  130. package/lib/solution/Checkout/index.d.ts +1 -0
  131. package/lib/solution/Checkout/index.js +399 -331
  132. package/lib/solution/Checkout/utils/index.d.ts +2 -1
  133. package/lib/solution/Checkout/utils/index.js +6 -4
  134. package/lib/solution/RegisterAndLogin/config.js +266 -1
  135. package/lib/solution/Sales/index.d.ts +96 -0
  136. package/lib/solution/Sales/index.js +416 -0
  137. package/lib/solution/Sales/types.d.ts +67 -0
  138. package/lib/solution/Sales/types.js +35 -0
  139. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  140. package/lib/solution/ShopDiscount/index.js +14 -6
  141. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  142. package/lib/solution/ShopDiscount/utils.d.ts +9 -0
  143. package/lib/solution/ShopDiscount/utils.js +6 -10
  144. package/lib/solution/index.d.ts +2 -1
  145. package/lib/solution/index.js +4 -2
  146. package/lib/types/index.d.ts +5 -0
  147. package/package.json +1 -1
@@ -1,9 +1,17 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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
+ 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
+ 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; }
2
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; } } }; }
3
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); }
4
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; }
5
- 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; }
6
- 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; }
7
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; }
8
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); } }
9
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); }); }; }
@@ -21,16 +29,18 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
21
29
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
30
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
31
  import { BaseModule } from "../../../modules/BaseModule";
24
- import { cloneDeep } from 'lodash-es';
25
32
  import { RequestModeENUM } from "../../../plugins";
26
33
  import { ProductsHooks } from "./types";
27
- import { applyDetailValueToProducts, applyPriceDataToProducts } from "../../utils/product";
34
+ import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
28
35
 
29
36
  /**
30
37
  * IndexDB 存储名称
31
38
  */
32
39
  var INDEXDB_STORE_NAME = 'products';
33
40
 
41
+ /** 商品同步防抖时间(毫秒) */
42
+ var PRODUCT_SYNC_DEBOUNCE_MS = 10000;
43
+
34
44
  /**
35
45
  * Products 模块 - 用于获取和管理完整的商品详细数据
36
46
  * 相比 ProductList 模块,Products 会获取所有详细信息并缓存
@@ -48,6 +58,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
48
58
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
49
59
  _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
50
60
  // IndexDBManager 实例
61
+ _defineProperty(_assertThisInitialized(_this), "logger", void 0);
62
+ // LoggerManager 实例
51
63
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
52
64
  // 商品价格缓存:Map<日期, 应用了价格的商品列表>
53
65
  _defineProperty(_assertThisInitialized(_this), "productsPriceCache", new Map());
@@ -58,6 +70,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
58
70
  _defineProperty(_assertThisInitialized(_this), "formatters", []);
59
71
  // 是否已注册内置价格格式化器
60
72
  _defineProperty(_assertThisInitialized(_this), "isPriceFormatterRegistered", false);
73
+ // ---- 商品数据同步相关 ----
74
+ _defineProperty(_assertThisInitialized(_this), "productDataSource", void 0);
75
+ _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
76
+ _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
61
77
  return _this;
62
78
  }
63
79
  _createClass(ProductsModule, [{
@@ -83,11 +99,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
83
99
  }
84
100
  this.request = core.getPlugin('request');
85
101
 
86
- // 获取并存储 dbManager
102
+ // 获取并存储 dbManager 和 logger
87
103
  appPlugin = core.getPlugin('app');
88
104
  if (appPlugin) {
89
105
  app = appPlugin.getApp();
90
106
  this.dbManager = app.dbManager;
107
+ this.logger = app.logger;
91
108
  if (this.dbManager) {
92
109
  console.log('[Products] IndexDB Manager 已初始化');
93
110
  } else {
@@ -97,7 +114,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
97
114
 
98
115
  // 注册内置的价格格式化器(作为第一个格式化器)
99
116
  this.registerBuiltinPriceFormatter();
100
- case 8:
117
+
118
+ // 初始化 ProductDataSource 实例
119
+ this.initProductDataSource();
120
+
121
+ // 初始化商品数据同步(pubsub 订阅)
122
+ this.setupProductSync();
123
+ this.logInfo('模块初始化完成', {
124
+ hasDbManager: !!this.dbManager,
125
+ hasLogger: !!this.logger,
126
+ initialProductCount: this.store.list.length
127
+ });
128
+ case 11:
101
129
  case "end":
102
130
  return _context.stop();
103
131
  }
@@ -108,6 +136,69 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
108
136
  }
109
137
  return initialize;
110
138
  }()
139
+ /**
140
+ * 记录信息日志
141
+ * @param title 日志标题
142
+ * @param metadata 日志元数据
143
+ */
144
+ }, {
145
+ key: "logInfo",
146
+ value: function logInfo(title, metadata) {
147
+ try {
148
+ if (this.logger) {
149
+ this.logger.addLog({
150
+ type: 'info',
151
+ title: "[ProductsModule] ".concat(title),
152
+ metadata: metadata || {}
153
+ });
154
+ }
155
+ } catch (_unused) {
156
+ // 日志记录失败不影响主流程
157
+ }
158
+ }
159
+
160
+ /**
161
+ * 记录警告日志
162
+ * @param title 日志标题
163
+ * @param metadata 日志元数据
164
+ */
165
+ }, {
166
+ key: "logWarning",
167
+ value: function logWarning(title, metadata) {
168
+ try {
169
+ if (this.logger) {
170
+ this.logger.addLog({
171
+ type: 'warning',
172
+ title: "[ProductsModule] ".concat(title),
173
+ metadata: metadata || {}
174
+ });
175
+ }
176
+ } catch (_unused2) {
177
+ // 日志记录失败不影响主流程
178
+ }
179
+ }
180
+
181
+ /**
182
+ * 记录错误日志
183
+ * @param title 日志标题
184
+ * @param metadata 日志元数据
185
+ */
186
+ }, {
187
+ key: "logError",
188
+ value: function logError(title, metadata) {
189
+ try {
190
+ if (this.logger) {
191
+ this.logger.addLog({
192
+ type: 'error',
193
+ title: "[ProductsModule] ".concat(title),
194
+ metadata: metadata || {}
195
+ });
196
+ }
197
+ } catch (_unused3) {
198
+ // 日志记录失败不影响主流程
199
+ }
200
+ }
201
+
111
202
  /**
112
203
  * 加载商品价格(原始方法,不带缓存)
113
204
  * @private
@@ -116,12 +207,19 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
116
207
  key: "loadProductsPrice",
117
208
  value: (function () {
118
209
  var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
119
- var _ref$ids, ids, customer_id, schedule_date, productsData;
210
+ var _ref$ids, ids, customer_id, schedule_date, startTime, _productsData$data$le, _productsData$data, productsData, duration, _duration, errorMessage;
120
211
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
121
212
  while (1) switch (_context2.prev = _context2.next) {
122
213
  case 0:
123
214
  _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date;
124
- _context2.next = 3;
215
+ this.logInfo('开始加载商品价格', {
216
+ productCount: ids.length,
217
+ schedule_date: schedule_date,
218
+ customer_id: customer_id
219
+ });
220
+ startTime = Date.now();
221
+ _context2.prev = 3;
222
+ _context2.next = 6;
125
223
  return this.request.post("/product/query/price", {
126
224
  ids: ids,
127
225
  customer_id: customer_id,
@@ -129,17 +227,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
129
227
  }, {
130
228
  cache: {
131
229
  mode: RequestModeENUM.REMOTE_LOCAL,
132
- type: "indexDB"
230
+ type: "memory"
133
231
  }
134
232
  });
135
- case 3:
233
+ case 6:
136
234
  productsData = _context2.sent;
235
+ duration = Date.now() - startTime;
236
+ this.logInfo('加载商品价格成功', {
237
+ productCount: ids.length,
238
+ priceDataCount: (_productsData$data$le = (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.length) !== null && _productsData$data$le !== void 0 ? _productsData$data$le : 0,
239
+ duration: "".concat(duration, "ms")
240
+ });
137
241
  return _context2.abrupt("return", productsData.data);
138
- case 5:
242
+ case 12:
243
+ _context2.prev = 12;
244
+ _context2.t0 = _context2["catch"](3);
245
+ _duration = Date.now() - startTime;
246
+ errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
247
+ this.logError('加载商品价格失败', {
248
+ productCount: ids.length,
249
+ duration: "".concat(_duration, "ms"),
250
+ error: errorMessage
251
+ });
252
+ return _context2.abrupt("return", []);
253
+ case 18:
139
254
  case "end":
140
255
  return _context2.stop();
141
256
  }
142
- }, _callee2, this);
257
+ }, _callee2, this, [[3, 12]]);
143
258
  }));
144
259
  function loadProductsPrice(_x3) {
145
260
  return _loadProductsPrice.apply(this, arguments);
@@ -152,45 +267,147 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
152
267
  * 缓存的是已经应用了价格的完整商品列表,避免重复转换
153
268
  * @param schedule_date 日期
154
269
  * @param extraContext 额外的上下文数据(可选,由 Server 层传入)
270
+ * @param options 可选参数
271
+ * @param options.changedIds 变更的商品 IDs,非空时仅对这些商品增量执行 prepare 并更新缓存
155
272
  * @returns 应用了价格的商品列表
156
273
  */
157
274
  )
158
275
  }, {
159
276
  key: "getProductsWithPrice",
160
277
  value: (function () {
161
- var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext) {
162
- var cacheKey, 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;
163
280
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
164
281
  while (1) switch (_context3.prev = _context3.next) {
165
282
  case 0:
166
- cacheKey = schedule_date; // 检查缓存
283
+ t0 = performance.now();
284
+ cacheKey = schedule_date;
285
+ changedIds = options === null || options === void 0 ? void 0 : options.changedIds;
167
286
  if (!this.productsPriceCache.has(cacheKey)) {
168
- _context3.next = 4;
287
+ _context3.next = 33;
169
288
  break;
170
289
  }
171
- console.log("[ProductsModule] \uD83D\uDCB0 \u5546\u54C1\u4EF7\u683C\u7F13\u5B58\u547D\u4E2D: ".concat(cacheKey));
172
- return _context3.abrupt("return", this.productsPriceCache.get(cacheKey));
173
- case 4:
174
- // 发起新请求并应用价格
175
- console.log("[ProductsModule] \uD83C\uDF10 \u83B7\u53D6\u5546\u54C1\u5E76\u5E94\u7528\u4EF7\u683C: ".concat(cacheKey));
176
- _context3.next = 7;
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;
309
+ break;
310
+ }
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:
376
+ perfMark('getProductsWithPrice(cacheHit)', performance.now() - t0, {
377
+ cacheKey: cacheKey,
378
+ count: cachedProducts.length
379
+ });
380
+ this.logInfo('商品价格缓存命中', {
381
+ cacheKey: cacheKey,
382
+ productCount: cachedProducts.length
383
+ });
384
+ return _context3.abrupt("return", cachedProducts);
385
+ case 33:
386
+ this.logInfo('商品价格缓存未命中,准备获取', {
387
+ cacheKey: cacheKey
388
+ });
389
+ _context3.next = 36;
177
390
  return this.prepareProductsWithPrice(schedule_date, extraContext);
178
- case 7:
391
+ case 36:
179
392
  result = _context3.sent;
180
- // 存入缓存
181
393
  this.productsPriceCache.set(cacheKey, result);
182
- console.log("[ProductsModule] \u2705 \u5546\u54C1\u4EF7\u683C\u5DF2\u7F13\u5B58: ".concat(cacheKey, ", \u5171 ").concat(result.length, " \u4E2A\u5546\u54C1"));
183
-
184
- // 清理过期缓存
394
+ this.logInfo('商品价格已缓存', {
395
+ cacheKey: cacheKey,
396
+ productCount: result.length
397
+ });
185
398
  this.cleanExpiredPriceCache();
399
+ perfMark('getProductsWithPrice(cacheMiss)', performance.now() - t0, {
400
+ cacheKey: cacheKey,
401
+ count: result.length
402
+ });
186
403
  return _context3.abrupt("return", result);
187
- case 12:
404
+ case 42:
188
405
  case "end":
189
406
  return _context3.stop();
190
407
  }
191
- }, _callee3, this);
408
+ }, _callee3, this, [[7, 24]]);
192
409
  }));
193
- function getProductsWithPrice(_x4, _x5) {
410
+ function getProductsWithPrice(_x4, _x5, _x6) {
194
411
  return _getProductsWithPrice.apply(this, arguments);
195
412
  }
196
413
  return getProductsWithPrice;
@@ -199,67 +416,120 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
199
416
  * 准备带价格的商品数据(通过格式化器流程处理)
200
417
  * @param schedule_date 日期
201
418
  * @param extraContext 额外的上下文数据(可选)
202
- * @returns 完整处理后的商品列表
419
+ * @param options 可选参数
420
+ * @param options.productIds 指定商品 IDs,仅处理这些商品;不传则处理全量
421
+ * @returns 处理后的商品列表
203
422
  * @private
204
423
  */
205
424
  )
206
425
  }, {
207
426
  key: "prepareProductsWithPrice",
208
427
  value: (function () {
209
- var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext) {
210
- var allProducts, priceData, context, processedProducts;
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;
211
430
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
212
431
  while (1) switch (_context4.prev = _context4.next) {
213
432
  case 0:
214
- _context4.prev = 0;
215
- _context4.next = 3;
216
- return this.getProducts();
217
- case 3:
218
- allProducts = _context4.sent;
219
- console.log("[ProductsModule] \uD83C\uDF10 \u5F00\u59CB\u83B7\u53D6\u5546\u54C1\u62A5\u4EF7\u5355\u4EF7\u683C");
220
- // 2. 获取价格数据
221
- _context4.next = 7;
433
+ tTotal = performance.now();
434
+ targetIds = options === null || options === void 0 ? void 0 : options.productIds;
435
+ isIncremental = targetIds && targetIds.length > 0;
436
+ this.logInfo('prepareProductsWithPrice 开始处理', {
437
+ schedule_date: schedule_date,
438
+ mode: isIncremental ? 'incremental' : 'full',
439
+ targetIdsCount: targetIds === null || targetIds === void 0 ? void 0 : targetIds.length
440
+ });
441
+ _context4.prev = 4;
442
+ // 1. 获取商品列表:指定 IDs 时从 store 取子集,否则取全量
443
+
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
+ });
462
+ }
463
+ this.logInfo('获取到商品列表', {
464
+ productCount: products.length
465
+ });
466
+
467
+ // 2. 获取价格数据(网络请求)
468
+ tPrice = performance.now();
469
+ _context4.next = 10;
222
470
  return this.loadProductsPrice({
223
- ids: allProducts.map(function (product) {
224
- return product.id;
225
- }).sort(function (a, b) {
226
- return a - b;
227
- }),
471
+ ids: ids,
228
472
  schedule_date: schedule_date
229
473
  });
230
- case 7:
474
+ case 10:
231
475
  priceData = _context4.sent;
232
- console.log("[ProductsModule] \uD83C\uDF10 \u83B7\u53D6\u5546\u54C1\u62A5\u4EF7\u5355\u4EF7\u683C\u6210\u529F", priceData);
233
- // 3. 构建上下文(包含价格数据,合并外部传入的额外上下文)
476
+ perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
477
+ count: ids.length
478
+ });
479
+ this.logInfo('获取商品报价单价格成功', {
480
+ priceDataCount: (_priceData$length = priceData === null || priceData === void 0 ? void 0 : priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
481
+ });
234
482
  context = _objectSpread({
235
483
  schedule_date: schedule_date,
236
- priceData: priceData
237
- }, extraContext);
238
- console.log("[ProductsModule] \uD83C\uDF10 \u901A\u8FC7\u683C\u5F0F\u5316\u5668\u6D41\u7A0B\u5904\u7406\u5546\u54C1\uFF08\u5305\u62EC\u4EF7\u683C\u5E94\u7528\u3001\u5B57\u6BB5\u6269\u5C55\u7B49\uFF09");
239
- // 4. 通过格式化器流程处理商品(包括价格应用、字段扩展等)
240
- _context4.next = 13;
241
- return this.applyFormatters(allProducts, context);
242
- case 13:
243
- processedProducts = _context4.sent;
244
- console.log("[ProductsModule] \uD83C\uDF10 \u901A\u8FC7\u683C\u5F0F\u5316\u5668\u6D41\u7A0B\u5904\u7406\u5546\u54C1\uFF08\u5305\u62EC\u4EF7\u683C\u5E94\u7528\u3001\u5B57\u6BB5\u6269\u5C55\u7B49\uFF09\u6210\u529F", processedProducts);
245
- // 5. 触发钩子事件(用于外部监听)
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. 通过格式化器流程处理商品
487
+ tFormat = performance.now();
246
488
  _context4.next = 17;
247
- return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
489
+ return this.applyFormatters(products, context);
248
490
  case 17:
491
+ processedProducts = _context4.sent;
492
+ perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
493
+ count: products.length,
494
+ formatterCount: this.formatters.length
495
+ });
496
+ this.logInfo('prepareProductsWithPrice 处理完成', {
497
+ mode: isIncremental ? 'incremental' : 'full',
498
+ originalProductCount: products.length,
499
+ processedProductCount: processedProducts.length,
500
+ formatterCount: this.formatters.length
501
+ });
502
+ if (isIncremental) {
503
+ _context4.next = 23;
504
+ break;
505
+ }
506
+ _context4.next = 23;
507
+ return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
508
+ case 23:
509
+ perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
510
+ productCount: products.length,
511
+ formatterCount: this.formatters.length,
512
+ mode: isIncremental ? 'incremental' : 'full'
513
+ });
249
514
  return _context4.abrupt("return", processedProducts);
250
- case 20:
251
- _context4.prev = 20;
252
- _context4.t0 = _context4["catch"](0);
515
+ case 27:
516
+ _context4.prev = 27;
517
+ _context4.t0 = _context4["catch"](4);
518
+ errorMessage = _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0);
253
519
  console.log("[ProductsModule] \uD83C\uDF10 ERROR", _context4.t0);
254
- case 23:
520
+ this.logError('prepareProductsWithPrice 处理失败', {
521
+ schedule_date: schedule_date,
522
+ error: errorMessage
523
+ });
524
+ case 32:
255
525
  return _context4.abrupt("return", []);
256
- case 24:
526
+ case 33:
257
527
  case "end":
258
528
  return _context4.stop();
259
529
  }
260
- }, _callee4, this, [[0, 20]]);
530
+ }, _callee4, this, [[4, 27]]);
261
531
  }));
262
- function prepareProductsWithPrice(_x6, _x7) {
532
+ function prepareProductsWithPrice(_x7, _x8, _x9) {
263
533
  return _prepareProductsWithPrice.apply(this, arguments);
264
534
  }
265
535
  return prepareProductsWithPrice;
@@ -276,52 +546,72 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
276
546
  key: "applyFormatters",
277
547
  value: (function () {
278
548
  var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products, context) {
279
- var result, i, formatter;
549
+ var result, i, formatter, tF, errorMessage;
280
550
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
281
551
  while (1) switch (_context5.prev = _context5.next) {
282
552
  case 0:
283
553
  result = products;
284
554
  if (!(this.formatters.length === 0)) {
285
- _context5.next = 4;
555
+ _context5.next = 5;
286
556
  break;
287
557
  }
288
558
  console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
559
+ this.logWarning('没有注册任何格式化器', {
560
+ productCount: products.length
561
+ });
289
562
  return _context5.abrupt("return", result);
290
- case 4:
291
- i = 0;
292
563
  case 5:
564
+ this.logInfo('开始应用格式化器', {
565
+ productCount: products.length,
566
+ formatterCount: this.formatters.length
567
+ });
568
+ i = 0;
569
+ case 7:
293
570
  if (!(i < this.formatters.length)) {
294
- _context5.next = 20;
571
+ _context5.next = 25;
295
572
  break;
296
573
  }
297
574
  formatter = this.formatters[i];
298
- _context5.prev = 7;
299
- console.log("[ProductsModule] \uD83D\uDCDD \u5E94\u7528\u683C\u5F0F\u5316\u5668 ".concat(i + 1, "/").concat(this.formatters.length));
300
- _context5.next = 11;
575
+ _context5.prev = 9;
576
+ tF = performance.now();
577
+ _context5.next = 13;
301
578
  return formatter(result, context);
302
- case 11:
579
+ case 13:
303
580
  result = _context5.sent;
304
- _context5.next = 17;
581
+ perfMark("applyFormatters[".concat(i, "]"), performance.now() - tF, {
582
+ index: i,
583
+ total: this.formatters.length,
584
+ productCount: result.length
585
+ });
586
+ _context5.next = 22;
305
587
  break;
306
- case 14:
307
- _context5.prev = 14;
308
- _context5.t0 = _context5["catch"](7);
309
- console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context5.t0);
310
- // 继续执行后续格式化器,不中断流程
311
588
  case 17:
589
+ _context5.prev = 17;
590
+ _context5.t0 = _context5["catch"](9);
591
+ errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
592
+ console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context5.t0);
593
+ this.logError("\u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25"), {
594
+ formatterIndex: i + 1,
595
+ totalFormatters: this.formatters.length,
596
+ error: errorMessage
597
+ });
598
+ case 22:
312
599
  i++;
313
- _context5.next = 5;
600
+ _context5.next = 7;
314
601
  break;
315
- case 20:
316
- console.log("[ProductsModule] \u2705 \u6240\u6709\u683C\u5F0F\u5316\u5668\u5DF2\u5E94\u7528\uFF0C\u5171 ".concat(this.formatters.length, " \u4E2A"));
602
+ case 25:
603
+ this.logInfo('所有格式化器已应用', {
604
+ formatterCount: this.formatters.length,
605
+ resultProductCount: result.length
606
+ });
317
607
  return _context5.abrupt("return", result);
318
- case 22:
608
+ case 27:
319
609
  case "end":
320
610
  return _context5.stop();
321
611
  }
322
- }, _callee5, this, [[7, 14]]);
612
+ }, _callee5, this, [[9, 17]]);
323
613
  }));
324
- function applyFormatters(_x8, _x9) {
614
+ function applyFormatters(_x10, _x11) {
325
615
  return _applyFormatters.apply(this, arguments);
326
616
  }
327
617
  return applyFormatters;
@@ -349,12 +639,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
349
639
  console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528\u4EF7\u683C\u6570\u636E\u5230 ".concat(products.length, " \u4E2A\u5546\u54C1"));
350
640
  return applyPriceDataToProducts(products, context.priceData);
351
641
  };
642
+ var i18nFormatter = function i18nFormatter(products, context) {
643
+ return applyI18nToProducts(products, context.locale);
644
+ };
352
645
  var detailValueFormatter = function detailValueFormatter(products, context) {
353
646
  return applyDetailValueToProducts(products, context);
354
647
  };
355
648
 
356
649
  // 将价格格式化器注册为第一个格式化器
357
650
  this.formatters.unshift(priceFormatter);
651
+ this.formatters.push(i18nFormatter);
358
652
  this.formatters.push(detailValueFormatter);
359
653
  this.isPriceFormatterRegistered = true;
360
654
  console.log('[ProductsModule] ✅ 内置价格格式化器已注册(第 1 个)');
@@ -438,34 +732,106 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
438
732
  }
439
733
 
440
734
  /**
441
- * 加载完整商品列表通过接口(包含所有详细数据)
442
- * @param params 查询参数
735
+ * 通过 ProductDataSource SSE 加载完整商品列表
443
736
  */
444
737
  }, {
445
738
  key: "loadProductsByServer",
446
739
  value: (function () {
447
- var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
448
- var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, _this$otherParams, _productsData$data, productsData;
740
+ var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
741
+ var t0, tSSE, productList, list, duration, errorMessage;
449
742
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
450
743
  while (1) switch (_context6.prev = _context6.next) {
744
+ case 0:
745
+ if (this.productDataSource) {
746
+ _context6.next = 3;
747
+ break;
748
+ }
749
+ this.logWarning('loadProductsByServer: ProductDataSource 不可用');
750
+ return _context6.abrupt("return", []);
751
+ case 3:
752
+ this.logInfo('开始通过 DataSource SSE 加载商品列表');
753
+ t0 = performance.now();
754
+ _context6.prev = 5;
755
+ tSSE = performance.now();
756
+ _context6.next = 9;
757
+ return this.productDataSource.run({
758
+ sse: {}
759
+ });
760
+ case 9:
761
+ productList = _context6.sent;
762
+ list = productList || [];
763
+ perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
764
+ count: list.length
765
+ });
766
+ this.logInfo('通过 DataSource SSE 加载商品列表成功', {
767
+ productCount: list.length,
768
+ duration: "".concat(Math.round(performance.now() - t0), "ms")
769
+ });
770
+ _context6.next = 15;
771
+ return this.saveProductsToIndexDB(list);
772
+ case 15:
773
+ _context6.next = 17;
774
+ return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
775
+ case 17:
776
+ perfMark('loadProductsByServer', performance.now() - t0, {
777
+ count: list.length
778
+ });
779
+ return _context6.abrupt("return", list);
780
+ case 21:
781
+ _context6.prev = 21;
782
+ _context6.t0 = _context6["catch"](5);
783
+ duration = Math.round(performance.now() - t0);
784
+ errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
785
+ console.error('[Products] 加载商品数据失败:', _context6.t0);
786
+ this.logError('通过 DataSource SSE 加载商品列表失败', {
787
+ duration: "".concat(duration, "ms"),
788
+ error: errorMessage
789
+ });
790
+ return _context6.abrupt("return", []);
791
+ case 28:
792
+ case "end":
793
+ return _context6.stop();
794
+ }
795
+ }, _callee6, this, [[5, 21]]);
796
+ }));
797
+ function loadProductsByServer() {
798
+ return _loadProductsByServer.apply(this, arguments);
799
+ }
800
+ return loadProductsByServer;
801
+ }()
802
+ /**
803
+ * 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
804
+ * @param params 查询参数
805
+ * @returns 商品列表
806
+ */
807
+ )
808
+ }, {
809
+ key: "fetchProductsByHttp",
810
+ value: (function () {
811
+ var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
812
+ var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, startTime, _this$otherParams, _productsData$data2, productsData, productList, duration, _duration2, errorMessage;
813
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
814
+ while (1) switch (_context7.prev = _context7.next) {
451
815
  case 0:
452
816
  _ref2 = params || {}, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids, _ref2$product_ids = _ref2.product_ids, product_ids = _ref2$product_ids === void 0 ? [] : _ref2$product_ids, _ref2$collection = _ref2.collection, collection = _ref2$collection === void 0 ? [] : _ref2$collection, customer_id = _ref2.customer_id, cacheId = _ref2.cacheId;
453
- _context6.prev = 1;
454
- _context6.next = 4;
817
+ this.logInfo('fetchProductsByHttp: 开始请求', {
818
+ categoryIdsCount: category_ids.length,
819
+ productIdsCount: product_ids.length,
820
+ collectionCount: Array.isArray(collection) ? collection.length : collection ? 1 : 0,
821
+ customer_id: customer_id
822
+ });
823
+ startTime = Date.now();
824
+ _context7.prev = 3;
825
+ _context7.next = 6;
455
826
  return this.request.post("/product/query", {
456
827
  open_bundle: 1,
457
828
  exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
458
829
  force_ignore_cache_flag: 1,
459
- // 获取所有详细信息
460
- with: ['category', 'collection', 'resourceRelation',
461
- // 套餐
462
- 'bundleGroup.bundleItem',
463
- // 单规格
464
- 'optionGroup.optionItem',
465
- // 组合规格
466
- 'variantGroup.variantItem'],
830
+ with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem'],
467
831
  open_deposit: 1,
832
+ is_append_product_description: 1,
468
833
  with_count: ['bundleGroup', 'optionGroup'],
834
+ with_category_tree: 1,
469
835
  status: 'published',
470
836
  num: 500,
471
837
  skip: 1,
@@ -475,82 +841,291 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
475
841
  front_end_cache_id: cacheId,
476
842
  application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel
477
843
  }, {
478
- useCache: true
844
+ cache: undefined
479
845
  });
480
- case 4:
481
- productsData = _context6.sent;
482
- _context6.next = 7;
483
- return this.saveProductsToIndexDB((productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || []);
484
- case 7:
485
- _context6.next = 9;
486
- return this.core.effects.emit(ProductsHooks.onProductsLoaded, productsData.data.list);
846
+ case 6:
847
+ productsData = _context7.sent;
848
+ productList = (productsData === null || productsData === void 0 || (_productsData$data2 = productsData.data) === null || _productsData$data2 === void 0 ? void 0 : _productsData$data2.list) || [];
849
+ duration = Date.now() - startTime;
850
+ this.logInfo('fetchProductsByHttp: 请求成功', {
851
+ productCount: productList.length,
852
+ duration: "".concat(duration, "ms")
853
+ });
854
+ return _context7.abrupt("return", productList);
855
+ case 13:
856
+ _context7.prev = 13;
857
+ _context7.t0 = _context7["catch"](3);
858
+ _duration2 = Date.now() - startTime;
859
+ errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
860
+ console.error('[Products] fetchProductsByHttp 失败:', _context7.t0);
861
+ this.logError('fetchProductsByHttp: 请求失败', {
862
+ duration: "".concat(_duration2, "ms"),
863
+ error: errorMessage
864
+ });
865
+ return _context7.abrupt("return", []);
866
+ case 20:
867
+ case "end":
868
+ return _context7.stop();
869
+ }
870
+ }, _callee7, this, [[3, 13]]);
871
+ }));
872
+ function fetchProductsByHttp(_x12) {
873
+ return _fetchProductsByHttp.apply(this, arguments);
874
+ }
875
+ return fetchProductsByHttp;
876
+ }()
877
+ /**
878
+ * 加载完整商品列表通过接口(包含所有详细数据)
879
+ * 包含副作用:保存到 IndexDB + 触发 onProductsLoaded 事件
880
+ * @param params 查询参数
881
+ */
882
+ )
883
+ }, {
884
+ key: "loadProductsByServerHttp",
885
+ value: (function () {
886
+ var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
887
+ var productList;
888
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
889
+ while (1) switch (_context8.prev = _context8.next) {
890
+ case 0:
891
+ _context8.next = 2;
892
+ return this.fetchProductsByHttp(params);
893
+ case 2:
894
+ productList = _context8.sent;
895
+ if (!(productList.length > 0)) {
896
+ _context8.next = 8;
897
+ break;
898
+ }
899
+ _context8.next = 6;
900
+ return this.saveProductsToIndexDB(productList);
901
+ case 6:
902
+ _context8.next = 8;
903
+ return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
904
+ case 8:
905
+ return _context8.abrupt("return", productList);
487
906
  case 9:
488
- return _context6.abrupt("return", productsData.data.list);
489
- case 12:
490
- _context6.prev = 12;
491
- _context6.t0 = _context6["catch"](1);
492
- console.error('[Products] 加载商品数据失败:', _context6.t0);
493
- return _context6.abrupt("return", []);
494
- case 16:
495
907
  case "end":
496
- return _context6.stop();
908
+ return _context8.stop();
497
909
  }
498
- }, _callee6, this, [[1, 12]]);
910
+ }, _callee8, this);
499
911
  }));
500
- function loadProductsByServer(_x10) {
501
- return _loadProductsByServer.apply(this, arguments);
912
+ function loadProductsByServerHttp(_x13) {
913
+ return _loadProductsByServerHttp.apply(this, arguments);
502
914
  }
503
- return loadProductsByServer;
915
+ return loadProductsByServerHttp;
504
916
  }()
505
917
  /**
506
- * 获取商品列表(从缓存)
918
+ * 获取商品列表(深拷贝,供外部安全使用)
507
919
  */
508
920
  )
509
921
  }, {
510
922
  key: "getProducts",
511
923
  value: (function () {
512
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
513
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
514
- while (1) switch (_context7.prev = _context7.next) {
924
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
925
+ var t0, result;
926
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
927
+ while (1) switch (_context9.prev = _context9.next) {
515
928
  case 0:
516
- return _context7.abrupt("return", cloneDeep(this.store.list));
517
- case 1:
929
+ t0 = performance.now();
930
+ result = structuredClone(this.store.list);
931
+ perfMark('ProductsModule.getProducts(structuredClone)', performance.now() - t0, {
932
+ count: result.length
933
+ });
934
+ return _context9.abrupt("return", result);
935
+ case 4:
518
936
  case "end":
519
- return _context7.stop();
937
+ return _context9.stop();
520
938
  }
521
- }, _callee7, this);
939
+ }, _callee9, this);
522
940
  }));
523
941
  function getProducts() {
524
942
  return _getProducts.apply(this, arguments);
525
943
  }
526
944
  return getProducts;
527
945
  }()
946
+ /**
947
+ * 内部获取商品列表的直接引用(无拷贝)
948
+ * 仅供内部 formatter 流程使用,因为 formatter 会创建新对象
949
+ */
950
+ )
951
+ }, {
952
+ key: "getProductsRef",
953
+ value: function getProductsRef() {
954
+ return this.store.list;
955
+ }
956
+
528
957
  /**
529
958
  * 根据ID获取单个商品(从内存缓存)
530
959
  * 使用 Map 快速查询,时间复杂度 O(1)
531
960
  */
532
- )
533
961
  }, {
534
962
  key: "getProductById",
535
963
  value: (function () {
536
- var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(id) {
964
+ var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(id) {
537
965
  var product;
538
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
539
- while (1) switch (_context8.prev = _context8.next) {
966
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
967
+ while (1) switch (_context10.prev = _context10.next) {
540
968
  case 0:
541
969
  product = this.store.map.get(id);
542
- return _context8.abrupt("return", product ? cloneDeep(product) : undefined);
970
+ return _context10.abrupt("return", product ? structuredClone(product) : undefined);
543
971
  case 2:
544
972
  case "end":
545
- return _context8.stop();
973
+ return _context10.stop();
546
974
  }
547
- }, _callee8, this);
975
+ }, _callee10, this);
548
976
  }));
549
- function getProductById(_x11) {
977
+ function getProductById(_x14) {
550
978
  return _getProductById.apply(this, arguments);
551
979
  }
552
980
  return getProductById;
553
981
  }()
982
+ /**
983
+ * 根据 ID 列表删除商品(用于 pubsub 同步删除场景)
984
+ * 同时更新 store.list、store.map、IndexDB 和价格缓存
985
+ */
986
+ )
987
+ }, {
988
+ key: "removeProductsByIds",
989
+ value: (function () {
990
+ var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(ids) {
991
+ var idSet, _iterator3, _step3, _id, _iterator4, _step4, id, errorMessage, _iterator5, _step5, _step5$value, dateKey, cachedProducts;
992
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
993
+ while (1) switch (_context11.prev = _context11.next) {
994
+ case 0:
995
+ idSet = new Set(ids);
996
+ this.logInfo('removeProductsByIds', {
997
+ ids: ids,
998
+ count: ids.length
999
+ });
1000
+ this.store.list = this.store.list.filter(function (p) {
1001
+ return !idSet.has(p.id);
1002
+ });
1003
+ _iterator3 = _createForOfIteratorHelper(ids);
1004
+ try {
1005
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1006
+ _id = _step3.value;
1007
+ this.store.map.delete(_id);
1008
+ }
1009
+ } catch (err) {
1010
+ _iterator3.e(err);
1011
+ } finally {
1012
+ _iterator3.f();
1013
+ }
1014
+ if (!this.dbManager) {
1015
+ _context11.next = 30;
1016
+ break;
1017
+ }
1018
+ _context11.prev = 6;
1019
+ _iterator4 = _createForOfIteratorHelper(ids);
1020
+ _context11.prev = 8;
1021
+ _iterator4.s();
1022
+ case 10:
1023
+ if ((_step4 = _iterator4.n()).done) {
1024
+ _context11.next = 16;
1025
+ break;
1026
+ }
1027
+ id = _step4.value;
1028
+ _context11.next = 14;
1029
+ return this.dbManager.delete(INDEXDB_STORE_NAME, id);
1030
+ case 14:
1031
+ _context11.next = 10;
1032
+ break;
1033
+ case 16:
1034
+ _context11.next = 21;
1035
+ break;
1036
+ case 18:
1037
+ _context11.prev = 18;
1038
+ _context11.t0 = _context11["catch"](8);
1039
+ _iterator4.e(_context11.t0);
1040
+ case 21:
1041
+ _context11.prev = 21;
1042
+ _iterator4.f();
1043
+ return _context11.finish(21);
1044
+ case 24:
1045
+ _context11.next = 30;
1046
+ break;
1047
+ case 26:
1048
+ _context11.prev = 26;
1049
+ _context11.t1 = _context11["catch"](6);
1050
+ errorMessage = _context11.t1 instanceof Error ? _context11.t1.message : String(_context11.t1);
1051
+ this.logError('removeProductsByIds: IndexDB 删除失败', {
1052
+ ids: ids,
1053
+ error: errorMessage
1054
+ });
1055
+ case 30:
1056
+ _iterator5 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1057
+ try {
1058
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1059
+ _step5$value = _slicedToArray(_step5.value, 2), dateKey = _step5$value[0], cachedProducts = _step5$value[1];
1060
+ this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
1061
+ return !idSet.has(p.id);
1062
+ }));
1063
+ }
1064
+ } catch (err) {
1065
+ _iterator5.e(err);
1066
+ } finally {
1067
+ _iterator5.f();
1068
+ }
1069
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1070
+ this.logInfo('removeProductsByIds 完成', {
1071
+ remaining: this.store.list.length
1072
+ });
1073
+ case 34:
1074
+ case "end":
1075
+ return _context11.stop();
1076
+ }
1077
+ }, _callee11, this, [[6, 26], [8, 18, 21, 24]]);
1078
+ }));
1079
+ function removeProductsByIds(_x15) {
1080
+ return _removeProductsByIds.apply(this, arguments);
1081
+ }
1082
+ return removeProductsByIds;
1083
+ }()
1084
+ /**
1085
+ * 重新从服务器加载全量商品列表并更新本地 store
1086
+ * 用于 pubsub 同步 create / update / batch_update 场景
1087
+ */
1088
+ )
1089
+ }, {
1090
+ key: "refreshProducts",
1091
+ value: (function () {
1092
+ var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1093
+ var tTotal, products;
1094
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1095
+ while (1) switch (_context12.prev = _context12.next) {
1096
+ case 0:
1097
+ tTotal = performance.now();
1098
+ this.logInfo('refreshProducts 开始');
1099
+ _context12.next = 4;
1100
+ return this.loadProductsByServer();
1101
+ case 4:
1102
+ products = _context12.sent;
1103
+ if (products && products.length > 0) {
1104
+ // 服务器返回的数据已经是全新的,无需 cloneDeep
1105
+ this.store.list = products;
1106
+ this.syncProductsMap();
1107
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1108
+ this.logInfo('refreshProducts 完成', {
1109
+ productCount: products.length
1110
+ });
1111
+ } else {
1112
+ this.logWarning('refreshProducts: 服务器未返回数据');
1113
+ }
1114
+ perfMark('refreshProducts', performance.now() - tTotal, {
1115
+ count: this.store.list.length
1116
+ });
1117
+ return _context12.abrupt("return", this.store.list);
1118
+ case 8:
1119
+ case "end":
1120
+ return _context12.stop();
1121
+ }
1122
+ }, _callee12, this);
1123
+ }));
1124
+ function refreshProducts() {
1125
+ return _refreshProducts.apply(this, arguments);
1126
+ }
1127
+ return refreshProducts;
1128
+ }()
554
1129
  /**
555
1130
  * 清空缓存
556
1131
  */
@@ -558,36 +1133,47 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
558
1133
  }, {
559
1134
  key: "clear",
560
1135
  value: (function () {
561
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
562
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
563
- while (1) switch (_context9.prev = _context9.next) {
1136
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1137
+ var errorMessage;
1138
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1139
+ while (1) switch (_context13.prev = _context13.next) {
564
1140
  case 0:
1141
+ this.logInfo('开始清空缓存', {
1142
+ currentProductCount: this.store.list.length,
1143
+ priceCacheCount: this.productsPriceCache.size
1144
+ });
565
1145
  this.store.list = [];
566
1146
  this.store.map.clear();
567
1147
 
568
1148
  // 同时清空 IndexDB 中的所有数据(包括商品和元数据)
569
1149
  if (!this.dbManager) {
570
- _context9.next = 12;
1150
+ _context13.next = 16;
571
1151
  break;
572
1152
  }
573
- _context9.prev = 3;
574
- _context9.next = 6;
1153
+ _context13.prev = 4;
1154
+ _context13.next = 7;
575
1155
  return this.dbManager.clear(INDEXDB_STORE_NAME);
576
- case 6:
1156
+ case 7:
577
1157
  console.log('[Products] IndexDB 缓存已清空');
578
- _context9.next = 12;
1158
+ this.logInfo('IndexDB 缓存已清空');
1159
+ _context13.next = 16;
579
1160
  break;
580
- case 9:
581
- _context9.prev = 9;
582
- _context9.t0 = _context9["catch"](3);
583
- console.error('[Products] 清空 IndexDB 缓存失败:', _context9.t0);
584
- case 12:
1161
+ case 11:
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);
1166
+ this.logError('清空 IndexDB 缓存失败', {
1167
+ error: errorMessage
1168
+ });
1169
+ case 16:
585
1170
  console.log('[Products] 缓存已清空');
586
- case 13:
1171
+ this.logInfo('缓存清空完成');
1172
+ case 18:
587
1173
  case "end":
588
- return _context9.stop();
1174
+ return _context13.stop();
589
1175
  }
590
- }, _callee9, this, [[3, 9]]);
1176
+ }, _callee13, this, [[4, 11]]);
591
1177
  }));
592
1178
  function clear() {
593
1179
  return _clear.apply(this, arguments);
@@ -602,33 +1188,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
602
1188
  }, {
603
1189
  key: "loadProductsFromIndexDB",
604
1190
  value: (function () {
605
- var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
606
- var products;
607
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
608
- while (1) switch (_context10.prev = _context10.next) {
1191
+ var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1192
+ var _products$length, _products$length2, t0, products, errorMessage;
1193
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1194
+ while (1) switch (_context14.prev = _context14.next) {
609
1195
  case 0:
610
1196
  if (this.dbManager) {
611
- _context10.next = 2;
1197
+ _context14.next = 3;
612
1198
  break;
613
1199
  }
614
- return _context10.abrupt("return", []);
615
- case 2:
616
- _context10.prev = 2;
617
- _context10.next = 5;
1200
+ this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
1201
+ return _context14.abrupt("return", []);
1202
+ case 3:
1203
+ _context14.prev = 3;
1204
+ t0 = performance.now();
1205
+ _context14.next = 7;
618
1206
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
619
- case 5:
620
- products = _context10.sent;
621
- return _context10.abrupt("return", products || []);
622
- case 9:
623
- _context10.prev = 9;
624
- _context10.t0 = _context10["catch"](2);
625
- console.error('[Products] IndexDB 读取数据失败:', _context10.t0);
626
- return _context10.abrupt("return", []);
1207
+ case 7:
1208
+ products = _context14.sent;
1209
+ perfMark('loadProductsFromIndexDB', performance.now() - t0, {
1210
+ count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
1211
+ });
1212
+ this.logInfo('从 IndexDB 加载商品数据', {
1213
+ productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
1214
+ });
1215
+ return _context14.abrupt("return", products || []);
627
1216
  case 13:
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);
1221
+ this.logError('从 IndexDB 读取数据失败', {
1222
+ error: errorMessage
1223
+ });
1224
+ return _context14.abrupt("return", []);
1225
+ case 19:
628
1226
  case "end":
629
- return _context10.stop();
1227
+ return _context14.stop();
630
1228
  }
631
- }, _callee10, this, [[2, 9]]);
1229
+ }, _callee14, this, [[3, 13]]);
632
1230
  }));
633
1231
  function loadProductsFromIndexDB() {
634
1232
  return _loadProductsFromIndexDB.apply(this, arguments);
@@ -643,43 +1241,54 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
643
1241
  }, {
644
1242
  key: "saveProductsToIndexDB",
645
1243
  value: (function () {
646
- var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(products) {
647
- var _this2 = this;
648
- var savePromises;
649
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
650
- while (1) switch (_context11.prev = _context11.next) {
1244
+ var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(products) {
1245
+ var t0, errorMessage;
1246
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1247
+ while (1) switch (_context15.prev = _context15.next) {
651
1248
  case 0:
652
1249
  if (this.dbManager) {
653
- _context11.next = 2;
1250
+ _context15.next = 3;
654
1251
  break;
655
1252
  }
656
- return _context11.abrupt("return");
657
- case 2:
658
- _context11.prev = 2;
659
- _context11.next = 5;
660
- return this.dbManager.clear(INDEXDB_STORE_NAME);
661
- case 5:
662
- // 逐个保存商品(每个商品是独立的记录)
663
- savePromises = products.map(function (product) {
664
- return _this2.dbManager.add(INDEXDB_STORE_NAME, product);
1253
+ this.logWarning('saveProductsToIndexDB: dbManager 不可用');
1254
+ return _context15.abrupt("return");
1255
+ case 3:
1256
+ this.logInfo('开始保存商品数据到 IndexDB', {
1257
+ productCount: products.length
665
1258
  });
666
- _context11.next = 8;
667
- return Promise.all(savePromises);
1259
+ _context15.prev = 4;
1260
+ t0 = performance.now();
1261
+ _context15.next = 8;
1262
+ return this.dbManager.clear(INDEXDB_STORE_NAME);
668
1263
  case 8:
1264
+ _context15.next = 10;
1265
+ return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1266
+ case 10:
1267
+ perfMark('saveProductsToIndexDB', performance.now() - t0, {
1268
+ count: products.length
1269
+ });
669
1270
  console.log("[Products] \u5DF2\u5C06 ".concat(products.length, " \u4E2A\u5546\u54C1\u5E73\u94FA\u4FDD\u5B58\u5230 IndexDB"));
670
- _context11.next = 14;
1271
+ this.logInfo('商品数据已保存到 IndexDB', {
1272
+ productCount: products.length
1273
+ });
1274
+ _context15.next = 20;
671
1275
  break;
672
- case 11:
673
- _context11.prev = 11;
674
- _context11.t0 = _context11["catch"](2);
675
- console.error('[Products] 保存数据到 IndexDB 失败:', _context11.t0);
676
- case 14:
1276
+ case 15:
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);
1281
+ this.logError('保存数据到 IndexDB 失败', {
1282
+ productCount: products.length,
1283
+ error: errorMessage
1284
+ });
1285
+ case 20:
677
1286
  case "end":
678
- return _context11.stop();
1287
+ return _context15.stop();
679
1288
  }
680
- }, _callee11, this, [[2, 11]]);
1289
+ }, _callee15, this, [[4, 15]]);
681
1290
  }));
682
- function saveProductsToIndexDB(_x12) {
1291
+ function saveProductsToIndexDB(_x16) {
683
1292
  return _saveProductsToIndexDB.apply(this, arguments);
684
1293
  }
685
1294
  return saveProductsToIndexDB;
@@ -693,20 +1302,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
693
1302
  }, {
694
1303
  key: "syncProductsMap",
695
1304
  value: function syncProductsMap() {
1305
+ var t0 = performance.now();
696
1306
  this.store.map.clear();
697
- var _iterator = _createForOfIteratorHelper(this.store.list),
698
- _step;
1307
+ var _iterator6 = _createForOfIteratorHelper(this.store.list),
1308
+ _step6;
699
1309
  try {
700
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
701
- var product = _step.value;
1310
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1311
+ var product = _step6.value;
702
1312
  this.store.map.set(product.id, product);
703
1313
  }
704
1314
  } catch (err) {
705
- _iterator.e(err);
1315
+ _iterator6.e(err);
706
1316
  } finally {
707
- _iterator.f();
1317
+ _iterator6.f();
708
1318
  }
709
- console.log("[Products] Map \u7F13\u5B58\u5DF2\u540C\u6B65\uFF0C\u5171 ".concat(this.store.map.size, " \u4E2A\u5546\u54C1"));
1319
+ perfMark('syncProductsMap', performance.now() - t0, {
1320
+ count: this.store.map.size
1321
+ });
710
1322
  }
711
1323
 
712
1324
  /**
@@ -716,68 +1328,666 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
716
1328
  }, {
717
1329
  key: "preload",
718
1330
  value: (function () {
719
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
720
- var cachedData, products;
721
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
722
- while (1) switch (_context12.prev = _context12.next) {
1331
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1332
+ var _products$length3;
1333
+ var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
1334
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1335
+ while (1) switch (_context16.prev = _context16.next) {
723
1336
  case 0:
724
1337
  console.log('[Products] 开始预加载数据...');
725
- _context12.prev = 1;
726
- _context12.next = 4;
1338
+ tTotal = performance.now();
1339
+ this.logInfo('开始预加载数据');
1340
+ _context16.prev = 3;
1341
+ tIndexDB = performance.now();
1342
+ _context16.next = 7;
727
1343
  return this.loadProductsFromIndexDB();
728
- case 4:
729
- cachedData = _context12.sent;
1344
+ case 7:
1345
+ cachedData = _context16.sent;
1346
+ perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1347
+ count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
1348
+ });
730
1349
  if (!(cachedData && cachedData.length > 0)) {
731
- _context12.next = 11;
1350
+ _context16.next = 19;
732
1351
  break;
733
1352
  }
734
1353
  console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
735
- // 将缓存数据放入 list
736
- this.store.list = cloneDeep(cachedData);
737
- // 同步更新 Map 缓存
1354
+ // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
1355
+ this.store.list = cachedData;
1356
+ tSync = performance.now();
738
1357
  this.syncProductsMap();
1358
+ perfMark('preload.syncProductsMap', performance.now() - tSync, {
1359
+ count: cachedData.length
1360
+ });
739
1361
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
740
- return _context12.abrupt("return");
741
- case 11:
1362
+ perfMark('preload(IndexDB)', performance.now() - tTotal, {
1363
+ count: cachedData.length,
1364
+ source: 'IndexDB'
1365
+ });
1366
+ this.logInfo('预加载完成(从 IndexDB)', {
1367
+ productCount: cachedData.length,
1368
+ duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1369
+ source: 'IndexDB'
1370
+ });
1371
+ return _context16.abrupt("return");
1372
+ case 19:
742
1373
  console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
743
- _context12.next = 17;
1374
+ this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
1375
+ _context16.next = 28;
744
1376
  break;
1377
+ case 23:
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);
1382
+ this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
1383
+ error: errorMessage
1384
+ });
1385
+ case 28:
1386
+ tServer = performance.now();
1387
+ _context16.next = 31;
1388
+ return this.loadProductsByServer();
1389
+ case 31:
1390
+ products = _context16.sent;
1391
+ perfMark('preload.loadFromServer', performance.now() - tServer, {
1392
+ count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
1393
+ });
1394
+ if (products && products.length > 0) {
1395
+ // 服务器返回的数据已经是全新的,无需 cloneDeep
1396
+ this.store.list = products;
1397
+ _tSync = performance.now();
1398
+ this.syncProductsMap();
1399
+ perfMark('preload.syncProductsMap', performance.now() - _tSync, {
1400
+ count: products.length
1401
+ });
1402
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1403
+ perfMark('preload(Server)', performance.now() - tTotal, {
1404
+ count: products.length,
1405
+ source: 'Server'
1406
+ });
1407
+ this.logInfo('预加载完成(从服务器)', {
1408
+ productCount: products.length,
1409
+ duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1410
+ source: 'Server'
1411
+ });
1412
+ } else {
1413
+ perfMark('preload(empty)', performance.now() - tTotal, {
1414
+ source: 'empty'
1415
+ });
1416
+ this.logWarning('预加载完成但未获取到数据', {
1417
+ duration: "".concat(Math.round(performance.now() - tTotal), "ms")
1418
+ });
1419
+ }
1420
+ case 34:
1421
+ case "end":
1422
+ return _context16.stop();
1423
+ }
1424
+ }, _callee16, this, [[3, 23]]);
1425
+ }));
1426
+ function preload() {
1427
+ return _preload.apply(this, arguments);
1428
+ }
1429
+ return preload;
1430
+ }() // =============================================
1431
+ // 商品数据同步(pubsub)
1432
+ // =============================================
1433
+ /**
1434
+ * 初始化 ProductDataSource 实例
1435
+ * 与 pubsub 订阅和数据获取分开,仅负责创建实例
1436
+ */
1437
+ )
1438
+ }, {
1439
+ key: "initProductDataSource",
1440
+ value: function initProductDataSource() {
1441
+ var _serverOptions;
1442
+ var ProductDataSourceClass = (_serverOptions = this.core.serverOptions) === null || _serverOptions === void 0 || (_serverOptions = _serverOptions.All_DATA_SOURCES) === null || _serverOptions === void 0 ? void 0 : _serverOptions.ProductDataSource;
1443
+ if (!ProductDataSourceClass) {
1444
+ this.logWarning('initProductDataSource: ProductDataSource 不可用');
1445
+ return;
1446
+ }
1447
+ this.productDataSource = new ProductDataSourceClass();
1448
+ this.logInfo('ProductDataSource 实例已创建');
1449
+ }
1450
+
1451
+ /**
1452
+ * 初始化 pubsub 订阅,监听管理后台商品变更
1453
+ * 仅负责订阅 product / product_quotation 频道,消息通过防抖合并后批量处理
1454
+ * 数据获取由 loadProductsByServer 单独负责
1455
+ */
1456
+ }, {
1457
+ key: "setupProductSync",
1458
+ value: function setupProductSync() {
1459
+ var _this2 = this;
1460
+ if (!this.productDataSource) {
1461
+ this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
1462
+ return;
1463
+ }
1464
+ var createHandler = function createHandler(channelKey) {
1465
+ return function (message) {
1466
+ var data = (message === null || message === void 0 ? void 0 : message.data) || message;
1467
+ if (!data) return;
1468
+ console.log("[ProductsModule] \u6536\u5230\u540C\u6B65\u6D88\u606F [".concat(channelKey, "]:"), data);
1469
+ _this2.logInfo('收到同步消息', {
1470
+ channelKey: channelKey,
1471
+ action: data.action,
1472
+ id: data.id,
1473
+ action_filed: data.action_filed
1474
+ });
1475
+ _this2.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
1476
+ _channelKey: channelKey
1477
+ }));
1478
+ if (_this2.syncTimer) {
1479
+ clearTimeout(_this2.syncTimer);
1480
+ }
1481
+ _this2.syncTimer = setTimeout(function () {
1482
+ _this2.processProductSyncMessages();
1483
+ }, PRODUCT_SYNC_DEBOUNCE_MS);
1484
+ };
1485
+ };
1486
+ this.productDataSource.run({
1487
+ pubsub: {
1488
+ callback: function callback(res) {
1489
+ console.log('sse_products_callback', res);
1490
+ _this2.logInfo('sse_products_callback: 收到同步消息', {
1491
+ data: res === null || res === void 0 ? void 0 : res.data
1492
+ });
1493
+ if (!(res !== null && res !== void 0 && res.data)) return;
1494
+ var data = res.data;
1495
+ var channelKey = data.module || 'product';
1496
+ createHandler(channelKey)(data);
1497
+ }
1498
+ }
1499
+ }).catch(function (err) {
1500
+ _this2.logError('setupProductSync: DataSource run 出错', {
1501
+ error: err instanceof Error ? err.message : String(err)
1502
+ });
1503
+ });
1504
+ this.logInfo('setupProductSync: pubsub 订阅已建立');
1505
+ }
1506
+
1507
+ /**
1508
+ * 处理防抖后的同步消息批次
1509
+ *
1510
+ * product 模块:
1511
+ * - operation === 'delete' → 本地删除
1512
+ * - change_types 包含 price → 仅收集变更 IDs(不拉商品数据)
1513
+ * - 有 body → body 完整数据直接覆盖本地
1514
+ * - 其他 → SSE 增量拉取
1515
+ *
1516
+ * product_collection / product_category:
1517
+ * - 按 relation_product_ids SSE 拉取受影响商品
1518
+ *
1519
+ * product_quotation:
1520
+ * - 报价单变更影响范围大,直接清除价格缓存走全量重建
1521
+ *
1522
+ * 处理完成后 emit onProductsSyncCompleted(携带 changedIds),
1523
+ * Server 层监听该事件后对变更商品增量执行 prepareProductsWithPrice 并更新缓存
1524
+ */
1525
+ }, {
1526
+ key: "processProductSyncMessages",
1527
+ value: (function () {
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, _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) {
1532
+ case 0:
1533
+ messages = _toConsumableArray(this.pendingSyncMessages);
1534
+ this.pendingSyncMessages = [];
1535
+ if (!(messages.length === 0)) {
1536
+ _context17.next = 4;
1537
+ break;
1538
+ }
1539
+ return _context17.abrupt("return");
1540
+ case 4:
1541
+ this.logInfo('processProductSyncMessages: 开始处理', {
1542
+ count: messages.length
1543
+ });
1544
+ deleteIds = [];
1545
+ bodyUpdates = new Map();
1546
+ sseRefreshIds = [];
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 = 36;
1555
+ break;
1556
+ }
1557
+ msg = _step7.value;
1558
+ channelKey = msg._channelKey || msg.module || 'product';
1559
+ if (!(channelKey === 'product')) {
1560
+ _context17.next = 33;
1561
+ break;
1562
+ }
1563
+ if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
1564
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1565
+ }
1566
+ // 1. 删除场景:operation === 'delete' 或 action === 'delete'
1567
+ if (!(msg.operation === 'delete' || msg.action === 'delete')) {
1568
+ _context17.next = 21;
1569
+ break;
1570
+ }
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);
1572
+ return _context17.abrupt("continue", 34);
1573
+ case 21:
1574
+ if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
1575
+ _context17.next = 26;
1576
+ break;
1577
+ }
1578
+ ids = msg.ids || (msg.id ? [msg.id] : []);
1579
+ priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(ids));
1580
+ if (msg.body) {
1581
+ bodyId = msg.body.id;
1582
+ if (bodyId) bodyUpdates.set(bodyId, msg.body);
1583
+ }
1584
+ return _context17.abrupt("continue", 34);
1585
+ case 26:
1586
+ if (!msg.body) {
1587
+ _context17.next = 30;
1588
+ break;
1589
+ }
1590
+ _bodyId = msg.body.id || msg.id;
1591
+ if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
1592
+ return _context17.abrupt("continue", 34);
1593
+ case 30:
1594
+ // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1595
+ if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
1596
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
1597
+ } else if (msg.id) {
1598
+ sseRefreshIds.push(msg.id);
1599
+ }
1600
+ _context17.next = 34;
1601
+ break;
1602
+ case 33:
1603
+ if (channelKey === 'product_quotation') {
1604
+ // 报价单变更影响范围大,标记清除全量价格缓存
1605
+ shouldClearPriceCache = true;
1606
+ if ((_msg$relation_product2 = msg.relation_product_ids) !== null && _msg$relation_product2 !== void 0 && _msg$relation_product2.length) {
1607
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1608
+ }
1609
+ } else if (['product_collection', 'product_category'].includes(channelKey)) {
1610
+ if ((_msg$relation_product3 = msg.relation_product_ids) !== null && _msg$relation_product3 !== void 0 && _msg$relation_product3.length) {
1611
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1612
+ }
1613
+ }
1614
+ case 34:
1615
+ _context17.next = 13;
1616
+ break;
1617
+ case 36:
1618
+ _context17.next = 41;
1619
+ break;
1620
+ case 38:
1621
+ _context17.prev = 38;
1622
+ _context17.t0 = _context17["catch"](11);
1623
+ _iterator7.e(_context17.t0);
1624
+ case 41:
1625
+ _context17.prev = 41;
1626
+ _iterator7.f();
1627
+ return _context17.finish(41);
1628
+ case 44:
1629
+ uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
1630
+ uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
1631
+ uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
1632
+ if (!(uniqueDeleteIds.length > 0)) {
1633
+ _context17.next = 50;
1634
+ break;
1635
+ }
1636
+ _context17.next = 50;
1637
+ return this.removeProductsByIds(uniqueDeleteIds);
1638
+ case 50:
1639
+ if (!(bodyUpdates.size > 0)) {
1640
+ _context17.next = 53;
1641
+ break;
1642
+ }
1643
+ _context17.next = 53;
1644
+ return this.applyBodyUpdatesToStore(bodyUpdates);
1645
+ case 53:
1646
+ if (!(uniqueSSEIds.length > 0)) {
1647
+ _context17.next = 61;
1648
+ break;
1649
+ }
1650
+ _context17.next = 56;
1651
+ return this.fetchProductsBySSE(uniqueSSEIds);
1652
+ case 56:
1653
+ freshProducts = _context17.sent;
1654
+ if (!(freshProducts.length > 0)) {
1655
+ _context17.next = 60;
1656
+ break;
1657
+ }
1658
+ _context17.next = 60;
1659
+ return this.mergeProductsToStore(freshProducts);
1660
+ case 60:
1661
+ this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
1662
+ requestedCount: uniqueSSEIds.length,
1663
+ receivedCount: freshProducts.length
1664
+ });
1665
+ case 61:
1666
+ // 收集所有非 delete 的变更 IDs(body + SSE + price),用于增量更新价格缓存
1667
+ allChangedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(Array.from(bodyUpdates.keys())), _toConsumableArray(uniqueSSEIds), _toConsumableArray(uniquePriceIds))));
1668
+ this.logInfo('processProductSyncMessages: 处理完成123', {
1669
+ deleteCount: uniqueDeleteIds.length,
1670
+ bodyUpdateCount: bodyUpdates.size,
1671
+ sseRefreshCount: uniqueSSEIds.length,
1672
+ priceRefreshCount: uniquePriceIds.length,
1673
+ allChangedIdsCount: allChangedIds.length,
1674
+ shouldClearPriceCache: shouldClearPriceCache
1675
+ });
1676
+ hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
1677
+ if (hasChanges) {
1678
+ _context17.next = 67;
1679
+ break;
1680
+ }
1681
+ this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
1682
+ return _context17.abrupt("return");
1683
+ case 67:
1684
+ // 报价单变更 → 清除全量价格缓存,后续走全量重建
1685
+ if (shouldClearPriceCache) {
1686
+ this.clearPriceCache();
1687
+ }
1688
+ _context17.next = 70;
1689
+ return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
1690
+ changedIds: allChangedIds
1691
+ });
1692
+ case 70:
1693
+ case "end":
1694
+ return _context17.stop();
1695
+ }
1696
+ }, _callee17, this, [[11, 38, 41, 44]]);
1697
+ }));
1698
+ function processProductSyncMessages() {
1699
+ return _processProductSyncMessages.apply(this, arguments);
1700
+ }
1701
+ return processProductSyncMessages;
1702
+ }()
1703
+ /**
1704
+ * 通过 SSE 按 ids 增量拉取商品数据
1705
+ * 请求 GET /shop/core/stream?type=product&ids={ids}
1706
+ */
1707
+ )
1708
+ }, {
1709
+ key: "fetchProductsBySSE",
1710
+ value: (function () {
1711
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
1712
+ var t0, productList, list, errorMessage;
1713
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1714
+ while (1) switch (_context18.prev = _context18.next) {
1715
+ case 0:
1716
+ if (this.productDataSource) {
1717
+ _context18.next = 3;
1718
+ break;
1719
+ }
1720
+ this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
1721
+ return _context18.abrupt("return", []);
1722
+ case 3:
1723
+ this.logInfo('fetchProductsBySSE: 开始', {
1724
+ ids: ids,
1725
+ count: ids.length
1726
+ });
1727
+ t0 = performance.now();
1728
+ _context18.prev = 5;
1729
+ _context18.next = 8;
1730
+ return this.productDataSource.run({
1731
+ sse: {
1732
+ query: {
1733
+ type: 'product',
1734
+ ids: ids
1735
+ }
1736
+ }
1737
+ });
1738
+ case 8:
1739
+ productList = _context18.sent;
1740
+ list = productList || [];
1741
+ perfMark('fetchProductsBySSE', performance.now() - t0, {
1742
+ count: list.length
1743
+ });
1744
+ this.logInfo('fetchProductsBySSE: 成功', {
1745
+ requestedCount: ids.length,
1746
+ receivedCount: list.length,
1747
+ duration: "".concat(Math.round(performance.now() - t0), "ms")
1748
+ });
1749
+ return _context18.abrupt("return", list);
1750
+ case 15:
1751
+ _context18.prev = 15;
1752
+ _context18.t0 = _context18["catch"](5);
1753
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1754
+ this.logError('fetchProductsBySSE: 失败', {
1755
+ ids: ids,
1756
+ error: errorMessage
1757
+ });
1758
+ return _context18.abrupt("return", []);
1759
+ case 20:
1760
+ case "end":
1761
+ return _context18.stop();
1762
+ }
1763
+ }, _callee18, this, [[5, 15]]);
1764
+ }));
1765
+ function fetchProductsBySSE(_x17) {
1766
+ return _fetchProductsBySSE.apply(this, arguments);
1767
+ }
1768
+ return fetchProductsBySSE;
1769
+ }()
1770
+ /**
1771
+ * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
1772
+ * 已存在的 → 直接替换;不存在的 → 追加
1773
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
1774
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
1775
+ */
1776
+ )
1777
+ }, {
1778
+ key: "applyBodyUpdatesToStore",
1779
+ value: (function () {
1780
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(bodyUpdates) {
1781
+ var updatedCount, newCount, appliedIds, _iterator8, _step8, _step8$value, id, body;
1782
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1783
+ while (1) switch (_context19.prev = _context19.next) {
1784
+ case 0:
1785
+ this.logInfo('applyBodyUpdatesToStore: 开始', {
1786
+ count: bodyUpdates.size
1787
+ });
1788
+ updatedCount = 0;
1789
+ newCount = 0;
1790
+ appliedIds = new Set();
1791
+ this.store.list = this.store.list.map(function (p) {
1792
+ if (bodyUpdates.has(p.id)) {
1793
+ updatedCount++;
1794
+ appliedIds.add(p.id);
1795
+ return bodyUpdates.get(p.id);
1796
+ }
1797
+ return p;
1798
+ });
1799
+ _iterator8 = _createForOfIteratorHelper(bodyUpdates);
1800
+ try {
1801
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1802
+ _step8$value = _slicedToArray(_step8.value, 2), id = _step8$value[0], body = _step8$value[1];
1803
+ if (!appliedIds.has(id)) {
1804
+ this.store.list.push(body);
1805
+ newCount++;
1806
+ }
1807
+ }
1808
+ } catch (err) {
1809
+ _iterator8.e(err);
1810
+ } finally {
1811
+ _iterator8.f();
1812
+ }
1813
+ this.syncProductsMap();
1814
+ _context19.next = 10;
1815
+ return this.saveProductsToIndexDB(this.store.list);
1816
+ case 10:
1817
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1818
+ this.logInfo('applyBodyUpdatesToStore: 完成', {
1819
+ updatedCount: updatedCount,
1820
+ newCount: newCount,
1821
+ totalCount: this.store.list.length
1822
+ });
1823
+ case 12:
1824
+ case "end":
1825
+ return _context19.stop();
1826
+ }
1827
+ }, _callee19, this);
1828
+ }));
1829
+ function applyBodyUpdatesToStore(_x18) {
1830
+ return _applyBodyUpdatesToStore.apply(this, arguments);
1831
+ }
1832
+ return applyBodyUpdatesToStore;
1833
+ }()
1834
+ /**
1835
+ * 将增量拉取的商品合并到 store
1836
+ * 已存在的 → 替换;新的 → 追加
1837
+ * 同时更新 store.map、IndexDB,触发 onProductsChanged
1838
+ */
1839
+ )
1840
+ }, {
1841
+ key: "mergeProductsToStore",
1842
+ value: (function () {
1843
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshProducts) {
1844
+ var freshMap, _iterator9, _step9, p, updatedList, newCount, _iterator10, _step10, _p2, updatedCount;
1845
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1846
+ while (1) switch (_context20.prev = _context20.next) {
1847
+ case 0:
1848
+ freshMap = new Map();
1849
+ _iterator9 = _createForOfIteratorHelper(freshProducts);
1850
+ try {
1851
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1852
+ p = _step9.value;
1853
+ freshMap.set(p.id, p);
1854
+ }
1855
+ } catch (err) {
1856
+ _iterator9.e(err);
1857
+ } finally {
1858
+ _iterator9.f();
1859
+ }
1860
+ updatedList = this.store.list.map(function (p) {
1861
+ if (freshMap.has(p.id)) {
1862
+ var fresh = freshMap.get(p.id);
1863
+ freshMap.delete(p.id);
1864
+ return fresh;
1865
+ }
1866
+ return p;
1867
+ }); // freshMap 中剩余的是新商品(create 场景)
1868
+ newCount = freshMap.size;
1869
+ _iterator10 = _createForOfIteratorHelper(freshMap.values());
1870
+ try {
1871
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1872
+ _p2 = _step10.value;
1873
+ updatedList.push(_p2);
1874
+ }
1875
+ } catch (err) {
1876
+ _iterator10.e(err);
1877
+ } finally {
1878
+ _iterator10.f();
1879
+ }
1880
+ updatedCount = freshProducts.length - newCount;
1881
+ this.store.list = updatedList;
1882
+ this.syncProductsMap();
1883
+ _context20.next = 12;
1884
+ return this.saveProductsToIndexDB(this.store.list);
1885
+ case 12:
1886
+ this.logInfo('mergeProductsToStore: 合并完成', {
1887
+ updatedCount: updatedCount,
1888
+ newCount: newCount,
1889
+ totalCount: this.store.list.length
1890
+ });
1891
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
745
1892
  case 14:
746
- _context12.prev = 14;
747
- _context12.t0 = _context12["catch"](1);
748
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context12.t0);
749
- case 17:
750
- _context12.next = 19;
1893
+ case "end":
1894
+ return _context20.stop();
1895
+ }
1896
+ }, _callee20, this);
1897
+ }));
1898
+ function mergeProductsToStore(_x19) {
1899
+ return _mergeProductsToStore.apply(this, arguments);
1900
+ }
1901
+ return mergeProductsToStore;
1902
+ }()
1903
+ /**
1904
+ * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
1905
+ * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
1906
+ * @returns 刷新后的商品列表
1907
+ */
1908
+ )
1909
+ }, {
1910
+ key: "silentRefresh",
1911
+ value: (function () {
1912
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1913
+ var t0, products, errorMessage;
1914
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1915
+ while (1) switch (_context21.prev = _context21.next) {
1916
+ case 0:
1917
+ t0 = performance.now();
1918
+ this.logInfo('silentRefresh 开始');
1919
+ _context21.prev = 2;
1920
+ _context21.next = 5;
751
1921
  return this.loadProductsByServer();
752
- case 19:
753
- products = _context12.sent;
1922
+ case 5:
1923
+ products = _context21.sent;
754
1924
  if (!(products && products.length > 0)) {
755
- _context12.next = 26;
1925
+ _context21.next = 16;
756
1926
  break;
757
1927
  }
758
- _context12.next = 23;
759
- return this.saveProductsToIndexDB(products);
760
- case 23:
761
- this.store.list = cloneDeep(products);
762
- // 同步更新 Map 缓存
1928
+ this.store.list = products;
763
1929
  this.syncProductsMap();
1930
+ this.clearPriceCache();
764
1931
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1932
+ _context21.next = 13;
1933
+ return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1934
+ case 13:
1935
+ this.logInfo('silentRefresh 完成', {
1936
+ productCount: products.length,
1937
+ duration: "".concat(Math.round(performance.now() - t0), "ms")
1938
+ });
1939
+ _context21.next = 17;
1940
+ break;
1941
+ case 16:
1942
+ this.logWarning('silentRefresh: 服务器未返回数据');
1943
+ case 17:
1944
+ perfMark('silentRefresh', performance.now() - t0, {
1945
+ count: this.store.list.length
1946
+ });
1947
+ return _context21.abrupt("return", this.store.list);
1948
+ case 21:
1949
+ _context21.prev = 21;
1950
+ _context21.t0 = _context21["catch"](2);
1951
+ errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
1952
+ this.logError('silentRefresh 失败', {
1953
+ duration: "".concat(Math.round(performance.now() - t0), "ms"),
1954
+ error: errorMessage
1955
+ });
1956
+ return _context21.abrupt("return", this.store.list);
765
1957
  case 26:
766
1958
  case "end":
767
- return _context12.stop();
1959
+ return _context21.stop();
768
1960
  }
769
- }, _callee12, this, [[1, 14]]);
1961
+ }, _callee21, this, [[2, 21]]);
770
1962
  }));
771
- function preload() {
772
- return _preload.apply(this, arguments);
1963
+ function silentRefresh() {
1964
+ return _silentRefresh.apply(this, arguments);
773
1965
  }
774
- return preload;
1966
+ return silentRefresh;
775
1967
  }()
1968
+ /**
1969
+ * 销毁同步资源(取消 pubsub 订阅、清除定时器)
1970
+ */
1971
+ )
1972
+ }, {
1973
+ key: "destroyProductSync",
1974
+ value: function destroyProductSync() {
1975
+ var _this$productDataSour;
1976
+ if (this.syncTimer) {
1977
+ clearTimeout(this.syncTimer);
1978
+ this.syncTimer = undefined;
1979
+ }
1980
+ if ((_this$productDataSour = this.productDataSource) !== null && _this$productDataSour !== void 0 && _this$productDataSour.destroy) {
1981
+ this.productDataSource.destroy();
1982
+ }
1983
+ this.pendingSyncMessages = [];
1984
+ this.logInfo('destroyProductSync: 同步资源已销毁');
1985
+ }
1986
+
776
1987
  /**
777
1988
  * 获取模块的路由定义
778
1989
  * Products 模块暂不提供路由,由 Server 层统一处理
779
1990
  */
780
- )
781
1991
  }, {
782
1992
  key: "getRoutes",
783
1993
  value: function getRoutes() {