@pisell/pisellos 2.3.210 → 2.3.211

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.
@@ -42,7 +42,7 @@ import { CommittedProductState } from "./replication";
42
42
  var INDEXDB_STORE_NAME = 'products';
43
43
  /** 商品同步防抖时间(毫秒) */
44
44
  var PRODUCT_SYNC_DEBOUNCE_MS = 10000;
45
- /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
45
+ /** silentRefresh 最小间隔,仅从成功的服务器全量刷新计时 */
46
46
  var PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
47
47
 
48
48
  /**
@@ -92,8 +92,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
92
92
  _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
93
93
  /** 最近一次 SSE 全量拉取完成时间 */
94
94
  _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
95
- /** 最近一次 preload 完成时间(含 IndexDB 命中) */
95
+ /** 最近一次 preload 完成时间(含 IndexDB 命中,仅用于日志) */
96
96
  _defineProperty(_assertThisInitialized(_this), "lastPreloadCompletedAtMs", 0);
97
+ _defineProperty(_assertThisInitialized(_this), "serverFullFetchPromise", void 0);
98
+ _defineProperty(_assertThisInitialized(_this), "silentRefreshPromise", void 0);
97
99
  /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
98
100
  _defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
99
101
  /** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
@@ -1585,13 +1587,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1585
1587
  value: (function () {
1586
1588
  var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1587
1589
  var options,
1588
- trigger,
1589
- t0,
1590
- tSSE,
1591
- productList,
1592
- list,
1593
- duration,
1594
- errorMessage,
1590
+ fetchPromise,
1595
1591
  _args17 = arguments;
1596
1592
  return _regeneratorRuntime().wrap(function _callee16$(_context17) {
1597
1593
  while (1) switch (_context17.prev = _context17.next) {
@@ -1603,33 +1599,68 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1603
1599
  }
1604
1600
  return _context17.abrupt("return", this.refreshFromReplica(options.trigger || 'loadProductsByServer'));
1605
1601
  case 3:
1602
+ if (!this.serverFullFetchPromise) {
1603
+ _context17.next = 5;
1604
+ break;
1605
+ }
1606
+ return _context17.abrupt("return", this.serverFullFetchPromise);
1607
+ case 5:
1608
+ fetchPromise = this.fetchAndPersistProductsByServer(options.trigger || 'unknown');
1609
+ this.serverFullFetchPromise = fetchPromise;
1610
+ _context17.prev = 7;
1611
+ _context17.next = 10;
1612
+ return fetchPromise;
1613
+ case 10:
1614
+ return _context17.abrupt("return", _context17.sent);
1615
+ case 11:
1616
+ _context17.prev = 11;
1617
+ if (this.serverFullFetchPromise === fetchPromise) this.serverFullFetchPromise = undefined;
1618
+ return _context17.finish(11);
1619
+ case 14:
1620
+ case "end":
1621
+ return _context17.stop();
1622
+ }
1623
+ }, _callee16, this, [[7,, 11, 14]]);
1624
+ }));
1625
+ function loadProductsByServer() {
1626
+ return _loadProductsByServer.apply(this, arguments);
1627
+ }
1628
+ return loadProductsByServer;
1629
+ }())
1630
+ }, {
1631
+ key: "fetchAndPersistProductsByServer",
1632
+ value: function () {
1633
+ var _fetchAndPersistProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(trigger) {
1634
+ var t0, tSSE, productList, list, duration, errorMessage;
1635
+ return _regeneratorRuntime().wrap(function _callee17$(_context18) {
1636
+ while (1) switch (_context18.prev = _context18.next) {
1637
+ case 0:
1606
1638
  if (this.productDataSource) {
1607
- _context17.next = 6;
1639
+ _context18.next = 3;
1608
1640
  break;
1609
1641
  }
1610
1642
  this.logWarning('loadProductsByServer: ProductDataSource 不可用');
1611
- return _context17.abrupt("return", []);
1612
- case 6:
1613
- trigger = options.trigger || 'unknown';
1643
+ return _context18.abrupt("return", []);
1644
+ case 3:
1614
1645
  this.logInfo('开始通过 DataSource SSE 加载商品列表', {
1615
1646
  trigger: trigger
1616
1647
  });
1617
1648
  t0 = performance.now();
1618
- _context17.prev = 9;
1649
+ _context18.prev = 5;
1619
1650
  tSSE = performance.now();
1620
- _context17.next = 13;
1651
+ _context18.next = 9;
1621
1652
  return this.productDataSource.run({
1622
1653
  sse: {}
1623
1654
  });
1624
- case 13:
1625
- productList = _context17.sent;
1655
+ case 9:
1656
+ productList = _context18.sent;
1626
1657
  list = productList || [];
1627
1658
  if (!this.isMemoryReplica()) {
1628
- _context17.next = 17;
1659
+ _context18.next = 13;
1629
1660
  break;
1630
1661
  }
1631
- return _context17.abrupt("return", this.store.list);
1632
- case 17:
1662
+ return _context18.abrupt("return", this.store.list);
1663
+ case 13:
1633
1664
  perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
1634
1665
  count: list.length
1635
1666
  });
@@ -1638,53 +1669,52 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1638
1669
  productCount: list.length,
1639
1670
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1640
1671
  });
1641
- _context17.next = 21;
1672
+ _context18.next = 17;
1642
1673
  return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
1643
- case 21:
1674
+ case 17:
1644
1675
  this.lastServerFullFetchAtMs = Date.now();
1645
- _context17.next = 24;
1676
+ _context18.next = 20;
1646
1677
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
1647
- case 24:
1678
+ case 20:
1648
1679
  perfMark('loadProductsByServer', performance.now() - t0, {
1649
1680
  count: list.length
1650
1681
  });
1651
- return _context17.abrupt("return", list);
1652
- case 28:
1653
- _context17.prev = 28;
1654
- _context17.t0 = _context17["catch"](9);
1682
+ return _context18.abrupt("return", list);
1683
+ case 24:
1684
+ _context18.prev = 24;
1685
+ _context18.t0 = _context18["catch"](5);
1655
1686
  duration = Math.round(performance.now() - t0);
1656
- errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
1657
- console.error('[Products] 加载商品数据失败:', _context17.t0);
1687
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1688
+ console.error('[Products] 加载商品数据失败:', _context18.t0);
1658
1689
  this.logError('通过 DataSource SSE 加载商品列表失败', {
1659
1690
  trigger: trigger,
1660
1691
  duration: "".concat(duration, "ms"),
1661
1692
  error: errorMessage
1662
1693
  });
1663
- return _context17.abrupt("return", []);
1664
- case 35:
1694
+ return _context18.abrupt("return", []);
1695
+ case 31:
1665
1696
  case "end":
1666
- return _context17.stop();
1697
+ return _context18.stop();
1667
1698
  }
1668
- }, _callee16, this, [[9, 28]]);
1699
+ }, _callee17, this, [[5, 24]]);
1669
1700
  }));
1670
- function loadProductsByServer() {
1671
- return _loadProductsByServer.apply(this, arguments);
1701
+ function fetchAndPersistProductsByServer(_x20) {
1702
+ return _fetchAndPersistProductsByServer.apply(this, arguments);
1672
1703
  }
1673
- return loadProductsByServer;
1704
+ return fetchAndPersistProductsByServer;
1674
1705
  }()
1675
1706
  /**
1676
1707
  * 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
1677
1708
  * @param params 查询参数
1678
1709
  * @returns 商品列表
1679
1710
  */
