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