@pisell/pisellos 2.2.260 → 2.2.262
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +1 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.js +15 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +25 -0
- package/dist/model/strategy/adapter/dataVariant/examples.js +1 -6
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +2 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +23 -13
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
- package/dist/modules/Discount/index.d.ts +5 -2
- package/dist/modules/Discount/index.js +30 -7
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +45 -2
- package/dist/modules/Order/index.js +1552 -926
- package/dist/modules/Order/types.d.ts +36 -2
- package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
- package/dist/modules/Order/utils.d.ts +8 -3
- package/dist/modules/Order/utils.js +136 -56
- package/dist/modules/Rules/index.d.ts +4 -10
- package/dist/modules/Rules/index.js +63 -12
- package/dist/modules/Rules/types.d.ts +12 -2
- package/dist/modules/SalesSummary/index.d.ts +7 -3
- package/dist/modules/SalesSummary/index.js +67 -39
- package/dist/modules/SalesSummary/types.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.js +2 -1
- package/dist/modules/SurchargeList/index.d.ts +6 -4
- package/dist/modules/SurchargeList/index.js +62 -39
- package/dist/modules/SurchargeList/types.d.ts +6 -2
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +1365 -911
- package/dist/server/modules/order/index.d.ts +32 -7
- package/dist/server/modules/order/index.js +551 -464
- package/dist/server/modules/order/types.d.ts +4 -0
- package/dist/server/modules/products/index.d.ts +5 -1
- package/dist/server/modules/products/index.js +384 -315
- package/dist/server/modules/products/types.d.ts +4 -0
- package/dist/solution/BaseSales/index.d.ts +42 -2
- package/dist/solution/BaseSales/index.js +1416 -775
- package/dist/solution/BaseSales/types.d.ts +7 -1
- package/dist/solution/BaseSales/types.js +3 -2
- package/dist/solution/BaseSales/utils/cartPromotion.js +19 -7
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +20 -4
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +8 -0
- package/dist/solution/BookingTicket/index.js +212 -31
- package/dist/solution/ShopDiscount/index.js +15 -14
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +1 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.js +10 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +20 -1
- package/lib/model/strategy/adapter/dataVariant/examples.js +0 -2
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +2 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
- package/lib/modules/Discount/index.d.ts +5 -2
- package/lib/modules/Discount/index.js +23 -3
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +45 -2
- package/lib/modules/Order/index.js +720 -116
- package/lib/modules/Order/types.d.ts +36 -2
- package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
- package/lib/modules/Order/utils.d.ts +8 -3
- package/lib/modules/Order/utils.js +104 -18
- package/lib/modules/Rules/index.d.ts +4 -10
- package/lib/modules/Rules/index.js +61 -9
- package/lib/modules/Rules/types.d.ts +12 -2
- package/lib/modules/SalesSummary/index.d.ts +7 -3
- package/lib/modules/SalesSummary/index.js +28 -11
- package/lib/modules/SalesSummary/types.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.js +2 -0
- package/lib/modules/SurchargeList/index.d.ts +6 -4
- package/lib/modules/SurchargeList/index.js +41 -21
- package/lib/modules/SurchargeList/types.d.ts +6 -2
- package/lib/server/index.d.ts +8 -0
- package/lib/server/index.js +336 -11
- package/lib/server/modules/order/index.d.ts +32 -7
- package/lib/server/modules/order/index.js +298 -189
- package/lib/server/modules/order/types.d.ts +4 -0
- package/lib/server/modules/products/index.d.ts +5 -1
- package/lib/server/modules/products/index.js +21 -0
- package/lib/server/modules/products/types.d.ts +4 -0
- package/lib/solution/BaseSales/index.d.ts +42 -2
- package/lib/solution/BaseSales/index.js +535 -108
- package/lib/solution/BaseSales/types.d.ts +7 -1
- package/lib/solution/BaseSales/types.js +2 -1
- package/lib/solution/BaseSales/utils/cartPromotion.js +13 -1
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -6
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +8 -0
- package/lib/solution/BookingTicket/index.js +134 -8
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/package.json +1 -1
|
@@ -1072,6 +1072,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1072
1072
|
channel: strategyContext.channel,
|
|
1073
1073
|
orderType: strategyContext.orderType || strategyContext.order_type,
|
|
1074
1074
|
businessCode: (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : strategyContext.businessCode,
|
|
1075
|
+
availableWalletIds: strategyContext.available_wallet_ids,
|
|
1075
1076
|
custom: strategyContext
|
|
1076
1077
|
};
|
|
1077
1078
|
var result = evaluator.resolveProducts(businessData);
|
|
@@ -1418,6 +1419,74 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1418
1419
|
}
|
|
1419
1420
|
return getProducts;
|
|
1420
1421
|
}()
|
|
1422
|
+
/**
|
|
1423
|
+
* 批量获取商品轻量快照,供订单详情等响应补齐展示协议字段。
|
|
1424
|
+
*/
|
|
1425
|
+
)
|
|
1426
|
+
}, {
|
|
1427
|
+
key: "getProductSnapshotsByIds",
|
|
1428
|
+
value: (function () {
|
|
1429
|
+
var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
|
|
1430
|
+
var snapshots, seen, _iterator6, _step6, id, product;
|
|
1431
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1432
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1433
|
+
case 0:
|
|
1434
|
+
snapshots = {};
|
|
1435
|
+
seen = new Set();
|
|
1436
|
+
_iterator6 = _createForOfIteratorHelper(ids);
|
|
1437
|
+
_context13.prev = 3;
|
|
1438
|
+
_iterator6.s();
|
|
1439
|
+
case 5:
|
|
1440
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
1441
|
+
_context13.next = 16;
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1444
|
+
id = _step6.value;
|
|
1445
|
+
if (!(!Number.isFinite(id) || seen.has(id))) {
|
|
1446
|
+
_context13.next = 9;
|
|
1447
|
+
break;
|
|
1448
|
+
}
|
|
1449
|
+
return _context13.abrupt("continue", 14);
|
|
1450
|
+
case 9:
|
|
1451
|
+
seen.add(id);
|
|
1452
|
+
product = this.store.map.get(id);
|
|
1453
|
+
if (product) {
|
|
1454
|
+
_context13.next = 13;
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
return _context13.abrupt("continue", 14);
|
|
1458
|
+
case 13:
|
|
1459
|
+
snapshots[String(id)] = {
|
|
1460
|
+
cover: product.cover,
|
|
1461
|
+
holder_config: product.holder_config
|
|
1462
|
+
};
|
|
1463
|
+
case 14:
|
|
1464
|
+
_context13.next = 5;
|
|
1465
|
+
break;
|
|
1466
|
+
case 16:
|
|
1467
|
+
_context13.next = 21;
|
|
1468
|
+
break;
|
|
1469
|
+
case 18:
|
|
1470
|
+
_context13.prev = 18;
|
|
1471
|
+
_context13.t0 = _context13["catch"](3);
|
|
1472
|
+
_iterator6.e(_context13.t0);
|
|
1473
|
+
case 21:
|
|
1474
|
+
_context13.prev = 21;
|
|
1475
|
+
_iterator6.f();
|
|
1476
|
+
return _context13.finish(21);
|
|
1477
|
+
case 24:
|
|
1478
|
+
return _context13.abrupt("return", snapshots);
|
|
1479
|
+
case 25:
|
|
1480
|
+
case "end":
|
|
1481
|
+
return _context13.stop();
|
|
1482
|
+
}
|
|
1483
|
+
}, _callee13, this, [[3, 18, 21, 24]]);
|
|
1484
|
+
}));
|
|
1485
|
+
function getProductSnapshotsByIds(_x17) {
|
|
1486
|
+
return _getProductSnapshotsByIds.apply(this, arguments);
|
|
1487
|
+
}
|
|
1488
|
+
return getProductSnapshotsByIds;
|
|
1489
|
+
}()
|
|
1421
1490
|
/**
|
|
1422
1491
|
* 内部获取商品列表的直接引用(无拷贝)
|
|
1423
1492
|
* 仅供内部 formatter 流程使用,因为 formatter 会创建新对象
|
|
@@ -1436,18 +1505,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1436
1505
|
key: "getProductsRefByIds",
|
|
1437
1506
|
value: function getProductsRefByIds(ids) {
|
|
1438
1507
|
var products = [];
|
|
1439
|
-
var
|
|
1440
|
-
|
|
1508
|
+
var _iterator7 = _createForOfIteratorHelper(ids),
|
|
1509
|
+
_step7;
|
|
1441
1510
|
try {
|
|
1442
|
-
for (
|
|
1443
|
-
var id =
|
|
1511
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1512
|
+
var id = _step7.value;
|
|
1444
1513
|
var product = this.store.map.get(id);
|
|
1445
1514
|
if (product) products.push(product);
|
|
1446
1515
|
}
|
|
1447
1516
|
} catch (err) {
|
|
1448
|
-
|
|
1517
|
+
_iterator7.e(err);
|
|
1449
1518
|
} finally {
|
|
1450
|
-
|
|
1519
|
+
_iterator7.f();
|
|
1451
1520
|
}
|
|
1452
1521
|
return products;
|
|
1453
1522
|
}
|
|
@@ -1459,20 +1528,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1459
1528
|
}, {
|
|
1460
1529
|
key: "getProductById",
|
|
1461
1530
|
value: (function () {
|
|
1462
|
-
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1531
|
+
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(id) {
|
|
1463
1532
|
var product;
|
|
1464
|
-
return _regeneratorRuntime().wrap(function
|
|
1465
|
-
while (1) switch (
|
|
1533
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1534
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1466
1535
|
case 0:
|
|
1467
1536
|
product = this.store.map.get(id);
|
|
1468
|
-
return
|
|
1537
|
+
return _context14.abrupt("return", product ? structuredClone(product) : undefined);
|
|
1469
1538
|
case 2:
|
|
1470
1539
|
case "end":
|
|
1471
|
-
return
|
|
1540
|
+
return _context14.stop();
|
|
1472
1541
|
}
|
|
1473
|
-
},
|
|
1542
|
+
}, _callee14, this);
|
|
1474
1543
|
}));
|
|
1475
|
-
function getProductById(
|
|
1544
|
+
function getProductById(_x18) {
|
|
1476
1545
|
return _getProductById.apply(this, arguments);
|
|
1477
1546
|
}
|
|
1478
1547
|
return getProductById;
|
|
@@ -1485,10 +1554,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1485
1554
|
}, {
|
|
1486
1555
|
key: "removeProductsByIds",
|
|
1487
1556
|
value: (function () {
|
|
1488
|
-
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1489
|
-
var idSet,
|
|
1490
|
-
return _regeneratorRuntime().wrap(function
|
|
1491
|
-
while (1) switch (
|
|
1557
|
+
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
|
|
1558
|
+
var idSet, _iterator8, _step8, _id, _iterator9, _step9, id, errorMessage, _iterator10, _step10, _step10$value, dateKey, cachedProducts;
|
|
1559
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1560
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1492
1561
|
case 0:
|
|
1493
1562
|
idSet = new Set(ids);
|
|
1494
1563
|
this.logInfo('removeProductsByIds', {
|
|
@@ -1498,71 +1567,71 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1498
1567
|
this.store.list = this.store.list.filter(function (p) {
|
|
1499
1568
|
return !idSet.has(p.id);
|
|
1500
1569
|
});
|
|
1501
|
-
|
|
1570
|
+
_iterator8 = _createForOfIteratorHelper(ids);
|
|
1502
1571
|
try {
|
|
1503
|
-
for (
|
|
1504
|
-
_id =
|
|
1572
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1573
|
+
_id = _step8.value;
|
|
1505
1574
|
this.store.map.delete(_id);
|
|
1506
1575
|
}
|
|
1507
1576
|
} catch (err) {
|
|
1508
|
-
|
|
1577
|
+
_iterator8.e(err);
|
|
1509
1578
|
} finally {
|
|
1510
|
-
|
|
1579
|
+
_iterator8.f();
|
|
1511
1580
|
}
|
|
1512
1581
|
if (!this.dbManager) {
|
|
1513
|
-
|
|
1582
|
+
_context15.next = 30;
|
|
1514
1583
|
break;
|
|
1515
1584
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1585
|
+
_context15.prev = 6;
|
|
1586
|
+
_iterator9 = _createForOfIteratorHelper(ids);
|
|
1587
|
+
_context15.prev = 8;
|
|
1588
|
+
_iterator9.s();
|
|
1520
1589
|
case 10:
|
|
1521
|
-
if ((
|
|
1522
|
-
|
|
1590
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1591
|
+
_context15.next = 16;
|
|
1523
1592
|
break;
|
|
1524
1593
|
}
|
|
1525
|
-
id =
|
|
1526
|
-
|
|
1594
|
+
id = _step9.value;
|
|
1595
|
+
_context15.next = 14;
|
|
1527
1596
|
return this.dbManager.delete(INDEXDB_STORE_NAME, id);
|
|
1528
1597
|
case 14:
|
|
1529
|
-
|
|
1598
|
+
_context15.next = 10;
|
|
1530
1599
|
break;
|
|
1531
1600
|
case 16:
|
|
1532
|
-
|
|
1601
|
+
_context15.next = 21;
|
|
1533
1602
|
break;
|
|
1534
1603
|
case 18:
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1604
|
+
_context15.prev = 18;
|
|
1605
|
+
_context15.t0 = _context15["catch"](8);
|
|
1606
|
+
_iterator9.e(_context15.t0);
|
|
1538
1607
|
case 21:
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
return
|
|
1608
|
+
_context15.prev = 21;
|
|
1609
|
+
_iterator9.f();
|
|
1610
|
+
return _context15.finish(21);
|
|
1542
1611
|
case 24:
|
|
1543
|
-
|
|
1612
|
+
_context15.next = 30;
|
|
1544
1613
|
break;
|
|
1545
1614
|
case 26:
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
errorMessage =
|
|
1615
|
+
_context15.prev = 26;
|
|
1616
|
+
_context15.t1 = _context15["catch"](6);
|
|
1617
|
+
errorMessage = _context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1);
|
|
1549
1618
|
this.logError('removeProductsByIds: IndexDB 删除失败', {
|
|
1550
1619
|
ids: ids,
|
|
1551
1620
|
error: errorMessage
|
|
1552
1621
|
});
|
|
1553
1622
|
case 30:
|
|
1554
|
-
|
|
1623
|
+
_iterator10 = _createForOfIteratorHelper(this.productsPriceCache.entries());
|
|
1555
1624
|
try {
|
|
1556
|
-
for (
|
|
1557
|
-
|
|
1625
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1626
|
+
_step10$value = _slicedToArray(_step10.value, 2), dateKey = _step10$value[0], cachedProducts = _step10$value[1];
|
|
1558
1627
|
this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
|
|
1559
1628
|
return !idSet.has(p.id);
|
|
1560
1629
|
}));
|
|
1561
1630
|
}
|
|
1562
1631
|
} catch (err) {
|
|
1563
|
-
|
|
1632
|
+
_iterator10.e(err);
|
|
1564
1633
|
} finally {
|
|
1565
|
-
|
|
1634
|
+
_iterator10.f();
|
|
1566
1635
|
}
|
|
1567
1636
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
1568
1637
|
this.logInfo('removeProductsByIds 完成', {
|
|
@@ -1570,11 +1639,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1570
1639
|
});
|
|
1571
1640
|
case 34:
|
|
1572
1641
|
case "end":
|
|
1573
|
-
return
|
|
1642
|
+
return _context15.stop();
|
|
1574
1643
|
}
|
|
1575
|
-
},
|
|
1644
|
+
}, _callee15, this, [[6, 26], [8, 18, 21, 24]]);
|
|
1576
1645
|
}));
|
|
1577
|
-
function removeProductsByIds(
|
|
1646
|
+
function removeProductsByIds(_x19) {
|
|
1578
1647
|
return _removeProductsByIds.apply(this, arguments);
|
|
1579
1648
|
}
|
|
1580
1649
|
return removeProductsByIds;
|
|
@@ -1587,17 +1656,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1587
1656
|
}, {
|
|
1588
1657
|
key: "refreshProducts",
|
|
1589
1658
|
value: (function () {
|
|
1590
|
-
var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1659
|
+
var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
1591
1660
|
var tTotal, products;
|
|
1592
|
-
return _regeneratorRuntime().wrap(function
|
|
1593
|
-
while (1) switch (
|
|
1661
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1662
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1594
1663
|
case 0:
|
|
1595
1664
|
tTotal = performance.now();
|
|
1596
1665
|
this.logInfo('refreshProducts 开始');
|
|
1597
|
-
|
|
1666
|
+
_context16.next = 4;
|
|
1598
1667
|
return this.loadProductsByServer();
|
|
1599
1668
|
case 4:
|
|
1600
|
-
products =
|
|
1669
|
+
products = _context16.sent;
|
|
1601
1670
|
if (products && products.length > 0) {
|
|
1602
1671
|
// 服务器返回的数据已经是全新的,无需 cloneDeep
|
|
1603
1672
|
this.store.list = products;
|
|
@@ -1612,12 +1681,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1612
1681
|
perfMark('refreshProducts', performance.now() - tTotal, {
|
|
1613
1682
|
count: this.store.list.length
|
|
1614
1683
|
});
|
|
1615
|
-
return
|
|
1684
|
+
return _context16.abrupt("return", this.store.list);
|
|
1616
1685
|
case 8:
|
|
1617
1686
|
case "end":
|
|
1618
|
-
return
|
|
1687
|
+
return _context16.stop();
|
|
1619
1688
|
}
|
|
1620
|
-
},
|
|
1689
|
+
}, _callee16, this);
|
|
1621
1690
|
}));
|
|
1622
1691
|
function refreshProducts() {
|
|
1623
1692
|
return _refreshProducts.apply(this, arguments);
|
|
@@ -1631,10 +1700,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1631
1700
|
}, {
|
|
1632
1701
|
key: "clear",
|
|
1633
1702
|
value: (function () {
|
|
1634
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1703
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
1635
1704
|
var errorMessage;
|
|
1636
|
-
return _regeneratorRuntime().wrap(function
|
|
1637
|
-
while (1) switch (
|
|
1705
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1706
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1638
1707
|
case 0:
|
|
1639
1708
|
this.logInfo('开始清空缓存', {
|
|
1640
1709
|
currentProductCount: this.store.list.length,
|
|
@@ -1645,22 +1714,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1645
1714
|
|
|
1646
1715
|
// 同时清空 IndexDB 中的所有数据(包括商品和元数据)
|
|
1647
1716
|
if (!this.dbManager) {
|
|
1648
|
-
|
|
1717
|
+
_context17.next = 16;
|
|
1649
1718
|
break;
|
|
1650
1719
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1720
|
+
_context17.prev = 4;
|
|
1721
|
+
_context17.next = 7;
|
|
1653
1722
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1654
1723
|
case 7:
|
|
1655
1724
|
console.log('[Products] IndexDB 缓存已清空');
|
|
1656
1725
|
this.logInfo('IndexDB 缓存已清空');
|
|
1657
|
-
|
|
1726
|
+
_context17.next = 16;
|
|
1658
1727
|
break;
|
|
1659
1728
|
case 11:
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
errorMessage =
|
|
1663
|
-
console.error('[Products] 清空 IndexDB 缓存失败:',
|
|
1729
|
+
_context17.prev = 11;
|
|
1730
|
+
_context17.t0 = _context17["catch"](4);
|
|
1731
|
+
errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
|
|
1732
|
+
console.error('[Products] 清空 IndexDB 缓存失败:', _context17.t0);
|
|
1664
1733
|
this.logError('清空 IndexDB 缓存失败', {
|
|
1665
1734
|
error: errorMessage
|
|
1666
1735
|
});
|
|
@@ -1669,9 +1738,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1669
1738
|
this.logInfo('缓存清空完成');
|
|
1670
1739
|
case 18:
|
|
1671
1740
|
case "end":
|
|
1672
|
-
return
|
|
1741
|
+
return _context17.stop();
|
|
1673
1742
|
}
|
|
1674
|
-
},
|
|
1743
|
+
}, _callee17, this, [[4, 11]]);
|
|
1675
1744
|
}));
|
|
1676
1745
|
function clear() {
|
|
1677
1746
|
return _clear.apply(this, arguments);
|
|
@@ -1686,45 +1755,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1686
1755
|
}, {
|
|
1687
1756
|
key: "loadProductsFromIndexDB",
|
|
1688
1757
|
value: (function () {
|
|
1689
|
-
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1758
|
+
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
|
|
1690
1759
|
var _products$length, _products$length2, t0, products, errorMessage;
|
|
1691
|
-
return _regeneratorRuntime().wrap(function
|
|
1692
|
-
while (1) switch (
|
|
1760
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1761
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1693
1762
|
case 0:
|
|
1694
1763
|
if (this.dbManager) {
|
|
1695
|
-
|
|
1764
|
+
_context18.next = 3;
|
|
1696
1765
|
break;
|
|
1697
1766
|
}
|
|
1698
1767
|
this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
|
|
1699
|
-
return
|
|
1768
|
+
return _context18.abrupt("return", []);
|
|
1700
1769
|
case 3:
|
|
1701
|
-
|
|
1770
|
+
_context18.prev = 3;
|
|
1702
1771
|
t0 = performance.now();
|
|
1703
|
-
|
|
1772
|
+
_context18.next = 7;
|
|
1704
1773
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
1705
1774
|
case 7:
|
|
1706
|
-
products =
|
|
1775
|
+
products = _context18.sent;
|
|
1707
1776
|
perfMark('loadProductsFromIndexDB', performance.now() - t0, {
|
|
1708
1777
|
count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
|
|
1709
1778
|
});
|
|
1710
1779
|
this.logInfo('从 IndexDB 加载商品数据', {
|
|
1711
1780
|
productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
|
|
1712
1781
|
});
|
|
1713
|
-
return
|
|
1782
|
+
return _context18.abrupt("return", products || []);
|
|
1714
1783
|
case 13:
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
errorMessage =
|
|
1718
|
-
console.error('[Products] 从 IndexDB 读取数据失败:',
|
|
1784
|
+
_context18.prev = 13;
|
|
1785
|
+
_context18.t0 = _context18["catch"](3);
|
|
1786
|
+
errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
|
|
1787
|
+
console.error('[Products] 从 IndexDB 读取数据失败:', _context18.t0);
|
|
1719
1788
|
this.logError('从 IndexDB 读取数据失败', {
|
|
1720
1789
|
error: errorMessage
|
|
1721
1790
|
});
|
|
1722
|
-
return
|
|
1791
|
+
return _context18.abrupt("return", []);
|
|
1723
1792
|
case 19:
|
|
1724
1793
|
case "end":
|
|
1725
|
-
return
|
|
1794
|
+
return _context18.stop();
|
|
1726
1795
|
}
|
|
1727
|
-
},
|
|
1796
|
+
}, _callee18, this, [[3, 13]]);
|
|
1728
1797
|
}));
|
|
1729
1798
|
function loadProductsFromIndexDB() {
|
|
1730
1799
|
return _loadProductsFromIndexDB.apply(this, arguments);
|
|
@@ -1743,10 +1812,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1743
1812
|
}, {
|
|
1744
1813
|
key: "runInProductIndexDBSaveQueue",
|
|
1745
1814
|
value: (function () {
|
|
1746
|
-
var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1815
|
+
var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(task) {
|
|
1747
1816
|
var queuedTask;
|
|
1748
|
-
return _regeneratorRuntime().wrap(function
|
|
1749
|
-
while (1) switch (
|
|
1817
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1818
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1750
1819
|
case 0:
|
|
1751
1820
|
queuedTask = this.productIndexDBSaveQueue.then(task, task);
|
|
1752
1821
|
this.productIndexDBSaveQueue = queuedTask.then(function () {
|
|
@@ -1754,14 +1823,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1754
1823
|
}, function () {
|
|
1755
1824
|
return undefined;
|
|
1756
1825
|
});
|
|
1757
|
-
return
|
|
1826
|
+
return _context19.abrupt("return", queuedTask);
|
|
1758
1827
|
case 3:
|
|
1759
1828
|
case "end":
|
|
1760
|
-
return
|
|
1829
|
+
return _context19.stop();
|
|
1761
1830
|
}
|
|
1762
|
-
},
|
|
1831
|
+
}, _callee19, this);
|
|
1763
1832
|
}));
|
|
1764
|
-
function runInProductIndexDBSaveQueue(
|
|
1833
|
+
function runInProductIndexDBSaveQueue(_x20) {
|
|
1765
1834
|
return _runInProductIndexDBSaveQueue.apply(this, arguments);
|
|
1766
1835
|
}
|
|
1767
1836
|
return runInProductIndexDBSaveQueue;
|
|
@@ -1776,39 +1845,39 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1776
1845
|
}, {
|
|
1777
1846
|
key: "replaceProductsSnapshotInIndexDB",
|
|
1778
1847
|
value: (function () {
|
|
1779
|
-
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1848
|
+
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(products, source) {
|
|
1780
1849
|
var _this9 = this;
|
|
1781
1850
|
var errorMessage;
|
|
1782
|
-
return _regeneratorRuntime().wrap(function
|
|
1783
|
-
while (1) switch (
|
|
1851
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1852
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1784
1853
|
case 0:
|
|
1785
1854
|
if (this.dbManager) {
|
|
1786
|
-
|
|
1855
|
+
_context21.next = 3;
|
|
1787
1856
|
break;
|
|
1788
1857
|
}
|
|
1789
1858
|
this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
|
|
1790
|
-
return
|
|
1859
|
+
return _context21.abrupt("return");
|
|
1791
1860
|
case 3:
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1861
|
+
_context21.prev = 3;
|
|
1862
|
+
_context21.next = 6;
|
|
1863
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
1795
1864
|
var t0;
|
|
1796
|
-
return _regeneratorRuntime().wrap(function
|
|
1797
|
-
while (1) switch (
|
|
1865
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1866
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1798
1867
|
case 0:
|
|
1799
1868
|
_this9.logInfo('replaceProductsSnapshotInIndexDB 开始', {
|
|
1800
1869
|
source: source,
|
|
1801
1870
|
productCount: products.length
|
|
1802
1871
|
});
|
|
1803
1872
|
t0 = performance.now();
|
|
1804
|
-
|
|
1873
|
+
_context20.next = 4;
|
|
1805
1874
|
return _this9.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1806
1875
|
case 4:
|
|
1807
1876
|
if (!(products.length > 0)) {
|
|
1808
|
-
|
|
1877
|
+
_context20.next = 7;
|
|
1809
1878
|
break;
|
|
1810
1879
|
}
|
|
1811
|
-
|
|
1880
|
+
_context20.next = 7;
|
|
1812
1881
|
return _this9.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
|
|
1813
1882
|
case 7:
|
|
1814
1883
|
perfMark('replaceProductsSnapshotInIndexDB', performance.now() - t0, {
|
|
@@ -1820,17 +1889,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1820
1889
|
});
|
|
1821
1890
|
case 9:
|
|
1822
1891
|
case "end":
|
|
1823
|
-
return
|
|
1892
|
+
return _context20.stop();
|
|
1824
1893
|
}
|
|
1825
|
-
},
|
|
1894
|
+
}, _callee20);
|
|
1826
1895
|
})));
|
|
1827
1896
|
case 6:
|
|
1828
|
-
|
|
1897
|
+
_context21.next = 12;
|
|
1829
1898
|
break;
|
|
1830
1899
|
case 8:
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
errorMessage =
|
|
1900
|
+
_context21.prev = 8;
|
|
1901
|
+
_context21.t0 = _context21["catch"](3);
|
|
1902
|
+
errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
|
|
1834
1903
|
this.logError('全量保存商品到 IndexDB 失败', {
|
|
1835
1904
|
source: source,
|
|
1836
1905
|
productCount: products.length,
|
|
@@ -1838,11 +1907,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1838
1907
|
});
|
|
1839
1908
|
case 12:
|
|
1840
1909
|
case "end":
|
|
1841
|
-
return
|
|
1910
|
+
return _context21.stop();
|
|
1842
1911
|
}
|
|
1843
|
-
},
|
|
1912
|
+
}, _callee21, this, [[3, 8]]);
|
|
1844
1913
|
}));
|
|
1845
|
-
function replaceProductsSnapshotInIndexDB(
|
|
1914
|
+
function replaceProductsSnapshotInIndexDB(_x21, _x22) {
|
|
1846
1915
|
return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
|
|
1847
1916
|
}
|
|
1848
1917
|
return replaceProductsSnapshotInIndexDB;
|
|
@@ -1857,37 +1926,37 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1857
1926
|
}, {
|
|
1858
1927
|
key: "patchProductsInIndexDB",
|
|
1859
1928
|
value: (function () {
|
|
1860
|
-
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1929
|
+
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(products, source) {
|
|
1861
1930
|
var _this10 = this;
|
|
1862
1931
|
var mergeActions,
|
|
1863
1932
|
validProducts,
|
|
1864
1933
|
errorMessage,
|
|
1865
|
-
|
|
1866
|
-
return _regeneratorRuntime().wrap(function
|
|
1867
|
-
while (1) switch (
|
|
1934
|
+
_args23 = arguments;
|
|
1935
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1936
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1868
1937
|
case 0:
|
|
1869
|
-
mergeActions =
|
|
1938
|
+
mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
|
|
1870
1939
|
if (!(!this.dbManager || products.length === 0)) {
|
|
1871
|
-
|
|
1940
|
+
_context23.next = 3;
|
|
1872
1941
|
break;
|
|
1873
1942
|
}
|
|
1874
|
-
return
|
|
1943
|
+
return _context23.abrupt("return");
|
|
1875
1944
|
case 3:
|
|
1876
1945
|
validProducts = products.filter(function (p) {
|
|
1877
1946
|
return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
|
|
1878
1947
|
});
|
|
1879
1948
|
if (!(validProducts.length === 0)) {
|
|
1880
|
-
|
|
1949
|
+
_context23.next = 6;
|
|
1881
1950
|
break;
|
|
1882
1951
|
}
|
|
1883
|
-
return
|
|
1952
|
+
return _context23.abrupt("return");
|
|
1884
1953
|
case 6:
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1888
|
-
var t0,
|
|
1889
|
-
return _regeneratorRuntime().wrap(function
|
|
1890
|
-
while (1) switch (
|
|
1954
|
+
_context23.prev = 6;
|
|
1955
|
+
_context23.next = 9;
|
|
1956
|
+
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
1957
|
+
var t0, _iterator11, _step11, product;
|
|
1958
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1959
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1891
1960
|
case 0:
|
|
1892
1961
|
_this10.logInfo('patchProductsInIndexDB 开始', {
|
|
1893
1962
|
source: source,
|
|
@@ -1895,44 +1964,44 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1895
1964
|
});
|
|
1896
1965
|
t0 = performance.now();
|
|
1897
1966
|
if (!(typeof _this10.dbManager.bulkUpdate === 'function')) {
|
|
1898
|
-
|
|
1967
|
+
_context22.next = 7;
|
|
1899
1968
|
break;
|
|
1900
1969
|
}
|
|
1901
|
-
|
|
1970
|
+
_context22.next = 5;
|
|
1902
1971
|
return _this10.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
|
|
1903
1972
|
case 5:
|
|
1904
|
-
|
|
1973
|
+
_context22.next = 25;
|
|
1905
1974
|
break;
|
|
1906
1975
|
case 7:
|
|
1907
1976
|
if (!(typeof _this10.dbManager.update === 'function')) {
|
|
1908
|
-
|
|
1977
|
+
_context22.next = 25;
|
|
1909
1978
|
break;
|
|
1910
1979
|
}
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1980
|
+
_iterator11 = _createForOfIteratorHelper(validProducts);
|
|
1981
|
+
_context22.prev = 9;
|
|
1982
|
+
_iterator11.s();
|
|
1914
1983
|
case 11:
|
|
1915
|
-
if ((
|
|
1916
|
-
|
|
1984
|
+
if ((_step11 = _iterator11.n()).done) {
|
|
1985
|
+
_context22.next = 17;
|
|
1917
1986
|
break;
|
|
1918
1987
|
}
|
|
1919
|
-
product =
|
|
1920
|
-
|
|
1988
|
+
product = _step11.value;
|
|
1989
|
+
_context22.next = 15;
|
|
1921
1990
|
return _this10.dbManager.update(INDEXDB_STORE_NAME, product);
|
|
1922
1991
|
case 15:
|
|
1923
|
-
|
|
1992
|
+
_context22.next = 11;
|
|
1924
1993
|
break;
|
|
1925
1994
|
case 17:
|
|
1926
|
-
|
|
1995
|
+
_context22.next = 22;
|
|
1927
1996
|
break;
|
|
1928
1997
|
case 19:
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1998
|
+
_context22.prev = 19;
|
|
1999
|
+
_context22.t0 = _context22["catch"](9);
|
|
2000
|
+
_iterator11.e(_context22.t0);
|
|
1932
2001
|
case 22:
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
return
|
|
2002
|
+
_context22.prev = 22;
|
|
2003
|
+
_iterator11.f();
|
|
2004
|
+
return _context22.finish(22);
|
|
1936
2005
|
case 25:
|
|
1937
2006
|
perfMark('patchProductsInIndexDB', performance.now() - t0, {
|
|
1938
2007
|
count: validProducts.length
|
|
@@ -1943,17 +2012,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1943
2012
|
});
|
|
1944
2013
|
case 27:
|
|
1945
2014
|
case "end":
|
|
1946
|
-
return
|
|
2015
|
+
return _context22.stop();
|
|
1947
2016
|
}
|
|
1948
|
-
},
|
|
2017
|
+
}, _callee22, null, [[9, 19, 22, 25]]);
|
|
1949
2018
|
})));
|
|
1950
2019
|
case 9:
|
|
1951
|
-
|
|
2020
|
+
_context23.next = 15;
|
|
1952
2021
|
break;
|
|
1953
2022
|
case 11:
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
errorMessage =
|
|
2023
|
+
_context23.prev = 11;
|
|
2024
|
+
_context23.t0 = _context23["catch"](6);
|
|
2025
|
+
errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
|
|
1957
2026
|
this.logError('增量保存商品到 IndexDB 失败', {
|
|
1958
2027
|
source: source,
|
|
1959
2028
|
error: errorMessage,
|
|
@@ -1961,11 +2030,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1961
2030
|
});
|
|
1962
2031
|
case 15:
|
|
1963
2032
|
case "end":
|
|
1964
|
-
return
|
|
2033
|
+
return _context23.stop();
|
|
1965
2034
|
}
|
|
1966
|
-
},
|
|
2035
|
+
}, _callee23, this, [[6, 11]]);
|
|
1967
2036
|
}));
|
|
1968
|
-
function patchProductsInIndexDB(
|
|
2037
|
+
function patchProductsInIndexDB(_x23, _x24) {
|
|
1969
2038
|
return _patchProductsInIndexDB.apply(this, arguments);
|
|
1970
2039
|
}
|
|
1971
2040
|
return patchProductsInIndexDB;
|
|
@@ -1981,17 +2050,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1981
2050
|
value: function syncProductsMap() {
|
|
1982
2051
|
var t0 = performance.now();
|
|
1983
2052
|
this.store.map.clear();
|
|
1984
|
-
var
|
|
1985
|
-
|
|
2053
|
+
var _iterator12 = _createForOfIteratorHelper(this.store.list),
|
|
2054
|
+
_step12;
|
|
1986
2055
|
try {
|
|
1987
|
-
for (
|
|
1988
|
-
var product =
|
|
2056
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
2057
|
+
var product = _step12.value;
|
|
1989
2058
|
this.store.map.set(product.id, product);
|
|
1990
2059
|
}
|
|
1991
2060
|
} catch (err) {
|
|
1992
|
-
|
|
2061
|
+
_iterator12.e(err);
|
|
1993
2062
|
} finally {
|
|
1994
|
-
|
|
2063
|
+
_iterator12.f();
|
|
1995
2064
|
}
|
|
1996
2065
|
perfMark('syncProductsMap', performance.now() - t0, {
|
|
1997
2066
|
count: this.store.map.size
|
|
@@ -2005,26 +2074,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2005
2074
|
}, {
|
|
2006
2075
|
key: "preload",
|
|
2007
2076
|
value: (function () {
|
|
2008
|
-
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2077
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
2009
2078
|
var _products$length3;
|
|
2010
2079
|
var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
|
|
2011
|
-
return _regeneratorRuntime().wrap(function
|
|
2012
|
-
while (1) switch (
|
|
2080
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2081
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2013
2082
|
case 0:
|
|
2014
2083
|
console.log('[Products] 开始预加载数据...');
|
|
2015
2084
|
tTotal = performance.now();
|
|
2016
2085
|
this.logInfo('开始预加载数据');
|
|
2017
|
-
|
|
2086
|
+
_context24.prev = 3;
|
|
2018
2087
|
tIndexDB = performance.now();
|
|
2019
|
-
|
|
2088
|
+
_context24.next = 7;
|
|
2020
2089
|
return this.loadProductsFromIndexDB();
|
|
2021
2090
|
case 7:
|
|
2022
|
-
cachedData =
|
|
2091
|
+
cachedData = _context24.sent;
|
|
2023
2092
|
perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
|
|
2024
2093
|
count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
|
|
2025
2094
|
});
|
|
2026
2095
|
if (!(cachedData && cachedData.length > 0)) {
|
|
2027
|
-
|
|
2096
|
+
_context24.next = 20;
|
|
2028
2097
|
break;
|
|
2029
2098
|
}
|
|
2030
2099
|
console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
|
|
@@ -2046,26 +2115,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2046
2115
|
source: 'IndexDB'
|
|
2047
2116
|
});
|
|
2048
2117
|
this.lastPreloadCompletedAtMs = Date.now();
|
|
2049
|
-
return
|
|
2118
|
+
return _context24.abrupt("return");
|
|
2050
2119
|
case 20:
|
|
2051
2120
|
console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
|
|
2052
2121
|
this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
|
|
2053
|
-
|
|
2122
|
+
_context24.next = 29;
|
|
2054
2123
|
break;
|
|
2055
2124
|
case 24:
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
errorMessage =
|
|
2059
|
-
console.warn('[Products] 从 IndexDB 加载数据失败:',
|
|
2125
|
+
_context24.prev = 24;
|
|
2126
|
+
_context24.t0 = _context24["catch"](3);
|
|
2127
|
+
errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
|
|
2128
|
+
console.warn('[Products] 从 IndexDB 加载数据失败:', _context24.t0);
|
|
2060
2129
|
this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
|
|
2061
2130
|
error: errorMessage
|
|
2062
2131
|
});
|
|
2063
2132
|
case 29:
|
|
2064
2133
|
tServer = performance.now();
|
|
2065
|
-
|
|
2134
|
+
_context24.next = 32;
|
|
2066
2135
|
return this.loadProductsByServer();
|
|
2067
2136
|
case 32:
|
|
2068
|
-
products =
|
|
2137
|
+
products = _context24.sent;
|
|
2069
2138
|
perfMark('preload.loadFromServer', performance.now() - tServer, {
|
|
2070
2139
|
count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
|
|
2071
2140
|
});
|
|
@@ -2098,9 +2167,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2098
2167
|
}
|
|
2099
2168
|
case 35:
|
|
2100
2169
|
case "end":
|
|
2101
|
-
return
|
|
2170
|
+
return _context24.stop();
|
|
2102
2171
|
}
|
|
2103
|
-
},
|
|
2172
|
+
}, _callee24, this, [[3, 24]]);
|
|
2104
2173
|
}));
|
|
2105
2174
|
function preload() {
|
|
2106
2175
|
return _preload.apply(this, arguments);
|
|
@@ -2204,18 +2273,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2204
2273
|
}, {
|
|
2205
2274
|
key: "processProductSyncMessages",
|
|
2206
2275
|
value: (function () {
|
|
2207
|
-
var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2208
|
-
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache,
|
|
2209
|
-
return _regeneratorRuntime().wrap(function
|
|
2210
|
-
while (1) switch (
|
|
2276
|
+
var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
2277
|
+
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator13, _step13, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator14, _step14, product, freshProducts, mergeResult, _iterator15, _step15, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
|
|
2278
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2279
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2211
2280
|
case 0:
|
|
2212
2281
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
2213
2282
|
this.pendingSyncMessages = [];
|
|
2214
2283
|
if (!(messages.length === 0)) {
|
|
2215
|
-
|
|
2284
|
+
_context25.next = 4;
|
|
2216
2285
|
break;
|
|
2217
2286
|
}
|
|
2218
|
-
return
|
|
2287
|
+
return _context25.abrupt("return");
|
|
2219
2288
|
case 4:
|
|
2220
2289
|
this.logInfo('processProductSyncMessages: 开始处理', {
|
|
2221
2290
|
count: messages.length
|
|
@@ -2225,18 +2294,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2225
2294
|
sseRefreshIds = [];
|
|
2226
2295
|
priceRefreshIds = [];
|
|
2227
2296
|
shouldClearPriceCache = false;
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2297
|
+
_iterator13 = _createForOfIteratorHelper(messages);
|
|
2298
|
+
_context25.prev = 11;
|
|
2299
|
+
_iterator13.s();
|
|
2231
2300
|
case 13:
|
|
2232
|
-
if ((
|
|
2233
|
-
|
|
2301
|
+
if ((_step13 = _iterator13.n()).done) {
|
|
2302
|
+
_context25.next = 36;
|
|
2234
2303
|
break;
|
|
2235
2304
|
}
|
|
2236
|
-
msg =
|
|
2305
|
+
msg = _step13.value;
|
|
2237
2306
|
channelKey = msg._channelKey || msg.module || 'product';
|
|
2238
2307
|
if (!(channelKey === 'product')) {
|
|
2239
|
-
|
|
2308
|
+
_context25.next = 33;
|
|
2240
2309
|
break;
|
|
2241
2310
|
}
|
|
2242
2311
|
if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
|
|
@@ -2244,14 +2313,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2244
2313
|
}
|
|
2245
2314
|
// 1. 删除场景:operation === 'delete' 或 action === 'delete'
|
|
2246
2315
|
if (!(msg.operation === 'delete' || msg.action === 'delete')) {
|
|
2247
|
-
|
|
2316
|
+
_context25.next = 21;
|
|
2248
2317
|
break;
|
|
2249
2318
|
}
|
|
2250
2319
|
if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
|
|
2251
|
-
return
|
|
2320
|
+
return _context25.abrupt("continue", 34);
|
|
2252
2321
|
case 21:
|
|
2253
2322
|
if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
|
|
2254
|
-
|
|
2323
|
+
_context25.next = 26;
|
|
2255
2324
|
break;
|
|
2256
2325
|
}
|
|
2257
2326
|
ids = msg.ids || (msg.id ? [msg.id] : []);
|
|
@@ -2260,15 +2329,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2260
2329
|
bodyId = msg.body.id;
|
|
2261
2330
|
if (bodyId) bodyUpdates.set(bodyId, msg.body);
|
|
2262
2331
|
}
|
|
2263
|
-
return
|
|
2332
|
+
return _context25.abrupt("continue", 34);
|
|
2264
2333
|
case 26:
|
|
2265
2334
|
if (!msg.body) {
|
|
2266
|
-
|
|
2335
|
+
_context25.next = 30;
|
|
2267
2336
|
break;
|
|
2268
2337
|
}
|
|
2269
2338
|
_bodyId = msg.body.id || msg.id;
|
|
2270
2339
|
if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
|
|
2271
|
-
return
|
|
2340
|
+
return _context25.abrupt("continue", 34);
|
|
2272
2341
|
case 30:
|
|
2273
2342
|
// 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
|
|
2274
2343
|
if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
|
|
@@ -2276,7 +2345,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2276
2345
|
} else if (msg.id) {
|
|
2277
2346
|
sseRefreshIds.push(msg.id);
|
|
2278
2347
|
}
|
|
2279
|
-
|
|
2348
|
+
_context25.next = 34;
|
|
2280
2349
|
break;
|
|
2281
2350
|
case 33:
|
|
2282
2351
|
if (channelKey === 'product_quotation') {
|
|
@@ -2295,28 +2364,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2295
2364
|
}
|
|
2296
2365
|
}
|
|
2297
2366
|
case 34:
|
|
2298
|
-
|
|
2367
|
+
_context25.next = 13;
|
|
2299
2368
|
break;
|
|
2300
2369
|
case 36:
|
|
2301
|
-
|
|
2370
|
+
_context25.next = 41;
|
|
2302
2371
|
break;
|
|
2303
2372
|
case 38:
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2373
|
+
_context25.prev = 38;
|
|
2374
|
+
_context25.t0 = _context25["catch"](11);
|
|
2375
|
+
_iterator13.e(_context25.t0);
|
|
2307
2376
|
case 41:
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
return
|
|
2377
|
+
_context25.prev = 41;
|
|
2378
|
+
_iterator13.f();
|
|
2379
|
+
return _context25.finish(41);
|
|
2311
2380
|
case 44:
|
|
2312
2381
|
uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
|
|
2313
2382
|
uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
|
|
2314
2383
|
uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
|
|
2315
2384
|
if (!(uniqueDeleteIds.length > 0)) {
|
|
2316
|
-
|
|
2385
|
+
_context25.next = 50;
|
|
2317
2386
|
break;
|
|
2318
2387
|
}
|
|
2319
|
-
|
|
2388
|
+
_context25.next = 50;
|
|
2320
2389
|
return this.removeProductsByIds(uniqueDeleteIds);
|
|
2321
2390
|
case 50:
|
|
2322
2391
|
/** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
|
|
@@ -2324,62 +2393,62 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2324
2393
|
patchMergeActions = {};
|
|
2325
2394
|
storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
|
|
2326
2395
|
if (!(bodyUpdates.size > 0)) {
|
|
2327
|
-
|
|
2396
|
+
_context25.next = 60;
|
|
2328
2397
|
break;
|
|
2329
2398
|
}
|
|
2330
|
-
|
|
2399
|
+
_context25.next = 56;
|
|
2331
2400
|
return this.applyBodyUpdatesToStore(bodyUpdates, {
|
|
2332
2401
|
skipIndexDB: true,
|
|
2333
2402
|
skipEmit: true
|
|
2334
2403
|
});
|
|
2335
2404
|
case 56:
|
|
2336
|
-
bodyResult =
|
|
2337
|
-
|
|
2405
|
+
bodyResult = _context25.sent;
|
|
2406
|
+
_iterator14 = _createForOfIteratorHelper(bodyResult.changedProducts);
|
|
2338
2407
|
try {
|
|
2339
|
-
for (
|
|
2340
|
-
product =
|
|
2408
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
2409
|
+
product = _step14.value;
|
|
2341
2410
|
patchProductMap.set(product.id, product);
|
|
2342
2411
|
patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
|
|
2343
2412
|
}
|
|
2344
2413
|
} catch (err) {
|
|
2345
|
-
|
|
2414
|
+
_iterator14.e(err);
|
|
2346
2415
|
} finally {
|
|
2347
|
-
|
|
2416
|
+
_iterator14.f();
|
|
2348
2417
|
}
|
|
2349
2418
|
storeMutated = true;
|
|
2350
2419
|
case 60:
|
|
2351
2420
|
// 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
|
|
2352
2421
|
freshProducts = [];
|
|
2353
2422
|
if (!(uniqueSSEIds.length > 0)) {
|
|
2354
|
-
|
|
2423
|
+
_context25.next = 73;
|
|
2355
2424
|
break;
|
|
2356
2425
|
}
|
|
2357
|
-
|
|
2426
|
+
_context25.next = 64;
|
|
2358
2427
|
return this.fetchProductsBySSE(uniqueSSEIds);
|
|
2359
2428
|
case 64:
|
|
2360
|
-
freshProducts =
|
|
2429
|
+
freshProducts = _context25.sent;
|
|
2361
2430
|
if (!(freshProducts.length > 0)) {
|
|
2362
|
-
|
|
2431
|
+
_context25.next = 72;
|
|
2363
2432
|
break;
|
|
2364
2433
|
}
|
|
2365
|
-
|
|
2434
|
+
_context25.next = 68;
|
|
2366
2435
|
return this.mergeProductsToStore(freshProducts, {
|
|
2367
2436
|
skipIndexDB: true,
|
|
2368
2437
|
skipEmit: true
|
|
2369
2438
|
});
|
|
2370
2439
|
case 68:
|
|
2371
|
-
mergeResult =
|
|
2372
|
-
|
|
2440
|
+
mergeResult = _context25.sent;
|
|
2441
|
+
_iterator15 = _createForOfIteratorHelper(mergeResult.changedProducts);
|
|
2373
2442
|
try {
|
|
2374
|
-
for (
|
|
2375
|
-
_product =
|
|
2443
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
2444
|
+
_product = _step15.value;
|
|
2376
2445
|
patchProductMap.set(_product.id, _product);
|
|
2377
2446
|
patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
|
|
2378
2447
|
}
|
|
2379
2448
|
} catch (err) {
|
|
2380
|
-
|
|
2449
|
+
_iterator15.e(err);
|
|
2381
2450
|
} finally {
|
|
2382
|
-
|
|
2451
|
+
_iterator15.f();
|
|
2383
2452
|
}
|
|
2384
2453
|
storeMutated = true;
|
|
2385
2454
|
case 72:
|
|
@@ -2390,10 +2459,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2390
2459
|
case 73:
|
|
2391
2460
|
patchProducts = _toConsumableArray(patchProductMap.values());
|
|
2392
2461
|
if (!(patchProducts.length > 0)) {
|
|
2393
|
-
|
|
2462
|
+
_context25.next = 77;
|
|
2394
2463
|
break;
|
|
2395
2464
|
}
|
|
2396
|
-
|
|
2465
|
+
_context25.next = 77;
|
|
2397
2466
|
return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
|
|
2398
2467
|
case 77:
|
|
2399
2468
|
if (storeMutated) {
|
|
@@ -2412,41 +2481,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2412
2481
|
});
|
|
2413
2482
|
hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
|
|
2414
2483
|
if (hasChanges) {
|
|
2415
|
-
|
|
2484
|
+
_context25.next = 84;
|
|
2416
2485
|
break;
|
|
2417
2486
|
}
|
|
2418
2487
|
this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
|
|
2419
|
-
return
|
|
2488
|
+
return _context25.abrupt("return");
|
|
2420
2489
|
case 84:
|
|
2421
2490
|
if (!shouldClearPriceCache) {
|
|
2422
|
-
|
|
2491
|
+
_context25.next = 95;
|
|
2423
2492
|
break;
|
|
2424
2493
|
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2494
|
+
_context25.prev = 85;
|
|
2495
|
+
_context25.next = 88;
|
|
2427
2496
|
return this.refreshQuotationPriceBridge();
|
|
2428
2497
|
case 88:
|
|
2429
|
-
|
|
2498
|
+
_context25.next = 94;
|
|
2430
2499
|
break;
|
|
2431
2500
|
case 90:
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
errorMessage =
|
|
2501
|
+
_context25.prev = 90;
|
|
2502
|
+
_context25.t1 = _context25["catch"](85);
|
|
2503
|
+
errorMessage = _context25.t1 instanceof Error ? _context25.t1.message : String(_context25.t1);
|
|
2435
2504
|
this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
|
|
2436
2505
|
error: errorMessage
|
|
2437
2506
|
});
|
|
2438
2507
|
case 94:
|
|
2439
2508
|
this.clearPriceCache();
|
|
2440
2509
|
case 95:
|
|
2441
|
-
|
|
2510
|
+
_context25.next = 97;
|
|
2442
2511
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
|
|
2443
2512
|
changedIds: allChangedIds
|
|
2444
2513
|
});
|
|
2445
2514
|
case 97:
|
|
2446
2515
|
case "end":
|
|
2447
|
-
return
|
|
2516
|
+
return _context25.stop();
|
|
2448
2517
|
}
|
|
2449
|
-
},
|
|
2518
|
+
}, _callee25, this, [[11, 38, 41, 44], [85, 90]]);
|
|
2450
2519
|
}));
|
|
2451
2520
|
function processProductSyncMessages() {
|
|
2452
2521
|
return _processProductSyncMessages.apply(this, arguments);
|
|
@@ -2461,25 +2530,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2461
2530
|
}, {
|
|
2462
2531
|
key: "fetchProductsBySSE",
|
|
2463
2532
|
value: (function () {
|
|
2464
|
-
var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2533
|
+
var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(ids) {
|
|
2465
2534
|
var t0, productList, list, errorMessage;
|
|
2466
|
-
return _regeneratorRuntime().wrap(function
|
|
2467
|
-
while (1) switch (
|
|
2535
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2536
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2468
2537
|
case 0:
|
|
2469
2538
|
if (this.productDataSource) {
|
|
2470
|
-
|
|
2539
|
+
_context26.next = 3;
|
|
2471
2540
|
break;
|
|
2472
2541
|
}
|
|
2473
2542
|
this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
|
|
2474
|
-
return
|
|
2543
|
+
return _context26.abrupt("return", []);
|
|
2475
2544
|
case 3:
|
|
2476
2545
|
this.logInfo('fetchProductsBySSE: 开始', {
|
|
2477
2546
|
ids: ids,
|
|
2478
2547
|
count: ids.length
|
|
2479
2548
|
});
|
|
2480
2549
|
t0 = performance.now();
|
|
2481
|
-
|
|
2482
|
-
|
|
2550
|
+
_context26.prev = 5;
|
|
2551
|
+
_context26.next = 8;
|
|
2483
2552
|
return this.productDataSource.run({
|
|
2484
2553
|
sse: {
|
|
2485
2554
|
query: {
|
|
@@ -2489,7 +2558,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2489
2558
|
}
|
|
2490
2559
|
});
|
|
2491
2560
|
case 8:
|
|
2492
|
-
productList =
|
|
2561
|
+
productList = _context26.sent;
|
|
2493
2562
|
list = productList || [];
|
|
2494
2563
|
perfMark('fetchProductsBySSE', performance.now() - t0, {
|
|
2495
2564
|
count: list.length
|
|
@@ -2499,23 +2568,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2499
2568
|
receivedCount: list.length,
|
|
2500
2569
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2501
2570
|
});
|
|
2502
|
-
return
|
|
2571
|
+
return _context26.abrupt("return", list);
|
|
2503
2572
|
case 15:
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
errorMessage =
|
|
2573
|
+
_context26.prev = 15;
|
|
2574
|
+
_context26.t0 = _context26["catch"](5);
|
|
2575
|
+
errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
|
|
2507
2576
|
this.logError('fetchProductsBySSE: 失败', {
|
|
2508
2577
|
ids: ids,
|
|
2509
2578
|
error: errorMessage
|
|
2510
2579
|
});
|
|
2511
|
-
return
|
|
2580
|
+
return _context26.abrupt("return", []);
|
|
2512
2581
|
case 20:
|
|
2513
2582
|
case "end":
|
|
2514
|
-
return
|
|
2583
|
+
return _context26.stop();
|
|
2515
2584
|
}
|
|
2516
|
-
},
|
|
2585
|
+
}, _callee26, this, [[5, 15]]);
|
|
2517
2586
|
}));
|
|
2518
|
-
function fetchProductsBySSE(
|
|
2587
|
+
function fetchProductsBySSE(_x25) {
|
|
2519
2588
|
return _fetchProductsBySSE.apply(this, arguments);
|
|
2520
2589
|
}
|
|
2521
2590
|
return fetchProductsBySSE;
|
|
@@ -2531,10 +2600,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2531
2600
|
}, {
|
|
2532
2601
|
key: "applyBodyUpdatesToStore",
|
|
2533
2602
|
value: (function () {
|
|
2534
|
-
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2535
|
-
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts,
|
|
2536
|
-
return _regeneratorRuntime().wrap(function
|
|
2537
|
-
while (1) switch (
|
|
2603
|
+
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(bodyUpdates, options) {
|
|
2604
|
+
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator16, _step16, _step16$value, id, body;
|
|
2605
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
2606
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2538
2607
|
case 0:
|
|
2539
2608
|
changedProductIds = _toConsumableArray(bodyUpdates.keys());
|
|
2540
2609
|
this.logInfo('applyBodyUpdatesToStore: 开始', {
|
|
@@ -2556,10 +2625,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2556
2625
|
}
|
|
2557
2626
|
return p;
|
|
2558
2627
|
});
|
|
2559
|
-
|
|
2628
|
+
_iterator16 = _createForOfIteratorHelper(bodyUpdates);
|
|
2560
2629
|
try {
|
|
2561
|
-
for (
|
|
2562
|
-
|
|
2630
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
2631
|
+
_step16$value = _slicedToArray(_step16.value, 2), id = _step16$value[0], body = _step16$value[1];
|
|
2563
2632
|
if (!appliedIds.has(id)) {
|
|
2564
2633
|
this.store.list.push(body);
|
|
2565
2634
|
newCount++;
|
|
@@ -2568,16 +2637,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2568
2637
|
}
|
|
2569
2638
|
}
|
|
2570
2639
|
} catch (err) {
|
|
2571
|
-
|
|
2640
|
+
_iterator16.e(err);
|
|
2572
2641
|
} finally {
|
|
2573
|
-
|
|
2642
|
+
_iterator16.f();
|
|
2574
2643
|
}
|
|
2575
2644
|
this.syncProductsMap();
|
|
2576
2645
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2577
|
-
|
|
2646
|
+
_context27.next = 14;
|
|
2578
2647
|
break;
|
|
2579
2648
|
}
|
|
2580
|
-
|
|
2649
|
+
_context27.next = 14;
|
|
2581
2650
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
|
|
2582
2651
|
case 14:
|
|
2583
2652
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
@@ -2588,7 +2657,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2588
2657
|
newCount: newCount,
|
|
2589
2658
|
totalCount: this.store.list.length
|
|
2590
2659
|
});
|
|
2591
|
-
return
|
|
2660
|
+
return _context27.abrupt("return", {
|
|
2592
2661
|
changedProducts: changedProducts,
|
|
2593
2662
|
mergeActions: mergeActions,
|
|
2594
2663
|
updatedCount: updatedCount,
|
|
@@ -2596,11 +2665,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2596
2665
|
});
|
|
2597
2666
|
case 17:
|
|
2598
2667
|
case "end":
|
|
2599
|
-
return
|
|
2668
|
+
return _context27.stop();
|
|
2600
2669
|
}
|
|
2601
|
-
},
|
|
2670
|
+
}, _callee27, this);
|
|
2602
2671
|
}));
|
|
2603
|
-
function applyBodyUpdatesToStore(
|
|
2672
|
+
function applyBodyUpdatesToStore(_x26, _x27) {
|
|
2604
2673
|
return _applyBodyUpdatesToStore.apply(this, arguments);
|
|
2605
2674
|
}
|
|
2606
2675
|
return applyBodyUpdatesToStore;
|
|
@@ -2616,22 +2685,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2616
2685
|
}, {
|
|
2617
2686
|
key: "mergeProductsToStore",
|
|
2618
2687
|
value: (function () {
|
|
2619
|
-
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2620
|
-
var freshMap,
|
|
2621
|
-
return _regeneratorRuntime().wrap(function
|
|
2622
|
-
while (1) switch (
|
|
2688
|
+
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(freshProducts, options) {
|
|
2689
|
+
var freshMap, _iterator17, _step17, p, mergeActions, changedProducts, updatedList, newCount, _iterator18, _step18, _p2, updatedCount, changedProductIds;
|
|
2690
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
2691
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2623
2692
|
case 0:
|
|
2624
2693
|
freshMap = new Map();
|
|
2625
|
-
|
|
2694
|
+
_iterator17 = _createForOfIteratorHelper(freshProducts);
|
|
2626
2695
|
try {
|
|
2627
|
-
for (
|
|
2628
|
-
p =
|
|
2696
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2697
|
+
p = _step17.value;
|
|
2629
2698
|
freshMap.set(p.id, p);
|
|
2630
2699
|
}
|
|
2631
2700
|
} catch (err) {
|
|
2632
|
-
|
|
2701
|
+
_iterator17.e(err);
|
|
2633
2702
|
} finally {
|
|
2634
|
-
|
|
2703
|
+
_iterator17.f();
|
|
2635
2704
|
}
|
|
2636
2705
|
mergeActions = {};
|
|
2637
2706
|
changedProducts = [];
|
|
@@ -2646,18 +2715,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2646
2715
|
return p;
|
|
2647
2716
|
}); // freshMap 中剩余的是新商品(create 场景)
|
|
2648
2717
|
newCount = freshMap.size;
|
|
2649
|
-
|
|
2718
|
+
_iterator18 = _createForOfIteratorHelper(freshMap.values());
|
|
2650
2719
|
try {
|
|
2651
|
-
for (
|
|
2652
|
-
_p2 =
|
|
2720
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2721
|
+
_p2 = _step18.value;
|
|
2653
2722
|
updatedList.push(_p2);
|
|
2654
2723
|
mergeActions[_p2.id] = 'insert';
|
|
2655
2724
|
changedProducts.push(_p2);
|
|
2656
2725
|
}
|
|
2657
2726
|
} catch (err) {
|
|
2658
|
-
|
|
2727
|
+
_iterator18.e(err);
|
|
2659
2728
|
} finally {
|
|
2660
|
-
|
|
2729
|
+
_iterator18.f();
|
|
2661
2730
|
}
|
|
2662
2731
|
updatedCount = freshProducts.length - newCount;
|
|
2663
2732
|
changedProductIds = freshProducts.map(function (p) {
|
|
@@ -2666,10 +2735,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2666
2735
|
this.store.list = updatedList;
|
|
2667
2736
|
this.syncProductsMap();
|
|
2668
2737
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2669
|
-
|
|
2738
|
+
_context28.next = 16;
|
|
2670
2739
|
break;
|
|
2671
2740
|
}
|
|
2672
|
-
|
|
2741
|
+
_context28.next = 16;
|
|
2673
2742
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
|
|
2674
2743
|
case 16:
|
|
2675
2744
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
@@ -2680,7 +2749,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2680
2749
|
newCount: newCount,
|
|
2681
2750
|
totalCount: this.store.list.length
|
|
2682
2751
|
});
|
|
2683
|
-
return
|
|
2752
|
+
return _context28.abrupt("return", {
|
|
2684
2753
|
changedProducts: changedProducts,
|
|
2685
2754
|
mergeActions: mergeActions,
|
|
2686
2755
|
updatedCount: updatedCount,
|
|
@@ -2688,11 +2757,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2688
2757
|
});
|
|
2689
2758
|
case 19:
|
|
2690
2759
|
case "end":
|
|
2691
|
-
return
|
|
2760
|
+
return _context28.stop();
|
|
2692
2761
|
}
|
|
2693
|
-
},
|
|
2762
|
+
}, _callee28, this);
|
|
2694
2763
|
}));
|
|
2695
|
-
function mergeProductsToStore(
|
|
2764
|
+
function mergeProductsToStore(_x28, _x29) {
|
|
2696
2765
|
return _mergeProductsToStore.apply(this, arguments);
|
|
2697
2766
|
}
|
|
2698
2767
|
return mergeProductsToStore;
|
|
@@ -2706,43 +2775,43 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2706
2775
|
}, {
|
|
2707
2776
|
key: "silentRefresh",
|
|
2708
2777
|
value: (function () {
|
|
2709
|
-
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2778
|
+
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
2710
2779
|
var t0, now, elapsedSincePreload, elapsedSinceFullFetch, products, errorMessage;
|
|
2711
|
-
return _regeneratorRuntime().wrap(function
|
|
2712
|
-
while (1) switch (
|
|
2780
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
2781
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
2713
2782
|
case 0:
|
|
2714
2783
|
t0 = performance.now();
|
|
2715
2784
|
now = Date.now();
|
|
2716
2785
|
elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
|
|
2717
2786
|
elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
|
|
2718
2787
|
if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
2719
|
-
|
|
2788
|
+
_context29.next = 6;
|
|
2720
2789
|
break;
|
|
2721
2790
|
}
|
|
2722
|
-
return
|
|
2791
|
+
return _context29.abrupt("return", this.store.list);
|
|
2723
2792
|
case 6:
|
|
2724
2793
|
this.logInfo('silentRefresh 开始');
|
|
2725
|
-
|
|
2726
|
-
|
|
2794
|
+
_context29.prev = 7;
|
|
2795
|
+
_context29.next = 10;
|
|
2727
2796
|
return this.loadProductsByServer();
|
|
2728
2797
|
case 10:
|
|
2729
|
-
products =
|
|
2798
|
+
products = _context29.sent;
|
|
2730
2799
|
if (!(products && products.length > 0)) {
|
|
2731
|
-
|
|
2800
|
+
_context29.next = 21;
|
|
2732
2801
|
break;
|
|
2733
2802
|
}
|
|
2734
2803
|
this.store.list = products;
|
|
2735
2804
|
this.syncProductsMap();
|
|
2736
2805
|
this.clearPriceCache();
|
|
2737
2806
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2738
|
-
|
|
2807
|
+
_context29.next = 18;
|
|
2739
2808
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
|
|
2740
2809
|
case 18:
|
|
2741
2810
|
this.logInfo('silentRefresh 完成', {
|
|
2742
2811
|
productCount: products.length,
|
|
2743
2812
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2744
2813
|
});
|
|
2745
|
-
|
|
2814
|
+
_context29.next = 22;
|
|
2746
2815
|
break;
|
|
2747
2816
|
case 21:
|
|
2748
2817
|
this.logWarning('silentRefresh: 服务器未返回数据');
|
|
@@ -2750,21 +2819,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2750
2819
|
perfMark('silentRefresh', performance.now() - t0, {
|
|
2751
2820
|
count: this.store.list.length
|
|
2752
2821
|
});
|
|
2753
|
-
return
|
|
2822
|
+
return _context29.abrupt("return", this.store.list);
|
|
2754
2823
|
case 26:
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
errorMessage =
|
|
2824
|
+
_context29.prev = 26;
|
|
2825
|
+
_context29.t0 = _context29["catch"](7);
|
|
2826
|
+
errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
|
|
2758
2827
|
this.logError('silentRefresh 失败', {
|
|
2759
2828
|
duration: "".concat(Math.round(performance.now() - t0), "ms"),
|
|
2760
2829
|
error: errorMessage
|
|
2761
2830
|
});
|
|
2762
|
-
return
|
|
2831
|
+
return _context29.abrupt("return", this.store.list);
|
|
2763
2832
|
case 31:
|
|
2764
2833
|
case "end":
|
|
2765
|
-
return
|
|
2834
|
+
return _context29.stop();
|
|
2766
2835
|
}
|
|
2767
|
-
},
|
|
2836
|
+
}, _callee29, this, [[7, 26]]);
|
|
2768
2837
|
}));
|
|
2769
2838
|
function silentRefresh() {
|
|
2770
2839
|
return _silentRefresh.apply(this, arguments);
|