@pisell/pisellos 2.2.315 → 2.2.316
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.
- package/dist/model/strategy/adapter/promotion/evaluator.js +89 -104
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +28 -4
- package/dist/modules/Holder/utils.d.ts +2 -0
- package/dist/modules/Holder/utils.js +32 -2
- package/dist/modules/OpenData/contactInfo.d.ts +20 -0
- package/dist/modules/OpenData/contactInfo.js +70 -0
- package/dist/modules/OpenData/index.d.ts +1 -0
- package/dist/modules/OpenData/index.js +1 -0
- package/dist/modules/OpenData/types.d.ts +9 -0
- package/dist/modules/Order/holderRelations.d.ts +14 -0
- package/dist/modules/Order/holderRelations.js +154 -0
- package/dist/modules/Order/index.d.ts +2 -2
- package/dist/modules/Order/index.js +89 -44
- package/dist/modules/Order/types.d.ts +19 -1
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
- package/dist/modules/Order/utils/discountProductLineIdentity.js +142 -7
- package/dist/modules/Order/utils/orderCollectionIdentity.js +24 -10
- package/dist/modules/Order/utils.d.ts +2 -1
- package/dist/modules/Order/utils.js +36 -10
- package/dist/modules/Rules/index.js +62 -61
- package/dist/server/index.js +36 -28
- package/dist/server/modules/order/index.d.ts +4 -0
- package/dist/server/modules/order/index.js +255 -190
- package/dist/server/modules/order/types.d.ts +3 -0
- package/dist/server/modules/products/index.d.ts +28 -7
- package/dist/server/modules/products/index.js +1297 -770
- package/dist/server/modules/products/replication.d.ts +8 -0
- package/dist/server/modules/products/replication.js +69 -0
- package/dist/server/modules/products/types.d.ts +12 -1
- package/dist/server/modules/products/types.js +4 -0
- package/dist/shared/receipt/small-ticket.js +24 -12
- package/dist/shared/receipt/templateVisibility.d.ts +3 -0
- package/dist/shared/receipt/templateVisibility.js +6 -2
- package/dist/shared/sales/loadSalesOrderSnapshot.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +4 -0
- package/dist/solution/BaseSales/index.js +1116 -935
- package/dist/solution/BaseSales/types.d.ts +2 -1
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +7 -3
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -4
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +15 -1
- package/dist/solution/BookingTicket/index.js +784 -501
- package/dist/solution/ScanOrder/index.js +65 -31
- package/dist/solution/ScanOrder/types.d.ts +3 -0
- package/dist/solution/UnifiedBookingSales/index.js +1 -1
- package/lib/model/strategy/adapter/promotion/evaluator.js +9 -14
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +17 -1
- package/lib/modules/Holder/utils.d.ts +2 -0
- package/lib/modules/Holder/utils.js +27 -1
- package/lib/modules/OpenData/contactInfo.d.ts +20 -0
- package/lib/modules/OpenData/contactInfo.js +56 -0
- package/lib/modules/OpenData/index.d.ts +1 -0
- package/lib/modules/OpenData/index.js +12 -0
- package/lib/modules/OpenData/types.d.ts +9 -0
- package/lib/modules/Order/holderRelations.d.ts +14 -0
- package/lib/modules/Order/holderRelations.js +98 -0
- package/lib/modules/Order/index.d.ts +2 -2
- package/lib/modules/Order/index.js +44 -12
- package/lib/modules/Order/types.d.ts +19 -1
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
- package/lib/modules/Order/utils/discountProductLineIdentity.js +51 -2
- package/lib/modules/Order/utils/orderCollectionIdentity.js +5 -0
- package/lib/modules/Order/utils.d.ts +2 -1
- package/lib/modules/Order/utils.js +28 -6
- package/lib/modules/Rules/index.js +2 -1
- package/lib/server/index.js +8 -2
- package/lib/server/modules/order/index.d.ts +4 -0
- package/lib/server/modules/order/index.js +46 -4
- package/lib/server/modules/order/types.d.ts +3 -0
- package/lib/server/modules/products/index.d.ts +28 -7
- package/lib/server/modules/products/index.js +226 -63
- package/lib/server/modules/products/replication.d.ts +8 -0
- package/lib/server/modules/products/replication.js +30 -0
- package/lib/server/modules/products/types.d.ts +12 -1
- package/lib/server/modules/products/types.js +3 -0
- package/lib/shared/receipt/small-ticket.js +22 -13
- package/lib/shared/receipt/templateVisibility.d.ts +3 -0
- package/lib/shared/receipt/templateVisibility.js +6 -2
- package/lib/shared/sales/loadSalesOrderSnapshot.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +4 -0
- package/lib/solution/BaseSales/index.js +68 -2
- package/lib/solution/BaseSales/types.d.ts +2 -1
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -8
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +15 -1
- package/lib/solution/BookingTicket/index.js +132 -3
- package/lib/solution/ScanOrder/index.js +59 -20
- package/lib/solution/ScanOrder/types.d.ts +3 -0
- package/lib/solution/UnifiedBookingSales/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
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 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; }
|
|
3
|
+
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; }
|
|
1
4
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
5
|
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."); }
|
|
3
6
|
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; } }
|
|
4
7
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
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; } } }; }
|
|
5
9
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
10
|
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."); }
|
|
11
|
+
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); }
|
|
7
12
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
13
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
|
-
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); }
|
|
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; }
|
|
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; } } }; }
|
|
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); }
|
|
14
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; }
|
|
15
15
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
16
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
@@ -18,6 +18,8 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
18
18
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
19
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
20
20
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
22
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
21
23
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
22
24
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
23
25
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
@@ -29,9 +31,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
29
31
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
30
32
|
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); }
|
|
31
33
|
import { BaseModule } from "../../../modules/BaseModule";
|
|
34
|
+
import { resolveProductHolderConfig } from "../../../modules/Holder/utils";
|
|
32
35
|
import { QuotationModule as ClientQuotationModule } from "../../../modules/Quotation";
|
|
33
36
|
import { ProductsHooks } from "./types";
|
|
34
37
|
import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
|
|
38
|
+
import { CommittedProductState } from "./replication";
|
|
35
39
|
/**
|
|
36
40
|
* IndexDB 存储名称
|
|
37
41
|
*/
|
|
@@ -94,16 +98,376 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
94
98
|
_defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
|
|
95
99
|
/** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
|
|
96
100
|
_defineProperty(_assertThisInitialized(_this), "lastScheduleTimePoints", []);
|
|
101
|
+
_defineProperty(_assertThisInitialized(_this), "committedProductState", void 0);
|
|
102
|
+
_defineProperty(_assertThisInitialized(_this), "productReplicationSourceGeneration", 0);
|
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "productPersistenceFailed", false);
|
|
104
|
+
_defineProperty(_assertThisInitialized(_this), "runtimeSyncMode", 'normal');
|
|
105
|
+
_defineProperty(_assertThisInitialized(_this), "runtimeSyncGeneration", 0);
|
|
106
|
+
_defineProperty(_assertThisInitialized(_this), "requestReplicaRefresh", void 0);
|
|
107
|
+
_defineProperty(_assertThisInitialized(_this), "replicaApplyQueue", Promise.resolve());
|
|
108
|
+
_defineProperty(_assertThisInitialized(_this), "productSyncQueue", Promise.resolve());
|
|
109
|
+
_defineProperty(_assertThisInitialized(_this), "replicaPriceDirtyIds", new Map());
|
|
97
110
|
return _this;
|
|
98
111
|
}
|
|
99
112
|
_createClass(ProductsModule, [{
|
|
113
|
+
key: "setRuntimeSyncMode",
|
|
114
|
+
value: ( /** Installed after initial preload; initial cache/network loading stays unchanged. */function () {
|
|
115
|
+
var _setRuntimeSyncMode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(mode, requestRefresh) {
|
|
116
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
117
|
+
while (1) switch (_context.prev = _context.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
this.runtimeSyncGeneration += 1;
|
|
120
|
+
this.runtimeSyncMode = mode;
|
|
121
|
+
this.requestReplicaRefresh = requestRefresh;
|
|
122
|
+
if (!(mode === 'memoryReplica')) {
|
|
123
|
+
_context.next = 10;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
if (this.syncTimer) clearTimeout(this.syncTimer);
|
|
127
|
+
this.pendingSyncMessages = [];
|
|
128
|
+
_context.next = 8;
|
|
129
|
+
return this.productSyncQueue;
|
|
130
|
+
case 8:
|
|
131
|
+
_context.next = 10;
|
|
132
|
+
return this.productIndexDBSaveQueue;
|
|
133
|
+
case 10:
|
|
134
|
+
case "end":
|
|
135
|
+
return _context.stop();
|
|
136
|
+
}
|
|
137
|
+
}, _callee, this);
|
|
138
|
+
}));
|
|
139
|
+
function setRuntimeSyncMode(_x, _x2) {
|
|
140
|
+
return _setRuntimeSyncMode.apply(this, arguments);
|
|
141
|
+
}
|
|
142
|
+
return setRuntimeSyncMode;
|
|
143
|
+
}())
|
|
144
|
+
}, {
|
|
145
|
+
key: "isMemoryReplica",
|
|
146
|
+
value: function isMemoryReplica() {
|
|
147
|
+
return this.runtimeSyncMode === 'memoryReplica';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Read persisted data once on the main screen to establish a committed baseline. */
|
|
151
|
+
}, {
|
|
152
|
+
key: "enableProductReplicationSource",
|
|
153
|
+
value: (function () {
|
|
154
|
+
var _enableProductReplicationSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
155
|
+
var _this2 = this;
|
|
156
|
+
var generation;
|
|
157
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
158
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
159
|
+
case 0:
|
|
160
|
+
generation = this.productReplicationSourceGeneration;
|
|
161
|
+
_context3.next = 3;
|
|
162
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
163
|
+
var products;
|
|
164
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
165
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
166
|
+
case 0:
|
|
167
|
+
if (!(generation !== _this2.productReplicationSourceGeneration)) {
|
|
168
|
+
_context2.next = 2;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
return _context2.abrupt("return");
|
|
172
|
+
case 2:
|
|
173
|
+
if (!_this2.committedProductState) {
|
|
174
|
+
_context2.next = 4;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
return _context2.abrupt("return");
|
|
178
|
+
case 4:
|
|
179
|
+
if (!(!_this2.dbManager || _this2.productPersistenceFailed)) {
|
|
180
|
+
_context2.next = 6;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
throw new Error('Product replication requires a successful persistence baseline');
|
|
184
|
+
case 6:
|
|
185
|
+
_context2.next = 8;
|
|
186
|
+
return _this2.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
187
|
+
case 8:
|
|
188
|
+
products = _context2.sent;
|
|
189
|
+
if (!(generation !== _this2.productReplicationSourceGeneration)) {
|
|
190
|
+
_context2.next = 11;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
return _context2.abrupt("return");
|
|
194
|
+
case 11:
|
|
195
|
+
if (Array.isArray(products)) {
|
|
196
|
+
_context2.next = 13;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
throw new Error('Invalid persisted product snapshot');
|
|
200
|
+
case 13:
|
|
201
|
+
_this2.committedProductState = new CommittedProductState();
|
|
202
|
+
_this2.committedProductState.commit({
|
|
203
|
+
kind: 'snapshot',
|
|
204
|
+
upserts: products,
|
|
205
|
+
deletedIds: []
|
|
206
|
+
});
|
|
207
|
+
case 15:
|
|
208
|
+
case "end":
|
|
209
|
+
return _context2.stop();
|
|
210
|
+
}
|
|
211
|
+
}, _callee2);
|
|
212
|
+
})));
|
|
213
|
+
case 3:
|
|
214
|
+
case "end":
|
|
215
|
+
return _context3.stop();
|
|
216
|
+
}
|
|
217
|
+
}, _callee3, this);
|
|
218
|
+
}));
|
|
219
|
+
function enableProductReplicationSource() {
|
|
220
|
+
return _enableProductReplicationSource.apply(this, arguments);
|
|
221
|
+
}
|
|
222
|
+
return enableProductReplicationSource;
|
|
223
|
+
}() /** Release the extra catalog without changing the normal product store or persistence. */)
|
|
224
|
+
}, {
|
|
225
|
+
key: "disableProductReplicationSource",
|
|
226
|
+
value: function disableProductReplicationSource() {
|
|
227
|
+
this.productReplicationSourceGeneration += 1;
|
|
228
|
+
this.committedProductState = undefined;
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
key: "getCommittedProductSnapshot",
|
|
232
|
+
value: function getCommittedProductSnapshot() {
|
|
233
|
+
var _this$committedProduc, _this$committedProduc2;
|
|
234
|
+
return (_this$committedProduc = (_this$committedProduc2 = this.committedProductState) === null || _this$committedProduc2 === void 0 ? void 0 : _this$committedProduc2.snapshot()) !== null && _this$committedProduc !== void 0 ? _this$committedProduc : null;
|
|
235
|
+
}
|
|
236
|
+
}, {
|
|
237
|
+
key: "recordProductCommit",
|
|
238
|
+
value: function () {
|
|
239
|
+
var _recordProductCommit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(change) {
|
|
240
|
+
var committed;
|
|
241
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
242
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
243
|
+
case 0:
|
|
244
|
+
this.productPersistenceFailed = false;
|
|
245
|
+
if (this.committedProductState) {
|
|
246
|
+
_context4.next = 3;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
return _context4.abrupt("return");
|
|
250
|
+
case 3:
|
|
251
|
+
committed = this.committedProductState.commit(change);
|
|
252
|
+
_context4.prev = 4;
|
|
253
|
+
_context4.next = 7;
|
|
254
|
+
return this.core.effects.emit(ProductsHooks.onProductsCommitted, committed);
|
|
255
|
+
case 7:
|
|
256
|
+
_context4.next = 12;
|
|
257
|
+
break;
|
|
258
|
+
case 9:
|
|
259
|
+
_context4.prev = 9;
|
|
260
|
+
_context4.t0 = _context4["catch"](4);
|
|
261
|
+
// Transport failure is not a persistence failure; peers recover using the snapshot.
|
|
262
|
+
this.logWarning('商品提交通知失败', {
|
|
263
|
+
revision: committed.revision,
|
|
264
|
+
error: String(_context4.t0)
|
|
265
|
+
});
|
|
266
|
+
case 12:
|
|
267
|
+
case "end":
|
|
268
|
+
return _context4.stop();
|
|
269
|
+
}
|
|
270
|
+
}, _callee4, this, [[4, 9]]);
|
|
271
|
+
}));
|
|
272
|
+
function recordProductCommit(_x3) {
|
|
273
|
+
return _recordProductCommit.apply(this, arguments);
|
|
274
|
+
}
|
|
275
|
+
return recordProductCommit;
|
|
276
|
+
}()
|
|
277
|
+
}, {
|
|
278
|
+
key: "applyReplicatedProducts",
|
|
279
|
+
value: function () {
|
|
280
|
+
var _applyReplicatedProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(change) {
|
|
281
|
+
var _this3 = this;
|
|
282
|
+
var generation, apply, task;
|
|
283
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context7) {
|
|
284
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
285
|
+
case 0:
|
|
286
|
+
if (this.isMemoryReplica()) {
|
|
287
|
+
_context7.next = 2;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
throw new Error('Product module is not a memory replica');
|
|
291
|
+
case 2:
|
|
292
|
+
generation = this.runtimeSyncGeneration;
|
|
293
|
+
apply = /*#__PURE__*/function () {
|
|
294
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
295
|
+
var changedIds, _this3$store$list, removed, updates, _iterator, _step, id, _iterator2, _step2, product, _iterator3, _step3, _loop;
|
|
296
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
|
|
297
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
298
|
+
case 0:
|
|
299
|
+
if (!(!_this3.isMemoryReplica() || generation !== _this3.runtimeSyncGeneration)) {
|
|
300
|
+
_context6.next = 2;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
return _context6.abrupt("return");
|
|
304
|
+
case 2:
|
|
305
|
+
changedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(change.deletedIds), _toConsumableArray(change.upserts.map(function (p) {
|
|
306
|
+
return p.id;
|
|
307
|
+
})))));
|
|
308
|
+
if (!(change.kind === 'snapshot')) {
|
|
309
|
+
_context6.next = 9;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
_this3.store.list = change.upserts;
|
|
313
|
+
_this3.syncProductsMap();
|
|
314
|
+
_this3.clearPriceCache();
|
|
315
|
+
_context6.next = 33;
|
|
316
|
+
break;
|
|
317
|
+
case 9:
|
|
318
|
+
removed = new Set(change.deletedIds);
|
|
319
|
+
updates = new Map(change.upserts.map(function (p) {
|
|
320
|
+
return [p.id, p];
|
|
321
|
+
}));
|
|
322
|
+
_this3.store.list = _this3.store.list.filter(function (p) {
|
|
323
|
+
return !removed.has(p.id);
|
|
324
|
+
}).map(function (p) {
|
|
325
|
+
var next = updates.get(p.id);
|
|
326
|
+
if (!next) return p;
|
|
327
|
+
updates.delete(p.id);
|
|
328
|
+
return next;
|
|
329
|
+
});
|
|
330
|
+
(_this3$store$list = _this3.store.list).push.apply(_this3$store$list, _toConsumableArray(updates.values()));
|
|
331
|
+
_iterator = _createForOfIteratorHelper(removed);
|
|
332
|
+
try {
|
|
333
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
334
|
+
id = _step.value;
|
|
335
|
+
_this3.store.map.delete(id);
|
|
336
|
+
}
|
|
337
|
+
} catch (err) {
|
|
338
|
+
_iterator.e(err);
|
|
339
|
+
} finally {
|
|
340
|
+
_iterator.f();
|
|
341
|
+
}
|
|
342
|
+
_iterator2 = _createForOfIteratorHelper(change.upserts);
|
|
343
|
+
try {
|
|
344
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
345
|
+
product = _step2.value;
|
|
346
|
+
_this3.store.map.set(product.id, product);
|
|
347
|
+
}
|
|
348
|
+
} catch (err) {
|
|
349
|
+
_iterator2.e(err);
|
|
350
|
+
} finally {
|
|
351
|
+
_iterator2.f();
|
|
352
|
+
}
|
|
353
|
+
_iterator3 = _createForOfIteratorHelper(_this3.productsPriceCache);
|
|
354
|
+
_context6.prev = 18;
|
|
355
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
356
|
+
var _this3$replicaPriceDi;
|
|
357
|
+
var _step3$value, key, cached, dirty;
|
|
358
|
+
return _regeneratorRuntime().wrap(function _loop$(_context5) {
|
|
359
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
360
|
+
case 0:
|
|
361
|
+
_step3$value = _slicedToArray(_step3.value, 2), key = _step3$value[0], cached = _step3$value[1];
|
|
362
|
+
_this3.productsPriceCache.set(key, cached.filter(function (p) {
|
|
363
|
+
return !removed.has(p.id);
|
|
364
|
+
}));
|
|
365
|
+
dirty = (_this3$replicaPriceDi = _this3.replicaPriceDirtyIds.get(key)) !== null && _this3$replicaPriceDi !== void 0 ? _this3$replicaPriceDi : new Set();
|
|
366
|
+
change.upserts.forEach(function (p) {
|
|
367
|
+
return dirty.add(p.id);
|
|
368
|
+
});
|
|
369
|
+
removed.forEach(function (id) {
|
|
370
|
+
return dirty.delete(id);
|
|
371
|
+
});
|
|
372
|
+
_this3.replicaPriceDirtyIds.set(key, dirty);
|
|
373
|
+
case 6:
|
|
374
|
+
case "end":
|
|
375
|
+
return _context5.stop();
|
|
376
|
+
}
|
|
377
|
+
}, _loop);
|
|
378
|
+
});
|
|
379
|
+
_iterator3.s();
|
|
380
|
+
case 21:
|
|
381
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
382
|
+
_context6.next = 25;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
return _context6.delegateYield(_loop(), "t0", 23);
|
|
386
|
+
case 23:
|
|
387
|
+
_context6.next = 21;
|
|
388
|
+
break;
|
|
389
|
+
case 25:
|
|
390
|
+
_context6.next = 30;
|
|
391
|
+
break;
|
|
392
|
+
case 27:
|
|
393
|
+
_context6.prev = 27;
|
|
394
|
+
_context6.t1 = _context6["catch"](18);
|
|
395
|
+
_iterator3.e(_context6.t1);
|
|
396
|
+
case 30:
|
|
397
|
+
_context6.prev = 30;
|
|
398
|
+
_iterator3.f();
|
|
399
|
+
return _context6.finish(30);
|
|
400
|
+
case 33:
|
|
401
|
+
_context6.next = 35;
|
|
402
|
+
return _this3.core.effects.emit(ProductsHooks.onProductsChanged, _this3.store.list);
|
|
403
|
+
case 35:
|
|
404
|
+
if (!(generation !== _this3.runtimeSyncGeneration)) {
|
|
405
|
+
_context6.next = 37;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
return _context6.abrupt("return");
|
|
409
|
+
case 37:
|
|
410
|
+
_context6.next = 39;
|
|
411
|
+
return _this3.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
|
|
412
|
+
changedIds: changedIds
|
|
413
|
+
});
|
|
414
|
+
case 39:
|
|
415
|
+
case "end":
|
|
416
|
+
return _context6.stop();
|
|
417
|
+
}
|
|
418
|
+
}, _callee5, null, [[18, 27, 30, 33]]);
|
|
419
|
+
}));
|
|
420
|
+
return function apply() {
|
|
421
|
+
return _ref2.apply(this, arguments);
|
|
422
|
+
};
|
|
423
|
+
}();
|
|
424
|
+
task = this.replicaApplyQueue.then(apply, apply);
|
|
425
|
+
this.replicaApplyQueue = task.catch(function () {
|
|
426
|
+
return undefined;
|
|
427
|
+
});
|
|
428
|
+
return _context7.abrupt("return", task);
|
|
429
|
+
case 7:
|
|
430
|
+
case "end":
|
|
431
|
+
return _context7.stop();
|
|
432
|
+
}
|
|
433
|
+
}, _callee6, this);
|
|
434
|
+
}));
|
|
435
|
+
function applyReplicatedProducts(_x4) {
|
|
436
|
+
return _applyReplicatedProducts.apply(this, arguments);
|
|
437
|
+
}
|
|
438
|
+
return applyReplicatedProducts;
|
|
439
|
+
}()
|
|
440
|
+
}, {
|
|
441
|
+
key: "refreshFromReplica",
|
|
442
|
+
value: function () {
|
|
443
|
+
var _refreshFromReplica = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(trigger) {
|
|
444
|
+
var _this$requestReplicaR;
|
|
445
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
|
|
446
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
447
|
+
case 0:
|
|
448
|
+
_context8.next = 2;
|
|
449
|
+
return (_this$requestReplicaR = this.requestReplicaRefresh) === null || _this$requestReplicaR === void 0 ? void 0 : _this$requestReplicaR.call(this, trigger);
|
|
450
|
+
case 2:
|
|
451
|
+
return _context8.abrupt("return", this.store.list);
|
|
452
|
+
case 3:
|
|
453
|
+
case "end":
|
|
454
|
+
return _context8.stop();
|
|
455
|
+
}
|
|
456
|
+
}, _callee7, this);
|
|
457
|
+
}));
|
|
458
|
+
function refreshFromReplica(_x5) {
|
|
459
|
+
return _refreshFromReplica.apply(this, arguments);
|
|
460
|
+
}
|
|
461
|
+
return refreshFromReplica;
|
|
462
|
+
}()
|
|
463
|
+
}, {
|
|
100
464
|
key: "initialize",
|
|
101
465
|
value: function () {
|
|
102
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
466
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(core, options) {
|
|
103
467
|
var _options$initialState;
|
|
104
468
|
var appPlugin, app;
|
|
105
|
-
return _regeneratorRuntime().wrap(function
|
|
106
|
-
while (1) switch (
|
|
469
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context9) {
|
|
470
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
107
471
|
case 0:
|
|
108
472
|
this.core = core;
|
|
109
473
|
this.store = options.store;
|
|
@@ -145,11 +509,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
145
509
|
});
|
|
146
510
|
case 11:
|
|
147
511
|
case "end":
|
|
148
|
-
return
|
|
512
|
+
return _context9.stop();
|
|
149
513
|
}
|
|
150
|
-
},
|
|
514
|
+
}, _callee8, this);
|
|
151
515
|
}));
|
|
152
|
-
function initialize(
|
|
516
|
+
function initialize(_x6, _x7) {
|
|
153
517
|
return _initialize.apply(this, arguments);
|
|
154
518
|
}
|
|
155
519
|
return initialize;
|
|
@@ -224,13 +588,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
224
588
|
}, {
|
|
225
589
|
key: "loadProductsPrice",
|
|
226
590
|
value: (function () {
|
|
227
|
-
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
228
|
-
var
|
|
229
|
-
var
|
|
230
|
-
return _regeneratorRuntime().wrap(function
|
|
231
|
-
while (1) switch (
|
|
591
|
+
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref3) {
|
|
592
|
+
var _this4 = this;
|
|
593
|
+
var _ref3$ids, ids, schedule_date, schedule_datetime, customer_id, startTime, datetime, idSet, products, priceData, duration, _duration, errorMessage;
|
|
594
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context10) {
|
|
595
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
232
596
|
case 0:
|
|
233
|
-
|
|
597
|
+
_ref3$ids = _ref3.ids, ids = _ref3$ids === void 0 ? [] : _ref3$ids, schedule_date = _ref3.schedule_date, schedule_datetime = _ref3.schedule_datetime, customer_id = _ref3.customer_id;
|
|
234
598
|
this.logInfo('开始加载商品价格', {
|
|
235
599
|
productCount: ids.length,
|
|
236
600
|
schedule_date: schedule_date,
|
|
@@ -239,8 +603,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
239
603
|
});
|
|
240
604
|
startTime = Date.now();
|
|
241
605
|
datetime = schedule_datetime || schedule_date;
|
|
242
|
-
|
|
243
|
-
|
|
606
|
+
_context10.prev = 4;
|
|
607
|
+
_context10.next = 7;
|
|
244
608
|
return this.ensureQuotationBridgeReady(customer_id);
|
|
245
609
|
case 7:
|
|
246
610
|
idSet = new Set(ids);
|
|
@@ -248,7 +612,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
248
612
|
return idSet.has(product.id);
|
|
249
613
|
});
|
|
250
614
|
priceData = products.map(function (product) {
|
|
251
|
-
return
|
|
615
|
+
return _this4.buildPriceDataFromQuotation(product, datetime, customer_id);
|
|
252
616
|
});
|
|
253
617
|
duration = Date.now() - startTime;
|
|
254
618
|
this.logInfo('加载商品价格成功', {
|
|
@@ -256,25 +620,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
256
620
|
priceDataCount: priceData.length,
|
|
257
621
|
duration: "".concat(duration, "ms")
|
|
258
622
|
});
|
|
259
|
-
return
|
|
623
|
+
return _context10.abrupt("return", priceData);
|
|
260
624
|
case 15:
|
|
261
|
-
|
|
262
|
-
|
|
625
|
+
_context10.prev = 15;
|
|
626
|
+
_context10.t0 = _context10["catch"](4);
|
|
263
627
|
_duration = Date.now() - startTime;
|
|
264
|
-
errorMessage =
|
|
628
|
+
errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
|
|
265
629
|
this.logError('加载商品价格失败', {
|
|
266
630
|
productCount: ids.length,
|
|
267
631
|
duration: "".concat(_duration, "ms"),
|
|
268
632
|
error: errorMessage
|
|
269
633
|
});
|
|
270
|
-
return
|
|
634
|
+
return _context10.abrupt("return", []);
|
|
271
635
|
case 21:
|
|
272
636
|
case "end":
|
|
273
|
-
return
|
|
637
|
+
return _context10.stop();
|
|
274
638
|
}
|
|
275
|
-
},
|
|
639
|
+
}, _callee9, this, [[4, 15]]);
|
|
276
640
|
}));
|
|
277
|
-
function loadProductsPrice(
|
|
641
|
+
function loadProductsPrice(_x8) {
|
|
278
642
|
return _loadProductsPrice.apply(this, arguments);
|
|
279
643
|
}
|
|
280
644
|
return loadProductsPrice;
|
|
@@ -287,30 +651,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
287
651
|
}, {
|
|
288
652
|
key: "setupQuotationPriceBridge",
|
|
289
653
|
value: (function () {
|
|
290
|
-
var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
654
|
+
var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
291
655
|
var _this$otherParams,
|
|
292
|
-
|
|
656
|
+
_this5 = this,
|
|
293
657
|
_this$quotationPriceB,
|
|
294
658
|
_this$quotationPriceB2;
|
|
295
659
|
var channel, quotation;
|
|
296
|
-
return _regeneratorRuntime().wrap(function
|
|
297
|
-
while (1) switch (
|
|
660
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context11) {
|
|
661
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
298
662
|
case 0:
|
|
299
663
|
if (this.core) {
|
|
300
|
-
|
|
664
|
+
_context11.next = 3;
|
|
301
665
|
break;
|
|
302
666
|
}
|
|
303
667
|
this.logWarning('setupQuotationPriceBridge: core 尚未初始化');
|
|
304
|
-
return
|
|
668
|
+
return _context11.abrupt("return");
|
|
305
669
|
case 3:
|
|
306
670
|
channel = params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel);
|
|
307
671
|
this.quotationBridgeChannel = channel;
|
|
308
672
|
if (this.quotationPriceBridge) {
|
|
309
|
-
|
|
673
|
+
_context11.next = 10;
|
|
310
674
|
break;
|
|
311
675
|
}
|
|
312
676
|
quotation = new ClientQuotationModule("".concat(this.name, "_quotation_price_bridge"));
|
|
313
|
-
|
|
677
|
+
_context11.next = 9;
|
|
314
678
|
return quotation.initialize(this.core, {});
|
|
315
679
|
case 9:
|
|
316
680
|
this.quotationPriceBridge = quotation;
|
|
@@ -324,31 +688,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
324
688
|
this.quotationPriceBridge.setScheduleResolver(function (id) {
|
|
325
689
|
var _params$scheduleModul3, _params$scheduleModul4, _params$scheduleModul5, _params$scheduleModul6;
|
|
326
690
|
var scheduleId = String(id);
|
|
327
|
-
if (
|
|
328
|
-
return
|
|
691
|
+
if (_this5.quotationScheduleCache.has(scheduleId)) {
|
|
692
|
+
return _this5.quotationScheduleCache.get(scheduleId);
|
|
329
693
|
}
|
|
330
|
-
if (!
|
|
694
|
+
if (!_this5.quotationScheduleCacheLoaded) {
|
|
331
695
|
var _params$scheduleModul, _params$scheduleModul2;
|
|
332
696
|
var scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
|
|
333
|
-
var
|
|
334
|
-
|
|
697
|
+
var _iterator4 = _createForOfIteratorHelper(scheduleList),
|
|
698
|
+
_step4;
|
|
335
699
|
try {
|
|
336
|
-
for (
|
|
337
|
-
var schedule =
|
|
338
|
-
|
|
700
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
701
|
+
var schedule = _step4.value;
|
|
702
|
+
_this5.quotationScheduleCache.set(String(schedule.id), schedule);
|
|
339
703
|
}
|
|
340
704
|
} catch (err) {
|
|
341
|
-
|
|
705
|
+
_iterator4.e(err);
|
|
342
706
|
} finally {
|
|
343
|
-
|
|
707
|
+
_iterator4.f();
|
|
344
708
|
}
|
|
345
|
-
|
|
709
|
+
_this5.quotationScheduleCacheLoaded = true;
|
|
346
710
|
}
|
|
347
|
-
if (
|
|
348
|
-
return
|
|
711
|
+
if (_this5.quotationScheduleCache.has(scheduleId)) {
|
|
712
|
+
return _this5.quotationScheduleCache.get(scheduleId);
|
|
349
713
|
}
|
|
350
714
|
var schedules = ((_params$scheduleModul3 = (_params$scheduleModul4 = params.scheduleModule).getScheduleListByIds) === null || _params$scheduleModul3 === void 0 ? void 0 : _params$scheduleModul3.call(_params$scheduleModul4, [id])) || ((_params$scheduleModul5 = (_params$scheduleModul6 = params.scheduleModule).getScheduleByIds) === null || _params$scheduleModul5 === void 0 ? void 0 : _params$scheduleModul5.call(_params$scheduleModul6, [id])) || [];
|
|
351
|
-
if (schedules[0])
|
|
715
|
+
if (schedules[0]) _this5.quotationScheduleCache.set(scheduleId, schedules[0]);
|
|
352
716
|
return schedules[0];
|
|
353
717
|
});
|
|
354
718
|
}
|
|
@@ -356,22 +720,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
356
720
|
this.quotationBridgeUpdatedCallback = params.onQuotationUpdated;
|
|
357
721
|
}
|
|
358
722
|
(_this$quotationPriceB = (_this$quotationPriceB2 = this.quotationPriceBridge).setQuotationListUpdatedListener) === null || _this$quotationPriceB === void 0 || _this$quotationPriceB.call(_this$quotationPriceB2, function () {
|
|
359
|
-
var
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
(
|
|
723
|
+
var _this5$quotationBridg;
|
|
724
|
+
_this5.quotationBridgeLoadedKey = _this5.getQuotationBridgeScopeKey();
|
|
725
|
+
_this5.clearPriceCache();
|
|
726
|
+
(_this5$quotationBridg = _this5.quotationBridgeUpdatedCallback) === null || _this5$quotationBridg === void 0 || _this5$quotationBridg.call(_this5);
|
|
363
727
|
});
|
|
364
|
-
|
|
728
|
+
_context11.next = 15;
|
|
365
729
|
return this.refreshQuotationPriceBridge({
|
|
366
730
|
customer_id: params.customer_id
|
|
367
731
|
});
|
|
368
732
|
case 15:
|
|
369
733
|
case "end":
|
|
370
|
-
return
|
|
734
|
+
return _context11.stop();
|
|
371
735
|
}
|
|
372
|
-
},
|
|
736
|
+
}, _callee10, this);
|
|
373
737
|
}));
|
|
374
|
-
function setupQuotationPriceBridge(
|
|
738
|
+
function setupQuotationPriceBridge(_x9) {
|
|
375
739
|
return _setupQuotationPriceBridge.apply(this, arguments);
|
|
376
740
|
}
|
|
377
741
|
return setupQuotationPriceBridge;
|
|
@@ -383,53 +747,53 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
383
747
|
}, {
|
|
384
748
|
key: "refreshQuotationPriceBridge",
|
|
385
749
|
value: (function () {
|
|
386
|
-
var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
387
|
-
var
|
|
750
|
+
var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
751
|
+
var _this6 = this;
|
|
388
752
|
var refreshKey;
|
|
389
|
-
return _regeneratorRuntime().wrap(function
|
|
390
|
-
while (1) switch (
|
|
753
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context12) {
|
|
754
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
391
755
|
case 0:
|
|
392
756
|
if (this.quotationPriceBridge) {
|
|
393
|
-
|
|
757
|
+
_context12.next = 2;
|
|
394
758
|
break;
|
|
395
759
|
}
|
|
396
|
-
return
|
|
760
|
+
return _context12.abrupt("return");
|
|
397
761
|
case 2:
|
|
398
762
|
refreshKey = this.getQuotationBridgeScopeKey();
|
|
399
763
|
if (!(this.quotationBridgeRefreshPromise && this.quotationBridgeRefreshKey === refreshKey)) {
|
|
400
|
-
|
|
764
|
+
_context12.next = 7;
|
|
401
765
|
break;
|
|
402
766
|
}
|
|
403
|
-
|
|
767
|
+
_context12.next = 6;
|
|
404
768
|
return this.quotationBridgeRefreshPromise;
|
|
405
769
|
case 6:
|
|
406
|
-
return
|
|
770
|
+
return _context12.abrupt("return");
|
|
407
771
|
case 7:
|
|
408
772
|
if (!this.quotationBridgeRefreshPromise) {
|
|
409
|
-
|
|
773
|
+
_context12.next = 10;
|
|
410
774
|
break;
|
|
411
775
|
}
|
|
412
|
-
|
|
776
|
+
_context12.next = 10;
|
|
413
777
|
return this.quotationBridgeRefreshPromise;
|
|
414
778
|
case 10:
|
|
415
779
|
this.quotationBridgeRefreshKey = refreshKey;
|
|
416
780
|
this.quotationBridgeRefreshPromise = this.quotationPriceBridge.loadQuotations({
|
|
417
781
|
channel: this.quotationBridgeChannel
|
|
418
782
|
}).then(function () {
|
|
419
|
-
|
|
783
|
+
_this6.quotationBridgeLoadedKey = refreshKey;
|
|
420
784
|
}).finally(function () {
|
|
421
|
-
|
|
422
|
-
|
|
785
|
+
_this6.quotationBridgeRefreshPromise = undefined;
|
|
786
|
+
_this6.quotationBridgeRefreshKey = undefined;
|
|
423
787
|
});
|
|
424
|
-
|
|
788
|
+
_context12.next = 14;
|
|
425
789
|
return this.quotationBridgeRefreshPromise;
|
|
426
790
|
case 14:
|
|
427
791
|
case "end":
|
|
428
|
-
return
|
|
792
|
+
return _context12.stop();
|
|
429
793
|
}
|
|
430
|
-
},
|
|
794
|
+
}, _callee11, this);
|
|
431
795
|
}));
|
|
432
|
-
function refreshQuotationPriceBridge(
|
|
796
|
+
function refreshQuotationPriceBridge(_x10) {
|
|
433
797
|
return _refreshQuotationPriceBridge.apply(this, arguments);
|
|
434
798
|
}
|
|
435
799
|
return refreshQuotationPriceBridge;
|
|
@@ -437,45 +801,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
437
801
|
}, {
|
|
438
802
|
key: "ensureQuotationBridgeReady",
|
|
439
803
|
value: function () {
|
|
440
|
-
var _ensureQuotationBridgeReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
804
|
+
var _ensureQuotationBridgeReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(customerId) {
|
|
441
805
|
var _this$otherParams2;
|
|
442
|
-
return _regeneratorRuntime().wrap(function
|
|
443
|
-
while (1) switch (
|
|
806
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context13) {
|
|
807
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
444
808
|
case 0:
|
|
445
809
|
if (this.quotationPriceBridge) {
|
|
446
|
-
|
|
810
|
+
_context13.next = 4;
|
|
447
811
|
break;
|
|
448
812
|
}
|
|
449
|
-
|
|
813
|
+
_context13.next = 3;
|
|
450
814
|
return this.setupQuotationPriceBridge({
|
|
451
815
|
channel: (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel,
|
|
452
816
|
customer_id: customerId
|
|
453
817
|
});
|
|
454
818
|
case 3:
|
|
455
|
-
return
|
|
819
|
+
return _context13.abrupt("return");
|
|
456
820
|
case 4:
|
|
457
821
|
if (!this.quotationBridgeRefreshPromise) {
|
|
458
|
-
|
|
822
|
+
_context13.next = 7;
|
|
459
823
|
break;
|
|
460
824
|
}
|
|
461
|
-
|
|
825
|
+
_context13.next = 7;
|
|
462
826
|
return this.quotationBridgeRefreshPromise;
|
|
463
827
|
case 7:
|
|
464
828
|
if (!(this.getQuotationBridgeScopeKey() !== this.quotationBridgeLoadedKey)) {
|
|
465
|
-
|
|
829
|
+
_context13.next = 10;
|
|
466
830
|
break;
|
|
467
831
|
}
|
|
468
|
-
|
|
832
|
+
_context13.next = 10;
|
|
469
833
|
return this.refreshQuotationPriceBridge({
|
|
470
834
|
customer_id: customerId
|
|
471
835
|
});
|
|
472
836
|
case 10:
|
|
473
837
|
case "end":
|
|
474
|
-
return
|
|
838
|
+
return _context13.stop();
|
|
475
839
|
}
|
|
476
|
-
},
|
|
840
|
+
}, _callee12, this);
|
|
477
841
|
}));
|
|
478
|
-
function ensureQuotationBridgeReady(
|
|
842
|
+
function ensureQuotationBridgeReady(_x11) {
|
|
479
843
|
return _ensureQuotationBridgeReady.apply(this, arguments);
|
|
480
844
|
}
|
|
481
845
|
return ensureQuotationBridgeReady;
|
|
@@ -508,14 +872,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
508
872
|
}, {
|
|
509
873
|
key: "buildPriceDataFromQuotation",
|
|
510
874
|
value: function buildPriceDataFromQuotation(product, datetime, customerId) {
|
|
511
|
-
var
|
|
875
|
+
var _ref4, _ref5;
|
|
512
876
|
var quotedPrice = this.getQuotedPrice({
|
|
513
877
|
productId: product.id,
|
|
514
878
|
datetime: datetime,
|
|
515
879
|
customerId: customerId
|
|
516
880
|
});
|
|
517
881
|
var productPrice = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.price;
|
|
518
|
-
var productBasePrice = (
|
|
882
|
+
var productBasePrice = (_ref4 = (_ref5 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.base_price) !== null && _ref5 !== void 0 ? _ref5 : product.price) !== null && _ref4 !== void 0 ? _ref4 : 0;
|
|
519
883
|
return {
|
|
520
884
|
id: product.id,
|
|
521
885
|
price: String(productPrice !== null && productPrice !== void 0 ? productPrice : 0),
|
|
@@ -527,18 +891,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
527
891
|
}, {
|
|
528
892
|
key: "buildVariantPriceData",
|
|
529
893
|
value: function buildVariantPriceData(product, datetime, customerId) {
|
|
530
|
-
var
|
|
894
|
+
var _this7 = this;
|
|
531
895
|
if (!Array.isArray(product.variant)) return [];
|
|
532
896
|
return product.variant.map(function (variant) {
|
|
533
|
-
var
|
|
534
|
-
var quotedPrice =
|
|
897
|
+
var _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _variant$product_id;
|
|
898
|
+
var quotedPrice = _this7.getQuotedPrice({
|
|
535
899
|
productId: product.id,
|
|
536
900
|
variantId: Number(variant.id),
|
|
537
901
|
datetime: datetime,
|
|
538
902
|
customerId: customerId
|
|
539
903
|
});
|
|
540
|
-
var price = (
|
|
541
|
-
var basePrice = (
|
|
904
|
+
var price = (_ref6 = (_ref7 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : 0;
|
|
905
|
+
var basePrice = (_ref8 = (_ref9 = (_ref10 = (_ref11 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.base_price) !== null && _ref11 !== void 0 ? _ref11 : variant.price) !== null && _ref10 !== void 0 ? _ref10 : product.base_price) !== null && _ref9 !== void 0 ? _ref9 : product.price) !== null && _ref8 !== void 0 ? _ref8 : 0;
|
|
542
906
|
return {
|
|
543
907
|
id: Number(variant.id),
|
|
544
908
|
product_id: Number((_variant$product_id = variant.product_id) !== null && _variant$product_id !== void 0 ? _variant$product_id : product.id),
|
|
@@ -550,23 +914,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
550
914
|
}, {
|
|
551
915
|
key: "buildBundleGroupPriceData",
|
|
552
916
|
value: function buildBundleGroupPriceData(product, datetime, customerId) {
|
|
553
|
-
var
|
|
917
|
+
var _this8 = this;
|
|
554
918
|
if (!Array.isArray(product.bundle_group)) return [];
|
|
555
919
|
return product.bundle_group.map(function (group) {
|
|
556
920
|
return {
|
|
557
921
|
id: Number(group.id),
|
|
558
922
|
bundle_item: (group.bundle_item || []).map(function (item) {
|
|
559
|
-
var
|
|
923
|
+
var _ref12, _ref13, _ref14, _item$product_id, _item$group_id;
|
|
560
924
|
var bundleProductId = Number(item.bundle_product_id);
|
|
561
925
|
var bundleVariantId = Number(item.bundle_variant_id || 0);
|
|
562
|
-
var quotedPrice =
|
|
926
|
+
var quotedPrice = _this8.getQuotedPrice({
|
|
563
927
|
productId: bundleProductId,
|
|
564
928
|
variantId: bundleVariantId,
|
|
565
929
|
datetime: datetime,
|
|
566
930
|
customerId: customerId
|
|
567
931
|
});
|
|
568
|
-
var price = (
|
|
569
|
-
var basePrice = (
|
|
932
|
+
var price = (_ref12 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref12 !== void 0 ? _ref12 : 0;
|
|
933
|
+
var basePrice = (_ref13 = (_ref14 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.base_price) !== null && _ref14 !== void 0 ? _ref14 : item.price) !== null && _ref13 !== void 0 ? _ref13 : 0;
|
|
570
934
|
return {
|
|
571
935
|
id: Number(item.id),
|
|
572
936
|
product_id: Number((_item$product_id = item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : product.id),
|
|
@@ -597,26 +961,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
597
961
|
}, {
|
|
598
962
|
key: "getProductsWithPrice",
|
|
599
963
|
value: (function () {
|
|
600
|
-
var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
601
|
-
var _options$changedIds;
|
|
602
|
-
var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache,
|
|
603
|
-
return _regeneratorRuntime().wrap(function
|
|
604
|
-
while (1) switch (
|
|
964
|
+
var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(schedule_date, extraContext, options) {
|
|
965
|
+
var _options$changedIds, _this$replicaPriceDir;
|
|
966
|
+
var t0, scopedProductIds, cacheKey, scopedProductIdSet, pendingIds, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator5, _step5, p, _iterator6, _step6, _p, errorMessage, result;
|
|
967
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context14) {
|
|
968
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
605
969
|
case 0:
|
|
606
970
|
t0 = performance.now();
|
|
607
971
|
scopedProductIds = this.normalizeProductIds(options === null || options === void 0 ? void 0 : options.productIds);
|
|
608
972
|
cacheKey = this.getProductsPriceCacheKey(schedule_date, extraContext, scopedProductIds);
|
|
609
973
|
scopedProductIdSet = scopedProductIds ? new Set(scopedProductIds) : undefined;
|
|
610
|
-
|
|
974
|
+
pendingIds = _toConsumableArray(new Set([].concat(_toConsumableArray((_options$changedIds = options === null || options === void 0 ? void 0 : options.changedIds) !== null && _options$changedIds !== void 0 ? _options$changedIds : []), _toConsumableArray((_this$replicaPriceDir = this.replicaPriceDirtyIds.get(cacheKey)) !== null && _this$replicaPriceDir !== void 0 ? _this$replicaPriceDir : []))));
|
|
975
|
+
changedIds = scopedProductIdSet ? pendingIds.filter(function (id) {
|
|
611
976
|
return scopedProductIdSet.has(id);
|
|
612
|
-
}) :
|
|
977
|
+
}) : pendingIds;
|
|
613
978
|
if (!this.productsPriceCache.has(cacheKey)) {
|
|
614
|
-
|
|
979
|
+
_context14.next = 37;
|
|
615
980
|
break;
|
|
616
981
|
}
|
|
617
982
|
cachedProducts = this.productsPriceCache.get(cacheKey); // 有变更的商品 → 增量 prepare 后 merge 回缓存
|
|
618
983
|
if (!(changedIds && changedIds.length > 0)) {
|
|
619
|
-
|
|
984
|
+
_context14.next = 34;
|
|
620
985
|
break;
|
|
621
986
|
}
|
|
622
987
|
this.logInfo('商品价格缓存命中,增量更新变更商品', {
|
|
@@ -624,15 +989,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
624
989
|
changedIds: changedIds,
|
|
625
990
|
cachedProductCount: cachedProducts.length
|
|
626
991
|
});
|
|
627
|
-
|
|
628
|
-
|
|
992
|
+
_context14.prev = 10;
|
|
993
|
+
_context14.next = 13;
|
|
629
994
|
return this.prepareProductsWithPrice(schedule_date, extraContext, {
|
|
630
995
|
productIds: changedIds
|
|
631
996
|
});
|
|
632
|
-
case
|
|
633
|
-
updatedProducts =
|
|
634
|
-
if (!(updatedProducts.length > 0)) {
|
|
635
|
-
|
|
997
|
+
case 13:
|
|
998
|
+
updatedProducts = _context14.sent;
|
|
999
|
+
if (!(updatedProducts.length > 0 || this.isMemoryReplica())) {
|
|
1000
|
+
_context14.next = 26;
|
|
636
1001
|
break;
|
|
637
1002
|
}
|
|
638
1003
|
// merge:用更新结果替换缓存中对应的商品,新增的追加
|
|
@@ -640,35 +1005,36 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
640
1005
|
return [p.id, p];
|
|
641
1006
|
}));
|
|
642
1007
|
mergedCache = [];
|
|
643
|
-
|
|
1008
|
+
_iterator5 = _createForOfIteratorHelper(cachedProducts);
|
|
644
1009
|
try {
|
|
645
|
-
for (
|
|
646
|
-
p =
|
|
1010
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1011
|
+
p = _step5.value;
|
|
647
1012
|
if (updatedMap.has(p.id)) {
|
|
648
1013
|
mergedCache.push(updatedMap.get(p.id));
|
|
649
1014
|
updatedMap.delete(p.id);
|
|
650
|
-
} else {
|
|
1015
|
+
} else if (!this.isMemoryReplica() || !changedIds.includes(p.id)) {
|
|
651
1016
|
mergedCache.push(p);
|
|
652
1017
|
}
|
|
653
1018
|
}
|
|
654
1019
|
// 剩余的是新增商品(create 场景)
|
|
655
1020
|
} catch (err) {
|
|
656
|
-
|
|
1021
|
+
_iterator5.e(err);
|
|
657
1022
|
} finally {
|
|
658
|
-
|
|
1023
|
+
_iterator5.f();
|
|
659
1024
|
}
|
|
660
|
-
|
|
1025
|
+
_iterator6 = _createForOfIteratorHelper(updatedMap.values());
|
|
661
1026
|
try {
|
|
662
|
-
for (
|
|
663
|
-
_p =
|
|
1027
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1028
|
+
_p = _step6.value;
|
|
664
1029
|
mergedCache.push(_p);
|
|
665
1030
|
}
|
|
666
1031
|
} catch (err) {
|
|
667
|
-
|
|
1032
|
+
_iterator6.e(err);
|
|
668
1033
|
} finally {
|
|
669
|
-
|
|
1034
|
+
_iterator6.f();
|
|
670
1035
|
}
|
|
671
1036
|
this.productsPriceCache.set(cacheKey, mergedCache);
|
|
1037
|
+
this.replicaPriceDirtyIds.delete(cacheKey);
|
|
672
1038
|
this.logInfo('增量更新完成', {
|
|
673
1039
|
cacheKey: cacheKey,
|
|
674
1040
|
changedCount: updatedProducts.length,
|
|
@@ -679,27 +1045,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
679
1045
|
changedCount: changedIds.length,
|
|
680
1046
|
count: mergedCache.length
|
|
681
1047
|
});
|
|
682
|
-
return
|
|
683
|
-
case 24:
|
|
684
|
-
_context6.next = 30;
|
|
685
|
-
break;
|
|
1048
|
+
return _context14.abrupt("return", mergedCache);
|
|
686
1049
|
case 26:
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
1050
|
+
_context14.next = 32;
|
|
1051
|
+
break;
|
|
1052
|
+
case 28:
|
|
1053
|
+
_context14.prev = 28;
|
|
1054
|
+
_context14.t0 = _context14["catch"](10);
|
|
1055
|
+
errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
|
|
690
1056
|
this.logError('增量更新失败,返回现有缓存', {
|
|
691
1057
|
cacheKey: cacheKey,
|
|
692
1058
|
changedIds: changedIds,
|
|
693
1059
|
error: errorMessage
|
|
694
1060
|
});
|
|
695
|
-
case
|
|
1061
|
+
case 32:
|
|
696
1062
|
perfMark('getProductsWithPrice(incrementalUpdate)', performance.now() - t0, {
|
|
697
1063
|
cacheKey: cacheKey,
|
|
698
1064
|
changedCount: changedIds.length,
|
|
699
1065
|
count: cachedProducts.length
|
|
700
1066
|
});
|
|
701
|
-
return
|
|
702
|
-
case
|
|
1067
|
+
return _context14.abrupt("return", cachedProducts);
|
|
1068
|
+
case 34:
|
|
703
1069
|
perfMark('getProductsWithPrice(cacheHit)', performance.now() - t0, {
|
|
704
1070
|
cacheKey: cacheKey,
|
|
705
1071
|
count: cachedProducts.length
|
|
@@ -708,19 +1074,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
708
1074
|
cacheKey: cacheKey,
|
|
709
1075
|
productCount: cachedProducts.length
|
|
710
1076
|
});
|
|
711
|
-
return
|
|
712
|
-
case
|
|
1077
|
+
return _context14.abrupt("return", cachedProducts);
|
|
1078
|
+
case 37:
|
|
713
1079
|
this.logInfo('商品价格缓存未命中,准备获取', {
|
|
714
1080
|
cacheKey: cacheKey,
|
|
715
1081
|
scopedProductCount: scopedProductIds === null || scopedProductIds === void 0 ? void 0 : scopedProductIds.length
|
|
716
1082
|
});
|
|
717
|
-
|
|
1083
|
+
_context14.next = 40;
|
|
718
1084
|
return this.prepareProductsWithPrice(schedule_date, extraContext, scopedProductIds ? {
|
|
719
1085
|
productIds: scopedProductIds
|
|
720
1086
|
} : undefined);
|
|
721
|
-
case
|
|
722
|
-
result =
|
|
1087
|
+
case 40:
|
|
1088
|
+
result = _context14.sent;
|
|
723
1089
|
this.productsPriceCache.set(cacheKey, result);
|
|
1090
|
+
this.replicaPriceDirtyIds.delete(cacheKey);
|
|
724
1091
|
this.logInfo('商品价格已缓存', {
|
|
725
1092
|
cacheKey: cacheKey,
|
|
726
1093
|
productCount: result.length
|
|
@@ -730,14 +1097,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
730
1097
|
cacheKey: cacheKey,
|
|
731
1098
|
count: result.length
|
|
732
1099
|
});
|
|
733
|
-
return
|
|
734
|
-
case
|
|
1100
|
+
return _context14.abrupt("return", result);
|
|
1101
|
+
case 47:
|
|
735
1102
|
case "end":
|
|
736
|
-
return
|
|
1103
|
+
return _context14.stop();
|
|
737
1104
|
}
|
|
738
|
-
},
|
|
1105
|
+
}, _callee13, this, [[10, 28]]);
|
|
739
1106
|
}));
|
|
740
|
-
function getProductsWithPrice(
|
|
1107
|
+
function getProductsWithPrice(_x12, _x13, _x14) {
|
|
741
1108
|
return _getProductsWithPrice.apply(this, arguments);
|
|
742
1109
|
}
|
|
743
1110
|
return getProductsWithPrice;
|
|
@@ -755,10 +1122,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
755
1122
|
}, {
|
|
756
1123
|
key: "prepareProductsWithPrice",
|
|
757
1124
|
value: (function () {
|
|
758
|
-
var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1125
|
+
var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(schedule_date, extraContext, options) {
|
|
759
1126
|
var tTotal, targetIds, isIncremental, _this$core, _this$core2, products, ids, tIds, i, priceData, _priceData$length, _priceData, tPrice, context, tFormat, processedProducts, errorMessage;
|
|
760
|
-
return _regeneratorRuntime().wrap(function
|
|
761
|
-
while (1) switch (
|
|
1127
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context15) {
|
|
1128
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
762
1129
|
case 0:
|
|
763
1130
|
tTotal = performance.now();
|
|
764
1131
|
targetIds = options === null || options === void 0 ? void 0 : options.productIds;
|
|
@@ -768,7 +1135,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
768
1135
|
mode: isIncremental ? 'incremental' : 'full',
|
|
769
1136
|
targetIdsCount: targetIds === null || targetIds === void 0 ? void 0 : targetIds.length
|
|
770
1137
|
});
|
|
771
|
-
|
|
1138
|
+
_context15.prev = 4;
|
|
772
1139
|
// 1. 获取商品列表:指定 IDs 时从 store 取子集,否则取全量
|
|
773
1140
|
|
|
774
1141
|
if (isIncremental) {
|
|
@@ -794,11 +1161,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
794
1161
|
// 2. 仅在 legacy 报价单 formatter 启用时加载报价单价格;默认由智能定价覆盖商品价格。
|
|
795
1162
|
priceData = [];
|
|
796
1163
|
if (!this.isLegacyPriceFormatterEnabled) {
|
|
797
|
-
|
|
1164
|
+
_context15.next = 15;
|
|
798
1165
|
break;
|
|
799
1166
|
}
|
|
800
1167
|
tPrice = performance.now();
|
|
801
|
-
|
|
1168
|
+
_context15.next = 12;
|
|
802
1169
|
return this.loadProductsPrice({
|
|
803
1170
|
ids: ids,
|
|
804
1171
|
schedule_date: schedule_date,
|
|
@@ -806,7 +1173,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
806
1173
|
customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id
|
|
807
1174
|
});
|
|
808
1175
|
case 12:
|
|
809
|
-
priceData =
|
|
1176
|
+
priceData = _context15.sent;
|
|
810
1177
|
perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
|
|
811
1178
|
count: ids.length
|
|
812
1179
|
});
|
|
@@ -826,10 +1193,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
826
1193
|
strategy_context: extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context
|
|
827
1194
|
}, extraContext); // 3. 通过格式化器流程处理商品
|
|
828
1195
|
tFormat = performance.now();
|
|
829
|
-
|
|
1196
|
+
_context15.next = 19;
|
|
830
1197
|
return this.applyFormatters(products, context);
|
|
831
1198
|
case 19:
|
|
832
|
-
processedProducts =
|
|
1199
|
+
processedProducts = _context15.sent;
|
|
833
1200
|
perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
|
|
834
1201
|
count: products.length,
|
|
835
1202
|
formatterCount: this.formatters.length
|
|
@@ -841,10 +1208,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
841
1208
|
formatterCount: this.formatters.length
|
|
842
1209
|
});
|
|
843
1210
|
if (isIncremental) {
|
|
844
|
-
|
|
1211
|
+
_context15.next = 25;
|
|
845
1212
|
break;
|
|
846
1213
|
}
|
|
847
|
-
|
|
1214
|
+
_context15.next = 25;
|
|
848
1215
|
return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
|
|
849
1216
|
case 25:
|
|
850
1217
|
perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
|
|
@@ -852,24 +1219,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
852
1219
|
formatterCount: this.formatters.length,
|
|
853
1220
|
mode: isIncremental ? 'incremental' : 'full'
|
|
854
1221
|
});
|
|
855
|
-
return
|
|
1222
|
+
return _context15.abrupt("return", processedProducts);
|
|
856
1223
|
case 29:
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
errorMessage =
|
|
1224
|
+
_context15.prev = 29;
|
|
1225
|
+
_context15.t0 = _context15["catch"](4);
|
|
1226
|
+
errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
|
|
860
1227
|
this.logError('prepareProductsWithPrice 处理失败', {
|
|
861
1228
|
schedule_date: schedule_date,
|
|
862
1229
|
error: errorMessage
|
|
863
1230
|
});
|
|
864
1231
|
case 33:
|
|
865
|
-
return
|
|
1232
|
+
return _context15.abrupt("return", []);
|
|
866
1233
|
case 34:
|
|
867
1234
|
case "end":
|
|
868
|
-
return
|
|
1235
|
+
return _context15.stop();
|
|
869
1236
|
}
|
|
870
|
-
},
|
|
1237
|
+
}, _callee14, this, [[4, 29]]);
|
|
871
1238
|
}));
|
|
872
|
-
function prepareProductsWithPrice(
|
|
1239
|
+
function prepareProductsWithPrice(_x15, _x16, _x17) {
|
|
873
1240
|
return _prepareProductsWithPrice.apply(this, arguments);
|
|
874
1241
|
}
|
|
875
1242
|
return prepareProductsWithPrice;
|
|
@@ -877,9 +1244,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
877
1244
|
}, {
|
|
878
1245
|
key: "getProductsPriceCacheKey",
|
|
879
1246
|
value: function getProductsPriceCacheKey(schedule_date, extraContext, productIds) {
|
|
880
|
-
var
|
|
1247
|
+
var _ref15, _extraContext$locale, _this$core3, _extraContext$custome;
|
|
881
1248
|
var datetime = (extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime) || schedule_date;
|
|
882
|
-
var locale = (
|
|
1249
|
+
var locale = (_ref15 = (_extraContext$locale = extraContext === null || extraContext === void 0 ? void 0 : extraContext.locale) !== null && _extraContext$locale !== void 0 ? _extraContext$locale : (_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.locale) !== null && _ref15 !== void 0 ? _ref15 : '';
|
|
883
1250
|
var productScope = productIds ? ":products:".concat(productIds.join(',')) : '';
|
|
884
1251
|
var strategyScope = this.stringifyStable((extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context) || {});
|
|
885
1252
|
return "".concat(datetime, ":locale:").concat(locale, ":customer:").concat((_extraContext$custome = extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id) !== null && _extraContext$custome !== void 0 ? _extraContext$custome : '') + ":strategy:".concat(strategyScope).concat(productScope);
|
|
@@ -891,14 +1258,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
891
1258
|
}, {
|
|
892
1259
|
key: "stringifyStable",
|
|
893
1260
|
value: function stringifyStable(value) {
|
|
894
|
-
var
|
|
1261
|
+
var _this9 = this;
|
|
895
1262
|
if (value == null) return '';
|
|
896
1263
|
if (Array.isArray(value)) return "[".concat(value.map(function (item) {
|
|
897
|
-
return
|
|
1264
|
+
return _this9.stringifyStable(item);
|
|
898
1265
|
}).join(','), "]");
|
|
899
1266
|
if (_typeof(value) === 'object') {
|
|
900
1267
|
return "{".concat(Object.keys(value).sort().map(function (key) {
|
|
901
|
-
return "".concat(key, ":").concat(
|
|
1268
|
+
return "".concat(key, ":").concat(_this9.stringifyStable(value[key]));
|
|
902
1269
|
}).join(','), "}");
|
|
903
1270
|
}
|
|
904
1271
|
return String(value);
|
|
@@ -931,25 +1298,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
931
1298
|
}
|
|
932
1299
|
if (productIds.length === 0 && collectionIds.length === 0) return [];
|
|
933
1300
|
var result = new Set();
|
|
934
|
-
var
|
|
935
|
-
|
|
1301
|
+
var _iterator7 = _createForOfIteratorHelper(productIds),
|
|
1302
|
+
_step7;
|
|
936
1303
|
try {
|
|
937
|
-
for (
|
|
938
|
-
var id =
|
|
1304
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1305
|
+
var id = _step7.value;
|
|
939
1306
|
if (this.store.map.has(id)) result.add(id);
|
|
940
1307
|
}
|
|
941
1308
|
} catch (err) {
|
|
942
|
-
|
|
1309
|
+
_iterator7.e(err);
|
|
943
1310
|
} finally {
|
|
944
|
-
|
|
1311
|
+
_iterator7.f();
|
|
945
1312
|
}
|
|
946
1313
|
if (collectionIds.length === 0) return Array.from(result);
|
|
947
1314
|
var collectionIdSet = new Set(collectionIds);
|
|
948
|
-
var
|
|
949
|
-
|
|
1315
|
+
var _iterator8 = _createForOfIteratorHelper(this.getProductsRef()),
|
|
1316
|
+
_step8;
|
|
950
1317
|
try {
|
|
951
|
-
for (
|
|
952
|
-
var product =
|
|
1318
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1319
|
+
var product = _step8.value;
|
|
953
1320
|
if (result.has(product.id)) continue;
|
|
954
1321
|
if (!Array.isArray(product.collection)) continue;
|
|
955
1322
|
var isInCollection = product.collection.some(function (collection) {
|
|
@@ -958,9 +1325,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
958
1325
|
if (isInCollection) result.add(product.id);
|
|
959
1326
|
}
|
|
960
1327
|
} catch (err) {
|
|
961
|
-
|
|
1328
|
+
_iterator8.e(err);
|
|
962
1329
|
} finally {
|
|
963
|
-
|
|
1330
|
+
_iterator8.f();
|
|
964
1331
|
}
|
|
965
1332
|
return Array.from(result);
|
|
966
1333
|
}
|
|
@@ -975,21 +1342,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
975
1342
|
}, {
|
|
976
1343
|
key: "applyFormatters",
|
|
977
1344
|
value: (function () {
|
|
978
|
-
var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1345
|
+
var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(products, context) {
|
|
979
1346
|
var result, i, formatter, tF, errorMessage;
|
|
980
|
-
return _regeneratorRuntime().wrap(function
|
|
981
|
-
while (1) switch (
|
|
1347
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context16) {
|
|
1348
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
982
1349
|
case 0:
|
|
983
1350
|
result = products;
|
|
984
1351
|
if (!(this.formatters.length === 0)) {
|
|
985
|
-
|
|
1352
|
+
_context16.next = 5;
|
|
986
1353
|
break;
|
|
987
1354
|
}
|
|
988
1355
|
console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
|
|
989
1356
|
this.logWarning('没有注册任何格式化器', {
|
|
990
1357
|
productCount: products.length
|
|
991
1358
|
});
|
|
992
|
-
return
|
|
1359
|
+
return _context16.abrupt("return", result);
|
|
993
1360
|
case 5:
|
|
994
1361
|
this.logInfo('开始应用格式化器', {
|
|
995
1362
|
productCount: products.length,
|
|
@@ -998,28 +1365,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
998
1365
|
i = 0;
|
|
999
1366
|
case 7:
|
|
1000
1367
|
if (!(i < this.formatters.length)) {
|
|
1001
|
-
|
|
1368
|
+
_context16.next = 25;
|
|
1002
1369
|
break;
|
|
1003
1370
|
}
|
|
1004
1371
|
formatter = this.formatters[i];
|
|
1005
|
-
|
|
1372
|
+
_context16.prev = 9;
|
|
1006
1373
|
tF = performance.now();
|
|
1007
|
-
|
|
1374
|
+
_context16.next = 13;
|
|
1008
1375
|
return formatter(result, context);
|
|
1009
1376
|
case 13:
|
|
1010
|
-
result =
|
|
1377
|
+
result = _context16.sent;
|
|
1011
1378
|
perfMark("applyFormatters[".concat(i, "]"), performance.now() - tF, {
|
|
1012
1379
|
index: i,
|
|
1013
1380
|
total: this.formatters.length,
|
|
1014
1381
|
productCount: result.length
|
|
1015
1382
|
});
|
|
1016
|
-
|
|
1383
|
+
_context16.next = 22;
|
|
1017
1384
|
break;
|
|
1018
1385
|
case 17:
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
errorMessage =
|
|
1022
|
-
console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"),
|
|
1386
|
+
_context16.prev = 17;
|
|
1387
|
+
_context16.t0 = _context16["catch"](9);
|
|
1388
|
+
errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
|
|
1389
|
+
console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context16.t0);
|
|
1023
1390
|
this.logError("\u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25"), {
|
|
1024
1391
|
formatterIndex: i + 1,
|
|
1025
1392
|
totalFormatters: this.formatters.length,
|
|
@@ -1027,21 +1394,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1027
1394
|
});
|
|
1028
1395
|
case 22:
|
|
1029
1396
|
i++;
|
|
1030
|
-
|
|
1397
|
+
_context16.next = 7;
|
|
1031
1398
|
break;
|
|
1032
1399
|
case 25:
|
|
1033
1400
|
this.logInfo('所有格式化器已应用', {
|
|
1034
1401
|
formatterCount: this.formatters.length,
|
|
1035
1402
|
resultProductCount: result.length
|
|
1036
1403
|
});
|
|
1037
|
-
return
|
|
1404
|
+
return _context16.abrupt("return", result);
|
|
1038
1405
|
case 27:
|
|
1039
1406
|
case "end":
|
|
1040
|
-
return
|
|
1407
|
+
return _context16.stop();
|
|
1041
1408
|
}
|
|
1042
|
-
},
|
|
1409
|
+
}, _callee15, this, [[9, 17]]);
|
|
1043
1410
|
}));
|
|
1044
|
-
function applyFormatters(
|
|
1411
|
+
function applyFormatters(_x18, _x19) {
|
|
1045
1412
|
return _applyFormatters.apply(this, arguments);
|
|
1046
1413
|
}
|
|
1047
1414
|
return applyFormatters;
|
|
@@ -1056,18 +1423,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1056
1423
|
}, {
|
|
1057
1424
|
key: "registerBuiltinProductFormatters",
|
|
1058
1425
|
value: function registerBuiltinProductFormatters() {
|
|
1059
|
-
var
|
|
1426
|
+
var _this10 = this;
|
|
1060
1427
|
if (this.isBuiltinFormatterRegistered) {
|
|
1061
1428
|
console.warn('[ProductsModule] 内置商品格式化器已注册,跳过');
|
|
1062
1429
|
return;
|
|
1063
1430
|
}
|
|
1064
1431
|
this.isLegacyPriceFormatterEnabled = this.shouldEnableLegacyPriceFormatter();
|
|
1065
1432
|
var dataVariantFormatter = function dataVariantFormatter(products, context) {
|
|
1066
|
-
var
|
|
1067
|
-
var evaluator = context.dataVariantEvaluator || ((
|
|
1433
|
+
var _this10$core, _strategyContext$busi;
|
|
1434
|
+
var evaluator = context.dataVariantEvaluator || ((_this10$core = _this10.core) === null || _this10$core === void 0 || (_this10$core = _this10$core.context) === null || _this10$core === void 0 ? void 0 : _this10$core.dataVariantEvaluator);
|
|
1068
1435
|
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
1069
|
-
|
|
1070
|
-
|
|
1436
|
+
_this10.lastScheduleTimePoints = [];
|
|
1437
|
+
_this10.logWarning('智能定价评估器未注入,跳过 DataVariant 格式化', {
|
|
1071
1438
|
productCount: products.length
|
|
1072
1439
|
});
|
|
1073
1440
|
return products;
|
|
@@ -1086,7 +1453,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1086
1453
|
custom: strategyContext
|
|
1087
1454
|
};
|
|
1088
1455
|
var result = evaluator.resolveProducts(businessData);
|
|
1089
|
-
|
|
1456
|
+
_this10.lastScheduleTimePoints = Array.isArray(result === null || result === void 0 ? void 0 : result.scheduleTimePoints) ? _toConsumableArray(result.scheduleTimePoints) : [];
|
|
1090
1457
|
return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
|
|
1091
1458
|
};
|
|
1092
1459
|
|
|
@@ -1193,6 +1560,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1193
1560
|
var keys = Array.from(this.productsPriceCache.keys());
|
|
1194
1561
|
var oldestKey = keys[0];
|
|
1195
1562
|
this.productsPriceCache.delete(oldestKey);
|
|
1563
|
+
this.replicaPriceDirtyIds.delete(oldestKey);
|
|
1196
1564
|
}
|
|
1197
1565
|
}
|
|
1198
1566
|
|
|
@@ -1204,6 +1572,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1204
1572
|
key: "clearPriceCache",
|
|
1205
1573
|
value: function clearPriceCache() {
|
|
1206
1574
|
this.productsPriceCache.clear();
|
|
1575
|
+
this.replicaPriceDirtyIds.clear();
|
|
1207
1576
|
this.quotationScheduleCache.clear();
|
|
1208
1577
|
this.quotationScheduleCacheLoaded = false;
|
|
1209
1578
|
}
|
|
@@ -1214,7 +1583,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1214
1583
|
}, {
|
|
1215
1584
|
key: "loadProductsByServer",
|
|
1216
1585
|
value: (function () {
|
|
1217
|
-
var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1586
|
+
var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
1218
1587
|
var options,
|
|
1219
1588
|
trigger,
|
|
1220
1589
|
t0,
|
|
@@ -1223,32 +1592,44 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1223
1592
|
list,
|
|
1224
1593
|
duration,
|
|
1225
1594
|
errorMessage,
|
|
1226
|
-
|
|
1227
|
-
return _regeneratorRuntime().wrap(function
|
|
1228
|
-
while (1) switch (
|
|
1595
|
+
_args17 = arguments;
|
|
1596
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context17) {
|
|
1597
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1229
1598
|
case 0:
|
|
1230
|
-
options =
|
|
1599
|
+
options = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : {};
|
|
1600
|
+
if (!this.isMemoryReplica()) {
|
|
1601
|
+
_context17.next = 3;
|
|
1602
|
+
break;
|
|
1603
|
+
}
|
|
1604
|
+
return _context17.abrupt("return", this.refreshFromReplica(options.trigger || 'loadProductsByServer'));
|
|
1605
|
+
case 3:
|
|
1231
1606
|
if (this.productDataSource) {
|
|
1232
|
-
|
|
1607
|
+
_context17.next = 6;
|
|
1233
1608
|
break;
|
|
1234
1609
|
}
|
|
1235
1610
|
this.logWarning('loadProductsByServer: ProductDataSource 不可用');
|
|
1236
|
-
return
|
|
1237
|
-
case
|
|
1611
|
+
return _context17.abrupt("return", []);
|
|
1612
|
+
case 6:
|
|
1238
1613
|
trigger = options.trigger || 'unknown';
|
|
1239
1614
|
this.logInfo('开始通过 DataSource SSE 加载商品列表', {
|
|
1240
1615
|
trigger: trigger
|
|
1241
1616
|
});
|
|
1242
1617
|
t0 = performance.now();
|
|
1243
|
-
|
|
1618
|
+
_context17.prev = 9;
|
|
1244
1619
|
tSSE = performance.now();
|
|
1245
|
-
|
|
1620
|
+
_context17.next = 13;
|
|
1246
1621
|
return this.productDataSource.run({
|
|
1247
1622
|
sse: {}
|
|
1248
1623
|
});
|
|
1249
|
-
case
|
|
1250
|
-
productList =
|
|
1624
|
+
case 13:
|
|
1625
|
+
productList = _context17.sent;
|
|
1251
1626
|
list = productList || [];
|
|
1627
|
+
if (!this.isMemoryReplica()) {
|
|
1628
|
+
_context17.next = 17;
|
|
1629
|
+
break;
|
|
1630
|
+
}
|
|
1631
|
+
return _context17.abrupt("return", this.store.list);
|
|
1632
|
+
case 17:
|
|
1252
1633
|
perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
|
|
1253
1634
|
count: list.length
|
|
1254
1635
|
});
|
|
@@ -1257,34 +1638,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1257
1638
|
productCount: list.length,
|
|
1258
1639
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
1259
1640
|
});
|
|
1260
|
-
|
|
1641
|
+
_context17.next = 21;
|
|
1261
1642
|
return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
|
|
1262
|
-
case
|
|
1643
|
+
case 21:
|
|
1263
1644
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1264
|
-
|
|
1645
|
+
_context17.next = 24;
|
|
1265
1646
|
return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
|
|
1266
|
-
case
|
|
1647
|
+
case 24:
|
|
1267
1648
|
perfMark('loadProductsByServer', performance.now() - t0, {
|
|
1268
1649
|
count: list.length
|
|
1269
1650
|
});
|
|
1270
|
-
return
|
|
1271
|
-
case
|
|
1272
|
-
|
|
1273
|
-
|
|
1651
|
+
return _context17.abrupt("return", list);
|
|
1652
|
+
case 28:
|
|
1653
|
+
_context17.prev = 28;
|
|
1654
|
+
_context17.t0 = _context17["catch"](9);
|
|
1274
1655
|
duration = Math.round(performance.now() - t0);
|
|
1275
|
-
errorMessage =
|
|
1276
|
-
console.error('[Products] 加载商品数据失败:',
|
|
1656
|
+
errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
|
|
1657
|
+
console.error('[Products] 加载商品数据失败:', _context17.t0);
|
|
1277
1658
|
this.logError('通过 DataSource SSE 加载商品列表失败', {
|
|
1278
1659
|
trigger: trigger,
|
|
1279
1660
|
duration: "".concat(duration, "ms"),
|
|
1280
1661
|
error: errorMessage
|
|
1281
1662
|
});
|
|
1282
|
-
return
|
|
1283
|
-
case
|
|
1663
|
+
return _context17.abrupt("return", []);
|
|
1664
|
+
case 35:
|
|
1284
1665
|
case "end":
|
|
1285
|
-
return
|
|
1666
|
+
return _context17.stop();
|
|
1286
1667
|
}
|
|
1287
|
-
},
|
|
1668
|
+
}, _callee16, this, [[9, 28]]);
|
|
1288
1669
|
}));
|
|
1289
1670
|
function loadProductsByServer() {
|
|
1290
1671
|
return _loadProductsByServer.apply(this, arguments);
|
|
@@ -1300,12 +1681,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1300
1681
|
}, {
|
|
1301
1682
|
key: "fetchProductsByHttp",
|
|
1302
1683
|
value: (function () {
|
|
1303
|
-
var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1304
|
-
var
|
|
1305
|
-
return _regeneratorRuntime().wrap(function
|
|
1306
|
-
while (1) switch (
|
|
1684
|
+
var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
|
|
1685
|
+
var _ref16, _ref16$category_ids, category_ids, _ref16$product_ids, product_ids, _ref16$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
|
|
1686
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context18) {
|
|
1687
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1307
1688
|
case 0:
|
|
1308
|
-
|
|
1689
|
+
_ref16 = params || {}, _ref16$category_ids = _ref16.category_ids, category_ids = _ref16$category_ids === void 0 ? [] : _ref16$category_ids, _ref16$product_ids = _ref16.product_ids, product_ids = _ref16$product_ids === void 0 ? [] : _ref16$product_ids, _ref16$collection = _ref16.collection, collection = _ref16$collection === void 0 ? [] : _ref16$collection, customer_id = _ref16.customer_id, cacheId = _ref16.cacheId;
|
|
1309
1690
|
this.logInfo('fetchProductsByHttp: 开始请求', {
|
|
1310
1691
|
categoryIdsCount: category_ids.length,
|
|
1311
1692
|
productIdsCount: product_ids.length,
|
|
@@ -1313,8 +1694,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1313
1694
|
customer_id: customer_id
|
|
1314
1695
|
});
|
|
1315
1696
|
startTime = Date.now();
|
|
1316
|
-
|
|
1317
|
-
|
|
1697
|
+
_context18.prev = 3;
|
|
1698
|
+
_context18.next = 6;
|
|
1318
1699
|
return this.request.post("/product/query", {
|
|
1319
1700
|
open_bundle: 1,
|
|
1320
1701
|
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
@@ -1336,32 +1717,32 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1336
1717
|
cache: undefined
|
|
1337
1718
|
});
|
|
1338
1719
|
case 6:
|
|
1339
|
-
productsData =
|
|
1720
|
+
productsData = _context18.sent;
|
|
1340
1721
|
productList = (productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || [];
|
|
1341
1722
|
duration = Date.now() - startTime;
|
|
1342
1723
|
this.logInfo('fetchProductsByHttp: 请求成功', {
|
|
1343
1724
|
productCount: productList.length,
|
|
1344
1725
|
duration: "".concat(duration, "ms")
|
|
1345
1726
|
});
|
|
1346
|
-
return
|
|
1727
|
+
return _context18.abrupt("return", productList);
|
|
1347
1728
|
case 13:
|
|
1348
|
-
|
|
1349
|
-
|
|
1729
|
+
_context18.prev = 13;
|
|
1730
|
+
_context18.t0 = _context18["catch"](3);
|
|
1350
1731
|
_duration2 = Date.now() - startTime;
|
|
1351
|
-
errorMessage =
|
|
1352
|
-
console.error('[Products] fetchProductsByHttp 失败:',
|
|
1732
|
+
errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
|
|
1733
|
+
console.error('[Products] fetchProductsByHttp 失败:', _context18.t0);
|
|
1353
1734
|
this.logError('fetchProductsByHttp: 请求失败', {
|
|
1354
1735
|
duration: "".concat(_duration2, "ms"),
|
|
1355
1736
|
error: errorMessage
|
|
1356
1737
|
});
|
|
1357
|
-
return
|
|
1738
|
+
return _context18.abrupt("return", []);
|
|
1358
1739
|
case 20:
|
|
1359
1740
|
case "end":
|
|
1360
|
-
return
|
|
1741
|
+
return _context18.stop();
|
|
1361
1742
|
}
|
|
1362
|
-
},
|
|
1743
|
+
}, _callee17, this, [[3, 13]]);
|
|
1363
1744
|
}));
|
|
1364
|
-
function fetchProductsByHttp(
|
|
1745
|
+
function fetchProductsByHttp(_x20) {
|
|
1365
1746
|
return _fetchProductsByHttp.apply(this, arguments);
|
|
1366
1747
|
}
|
|
1367
1748
|
return fetchProductsByHttp;
|
|
@@ -1375,34 +1756,46 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1375
1756
|
}, {
|
|
1376
1757
|
key: "loadProductsByServerHttp",
|
|
1377
1758
|
value: (function () {
|
|
1378
|
-
var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1759
|
+
var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
|
|
1379
1760
|
var productList;
|
|
1380
|
-
return _regeneratorRuntime().wrap(function
|
|
1381
|
-
while (1) switch (
|
|
1761
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context19) {
|
|
1762
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1382
1763
|
case 0:
|
|
1383
|
-
|
|
1384
|
-
|
|
1764
|
+
if (!this.isMemoryReplica()) {
|
|
1765
|
+
_context19.next = 2;
|
|
1766
|
+
break;
|
|
1767
|
+
}
|
|
1768
|
+
return _context19.abrupt("return", this.refreshFromReplica('loadProductsByServerHttp'));
|
|
1385
1769
|
case 2:
|
|
1386
|
-
|
|
1770
|
+
_context19.next = 4;
|
|
1771
|
+
return this.fetchProductsByHttp(params);
|
|
1772
|
+
case 4:
|
|
1773
|
+
productList = _context19.sent;
|
|
1774
|
+
if (!this.isMemoryReplica()) {
|
|
1775
|
+
_context19.next = 7;
|
|
1776
|
+
break;
|
|
1777
|
+
}
|
|
1778
|
+
return _context19.abrupt("return", this.store.list);
|
|
1779
|
+
case 7:
|
|
1387
1780
|
if (!(productList.length > 0)) {
|
|
1388
|
-
|
|
1781
|
+
_context19.next = 13;
|
|
1389
1782
|
break;
|
|
1390
1783
|
}
|
|
1391
|
-
|
|
1784
|
+
_context19.next = 10;
|
|
1392
1785
|
return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
|
|
1393
|
-
case
|
|
1786
|
+
case 10:
|
|
1394
1787
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1395
|
-
|
|
1788
|
+
_context19.next = 13;
|
|
1396
1789
|
return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
|
|
1397
|
-
case
|
|
1398
|
-
return
|
|
1399
|
-
case
|
|
1790
|
+
case 13:
|
|
1791
|
+
return _context19.abrupt("return", productList);
|
|
1792
|
+
case 14:
|
|
1400
1793
|
case "end":
|
|
1401
|
-
return
|
|
1794
|
+
return _context19.stop();
|
|
1402
1795
|
}
|
|
1403
|
-
},
|
|
1796
|
+
}, _callee18, this);
|
|
1404
1797
|
}));
|
|
1405
|
-
function loadProductsByServerHttp(
|
|
1798
|
+
function loadProductsByServerHttp(_x21) {
|
|
1406
1799
|
return _loadProductsByServerHttp.apply(this, arguments);
|
|
1407
1800
|
}
|
|
1408
1801
|
return loadProductsByServerHttp;
|
|
@@ -1414,22 +1807,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1414
1807
|
}, {
|
|
1415
1808
|
key: "getProducts",
|
|
1416
1809
|
value: (function () {
|
|
1417
|
-
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1810
|
+
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
1418
1811
|
var t0, result;
|
|
1419
|
-
return _regeneratorRuntime().wrap(function
|
|
1420
|
-
while (1) switch (
|
|
1812
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context20) {
|
|
1813
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1421
1814
|
case 0:
|
|
1422
1815
|
t0 = performance.now();
|
|
1423
1816
|
result = structuredClone(this.store.list);
|
|
1424
1817
|
perfMark('ProductsModule.getProducts(structuredClone)', performance.now() - t0, {
|
|
1425
1818
|
count: result.length
|
|
1426
1819
|
});
|
|
1427
|
-
return
|
|
1820
|
+
return _context20.abrupt("return", result);
|
|
1428
1821
|
case 4:
|
|
1429
1822
|
case "end":
|
|
1430
|
-
return
|
|
1823
|
+
return _context20.stop();
|
|
1431
1824
|
}
|
|
1432
|
-
},
|
|
1825
|
+
}, _callee19, this);
|
|
1433
1826
|
}));
|
|
1434
1827
|
function getProducts() {
|
|
1435
1828
|
return _getProducts.apply(this, arguments);
|
|
@@ -1443,63 +1836,63 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1443
1836
|
}, {
|
|
1444
1837
|
key: "getProductSnapshotsByIds",
|
|
1445
1838
|
value: (function () {
|
|
1446
|
-
var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1447
|
-
var snapshots, seen,
|
|
1448
|
-
return _regeneratorRuntime().wrap(function
|
|
1449
|
-
while (1) switch (
|
|
1839
|
+
var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(ids) {
|
|
1840
|
+
var snapshots, seen, _iterator9, _step9, _resolveProductHolder, id, product;
|
|
1841
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context21) {
|
|
1842
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1450
1843
|
case 0:
|
|
1451
1844
|
snapshots = {};
|
|
1452
1845
|
seen = new Set();
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1846
|
+
_iterator9 = _createForOfIteratorHelper(ids);
|
|
1847
|
+
_context21.prev = 3;
|
|
1848
|
+
_iterator9.s();
|
|
1456
1849
|
case 5:
|
|
1457
|
-
if ((
|
|
1458
|
-
|
|
1850
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1851
|
+
_context21.next = 16;
|
|
1459
1852
|
break;
|
|
1460
1853
|
}
|
|
1461
|
-
id =
|
|
1854
|
+
id = _step9.value;
|
|
1462
1855
|
if (!(!Number.isFinite(id) || seen.has(id))) {
|
|
1463
|
-
|
|
1856
|
+
_context21.next = 9;
|
|
1464
1857
|
break;
|
|
1465
1858
|
}
|
|
1466
|
-
return
|
|
1859
|
+
return _context21.abrupt("continue", 14);
|
|
1467
1860
|
case 9:
|
|
1468
1861
|
seen.add(id);
|
|
1469
1862
|
product = this.store.map.get(id);
|
|
1470
1863
|
if (product) {
|
|
1471
|
-
|
|
1864
|
+
_context21.next = 13;
|
|
1472
1865
|
break;
|
|
1473
1866
|
}
|
|
1474
|
-
return
|
|
1867
|
+
return _context21.abrupt("continue", 14);
|
|
1475
1868
|
case 13:
|
|
1476
1869
|
snapshots[String(id)] = {
|
|
1477
1870
|
cover: product.cover,
|
|
1478
|
-
holder_config: product
|
|
1871
|
+
holder_config: (_resolveProductHolder = resolveProductHolderConfig(product)) !== null && _resolveProductHolder !== void 0 ? _resolveProductHolder : undefined
|
|
1479
1872
|
};
|
|
1480
1873
|
case 14:
|
|
1481
|
-
|
|
1874
|
+
_context21.next = 5;
|
|
1482
1875
|
break;
|
|
1483
1876
|
case 16:
|
|
1484
|
-
|
|
1877
|
+
_context21.next = 21;
|
|
1485
1878
|
break;
|
|
1486
1879
|
case 18:
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1880
|
+
_context21.prev = 18;
|
|
1881
|
+
_context21.t0 = _context21["catch"](3);
|
|
1882
|
+
_iterator9.e(_context21.t0);
|
|
1490
1883
|
case 21:
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
return
|
|
1884
|
+
_context21.prev = 21;
|
|
1885
|
+
_iterator9.f();
|
|
1886
|
+
return _context21.finish(21);
|
|
1494
1887
|
case 24:
|
|
1495
|
-
return
|
|
1888
|
+
return _context21.abrupt("return", snapshots);
|
|
1496
1889
|
case 25:
|
|
1497
1890
|
case "end":
|
|
1498
|
-
return
|
|
1891
|
+
return _context21.stop();
|
|
1499
1892
|
}
|
|
1500
|
-
},
|
|
1893
|
+
}, _callee20, this, [[3, 18, 21, 24]]);
|
|
1501
1894
|
}));
|
|
1502
|
-
function getProductSnapshotsByIds(
|
|
1895
|
+
function getProductSnapshotsByIds(_x22) {
|
|
1503
1896
|
return _getProductSnapshotsByIds.apply(this, arguments);
|
|
1504
1897
|
}
|
|
1505
1898
|
return getProductSnapshotsByIds;
|
|
@@ -1522,18 +1915,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1522
1915
|
key: "getProductsRefByIds",
|
|
1523
1916
|
value: function getProductsRefByIds(ids) {
|
|
1524
1917
|
var products = [];
|
|
1525
|
-
var
|
|
1526
|
-
|
|
1918
|
+
var _iterator10 = _createForOfIteratorHelper(ids),
|
|
1919
|
+
_step10;
|
|
1527
1920
|
try {
|
|
1528
|
-
for (
|
|
1529
|
-
var id =
|
|
1921
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1922
|
+
var id = _step10.value;
|
|
1530
1923
|
var product = this.store.map.get(id);
|
|
1531
1924
|
if (product) products.push(product);
|
|
1532
1925
|
}
|
|
1533
1926
|
} catch (err) {
|
|
1534
|
-
|
|
1927
|
+
_iterator10.e(err);
|
|
1535
1928
|
} finally {
|
|
1536
|
-
|
|
1929
|
+
_iterator10.f();
|
|
1537
1930
|
}
|
|
1538
1931
|
return products;
|
|
1539
1932
|
}
|
|
@@ -1545,20 +1938,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1545
1938
|
}, {
|
|
1546
1939
|
key: "getProductById",
|
|
1547
1940
|
value: (function () {
|
|
1548
|
-
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1941
|
+
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(id) {
|
|
1549
1942
|
var product;
|
|
1550
|
-
return _regeneratorRuntime().wrap(function
|
|
1551
|
-
while (1) switch (
|
|
1943
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context22) {
|
|
1944
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1552
1945
|
case 0:
|
|
1553
1946
|
product = this.store.map.get(id);
|
|
1554
|
-
return
|
|
1947
|
+
return _context22.abrupt("return", product ? structuredClone(product) : undefined);
|
|
1555
1948
|
case 2:
|
|
1556
1949
|
case "end":
|
|
1557
|
-
return
|
|
1950
|
+
return _context22.stop();
|
|
1558
1951
|
}
|
|
1559
|
-
},
|
|
1952
|
+
}, _callee21, this);
|
|
1560
1953
|
}));
|
|
1561
|
-
function getProductById(
|
|
1954
|
+
function getProductById(_x23) {
|
|
1562
1955
|
return _getProductById.apply(this, arguments);
|
|
1563
1956
|
}
|
|
1564
1957
|
return getProductById;
|
|
@@ -1571,11 +1964,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1571
1964
|
}, {
|
|
1572
1965
|
key: "removeProductsByIds",
|
|
1573
1966
|
value: (function () {
|
|
1574
|
-
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1575
|
-
var idSet,
|
|
1576
|
-
return _regeneratorRuntime().wrap(function
|
|
1577
|
-
while (1) switch (
|
|
1967
|
+
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(ids, options) {
|
|
1968
|
+
var idSet, _iterator11, _step11, id, _iterator12, _step12, _step12$value, dateKey, cachedProducts;
|
|
1969
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context23) {
|
|
1970
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1578
1971
|
case 0:
|
|
1972
|
+
if (!(this.isMemoryReplica() && !(options !== null && options !== void 0 && options.skipIndexDB))) {
|
|
1973
|
+
_context23.next = 4;
|
|
1974
|
+
break;
|
|
1975
|
+
}
|
|
1976
|
+
_context23.next = 3;
|
|
1977
|
+
return this.refreshFromReplica('removeProducts');
|
|
1978
|
+
case 3:
|
|
1979
|
+
return _context23.abrupt("return");
|
|
1980
|
+
case 4:
|
|
1579
1981
|
idSet = new Set(ids);
|
|
1580
1982
|
this.logInfo('removeProductsByIds', {
|
|
1581
1983
|
ids: ids,
|
|
@@ -1584,83 +1986,48 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1584
1986
|
this.store.list = this.store.list.filter(function (p) {
|
|
1585
1987
|
return !idSet.has(p.id);
|
|
1586
1988
|
});
|
|
1587
|
-
|
|
1989
|
+
_iterator11 = _createForOfIteratorHelper(ids);
|
|
1588
1990
|
try {
|
|
1589
|
-
for (
|
|
1590
|
-
|
|
1591
|
-
this.store.map.delete(
|
|
1991
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1992
|
+
id = _step11.value;
|
|
1993
|
+
this.store.map.delete(id);
|
|
1592
1994
|
}
|
|
1593
1995
|
} catch (err) {
|
|
1594
|
-
|
|
1996
|
+
_iterator11.e(err);
|
|
1595
1997
|
} finally {
|
|
1596
|
-
|
|
1597
|
-
}
|
|
1598
|
-
if (!this.dbManager) {
|
|
1599
|
-
_context15.next = 30;
|
|
1600
|
-
break;
|
|
1998
|
+
_iterator11.f();
|
|
1601
1999
|
}
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
_context15.prev = 8;
|
|
1605
|
-
_iterator9.s();
|
|
1606
|
-
case 10:
|
|
1607
|
-
if ((_step9 = _iterator9.n()).done) {
|
|
1608
|
-
_context15.next = 16;
|
|
2000
|
+
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2001
|
+
_context23.next = 12;
|
|
1609
2002
|
break;
|
|
1610
2003
|
}
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
_context15.next = 10;
|
|
1616
|
-
break;
|
|
1617
|
-
case 16:
|
|
1618
|
-
_context15.next = 21;
|
|
1619
|
-
break;
|
|
1620
|
-
case 18:
|
|
1621
|
-
_context15.prev = 18;
|
|
1622
|
-
_context15.t0 = _context15["catch"](8);
|
|
1623
|
-
_iterator9.e(_context15.t0);
|
|
1624
|
-
case 21:
|
|
1625
|
-
_context15.prev = 21;
|
|
1626
|
-
_iterator9.f();
|
|
1627
|
-
return _context15.finish(21);
|
|
1628
|
-
case 24:
|
|
1629
|
-
_context15.next = 30;
|
|
1630
|
-
break;
|
|
1631
|
-
case 26:
|
|
1632
|
-
_context15.prev = 26;
|
|
1633
|
-
_context15.t1 = _context15["catch"](6);
|
|
1634
|
-
errorMessage = _context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1);
|
|
1635
|
-
this.logError('removeProductsByIds: IndexDB 删除失败', {
|
|
1636
|
-
ids: ids,
|
|
1637
|
-
error: errorMessage
|
|
1638
|
-
});
|
|
1639
|
-
case 30:
|
|
1640
|
-
_iterator10 = _createForOfIteratorHelper(this.productsPriceCache.entries());
|
|
2004
|
+
_context23.next = 12;
|
|
2005
|
+
return this.persistProductDelta([], ids, 'removeProductsByIds');
|
|
2006
|
+
case 12:
|
|
2007
|
+
_iterator12 = _createForOfIteratorHelper(this.productsPriceCache.entries());
|
|
1641
2008
|
try {
|
|
1642
|
-
for (
|
|
1643
|
-
|
|
2009
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
2010
|
+
_step12$value = _slicedToArray(_step12.value, 2), dateKey = _step12$value[0], cachedProducts = _step12$value[1];
|
|
1644
2011
|
this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
|
|
1645
2012
|
return !idSet.has(p.id);
|
|
1646
2013
|
}));
|
|
1647
2014
|
}
|
|
1648
2015
|
} catch (err) {
|
|
1649
|
-
|
|
2016
|
+
_iterator12.e(err);
|
|
1650
2017
|
} finally {
|
|
1651
|
-
|
|
2018
|
+
_iterator12.f();
|
|
1652
2019
|
}
|
|
1653
|
-
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2020
|
+
if (!(options !== null && options !== void 0 && options.skipEmit)) this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
1654
2021
|
this.logInfo('removeProductsByIds 完成', {
|
|
1655
2022
|
remaining: this.store.list.length
|
|
1656
2023
|
});
|
|
1657
|
-
case
|
|
2024
|
+
case 16:
|
|
1658
2025
|
case "end":
|
|
1659
|
-
return
|
|
2026
|
+
return _context23.stop();
|
|
1660
2027
|
}
|
|
1661
|
-
},
|
|
2028
|
+
}, _callee22, this);
|
|
1662
2029
|
}));
|
|
1663
|
-
function removeProductsByIds(
|
|
2030
|
+
function removeProductsByIds(_x24, _x25) {
|
|
1664
2031
|
return _removeProductsByIds.apply(this, arguments);
|
|
1665
2032
|
}
|
|
1666
2033
|
return removeProductsByIds;
|
|
@@ -1673,19 +2040,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1673
2040
|
}, {
|
|
1674
2041
|
key: "refreshProducts",
|
|
1675
2042
|
value: (function () {
|
|
1676
|
-
var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2043
|
+
var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
1677
2044
|
var tTotal, products;
|
|
1678
|
-
return _regeneratorRuntime().wrap(function
|
|
1679
|
-
while (1) switch (
|
|
2045
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context24) {
|
|
2046
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1680
2047
|
case 0:
|
|
2048
|
+
if (!this.isMemoryReplica()) {
|
|
2049
|
+
_context24.next = 2;
|
|
2050
|
+
break;
|
|
2051
|
+
}
|
|
2052
|
+
return _context24.abrupt("return", this.refreshFromReplica('refreshProducts'));
|
|
2053
|
+
case 2:
|
|
1681
2054
|
tTotal = performance.now();
|
|
1682
2055
|
this.logInfo('refreshProducts 开始');
|
|
1683
|
-
|
|
2056
|
+
_context24.next = 6;
|
|
1684
2057
|
return this.loadProductsByServer({
|
|
1685
2058
|
trigger: 'product_sync'
|
|
1686
2059
|
});
|
|
1687
|
-
case
|
|
1688
|
-
products =
|
|
2060
|
+
case 6:
|
|
2061
|
+
products = _context24.sent;
|
|
1689
2062
|
if (products && products.length > 0) {
|
|
1690
2063
|
// 服务器返回的数据已经是全新的,无需 cloneDeep
|
|
1691
2064
|
this.store.list = products;
|
|
@@ -1700,12 +2073,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1700
2073
|
perfMark('refreshProducts', performance.now() - tTotal, {
|
|
1701
2074
|
count: this.store.list.length
|
|
1702
2075
|
});
|
|
1703
|
-
return
|
|
1704
|
-
case
|
|
2076
|
+
return _context24.abrupt("return", this.store.list);
|
|
2077
|
+
case 10:
|
|
1705
2078
|
case "end":
|
|
1706
|
-
return
|
|
2079
|
+
return _context24.stop();
|
|
1707
2080
|
}
|
|
1708
|
-
},
|
|
2081
|
+
}, _callee23, this);
|
|
1709
2082
|
}));
|
|
1710
2083
|
function refreshProducts() {
|
|
1711
2084
|
return _refreshProducts.apply(this, arguments);
|
|
@@ -1719,10 +2092,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1719
2092
|
}, {
|
|
1720
2093
|
key: "clear",
|
|
1721
2094
|
value: (function () {
|
|
1722
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2095
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
1723
2096
|
var errorMessage;
|
|
1724
|
-
return _regeneratorRuntime().wrap(function
|
|
1725
|
-
while (1) switch (
|
|
2097
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context25) {
|
|
2098
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1726
2099
|
case 0:
|
|
1727
2100
|
this.logInfo('开始清空缓存', {
|
|
1728
2101
|
currentProductCount: this.store.list.length,
|
|
@@ -1733,21 +2106,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1733
2106
|
|
|
1734
2107
|
// 同时清空 IndexDB 中的所有数据(包括商品和元数据)
|
|
1735
2108
|
if (!this.dbManager) {
|
|
1736
|
-
|
|
2109
|
+
_context25.next = 15;
|
|
1737
2110
|
break;
|
|
1738
2111
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
2112
|
+
_context25.prev = 4;
|
|
2113
|
+
_context25.next = 7;
|
|
1741
2114
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1742
2115
|
case 7:
|
|
1743
2116
|
this.logInfo('IndexDB 缓存已清空');
|
|
1744
|
-
|
|
2117
|
+
_context25.next = 15;
|
|
1745
2118
|
break;
|
|
1746
2119
|
case 10:
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
errorMessage =
|
|
1750
|
-
console.error('[Products] 清空 IndexDB 缓存失败:',
|
|
2120
|
+
_context25.prev = 10;
|
|
2121
|
+
_context25.t0 = _context25["catch"](4);
|
|
2122
|
+
errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
|
|
2123
|
+
console.error('[Products] 清空 IndexDB 缓存失败:', _context25.t0);
|
|
1751
2124
|
this.logError('清空 IndexDB 缓存失败', {
|
|
1752
2125
|
error: errorMessage
|
|
1753
2126
|
});
|
|
@@ -1755,9 +2128,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1755
2128
|
this.logInfo('缓存清空完成');
|
|
1756
2129
|
case 16:
|
|
1757
2130
|
case "end":
|
|
1758
|
-
return
|
|
2131
|
+
return _context25.stop();
|
|
1759
2132
|
}
|
|
1760
|
-
},
|
|
2133
|
+
}, _callee24, this, [[4, 10]]);
|
|
1761
2134
|
}));
|
|
1762
2135
|
function clear() {
|
|
1763
2136
|
return _clear.apply(this, arguments);
|
|
@@ -1772,24 +2145,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1772
2145
|
}, {
|
|
1773
2146
|
key: "loadProductsFromIndexDB",
|
|
1774
2147
|
value: (function () {
|
|
1775
|
-
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2148
|
+
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1776
2149
|
var startedAt, _products$length, _products$length2, products, durationMs, errorMessage;
|
|
1777
|
-
return _regeneratorRuntime().wrap(function
|
|
1778
|
-
while (1) switch (
|
|
2150
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context26) {
|
|
2151
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1779
2152
|
case 0:
|
|
1780
2153
|
if (this.dbManager) {
|
|
1781
|
-
|
|
2154
|
+
_context26.next = 3;
|
|
1782
2155
|
break;
|
|
1783
2156
|
}
|
|
1784
2157
|
this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
|
|
1785
|
-
return
|
|
2158
|
+
return _context26.abrupt("return", []);
|
|
1786
2159
|
case 3:
|
|
1787
2160
|
startedAt = performance.now();
|
|
1788
|
-
|
|
1789
|
-
|
|
2161
|
+
_context26.prev = 4;
|
|
2162
|
+
_context26.next = 7;
|
|
1790
2163
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
1791
2164
|
case 7:
|
|
1792
|
-
products =
|
|
2165
|
+
products = _context26.sent;
|
|
1793
2166
|
durationMs = +(performance.now() - startedAt).toFixed(2);
|
|
1794
2167
|
perfMark('loadProductsFromIndexDB', durationMs, {
|
|
1795
2168
|
count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
|
|
@@ -1798,22 +2171,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1798
2171
|
productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0,
|
|
1799
2172
|
durationMs: durationMs
|
|
1800
2173
|
});
|
|
1801
|
-
return
|
|
2174
|
+
return _context26.abrupt("return", products || []);
|
|
1802
2175
|
case 14:
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
errorMessage =
|
|
1806
|
-
console.error('[Products] 从 IndexDB 读取数据失败:',
|
|
2176
|
+
_context26.prev = 14;
|
|
2177
|
+
_context26.t0 = _context26["catch"](4);
|
|
2178
|
+
errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
|
|
2179
|
+
console.error('[Products] 从 IndexDB 读取数据失败:', _context26.t0);
|
|
1807
2180
|
this.logError('从 IndexDB 读取数据失败', {
|
|
1808
2181
|
durationMs: +(performance.now() - startedAt).toFixed(2),
|
|
1809
2182
|
error: errorMessage
|
|
1810
2183
|
});
|
|
1811
|
-
return
|
|
2184
|
+
return _context26.abrupt("return", []);
|
|
1812
2185
|
case 20:
|
|
1813
2186
|
case "end":
|
|
1814
|
-
return
|
|
2187
|
+
return _context26.stop();
|
|
1815
2188
|
}
|
|
1816
|
-
},
|
|
2189
|
+
}, _callee25, this, [[4, 14]]);
|
|
1817
2190
|
}));
|
|
1818
2191
|
function loadProductsFromIndexDB() {
|
|
1819
2192
|
return _loadProductsFromIndexDB.apply(this, arguments);
|
|
@@ -1832,10 +2205,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1832
2205
|
}, {
|
|
1833
2206
|
key: "runInProductIndexDBSaveQueue",
|
|
1834
2207
|
value: (function () {
|
|
1835
|
-
var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2208
|
+
var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(task) {
|
|
1836
2209
|
var queuedTask;
|
|
1837
|
-
return _regeneratorRuntime().wrap(function
|
|
1838
|
-
while (1) switch (
|
|
2210
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context27) {
|
|
2211
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
1839
2212
|
case 0:
|
|
1840
2213
|
queuedTask = this.productIndexDBSaveQueue.then(task, task);
|
|
1841
2214
|
this.productIndexDBSaveQueue = queuedTask.then(function () {
|
|
@@ -1843,14 +2216,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1843
2216
|
}, function () {
|
|
1844
2217
|
return undefined;
|
|
1845
2218
|
});
|
|
1846
|
-
return
|
|
2219
|
+
return _context27.abrupt("return", queuedTask);
|
|
1847
2220
|
case 3:
|
|
1848
2221
|
case "end":
|
|
1849
|
-
return
|
|
2222
|
+
return _context27.stop();
|
|
1850
2223
|
}
|
|
1851
|
-
},
|
|
2224
|
+
}, _callee26, this);
|
|
1852
2225
|
}));
|
|
1853
|
-
function runInProductIndexDBSaveQueue(
|
|
2226
|
+
function runInProductIndexDBSaveQueue(_x26) {
|
|
1854
2227
|
return _runInProductIndexDBSaveQueue.apply(this, arguments);
|
|
1855
2228
|
}
|
|
1856
2229
|
return runInProductIndexDBSaveQueue;
|
|
@@ -1865,64 +2238,77 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1865
2238
|
}, {
|
|
1866
2239
|
key: "replaceProductsSnapshotInIndexDB",
|
|
1867
2240
|
value: (function () {
|
|
1868
|
-
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1869
|
-
var
|
|
2241
|
+
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(products, source) {
|
|
2242
|
+
var _this11 = this;
|
|
1870
2243
|
var enqueuedAt, queueWaitMs, clearDurationMs, writeDurationMs, errorMessage;
|
|
1871
|
-
return _regeneratorRuntime().wrap(function
|
|
1872
|
-
while (1) switch (
|
|
2244
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context29) {
|
|
2245
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1873
2246
|
case 0:
|
|
2247
|
+
if (!this.isMemoryReplica()) {
|
|
2248
|
+
_context29.next = 2;
|
|
2249
|
+
break;
|
|
2250
|
+
}
|
|
2251
|
+
return _context29.abrupt("return", false);
|
|
2252
|
+
case 2:
|
|
1874
2253
|
if (this.dbManager) {
|
|
1875
|
-
|
|
2254
|
+
_context29.next = 5;
|
|
1876
2255
|
break;
|
|
1877
2256
|
}
|
|
1878
2257
|
this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
|
|
1879
|
-
return
|
|
1880
|
-
case
|
|
2258
|
+
return _context29.abrupt("return", false);
|
|
2259
|
+
case 5:
|
|
1881
2260
|
enqueuedAt = performance.now();
|
|
1882
2261
|
queueWaitMs = 0;
|
|
1883
2262
|
clearDurationMs = 0;
|
|
1884
2263
|
writeDurationMs = 0;
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2264
|
+
_context29.prev = 9;
|
|
2265
|
+
_context29.next = 12;
|
|
2266
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
1888
2267
|
var operationStartedAt, clearStartedAt, writeStartedAt, executeDurationMs;
|
|
1889
|
-
return _regeneratorRuntime().wrap(function
|
|
1890
|
-
while (1) switch (
|
|
2268
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
2269
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
1891
2270
|
case 0:
|
|
1892
2271
|
operationStartedAt = performance.now();
|
|
1893
2272
|
queueWaitMs = +(operationStartedAt - enqueuedAt).toFixed(2);
|
|
1894
|
-
|
|
2273
|
+
_this11.logInfo('replaceProductsSnapshotInIndexDB 开始', {
|
|
1895
2274
|
source: source,
|
|
1896
2275
|
productCount: products.length,
|
|
1897
2276
|
queueWaitMs: queueWaitMs
|
|
1898
2277
|
});
|
|
1899
2278
|
clearStartedAt = performance.now();
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
return
|
|
2279
|
+
_context28.prev = 4;
|
|
2280
|
+
_context28.next = 7;
|
|
2281
|
+
return _this11.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1903
2282
|
case 7:
|
|
1904
|
-
|
|
2283
|
+
_context28.prev = 7;
|
|
1905
2284
|
clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
|
|
1906
|
-
return
|
|
2285
|
+
return _context28.finish(7);
|
|
1907
2286
|
case 10:
|
|
1908
2287
|
if (!(products.length > 0)) {
|
|
1909
|
-
|
|
2288
|
+
_context28.next = 18;
|
|
1910
2289
|
break;
|
|
1911
2290
|
}
|
|
1912
2291
|
writeStartedAt = performance.now();
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
return
|
|
2292
|
+
_context28.prev = 12;
|
|
2293
|
+
_context28.next = 15;
|
|
2294
|
+
return _this11.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
|
|
1916
2295
|
case 15:
|
|
1917
|
-
|
|
2296
|
+
_context28.prev = 15;
|
|
1918
2297
|
writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
|
|
1919
|
-
return
|
|
2298
|
+
return _context28.finish(15);
|
|
1920
2299
|
case 18:
|
|
2300
|
+
_context28.next = 20;
|
|
2301
|
+
return _this11.recordProductCommit({
|
|
2302
|
+
kind: 'snapshot',
|
|
2303
|
+
upserts: products,
|
|
2304
|
+
deletedIds: []
|
|
2305
|
+
});
|
|
2306
|
+
case 20:
|
|
1921
2307
|
executeDurationMs = +(performance.now() - operationStartedAt).toFixed(2);
|
|
1922
2308
|
perfMark('replaceProductsSnapshotInIndexDB', executeDurationMs, {
|
|
1923
2309
|
count: products.length
|
|
1924
2310
|
});
|
|
1925
|
-
|
|
2311
|
+
_this11.logInfo('replaceProductsSnapshotInIndexDB 完成', {
|
|
1926
2312
|
source: source,
|
|
1927
2313
|
productCount: products.length,
|
|
1928
2314
|
queueWaitMs: queueWaitMs,
|
|
@@ -1931,19 +2317,19 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1931
2317
|
executeDurationMs: executeDurationMs,
|
|
1932
2318
|
totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2)
|
|
1933
2319
|
});
|
|
1934
|
-
case
|
|
2320
|
+
case 23:
|
|
1935
2321
|
case "end":
|
|
1936
|
-
return
|
|
2322
|
+
return _context28.stop();
|
|
1937
2323
|
}
|
|
1938
|
-
},
|
|
2324
|
+
}, _callee27, null, [[4,, 7, 10], [12,, 15, 18]]);
|
|
1939
2325
|
})));
|
|
1940
|
-
case 10:
|
|
1941
|
-
_context21.next = 16;
|
|
1942
|
-
break;
|
|
1943
2326
|
case 12:
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
2327
|
+
return _context29.abrupt("return", true);
|
|
2328
|
+
case 15:
|
|
2329
|
+
_context29.prev = 15;
|
|
2330
|
+
_context29.t0 = _context29["catch"](9);
|
|
2331
|
+
this.productPersistenceFailed = true;
|
|
2332
|
+
errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
|
|
1947
2333
|
this.logError('全量保存商品到 IndexDB 失败', {
|
|
1948
2334
|
source: source,
|
|
1949
2335
|
productCount: products.length,
|
|
@@ -1953,162 +2339,211 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1953
2339
|
totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2),
|
|
1954
2340
|
error: errorMessage
|
|
1955
2341
|
});
|
|
1956
|
-
|
|
2342
|
+
return _context29.abrupt("return", false);
|
|
2343
|
+
case 21:
|
|
1957
2344
|
case "end":
|
|
1958
|
-
return
|
|
2345
|
+
return _context29.stop();
|
|
1959
2346
|
}
|
|
1960
|
-
},
|
|
2347
|
+
}, _callee28, this, [[9, 15]]);
|
|
1961
2348
|
}));
|
|
1962
|
-
function replaceProductsSnapshotInIndexDB(
|
|
2349
|
+
function replaceProductsSnapshotInIndexDB(_x27, _x28) {
|
|
1963
2350
|
return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
|
|
1964
2351
|
}
|
|
1965
2352
|
return replaceProductsSnapshotInIndexDB;
|
|
1966
|
-
}()
|
|
1967
|
-
/**
|
|
1968
|
-
* 增量 upsert 商品到 IndexDB,不清空表;用于 pubsub 批次合并后的变更商品。
|
|
1969
|
-
*
|
|
1970
|
-
* @example
|
|
1971
|
-
* await this.patchProductsInIndexDB(changedProducts, 'pubsub.processProductSyncMessages', mergeActions)
|
|
1972
|
-
*/
|
|
1973
|
-
)
|
|
2353
|
+
}())
|
|
1974
2354
|
}, {
|
|
1975
2355
|
key: "patchProductsInIndexDB",
|
|
1976
|
-
value:
|
|
1977
|
-
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1978
|
-
var
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
2356
|
+
value: function () {
|
|
2357
|
+
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(products, source) {
|
|
2358
|
+
var _mergeActions,
|
|
2359
|
+
_args30 = arguments;
|
|
2360
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context30) {
|
|
2361
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
2362
|
+
case 0:
|
|
2363
|
+
_mergeActions = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : {};
|
|
2364
|
+
return _context30.abrupt("return", this.persistProductDelta(products, [], source));
|
|
2365
|
+
case 2:
|
|
2366
|
+
case "end":
|
|
2367
|
+
return _context30.stop();
|
|
2368
|
+
}
|
|
2369
|
+
}, _callee29, this);
|
|
2370
|
+
}));
|
|
2371
|
+
function patchProductsInIndexDB(_x29, _x30) {
|
|
2372
|
+
return _patchProductsInIndexDB.apply(this, arguments);
|
|
2373
|
+
}
|
|
2374
|
+
return patchProductsInIndexDB;
|
|
2375
|
+
}()
|
|
2376
|
+
}, {
|
|
2377
|
+
key: "persistProductDelta",
|
|
2378
|
+
value: function () {
|
|
2379
|
+
var _persistProductDelta = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(products, deletedIds, source) {
|
|
2380
|
+
var _this12 = this;
|
|
2381
|
+
var validProducts, startedAt;
|
|
2382
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context32) {
|
|
2383
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
1985
2384
|
case 0:
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
_context23.next = 3;
|
|
2385
|
+
if (!(this.isMemoryReplica() || !this.dbManager)) {
|
|
2386
|
+
_context32.next = 2;
|
|
1989
2387
|
break;
|
|
1990
2388
|
}
|
|
1991
|
-
return
|
|
1992
|
-
case
|
|
2389
|
+
return _context32.abrupt("return", false);
|
|
2390
|
+
case 2:
|
|
1993
2391
|
validProducts = products.filter(function (p) {
|
|
1994
2392
|
return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
|
|
1995
2393
|
});
|
|
1996
|
-
if (!(validProducts.length
|
|
1997
|
-
|
|
2394
|
+
if (!(!validProducts.length && !deletedIds.length)) {
|
|
2395
|
+
_context32.next = 5;
|
|
1998
2396
|
break;
|
|
1999
2397
|
}
|
|
2000
|
-
return
|
|
2001
|
-
case
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2398
|
+
return _context32.abrupt("return", true);
|
|
2399
|
+
case 5:
|
|
2400
|
+
startedAt = performance.now();
|
|
2401
|
+
_context32.prev = 6;
|
|
2402
|
+
_context32.next = 9;
|
|
2403
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
2404
|
+
var _iterator13, _step13, id, _iterator14, _step14, product;
|
|
2405
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context31) {
|
|
2406
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
2008
2407
|
case 0:
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
_context22.next = 7;
|
|
2408
|
+
_iterator13 = _createForOfIteratorHelper(deletedIds);
|
|
2409
|
+
_context31.prev = 1;
|
|
2410
|
+
_iterator13.s();
|
|
2411
|
+
case 3:
|
|
2412
|
+
if ((_step13 = _iterator13.n()).done) {
|
|
2413
|
+
_context31.next = 9;
|
|
2016
2414
|
break;
|
|
2017
2415
|
}
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
_context22.next = 25;
|
|
2022
|
-
break;
|
|
2416
|
+
id = _step13.value;
|
|
2417
|
+
_context31.next = 7;
|
|
2418
|
+
return _this12.dbManager.delete(INDEXDB_STORE_NAME, id);
|
|
2023
2419
|
case 7:
|
|
2024
|
-
|
|
2025
|
-
|
|
2420
|
+
_context31.next = 3;
|
|
2421
|
+
break;
|
|
2422
|
+
case 9:
|
|
2423
|
+
_context31.next = 14;
|
|
2424
|
+
break;
|
|
2425
|
+
case 11:
|
|
2426
|
+
_context31.prev = 11;
|
|
2427
|
+
_context31.t0 = _context31["catch"](1);
|
|
2428
|
+
_iterator13.e(_context31.t0);
|
|
2429
|
+
case 14:
|
|
2430
|
+
_context31.prev = 14;
|
|
2431
|
+
_iterator13.f();
|
|
2432
|
+
return _context31.finish(14);
|
|
2433
|
+
case 17:
|
|
2434
|
+
if (!validProducts.length) {
|
|
2435
|
+
_context31.next = 44;
|
|
2026
2436
|
break;
|
|
2027
2437
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
_iterator11.s();
|
|
2031
|
-
case 11:
|
|
2032
|
-
if ((_step11 = _iterator11.n()).done) {
|
|
2033
|
-
_context22.next = 17;
|
|
2438
|
+
if (!(typeof _this12.dbManager.bulkUpdate === 'function')) {
|
|
2439
|
+
_context31.next = 23;
|
|
2034
2440
|
break;
|
|
2035
2441
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
_context22.next = 11;
|
|
2442
|
+
_context31.next = 21;
|
|
2443
|
+
return _this12.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
|
|
2444
|
+
case 21:
|
|
2445
|
+
_context31.next = 44;
|
|
2041
2446
|
break;
|
|
2042
|
-
case
|
|
2043
|
-
|
|
2447
|
+
case 23:
|
|
2448
|
+
if (!(typeof _this12.dbManager.update === 'function')) {
|
|
2449
|
+
_context31.next = 43;
|
|
2450
|
+
break;
|
|
2451
|
+
}
|
|
2452
|
+
_iterator14 = _createForOfIteratorHelper(validProducts);
|
|
2453
|
+
_context31.prev = 25;
|
|
2454
|
+
_iterator14.s();
|
|
2455
|
+
case 27:
|
|
2456
|
+
if ((_step14 = _iterator14.n()).done) {
|
|
2457
|
+
_context31.next = 33;
|
|
2458
|
+
break;
|
|
2459
|
+
}
|
|
2460
|
+
product = _step14.value;
|
|
2461
|
+
_context31.next = 31;
|
|
2462
|
+
return _this12.dbManager.update(INDEXDB_STORE_NAME, product);
|
|
2463
|
+
case 31:
|
|
2464
|
+
_context31.next = 27;
|
|
2465
|
+
break;
|
|
2466
|
+
case 33:
|
|
2467
|
+
_context31.next = 38;
|
|
2468
|
+
break;
|
|
2469
|
+
case 35:
|
|
2470
|
+
_context31.prev = 35;
|
|
2471
|
+
_context31.t1 = _context31["catch"](25);
|
|
2472
|
+
_iterator14.e(_context31.t1);
|
|
2473
|
+
case 38:
|
|
2474
|
+
_context31.prev = 38;
|
|
2475
|
+
_iterator14.f();
|
|
2476
|
+
return _context31.finish(38);
|
|
2477
|
+
case 41:
|
|
2478
|
+
_context31.next = 44;
|
|
2044
2479
|
break;
|
|
2045
|
-
case
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
case 25:
|
|
2054
|
-
perfMark('patchProductsInIndexDB', performance.now() - t0, {
|
|
2055
|
-
count: validProducts.length
|
|
2480
|
+
case 43:
|
|
2481
|
+
throw new Error('Product persistence adapter has no upsert method');
|
|
2482
|
+
case 44:
|
|
2483
|
+
_context31.next = 46;
|
|
2484
|
+
return _this12.recordProductCommit({
|
|
2485
|
+
kind: 'delta',
|
|
2486
|
+
upserts: validProducts,
|
|
2487
|
+
deletedIds: deletedIds
|
|
2056
2488
|
});
|
|
2057
|
-
|
|
2489
|
+
case 46:
|
|
2490
|
+
_this12.logInfo('patchProductsInIndexDB 完成', {
|
|
2058
2491
|
source: source,
|
|
2059
|
-
|
|
2492
|
+
productCount: validProducts.length,
|
|
2493
|
+
deletedCount: deletedIds.length,
|
|
2494
|
+
durationMs: Math.round(performance.now() - startedAt)
|
|
2060
2495
|
});
|
|
2061
|
-
case
|
|
2496
|
+
case 47:
|
|
2062
2497
|
case "end":
|
|
2063
|
-
return
|
|
2498
|
+
return _context31.stop();
|
|
2064
2499
|
}
|
|
2065
|
-
},
|
|
2500
|
+
}, _callee30, null, [[1, 11, 14, 17], [25, 35, 38, 41]]);
|
|
2066
2501
|
})));
|
|
2067
2502
|
case 9:
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
this.logError('增量保存商品到 IndexDB 失败', {
|
|
2503
|
+
return _context32.abrupt("return", true);
|
|
2504
|
+
case 12:
|
|
2505
|
+
_context32.prev = 12;
|
|
2506
|
+
_context32.t0 = _context32["catch"](6);
|
|
2507
|
+
this.productPersistenceFailed = true;
|
|
2508
|
+
this.logError('增量保存商品失败', {
|
|
2075
2509
|
source: source,
|
|
2076
|
-
|
|
2077
|
-
|
|
2510
|
+
productCount: validProducts.length,
|
|
2511
|
+
deletedCount: deletedIds.length,
|
|
2512
|
+
error: String(_context32.t0)
|
|
2078
2513
|
});
|
|
2079
|
-
|
|
2514
|
+
return _context32.abrupt("return", false);
|
|
2515
|
+
case 17:
|
|
2080
2516
|
case "end":
|
|
2081
|
-
return
|
|
2517
|
+
return _context32.stop();
|
|
2082
2518
|
}
|
|
2083
|
-
},
|
|
2519
|
+
}, _callee31, this, [[6, 12]]);
|
|
2084
2520
|
}));
|
|
2085
|
-
function
|
|
2086
|
-
return
|
|
2521
|
+
function persistProductDelta(_x31, _x32, _x33) {
|
|
2522
|
+
return _persistProductDelta.apply(this, arguments);
|
|
2087
2523
|
}
|
|
2088
|
-
return
|
|
2524
|
+
return persistProductDelta;
|
|
2089
2525
|
}()
|
|
2090
2526
|
/**
|
|
2091
2527
|
* 同步更新商品 Map 缓存
|
|
2092
2528
|
* 将 list 中的商品同步到 map,以 id 为 key
|
|
2093
2529
|
* @private
|
|
2094
2530
|
*/
|
|
2095
|
-
)
|
|
2096
2531
|
}, {
|
|
2097
2532
|
key: "syncProductsMap",
|
|
2098
2533
|
value: function syncProductsMap() {
|
|
2099
2534
|
var t0 = performance.now();
|
|
2100
2535
|
this.store.map.clear();
|
|
2101
|
-
var
|
|
2102
|
-
|
|
2536
|
+
var _iterator15 = _createForOfIteratorHelper(this.store.list),
|
|
2537
|
+
_step15;
|
|
2103
2538
|
try {
|
|
2104
|
-
for (
|
|
2105
|
-
var product =
|
|
2539
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
2540
|
+
var product = _step15.value;
|
|
2106
2541
|
this.store.map.set(product.id, product);
|
|
2107
2542
|
}
|
|
2108
2543
|
} catch (err) {
|
|
2109
|
-
|
|
2544
|
+
_iterator15.e(err);
|
|
2110
2545
|
} finally {
|
|
2111
|
-
|
|
2546
|
+
_iterator15.f();
|
|
2112
2547
|
}
|
|
2113
2548
|
perfMark('syncProductsMap', performance.now() - t0, {
|
|
2114
2549
|
count: this.store.map.size
|
|
@@ -2122,25 +2557,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2122
2557
|
}, {
|
|
2123
2558
|
key: "preload",
|
|
2124
2559
|
value: (function () {
|
|
2125
|
-
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2560
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
|
|
2126
2561
|
var _products$length3;
|
|
2127
2562
|
var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
|
|
2128
|
-
return _regeneratorRuntime().wrap(function
|
|
2129
|
-
while (1) switch (
|
|
2563
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context33) {
|
|
2564
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
2130
2565
|
case 0:
|
|
2566
|
+
if (!this.isMemoryReplica()) {
|
|
2567
|
+
_context33.next = 4;
|
|
2568
|
+
break;
|
|
2569
|
+
}
|
|
2570
|
+
_context33.next = 3;
|
|
2571
|
+
return this.refreshFromReplica('preload');
|
|
2572
|
+
case 3:
|
|
2573
|
+
return _context33.abrupt("return");
|
|
2574
|
+
case 4:
|
|
2131
2575
|
tTotal = performance.now();
|
|
2132
2576
|
this.logInfo('开始预加载数据');
|
|
2133
|
-
|
|
2577
|
+
_context33.prev = 6;
|
|
2134
2578
|
tIndexDB = performance.now();
|
|
2135
|
-
|
|
2579
|
+
_context33.next = 10;
|
|
2136
2580
|
return this.loadProductsFromIndexDB();
|
|
2137
|
-
case
|
|
2138
|
-
cachedData =
|
|
2581
|
+
case 10:
|
|
2582
|
+
cachedData = _context33.sent;
|
|
2139
2583
|
perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
|
|
2140
2584
|
count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
|
|
2141
2585
|
});
|
|
2142
2586
|
if (!(cachedData && cachedData.length > 0)) {
|
|
2143
|
-
|
|
2587
|
+
_context33.next = 22;
|
|
2144
2588
|
break;
|
|
2145
2589
|
}
|
|
2146
2590
|
// IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
|
|
@@ -2162,27 +2606,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2162
2606
|
source: 'IndexDB'
|
|
2163
2607
|
});
|
|
2164
2608
|
this.lastPreloadCompletedAtMs = Date.now();
|
|
2165
|
-
return
|
|
2166
|
-
case
|
|
2609
|
+
return _context33.abrupt("return");
|
|
2610
|
+
case 22:
|
|
2167
2611
|
this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
|
|
2168
|
-
|
|
2612
|
+
_context33.next = 30;
|
|
2169
2613
|
break;
|
|
2170
|
-
case
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
errorMessage =
|
|
2174
|
-
console.warn('[Products] 从 IndexDB 加载数据失败:',
|
|
2614
|
+
case 25:
|
|
2615
|
+
_context33.prev = 25;
|
|
2616
|
+
_context33.t0 = _context33["catch"](6);
|
|
2617
|
+
errorMessage = _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0);
|
|
2618
|
+
console.warn('[Products] 从 IndexDB 加载数据失败:', _context33.t0);
|
|
2175
2619
|
this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
|
|
2176
2620
|
error: errorMessage
|
|
2177
2621
|
});
|
|
2178
|
-
case
|
|
2622
|
+
case 30:
|
|
2179
2623
|
tServer = performance.now();
|
|
2180
|
-
|
|
2624
|
+
_context33.next = 33;
|
|
2181
2625
|
return this.loadProductsByServer({
|
|
2182
2626
|
trigger: 'preload'
|
|
2183
2627
|
});
|
|
2184
|
-
case
|
|
2185
|
-
products =
|
|
2628
|
+
case 33:
|
|
2629
|
+
products = _context33.sent;
|
|
2186
2630
|
perfMark('preload.loadFromServer', performance.now() - tServer, {
|
|
2187
2631
|
count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
|
|
2188
2632
|
});
|
|
@@ -2214,11 +2658,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2214
2658
|
duration: "".concat(Math.round(performance.now() - tTotal), "ms")
|
|
2215
2659
|
});
|
|
2216
2660
|
}
|
|
2217
|
-
case
|
|
2661
|
+
case 36:
|
|
2218
2662
|
case "end":
|
|
2219
|
-
return
|
|
2663
|
+
return _context33.stop();
|
|
2220
2664
|
}
|
|
2221
|
-
},
|
|
2665
|
+
}, _callee32, this, [[6, 25]]);
|
|
2222
2666
|
}));
|
|
2223
2667
|
function preload() {
|
|
2224
2668
|
return _preload.apply(this, arguments);
|
|
@@ -2253,29 +2697,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2253
2697
|
}, {
|
|
2254
2698
|
key: "setupProductSync",
|
|
2255
2699
|
value: function setupProductSync() {
|
|
2256
|
-
var
|
|
2700
|
+
var _this13 = this;
|
|
2257
2701
|
if (!this.productDataSource) {
|
|
2258
2702
|
this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
|
|
2259
2703
|
return;
|
|
2260
2704
|
}
|
|
2261
2705
|
var createHandler = function createHandler(channelKey) {
|
|
2262
2706
|
return function (message) {
|
|
2707
|
+
if (_this13.isMemoryReplica()) return;
|
|
2263
2708
|
var data = (message === null || message === void 0 ? void 0 : message.data) || message;
|
|
2264
2709
|
if (!data) return;
|
|
2265
|
-
|
|
2710
|
+
_this13.logInfo('收到同步消息', {
|
|
2266
2711
|
channelKey: channelKey,
|
|
2267
2712
|
action: data.action,
|
|
2268
2713
|
id: data.id,
|
|
2269
2714
|
action_filed: data.action_filed
|
|
2270
2715
|
});
|
|
2271
|
-
|
|
2716
|
+
_this13.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
2272
2717
|
_channelKey: channelKey
|
|
2273
2718
|
}));
|
|
2274
|
-
if (
|
|
2275
|
-
clearTimeout(
|
|
2719
|
+
if (_this13.syncTimer) {
|
|
2720
|
+
clearTimeout(_this13.syncTimer);
|
|
2276
2721
|
}
|
|
2277
|
-
|
|
2278
|
-
|
|
2722
|
+
_this13.syncTimer = setTimeout(function () {
|
|
2723
|
+
_this13.processProductSyncMessages();
|
|
2279
2724
|
}, PRODUCT_SYNC_DEBOUNCE_MS);
|
|
2280
2725
|
};
|
|
2281
2726
|
};
|
|
@@ -2293,7 +2738,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2293
2738
|
}
|
|
2294
2739
|
}
|
|
2295
2740
|
}).catch(function (err) {
|
|
2296
|
-
|
|
2741
|
+
_this13.logError('setupProductSync: DataSource run 出错', {
|
|
2297
2742
|
error: err instanceof Error ? err.message : String(err)
|
|
2298
2743
|
});
|
|
2299
2744
|
});
|
|
@@ -2320,40 +2765,61 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2320
2765
|
*/
|
|
2321
2766
|
}, {
|
|
2322
2767
|
key: "processProductSyncMessages",
|
|
2323
|
-
value:
|
|
2324
|
-
var
|
|
2325
|
-
|
|
2326
|
-
return
|
|
2327
|
-
|
|
2768
|
+
value: function processProductSyncMessages() {
|
|
2769
|
+
var _this14 = this;
|
|
2770
|
+
var run = function run() {
|
|
2771
|
+
return _this14.processProductSyncBatch();
|
|
2772
|
+
};
|
|
2773
|
+
var task = this.productSyncQueue.then(run, run);
|
|
2774
|
+
this.productSyncQueue = task.catch(function (error) {
|
|
2775
|
+
_this14.logError('商品同步批次失败', {
|
|
2776
|
+
error: String(error)
|
|
2777
|
+
});
|
|
2778
|
+
});
|
|
2779
|
+
return this.productSyncQueue;
|
|
2780
|
+
}
|
|
2781
|
+
}, {
|
|
2782
|
+
key: "processProductSyncBatch",
|
|
2783
|
+
value: function () {
|
|
2784
|
+
var _processProductSyncBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
2785
|
+
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator16, _step16, msg, channelKey, _msg$relation_product, _msg$body, _msg$change_types, _msg$ids2, _msg$ids, ids, _iterator20, _step20, id, _iterator21, _step21, _id, _ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, storeMutated, bodyResult, _iterator17, _step17, product, freshProducts, mergeResult, _iterator18, _step18, _product, patchProducts, committedUpserts, _iterator19, _step19, _id2, _product2, allChangedIds, hasChanges, errorMessage;
|
|
2786
|
+
return _regeneratorRuntime().wrap(function _callee33$(_context34) {
|
|
2787
|
+
while (1) switch (_context34.prev = _context34.next) {
|
|
2328
2788
|
case 0:
|
|
2789
|
+
if (!this.isMemoryReplica()) {
|
|
2790
|
+
_context34.next = 2;
|
|
2791
|
+
break;
|
|
2792
|
+
}
|
|
2793
|
+
return _context34.abrupt("return");
|
|
2794
|
+
case 2:
|
|
2329
2795
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
2330
2796
|
this.pendingSyncMessages = [];
|
|
2331
2797
|
if (!(messages.length === 0)) {
|
|
2332
|
-
|
|
2798
|
+
_context34.next = 6;
|
|
2333
2799
|
break;
|
|
2334
2800
|
}
|
|
2335
|
-
return
|
|
2336
|
-
case
|
|
2801
|
+
return _context34.abrupt("return");
|
|
2802
|
+
case 6:
|
|
2337
2803
|
this.logInfo('processProductSyncMessages: 开始处理', {
|
|
2338
2804
|
count: messages.length
|
|
2339
2805
|
});
|
|
2340
|
-
deleteIds =
|
|
2806
|
+
deleteIds = new Set();
|
|
2341
2807
|
bodyUpdates = new Map();
|
|
2342
2808
|
sseRefreshIds = [];
|
|
2343
2809
|
priceRefreshIds = [];
|
|
2344
2810
|
shouldClearPriceCache = false;
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
case
|
|
2349
|
-
if ((
|
|
2350
|
-
|
|
2811
|
+
_iterator16 = _createForOfIteratorHelper(messages);
|
|
2812
|
+
_context34.prev = 13;
|
|
2813
|
+
_iterator16.s();
|
|
2814
|
+
case 15:
|
|
2815
|
+
if ((_step16 = _iterator16.n()).done) {
|
|
2816
|
+
_context34.next = 43;
|
|
2351
2817
|
break;
|
|
2352
2818
|
}
|
|
2353
|
-
msg =
|
|
2819
|
+
msg = _step16.value;
|
|
2354
2820
|
channelKey = msg._channelKey || msg.module || 'product';
|
|
2355
2821
|
if (!(channelKey === 'product')) {
|
|
2356
|
-
|
|
2822
|
+
_context34.next = 40;
|
|
2357
2823
|
break;
|
|
2358
2824
|
}
|
|
2359
2825
|
if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
|
|
@@ -2361,41 +2827,68 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2361
2827
|
}
|
|
2362
2828
|
// 1. 删除场景:operation === 'delete' 或 action === 'delete'
|
|
2363
2829
|
if (!(msg.operation === 'delete' || msg.action === 'delete')) {
|
|
2364
|
-
|
|
2830
|
+
_context34.next = 25;
|
|
2365
2831
|
break;
|
|
2366
2832
|
}
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2833
|
+
ids = (_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length ? msg.ids : msg.id ? [msg.id] : [];
|
|
2834
|
+
_iterator20 = _createForOfIteratorHelper(ids);
|
|
2835
|
+
try {
|
|
2836
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
2837
|
+
id = _step20.value;
|
|
2838
|
+
deleteIds.add(id);
|
|
2839
|
+
bodyUpdates.delete(id);
|
|
2840
|
+
}
|
|
2841
|
+
} catch (err) {
|
|
2842
|
+
_iterator20.e(err);
|
|
2843
|
+
} finally {
|
|
2844
|
+
_iterator20.f();
|
|
2845
|
+
}
|
|
2846
|
+
return _context34.abrupt("continue", 41);
|
|
2847
|
+
case 25:
|
|
2848
|
+
// The last explicit product operation wins within the existing sync batch.
|
|
2849
|
+
_iterator21 = _createForOfIteratorHelper(msg.ids || (msg.id ? [msg.id] : []));
|
|
2850
|
+
try {
|
|
2851
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2852
|
+
_id = _step21.value;
|
|
2853
|
+
deleteIds.delete(_id);
|
|
2854
|
+
}
|
|
2855
|
+
} catch (err) {
|
|
2856
|
+
_iterator21.e(err);
|
|
2857
|
+
} finally {
|
|
2858
|
+
_iterator21.f();
|
|
2859
|
+
}
|
|
2860
|
+
if ((_msg$body = msg.body) !== null && _msg$body !== void 0 && _msg$body.id) deleteIds.delete(msg.body.id);
|
|
2861
|
+
|
|
2862
|
+
// 2. change_types 包含 price → 仅收集需要刷新价格的 IDs(不走 SSE 拉取)
|
|
2370
2863
|
if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
|
|
2371
|
-
|
|
2864
|
+
_context34.next = 33;
|
|
2372
2865
|
break;
|
|
2373
2866
|
}
|
|
2374
|
-
|
|
2375
|
-
priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(
|
|
2867
|
+
_ids = msg.ids || (msg.id ? [msg.id] : []);
|
|
2868
|
+
priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(_ids));
|
|
2376
2869
|
if (msg.body) {
|
|
2377
2870
|
bodyId = msg.body.id;
|
|
2378
2871
|
if (bodyId) bodyUpdates.set(bodyId, msg.body);
|
|
2379
2872
|
}
|
|
2380
|
-
return
|
|
2381
|
-
case
|
|
2873
|
+
return _context34.abrupt("continue", 41);
|
|
2874
|
+
case 33:
|
|
2382
2875
|
if (!msg.body) {
|
|
2383
|
-
|
|
2876
|
+
_context34.next = 37;
|
|
2384
2877
|
break;
|
|
2385
2878
|
}
|
|
2386
2879
|
_bodyId = msg.body.id || msg.id;
|
|
2387
2880
|
if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
|
|
2388
|
-
return
|
|
2389
|
-
case
|
|
2881
|
+
return _context34.abrupt("continue", 41);
|
|
2882
|
+
case 37:
|
|
2390
2883
|
// 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
|
|
2391
2884
|
if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
|
|
2392
2885
|
sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
|
|
2393
2886
|
} else if (msg.id) {
|
|
2394
2887
|
sseRefreshIds.push(msg.id);
|
|
2395
2888
|
}
|
|
2396
|
-
|
|
2889
|
+
_context34.next = 41;
|
|
2397
2890
|
break;
|
|
2398
|
-
case
|
|
2891
|
+
case 40:
|
|
2399
2892
|
if (channelKey === 'product_quotation') {
|
|
2400
2893
|
// 报价单变更影响范围大,标记清除全量价格缓存
|
|
2401
2894
|
shouldClearPriceCache = true;
|
|
@@ -2411,108 +2904,127 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2411
2904
|
sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.product_ids));
|
|
2412
2905
|
}
|
|
2413
2906
|
}
|
|
2414
|
-
case
|
|
2415
|
-
|
|
2907
|
+
case 41:
|
|
2908
|
+
_context34.next = 15;
|
|
2416
2909
|
break;
|
|
2417
|
-
case
|
|
2418
|
-
|
|
2910
|
+
case 43:
|
|
2911
|
+
_context34.next = 48;
|
|
2419
2912
|
break;
|
|
2420
|
-
case
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
case
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
return
|
|
2428
|
-
case
|
|
2429
|
-
uniqueDeleteIds = _toConsumableArray(
|
|
2430
|
-
uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds))
|
|
2431
|
-
|
|
2913
|
+
case 45:
|
|
2914
|
+
_context34.prev = 45;
|
|
2915
|
+
_context34.t0 = _context34["catch"](13);
|
|
2916
|
+
_iterator16.e(_context34.t0);
|
|
2917
|
+
case 48:
|
|
2918
|
+
_context34.prev = 48;
|
|
2919
|
+
_iterator16.f();
|
|
2920
|
+
return _context34.finish(48);
|
|
2921
|
+
case 51:
|
|
2922
|
+
uniqueDeleteIds = _toConsumableArray(deleteIds);
|
|
2923
|
+
uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds)).filter(function (id) {
|
|
2924
|
+
return !deleteIds.has(id);
|
|
2925
|
+
});
|
|
2926
|
+
uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)).filter(function (id) {
|
|
2927
|
+
return !deleteIds.has(id);
|
|
2928
|
+
}); // 1. 处理删除
|
|
2432
2929
|
if (!(uniqueDeleteIds.length > 0)) {
|
|
2433
|
-
|
|
2930
|
+
_context34.next = 57;
|
|
2434
2931
|
break;
|
|
2435
2932
|
}
|
|
2436
|
-
|
|
2437
|
-
return this.removeProductsByIds(uniqueDeleteIds
|
|
2438
|
-
|
|
2933
|
+
_context34.next = 57;
|
|
2934
|
+
return this.removeProductsByIds(uniqueDeleteIds, {
|
|
2935
|
+
skipIndexDB: true,
|
|
2936
|
+
skipEmit: true
|
|
2937
|
+
});
|
|
2938
|
+
case 57:
|
|
2439
2939
|
/** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
|
|
2440
2940
|
patchProductMap = new Map();
|
|
2441
|
-
patchMergeActions = {};
|
|
2442
2941
|
storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
|
|
2443
2942
|
if (!(bodyUpdates.size > 0)) {
|
|
2444
|
-
|
|
2943
|
+
_context34.next = 66;
|
|
2445
2944
|
break;
|
|
2446
2945
|
}
|
|
2447
|
-
|
|
2946
|
+
_context34.next = 62;
|
|
2448
2947
|
return this.applyBodyUpdatesToStore(bodyUpdates, {
|
|
2449
2948
|
skipIndexDB: true,
|
|
2450
2949
|
skipEmit: true
|
|
2451
2950
|
});
|
|
2452
|
-
case
|
|
2453
|
-
bodyResult =
|
|
2454
|
-
|
|
2951
|
+
case 62:
|
|
2952
|
+
bodyResult = _context34.sent;
|
|
2953
|
+
_iterator17 = _createForOfIteratorHelper(bodyResult.changedProducts);
|
|
2455
2954
|
try {
|
|
2456
|
-
for (
|
|
2457
|
-
product =
|
|
2955
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2956
|
+
product = _step17.value;
|
|
2458
2957
|
patchProductMap.set(product.id, product);
|
|
2459
|
-
patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
|
|
2460
2958
|
}
|
|
2461
2959
|
} catch (err) {
|
|
2462
|
-
|
|
2960
|
+
_iterator17.e(err);
|
|
2463
2961
|
} finally {
|
|
2464
|
-
|
|
2962
|
+
_iterator17.f();
|
|
2465
2963
|
}
|
|
2466
2964
|
storeMutated = true;
|
|
2467
|
-
case
|
|
2965
|
+
case 66:
|
|
2468
2966
|
// 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
|
|
2469
2967
|
freshProducts = [];
|
|
2470
2968
|
if (!(uniqueSSEIds.length > 0)) {
|
|
2471
|
-
|
|
2969
|
+
_context34.next = 79;
|
|
2472
2970
|
break;
|
|
2473
2971
|
}
|
|
2474
|
-
|
|
2972
|
+
_context34.next = 70;
|
|
2475
2973
|
return this.fetchProductsBySSE(uniqueSSEIds);
|
|
2476
|
-
case
|
|
2477
|
-
freshProducts =
|
|
2974
|
+
case 70:
|
|
2975
|
+
freshProducts = _context34.sent;
|
|
2478
2976
|
if (!(freshProducts.length > 0)) {
|
|
2479
|
-
|
|
2977
|
+
_context34.next = 78;
|
|
2480
2978
|
break;
|
|
2481
2979
|
}
|
|
2482
|
-
|
|
2980
|
+
_context34.next = 74;
|
|
2483
2981
|
return this.mergeProductsToStore(freshProducts, {
|
|
2484
2982
|
skipIndexDB: true,
|
|
2485
2983
|
skipEmit: true
|
|
2486
2984
|
});
|
|
2487
|
-
case
|
|
2488
|
-
mergeResult =
|
|
2489
|
-
|
|
2985
|
+
case 74:
|
|
2986
|
+
mergeResult = _context34.sent;
|
|
2987
|
+
_iterator18 = _createForOfIteratorHelper(mergeResult.changedProducts);
|
|
2490
2988
|
try {
|
|
2491
|
-
for (
|
|
2492
|
-
_product =
|
|
2989
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2990
|
+
_product = _step18.value;
|
|
2493
2991
|
patchProductMap.set(_product.id, _product);
|
|
2494
|
-
patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
|
|
2495
2992
|
}
|
|
2496
2993
|
} catch (err) {
|
|
2497
|
-
|
|
2994
|
+
_iterator18.e(err);
|
|
2498
2995
|
} finally {
|
|
2499
|
-
|
|
2996
|
+
_iterator18.f();
|
|
2500
2997
|
}
|
|
2501
2998
|
storeMutated = true;
|
|
2502
|
-
case
|
|
2999
|
+
case 78:
|
|
2503
3000
|
this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
|
|
2504
3001
|
requestedCount: uniqueSSEIds.length,
|
|
2505
3002
|
receivedCount: freshProducts.length
|
|
2506
3003
|
});
|
|
2507
|
-
case
|
|
2508
|
-
patchProducts = _toConsumableArray(patchProductMap.values());
|
|
2509
|
-
|
|
2510
|
-
|
|
3004
|
+
case 79:
|
|
3005
|
+
patchProducts = _toConsumableArray(patchProductMap.values()); // Publish one committed delta for the entire batch, including deletions and price-only IDs.
|
|
3006
|
+
committedUpserts = new Map(patchProducts.map(function (p) {
|
|
3007
|
+
return [p.id, p];
|
|
3008
|
+
}));
|
|
3009
|
+
_iterator19 = _createForOfIteratorHelper(uniquePriceIds);
|
|
3010
|
+
try {
|
|
3011
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
3012
|
+
_id2 = _step19.value;
|
|
3013
|
+
_product2 = this.store.map.get(_id2);
|
|
3014
|
+
if (_product2 && !uniqueDeleteIds.includes(_id2)) committedUpserts.set(_id2, _product2);
|
|
3015
|
+
}
|
|
3016
|
+
} catch (err) {
|
|
3017
|
+
_iterator19.e(err);
|
|
3018
|
+
} finally {
|
|
3019
|
+
_iterator19.f();
|
|
3020
|
+
}
|
|
3021
|
+
if (!(committedUpserts.size || uniqueDeleteIds.length)) {
|
|
3022
|
+
_context34.next = 86;
|
|
2511
3023
|
break;
|
|
2512
3024
|
}
|
|
2513
|
-
|
|
2514
|
-
return this.
|
|
2515
|
-
case
|
|
3025
|
+
_context34.next = 86;
|
|
3026
|
+
return this.persistProductDelta(_toConsumableArray(committedUpserts.values()), uniqueDeleteIds, 'pubsub.batch');
|
|
3027
|
+
case 86:
|
|
2516
3028
|
if (storeMutated) {
|
|
2517
3029
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2518
3030
|
}
|
|
@@ -2529,74 +3041,73 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2529
3041
|
});
|
|
2530
3042
|
hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
|
|
2531
3043
|
if (hasChanges) {
|
|
2532
|
-
|
|
3044
|
+
_context34.next = 93;
|
|
2533
3045
|
break;
|
|
2534
3046
|
}
|
|
2535
3047
|
this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
|
|
2536
|
-
return
|
|
2537
|
-
case
|
|
3048
|
+
return _context34.abrupt("return");
|
|
3049
|
+
case 93:
|
|
2538
3050
|
if (!shouldClearPriceCache) {
|
|
2539
|
-
|
|
3051
|
+
_context34.next = 104;
|
|
2540
3052
|
break;
|
|
2541
3053
|
}
|
|
2542
|
-
|
|
2543
|
-
|
|
3054
|
+
_context34.prev = 94;
|
|
3055
|
+
_context34.next = 97;
|
|
2544
3056
|
return this.refreshQuotationPriceBridge();
|
|
2545
|
-
case
|
|
2546
|
-
|
|
3057
|
+
case 97:
|
|
3058
|
+
_context34.next = 103;
|
|
2547
3059
|
break;
|
|
2548
|
-
case
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
errorMessage =
|
|
3060
|
+
case 99:
|
|
3061
|
+
_context34.prev = 99;
|
|
3062
|
+
_context34.t1 = _context34["catch"](94);
|
|
3063
|
+
errorMessage = _context34.t1 instanceof Error ? _context34.t1.message : String(_context34.t1);
|
|
2552
3064
|
this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
|
|
2553
3065
|
error: errorMessage
|
|
2554
3066
|
});
|
|
2555
|
-
case
|
|
3067
|
+
case 103:
|
|
2556
3068
|
this.clearPriceCache();
|
|
2557
|
-
case
|
|
2558
|
-
|
|
3069
|
+
case 104:
|
|
3070
|
+
_context34.next = 106;
|
|
2559
3071
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
|
|
2560
3072
|
changedIds: allChangedIds
|
|
2561
3073
|
});
|
|
2562
|
-
case
|
|
3074
|
+
case 106:
|
|
2563
3075
|
case "end":
|
|
2564
|
-
return
|
|
3076
|
+
return _context34.stop();
|
|
2565
3077
|
}
|
|
2566
|
-
},
|
|
3078
|
+
}, _callee33, this, [[13, 45, 48, 51], [94, 99]]);
|
|
2567
3079
|
}));
|
|
2568
|
-
function
|
|
2569
|
-
return
|
|
3080
|
+
function processProductSyncBatch() {
|
|
3081
|
+
return _processProductSyncBatch.apply(this, arguments);
|
|
2570
3082
|
}
|
|
2571
|
-
return
|
|
3083
|
+
return processProductSyncBatch;
|
|
2572
3084
|
}()
|
|
2573
3085
|
/**
|
|
2574
3086
|
* 通过 SSE 按 ids 增量拉取商品数据
|
|
2575
3087
|
* 请求 GET /shop/core/stream?type=product&ids={ids}
|
|
2576
3088
|
*/
|
|
2577
|
-
)
|
|
2578
3089
|
}, {
|
|
2579
3090
|
key: "fetchProductsBySSE",
|
|
2580
3091
|
value: (function () {
|
|
2581
|
-
var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3092
|
+
var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(ids) {
|
|
2582
3093
|
var t0, productList, list, errorMessage;
|
|
2583
|
-
return _regeneratorRuntime().wrap(function
|
|
2584
|
-
while (1) switch (
|
|
3094
|
+
return _regeneratorRuntime().wrap(function _callee34$(_context35) {
|
|
3095
|
+
while (1) switch (_context35.prev = _context35.next) {
|
|
2585
3096
|
case 0:
|
|
2586
3097
|
if (this.productDataSource) {
|
|
2587
|
-
|
|
3098
|
+
_context35.next = 3;
|
|
2588
3099
|
break;
|
|
2589
3100
|
}
|
|
2590
3101
|
this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
|
|
2591
|
-
return
|
|
3102
|
+
return _context35.abrupt("return", []);
|
|
2592
3103
|
case 3:
|
|
2593
3104
|
this.logInfo('fetchProductsBySSE: 开始', {
|
|
2594
3105
|
ids: ids,
|
|
2595
3106
|
count: ids.length
|
|
2596
3107
|
});
|
|
2597
3108
|
t0 = performance.now();
|
|
2598
|
-
|
|
2599
|
-
|
|
3109
|
+
_context35.prev = 5;
|
|
3110
|
+
_context35.next = 8;
|
|
2600
3111
|
return this.productDataSource.run({
|
|
2601
3112
|
sse: {
|
|
2602
3113
|
query: {
|
|
@@ -2606,7 +3117,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2606
3117
|
}
|
|
2607
3118
|
});
|
|
2608
3119
|
case 8:
|
|
2609
|
-
productList =
|
|
3120
|
+
productList = _context35.sent;
|
|
2610
3121
|
list = productList || [];
|
|
2611
3122
|
perfMark('fetchProductsBySSE', performance.now() - t0, {
|
|
2612
3123
|
count: list.length
|
|
@@ -2616,23 +3127,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2616
3127
|
receivedCount: list.length,
|
|
2617
3128
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2618
3129
|
});
|
|
2619
|
-
return
|
|
3130
|
+
return _context35.abrupt("return", list);
|
|
2620
3131
|
case 15:
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
errorMessage =
|
|
3132
|
+
_context35.prev = 15;
|
|
3133
|
+
_context35.t0 = _context35["catch"](5);
|
|
3134
|
+
errorMessage = _context35.t0 instanceof Error ? _context35.t0.message : String(_context35.t0);
|
|
2624
3135
|
this.logError('fetchProductsBySSE: 失败', {
|
|
2625
3136
|
ids: ids,
|
|
2626
3137
|
error: errorMessage
|
|
2627
3138
|
});
|
|
2628
|
-
return
|
|
3139
|
+
return _context35.abrupt("return", []);
|
|
2629
3140
|
case 20:
|
|
2630
3141
|
case "end":
|
|
2631
|
-
return
|
|
3142
|
+
return _context35.stop();
|
|
2632
3143
|
}
|
|
2633
|
-
},
|
|
3144
|
+
}, _callee34, this, [[5, 15]]);
|
|
2634
3145
|
}));
|
|
2635
|
-
function fetchProductsBySSE(
|
|
3146
|
+
function fetchProductsBySSE(_x34) {
|
|
2636
3147
|
return _fetchProductsBySSE.apply(this, arguments);
|
|
2637
3148
|
}
|
|
2638
3149
|
return fetchProductsBySSE;
|
|
@@ -2648,10 +3159,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2648
3159
|
}, {
|
|
2649
3160
|
key: "applyBodyUpdatesToStore",
|
|
2650
3161
|
value: (function () {
|
|
2651
|
-
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2652
|
-
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts,
|
|
2653
|
-
return _regeneratorRuntime().wrap(function
|
|
2654
|
-
while (1) switch (
|
|
3162
|
+
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(bodyUpdates, options) {
|
|
3163
|
+
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator22, _step22, _step22$value, id, body;
|
|
3164
|
+
return _regeneratorRuntime().wrap(function _callee35$(_context36) {
|
|
3165
|
+
while (1) switch (_context36.prev = _context36.next) {
|
|
2655
3166
|
case 0:
|
|
2656
3167
|
changedProductIds = _toConsumableArray(bodyUpdates.keys());
|
|
2657
3168
|
this.logInfo('applyBodyUpdatesToStore: 开始', {
|
|
@@ -2673,10 +3184,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2673
3184
|
}
|
|
2674
3185
|
return p;
|
|
2675
3186
|
});
|
|
2676
|
-
|
|
3187
|
+
_iterator22 = _createForOfIteratorHelper(bodyUpdates);
|
|
2677
3188
|
try {
|
|
2678
|
-
for (
|
|
2679
|
-
|
|
3189
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
3190
|
+
_step22$value = _slicedToArray(_step22.value, 2), id = _step22$value[0], body = _step22$value[1];
|
|
2680
3191
|
if (!appliedIds.has(id)) {
|
|
2681
3192
|
this.store.list.push(body);
|
|
2682
3193
|
newCount++;
|
|
@@ -2685,16 +3196,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2685
3196
|
}
|
|
2686
3197
|
}
|
|
2687
3198
|
} catch (err) {
|
|
2688
|
-
|
|
3199
|
+
_iterator22.e(err);
|
|
2689
3200
|
} finally {
|
|
2690
|
-
|
|
3201
|
+
_iterator22.f();
|
|
2691
3202
|
}
|
|
2692
3203
|
this.syncProductsMap();
|
|
2693
3204
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2694
|
-
|
|
3205
|
+
_context36.next = 14;
|
|
2695
3206
|
break;
|
|
2696
3207
|
}
|
|
2697
|
-
|
|
3208
|
+
_context36.next = 14;
|
|
2698
3209
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
|
|
2699
3210
|
case 14:
|
|
2700
3211
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
@@ -2705,7 +3216,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2705
3216
|
newCount: newCount,
|
|
2706
3217
|
totalCount: this.store.list.length
|
|
2707
3218
|
});
|
|
2708
|
-
return
|
|
3219
|
+
return _context36.abrupt("return", {
|
|
2709
3220
|
changedProducts: changedProducts,
|
|
2710
3221
|
mergeActions: mergeActions,
|
|
2711
3222
|
updatedCount: updatedCount,
|
|
@@ -2713,11 +3224,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2713
3224
|
});
|
|
2714
3225
|
case 17:
|
|
2715
3226
|
case "end":
|
|
2716
|
-
return
|
|
3227
|
+
return _context36.stop();
|
|
2717
3228
|
}
|
|
2718
|
-
},
|
|
3229
|
+
}, _callee35, this);
|
|
2719
3230
|
}));
|
|
2720
|
-
function applyBodyUpdatesToStore(
|
|
3231
|
+
function applyBodyUpdatesToStore(_x35, _x36) {
|
|
2721
3232
|
return _applyBodyUpdatesToStore.apply(this, arguments);
|
|
2722
3233
|
}
|
|
2723
3234
|
return applyBodyUpdatesToStore;
|
|
@@ -2733,22 +3244,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2733
3244
|
}, {
|
|
2734
3245
|
key: "mergeProductsToStore",
|
|
2735
3246
|
value: (function () {
|
|
2736
|
-
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2737
|
-
var freshMap,
|
|
2738
|
-
return _regeneratorRuntime().wrap(function
|
|
2739
|
-
while (1) switch (
|
|
3247
|
+
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(freshProducts, options) {
|
|
3248
|
+
var freshMap, _iterator23, _step23, p, mergeActions, changedProducts, updatedList, newCount, _iterator24, _step24, _p2, updatedCount, changedProductIds;
|
|
3249
|
+
return _regeneratorRuntime().wrap(function _callee36$(_context37) {
|
|
3250
|
+
while (1) switch (_context37.prev = _context37.next) {
|
|
2740
3251
|
case 0:
|
|
2741
3252
|
freshMap = new Map();
|
|
2742
|
-
|
|
3253
|
+
_iterator23 = _createForOfIteratorHelper(freshProducts);
|
|
2743
3254
|
try {
|
|
2744
|
-
for (
|
|
2745
|
-
p =
|
|
3255
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
3256
|
+
p = _step23.value;
|
|
2746
3257
|
freshMap.set(p.id, p);
|
|
2747
3258
|
}
|
|
2748
3259
|
} catch (err) {
|
|
2749
|
-
|
|
3260
|
+
_iterator23.e(err);
|
|
2750
3261
|
} finally {
|
|
2751
|
-
|
|
3262
|
+
_iterator23.f();
|
|
2752
3263
|
}
|
|
2753
3264
|
mergeActions = {};
|
|
2754
3265
|
changedProducts = [];
|
|
@@ -2763,18 +3274,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2763
3274
|
return p;
|
|
2764
3275
|
}); // freshMap 中剩余的是新商品(create 场景)
|
|
2765
3276
|
newCount = freshMap.size;
|
|
2766
|
-
|
|
3277
|
+
_iterator24 = _createForOfIteratorHelper(freshMap.values());
|
|
2767
3278
|
try {
|
|
2768
|
-
for (
|
|
2769
|
-
_p2 =
|
|
3279
|
+
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
3280
|
+
_p2 = _step24.value;
|
|
2770
3281
|
updatedList.push(_p2);
|
|
2771
3282
|
mergeActions[_p2.id] = 'insert';
|
|
2772
3283
|
changedProducts.push(_p2);
|
|
2773
3284
|
}
|
|
2774
3285
|
} catch (err) {
|
|
2775
|
-
|
|
3286
|
+
_iterator24.e(err);
|
|
2776
3287
|
} finally {
|
|
2777
|
-
|
|
3288
|
+
_iterator24.f();
|
|
2778
3289
|
}
|
|
2779
3290
|
updatedCount = freshProducts.length - newCount;
|
|
2780
3291
|
changedProductIds = freshProducts.map(function (p) {
|
|
@@ -2783,10 +3294,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2783
3294
|
this.store.list = updatedList;
|
|
2784
3295
|
this.syncProductsMap();
|
|
2785
3296
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2786
|
-
|
|
3297
|
+
_context37.next = 16;
|
|
2787
3298
|
break;
|
|
2788
3299
|
}
|
|
2789
|
-
|
|
3300
|
+
_context37.next = 16;
|
|
2790
3301
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
|
|
2791
3302
|
case 16:
|
|
2792
3303
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
@@ -2797,7 +3308,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2797
3308
|
newCount: newCount,
|
|
2798
3309
|
totalCount: this.store.list.length
|
|
2799
3310
|
});
|
|
2800
|
-
return
|
|
3311
|
+
return _context37.abrupt("return", {
|
|
2801
3312
|
changedProducts: changedProducts,
|
|
2802
3313
|
mergeActions: mergeActions,
|
|
2803
3314
|
updatedCount: updatedCount,
|
|
@@ -2805,11 +3316,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2805
3316
|
});
|
|
2806
3317
|
case 19:
|
|
2807
3318
|
case "end":
|
|
2808
|
-
return
|
|
3319
|
+
return _context37.stop();
|
|
2809
3320
|
}
|
|
2810
|
-
},
|
|
3321
|
+
}, _callee36, this);
|
|
2811
3322
|
}));
|
|
2812
|
-
function mergeProductsToStore(
|
|
3323
|
+
function mergeProductsToStore(_x37, _x38) {
|
|
2813
3324
|
return _mergeProductsToStore.apply(this, arguments);
|
|
2814
3325
|
}
|
|
2815
3326
|
return mergeProductsToStore;
|
|
@@ -2823,7 +3334,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2823
3334
|
}, {
|
|
2824
3335
|
key: "silentRefresh",
|
|
2825
3336
|
value: (function () {
|
|
2826
|
-
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3337
|
+
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
|
|
2827
3338
|
var options,
|
|
2828
3339
|
t0,
|
|
2829
3340
|
now,
|
|
@@ -2832,18 +3343,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2832
3343
|
elapsedSinceFullFetchMs,
|
|
2833
3344
|
products,
|
|
2834
3345
|
errorMessage,
|
|
2835
|
-
|
|
2836
|
-
return _regeneratorRuntime().wrap(function
|
|
2837
|
-
while (1) switch (
|
|
3346
|
+
_args38 = arguments;
|
|
3347
|
+
return _regeneratorRuntime().wrap(function _callee37$(_context38) {
|
|
3348
|
+
while (1) switch (_context38.prev = _context38.next) {
|
|
2838
3349
|
case 0:
|
|
2839
|
-
options =
|
|
3350
|
+
options = _args38.length > 0 && _args38[0] !== undefined ? _args38[0] : {};
|
|
3351
|
+
if (!this.isMemoryReplica()) {
|
|
3352
|
+
_context38.next = 3;
|
|
3353
|
+
break;
|
|
3354
|
+
}
|
|
3355
|
+
return _context38.abrupt("return", this.refreshFromReplica(options.trigger || 'background'));
|
|
3356
|
+
case 3:
|
|
2840
3357
|
t0 = performance.now();
|
|
2841
3358
|
now = Date.now();
|
|
2842
3359
|
trigger = options.trigger || 'background';
|
|
2843
3360
|
elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
|
|
2844
3361
|
elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
|
|
2845
3362
|
if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
2846
|
-
|
|
3363
|
+
_context38.next = 11;
|
|
2847
3364
|
break;
|
|
2848
3365
|
}
|
|
2849
3366
|
this.logInfo('silentRefresh 跳过全量 SSE', {
|
|
@@ -2854,61 +3371,61 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2854
3371
|
elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
|
|
2855
3372
|
productCount: this.store.list.length
|
|
2856
3373
|
});
|
|
2857
|
-
return
|
|
2858
|
-
case
|
|
3374
|
+
return _context38.abrupt("return", this.store.list);
|
|
3375
|
+
case 11:
|
|
2859
3376
|
this.logInfo('silentRefresh 开始', {
|
|
2860
3377
|
trigger: trigger,
|
|
2861
3378
|
elapsedSincePreloadMs: elapsedSincePreloadMs,
|
|
2862
3379
|
elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
|
|
2863
3380
|
productCount: this.store.list.length
|
|
2864
3381
|
});
|
|
2865
|
-
|
|
2866
|
-
|
|
3382
|
+
_context38.prev = 12;
|
|
3383
|
+
_context38.next = 15;
|
|
2867
3384
|
return this.loadProductsByServer({
|
|
2868
3385
|
trigger: trigger
|
|
2869
3386
|
});
|
|
2870
|
-
case
|
|
2871
|
-
products =
|
|
3387
|
+
case 15:
|
|
3388
|
+
products = _context38.sent;
|
|
2872
3389
|
if (!(products && products.length > 0)) {
|
|
2873
|
-
|
|
3390
|
+
_context38.next = 26;
|
|
2874
3391
|
break;
|
|
2875
3392
|
}
|
|
2876
3393
|
this.store.list = products;
|
|
2877
3394
|
this.syncProductsMap();
|
|
2878
3395
|
this.clearPriceCache();
|
|
2879
3396
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2880
|
-
|
|
3397
|
+
_context38.next = 23;
|
|
2881
3398
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
|
|
2882
|
-
case
|
|
3399
|
+
case 23:
|
|
2883
3400
|
this.logInfo('silentRefresh 完成', {
|
|
2884
3401
|
trigger: trigger,
|
|
2885
3402
|
productCount: products.length,
|
|
2886
3403
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2887
3404
|
});
|
|
2888
|
-
|
|
3405
|
+
_context38.next = 27;
|
|
2889
3406
|
break;
|
|
2890
|
-
case
|
|
3407
|
+
case 26:
|
|
2891
3408
|
this.logWarning('silentRefresh: 服务器未返回数据');
|
|
2892
|
-
case
|
|
3409
|
+
case 27:
|
|
2893
3410
|
perfMark('silentRefresh', performance.now() - t0, {
|
|
2894
3411
|
count: this.store.list.length
|
|
2895
3412
|
});
|
|
2896
|
-
return
|
|
2897
|
-
case
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
errorMessage =
|
|
3413
|
+
return _context38.abrupt("return", this.store.list);
|
|
3414
|
+
case 31:
|
|
3415
|
+
_context38.prev = 31;
|
|
3416
|
+
_context38.t0 = _context38["catch"](12);
|
|
3417
|
+
errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0);
|
|
2901
3418
|
this.logError('silentRefresh 失败', {
|
|
2902
3419
|
trigger: trigger,
|
|
2903
3420
|
duration: "".concat(Math.round(performance.now() - t0), "ms"),
|
|
2904
3421
|
error: errorMessage
|
|
2905
3422
|
});
|
|
2906
|
-
return
|
|
2907
|
-
case
|
|
3423
|
+
return _context38.abrupt("return", this.store.list);
|
|
3424
|
+
case 36:
|
|
2908
3425
|
case "end":
|
|
2909
|
-
return
|
|
3426
|
+
return _context38.stop();
|
|
2910
3427
|
}
|
|
2911
|
-
},
|
|
3428
|
+
}, _callee37, this, [[12, 31]]);
|
|
2912
3429
|
}));
|
|
2913
3430
|
function silentRefresh() {
|
|
2914
3431
|
return _silentRefresh.apply(this, arguments);
|
|
@@ -2923,6 +3440,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2923
3440
|
key: "destroyProductSync",
|
|
2924
3441
|
value: function destroyProductSync() {
|
|
2925
3442
|
var _this$productDataSour;
|
|
3443
|
+
void this.core.effects.emit(ProductsHooks.onProductSyncDestroyed, null);
|
|
3444
|
+
this.disableProductReplicationSource();
|
|
3445
|
+
this.requestReplicaRefresh = undefined;
|
|
2926
3446
|
if (this.syncTimer) {
|
|
2927
3447
|
clearTimeout(this.syncTimer);
|
|
2928
3448
|
this.syncTimer = undefined;
|
|
@@ -2933,6 +3453,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2933
3453
|
this.pendingSyncMessages = [];
|
|
2934
3454
|
this.logInfo('destroyProductSync: 同步资源已销毁');
|
|
2935
3455
|
}
|
|
3456
|
+
}, {
|
|
3457
|
+
key: "destroy",
|
|
3458
|
+
value: function destroy() {
|
|
3459
|
+
this.runtimeSyncGeneration += 1;
|
|
3460
|
+
this.destroyProductSync();
|
|
3461
|
+
_get(_getPrototypeOf(ProductsModule.prototype), "destroy", this).call(this);
|
|
3462
|
+
}
|
|
2936
3463
|
|
|
2937
3464
|
/**
|
|
2938
3465
|
* 获取模块的路由定义
|