1680
- )
1681
1711
  }, {
1682
1712
  key: "fetchProductsByHttp",
1683
1713
  value: (function () {
1684
- var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1714
+ var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1685
1715
  var _ref16, _ref16$category_ids, category_ids, _ref16$product_ids, product_ids, _ref16$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1686
- return _regeneratorRuntime().wrap(function _callee17$(_context18) {
1687
- while (1) switch (_context18.prev = _context18.next) {
1716
+ return _regeneratorRuntime().wrap(function _callee18$(_context19) {
1717
+ while (1) switch (_context19.prev = _context19.next) {
1688
1718
  case 0:
1689
1719
  _ref16 = params || {}, _ref16$category_ids = _ref16.category_ids, category_ids = _ref16$category_ids === void 0 ? [] : _ref16$category_ids, _ref16$product_ids = _ref16.product_ids, product_ids = _ref16$product_ids === void 0 ? [] : _ref16$product_ids, _ref16$collection = _ref16.collection, collection = _ref16$collection === void 0 ? [] : _ref16$collection, customer_id = _ref16.customer_id, cacheId = _ref16.cacheId;
1690
1720
  this.logInfo('fetchProductsByHttp: 开始请求', {
@@ -1694,8 +1724,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1694
1724
  customer_id: customer_id
1695
1725
  });
1696
1726
  startTime = Date.now();
1697
- _context18.prev = 3;
1698
- _context18.next = 6;
1727
+ _context19.prev = 3;
1728
+ _context19.next = 6;
1699
1729
  return this.request.post("/product/query", {
1700
1730
  open_bundle: 1,
1701
1731
  exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
@@ -1717,32 +1747,32 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1717
1747
  cache: undefined
1718
1748
  });
1719
1749
  case 6:
1720
- productsData = _context18.sent;
1750
+ productsData = _context19.sent;
1721
1751
  productList = (productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || [];
1722
1752
  duration = Date.now() - startTime;
1723
1753
  this.logInfo('fetchProductsByHttp: 请求成功', {
1724
1754
  productCount: productList.length,
1725
1755
  duration: "".concat(duration, "ms")
1726
1756
  });
1727
- return _context18.abrupt("return", productList);
1757
+ return _context19.abrupt("return", productList);
1728
1758
  case 13:
1729
- _context18.prev = 13;
1730
- _context18.t0 = _context18["catch"](3);
1759
+ _context19.prev = 13;
1760
+ _context19.t0 = _context19["catch"](3);
1731
1761
  _duration2 = Date.now() - startTime;
1732
- errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1733
- console.error('[Products] fetchProductsByHttp 失败:', _context18.t0);
1762
+ errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0);
1763
+ console.error('[Products] fetchProductsByHttp 失败:', _context19.t0);
1734
1764
  this.logError('fetchProductsByHttp: 请求失败', {
1735
1765
  duration: "".concat(_duration2, "ms"),
1736
1766
  error: errorMessage
1737
1767
  });
1738
- return _context18.abrupt("return", []);
1768
+ return _context19.abrupt("return", []);
1739
1769
  case 20:
1740
1770
  case "end":
1741
- return _context18.stop();
1771
+ return _context19.stop();
1742
1772
  }
1743
- }, _callee17, this, [[3, 13]]);
1773
+ }, _callee18, this, [[3, 13]]);
1744
1774
  }));
1745
- function fetchProductsByHttp(_x20) {
1775
+ function fetchProductsByHttp(_x21) {
1746
1776
  return _fetchProductsByHttp.apply(this, arguments);
1747
1777
  }
1748
1778
  return fetchProductsByHttp;
@@ -1756,46 +1786,46 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1756
1786
  }, {
1757
1787
  key: "loadProductsByServerHttp",
1758
1788
  value: (function () {
1759
- var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1789
+ var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
1760
1790
  var productList;
1761
- return _regeneratorRuntime().wrap(function _callee18$(_context19) {
1762
- while (1) switch (_context19.prev = _context19.next) {
1791
+ return _regeneratorRuntime().wrap(function _callee19$(_context20) {
1792
+ while (1) switch (_context20.prev = _context20.next) {
1763
1793
  case 0:
1764
1794
  if (!this.isMemoryReplica()) {
1765
- _context19.next = 2;
1795
+ _context20.next = 2;
1766
1796
  break;
1767
1797
  }
1768
- return _context19.abrupt("return", this.refreshFromReplica('loadProductsByServerHttp'));
1798
+ return _context20.abrupt("return", this.refreshFromReplica('loadProductsByServerHttp'));
1769
1799
  case 2:
1770
- _context19.next = 4;
1800
+ _context20.next = 4;
1771
1801
  return this.fetchProductsByHttp(params);
1772
1802
  case 4:
1773
- productList = _context19.sent;
1803
+ productList = _context20.sent;
1774
1804
  if (!this.isMemoryReplica()) {
1775
- _context19.next = 7;
1805
+ _context20.next = 7;
1776
1806
  break;
1777
1807
  }
1778
- return _context19.abrupt("return", this.store.list);
1808
+ return _context20.abrupt("return", this.store.list);
1779
1809
  case 7:
1780
1810
  if (!(productList.length > 0)) {
1781
- _context19.next = 13;
1811
+ _context20.next = 13;
1782
1812
  break;
1783
1813
  }
1784
- _context19.next = 10;
1814
+ _context20.next = 10;
1785
1815
  return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
1786
1816
  case 10:
1787
1817
  this.lastServerFullFetchAtMs = Date.now();
1788
- _context19.next = 13;
1818
+ _context20.next = 13;
1789
1819
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
1790
1820
  case 13:
1791
- return _context19.abrupt("return", productList);
1821
+ return _context20.abrupt("return", productList);
1792
1822
  case 14:
1793
1823
  case "end":
1794
- return _context19.stop();
1824
+ return _context20.stop();
1795
1825
  }
1796
- }, _callee18, this);
1826
+ }, _callee19, this);
1797
1827
  }));
1798
- function loadProductsByServerHttp(_x21) {
1828
+ function loadProductsByServerHttp(_x22) {
1799
1829
  return _loadProductsByServerHttp.apply(this, arguments);
1800
1830
  }
1801
1831
  return loadProductsByServerHttp;
@@ -1807,22 +1837,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1807
1837
  }, {
1808
1838
  key: "getProducts",
1809
1839
  value: (function () {
1810
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1840
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1811
1841
  var t0, result;
1812
- return _regeneratorRuntime().wrap(function _callee19$(_context20) {
1813
- while (1) switch (_context20.prev = _context20.next) {
1842
+ return _regeneratorRuntime().wrap(function _callee20$(_context21) {
1843
+ while (1) switch (_context21.prev = _context21.next) {
1814
1844
  case 0:
1815
1845
  t0 = performance.now();
1816
1846
  result = structuredClone(this.store.list);
1817
1847
  perfMark('ProductsModule.getProducts(structuredClone)', performance.now() - t0, {
1818
1848
  count: result.length
1819
1849
  });
1820
- return _context20.abrupt("return", result);
1850
+ return _context21.abrupt("return", result);
1821
1851
  case 4:
1822
1852
  case "end":
1823
- return _context20.stop();
1853
+ return _context21.stop();
1824
1854
  }
1825
- }, _callee19, this);
1855
+ }, _callee20, this);
1826
1856
  }));
1827
1857
  function getProducts() {
1828
1858
  return _getProducts.apply(this, arguments);
@@ -1836,63 +1866,63 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1836
1866
  }, {
1837
1867
  key: "getProductSnapshotsByIds",
1838
1868
  value: (function () {
1839
- var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(ids) {
1869
+ var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(ids) {
1840
1870
  var snapshots, seen, _iterator9, _step9, _resolveProductHolder, id, product;
1841
- return _regeneratorRuntime().wrap(function _callee20$(_context21) {
1842
- while (1) switch (_context21.prev = _context21.next) {
1871
+ return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1872
+ while (1) switch (_context22.prev = _context22.next) {
1843
1873
  case 0:
1844
1874
  snapshots = {};
1845
1875
  seen = new Set();
1846
1876
  _iterator9 = _createForOfIteratorHelper(ids);
1847
- _context21.prev = 3;
1877
+ _context22.prev = 3;
1848
1878
  _iterator9.s();
1849
1879
  case 5:
1850
1880
  if ((_step9 = _iterator9.n()).done) {
1851
- _context21.next = 16;
1881
+ _context22.next = 16;
1852
1882
  break;
1853
1883
  }
1854
1884
  id = _step9.value;
1855
1885
  if (!(!Number.isFinite(id) || seen.has(id))) {
1856
- _context21.next = 9;
1886
+ _context22.next = 9;
1857
1887
  break;
1858
1888
  }
1859
- return _context21.abrupt("continue", 14);
1889
+ return _context22.abrupt("continue", 14);
1860
1890
  case 9:
1861
1891
  seen.add(id);
1862
1892
  product = this.store.map.get(id);
1863
1893
  if (product) {
1864
- _context21.next = 13;
1894
+ _context22.next = 13;
1865
1895
  break;
1866
1896
  }
1867
- return _context21.abrupt("continue", 14);
1897
+ return _context22.abrupt("continue", 14);
1868
1898
  case 13:
1869
1899
  snapshots[String(id)] = {
1870
1900
  cover: product.cover,
1871
1901
  holder_config: (_resolveProductHolder = resolveProductHolderConfig(product)) !== null && _resolveProductHolder !== void 0 ? _resolveProductHolder : undefined
1872
1902
  };
1873
1903
  case 14:
1874
- _context21.next = 5;
1904
+ _context22.next = 5;
1875
1905
  break;
1876
1906
  case 16:
1877
- _context21.next = 21;
1907
+ _context22.next = 21;
1878
1908
  break;
1879
1909
  case 18:
1880
- _context21.prev = 18;
1881
- _context21.t0 = _context21["catch"](3);
1882
- _iterator9.e(_context21.t0);
1910
+ _context22.prev = 18;
1911
+ _context22.t0 = _context22["catch"](3);
1912
+ _iterator9.e(_context22.t0);
1883
1913
  case 21:
1884
- _context21.prev = 21;
1914
+ _context22.prev = 21;
1885
1915
  _iterator9.f();
1886
- return _context21.finish(21);
1916
+ return _context22.finish(21);
1887
1917
  case 24:
1888
- return _context21.abrupt("return", snapshots);
1918
+ return _context22.abrupt("return", snapshots);
1889
1919
  case 25:
1890
1920
  case "end":
1891
- return _context21.stop();
1921
+ return _context22.stop();
1892
1922
  }
1893
- }, _callee20, this, [[3, 18, 21, 24]]);
1923
+ }, _callee21, this, [[3, 18, 21, 24]]);
1894
1924
  }));
1895
- function getProductSnapshotsByIds(_x22) {
1925
+ function getProductSnapshotsByIds(_x23) {
1896
1926
  return _getProductSnapshotsByIds.apply(this, arguments);
1897
1927
  }
1898
1928
  return getProductSnapshotsByIds;
@@ -1938,20 +1968,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1938
1968
  }, {
1939
1969
  key: "getProductById",
1940
1970
  value: (function () {
1941
- var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(id) {
1971
+ var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(id) {
1942
1972
  var product;
1943
- return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1944
- while (1) switch (_context22.prev = _context22.next) {
1973
+ return _regeneratorRuntime().wrap(function _callee22$(_context23) {
1974
+ while (1) switch (_context23.prev = _context23.next) {
1945
1975
  case 0:
1946
1976
  product = this.store.map.get(id);
1947
- return _context22.abrupt("return", product ? structuredClone(product) : undefined);
1977
+ return _context23.abrupt("return", product ? structuredClone(product) : undefined);
1948
1978
  case 2:
1949
1979
  case "end":
1950
- return _context22.stop();
1980
+ return _context23.stop();
1951
1981
  }
1952
- }, _callee21, this);
1982
+ }, _callee22, this);
1953
1983
  }));
1954
- function getProductById(_x23) {
1984
+ function getProductById(_x24) {
1955
1985
  return _getProductById.apply(this, arguments);
1956
1986
  }
1957
1987
  return getProductById;
@@ -1964,19 +1994,19 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1964
1994
  }, {
1965
1995
  key: "removeProductsByIds",
1966
1996
  value: (function () {
1967
- var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(ids, options) {
1997
+ var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(ids, options) {
1968
1998
  var idSet, _iterator11, _step11, id, _iterator12, _step12, _step12$value, dateKey, cachedProducts;
1969
- return _regeneratorRuntime().wrap(function _callee22$(_context23) {
1970
- while (1) switch (_context23.prev = _context23.next) {
1999
+ return _regeneratorRuntime().wrap(function _callee23$(_context24) {
2000
+ while (1) switch (_context24.prev = _context24.next) {
1971
2001
  case 0:
1972
2002
  if (!(this.isMemoryReplica() && !(options !== null && options !== void 0 && options.skipIndexDB))) {
1973
- _context23.next = 4;
2003
+ _context24.next = 4;
1974
2004
  break;
1975
2005
  }
1976
- _context23.next = 3;
2006
+ _context24.next = 3;
1977
2007
  return this.refreshFromReplica('removeProducts');
1978
2008
  case 3:
1979
- return _context23.abrupt("return");
2009
+ return _context24.abrupt("return");
1980
2010
  case 4:
1981
2011
  idSet = new Set(ids);
1982
2012
  this.logInfo('removeProductsByIds', {
@@ -1998,10 +2028,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1998
2028
  _iterator11.f();
1999
2029
  }
2000
2030
  if (options !== null && options !== void 0 && options.skipIndexDB) {
2001
- _context23.next = 12;
2031
+ _context24.next = 12;
2002
2032
  break;
2003
2033
  }
2004
- _context23.next = 12;
2034
+ _context24.next = 12;
2005
2035
  return this.persistProductDelta([], ids, 'removeProductsByIds');
2006
2036
  case 12:
2007
2037
  _iterator12 = _createForOfIteratorHelper(this.productsPriceCache.entries());
@@ -2023,11 +2053,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2023
2053
  });
2024
2054
  case 16:
2025
2055
  case "end":
2026
- return _context23.stop();
2056
+ return _context24.stop();
2027
2057
  }
2028
- }, _callee22, this);
2058
+ }, _callee23, this);
2029
2059
  }));
2030
- function removeProductsByIds(_x24, _x25) {
2060
+ function removeProductsByIds(_x25, _x26) {
2031
2061
  return _removeProductsByIds.apply(this, arguments);
2032
2062
  }
2033
2063
  return removeProductsByIds;
@@ -2040,25 +2070,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2040
2070
  }, {
2041
2071
  key: "refreshProducts",
2042
2072
  value: (function () {
2043
- var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2073
+ var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2044
2074
  var tTotal, products;
2045
- return _regeneratorRuntime().wrap(function _callee23$(_context24) {
2046
- while (1) switch (_context24.prev = _context24.next) {
2075
+ return _regeneratorRuntime().wrap(function _callee24$(_context25) {
2076
+ while (1) switch (_context25.prev = _context25.next) {
2047
2077
  case 0:
2048
2078
  if (!this.isMemoryReplica()) {
2049
- _context24.next = 2;
2079
+ _context25.next = 2;
2050
2080
  break;
2051
2081
  }
2052
- return _context24.abrupt("return", this.refreshFromReplica('refreshProducts'));
2082
+ return _context25.abrupt("return", this.refreshFromReplica('refreshProducts'));
2053
2083
  case 2:
2054
2084
  tTotal = performance.now();
2055
2085
  this.logInfo('refreshProducts 开始');
2056
- _context24.next = 6;
2086
+ _context25.next = 6;
2057
2087
  return this.loadProductsByServer({
2058
2088
  trigger: 'product_sync'
2059
2089
  });
2060
2090
  case 6:
2061
- products = _context24.sent;
2091
+ products = _context25.sent;
2062
2092
  if (products && products.length > 0) {
2063
2093
  // 服务器返回的数据已经是全新的,无需 cloneDeep
2064
2094
  this.store.list = products;
@@ -2073,12 +2103,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2073
2103
  perfMark('refreshProducts', performance.now() - tTotal, {
2074
2104
  count: this.store.list.length
2075
2105
  });
2076
- return _context24.abrupt("return", this.store.list);
2106
+ return _context25.abrupt("return", this.store.list);
2077
2107
  case 10:
2078
2108
  case "end":
2079
- return _context24.stop();
2109
+ return _context25.stop();
2080
2110
  }
2081
- }, _callee23, this);
2111
+ }, _callee24, this);
2082
2112
  }));
2083
2113
  function refreshProducts() {
2084
2114
  return _refreshProducts.apply(this, arguments);
@@ -2092,10 +2122,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2092
2122
  }, {
2093
2123
  key: "clear",
2094
2124
  value: (function () {
2095
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2125
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2096
2126
  var errorMessage;
2097
- return _regeneratorRuntime().wrap(function _callee24$(_context25) {
2098
- while (1) switch (_context25.prev = _context25.next) {
2127
+ return _regeneratorRuntime().wrap(function _callee25$(_context26) {
2128
+ while (1) switch (_context26.prev = _context26.next) {
2099
2129
  case 0:
2100
2130
  this.logInfo('开始清空缓存', {
2101
2131
  currentProductCount: this.store.list.length,
@@ -2106,21 +2136,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2106
2136
 
2107
2137
  // 同时清空 IndexDB 中的所有数据(包括商品和元数据)
2108
2138
  if (!this.dbManager) {
2109
- _context25.next = 15;
2139
+ _context26.next = 15;
2110
2140
  break;
2111
2141
  }
2112
- _context25.prev = 4;
2113
- _context25.next = 7;
2142
+ _context26.prev = 4;
2143
+ _context26.next = 7;
2114
2144
  return this.dbManager.clear(INDEXDB_STORE_NAME);
2115
2145
  case 7:
2116
2146
  this.logInfo('IndexDB 缓存已清空');
2117
- _context25.next = 15;
2147
+ _context26.next = 15;
2118
2148
  break;
2119
2149
  case 10:
2120
- _context25.prev = 10;
2121
- _context25.t0 = _context25["catch"](4);
2122
- errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
2123
- console.error('[Products] 清空 IndexDB 缓存失败:', _context25.t0);
2150
+ _context26.prev = 10;
2151
+ _context26.t0 = _context26["catch"](4);
2152
+ errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
2153
+ console.error('[Products] 清空 IndexDB 缓存失败:', _context26.t0);
2124
2154
  this.logError('清空 IndexDB 缓存失败', {
2125
2155
  error: errorMessage
2126
2156
  });
@@ -2128,9 +2158,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2128
2158
  this.logInfo('缓存清空完成');
2129
2159
  case 16:
2130
2160
  case "end":
2131
- return _context25.stop();
2161
+ return _context26.stop();
2132
2162
  }
2133
- }, _callee24, this, [[4, 10]]);
2163
+ }, _callee25, this, [[4, 10]]);
2134
2164
  }));
2135
2165
  function clear() {
2136
2166
  return _clear.apply(this, arguments);
@@ -2145,24 +2175,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2145
2175
  }, {
2146
2176
  key: "loadProductsFromIndexDB",
2147
2177
  value: (function () {
2148
- var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2178
+ var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2149
2179
  var startedAt, _products$length, _products$length2, products, durationMs, errorMessage;
2150
- return _regeneratorRuntime().wrap(function _callee25$(_context26) {
2151
- while (1) switch (_context26.prev = _context26.next) {
2180
+ return _regeneratorRuntime().wrap(function _callee26$(_context27) {
2181
+ while (1) switch (_context27.prev = _context27.next) {
2152
2182
  case 0:
2153
2183
  if (this.dbManager) {
2154
- _context26.next = 3;
2184
+ _context27.next = 3;
2155
2185
  break;
2156
2186
  }
2157
2187
  this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
2158
- return _context26.abrupt("return", []);
2188
+ return _context27.abrupt("return", []);
2159
2189
  case 3:
2160
2190
  startedAt = performance.now();
2161
- _context26.prev = 4;
2162
- _context26.next = 7;
2191
+ _context27.prev = 4;
2192
+ _context27.next = 7;
2163
2193
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
2164
2194
  case 7:
2165
- products = _context26.sent;
2195
+ products = _context27.sent;
2166
2196
  durationMs = +(performance.now() - startedAt).toFixed(2);
2167
2197
  perfMark('loadProductsFromIndexDB', durationMs, {
2168
2198
  count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
@@ -2171,22 +2201,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2171
2201
  productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0,
2172
2202
  durationMs: durationMs
2173
2203
  });
2174
- return _context26.abrupt("return", products || []);
2204
+ return _context27.abrupt("return", products || []);
2175
2205
  case 14:
2176
- _context26.prev = 14;
2177
- _context26.t0 = _context26["catch"](4);
2178
- errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
2179
- console.error('[Products] 从 IndexDB 读取数据失败:', _context26.t0);
2206
+ _context27.prev = 14;
2207
+ _context27.t0 = _context27["catch"](4);
2208
+ errorMessage = _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0);
2209
+ console.error('[Products] 从 IndexDB 读取数据失败:', _context27.t0);
2180
2210
  this.logError('从 IndexDB 读取数据失败', {
2181
2211
  durationMs: +(performance.now() - startedAt).toFixed(2),
2182
2212
  error: errorMessage
2183
2213
  });
2184
- return _context26.abrupt("return", []);
2214
+ return _context27.abrupt("return", []);
2185
2215
  case 20:
2186
2216
  case "end":
2187
- return _context26.stop();
2217
+ return _context27.stop();
2188
2218
  }
2189
- }, _callee25, this, [[4, 14]]);
2219
+ }, _callee26, this, [[4, 14]]);
2190
2220
  }));
2191
2221
  function loadProductsFromIndexDB() {
2192
2222
  return _loadProductsFromIndexDB.apply(this, arguments);
@@ -2205,10 +2235,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2205
2235
  }, {
2206
2236
  key: "runInProductIndexDBSaveQueue",
2207
2237
  value: (function () {
2208
- var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(task) {
2238
+ var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(task) {
2209
2239
  var queuedTask;
2210
- return _regeneratorRuntime().wrap(function _callee26$(_context27) {
2211
- while (1) switch (_context27.prev = _context27.next) {
2240
+ return _regeneratorRuntime().wrap(function _callee27$(_context28) {
2241
+ while (1) switch (_context28.prev = _context28.next) {
2212
2242
  case 0:
2213
2243
  queuedTask = this.productIndexDBSaveQueue.then(task, task);
2214
2244
  this.productIndexDBSaveQueue = queuedTask.then(function () {
@@ -2216,14 +2246,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2216
2246
  }, function () {
2217
2247
  return undefined;
2218
2248
  });
2219
- return _context27.abrupt("return", queuedTask);
2249
+ return _context28.abrupt("return", queuedTask);
2220
2250
  case 3:
2221
2251
  case "end":
2222
- return _context27.stop();
2252
+ return _context28.stop();
2223
2253
  }
2224
- }, _callee26, this);
2254
+ }, _callee27, this);
2225
2255
  }));
2226
- function runInProductIndexDBSaveQueue(_x26) {
2256
+ function runInProductIndexDBSaveQueue(_x27) {
2227
2257
  return _runInProductIndexDBSaveQueue.apply(this, arguments);
2228
2258
  }
2229
2259
  return runInProductIndexDBSaveQueue;
@@ -2238,35 +2268,35 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2238
2268
  }, {
2239
2269
  key: "replaceProductsSnapshotInIndexDB",
2240
2270
  value: (function () {
2241
- var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(products, source) {
2271
+ var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(products, source) {
2242
2272
  var _this11 = this;
2243
2273
  var enqueuedAt, queueWaitMs, clearDurationMs, writeDurationMs, errorMessage;
2244
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2245
- while (1) switch (_context29.prev = _context29.next) {
2274
+ return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2275
+ while (1) switch (_context30.prev = _context30.next) {
2246
2276
  case 0:
2247
2277
  if (!this.isMemoryReplica()) {
2248
- _context29.next = 2;
2278
+ _context30.next = 2;
2249
2279
  break;
2250
2280
  }
2251
- return _context29.abrupt("return", false);
2281
+ return _context30.abrupt("return", false);
2252
2282
  case 2:
2253
2283
  if (this.dbManager) {
2254
- _context29.next = 5;
2284
+ _context30.next = 5;
2255
2285
  break;
2256
2286
  }
2257
2287
  this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
2258
- return _context29.abrupt("return", false);
2288
+ return _context30.abrupt("return", false);
2259
2289
  case 5:
2260
2290
  enqueuedAt = performance.now();
2261
2291
  queueWaitMs = 0;
2262
2292
  clearDurationMs = 0;
2263
2293
  writeDurationMs = 0;
2264
- _context29.prev = 9;
2265
- _context29.next = 12;
2266
- return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2294
+ _context30.prev = 9;
2295
+ _context30.next = 12;
2296
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2267
2297
  var operationStartedAt, clearStartedAt, writeStartedAt, executeDurationMs;
2268
- return _regeneratorRuntime().wrap(function _callee27$(_context28) {
2269
- while (1) switch (_context28.prev = _context28.next) {
2298
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2299
+ while (1) switch (_context29.prev = _context29.next) {
2270
2300
  case 0:
2271
2301
  operationStartedAt = performance.now();
2272
2302
  queueWaitMs = +(operationStartedAt - enqueuedAt).toFixed(2);
@@ -2276,28 +2306,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2276
2306
  queueWaitMs: queueWaitMs
2277
2307
  });
2278
2308
  clearStartedAt = performance.now();
2279
- _context28.prev = 4;
2280
- _context28.next = 7;
2309
+ _context29.prev = 4;
2310
+ _context29.next = 7;
2281
2311
  return _this11.dbManager.clear(INDEXDB_STORE_NAME);
2282
2312
  case 7:
2283
- _context28.prev = 7;
2313
+ _context29.prev = 7;
2284
2314
  clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
2285
- return _context28.finish(7);
2315
+ return _context29.finish(7);
2286
2316
  case 10:
2287
2317
  if (!(products.length > 0)) {
2288
- _context28.next = 18;
2318
+ _context29.next = 18;
2289
2319
  break;
2290
2320
  }
2291
2321
  writeStartedAt = performance.now();
2292
- _context28.prev = 12;
2293
- _context28.next = 15;
2322
+ _context29.prev = 12;
2323
+ _context29.next = 15;
2294
2324
  return _this11.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
2295
2325
  case 15:
2296
- _context28.prev = 15;
2326
+ _context29.prev = 15;
2297
2327
  writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
2298
- return _context28.finish(15);
2328
+ return _context29.finish(15);
2299
2329
  case 18:
2300
- _context28.next = 20;
2330
+ _context29.next = 20;
2301
2331
  return _this11.recordProductCommit({
2302
2332
  kind: 'snapshot',
2303
2333
  upserts: products,
@@ -2319,17 +2349,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2319
2349
  });
2320
2350
  case 23:
2321
2351
  case "end":
2322
- return _context28.stop();
2352
+ return _context29.stop();
2323
2353
  }
2324
- }, _callee27, null, [[4,, 7, 10], [12,, 15, 18]]);
2354
+ }, _callee28, null, [[4,, 7, 10], [12,, 15, 18]]);
2325
2355
  })));
2326
2356
  case 12:
2327
- return _context29.abrupt("return", true);
2357
+ return _context30.abrupt("return", true);
2328
2358
  case 15:
2329
- _context29.prev = 15;
2330
- _context29.t0 = _context29["catch"](9);
2359
+ _context30.prev = 15;
2360
+ _context30.t0 = _context30["catch"](9);
2331
2361
  this.productPersistenceFailed = true;
2332
- errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
2362
+ errorMessage = _context30.t0 instanceof Error ? _context30.t0.message : String(_context30.t0);
2333
2363
  this.logError('全量保存商品到 IndexDB 失败', {
2334
2364
  source: source,
2335
2365
  productCount: products.length,
@@ -2339,14 +2369,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2339
2369
  totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2),
2340
2370
  error: errorMessage
2341
2371
  });
2342
- return _context29.abrupt("return", false);
2372
+ return _context30.abrupt("return", false);
2343
2373
  case 21:
2344
2374
  case "end":
2345
- return _context29.stop();
2375
+ return _context30.stop();
2346
2376
  }
2347
- }, _callee28, this, [[9, 15]]);
2377
+ }, _callee29, this, [[9, 15]]);
2348
2378
  }));
2349
- function replaceProductsSnapshotInIndexDB(_x27, _x28) {
2379
+ function replaceProductsSnapshotInIndexDB(_x28, _x29) {
2350
2380
  return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
2351
2381
  }
2352
2382
  return replaceProductsSnapshotInIndexDB;
@@ -2354,21 +2384,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2354
2384
  }, {
2355
2385
  key: "patchProductsInIndexDB",
2356
2386
  value: function () {
2357
- var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(products, source) {
2387
+ var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(products, source) {
2358
2388
  var _mergeActions,
2359
- _args30 = arguments;
2360
- return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2361
- while (1) switch (_context30.prev = _context30.next) {
2389
+ _args31 = arguments;
2390
+ return _regeneratorRuntime().wrap(function _callee30$(_context31) {
2391
+ while (1) switch (_context31.prev = _context31.next) {
2362
2392
  case 0:
2363
- _mergeActions = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : {};
2364
- return _context30.abrupt("return", this.persistProductDelta(products, [], source));
2393
+ _mergeActions = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : {};
2394
+ return _context31.abrupt("return", this.persistProductDelta(products, [], source));
2365
2395
  case 2:
2366
2396
  case "end":
2367
- return _context30.stop();
2397
+ return _context31.stop();
2368
2398
  }
2369
- }, _callee29, this);
2399
+ }, _callee30, this);
2370
2400
  }));
2371
- function patchProductsInIndexDB(_x29, _x30) {
2401
+ function patchProductsInIndexDB(_x30, _x31) {
2372
2402
  return _patchProductsInIndexDB.apply(this, arguments);
2373
2403
  }
2374
2404
  return patchProductsInIndexDB;
@@ -2376,111 +2406,111 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2376
2406
  }, {
2377
2407
  key: "persistProductDelta",
2378
2408
  value: function () {
2379
- var _persistProductDelta = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(products, deletedIds, source) {
2409
+ var _persistProductDelta = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(products, deletedIds, source) {
2380
2410
  var _this12 = this;
2381
2411
  var validProducts, startedAt;
2382
- return _regeneratorRuntime().wrap(function _callee31$(_context32) {
2383
- while (1) switch (_context32.prev = _context32.next) {
2412
+ return _regeneratorRuntime().wrap(function _callee32$(_context33) {
2413
+ while (1) switch (_context33.prev = _context33.next) {
2384
2414
  case 0:
2385
2415
  if (!(this.isMemoryReplica() || !this.dbManager)) {
2386
- _context32.next = 2;
2416
+ _context33.next = 2;
2387
2417
  break;
2388
2418
  }
2389
- return _context32.abrupt("return", false);
2419
+ return _context33.abrupt("return", false);
2390
2420
  case 2:
2391
2421
  validProducts = products.filter(function (p) {
2392
2422
  return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
2393
2423
  });
2394
2424
  if (!(!validProducts.length && !deletedIds.length)) {
2395
- _context32.next = 5;
2425
+ _context33.next = 5;
2396
2426
  break;
2397
2427
  }
2398
- return _context32.abrupt("return", true);
2428
+ return _context33.abrupt("return", true);
2399
2429
  case 5:
2400
2430
  startedAt = performance.now();
2401
- _context32.prev = 6;
2402
- _context32.next = 9;
2403
- return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2431
+ _context33.prev = 6;
2432
+ _context33.next = 9;
2433
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2404
2434
  var _iterator13, _step13, id, _iterator14, _step14, product;
2405
- return _regeneratorRuntime().wrap(function _callee30$(_context31) {
2406
- while (1) switch (_context31.prev = _context31.next) {
2435
+ return _regeneratorRuntime().wrap(function _callee31$(_context32) {
2436
+ while (1) switch (_context32.prev = _context32.next) {
2407
2437
  case 0:
2408
2438
  _iterator13 = _createForOfIteratorHelper(deletedIds);
2409
- _context31.prev = 1;
2439
+ _context32.prev = 1;
2410
2440
  _iterator13.s();
2411
2441
  case 3:
2412
2442
  if ((_step13 = _iterator13.n()).done) {
2413
- _context31.next = 9;
2443
+ _context32.next = 9;
2414
2444
  break;
2415
2445
  }
2416
2446
  id = _step13.value;
2417
- _context31.next = 7;
2447
+ _context32.next = 7;
2418
2448
  return _this12.dbManager.delete(INDEXDB_STORE_NAME, id);
2419
2449
  case 7:
2420
- _context31.next = 3;
2450
+ _context32.next = 3;
2421
2451
  break;
2422
2452
  case 9:
2423
- _context31.next = 14;
2453
+ _context32.next = 14;
2424
2454
  break;
2425
2455
  case 11:
2426
- _context31.prev = 11;
2427
- _context31.t0 = _context31["catch"](1);
2428
- _iterator13.e(_context31.t0);
2456
+ _context32.prev = 11;
2457
+ _context32.t0 = _context32["catch"](1);
2458
+ _iterator13.e(_context32.t0);
2429
2459
  case 14:
2430
- _context31.prev = 14;
2460
+ _context32.prev = 14;
2431
2461
  _iterator13.f();
2432
- return _context31.finish(14);
2462
+ return _context32.finish(14);
2433
2463
  case 17:
2434
2464
  if (!validProducts.length) {
2435
- _context31.next = 44;
2465
+ _context32.next = 44;
2436
2466
  break;
2437
2467
  }
2438
2468
  if (!(typeof _this12.dbManager.bulkUpdate === 'function')) {
2439
- _context31.next = 23;
2469
+ _context32.next = 23;
2440
2470
  break;
2441
2471
  }
2442
- _context31.next = 21;
2472
+ _context32.next = 21;
2443
2473
  return _this12.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
2444
2474
  case 21:
2445
- _context31.next = 44;
2475
+ _context32.next = 44;
2446
2476
  break;
2447
2477
  case 23:
2448
2478
  if (!(typeof _this12.dbManager.update === 'function')) {
2449
- _context31.next = 43;
2479
+ _context32.next = 43;
2450
2480
  break;
2451
2481
  }
2452
2482
  _iterator14 = _createForOfIteratorHelper(validProducts);
2453
- _context31.prev = 25;
2483
+ _context32.prev = 25;
2454
2484
  _iterator14.s();
2455
2485
  case 27:
2456
2486
  if ((_step14 = _iterator14.n()).done) {
2457
- _context31.next = 33;
2487
+ _context32.next = 33;
2458
2488
  break;
2459
2489
  }
2460
2490
  product = _step14.value;
2461
- _context31.next = 31;
2491
+ _context32.next = 31;
2462
2492
  return _this12.dbManager.update(INDEXDB_STORE_NAME, product);
2463
2493
  case 31:
2464
- _context31.next = 27;
2494
+ _context32.next = 27;
2465
2495
  break;
2466
2496
  case 33:
2467
- _context31.next = 38;
2497
+ _context32.next = 38;
2468
2498
  break;
2469
2499
  case 35:
2470
- _context31.prev = 35;
2471
- _context31.t1 = _context31["catch"](25);
2472
- _iterator14.e(_context31.t1);
2500
+ _context32.prev = 35;
2501
+ _context32.t1 = _context32["catch"](25);
2502
+ _iterator14.e(_context32.t1);
2473
2503
  case 38:
2474
- _context31.prev = 38;
2504
+ _context32.prev = 38;
2475
2505
  _iterator14.f();
2476
- return _context31.finish(38);
2506
+ return _context32.finish(38);
2477
2507
  case 41:
2478
- _context31.next = 44;
2508
+ _context32.next = 44;
2479
2509
  break;
2480
2510
  case 43:
2481
2511
  throw new Error('Product persistence adapter has no upsert method');
2482
2512
  case 44:
2483
- _context31.next = 46;
2513
+ _context32.next = 46;
2484
2514
  return _this12.recordProductCommit({
2485
2515
  kind: 'delta',
2486
2516
  upserts: validProducts,
@@ -2495,30 +2525,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2495
2525
  });
2496
2526
  case 47:
2497
2527
  case "end":
2498
- return _context31.stop();
2528
+ return _context32.stop();
2499
2529
  }
2500
- }, _callee30, null, [[1, 11, 14, 17], [25, 35, 38, 41]]);
2530
+ }, _callee31, null, [[1, 11, 14, 17], [25, 35, 38, 41]]);
2501
2531
  })));
2502
2532
  case 9:
2503
- return _context32.abrupt("return", true);
2533
+ return _context33.abrupt("return", true);
2504
2534
  case 12:
2505
- _context32.prev = 12;
2506
- _context32.t0 = _context32["catch"](6);
2535
+ _context33.prev = 12;
2536
+ _context33.t0 = _context33["catch"](6);
2507
2537
  this.productPersistenceFailed = true;
2508
2538
  this.logError('增量保存商品失败', {
2509
2539
  source: source,
2510
2540
  productCount: validProducts.length,
2511
2541
  deletedCount: deletedIds.length,
2512
- error: String(_context32.t0)
2542
+ error: String(_context33.t0)
2513
2543
  });
2514
- return _context32.abrupt("return", false);
2544
+ return _context33.abrupt("return", false);
2515
2545
  case 17:
2516
2546
  case "end":
2517
- return _context32.stop();
2547
+ return _context33.stop();
2518
2548
  }
2519
- }, _callee31, this, [[6, 12]]);
2549
+ }, _callee32, this, [[6, 12]]);
2520
2550
  }));
2521
- function persistProductDelta(_x31, _x32, _x33) {
2551
+ function persistProductDelta(_x32, _x33, _x34) {
2522
2552
  return _persistProductDelta.apply(this, arguments);
2523
2553
  }
2524
2554
  return persistProductDelta;
@@ -2557,34 +2587,44 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2557
2587
  }, {
2558
2588
  key: "preload",
2559
2589
  value: (function () {
2560
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2590
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2561
2591
  var _products$length3;
2562
- var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
2563
- return _regeneratorRuntime().wrap(function _callee32$(_context33) {
2564
- while (1) switch (_context33.prev = _context33.next) {
2592
+ var productsBeforePreload, fullFetchBeforePreload, tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
2593
+ return _regeneratorRuntime().wrap(function _callee33$(_context34) {
2594
+ while (1) switch (_context34.prev = _context34.next) {
2565
2595
  case 0:
2566
2596
  if (!this.isMemoryReplica()) {
2567
- _context33.next = 4;
2597
+ _context34.next = 4;
2568
2598
  break;
2569
2599
  }
2570
- _context33.next = 3;
2600
+ _context34.next = 3;
2571
2601
  return this.refreshFromReplica('preload');
2572
2602
  case 3:
2573
- return _context33.abrupt("return");
2603
+ return _context34.abrupt("return");
2574
2604
  case 4:
2605
+ productsBeforePreload = this.store.list;
2606
+ fullFetchBeforePreload = this.lastServerFullFetchAtMs;
2575
2607
  tTotal = performance.now();
2576
2608
  this.logInfo('开始预加载数据');
2577
- _context33.prev = 6;
2609
+ _context34.prev = 8;
2578
2610
  tIndexDB = performance.now();
2579
- _context33.next = 10;
2611
+ _context34.next = 12;
2580
2612
  return this.loadProductsFromIndexDB();
2581
- case 10:
2582
- cachedData = _context33.sent;
2613
+ case 12:
2614
+ cachedData = _context34.sent;
2583
2615
  perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
2584
2616
  count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
2585
2617
  });
2618
+
2619
+ // PIN 刷新若先完成,不用随后读出的旧缓存覆盖服务器列表。
2620
+ if (!(this.lastServerFullFetchAtMs !== fullFetchBeforePreload && this.store.list !== productsBeforePreload)) {
2621
+ _context34.next = 16;
2622
+ break;
2623
+ }
2624
+ return _context34.abrupt("return");
2625
+ case 16:
2586
2626
  if (!(cachedData && cachedData.length > 0)) {
2587
- _context33.next = 22;
2627
+ _context34.next = 26;
2588
2628
  break;
2589
2629
  }
2590
2630
  // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
@@ -2606,27 +2646,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2606
2646
  source: 'IndexDB'
2607
2647
  });
2608
2648
  this.lastPreloadCompletedAtMs = Date.now();
2609
- return _context33.abrupt("return");
2610
- case 22:
2649
+ return _context34.abrupt("return");
2650
+ case 26:
2611
2651
  this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
2612
- _context33.next = 30;
2652
+ _context34.next = 34;
2613
2653
  break;
2614
- case 25:
2615
- _context33.prev = 25;
2616
- _context33.t0 = _context33["catch"](6);
2617
- errorMessage = _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0);
2618
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context33.t0);
2654
+ case 29:
2655
+ _context34.prev = 29;
2656
+ _context34.t0 = _context34["catch"](8);
2657
+ errorMessage = _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0);
2658
+ console.warn('[Products] 从 IndexDB 加载数据失败:', _context34.t0);
2619
2659
  this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
2620
2660
  error: errorMessage
2621
2661
  });
2622
- case 30:
2662
+ case 34:
2623
2663
  tServer = performance.now();
2624
- _context33.next = 33;
2664
+ _context34.next = 37;
2625
2665
  return this.loadProductsByServer({
2626
2666
  trigger: 'preload'
2627
2667
  });
2628
- case 33:
2629
- products = _context33.sent;
2668
+ case 37:
2669
+ products = _context34.sent;
2630
2670
  perfMark('preload.loadFromServer', performance.now() - tServer, {
2631
2671
  count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
2632
2672
  });
@@ -2658,11 +2698,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2658
2698
  duration: "".concat(Math.round(performance.now() - tTotal), "ms")
2659
2699
  });
2660
2700
  }
2661
- case 36:
2701
+ case 40:
2662
2702
  case "end":
2663
- return _context33.stop();
2703
+ return _context34.stop();
2664
2704
  }
2665
- }, _callee32, this, [[6, 25]]);
2705
+ }, _callee33, this, [[8, 29]]);
2666
2706
  }));
