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