@pisell/pisellos 2.2.261 → 2.2.263
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/dataVariant/adapter.d.ts +50 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
- package/dist/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +5 -1
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
- package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
- package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
- package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
- package/dist/model/strategy/adapter/promotion/examples.js +0 -99
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +1 -1
- package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
- package/dist/model/strategy/adapter/promotion/type.js +0 -45
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
- package/dist/modules/Discount/index.d.ts +5 -2
- package/dist/modules/Discount/index.js +30 -7
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +14 -2
- package/dist/modules/Order/index.js +1035 -736
- package/dist/modules/Order/types.d.ts +16 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
- package/dist/modules/Order/utils.d.ts +4 -3
- package/dist/modules/Order/utils.js +54 -61
- package/dist/modules/Product/types.d.ts +22 -0
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +4 -2
- package/dist/modules/ProductList/types.d.ts +2 -0
- package/dist/modules/Rules/index.d.ts +2 -9
- package/dist/modules/Rules/index.js +69 -43
- package/dist/modules/Rules/types.d.ts +10 -1
- package/dist/server/index.d.ts +55 -0
- package/dist/server/index.js +1173 -753
- package/dist/server/modules/order/index.d.ts +10 -4
- package/dist/server/modules/order/index.js +404 -399
- package/dist/server/modules/order/types.d.ts +4 -0
- package/dist/server/modules/products/index.d.ts +31 -8
- package/dist/server/modules/products/index.js +549 -390
- package/dist/server/modules/products/types.d.ts +18 -0
- package/dist/solution/BaseSales/index.d.ts +21 -1
- package/dist/solution/BaseSales/index.js +1136 -789
- package/dist/solution/BaseSales/types.d.ts +6 -1
- package/dist/solution/BaseSales/types.js +1 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +48 -81
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +59 -25
- package/dist/solution/BookingTicket/types.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +20 -31
- package/dist/solution/ShopDiscount/index.js +15 -14
- package/dist/solution/VenueBooking/index.js +19 -30
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +13 -2
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
- package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
- package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
- package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
- package/lib/model/strategy/adapter/promotion/examples.js +0 -91
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +0 -51
- package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
- package/lib/model/strategy/adapter/promotion/type.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
- package/lib/modules/Discount/index.d.ts +5 -2
- package/lib/modules/Discount/index.js +23 -3
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +14 -2
- package/lib/modules/Order/index.js +326 -60
- package/lib/modules/Order/types.d.ts +16 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
- package/lib/modules/Order/utils.d.ts +4 -3
- package/lib/modules/Order/utils.js +22 -23
- package/lib/modules/Product/types.d.ts +22 -0
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +4 -2
- package/lib/modules/ProductList/types.d.ts +2 -0
- package/lib/modules/Rules/index.d.ts +2 -9
- package/lib/modules/Rules/index.js +61 -29
- package/lib/modules/Rules/types.d.ts +10 -1
- package/lib/server/index.d.ts +55 -0
- package/lib/server/index.js +332 -34
- package/lib/server/modules/order/index.d.ts +10 -4
- package/lib/server/modules/order/index.js +198 -139
- package/lib/server/modules/order/types.d.ts +4 -0
- package/lib/server/modules/products/index.d.ts +31 -8
- package/lib/server/modules/products/index.js +134 -35
- package/lib/server/modules/products/types.d.ts +18 -0
- package/lib/solution/BaseSales/index.d.ts +21 -1
- package/lib/solution/BaseSales/index.js +313 -72
- package/lib/solution/BaseSales/types.d.ts +6 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +29 -60
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +33 -8
- package/lib/solution/BookingTicket/types.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +0 -8
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/lib/solution/VenueBooking/index.js +0 -8
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7
2
|
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
3
|
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
4
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
+
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."); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
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
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
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
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; } } }; }
|
|
@@ -32,7 +32,6 @@ import { BaseModule } from "../../../modules/BaseModule";
|
|
|
32
32
|
import { QuotationModule as ClientQuotationModule } from "../../../modules/Quotation";
|
|
33
33
|
import { ProductsHooks } from "./types";
|
|
34
34
|
import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
|
|
35
|
-
|
|
36
35
|
/**
|
|
37
36
|
* IndexDB 存储名称
|
|
38
37
|
*/
|
|
@@ -69,8 +68,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
69
68
|
// 最多缓存7天
|
|
70
69
|
// 商品格式化器列表
|
|
71
70
|
_defineProperty(_assertThisInitialized(_this), "formatters", []);
|
|
72
|
-
//
|
|
73
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
71
|
+
// 是否已注册内置商品格式化器
|
|
72
|
+
_defineProperty(_assertThisInitialized(_this), "isBuiltinFormatterRegistered", false);
|
|
73
|
+
// 旧报价单格式化器默认关闭,仅显式开启时作为兼容兜底注册
|
|
74
|
+
_defineProperty(_assertThisInitialized(_this), "isLegacyPriceFormatterEnabled", false);
|
|
74
75
|
// 普通层 QuotationModule 桥接器:本地计算报价单价格,替代 /product/query/price
|
|
75
76
|
_defineProperty(_assertThisInitialized(_this), "quotationPriceBridge", void 0);
|
|
76
77
|
_defineProperty(_assertThisInitialized(_this), "quotationBridgeChannel", void 0);
|
|
@@ -90,6 +91,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
90
91
|
_defineProperty(_assertThisInitialized(_this), "lastPreloadCompletedAtMs", 0);
|
|
91
92
|
/** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
|
|
92
93
|
_defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
|
|
94
|
+
/** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
|
|
95
|
+
_defineProperty(_assertThisInitialized(_this), "lastScheduleTimePoints", []);
|
|
93
96
|
return _this;
|
|
94
97
|
}
|
|
95
98
|
_createClass(ProductsModule, [{
|
|
@@ -128,8 +131,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
//
|
|
132
|
-
this.
|
|
134
|
+
// 注册内置商品格式化器;智能定价默认替代报价单价格逻辑
|
|
135
|
+
this.registerBuiltinProductFormatters();
|
|
133
136
|
|
|
134
137
|
// 初始化 ProductDataSource 实例
|
|
135
138
|
this.initProductDataSource();
|
|
@@ -743,7 +746,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
743
746
|
key: "prepareProductsWithPrice",
|
|
744
747
|
value: (function () {
|
|
745
748
|
var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(schedule_date, extraContext, options) {
|
|
746
|
-
var tTotal, targetIds, isIncremental,
|
|
749
|
+
var tTotal, targetIds, isIncremental, _this$core, _this$core2, products, ids, tIds, i, priceData, _priceData$length, _priceData, tPrice, context, tFormat, processedProducts, errorMessage;
|
|
747
750
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
748
751
|
while (1) switch (_context7.prev = _context7.next) {
|
|
749
752
|
case 0:
|
|
@@ -778,34 +781,44 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
778
781
|
productCount: products.length
|
|
779
782
|
});
|
|
780
783
|
|
|
781
|
-
// 2.
|
|
784
|
+
// 2. 仅在 legacy 报价单 formatter 启用时加载报价单价格;默认由智能定价覆盖商品价格。
|
|
785
|
+
priceData = [];
|
|
786
|
+
if (!this.isLegacyPriceFormatterEnabled) {
|
|
787
|
+
_context7.next = 15;
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
782
790
|
tPrice = performance.now();
|
|
783
|
-
_context7.next =
|
|
791
|
+
_context7.next = 12;
|
|
784
792
|
return this.loadProductsPrice({
|
|
785
793
|
ids: ids,
|
|
786
794
|
schedule_date: schedule_date,
|
|
787
795
|
schedule_datetime: extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime,
|
|
788
796
|
customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id
|
|
789
797
|
});
|
|
790
|
-
case
|
|
798
|
+
case 12:
|
|
791
799
|
priceData = _context7.sent;
|
|
792
800
|
perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
|
|
793
801
|
count: ids.length
|
|
794
802
|
});
|
|
795
803
|
this.logInfo('获取商品报价单价格成功', {
|
|
796
|
-
priceDataCount: (_priceData$length = priceData === null ||
|
|
804
|
+
priceDataCount: (_priceData$length = (_priceData = priceData) === null || _priceData === void 0 ? void 0 : _priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
|
|
797
805
|
});
|
|
806
|
+
case 15:
|
|
798
807
|
context = _objectSpread({
|
|
799
808
|
schedule_date: schedule_date,
|
|
800
809
|
schedule_datetime: extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime,
|
|
801
810
|
customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id,
|
|
802
811
|
priceData: priceData,
|
|
803
|
-
locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale
|
|
812
|
+
locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale,
|
|
813
|
+
dataVariantEvaluator: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.dataVariantEvaluator) || ((_this$core2 = this.core) === null || _this$core2 === void 0 || (_this$core2 = _this$core2.context) === null || _this$core2 === void 0 ? void 0 : _this$core2.dataVariantEvaluator),
|
|
814
|
+
menuList: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.menuList) || [],
|
|
815
|
+
scheduleList: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.scheduleList) || [],
|
|
816
|
+
strategy_context: extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context
|
|
804
817
|
}, extraContext); // 3. 通过格式化器流程处理商品
|
|
805
818
|
tFormat = performance.now();
|
|
806
|
-
_context7.next =
|
|
819
|
+
_context7.next = 19;
|
|
807
820
|
return this.applyFormatters(products, context);
|
|
808
|
-
case
|
|
821
|
+
case 19:
|
|
809
822
|
processedProducts = _context7.sent;
|
|
810
823
|
perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
|
|
811
824
|
count: products.length,
|
|
@@ -818,20 +831,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
818
831
|
formatterCount: this.formatters.length
|
|
819
832
|
});
|
|
820
833
|
if (isIncremental) {
|
|
821
|
-
_context7.next =
|
|
834
|
+
_context7.next = 25;
|
|
822
835
|
break;
|
|
823
836
|
}
|
|
824
|
-
_context7.next =
|
|
837
|
+
_context7.next = 25;
|
|
825
838
|
return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
|
|
826
|
-
case
|
|
839
|
+
case 25:
|
|
827
840
|
perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
|
|
828
841
|
productCount: products.length,
|
|
829
842
|
formatterCount: this.formatters.length,
|
|
830
843
|
mode: isIncremental ? 'incremental' : 'full'
|
|
831
844
|
});
|
|
832
845
|
return _context7.abrupt("return", processedProducts);
|
|
833
|
-
case
|
|
834
|
-
_context7.prev =
|
|
846
|
+
case 29:
|
|
847
|
+
_context7.prev = 29;
|
|
835
848
|
_context7.t0 = _context7["catch"](4);
|
|
836
849
|
errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
|
|
837
850
|
console.log("[ProductsModule] \uD83C\uDF10 ERROR", _context7.t0);
|
|
@@ -839,13 +852,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
839
852
|
schedule_date: schedule_date,
|
|
840
853
|
error: errorMessage
|
|
841
854
|
});
|
|
842
|
-
case
|
|
855
|
+
case 34:
|
|
843
856
|
return _context7.abrupt("return", []);
|
|
844
|
-
case
|
|
857
|
+
case 35:
|
|
845
858
|
case "end":
|
|
846
859
|
return _context7.stop();
|
|
847
860
|
}
|
|
848
|
-
}, _callee7, this, [[4,
|
|
861
|
+
}, _callee7, this, [[4, 29]]);
|
|
849
862
|
}));
|
|
850
863
|
function prepareProductsWithPrice(_x10, _x11, _x12) {
|
|
851
864
|
return _prepareProductsWithPrice.apply(this, arguments);
|
|
@@ -858,7 +871,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
858
871
|
var _extraContext$custome;
|
|
859
872
|
var datetime = (extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime) || schedule_date;
|
|
860
873
|
var productScope = productIds ? ":products:".concat(productIds.join(',')) : '';
|
|
861
|
-
|
|
874
|
+
var strategyScope = this.stringifyStable((extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context) || {});
|
|
875
|
+
return "".concat(datetime, ":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);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* 稳定序列化策略上下文,避免对象 key 顺序不同导致缓存 key 抖动。
|
|
880
|
+
*/
|
|
881
|
+
}, {
|
|
882
|
+
key: "stringifyStable",
|
|
883
|
+
value: function stringifyStable(value) {
|
|
884
|
+
var _this7 = this;
|
|
885
|
+
if (value == null) return '';
|
|
886
|
+
if (Array.isArray(value)) return "[".concat(value.map(function (item) {
|
|
887
|
+
return _this7.stringifyStable(item);
|
|
888
|
+
}).join(','), "]");
|
|
889
|
+
if (_typeof(value) === 'object') {
|
|
890
|
+
return "{".concat(Object.keys(value).sort().map(function (key) {
|
|
891
|
+
return "".concat(key, ":").concat(_this7.stringifyStable(value[key]));
|
|
892
|
+
}).join(','), "}");
|
|
893
|
+
}
|
|
894
|
+
return String(value);
|
|
862
895
|
}
|
|
863
896
|
}, {
|
|
864
897
|
key: "normalizeProductIds",
|
|
@@ -1004,26 +1037,56 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1004
1037
|
return applyFormatters;
|
|
1005
1038
|
}()
|
|
1006
1039
|
/**
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1040
|
+
* 注册内置商品格式化器。
|
|
1041
|
+
*
|
|
1042
|
+
* 智能定价默认替代报价单逻辑;报价单 formatter 仅在 enableLegacyPriceFormatter=true 时启用。
|
|
1009
1043
|
* @private
|
|
1010
1044
|
*/
|
|
1011
1045
|
)
|
|
1012
1046
|
}, {
|
|
1013
|
-
key: "
|
|
1014
|
-
value: function
|
|
1015
|
-
|
|
1016
|
-
|
|
1047
|
+
key: "registerBuiltinProductFormatters",
|
|
1048
|
+
value: function registerBuiltinProductFormatters() {
|
|
1049
|
+
var _this8 = this;
|
|
1050
|
+
if (this.isBuiltinFormatterRegistered) {
|
|
1051
|
+
console.warn('[ProductsModule] 内置商品格式化器已注册,跳过');
|
|
1017
1052
|
return;
|
|
1018
1053
|
}
|
|
1054
|
+
this.isLegacyPriceFormatterEnabled = this.shouldEnableLegacyPriceFormatter();
|
|
1055
|
+
var dataVariantFormatter = function dataVariantFormatter(products, context) {
|
|
1056
|
+
var _this8$core, _strategyContext$busi;
|
|
1057
|
+
var evaluator = context.dataVariantEvaluator || ((_this8$core = _this8.core) === null || _this8$core === void 0 || (_this8$core = _this8$core.context) === null || _this8$core === void 0 ? void 0 : _this8$core.dataVariantEvaluator);
|
|
1058
|
+
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
1059
|
+
_this8.lastScheduleTimePoints = [];
|
|
1060
|
+
_this8.logWarning('智能定价评估器未注入,跳过 DataVariant 格式化', {
|
|
1061
|
+
productCount: products.length
|
|
1062
|
+
});
|
|
1063
|
+
return products;
|
|
1064
|
+
}
|
|
1065
|
+
var strategyContext = context.strategy_context || {};
|
|
1066
|
+
var businessData = {
|
|
1067
|
+
products: products,
|
|
1068
|
+
scheduleDateTime: context.schedule_datetime || context.schedule_date,
|
|
1069
|
+
scheduleList: context.scheduleList || [],
|
|
1070
|
+
menuList: context.menuList || [],
|
|
1071
|
+
customerId: context.customer_id,
|
|
1072
|
+
channel: strategyContext.channel,
|
|
1073
|
+
orderType: strategyContext.orderType || strategyContext.order_type,
|
|
1074
|
+
businessCode: (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : strategyContext.businessCode,
|
|
1075
|
+
availableWalletIds: strategyContext.available_wallet_ids,
|
|
1076
|
+
custom: strategyContext
|
|
1077
|
+
};
|
|
1078
|
+
var result = evaluator.resolveProducts(businessData);
|
|
1079
|
+
_this8.lastScheduleTimePoints = Array.isArray(result === null || result === void 0 ? void 0 : result.scheduleTimePoints) ? _toConsumableArray(result.scheduleTimePoints) : [];
|
|
1080
|
+
return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
|
|
1081
|
+
};
|
|
1019
1082
|
|
|
1020
|
-
//
|
|
1021
|
-
var
|
|
1083
|
+
// 创建 legacy 报价单格式化器
|
|
1084
|
+
var legacyPriceFormatter = function legacyPriceFormatter(products, context) {
|
|
1022
1085
|
if (!context.priceData || context.priceData.length === 0) {
|
|
1023
|
-
console.log('[ProductsModule] 💰
|
|
1086
|
+
console.log('[ProductsModule] 💰 没有价格数据,跳过 legacy 报价单价格应用');
|
|
1024
1087
|
return products;
|
|
1025
1088
|
}
|
|
1026
|
-
console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528\u4EF7\
|
|
1089
|
+
console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528 legacy \u62A5\u4EF7\u5355\u4EF7\u683C\u5230 ".concat(products.length, " \u4E2A\u5546\u54C1"));
|
|
1027
1090
|
return applyPriceDataToProducts(products, context.priceData);
|
|
1028
1091
|
};
|
|
1029
1092
|
var i18nFormatter = function i18nFormatter(products, context) {
|
|
@@ -1032,18 +1095,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1032
1095
|
var detailValueFormatter = function detailValueFormatter(products, context) {
|
|
1033
1096
|
return applyDetailValueToProducts(products, context);
|
|
1034
1097
|
};
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1098
|
+
if (this.isLegacyPriceFormatterEnabled) {
|
|
1099
|
+
this.formatters.push(legacyPriceFormatter);
|
|
1100
|
+
}
|
|
1101
|
+
this.formatters.push(dataVariantFormatter);
|
|
1038
1102
|
this.formatters.push(i18nFormatter);
|
|
1039
1103
|
this.formatters.push(detailValueFormatter);
|
|
1040
|
-
this.
|
|
1041
|
-
console.log('[ProductsModule] ✅
|
|
1104
|
+
this.isBuiltinFormatterRegistered = true;
|
|
1105
|
+
console.log('[ProductsModule] ✅ 内置商品格式化器已注册(智能定价优先)');
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* 是否启用旧报价单价格 formatter。
|
|
1110
|
+
*
|
|
1111
|
+
* 默认关闭,避免报价单逻辑覆盖智能定价结果。
|
|
1112
|
+
*/
|
|
1113
|
+
}, {
|
|
1114
|
+
key: "shouldEnableLegacyPriceFormatter",
|
|
1115
|
+
value: function shouldEnableLegacyPriceFormatter() {
|
|
1116
|
+
var _this$otherParams3, _this$core3;
|
|
1117
|
+
return ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.enableLegacyPriceFormatter) === true || ((_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.enableLegacyPriceFormatter) === true;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* 返回最近一次 prepareProductsWithPrice / DataVariant 评估提取的变价时间点(HH:mm)。
|
|
1122
|
+
* 供 OS Server 商品 query 订阅定时刷新使用。
|
|
1123
|
+
*/
|
|
1124
|
+
}, {
|
|
1125
|
+
key: "getLastScheduleTimePoints",
|
|
1126
|
+
value: function getLastScheduleTimePoints() {
|
|
1127
|
+
return _toConsumableArray(this.lastScheduleTimePoints);
|
|
1042
1128
|
}
|
|
1043
1129
|
|
|
1044
1130
|
/**
|
|
1045
1131
|
* 注册商品格式化器
|
|
1046
|
-
*
|
|
1132
|
+
* 格式化器会按注册顺序依次执行;legacy 启用时先兜底报价,再由智能定价覆盖。
|
|
1047
1133
|
* @param formatter 格式化函数
|
|
1048
1134
|
* @param prepend 是否插入到队列开头(默认 false,追加到末尾)
|
|
1049
1135
|
* @example
|
|
@@ -1061,8 +1147,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1061
1147
|
value: function registerFormatter(formatter) {
|
|
1062
1148
|
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1063
1149
|
if (prepend) {
|
|
1064
|
-
//
|
|
1065
|
-
var insertIndex = this.
|
|
1150
|
+
// 插入到内置智能定价格式化器之后;legacy 报价单启用时需跳过它。
|
|
1151
|
+
var insertIndex = this.isBuiltinFormatterRegistered ? this.isLegacyPriceFormatterEnabled ? 2 : 1 : 0;
|
|
1066
1152
|
this.formatters.splice(insertIndex, 0, formatter);
|
|
1067
1153
|
console.log("[ProductsModule] \uD83D\uDCCC \u5DF2\u5728\u4F4D\u7F6E ".concat(insertIndex + 1, " \u63D2\u5165\u683C\u5F0F\u5316\u5668\uFF0C\u5F53\u524D\u5171 ").concat(this.formatters.length, " \u4E2A"));
|
|
1068
1154
|
} else {
|
|
@@ -1073,20 +1159,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1073
1159
|
}
|
|
1074
1160
|
|
|
1075
1161
|
/**
|
|
1076
|
-
*
|
|
1077
|
-
* @param keepBuiltin
|
|
1162
|
+
* 清空所有格式化器(包括内置智能定价格式化器)
|
|
1163
|
+
* @param keepBuiltin 是否保留内置智能定价格式化器(默认 true)
|
|
1078
1164
|
*/
|
|
1079
1165
|
}, {
|
|
1080
1166
|
key: "clearFormatters",
|
|
1081
1167
|
value: function clearFormatters() {
|
|
1082
1168
|
var keepBuiltin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1083
|
-
if (keepBuiltin && this.
|
|
1084
|
-
//
|
|
1085
|
-
|
|
1086
|
-
|
|
1169
|
+
if (keepBuiltin && this.isBuiltinFormatterRegistered) {
|
|
1170
|
+
// 保留 legacy 兜底(如果启用)和智能定价格式化器。
|
|
1171
|
+
var builtinCount = this.isLegacyPriceFormatterEnabled ? 2 : 1;
|
|
1172
|
+
this.formatters = this.formatters.slice(0, builtinCount);
|
|
1173
|
+
console.log('[ProductsModule] 🧹 已清空自定义格式化器,保留内置智能定价格式化器');
|
|
1087
1174
|
} else {
|
|
1088
1175
|
this.formatters = [];
|
|
1089
|
-
this.
|
|
1176
|
+
this.isBuiltinFormatterRegistered = false;
|
|
1090
1177
|
console.log('[ProductsModule] 🧹 已清空所有格式化器');
|
|
1091
1178
|
}
|
|
1092
1179
|
}
|
|
@@ -1197,7 +1284,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1197
1284
|
key: "fetchProductsByHttp",
|
|
1198
1285
|
value: (function () {
|
|
1199
1286
|
var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
1200
|
-
var _ref13, _ref13$category_ids, category_ids, _ref13$product_ids, product_ids, _ref13$collection, collection, customer_id, cacheId, startTime, _this$
|
|
1287
|
+
var _ref13, _ref13$category_ids, category_ids, _ref13$product_ids, product_ids, _ref13$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
|
|
1201
1288
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1202
1289
|
while (1) switch (_context10.prev = _context10.next) {
|
|
1203
1290
|
case 0:
|
|
@@ -1215,7 +1302,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1215
1302
|
open_bundle: 1,
|
|
1216
1303
|
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
1217
1304
|
force_ignore_cache_flag: 1,
|
|
1218
|
-
with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem'],
|
|
1305
|
+
with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem', 'dataVariants'],
|
|
1219
1306
|
open_deposit: 1,
|
|
1220
1307
|
is_append_product_description: 1,
|
|
1221
1308
|
with_count: ['bundleGroup', 'optionGroup'],
|
|
@@ -1227,7 +1314,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1227
1314
|
ids: product_ids,
|
|
1228
1315
|
collection: collection,
|
|
1229
1316
|
front_end_cache_id: cacheId,
|
|
1230
|
-
application_code: (_this$
|
|
1317
|
+
application_code: (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.channel
|
|
1231
1318
|
}, {
|
|
1232
1319
|
cache: undefined
|
|
1233
1320
|
});
|
|
@@ -1332,6 +1419,74 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1332
1419
|
}
|
|
1333
1420
|
return getProducts;
|
|
1334
1421
|
}()
|
|
1422
|
+
/**
|
|
1423
|
+
* 批量获取商品轻量快照,供订单详情等响应补齐展示协议字段。
|
|
1424
|
+
*/
|
|
1425
|
+
)
|
|
1426
|
+
}, {
|
|
1427
|
+
key: "getProductSnapshotsByIds",
|
|
1428
|
+
value: (function () {
|
|
1429
|
+
var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
|
|
1430
|
+
var snapshots, seen, _iterator6, _step6, id, product;
|
|
1431
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1432
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1433
|
+
case 0:
|
|
1434
|
+
snapshots = {};
|
|
1435
|
+
seen = new Set();
|
|
1436
|
+
_iterator6 = _createForOfIteratorHelper(ids);
|
|
1437
|
+
_context13.prev = 3;
|
|
1438
|
+
_iterator6.s();
|
|
1439
|
+
case 5:
|
|
1440
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
1441
|
+
_context13.next = 16;
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1444
|
+
id = _step6.value;
|
|
1445
|
+
if (!(!Number.isFinite(id) || seen.has(id))) {
|
|
1446
|
+
_context13.next = 9;
|
|
1447
|
+
break;
|
|
1448
|
+
}
|
|
1449
|
+
return _context13.abrupt("continue", 14);
|
|
1450
|
+
case 9:
|
|
1451
|
+
seen.add(id);
|
|
1452
|
+
product = this.store.map.get(id);
|
|
1453
|
+
if (product) {
|
|
1454
|
+
_context13.next = 13;
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
return _context13.abrupt("continue", 14);
|
|
1458
|
+
case 13:
|
|
1459
|
+
snapshots[String(id)] = {
|
|
1460
|
+
cover: product.cover,
|
|
1461
|
+
holder_config: product.holder_config
|
|
1462
|
+
};
|
|
1463
|
+
case 14:
|
|
1464
|
+
_context13.next = 5;
|
|
1465
|
+
break;
|
|
1466
|
+
case 16:
|
|
1467
|
+
_context13.next = 21;
|
|
1468
|
+
break;
|
|
1469
|
+
case 18:
|
|
1470
|
+
_context13.prev = 18;
|
|
1471
|
+
_context13.t0 = _context13["catch"](3);
|
|
1472
|
+
_iterator6.e(_context13.t0);
|
|
1473
|
+
case 21:
|
|
1474
|
+
_context13.prev = 21;
|
|
1475
|
+
_iterator6.f();
|
|
1476
|
+
return _context13.finish(21);
|
|
1477
|
+
case 24:
|
|
1478
|
+
return _context13.abrupt("return", snapshots);
|
|
1479
|
+
case 25:
|
|
1480
|
+
case "end":
|
|
1481
|
+
return _context13.stop();
|
|
1482
|
+
}
|
|
1483
|
+
}, _callee13, this, [[3, 18, 21, 24]]);
|
|
1484
|
+
}));
|
|
1485
|
+
function getProductSnapshotsByIds(_x17) {
|
|
1486
|
+
return _getProductSnapshotsByIds.apply(this, arguments);
|
|
1487
|
+
}
|
|
1488
|
+
return getProductSnapshotsByIds;
|
|
1489
|
+
}()
|
|
1335
1490
|
/**
|
|
1336
1491
|
* 内部获取商品列表的直接引用(无拷贝)
|
|
1337
1492
|
* 仅供内部 formatter 流程使用,因为 formatter 会创建新对象
|
|
@@ -1350,18 +1505,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1350
1505
|
key: "getProductsRefByIds",
|
|
1351
1506
|
value: function getProductsRefByIds(ids) {
|
|
1352
1507
|
var products = [];
|
|
1353
|
-
var
|
|
1354
|
-
|
|
1508
|
+
var _iterator7 = _createForOfIteratorHelper(ids),
|
|
1509
|
+
_step7;
|
|
1355
1510
|
try {
|
|
1356
|
-
for (
|
|
1357
|
-
var id =
|
|
1511
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1512
|
+
var id = _step7.value;
|
|
1358
1513
|
var product = this.store.map.get(id);
|
|
1359
1514
|
if (product) products.push(product);
|
|
1360
1515
|
}
|
|
1361
1516
|
} catch (err) {
|
|
1362
|
-
|
|
1517
|
+
_iterator7.e(err);
|
|
1363
1518
|
} finally {
|
|
1364
|
-
|
|
1519
|
+
_iterator7.f();
|
|
1365
1520
|
}
|
|
1366
1521
|
return products;
|
|
1367
1522
|
}
|
|
@@ -1373,20 +1528,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1373
1528
|
}, {
|
|
1374
1529
|
key: "getProductById",
|
|
1375
1530
|
value: (function () {
|
|
1376
|
-
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1531
|
+
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(id) {
|
|
1377
1532
|
var product;
|
|
1378
|
-
return _regeneratorRuntime().wrap(function
|
|
1379
|
-
while (1) switch (
|
|
1533
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1534
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1380
1535
|
case 0:
|
|
1381
1536
|
product = this.store.map.get(id);
|
|
1382
|
-
return
|
|
1537
|
+
return _context14.abrupt("return", product ? structuredClone(product) : undefined);
|
|
1383
1538
|
case 2:
|
|
1384
1539
|
case "end":
|
|
1385
|
-
return
|
|
1540
|
+
return _context14.stop();
|
|
1386
1541
|
}
|
|
1387
|
-
},
|
|
1542
|
+
}, _callee14, this);
|
|
1388
1543
|
}));
|
|
1389
|
-
function getProductById(
|
|
1544
|
+
function getProductById(_x18) {
|
|
1390
1545
|
return _getProductById.apply(this, arguments);
|
|
1391
1546
|
}
|
|
1392
1547
|
return getProductById;
|
|
@@ -1399,10 +1554,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1399
1554
|
}, {
|
|
1400
1555
|
key: "removeProductsByIds",
|
|
1401
1556
|
value: (function () {
|
|
1402
|
-
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1403
|
-
var idSet,
|
|
1404
|
-
return _regeneratorRuntime().wrap(function
|
|
1405
|
-
while (1) switch (
|
|
1557
|
+
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
|
|
1558
|
+
var idSet, _iterator8, _step8, _id, _iterator9, _step9, id, errorMessage, _iterator10, _step10, _step10$value, dateKey, cachedProducts;
|
|
1559
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1560
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1406
1561
|
case 0:
|
|
1407
1562
|
idSet = new Set(ids);
|
|
1408
1563
|
this.logInfo('removeProductsByIds', {
|
|
@@ -1412,71 +1567,71 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1412
1567
|
this.store.list = this.store.list.filter(function (p) {
|
|
1413
1568
|
return !idSet.has(p.id);
|
|
1414
1569
|
});
|
|
1415
|
-
|
|
1570
|
+
_iterator8 = _createForOfIteratorHelper(ids);
|
|
1416
1571
|
try {
|
|
1417
|
-
for (
|
|
1418
|
-
_id =
|
|
1572
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1573
|
+
_id = _step8.value;
|
|
1419
1574
|
this.store.map.delete(_id);
|
|
1420
1575
|
}
|
|
1421
1576
|
} catch (err) {
|
|
1422
|
-
|
|
1577
|
+
_iterator8.e(err);
|
|
1423
1578
|
} finally {
|
|
1424
|
-
|
|
1579
|
+
_iterator8.f();
|
|
1425
1580
|
}
|
|
1426
1581
|
if (!this.dbManager) {
|
|
1427
|
-
|
|
1582
|
+
_context15.next = 30;
|
|
1428
1583
|
break;
|
|
1429
1584
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1585
|
+
_context15.prev = 6;
|
|
1586
|
+
_iterator9 = _createForOfIteratorHelper(ids);
|
|
1587
|
+
_context15.prev = 8;
|
|
1588
|
+
_iterator9.s();
|
|
1434
1589
|
case 10:
|
|
1435
|
-
if ((
|
|
1436
|
-
|
|
1590
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1591
|
+
_context15.next = 16;
|
|
1437
1592
|
break;
|
|
1438
1593
|
}
|
|
1439
|
-
id =
|
|
1440
|
-
|
|
1594
|
+
id = _step9.value;
|
|
1595
|
+
_context15.next = 14;
|
|
1441
1596
|
return this.dbManager.delete(INDEXDB_STORE_NAME, id);
|
|
1442
1597
|
case 14:
|
|
1443
|
-
|
|
1598
|
+
_context15.next = 10;
|
|
1444
1599
|
break;
|
|
1445
1600
|
case 16:
|
|
1446
|
-
|
|
1601
|
+
_context15.next = 21;
|
|
1447
1602
|
break;
|
|
1448
1603
|
case 18:
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1604
|
+
_context15.prev = 18;
|
|
1605
|
+
_context15.t0 = _context15["catch"](8);
|
|
1606
|
+
_iterator9.e(_context15.t0);
|
|
1452
1607
|
case 21:
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
return
|
|
1608
|
+
_context15.prev = 21;
|
|
1609
|
+
_iterator9.f();
|
|
1610
|
+
return _context15.finish(21);
|
|
1456
1611
|
case 24:
|
|
1457
|
-
|
|
1612
|
+
_context15.next = 30;
|
|
1458
1613
|
break;
|
|
1459
1614
|
case 26:
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
errorMessage =
|
|
1615
|
+
_context15.prev = 26;
|
|
1616
|
+
_context15.t1 = _context15["catch"](6);
|
|
1617
|
+
errorMessage = _context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1);
|
|
1463
1618
|
this.logError('removeProductsByIds: IndexDB 删除失败', {
|
|
1464
1619
|
ids: ids,
|
|
1465
1620
|
error: errorMessage
|
|
1466
1621
|
});
|
|
1467
1622
|
case 30:
|
|
1468
|
-
|
|
1623
|
+
_iterator10 = _createForOfIteratorHelper(this.productsPriceCache.entries());
|
|
1469
1624
|
try {
|
|
1470
|
-
for (
|
|
1471
|
-
|
|
1625
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1626
|
+
_step10$value = _slicedToArray(_step10.value, 2), dateKey = _step10$value[0], cachedProducts = _step10$value[1];
|
|
1472
1627
|
this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
|
|
1473
1628
|
return !idSet.has(p.id);
|
|
1474
1629
|
}));
|
|
1475
1630
|
}
|
|
1476
1631
|
} catch (err) {
|
|
1477
|
-
|
|
1632
|
+
_iterator10.e(err);
|
|
1478
1633
|
} finally {
|
|
1479
|
-
|
|
1634
|
+
_iterator10.f();
|
|
1480
1635
|
}
|
|
1481
1636
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
1482
1637
|
this.logInfo('removeProductsByIds 完成', {
|
|
@@ -1484,11 +1639,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1484
1639
|
});
|
|
1485
1640
|
case 34:
|
|
1486
1641
|
case "end":
|
|
1487
|
-
return
|
|
1642
|
+
return _context15.stop();
|
|
1488
1643
|
}
|
|
1489
|
-
},
|
|
1644
|
+
}, _callee15, this, [[6, 26], [8, 18, 21, 24]]);
|
|
1490
1645
|
}));
|
|
1491
|
-
function removeProductsByIds(
|
|
1646
|
+
function removeProductsByIds(_x19) {
|
|
1492
1647
|
return _removeProductsByIds.apply(this, arguments);
|
|
1493
1648
|
}
|
|
1494
1649
|
return removeProductsByIds;
|
|
@@ -1501,17 +1656,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1501
1656
|
}, {
|
|
1502
1657
|
key: "refreshProducts",
|
|
1503
1658
|
value: (function () {
|
|
1504
|
-
var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1659
|
+
var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
1505
1660
|
var tTotal, products;
|
|
1506
|
-
return _regeneratorRuntime().wrap(function
|
|
1507
|
-
while (1) switch (
|
|
1661
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1662
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1508
1663
|
case 0:
|
|
1509
1664
|
tTotal = performance.now();
|
|
1510
1665
|
this.logInfo('refreshProducts 开始');
|
|
1511
|
-
|
|
1666
|
+
_context16.next = 4;
|
|
1512
1667
|
return this.loadProductsByServer();
|
|
1513
1668
|
case 4:
|
|
1514
|
-
products =
|
|
1669
|
+
products = _context16.sent;
|
|
1515
1670
|
if (products && products.length > 0) {
|
|
1516
1671
|
// 服务器返回的数据已经是全新的,无需 cloneDeep
|
|
1517
1672
|
this.store.list = products;
|
|
@@ -1526,12 +1681,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1526
1681
|
perfMark('refreshProducts', performance.now() - tTotal, {
|
|
1527
1682
|
count: this.store.list.length
|
|
1528
1683
|
});
|
|
1529
|
-
return
|
|
1684
|
+
return _context16.abrupt("return", this.store.list);
|
|
1530
1685
|
case 8:
|
|
1531
1686
|
case "end":
|
|
1532
|
-
return
|
|
1687
|
+
return _context16.stop();
|
|
1533
1688
|
}
|
|
1534
|
-
},
|
|
1689
|
+
}, _callee16, this);
|
|
1535
1690
|
}));
|
|
1536
1691
|
function refreshProducts() {
|
|
1537
1692
|
return _refreshProducts.apply(this, arguments);
|
|
@@ -1545,10 +1700,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1545
1700
|
}, {
|
|
1546
1701
|
key: "clear",
|
|
1547
1702
|
value: (function () {
|
|
1548
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1703
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
1549
1704
|
var errorMessage;
|
|
1550
|
-
return _regeneratorRuntime().wrap(function
|
|
1551
|
-
while (1) switch (
|
|
1705
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1706
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1552
1707
|
case 0:
|
|
1553
1708
|
this.logInfo('开始清空缓存', {
|
|
1554
1709
|
currentProductCount: this.store.list.length,
|
|
@@ -1559,22 +1714,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1559
1714
|
|
|
1560
1715
|
// 同时清空 IndexDB 中的所有数据(包括商品和元数据)
|
|
1561
1716
|
if (!this.dbManager) {
|
|
1562
|
-
|
|
1717
|
+
_context17.next = 16;
|
|
1563
1718
|
break;
|
|
1564
1719
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1720
|
+
_context17.prev = 4;
|
|
1721
|
+
_context17.next = 7;
|
|
1567
1722
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1568
1723
|
case 7:
|
|
1569
1724
|
console.log('[Products] IndexDB 缓存已清空');
|
|
1570
1725
|
this.logInfo('IndexDB 缓存已清空');
|
|
1571
|
-
|
|
1726
|
+
_context17.next = 16;
|
|
1572
1727
|
break;
|
|
1573
1728
|
case 11:
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
errorMessage =
|
|
1577
|
-
console.error('[Products] 清空 IndexDB 缓存失败:',
|
|
1729
|
+
_context17.prev = 11;
|
|
1730
|
+
_context17.t0 = _context17["catch"](4);
|
|
1731
|
+
errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
|
|
1732
|
+
console.error('[Products] 清空 IndexDB 缓存失败:', _context17.t0);
|
|
1578
1733
|
this.logError('清空 IndexDB 缓存失败', {
|
|
1579
1734
|
error: errorMessage
|
|
1580
1735
|
});
|
|
@@ -1583,9 +1738,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1583
1738
|
this.logInfo('缓存清空完成');
|
|
1584
1739
|
case 18:
|
|
1585
1740
|
case "end":
|
|
1586
|
-
return
|
|
1741
|
+
return _context17.stop();
|
|
1587
1742
|
}
|
|
1588
|
-
},
|
|
1743
|
+
}, _callee17, this, [[4, 11]]);
|
|
1589
1744
|
}));
|
|
1590
1745
|
function clear() {
|
|
1591
1746
|
return _clear.apply(this, arguments);
|
|
@@ -1600,45 +1755,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1600
1755
|
}, {
|
|
1601
1756
|
key: "loadProductsFromIndexDB",
|
|
1602
1757
|
value: (function () {
|
|
1603
|
-
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1758
|
+
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
|
|
1604
1759
|
var _products$length, _products$length2, t0, products, errorMessage;
|
|
1605
|
-
return _regeneratorRuntime().wrap(function
|
|
1606
|
-
while (1) switch (
|
|
1760
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1761
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1607
1762
|
case 0:
|
|
1608
1763
|
if (this.dbManager) {
|
|
1609
|
-
|
|
1764
|
+
_context18.next = 3;
|
|
1610
1765
|
break;
|
|
1611
1766
|
}
|
|
1612
1767
|
this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
|
|
1613
|
-
return
|
|
1768
|
+
return _context18.abrupt("return", []);
|
|
1614
1769
|
case 3:
|
|
1615
|
-
|
|
1770
|
+
_context18.prev = 3;
|
|
1616
1771
|
t0 = performance.now();
|
|
1617
|
-
|
|
1772
|
+
_context18.next = 7;
|
|
1618
1773
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
1619
1774
|
case 7:
|
|
1620
|
-
products =
|
|
1775
|
+
products = _context18.sent;
|
|
1621
1776
|
perfMark('loadProductsFromIndexDB', performance.now() - t0, {
|
|
1622
1777
|
count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
|
|
1623
1778
|
});
|
|
1624
1779
|
this.logInfo('从 IndexDB 加载商品数据', {
|
|
1625
1780
|
productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
|
|
1626
1781
|
});
|
|
1627
|
-
return
|
|
1782
|
+
return _context18.abrupt("return", products || []);
|
|
1628
1783
|
case 13:
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
errorMessage =
|
|
1632
|
-
console.error('[Products] 从 IndexDB 读取数据失败:',
|
|
1784
|
+
_context18.prev = 13;
|
|
1785
|
+
_context18.t0 = _context18["catch"](3);
|
|
1786
|
+
errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
|
|
1787
|
+
console.error('[Products] 从 IndexDB 读取数据失败:', _context18.t0);
|
|
1633
1788
|
this.logError('从 IndexDB 读取数据失败', {
|
|
1634
1789
|
error: errorMessage
|
|
1635
1790
|
});
|
|
1636
|
-
return
|
|
1791
|
+
return _context18.abrupt("return", []);
|
|
1637
1792
|
case 19:
|
|
1638
1793
|
case "end":
|
|
1639
|
-
return
|
|
1794
|
+
return _context18.stop();
|
|
1640
1795
|
}
|
|
1641
|
-
},
|
|
1796
|
+
}, _callee18, this, [[3, 13]]);
|
|
1642
1797
|
}));
|
|
1643
1798
|
function loadProductsFromIndexDB() {
|
|
1644
1799
|
return _loadProductsFromIndexDB.apply(this, arguments);
|
|
@@ -1657,10 +1812,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1657
1812
|
}, {
|
|
1658
1813
|
key: "runInProductIndexDBSaveQueue",
|
|
1659
1814
|
value: (function () {
|
|
1660
|
-
var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1815
|
+
var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(task) {
|
|
1661
1816
|
var queuedTask;
|
|
1662
|
-
return _regeneratorRuntime().wrap(function
|
|
1663
|
-
while (1) switch (
|
|
1817
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1818
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1664
1819
|
case 0:
|
|
1665
1820
|
queuedTask = this.productIndexDBSaveQueue.then(task, task);
|
|
1666
1821
|
this.productIndexDBSaveQueue = queuedTask.then(function () {
|
|
@@ -1668,14 +1823,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1668
1823
|
}, function () {
|
|
1669
1824
|
return undefined;
|
|
1670
1825
|
});
|
|
1671
|
-
return
|
|
1826
|
+
return _context19.abrupt("return", queuedTask);
|
|
1672
1827
|
case 3:
|
|
1673
1828
|
case "end":
|
|
1674
|
-
return
|
|
1829
|
+
return _context19.stop();
|
|
1675
1830
|
}
|
|
1676
|
-
},
|
|
1831
|
+
}, _callee19, this);
|
|
1677
1832
|
}));
|
|
1678
|
-
function runInProductIndexDBSaveQueue(
|
|
1833
|
+
function runInProductIndexDBSaveQueue(_x20) {
|
|
1679
1834
|
return _runInProductIndexDBSaveQueue.apply(this, arguments);
|
|
1680
1835
|
}
|
|
1681
1836
|
return runInProductIndexDBSaveQueue;
|
|
@@ -1690,61 +1845,61 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1690
1845
|
}, {
|
|
1691
1846
|
key: "replaceProductsSnapshotInIndexDB",
|
|
1692
1847
|
value: (function () {
|
|
1693
|
-
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1694
|
-
var
|
|
1848
|
+
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(products, source) {
|
|
1849
|
+
var _this9 = this;
|
|
1695
1850
|
var errorMessage;
|
|
1696
|
-
return _regeneratorRuntime().wrap(function
|
|
1697
|
-
while (1) switch (
|
|
1851
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1852
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1698
1853
|
case 0:
|
|
1699
1854
|
if (this.dbManager) {
|
|
1700
|
-
|
|
1855
|
+
_context21.next = 3;
|
|
1701
1856
|
break;
|
|
1702
1857
|
}
|
|
1703
1858
|
this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
|
|
1704
|
-
return
|
|
1859
|
+
return _context21.abrupt("return");
|
|
1705
1860
|
case 3:
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1861
|
+
_context21.prev = 3;
|
|
1862
|
+
_context21.next = 6;
|
|
1863
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
1709
1864
|
var t0;
|
|
1710
|
-
return _regeneratorRuntime().wrap(function
|
|
1711
|
-
while (1) switch (
|
|
1865
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1866
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1712
1867
|
case 0:
|
|
1713
|
-
|
|
1868
|
+
_this9.logInfo('replaceProductsSnapshotInIndexDB 开始', {
|
|
1714
1869
|
source: source,
|
|
1715
1870
|
productCount: products.length
|
|
1716
1871
|
});
|
|
1717
1872
|
t0 = performance.now();
|
|
1718
|
-
|
|
1719
|
-
return
|
|
1873
|
+
_context20.next = 4;
|
|
1874
|
+
return _this9.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1720
1875
|
case 4:
|
|
1721
1876
|
if (!(products.length > 0)) {
|
|
1722
|
-
|
|
1877
|
+
_context20.next = 7;
|
|
1723
1878
|
break;
|
|
1724
1879
|
}
|
|
1725
|
-
|
|
1726
|
-
return
|
|
1880
|
+
_context20.next = 7;
|
|
1881
|
+
return _this9.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
|
|
1727
1882
|
case 7:
|
|
1728
1883
|
perfMark('replaceProductsSnapshotInIndexDB', performance.now() - t0, {
|
|
1729
1884
|
count: products.length
|
|
1730
1885
|
});
|
|
1731
|
-
|
|
1886
|
+
_this9.logInfo('replaceProductsSnapshotInIndexDB 完成', {
|
|
1732
1887
|
source: source,
|
|
1733
1888
|
productCount: products.length
|
|
1734
1889
|
});
|
|
1735
1890
|
case 9:
|
|
1736
1891
|
case "end":
|
|
1737
|
-
return
|
|
1892
|
+
return _context20.stop();
|
|
1738
1893
|
}
|
|
1739
|
-
},
|
|
1894
|
+
}, _callee20);
|
|
1740
1895
|
})));
|
|
1741
1896
|
case 6:
|
|
1742
|
-
|
|
1897
|
+
_context21.next = 12;
|
|
1743
1898
|
break;
|
|
1744
1899
|
case 8:
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
errorMessage =
|
|
1900
|
+
_context21.prev = 8;
|
|
1901
|
+
_context21.t0 = _context21["catch"](3);
|
|
1902
|
+
errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
|
|
1748
1903
|
this.logError('全量保存商品到 IndexDB 失败', {
|
|
1749
1904
|
source: source,
|
|
1750
1905
|
productCount: products.length,
|
|
@@ -1752,11 +1907,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1752
1907
|
});
|
|
1753
1908
|
case 12:
|
|
1754
1909
|
case "end":
|
|
1755
|
-
return
|
|
1910
|
+
return _context21.stop();
|
|
1756
1911
|
}
|
|
1757
|
-
},
|
|
1912
|
+
}, _callee21, this, [[3, 8]]);
|
|
1758
1913
|
}));
|
|
1759
|
-
function replaceProductsSnapshotInIndexDB(
|
|
1914
|
+
function replaceProductsSnapshotInIndexDB(_x21, _x22) {
|
|
1760
1915
|
return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
|
|
1761
1916
|
}
|
|
1762
1917
|
return replaceProductsSnapshotInIndexDB;
|
|
@@ -1771,103 +1926,103 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1771
1926
|
}, {
|
|
1772
1927
|
key: "patchProductsInIndexDB",
|
|
1773
1928
|
value: (function () {
|
|
1774
|
-
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1775
|
-
var
|
|
1929
|
+
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(products, source) {
|
|
1930
|
+
var _this10 = this;
|
|
1776
1931
|
var mergeActions,
|
|
1777
1932
|
validProducts,
|
|
1778
1933
|
errorMessage,
|
|
1779
|
-
|
|
1780
|
-
return _regeneratorRuntime().wrap(function
|
|
1781
|
-
while (1) switch (
|
|
1934
|
+
_args23 = arguments;
|
|
1935
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1936
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1782
1937
|
case 0:
|
|
1783
|
-
mergeActions =
|
|
1938
|
+
mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
|
|
1784
1939
|
if (!(!this.dbManager || products.length === 0)) {
|
|
1785
|
-
|
|
1940
|
+
_context23.next = 3;
|
|
1786
1941
|
break;
|
|
1787
1942
|
}
|
|
1788
|
-
return
|
|
1943
|
+
return _context23.abrupt("return");
|
|
1789
1944
|
case 3:
|
|
1790
1945
|
validProducts = products.filter(function (p) {
|
|
1791
1946
|
return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
|
|
1792
1947
|
});
|
|
1793
1948
|
if (!(validProducts.length === 0)) {
|
|
1794
|
-
|
|
1949
|
+
_context23.next = 6;
|
|
1795
1950
|
break;
|
|
1796
1951
|
}
|
|
1797
|
-
return
|
|
1952
|
+
return _context23.abrupt("return");
|
|
1798
1953
|
case 6:
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1802
|
-
var t0,
|
|
1803
|
-
return _regeneratorRuntime().wrap(function
|
|
1804
|
-
while (1) switch (
|
|
1954
|
+
_context23.prev = 6;
|
|
1955
|
+
_context23.next = 9;
|
|
1956
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
1957
|
+
var t0, _iterator11, _step11, product;
|
|
1958
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1959
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1805
1960
|
case 0:
|
|
1806
|
-
|
|
1961
|
+
_this10.logInfo('patchProductsInIndexDB 开始', {
|
|
1807
1962
|
source: source,
|
|
1808
1963
|
count: validProducts.length
|
|
1809
1964
|
});
|
|
1810
1965
|
t0 = performance.now();
|
|
1811
|
-
if (!(typeof
|
|
1812
|
-
|
|
1966
|
+
if (!(typeof _this10.dbManager.bulkUpdate === 'function')) {
|
|
1967
|
+
_context22.next = 7;
|
|
1813
1968
|
break;
|
|
1814
1969
|
}
|
|
1815
|
-
|
|
1816
|
-
return
|
|
1970
|
+
_context22.next = 5;
|
|
1971
|
+
return _this10.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
|
|
1817
1972
|
case 5:
|
|
1818
|
-
|
|
1973
|
+
_context22.next = 25;
|
|
1819
1974
|
break;
|
|
1820
1975
|
case 7:
|
|
1821
|
-
if (!(typeof
|
|
1822
|
-
|
|
1976
|
+
if (!(typeof _this10.dbManager.update === 'function')) {
|
|
1977
|
+
_context22.next = 25;
|
|
1823
1978
|
break;
|
|
1824
1979
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1980
|
+
_iterator11 = _createForOfIteratorHelper(validProducts);
|
|
1981
|
+
_context22.prev = 9;
|
|
1982
|
+
_iterator11.s();
|
|
1828
1983
|
case 11:
|
|
1829
|
-
if ((
|
|
1830
|
-
|
|
1984
|
+
if ((_step11 = _iterator11.n()).done) {
|
|
1985
|
+
_context22.next = 17;
|
|
1831
1986
|
break;
|
|
1832
1987
|
}
|
|
1833
|
-
product =
|
|
1834
|
-
|
|
1835
|
-
return
|
|
1988
|
+
product = _step11.value;
|
|
1989
|
+
_context22.next = 15;
|
|
1990
|
+
return _this10.dbManager.update(INDEXDB_STORE_NAME, product);
|
|
1836
1991
|
case 15:
|
|
1837
|
-
|
|
1992
|
+
_context22.next = 11;
|
|
1838
1993
|
break;
|
|
1839
1994
|
case 17:
|
|
1840
|
-
|
|
1995
|
+
_context22.next = 22;
|
|
1841
1996
|
break;
|
|
1842
1997
|
case 19:
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1998
|
+
_context22.prev = 19;
|
|
1999
|
+
_context22.t0 = _context22["catch"](9);
|
|
2000
|
+
_iterator11.e(_context22.t0);
|
|
1846
2001
|
case 22:
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
return
|
|
2002
|
+
_context22.prev = 22;
|
|
2003
|
+
_iterator11.f();
|
|
2004
|
+
return _context22.finish(22);
|
|
1850
2005
|
case 25:
|
|
1851
2006
|
perfMark('patchProductsInIndexDB', performance.now() - t0, {
|
|
1852
2007
|
count: validProducts.length
|
|
1853
2008
|
});
|
|
1854
|
-
|
|
2009
|
+
_this10.logInfo('patchProductsInIndexDB 完成', {
|
|
1855
2010
|
source: source,
|
|
1856
2011
|
count: validProducts.length
|
|
1857
2012
|
});
|
|
1858
2013
|
case 27:
|
|
1859
2014
|
case "end":
|
|
1860
|
-
return
|
|
2015
|
+
return _context22.stop();
|
|
1861
2016
|
}
|
|
1862
|
-
},
|
|
2017
|
+
}, _callee22, null, [[9, 19, 22, 25]]);
|
|
1863
2018
|
})));
|
|
1864
2019
|
case 9:
|
|
1865
|
-
|
|
2020
|
+
_context23.next = 15;
|
|
1866
2021
|
break;
|
|
1867
2022
|
case 11:
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
errorMessage =
|
|
2023
|
+
_context23.prev = 11;
|
|
2024
|
+
_context23.t0 = _context23["catch"](6);
|
|
2025
|
+
errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
|
|
1871
2026
|
this.logError('增量保存商品到 IndexDB 失败', {
|
|
1872
2027
|
source: source,
|
|
1873
2028
|
error: errorMessage,
|
|
@@ -1875,11 +2030,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1875
2030
|
});
|
|
1876
2031
|
case 15:
|
|
1877
2032
|
case "end":
|
|
1878
|
-
return
|
|
2033
|
+
return _context23.stop();
|
|
1879
2034
|
}
|
|
1880
|
-
},
|
|
2035
|
+
}, _callee23, this, [[6, 11]]);
|
|
1881
2036
|
}));
|
|
1882
|
-
function patchProductsInIndexDB(
|
|
2037
|
+
function patchProductsInIndexDB(_x23, _x24) {
|
|
1883
2038
|
return _patchProductsInIndexDB.apply(this, arguments);
|
|
1884
2039
|
}
|
|
1885
2040
|
return patchProductsInIndexDB;
|
|
@@ -1895,17 +2050,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1895
2050
|
value: function syncProductsMap() {
|
|
1896
2051
|
var t0 = performance.now();
|
|
1897
2052
|
this.store.map.clear();
|
|
1898
|
-
var
|
|
1899
|
-
|
|
2053
|
+
var _iterator12 = _createForOfIteratorHelper(this.store.list),
|
|
2054
|
+
_step12;
|
|
1900
2055
|
try {
|
|
1901
|
-
for (
|
|
1902
|
-
var product =
|
|
2056
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
2057
|
+
var product = _step12.value;
|
|
1903
2058
|
this.store.map.set(product.id, product);
|
|
1904
2059
|
}
|
|
1905
2060
|
} catch (err) {
|
|
1906
|
-
|
|
2061
|
+
_iterator12.e(err);
|
|
1907
2062
|
} finally {
|
|
1908
|
-
|
|
2063
|
+
_iterator12.f();
|
|
1909
2064
|
}
|
|
1910
2065
|
perfMark('syncProductsMap', performance.now() - t0, {
|
|
1911
2066
|
count: this.store.map.size
|
|
@@ -1919,26 +2074,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1919
2074
|
}, {
|
|
1920
2075
|
key: "preload",
|
|
1921
2076
|
value: (function () {
|
|
1922
|
-
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2077
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
1923
2078
|
var _products$length3;
|
|
1924
2079
|
var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
|
|
1925
|
-
return _regeneratorRuntime().wrap(function
|
|
1926
|
-
while (1) switch (
|
|
2080
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2081
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1927
2082
|
case 0:
|
|
1928
2083
|
console.log('[Products] 开始预加载数据...');
|
|
1929
2084
|
tTotal = performance.now();
|
|
1930
2085
|
this.logInfo('开始预加载数据');
|
|
1931
|
-
|
|
2086
|
+
_context24.prev = 3;
|
|
1932
2087
|
tIndexDB = performance.now();
|
|
1933
|
-
|
|
2088
|
+
_context24.next = 7;
|
|
1934
2089
|
return this.loadProductsFromIndexDB();
|
|
1935
2090
|
case 7:
|
|
1936
|
-
cachedData =
|
|
2091
|
+
cachedData = _context24.sent;
|
|
1937
2092
|
perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
|
|
1938
2093
|
count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
|
|
1939
2094
|
});
|
|
1940
2095
|
if (!(cachedData && cachedData.length > 0)) {
|
|
1941
|
-
|
|
2096
|
+
_context24.next = 20;
|
|
1942
2097
|
break;
|
|
1943
2098
|
}
|
|
1944
2099
|
console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
|
|
@@ -1960,26 +2115,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1960
2115
|
source: 'IndexDB'
|
|
1961
2116
|
});
|
|
1962
2117
|
this.lastPreloadCompletedAtMs = Date.now();
|
|
1963
|
-
return
|
|
2118
|
+
return _context24.abrupt("return");
|
|
1964
2119
|
case 20:
|
|
1965
2120
|
console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
|
|
1966
2121
|
this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
|
|
1967
|
-
|
|
2122
|
+
_context24.next = 29;
|
|
1968
2123
|
break;
|
|
1969
2124
|
case 24:
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
errorMessage =
|
|
1973
|
-
console.warn('[Products] 从 IndexDB 加载数据失败:',
|
|
2125
|
+
_context24.prev = 24;
|
|
2126
|
+
_context24.t0 = _context24["catch"](3);
|
|
2127
|
+
errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
|
|
2128
|
+
console.warn('[Products] 从 IndexDB 加载数据失败:', _context24.t0);
|
|
1974
2129
|
this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
|
|
1975
2130
|
error: errorMessage
|
|
1976
2131
|
});
|
|
1977
2132
|
case 29:
|
|
1978
2133
|
tServer = performance.now();
|
|
1979
|
-
|
|
2134
|
+
_context24.next = 32;
|
|
1980
2135
|
return this.loadProductsByServer();
|
|
1981
2136
|
case 32:
|
|
1982
|
-
products =
|
|
2137
|
+
products = _context24.sent;
|
|
1983
2138
|
perfMark('preload.loadFromServer', performance.now() - tServer, {
|
|
1984
2139
|
count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
|
|
1985
2140
|
});
|
|
@@ -2012,9 +2167,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2012
2167
|
}
|
|
2013
2168
|
case 35:
|
|
2014
2169
|
case "end":
|
|
2015
|
-
return
|
|
2170
|
+
return _context24.stop();
|
|
2016
2171
|
}
|
|
2017
|
-
},
|
|
2172
|
+
}, _callee24, this, [[3, 24]]);
|
|
2018
2173
|
}));
|
|
2019
2174
|
function preload() {
|
|
2020
2175
|
return _preload.apply(this, arguments);
|
|
@@ -2049,7 +2204,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2049
2204
|
}, {
|
|
2050
2205
|
key: "setupProductSync",
|
|
2051
2206
|
value: function setupProductSync() {
|
|
2052
|
-
var
|
|
2207
|
+
var _this11 = this;
|
|
2053
2208
|
if (!this.productDataSource) {
|
|
2054
2209
|
this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
|
|
2055
2210
|
return;
|
|
@@ -2059,20 +2214,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2059
2214
|
var data = (message === null || message === void 0 ? void 0 : message.data) || message;
|
|
2060
2215
|
if (!data) return;
|
|
2061
2216
|
console.log("[ProductsModule] \u6536\u5230\u540C\u6B65\u6D88\u606F [".concat(channelKey, "]:"), data);
|
|
2062
|
-
|
|
2217
|
+
_this11.logInfo('收到同步消息', {
|
|
2063
2218
|
channelKey: channelKey,
|
|
2064
2219
|
action: data.action,
|
|
2065
2220
|
id: data.id,
|
|
2066
2221
|
action_filed: data.action_filed
|
|
2067
2222
|
});
|
|
2068
|
-
|
|
2223
|
+
_this11.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
2069
2224
|
_channelKey: channelKey
|
|
2070
2225
|
}));
|
|
2071
|
-
if (
|
|
2072
|
-
clearTimeout(
|
|
2226
|
+
if (_this11.syncTimer) {
|
|
2227
|
+
clearTimeout(_this11.syncTimer);
|
|
2073
2228
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2229
|
+
_this11.syncTimer = setTimeout(function () {
|
|
2230
|
+
_this11.processProductSyncMessages();
|
|
2076
2231
|
}, PRODUCT_SYNC_DEBOUNCE_MS);
|
|
2077
2232
|
};
|
|
2078
2233
|
};
|
|
@@ -2090,7 +2245,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2090
2245
|
}
|
|
2091
2246
|
}
|
|
2092
2247
|
}).catch(function (err) {
|
|
2093
|
-
|
|
2248
|
+
_this11.logError('setupProductSync: DataSource run 出错', {
|
|
2094
2249
|
error: err instanceof Error ? err.message : String(err)
|
|
2095
2250
|
});
|
|
2096
2251
|
});
|
|
@@ -2118,18 +2273,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2118
2273
|
}, {
|
|
2119
2274
|
key: "processProductSyncMessages",
|
|
2120
2275
|
value: (function () {
|
|
2121
|
-
var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2122
|
-
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache,
|
|
2123
|
-
return _regeneratorRuntime().wrap(function
|
|
2124
|
-
while (1) switch (
|
|
2276
|
+
var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
2277
|
+
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator13, _step13, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator14, _step14, product, freshProducts, mergeResult, _iterator15, _step15, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
|
|
2278
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2279
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2125
2280
|
case 0:
|
|
2126
2281
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
2127
2282
|
this.pendingSyncMessages = [];
|
|
2128
2283
|
if (!(messages.length === 0)) {
|
|
2129
|
-
|
|
2284
|
+
_context25.next = 4;
|
|
2130
2285
|
break;
|
|
2131
2286
|
}
|
|
2132
|
-
return
|
|
2287
|
+
return _context25.abrupt("return");
|
|
2133
2288
|
case 4:
|
|
2134
2289
|
this.logInfo('processProductSyncMessages: 开始处理', {
|
|
2135
2290
|
count: messages.length
|
|
@@ -2139,18 +2294,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2139
2294
|
sseRefreshIds = [];
|
|
2140
2295
|
priceRefreshIds = [];
|
|
2141
2296
|
shouldClearPriceCache = false;
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2297
|
+
_iterator13 = _createForOfIteratorHelper(messages);
|
|
2298
|
+
_context25.prev = 11;
|
|
2299
|
+
_iterator13.s();
|
|
2145
2300
|
case 13:
|
|
2146
|
-
if ((
|
|
2147
|
-
|
|
2301
|
+
if ((_step13 = _iterator13.n()).done) {
|
|
2302
|
+
_context25.next = 36;
|
|
2148
2303
|
break;
|
|
2149
2304
|
}
|
|
2150
|
-
msg =
|
|
2305
|
+
msg = _step13.value;
|
|
2151
2306
|
channelKey = msg._channelKey || msg.module || 'product';
|
|
2152
2307
|
if (!(channelKey === 'product')) {
|
|
2153
|
-
|
|
2308
|
+
_context25.next = 33;
|
|
2154
2309
|
break;
|
|
2155
2310
|
}
|
|
2156
2311
|
if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
|
|
@@ -2158,14 +2313,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2158
2313
|
}
|
|
2159
2314
|
// 1. 删除场景:operation === 'delete' 或 action === 'delete'
|
|
2160
2315
|
if (!(msg.operation === 'delete' || msg.action === 'delete')) {
|
|
2161
|
-
|
|
2316
|
+
_context25.next = 21;
|
|
2162
2317
|
break;
|
|
2163
2318
|
}
|
|
2164
2319
|
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);
|
|
2165
|
-
return
|
|
2320
|
+
return _context25.abrupt("continue", 34);
|
|
2166
2321
|
case 21:
|
|
2167
2322
|
if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
|
|
2168
|
-
|
|
2323
|
+
_context25.next = 26;
|
|
2169
2324
|
break;
|
|
2170
2325
|
}
|
|
2171
2326
|
ids = msg.ids || (msg.id ? [msg.id] : []);
|
|
@@ -2174,15 +2329,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2174
2329
|
bodyId = msg.body.id;
|
|
2175
2330
|
if (bodyId) bodyUpdates.set(bodyId, msg.body);
|
|
2176
2331
|
}
|
|
2177
|
-
return
|
|
2332
|
+
return _context25.abrupt("continue", 34);
|
|
2178
2333
|
case 26:
|
|
2179
2334
|
if (!msg.body) {
|
|
2180
|
-
|
|
2335
|
+
_context25.next = 30;
|
|
2181
2336
|
break;
|
|
2182
2337
|
}
|
|
2183
2338
|
_bodyId = msg.body.id || msg.id;
|
|
2184
2339
|
if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
|
|
2185
|
-
return
|
|
2340
|
+
return _context25.abrupt("continue", 34);
|
|
2186
2341
|
case 30:
|
|
2187
2342
|
// 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
|
|
2188
2343
|
if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
|
|
@@ -2190,7 +2345,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2190
2345
|
} else if (msg.id) {
|
|
2191
2346
|
sseRefreshIds.push(msg.id);
|
|
2192
2347
|
}
|
|
2193
|
-
|
|
2348
|
+
_context25.next = 34;
|
|
2194
2349
|
break;
|
|
2195
2350
|
case 33:
|
|
2196
2351
|
if (channelKey === 'product_quotation') {
|
|
@@ -2203,30 +2358,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2203
2358
|
if ((_msg$relation_product3 = msg.relation_product_ids) !== null && _msg$relation_product3 !== void 0 && _msg$relation_product3.length) {
|
|
2204
2359
|
sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
|
|
2205
2360
|
}
|
|
2361
|
+
} else if (['product_data_variant'].includes(channelKey)) {
|
|
2362
|
+
if ((_msg$product_ids = msg.product_ids) !== null && _msg$product_ids !== void 0 && _msg$product_ids.length) {
|
|
2363
|
+
sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.product_ids));
|
|
2364
|
+
}
|
|
2206
2365
|
}
|
|
2207
2366
|
case 34:
|
|
2208
|
-
|
|
2367
|
+
_context25.next = 13;
|
|
2209
2368
|
break;
|
|
2210
2369
|
case 36:
|
|
2211
|
-
|
|
2370
|
+
_context25.next = 41;
|
|
2212
2371
|
break;
|
|
2213
2372
|
case 38:
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2373
|
+
_context25.prev = 38;
|
|
2374
|
+
_context25.t0 = _context25["catch"](11);
|
|
2375
|
+
_iterator13.e(_context25.t0);
|
|
2217
2376
|
case 41:
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
return
|
|
2377
|
+
_context25.prev = 41;
|
|
2378
|
+
_iterator13.f();
|
|
2379
|
+
return _context25.finish(41);
|
|
2221
2380
|
case 44:
|
|
2222
2381
|
uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
|
|
2223
2382
|
uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
|
|
2224
2383
|
uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
|
|
2225
2384
|
if (!(uniqueDeleteIds.length > 0)) {
|
|
2226
|
-
|
|
2385
|
+
_context25.next = 50;
|
|
2227
2386
|
break;
|
|
2228
2387
|
}
|
|
2229
|
-
|
|
2388
|
+
_context25.next = 50;
|
|
2230
2389
|
return this.removeProductsByIds(uniqueDeleteIds);
|
|
2231
2390
|
case 50:
|
|
2232
2391
|
/** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
|
|
@@ -2234,62 +2393,62 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2234
2393
|
patchMergeActions = {};
|
|
2235
2394
|
storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
|
|
2236
2395
|
if (!(bodyUpdates.size > 0)) {
|
|
2237
|
-
|
|
2396
|
+
_context25.next = 60;
|
|
2238
2397
|
break;
|
|
2239
2398
|
}
|
|
2240
|
-
|
|
2399
|
+
_context25.next = 56;
|
|
2241
2400
|
return this.applyBodyUpdatesToStore(bodyUpdates, {
|
|
2242
2401
|
skipIndexDB: true,
|
|
2243
2402
|
skipEmit: true
|
|
2244
2403
|
});
|
|
2245
2404
|
case 56:
|
|
2246
|
-
bodyResult =
|
|
2247
|
-
|
|
2405
|
+
bodyResult = _context25.sent;
|
|
2406
|
+
_iterator14 = _createForOfIteratorHelper(bodyResult.changedProducts);
|
|
2248
2407
|
try {
|
|
2249
|
-
for (
|
|
2250
|
-
product =
|
|
2408
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
2409
|
+
product = _step14.value;
|
|
2251
2410
|
patchProductMap.set(product.id, product);
|
|
2252
2411
|
patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
|
|
2253
2412
|
}
|
|
2254
2413
|
} catch (err) {
|
|
2255
|
-
|
|
2414
|
+
_iterator14.e(err);
|
|
2256
2415
|
} finally {
|
|
2257
|
-
|
|
2416
|
+
_iterator14.f();
|
|
2258
2417
|
}
|
|
2259
2418
|
storeMutated = true;
|
|
2260
2419
|
case 60:
|
|
2261
2420
|
// 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
|
|
2262
2421
|
freshProducts = [];
|
|
2263
2422
|
if (!(uniqueSSEIds.length > 0)) {
|
|
2264
|
-
|
|
2423
|
+
_context25.next = 73;
|
|
2265
2424
|
break;
|
|
2266
2425
|
}
|
|
2267
|
-
|
|
2426
|
+
_context25.next = 64;
|
|
2268
2427
|
return this.fetchProductsBySSE(uniqueSSEIds);
|
|
2269
2428
|
case 64:
|
|
2270
|
-
freshProducts =
|
|
2429
|
+
freshProducts = _context25.sent;
|
|
2271
2430
|
if (!(freshProducts.length > 0)) {
|
|
2272
|
-
|
|
2431
|
+
_context25.next = 72;
|
|
2273
2432
|
break;
|
|
2274
2433
|
}
|
|
2275
|
-
|
|
2434
|
+
_context25.next = 68;
|
|
2276
2435
|
return this.mergeProductsToStore(freshProducts, {
|
|
2277
2436
|
skipIndexDB: true,
|
|
2278
2437
|
skipEmit: true
|
|
2279
2438
|
});
|
|
2280
2439
|
case 68:
|
|
2281
|
-
mergeResult =
|
|
2282
|
-
|
|
2440
|
+
mergeResult = _context25.sent;
|
|
2441
|
+
_iterator15 = _createForOfIteratorHelper(mergeResult.changedProducts);
|
|
2283
2442
|
try {
|
|
2284
|
-
for (
|
|
2285
|
-
_product =
|
|
2443
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
2444
|
+
_product = _step15.value;
|
|
2286
2445
|
patchProductMap.set(_product.id, _product);
|
|
2287
2446
|
patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
|
|
2288
2447
|
}
|
|
2289
2448
|
} catch (err) {
|
|
2290
|
-
|
|
2449
|
+
_iterator15.e(err);
|
|
2291
2450
|
} finally {
|
|
2292
|
-
|
|
2451
|
+
_iterator15.f();
|
|
2293
2452
|
}
|
|
2294
2453
|
storeMutated = true;
|
|
2295
2454
|
case 72:
|
|
@@ -2300,10 +2459,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2300
2459
|
case 73:
|
|
2301
2460
|
patchProducts = _toConsumableArray(patchProductMap.values());
|
|
2302
2461
|
if (!(patchProducts.length > 0)) {
|
|
2303
|
-
|
|
2462
|
+
_context25.next = 77;
|
|
2304
2463
|
break;
|
|
2305
2464
|
}
|
|
2306
|
-
|
|
2465
|
+
_context25.next = 77;
|
|
2307
2466
|
return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
|
|
2308
2467
|
case 77:
|
|
2309
2468
|
if (storeMutated) {
|
|
@@ -2322,41 +2481,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2322
2481
|
});
|
|
2323
2482
|
hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
|
|
2324
2483
|
if (hasChanges) {
|
|
2325
|
-
|
|
2484
|
+
_context25.next = 84;
|
|
2326
2485
|
break;
|
|
2327
2486
|
}
|
|
2328
2487
|
this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
|
|
2329
|
-
return
|
|
2488
|
+
return _context25.abrupt("return");
|
|
2330
2489
|
case 84:
|
|
2331
2490
|
if (!shouldClearPriceCache) {
|
|
2332
|
-
|
|
2491
|
+
_context25.next = 95;
|
|
2333
2492
|
break;
|
|
2334
2493
|
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2494
|
+
_context25.prev = 85;
|
|
2495
|
+
_context25.next = 88;
|
|
2337
2496
|
return this.refreshQuotationPriceBridge();
|
|
2338
2497
|
case 88:
|
|
2339
|
-
|
|
2498
|
+
_context25.next = 94;
|
|
2340
2499
|
break;
|
|
2341
2500
|
case 90:
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
errorMessage =
|
|
2501
|
+
_context25.prev = 90;
|
|
2502
|
+
_context25.t1 = _context25["catch"](85);
|
|
2503
|
+
errorMessage = _context25.t1 instanceof Error ? _context25.t1.message : String(_context25.t1);
|
|
2345
2504
|
this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
|
|
2346
2505
|
error: errorMessage
|
|
2347
2506
|
});
|
|
2348
2507
|
case 94:
|
|
2349
2508
|
this.clearPriceCache();
|
|
2350
2509
|
case 95:
|
|
2351
|
-
|
|
2510
|
+
_context25.next = 97;
|
|
2352
2511
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
|
|
2353
2512
|
changedIds: allChangedIds
|
|
2354
2513
|
});
|
|
2355
2514
|
case 97:
|
|
2356
2515
|
case "end":
|
|
2357
|
-
return
|
|
2516
|
+
return _context25.stop();
|
|
2358
2517
|
}
|
|
2359
|
-
},
|
|
2518
|
+
}, _callee25, this, [[11, 38, 41, 44], [85, 90]]);
|
|
2360
2519
|
}));
|
|
2361
2520
|
function processProductSyncMessages() {
|
|
2362
2521
|
return _processProductSyncMessages.apply(this, arguments);
|
|
@@ -2371,25 +2530,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2371
2530
|
}, {
|
|
2372
2531
|
key: "fetchProductsBySSE",
|
|
2373
2532
|
value: (function () {
|
|
2374
|
-
var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2533
|
+
var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(ids) {
|
|
2375
2534
|
var t0, productList, list, errorMessage;
|
|
2376
|
-
return _regeneratorRuntime().wrap(function
|
|
2377
|
-
while (1) switch (
|
|
2535
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2536
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2378
2537
|
case 0:
|
|
2379
2538
|
if (this.productDataSource) {
|
|
2380
|
-
|
|
2539
|
+
_context26.next = 3;
|
|
2381
2540
|
break;
|
|
2382
2541
|
}
|
|
2383
2542
|
this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
|
|
2384
|
-
return
|
|
2543
|
+
return _context26.abrupt("return", []);
|
|
2385
2544
|
case 3:
|
|
2386
2545
|
this.logInfo('fetchProductsBySSE: 开始', {
|
|
2387
2546
|
ids: ids,
|
|
2388
2547
|
count: ids.length
|
|
2389
2548
|
});
|
|
2390
2549
|
t0 = performance.now();
|
|
2391
|
-
|
|
2392
|
-
|
|
2550
|
+
_context26.prev = 5;
|
|
2551
|
+
_context26.next = 8;
|
|
2393
2552
|
return this.productDataSource.run({
|
|
2394
2553
|
sse: {
|
|
2395
2554
|
query: {
|
|
@@ -2399,7 +2558,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2399
2558
|
}
|
|
2400
2559
|
});
|
|
2401
2560
|
case 8:
|
|
2402
|
-
productList =
|
|
2561
|
+
productList = _context26.sent;
|
|
2403
2562
|
list = productList || [];
|
|
2404
2563
|
perfMark('fetchProductsBySSE', performance.now() - t0, {
|
|
2405
2564
|
count: list.length
|
|
@@ -2409,23 +2568,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2409
2568
|
receivedCount: list.length,
|
|
2410
2569
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2411
2570
|
});
|
|
2412
|
-
return
|
|
2571
|
+
return _context26.abrupt("return", list);
|
|
2413
2572
|
case 15:
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
errorMessage =
|
|
2573
|
+
_context26.prev = 15;
|
|
2574
|
+
_context26.t0 = _context26["catch"](5);
|
|
2575
|
+
errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
|
|
2417
2576
|
this.logError('fetchProductsBySSE: 失败', {
|
|
2418
2577
|
ids: ids,
|
|
2419
2578
|
error: errorMessage
|
|
2420
2579
|
});
|
|
2421
|
-
return
|
|
2580
|
+
return _context26.abrupt("return", []);
|
|
2422
2581
|
case 20:
|
|
2423
2582
|
case "end":
|
|
2424
|
-
return
|
|
2583
|
+
return _context26.stop();
|
|
2425
2584
|
}
|
|
2426
|
-
},
|
|
2585
|
+
}, _callee26, this, [[5, 15]]);
|
|
2427
2586
|
}));
|
|
2428
|
-
function fetchProductsBySSE(
|
|
2587
|
+
function fetchProductsBySSE(_x25) {
|
|
2429
2588
|
return _fetchProductsBySSE.apply(this, arguments);
|
|
2430
2589
|
}
|
|
2431
2590
|
return fetchProductsBySSE;
|
|
@@ -2441,10 +2600,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2441
2600
|
}, {
|
|
2442
2601
|
key: "applyBodyUpdatesToStore",
|
|
2443
2602
|
value: (function () {
|
|
2444
|
-
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2445
|
-
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts,
|
|
2446
|
-
return _regeneratorRuntime().wrap(function
|
|
2447
|
-
while (1) switch (
|
|
2603
|
+
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(bodyUpdates, options) {
|
|
2604
|
+
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator16, _step16, _step16$value, id, body;
|
|
2605
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
2606
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2448
2607
|
case 0:
|
|
2449
2608
|
changedProductIds = _toConsumableArray(bodyUpdates.keys());
|
|
2450
2609
|
this.logInfo('applyBodyUpdatesToStore: 开始', {
|
|
@@ -2466,10 +2625,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2466
2625
|
}
|
|
2467
2626
|
return p;
|
|
2468
2627
|
});
|
|
2469
|
-
|
|
2628
|
+
_iterator16 = _createForOfIteratorHelper(bodyUpdates);
|
|
2470
2629
|
try {
|
|
2471
|
-
for (
|
|
2472
|
-
|
|
2630
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
2631
|
+
_step16$value = _slicedToArray(_step16.value, 2), id = _step16$value[0], body = _step16$value[1];
|
|
2473
2632
|
if (!appliedIds.has(id)) {
|
|
2474
2633
|
this.store.list.push(body);
|
|
2475
2634
|
newCount++;
|
|
@@ -2478,16 +2637,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2478
2637
|
}
|
|
2479
2638
|
}
|
|
2480
2639
|
} catch (err) {
|
|
2481
|
-
|
|
2640
|
+
_iterator16.e(err);
|
|
2482
2641
|
} finally {
|
|
2483
|
-
|
|
2642
|
+
_iterator16.f();
|
|
2484
2643
|
}
|
|
2485
2644
|
this.syncProductsMap();
|
|
2486
2645
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2487
|
-
|
|
2646
|
+
_context27.next = 14;
|
|
2488
2647
|
break;
|
|
2489
2648
|
}
|
|
2490
|
-
|
|
2649
|
+
_context27.next = 14;
|
|
2491
2650
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
|
|
2492
2651
|
case 14:
|
|
2493
2652
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
@@ -2498,7 +2657,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2498
2657
|
newCount: newCount,
|
|
2499
2658
|
totalCount: this.store.list.length
|
|
2500
2659
|
});
|
|
2501
|
-
return
|
|
2660
|
+
return _context27.abrupt("return", {
|
|
2502
2661
|
changedProducts: changedProducts,
|
|
2503
2662
|
mergeActions: mergeActions,
|
|
2504
2663
|
updatedCount: updatedCount,
|
|
@@ -2506,11 +2665,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2506
2665
|
});
|
|
2507
2666
|
case 17:
|
|
2508
2667
|
case "end":
|
|
2509
|
-
return
|
|
2668
|
+
return _context27.stop();
|
|
2510
2669
|
}
|
|
2511
|
-
},
|
|
2670
|
+
}, _callee27, this);
|
|
2512
2671
|
}));
|
|
2513
|
-
function applyBodyUpdatesToStore(
|
|
2672
|
+
function applyBodyUpdatesToStore(_x26, _x27) {
|
|
2514
2673
|
return _applyBodyUpdatesToStore.apply(this, arguments);
|
|
2515
2674
|
}
|
|
2516
2675
|
return applyBodyUpdatesToStore;
|
|
@@ -2526,22 +2685,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2526
2685
|
}, {
|
|
2527
2686
|
key: "mergeProductsToStore",
|
|
2528
2687
|
value: (function () {
|
|
2529
|
-
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2530
|
-
var freshMap,
|
|
2531
|
-
return _regeneratorRuntime().wrap(function
|
|
2532
|
-
while (1) switch (
|
|
2688
|
+
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(freshProducts, options) {
|
|
2689
|
+
var freshMap, _iterator17, _step17, p, mergeActions, changedProducts, updatedList, newCount, _iterator18, _step18, _p2, updatedCount, changedProductIds;
|
|
2690
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
2691
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2533
2692
|
case 0:
|
|
2534
2693
|
freshMap = new Map();
|
|
2535
|
-
|
|
2694
|
+
_iterator17 = _createForOfIteratorHelper(freshProducts);
|
|
2536
2695
|
try {
|
|
2537
|
-
for (
|
|
2538
|
-
p =
|
|
2696
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2697
|
+
p = _step17.value;
|
|
2539
2698
|
freshMap.set(p.id, p);
|
|
2540
2699
|
}
|
|
2541
2700
|
} catch (err) {
|
|
2542
|
-
|
|
2701
|
+
_iterator17.e(err);
|
|
2543
2702
|
} finally {
|
|
2544
|
-
|
|
2703
|
+
_iterator17.f();
|
|
2545
2704
|
}
|
|
2546
2705
|
mergeActions = {};
|
|
2547
2706
|
changedProducts = [];
|
|
@@ -2556,18 +2715,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2556
2715
|
return p;
|
|
2557
2716
|
}); // freshMap 中剩余的是新商品(create 场景)
|
|
2558
2717
|
newCount = freshMap.size;
|
|
2559
|
-
|
|
2718
|
+
_iterator18 = _createForOfIteratorHelper(freshMap.values());
|
|
2560
2719
|
try {
|
|
2561
|
-
for (
|
|
2562
|
-
_p2 =
|
|
2720
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2721
|
+
_p2 = _step18.value;
|
|
2563
2722
|
updatedList.push(_p2);
|
|
2564
2723
|
mergeActions[_p2.id] = 'insert';
|
|
2565
2724
|
changedProducts.push(_p2);
|
|
2566
2725
|
}
|
|
2567
2726
|
} catch (err) {
|
|
2568
|
-
|
|
2727
|
+
_iterator18.e(err);
|
|
2569
2728
|
} finally {
|
|
2570
|
-
|
|
2729
|
+
_iterator18.f();
|
|
2571
2730
|
}
|
|
2572
2731
|
updatedCount = freshProducts.length - newCount;
|
|
2573
2732
|
changedProductIds = freshProducts.map(function (p) {
|
|
@@ -2576,10 +2735,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2576
2735
|
this.store.list = updatedList;
|
|
2577
2736
|
this.syncProductsMap();
|
|
2578
2737
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2579
|
-
|
|
2738
|
+
_context28.next = 16;
|
|
2580
2739
|
break;
|
|
2581
2740
|
}
|
|
2582
|
-
|
|
2741
|
+
_context28.next = 16;
|
|
2583
2742
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
|
|
2584
2743
|
case 16:
|
|
2585
2744
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
@@ -2590,7 +2749,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2590
2749
|
newCount: newCount,
|
|
2591
2750
|
totalCount: this.store.list.length
|
|
2592
2751
|
});
|
|
2593
|
-
return
|
|
2752
|
+
return _context28.abrupt("return", {
|
|
2594
2753
|
changedProducts: changedProducts,
|
|
2595
2754
|
mergeActions: mergeActions,
|
|
2596
2755
|
updatedCount: updatedCount,
|
|
@@ -2598,11 +2757,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2598
2757
|
});
|
|
2599
2758
|
case 19:
|
|
2600
2759
|
case "end":
|
|
2601
|
-
return
|
|
2760
|
+
return _context28.stop();
|
|
2602
2761
|
}
|
|
2603
|
-
},
|
|
2762
|
+
}, _callee28, this);
|
|
2604
2763
|
}));
|
|
2605
|
-
function mergeProductsToStore(
|
|
2764
|
+
function mergeProductsToStore(_x28, _x29) {
|
|
2606
2765
|
return _mergeProductsToStore.apply(this, arguments);
|
|
2607
2766
|
}
|
|
2608
2767
|
return mergeProductsToStore;
|
|
@@ -2616,43 +2775,43 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2616
2775
|
}, {
|
|
2617
2776
|
key: "silentRefresh",
|
|
2618
2777
|
value: (function () {
|
|
2619
|
-
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2778
|
+
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
2620
2779
|
var t0, now, elapsedSincePreload, elapsedSinceFullFetch, products, errorMessage;
|
|
2621
|
-
return _regeneratorRuntime().wrap(function
|
|
2622
|
-
while (1) switch (
|
|
2780
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
2781
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
2623
2782
|
case 0:
|
|
2624
2783
|
t0 = performance.now();
|
|
2625
2784
|
now = Date.now();
|
|
2626
2785
|
elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
|
|
2627
2786
|
elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
|
|
2628
2787
|
if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
2629
|
-
|
|
2788
|
+
_context29.next = 6;
|
|
2630
2789
|
break;
|
|
2631
2790
|
}
|
|
2632
|
-
return
|
|
2791
|
+
return _context29.abrupt("return", this.store.list);
|
|
2633
2792
|
case 6:
|
|
2634
2793
|
this.logInfo('silentRefresh 开始');
|
|
2635
|
-
|
|
2636
|
-
|
|
2794
|
+
_context29.prev = 7;
|
|
2795
|
+
_context29.next = 10;
|
|
2637
2796
|
return this.loadProductsByServer();
|
|
2638
2797
|
case 10:
|
|
2639
|
-
products =
|
|
2798
|
+
products = _context29.sent;
|
|
2640
2799
|
if (!(products && products.length > 0)) {
|
|
2641
|
-
|
|
2800
|
+
_context29.next = 21;
|
|
2642
2801
|
break;
|
|
2643
2802
|
}
|
|
2644
2803
|
this.store.list = products;
|
|
2645
2804
|
this.syncProductsMap();
|
|
2646
2805
|
this.clearPriceCache();
|
|
2647
2806
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2648
|
-
|
|
2807
|
+
_context29.next = 18;
|
|
2649
2808
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
|
|
2650
2809
|
case 18:
|
|
2651
2810
|
this.logInfo('silentRefresh 完成', {
|
|
2652
2811
|
productCount: products.length,
|
|
2653
2812
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2654
2813
|
});
|
|
2655
|
-
|
|
2814
|
+
_context29.next = 22;
|
|
2656
2815
|
break;
|
|
2657
2816
|
case 21:
|
|
2658
2817
|
this.logWarning('silentRefresh: 服务器未返回数据');
|
|
@@ -2660,21 +2819,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2660
2819
|
perfMark('silentRefresh', performance.now() - t0, {
|
|
2661
2820
|
count: this.store.list.length
|
|
2662
2821
|
});
|
|
2663
|
-
return
|
|
2822
|
+
return _context29.abrupt("return", this.store.list);
|
|
2664
2823
|
case 26:
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
errorMessage =
|
|
2824
|
+
_context29.prev = 26;
|
|
2825
|
+
_context29.t0 = _context29["catch"](7);
|
|
2826
|
+
errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
|
|
2668
2827
|
this.logError('silentRefresh 失败', {
|
|
2669
2828
|
duration: "".concat(Math.round(performance.now() - t0), "ms"),
|
|
2670
2829
|
error: errorMessage
|
|
2671
2830
|
});
|
|
2672
|
-
return
|
|
2831
|
+
return _context29.abrupt("return", this.store.list);
|
|
2673
2832
|
case 31:
|
|
2674
2833
|
case "end":
|
|
2675
|
-
return
|
|
2834
|
+
return _context29.stop();
|
|
2676
2835
|
}
|
|
2677
|
-
},
|
|
2836
|
+
}, _callee29, this, [[7, 26]]);
|
|
2678
2837
|
}));
|
|
2679
2838
|
function silentRefresh() {
|
|
2680
2839
|
return _silentRefresh.apply(this, arguments);
|