2667
2707
  function preload() {
2668
2708
  return _preload.apply(this, arguments);
@@ -2781,24 +2821,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2781
2821
  }, {
2782
2822
  key: "processProductSyncBatch",
2783
2823
  value: function () {
2784
- var _processProductSyncBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2824
+ var _processProductSyncBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2785
2825
  var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator16, _step16, msg, channelKey, _msg$relation_product, _msg$body, _msg$change_types, _msg$ids2, _msg$ids, ids, _iterator20, _step20, id, _iterator21, _step21, _id, _ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, storeMutated, bodyResult, _iterator17, _step17, product, freshProducts, mergeResult, _iterator18, _step18, _product, patchProducts, committedUpserts, _iterator19, _step19, _id2, _product2, allChangedIds, hasChanges, errorMessage;
2786
- return _regeneratorRuntime().wrap(function _callee33$(_context34) {
2787
- while (1) switch (_context34.prev = _context34.next) {
2826
+ return _regeneratorRuntime().wrap(function _callee34$(_context35) {
2827
+ while (1) switch (_context35.prev = _context35.next) {
2788
2828
  case 0:
2789
2829
  if (!this.isMemoryReplica()) {
2790
- _context34.next = 2;
2830
+ _context35.next = 2;
2791
2831
  break;
2792
2832
  }
2793
- return _context34.abrupt("return");
2833
+ return _context35.abrupt("return");
2794
2834
  case 2:
2795
2835
  messages = _toConsumableArray(this.pendingSyncMessages);
2796
2836
  this.pendingSyncMessages = [];
2797
2837
  if (!(messages.length === 0)) {
2798
- _context34.next = 6;
2838
+ _context35.next = 6;
2799
2839
  break;
2800
2840
  }
2801
- return _context34.abrupt("return");
2841
+ return _context35.abrupt("return");
2802
2842
  case 6:
2803
2843
  this.logInfo('processProductSyncMessages: 开始处理', {
2804
2844
  count: messages.length
@@ -2809,17 +2849,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2809
2849
  priceRefreshIds = [];
2810
2850
  shouldClearPriceCache = false;
2811
2851
  _iterator16 = _createForOfIteratorHelper(messages);
2812
- _context34.prev = 13;
2852
+ _context35.prev = 13;
2813
2853
  _iterator16.s();
2814
2854
  case 15:
2815
2855
  if ((_step16 = _iterator16.n()).done) {
2816
- _context34.next = 43;
2856
+ _context35.next = 43;
2817
2857
  break;
2818
2858
  }
2819
2859
  msg = _step16.value;
2820
2860
  channelKey = msg._channelKey || msg.module || 'product';
2821
2861
  if (!(channelKey === 'product')) {
2822
- _context34.next = 40;
2862
+ _context35.next = 40;
2823
2863
  break;
2824
2864
  }
2825
2865
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
@@ -2827,7 +2867,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2827
2867
  }
2828
2868
  // 1. 删除场景:operation === 'delete' 或 action === 'delete'
2829
2869
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
2830
- _context34.next = 25;
2870
+ _context35.next = 25;
2831
2871
  break;
2832
2872
  }
2833
2873
  ids = (_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length ? msg.ids : msg.id ? [msg.id] : [];
@@ -2843,7 +2883,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2843
2883
  } finally {
2844
2884
  _iterator20.f();
2845
2885
  }
2846
- return _context34.abrupt("continue", 41);
2886
+ return _context35.abrupt("continue", 41);
2847
2887
  case 25:
2848
2888
  // The last explicit product operation wins within the existing sync batch.
2849
2889
  _iterator21 = _createForOfIteratorHelper(msg.ids || (msg.id ? [msg.id] : []));
@@ -2861,7 +2901,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2861
2901
 
2862
2902
  // 2. change_types 包含 price → 仅收集需要刷新价格的 IDs(不走 SSE 拉取)
2863
2903
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
2864
- _context34.next = 33;
2904
+ _context35.next = 33;
2865
2905
  break;
2866
2906
  }
2867
2907
  _ids = msg.ids || (msg.id ? [msg.id] : []);
@@ -2870,15 +2910,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2870
2910
  bodyId = msg.body.id;
2871
2911
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
2872
2912
  }
2873
- return _context34.abrupt("continue", 41);
2913
+ return _context35.abrupt("continue", 41);
2874
2914
  case 33:
2875
2915
  if (!msg.body) {
2876
- _context34.next = 37;
2916
+ _context35.next = 37;
2877
2917
  break;
2878
2918
  }
2879
2919
  _bodyId = msg.body.id || msg.id;
2880
2920
  if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
2881
- return _context34.abrupt("continue", 41);
2921
+ return _context35.abrupt("continue", 41);
2882
2922
  case 37:
2883
2923
  // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
2884
2924
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
@@ -2886,7 +2926,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2886
2926
  } else if (msg.id) {
2887
2927
  sseRefreshIds.push(msg.id);
2888
2928
  }
2889
- _context34.next = 41;
2929
+ _context35.next = 41;
2890
2930
  break;
2891
2931
  case 40:
2892
2932
  if (channelKey === 'product_quotation') {
@@ -2905,19 +2945,19 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2905
2945
  }
2906
2946
  }
2907
2947
  case 41:
2908
- _context34.next = 15;
2948
+ _context35.next = 15;
2909
2949
  break;
2910
2950
  case 43:
2911
- _context34.next = 48;
2951
+ _context35.next = 48;
2912
2952
  break;
2913
2953
  case 45:
2914
- _context34.prev = 45;
2915
- _context34.t0 = _context34["catch"](13);
2916
- _iterator16.e(_context34.t0);
2954
+ _context35.prev = 45;
2955
+ _context35.t0 = _context35["catch"](13);
2956
+ _iterator16.e(_context35.t0);
2917
2957
  case 48:
2918
- _context34.prev = 48;
2958
+ _context35.prev = 48;
2919
2959
  _iterator16.f();
2920
- return _context34.finish(48);
2960
+ return _context35.finish(48);
2921
2961
  case 51:
2922
2962
  uniqueDeleteIds = _toConsumableArray(deleteIds);
2923
2963
  uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds)).filter(function (id) {
@@ -2927,10 +2967,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2927
2967
  return !deleteIds.has(id);
2928
2968
  }); // 1. 处理删除
2929
2969
  if (!(uniqueDeleteIds.length > 0)) {
2930
- _context34.next = 57;
2970
+ _context35.next = 57;
2931
2971
  break;
2932
2972
  }
2933
- _context34.next = 57;
2973
+ _context35.next = 57;
2934
2974
  return this.removeProductsByIds(uniqueDeleteIds, {
2935
2975
  skipIndexDB: true,
2936
2976
  skipEmit: true
@@ -2940,16 +2980,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2940
2980
  patchProductMap = new Map();
2941
2981
  storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
2942
2982
  if (!(bodyUpdates.size > 0)) {
2943
- _context34.next = 66;
2983
+ _context35.next = 66;
2944
2984
  break;
2945
2985
  }
2946
- _context34.next = 62;
2986
+ _context35.next = 62;
2947
2987
  return this.applyBodyUpdatesToStore(bodyUpdates, {
2948
2988
  skipIndexDB: true,
2949
2989
  skipEmit: true
2950
2990
  });
2951
2991
  case 62:
2952
- bodyResult = _context34.sent;
2992
+ bodyResult = _context35.sent;
2953
2993
  _iterator17 = _createForOfIteratorHelper(bodyResult.changedProducts);
2954
2994
  try {
2955
2995
  for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
@@ -2966,24 +3006,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2966
3006
  // 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
2967
3007
  freshProducts = [];
2968
3008
  if (!(uniqueSSEIds.length > 0)) {
2969
- _context34.next = 79;
3009
+ _context35.next = 79;
2970
3010
  break;
2971
3011
  }
2972
- _context34.next = 70;
3012
+ _context35.next = 70;
2973
3013
  return this.fetchProductsBySSE(uniqueSSEIds);
2974
3014
  case 70:
2975
- freshProducts = _context34.sent;
3015
+ freshProducts = _context35.sent;
2976
3016
  if (!(freshProducts.length > 0)) {
2977
- _context34.next = 78;
3017
+ _context35.next = 78;
2978
3018
  break;
2979
3019
  }
2980
- _context34.next = 74;
3020
+ _context35.next = 74;
2981
3021
  return this.mergeProductsToStore(freshProducts, {
2982
3022
  skipIndexDB: true,
2983
3023
  skipEmit: true
2984
3024
  });
2985
3025
  case 74:
2986
- mergeResult = _context34.sent;
3026
+ mergeResult = _context35.sent;
2987
3027
  _iterator18 = _createForOfIteratorHelper(mergeResult.changedProducts);
2988
3028
  try {
2989
3029
  for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
@@ -3019,10 +3059,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3019
3059
  _iterator19.f();
3020
3060
  }
3021
3061
  if (!(committedUpserts.size || uniqueDeleteIds.length)) {
3022
- _context34.next = 86;
3062
+ _context35.next = 86;
3023
3063
  break;
3024
3064
  }
3025
- _context34.next = 86;
3065
+ _context35.next = 86;
3026
3066
  return this.persistProductDelta(_toConsumableArray(committedUpserts.values()), uniqueDeleteIds, 'pubsub.batch');
3027
3067
  case 86:
3028
3068
  if (storeMutated) {
@@ -3041,41 +3081,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3041
3081
  });
3042
3082
  hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
3043
3083
  if (hasChanges) {
3044
- _context34.next = 93;
3084
+ _context35.next = 93;
3045
3085
  break;
3046
3086
  }
3047
3087
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
3048
- return _context34.abrupt("return");
3088
+ return _context35.abrupt("return");
3049
3089
  case 93:
3050
3090
  if (!shouldClearPriceCache) {
3051
- _context34.next = 104;
3091
+ _context35.next = 104;
3052
3092
  break;
3053
3093
  }
3054
- _context34.prev = 94;
3055
- _context34.next = 97;
3094
+ _context35.prev = 94;
3095
+ _context35.next = 97;
3056
3096
  return this.refreshQuotationPriceBridge();
3057
3097
  case 97:
3058
- _context34.next = 103;
3098
+ _context35.next = 103;
3059
3099
  break;
3060
3100
  case 99:
3061
- _context34.prev = 99;
3062
- _context34.t1 = _context34["catch"](94);
3063
- errorMessage = _context34.t1 instanceof Error ? _context34.t1.message : String(_context34.t1);
3101
+ _context35.prev = 99;
3102
+ _context35.t1 = _context35["catch"](94);
3103
+ errorMessage = _context35.t1 instanceof Error ? _context35.t1.message : String(_context35.t1);
3064
3104
  this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
3065
3105
  error: errorMessage
3066
3106
  });
3067
3107
  case 103:
3068
3108
  this.clearPriceCache();
3069
3109
  case 104:
3070
- _context34.next = 106;
3110
+ _context35.next = 106;
3071
3111
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
3072
3112
  changedIds: allChangedIds
3073
3113
  });
3074
3114
  case 106:
3075
3115
  case "end":
3076
- return _context34.stop();
3116
+ return _context35.stop();
3077
3117
  }
3078
- }, _callee33, this, [[13, 45, 48, 51], [94, 99]]);
3118
+ }, _callee34, this, [[13, 45, 48, 51], [94, 99]]);
3079
3119
  }));
3080
3120
  function processProductSyncBatch() {
3081
3121
  return _processProductSyncBatch.apply(this, arguments);
@@ -3089,25 +3129,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3089
3129
  }, {
3090
3130
  key: "fetchProductsBySSE",
3091
3131
  value: (function () {
3092
- var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(ids) {
3132
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(ids) {
3093
3133
  var t0, productList, list, errorMessage;
3094
- return _regeneratorRuntime().wrap(function _callee34$(_context35) {
3095
- while (1) switch (_context35.prev = _context35.next) {
3134
+ return _regeneratorRuntime().wrap(function _callee35$(_context36) {
3135
+ while (1) switch (_context36.prev = _context36.next) {
3096
3136
  case 0:
3097
3137
  if (this.productDataSource) {
3098
- _context35.next = 3;
3138
+ _context36.next = 3;
3099
3139
  break;
3100
3140
  }
3101
3141
  this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
3102
- return _context35.abrupt("return", []);
3142
+ return _context36.abrupt("return", []);
3103
3143
  case 3:
3104
3144
  this.logInfo('fetchProductsBySSE: 开始', {
3105
3145
  ids: ids,
3106
3146
  count: ids.length
3107
3147
  });
3108
3148
  t0 = performance.now();
3109
- _context35.prev = 5;
3110
- _context35.next = 8;
3149
+ _context36.prev = 5;
3150
+ _context36.next = 8;
3111
3151
  return this.productDataSource.run({
3112
3152
  sse: {
3113
3153
  query: {
@@ -3117,7 +3157,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3117
3157
  }
3118
3158
  });
3119
3159
  case 8:
3120
- productList = _context35.sent;
3160
+ productList = _context36.sent;
3121
3161
  list = productList || [];
3122
3162
  perfMark('fetchProductsBySSE', performance.now() - t0, {
3123
3163
  count: list.length
@@ -3127,23 +3167,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3127
3167
  receivedCount: list.length,
3128
3168
  duration: "".concat(Math.round(performance.now() - t0), "ms")
3129
3169
  });
3130
- return _context35.abrupt("return", list);
3170
+ return _context36.abrupt("return", list);
3131
3171
  case 15:
3132
- _context35.prev = 15;
3133
- _context35.t0 = _context35["catch"](5);
3134
- errorMessage = _context35.t0 instanceof Error ? _context35.t0.message : String(_context35.t0);
3172
+ _context36.prev = 15;
3173
+ _context36.t0 = _context36["catch"](5);
3174
+ errorMessage = _context36.t0 instanceof Error ? _context36.t0.message : String(_context36.t0);
3135
3175
  this.logError('fetchProductsBySSE: 失败', {
3136
3176
  ids: ids,
3137
3177
  error: errorMessage
3138
3178
  });
3139
- return _context35.abrupt("return", []);
3179
+ return _context36.abrupt("return", []);
3140
3180
  case 20:
3141
3181
  case "end":
3142
- return _context35.stop();
3182
+ return _context36.stop();
3143
3183
  }
3144
- }, _callee34, this, [[5, 15]]);
3184
+ }, _callee35, this, [[5, 15]]);
3145
3185
  }));
3146
- function fetchProductsBySSE(_x34) {
3186
+ function fetchProductsBySSE(_x35) {
3147
3187
  return _fetchProductsBySSE.apply(this, arguments);
3148
3188
  }
3149
3189
  return fetchProductsBySSE;
@@ -3159,10 +3199,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3159
3199
  }, {
3160
3200
  key: "applyBodyUpdatesToStore",
3161
3201
  value: (function () {
3162
- var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(bodyUpdates, options) {
3202
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(bodyUpdates, options) {
3163
3203
  var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator22, _step22, _step22$value, id, body;
3164
- return _regeneratorRuntime().wrap(function _callee35$(_context36) {
3165
- while (1) switch (_context36.prev = _context36.next) {
3204
+ return _regeneratorRuntime().wrap(function _callee36$(_context37) {
3205
+ while (1) switch (_context37.prev = _context37.next) {
3166
3206
  case 0:
3167
3207
  changedProductIds = _toConsumableArray(bodyUpdates.keys());
3168
3208
  this.logInfo('applyBodyUpdatesToStore: 开始', {
@@ -3202,10 +3242,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3202
3242
  }
3203
3243
  this.syncProductsMap();
3204
3244
  if (options !== null && options !== void 0 && options.skipIndexDB) {
3205
- _context36.next = 14;
3245
+ _context37.next = 14;
3206
3246
  break;
3207
3247
  }
3208
- _context36.next = 14;
3248
+ _context37.next = 14;
3209
3249
  return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
3210
3250
  case 14:
3211
3251
  if (!(options !== null && options !== void 0 && options.skipEmit)) {
@@ -3216,7 +3256,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3216
3256
  newCount: newCount,
3217
3257
  totalCount: this.store.list.length
3218
3258
  });
3219
- return _context36.abrupt("return", {
3259
+ return _context37.abrupt("return", {
3220
3260
  changedProducts: changedProducts,
3221
3261
  mergeActions: mergeActions,
3222
3262
  updatedCount: updatedCount,
@@ -3224,11 +3264,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3224
3264
  });
3225
3265
  case 17:
3226
3266
  case "end":
3227
- return _context36.stop();
3267
+ return _context37.stop();
3228
3268
  }
3229
- }, _callee35, this);
3269
+ }, _callee36, this);
3230
3270
  }));
3231
- function applyBodyUpdatesToStore(_x35, _x36) {
3271
+ function applyBodyUpdatesToStore(_x36, _x37) {
3232
3272
  return _applyBodyUpdatesToStore.apply(this, arguments);
3233
3273
  }
3234
3274
  return applyBodyUpdatesToStore;
@@ -3244,10 +3284,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3244
3284
  }, {
3245
3285
  key: "mergeProductsToStore",
3246
3286
  value: (function () {
3247
- var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(freshProducts, options) {
3287
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(freshProducts, options) {
3248
3288
  var freshMap, _iterator23, _step23, p, mergeActions, changedProducts, updatedList, newCount, _iterator24, _step24, _p2, updatedCount, changedProductIds;
3249
- return _regeneratorRuntime().wrap(function _callee36$(_context37) {
3250
- while (1) switch (_context37.prev = _context37.next) {
3289
+ return _regeneratorRuntime().wrap(function _callee37$(_context38) {
3290
+ while (1) switch (_context38.prev = _context38.next) {
3251
3291
  case 0:
3252
3292
  freshMap = new Map();
3253
3293
  _iterator23 = _createForOfIteratorHelper(freshProducts);
@@ -3294,10 +3334,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3294
3334
  this.store.list = updatedList;
3295
3335
  this.syncProductsMap();
3296
3336
  if (options !== null && options !== void 0 && options.skipIndexDB) {
3297
- _context37.next = 16;
3337
+ _context38.next = 16;
3298
3338
  break;
3299
3339
  }
3300
- _context37.next = 16;
3340
+ _context38.next = 16;
3301
3341
  return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
3302
3342
  case 16:
3303
3343
  if (!(options !== null && options !== void 0 && options.skipEmit)) {
@@ -3308,7 +3348,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3308
3348
  newCount: newCount,
3309
3349
  totalCount: this.store.list.length
3310
3350
  });
3311
- return _context37.abrupt("return", {
3351
+ return _context38.abrupt("return", {
3312
3352
  changedProducts: changedProducts,
3313
3353
  mergeActions: mergeActions,
3314
3354
  updatedCount: updatedCount,
@@ -3316,11 +3356,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3316
3356
  });
3317
3357
  case 19:
3318
3358
  case "end":
3319
- return _context37.stop();
3359
+ return _context38.stop();
3320
3360
  }
3321
- }, _callee36, this);
3361
+ }, _callee37, this);
3322
3362
  }));
3323
- function mergeProductsToStore(_x37, _x38) {
3363
+ function mergeProductsToStore(_x38, _x39) {
3324
3364
  return _mergeProductsToStore.apply(this, arguments);
3325
3365
  }
3326
3366
  return mergeProductsToStore;
@@ -3334,33 +3374,39 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3334
3374
  }, {
3335
3375
  key: "silentRefresh",
3336
3376
  value: (function () {
3337
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
3377
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
3338
3378
  var options,
3339
- t0,
3340
- now,
3341
3379
  trigger,
3380
+ now,
3342
3381
  elapsedSincePreloadMs,
3343
3382
  elapsedSinceFullFetchMs,
3344
- products,
3345
- errorMessage,
3346
- _args38 = arguments;
3347
- return _regeneratorRuntime().wrap(function _callee37$(_context38) {
3348
- while (1) switch (_context38.prev = _context38.next) {
3383
+ refreshPromise,
3384
+ _args39 = arguments;
3385
+ return _regeneratorRuntime().wrap(function _callee38$(_context39) {
3386
+ while (1) switch (_context39.prev = _context39.next) {
3349
3387
  case 0:
3350
- options = _args38.length > 0 && _args38[0] !== undefined ? _args38[0] : {};
3388
+ options = _args39.length > 0 && _args39[0] !== undefined ? _args39[0] : {};
3389
+ trigger = options.trigger || 'background';
3351
3390
  if (!this.isMemoryReplica()) {
3352
- _context38.next = 3;
3391
+ _context39.next = 4;
3353
3392
  break;
3354
3393
  }
3355
- return _context38.abrupt("return", this.refreshFromReplica(options.trigger || 'background'));
3356
- case 3:
3357
- t0 = performance.now();
3394
+ return _context39.abrupt("return", this.refreshFromReplica(trigger));
3395
+ case 4:
3396
+ if (!this.silentRefreshPromise) {
3397
+ _context39.next = 7;
3398
+ break;
3399
+ }
3400
+ this.logInfo('silentRefresh 复用进行中的全量刷新', {
3401
+ trigger: trigger
3402
+ });
3403
+ return _context39.abrupt("return", this.silentRefreshPromise);
3404
+ case 7:
3358
3405
  now = Date.now();
3359
- trigger = options.trigger || 'background';
3360
3406
  elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
3361
3407
  elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
3362
- if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
3363
- _context38.next = 11;
3408
+ if (!(!this.serverFullFetchPromise && this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
3409
+ _context39.next = 13;
3364
3410
  break;
3365
3411
  }
3366
3412
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -3371,71 +3417,101 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
3371
3417
  elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
3372
3418
  productCount: this.store.list.length
3373
3419
  });
3374
- return _context38.abrupt("return", this.store.list);
3375
- case 11:
3420
+ return _context39.abrupt("return", this.store.list);
3421
+ case 13:
3376
3422
  this.logInfo('silentRefresh 开始', {
3377
3423
  trigger: trigger,
3378
3424
  elapsedSincePreloadMs: elapsedSincePreloadMs,
3379
3425
  elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
3380
3426
  productCount: this.store.list.length
3381
3427
  });
3382
- _context38.prev = 12;
3383
- _context38.next = 15;
3428
+ refreshPromise = this.runSilentRefresh(trigger);
3429
+ this.silentRefreshPromise = refreshPromise;
3430
+ _context39.prev = 16;
3431
+ _context39.next = 19;
3432
+ return refreshPromise;
3433
+ case 19:
3434
+ return _context39.abrupt("return", _context39.sent);
3435
+ case 20:
3436
+ _context39.prev = 20;
3437
+ if (this.silentRefreshPromise === refreshPromise) this.silentRefreshPromise = undefined;
3438
+ return _context39.finish(20);
3439
+ case 23:
3440
+ case "end":
3441
+ return _context39.stop();
3442
+ }
3443
+ }, _callee38, this, [[16,, 20, 23]]);
3444
+ }));
3445
+ function silentRefresh() {
3446
+ return _silentRefresh.apply(this, arguments);
3447
+ }
3448
+ return silentRefresh;
3449
+ }())
3450
+ }, {
3451
+ key: "runSilentRefresh",
3452
+ value: function () {
3453
+ var _runSilentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(trigger) {
3454
+ var t0, products, errorMessage;
3455
+ return _regeneratorRuntime().wrap(function _callee39$(_context40) {
3456
+ while (1) switch (_context40.prev = _context40.next) {
3457
+ case 0:
3458
+ t0 = performance.now();
3459
+ _context40.prev = 1;
3460
+ _context40.next = 4;
3384
3461
  return this.loadProductsByServer({
3385
3462
  trigger: trigger
3386
3463
  });
3387
- case 15:
3388
- products = _context38.sent;
3464
+ case 4:
3465
+ products = _context40.sent;
3389
3466
  if (!(products && products.length > 0)) {
3390
- _context38.next = 26;
3467
+ _context40.next = 15;
3391
3468
  break;
3392
3469
  }
3393
3470
  this.store.list = products;
3394
3471
  this.syncProductsMap();
3395
3472
  this.clearPriceCache();
3396
3473
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
3397
- _context38.next = 23;
3474
+ _context40.next = 12;
3398
3475
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
3399
- case 23:
3476
+ case 12:
3400
3477
  this.logInfo('silentRefresh 完成', {
3401
3478
  trigger: trigger,
3402
3479
  productCount: products.length,
3403
3480
  duration: "".concat(Math.round(performance.now() - t0), "ms")
3404
3481
  });
3405
- _context38.next = 27;
3482
+ _context40.next = 16;
3406
3483
  break;
3407
- case 26:
3484
+ case 15:
3408
3485
  this.logWarning('silentRefresh: 服务器未返回数据');
3409
- case 27:
3486
+ case 16:
3410
3487
  perfMark('silentRefresh', performance.now() - t0, {
3411
3488
  count: this.store.list.length
3412
3489
  });
3413
- return _context38.abrupt("return", this.store.list);
3414
- case 31:
3415
- _context38.prev = 31;
3416
- _context38.t0 = _context38["catch"](12);
3417
- errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0);
3490
+ return _context40.abrupt("return", this.store.list);
3491
+ case 20:
3492
+ _context40.prev = 20;
3493
+ _context40.t0 = _context40["catch"](1);
3494
+ errorMessage = _context40.t0 instanceof Error ? _context40.t0.message : String(_context40.t0);
3418
3495
  this.logError('silentRefresh 失败', {
3419
3496
  trigger: trigger,
3420
3497
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
3421
3498
  error: errorMessage
3422
3499
  });
3423
- return _context38.abrupt("return", this.store.list);
3424
- case 36:
3500
+ return _context40.abrupt("return", this.store.list);
3501
+ case 25:
3425
3502
  case "end":
3426
- return _context38.stop();
3503
+ return _context40.stop();
3427
3504
  }
3428
- }, _callee37, this, [[12, 31]]);
3505
+ }, _callee39, this, [[1, 20]]);
3429
3506
  }));
3430
- function silentRefresh() {
3431
- return _silentRefresh.apply(this, arguments);
3507
+ function runSilentRefresh(_x40) {
3508
+ return _runSilentRefresh.apply(this, arguments);
3432
3509
  }
3433
- return silentRefresh;
3510
+ return runSilentRefresh;
3434
3511
  }()
3435
3512
  /**
3436
3513
  * 销毁同步资源(取消 pubsub 订阅、清除定时器)
3437
3514
  */
3438
- )
3439
3515
  }, {
3440
3516
  key: "destroyProductSync",
3441
3517
  value: function destroyProductSync() {