@pisell/pisellos 2.2.243 → 2.2.244

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.
Files changed (315) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +2 -3
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/utils.js +4 -7
  4. package/dist/modules/Cart/utils/cartProduct.js +3 -24
  5. package/dist/modules/Cart/utils/changePrice.js +11 -11
  6. package/dist/modules/Customer/index.d.ts +0 -20
  7. package/dist/modules/Customer/index.js +83 -172
  8. package/dist/modules/Customer/types.d.ts +0 -2
  9. package/dist/modules/Discount/index.js +3 -4
  10. package/dist/modules/Discount/types.d.ts +0 -1
  11. package/dist/modules/OpenData/index.d.ts +0 -8
  12. package/dist/modules/OpenData/index.js +17 -37
  13. package/dist/modules/Order/index.d.ts +18 -268
  14. package/dist/modules/Order/index.js +757 -3306
  15. package/dist/modules/Order/types.d.ts +31 -279
  16. package/dist/modules/Order/types.js +0 -38
  17. package/dist/modules/Order/utils.d.ts +5 -147
  18. package/dist/modules/Order/utils.js +103 -746
  19. package/dist/modules/Payment/index.d.ts +13 -10
  20. package/dist/modules/Payment/index.js +837 -467
  21. package/dist/modules/Payment/types.d.ts +0 -2
  22. package/dist/modules/Payment/utils.js +1 -2
  23. package/dist/modules/Payment/walletpass.js +7 -14
  24. package/dist/modules/ProductList/index.d.ts +12 -16
  25. package/dist/modules/ProductList/index.js +59 -133
  26. package/dist/modules/ProductList/types.d.ts +0 -14
  27. package/dist/modules/Quotation/index.d.ts +1 -0
  28. package/dist/modules/Quotation/index.js +22 -25
  29. package/dist/modules/Rules/index.d.ts +0 -4
  30. package/dist/modules/Rules/index.js +69 -93
  31. package/dist/modules/Rules/types.d.ts +0 -1
  32. package/dist/modules/SalesSummary/index.d.ts +25 -8
  33. package/dist/modules/SalesSummary/index.js +35 -86
  34. package/dist/modules/SalesSummary/types.d.ts +1 -4
  35. package/dist/modules/SalesSummary/utils.d.ts +25 -2
  36. package/dist/modules/SalesSummary/utils.js +162 -794
  37. package/dist/modules/Schedule/index.d.ts +0 -7
  38. package/dist/modules/Schedule/index.js +2 -24
  39. package/dist/modules/Summary/index.js +3 -4
  40. package/dist/modules/index.d.ts +0 -2
  41. package/dist/modules/index.js +1 -3
  42. package/dist/plugins/request.d.ts +0 -1
  43. package/dist/server/index.d.ts +1 -204
  44. package/dist/server/index.js +928 -3658
  45. package/dist/server/modules/index.d.ts +0 -2
  46. package/dist/server/modules/index.js +0 -2
  47. package/dist/server/modules/order/index.d.ts +4 -120
  48. package/dist/server/modules/order/index.js +483 -1779
  49. package/dist/server/modules/order/types.d.ts +3 -32
  50. package/dist/server/modules/order/types.js +0 -8
  51. package/dist/server/modules/order/utils/filterBookings.js +3 -26
  52. package/dist/server/modules/order/utils/filterOrders.js +8 -23
  53. package/dist/server/modules/products/index.d.ts +7 -34
  54. package/dist/server/modules/products/index.js +317 -631
  55. package/dist/server/modules/resource/index.d.ts +0 -2
  56. package/dist/server/modules/resource/index.js +3 -29
  57. package/dist/server/modules/schedule/index.d.ts +4 -4
  58. package/dist/server/modules/schedule/index.js +88 -111
  59. package/dist/solution/BaseSales/index.d.ts +9 -131
  60. package/dist/solution/BaseSales/index.js +447 -1944
  61. package/dist/solution/BaseSales/types.d.ts +6 -76
  62. package/dist/solution/BaseSales/types.js +4 -5
  63. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
  64. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -105
  65. package/dist/solution/BaseSales/utils.d.ts +1 -1
  66. package/dist/solution/BaseSales/utils.js +21 -62
  67. package/dist/solution/BookingByStep/index.d.ts +1 -1
  68. package/dist/solution/BookingTicket/index.d.ts +10 -270
  69. package/dist/solution/BookingTicket/index.js +237 -1772
  70. package/dist/solution/BookingTicket/types.d.ts +1 -118
  71. package/dist/solution/BookingTicket/types.js +2 -41
  72. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
  73. package/dist/solution/BookingTicket/utils/bookingStatus.js +0 -70
  74. package/dist/solution/BookingTicket/utils/cartView.d.ts +1 -9
  75. package/dist/solution/BookingTicket/utils/cartView.js +7 -94
  76. package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -5
  77. package/dist/solution/BookingTicket/utils/scan/index.js +8 -20
  78. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  79. package/dist/solution/Checkout/index.d.ts +0 -1
  80. package/dist/solution/Checkout/index.js +9 -10
  81. package/dist/solution/RegisterAndLogin/config.js +10 -2
  82. package/dist/solution/ScanOrder/index.d.ts +3 -9
  83. package/dist/solution/ScanOrder/index.js +134 -241
  84. package/dist/solution/ScanOrder/types.d.ts +5 -9
  85. package/dist/solution/ScanOrder/types.js +3 -2
  86. package/dist/solution/ScanOrder/utils.d.ts +1 -1
  87. package/dist/solution/ScanOrder/utils.js +22 -84
  88. package/dist/solution/VenueBooking/index.d.ts +2 -5
  89. package/dist/solution/VenueBooking/index.js +59 -110
  90. package/dist/solution/VenueBooking/sales-section-4-annotated.json +2 -0
  91. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  92. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  93. package/dist/types/index.d.ts +0 -10
  94. package/lib/model/strategy/adapter/promotion/evaluator.js +1 -2
  95. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  96. package/lib/model/strategy/adapter/walletPass/utils.js +2 -3
  97. package/lib/modules/Cart/utils/cartProduct.js +3 -20
  98. package/lib/modules/Cart/utils/changePrice.js +20 -12
  99. package/lib/modules/Customer/index.d.ts +0 -20
  100. package/lib/modules/Customer/index.js +11 -64
  101. package/lib/modules/Customer/types.d.ts +0 -2
  102. package/lib/modules/Discount/index.js +1 -5
  103. package/lib/modules/Discount/types.d.ts +0 -1
  104. package/lib/modules/OpenData/index.d.ts +0 -8
  105. package/lib/modules/OpenData/index.js +5 -19
  106. package/lib/modules/Order/index.d.ts +18 -268
  107. package/lib/modules/Order/index.js +344 -2149
  108. package/lib/modules/Order/types.d.ts +31 -279
  109. package/lib/modules/Order/types.js +0 -1
  110. package/lib/modules/Order/utils.d.ts +5 -147
  111. package/lib/modules/Order/utils.js +46 -614
  112. package/lib/modules/Payment/index.d.ts +13 -10
  113. package/lib/modules/Payment/index.js +150 -18
  114. package/lib/modules/Payment/types.d.ts +0 -2
  115. package/lib/modules/Payment/utils.js +1 -2
  116. package/lib/modules/Payment/walletpass.js +3 -7
  117. package/lib/modules/ProductList/index.d.ts +12 -16
  118. package/lib/modules/ProductList/index.js +4 -41
  119. package/lib/modules/ProductList/types.d.ts +0 -14
  120. package/lib/modules/Quotation/index.d.ts +1 -0
  121. package/lib/modules/Quotation/index.js +16 -19
  122. package/lib/modules/Rules/index.d.ts +0 -4
  123. package/lib/modules/Rules/index.js +120 -136
  124. package/lib/modules/Rules/types.d.ts +0 -1
  125. package/lib/modules/SalesSummary/index.d.ts +25 -8
  126. package/lib/modules/SalesSummary/index.js +4 -30
  127. package/lib/modules/SalesSummary/types.d.ts +1 -4
  128. package/lib/modules/SalesSummary/utils.d.ts +25 -2
  129. package/lib/modules/SalesSummary/utils.js +91 -645
  130. package/lib/modules/Schedule/index.d.ts +0 -7
  131. package/lib/modules/Schedule/index.js +1 -17
  132. package/lib/modules/Summary/index.js +4 -5
  133. package/lib/modules/index.d.ts +0 -2
  134. package/lib/modules/index.js +1 -5
  135. package/lib/plugins/request.d.ts +0 -1
  136. package/lib/server/index.d.ts +1 -204
  137. package/lib/server/index.js +57 -1888
  138. package/lib/server/modules/index.d.ts +0 -2
  139. package/lib/server/modules/index.js +0 -3
  140. package/lib/server/modules/order/index.d.ts +4 -120
  141. package/lib/server/modules/order/index.js +142 -919
  142. package/lib/server/modules/order/types.d.ts +3 -32
  143. package/lib/server/modules/order/utils/filterBookings.js +5 -24
  144. package/lib/server/modules/order/utils/filterOrders.js +6 -15
  145. package/lib/server/modules/products/index.d.ts +7 -34
  146. package/lib/server/modules/products/index.js +54 -189
  147. package/lib/server/modules/resource/index.d.ts +0 -2
  148. package/lib/server/modules/resource/index.js +3 -27
  149. package/lib/server/modules/schedule/index.d.ts +4 -4
  150. package/lib/server/modules/schedule/index.js +40 -47
  151. package/lib/solution/BaseSales/index.d.ts +9 -131
  152. package/lib/solution/BaseSales/index.js +63 -1106
  153. package/lib/solution/BaseSales/types.d.ts +6 -76
  154. package/lib/solution/BaseSales/types.js +1 -3
  155. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
  156. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +18 -106
  157. package/lib/solution/BaseSales/utils.d.ts +1 -1
  158. package/lib/solution/BaseSales/utils.js +10 -54
  159. package/lib/solution/BookingByStep/index.d.ts +1 -1
  160. package/lib/solution/BookingTicket/index.d.ts +10 -270
  161. package/lib/solution/BookingTicket/index.js +29 -922
  162. package/lib/solution/BookingTicket/types.d.ts +1 -118
  163. package/lib/solution/BookingTicket/types.js +0 -11
  164. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
  165. package/lib/solution/BookingTicket/utils/bookingStatus.js +2 -44
  166. package/lib/solution/BookingTicket/utils/cartView.d.ts +1 -9
  167. package/lib/solution/BookingTicket/utils/cartView.js +6 -61
  168. package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -5
  169. package/lib/solution/BookingTicket/utils/scan/index.js +3 -17
  170. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  171. package/lib/solution/Checkout/index.d.ts +0 -1
  172. package/lib/solution/Checkout/index.js +2 -1
  173. package/lib/solution/RegisterAndLogin/config.js +10 -2
  174. package/lib/solution/ScanOrder/index.d.ts +3 -9
  175. package/lib/solution/ScanOrder/index.js +70 -153
  176. package/lib/solution/ScanOrder/types.d.ts +5 -9
  177. package/lib/solution/ScanOrder/utils.d.ts +1 -1
  178. package/lib/solution/ScanOrder/utils.js +17 -83
  179. package/lib/solution/VenueBooking/index.d.ts +2 -5
  180. package/lib/solution/VenueBooking/index.js +17 -54
  181. package/lib/solution/VenueBooking/sales-section-4-annotated.json +2 -0
  182. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  183. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  184. package/lib/types/index.d.ts +0 -10
  185. package/package.json +1 -1
  186. package/dist/modules/BookingContext/index.d.ts +0 -48
  187. package/dist/modules/BookingContext/index.js +0 -566
  188. package/dist/modules/BookingContext/types.d.ts +0 -102
  189. package/dist/modules/BookingContext/types.js +0 -51
  190. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  191. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -284
  192. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  193. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -145
  194. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
  195. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -218
  196. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  197. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  198. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  199. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  200. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  201. package/dist/modules/BookingContext/utils/index.js +0 -11
  202. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  203. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  204. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
  205. package/dist/modules/BookingContext/utils/orderLineDisplay.js +0 -36
  206. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  207. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  208. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  209. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  210. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  211. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  212. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  213. package/dist/modules/BookingContext/utils/resources.js +0 -486
  214. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  215. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  216. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  217. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  218. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  219. package/dist/modules/Order/utils/manualProductDiscount.js +0 -210
  220. package/dist/modules/SurchargeList/index.d.ts +0 -16
  221. package/dist/modules/SurchargeList/index.js +0 -162
  222. package/dist/modules/SurchargeList/types.d.ts +0 -11
  223. package/dist/modules/SurchargeList/types.js +0 -1
  224. package/dist/server/modules/payment/index.d.ts +0 -28
  225. package/dist/server/modules/payment/index.js +0 -305
  226. package/dist/server/modules/payment/types.d.ts +0 -9
  227. package/dist/server/modules/payment/types.js +0 -1
  228. package/dist/server/test.json +0 -713
  229. package/dist/server/utils/small-ticket.d.ts +0 -71
  230. package/dist/server/utils/small-ticket.js +0 -830
  231. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
  232. package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1438
  233. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  234. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
  235. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
  236. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  237. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
  238. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +0 -95
  239. package/dist/solution/BookingTicket/utils/exampleData.d.ts +0 -123
  240. package/dist/solution/BookingTicket/utils/exampleData.js +0 -183
  241. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
  242. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -438
  243. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
  244. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -399
  245. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
  246. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -56
  247. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
  248. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +0 -150
  249. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
  250. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +0 -78
  251. package/lib/modules/BookingContext/index.d.ts +0 -48
  252. package/lib/modules/BookingContext/index.js +0 -368
  253. package/lib/modules/BookingContext/types.d.ts +0 -102
  254. package/lib/modules/BookingContext/types.js +0 -34
  255. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  256. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -276
  257. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  258. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -151
  259. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
  260. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -201
  261. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  262. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  263. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  264. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  265. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  266. package/lib/modules/BookingContext/utils/index.js +0 -43
  267. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  268. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  269. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
  270. package/lib/modules/BookingContext/utils/orderLineDisplay.js +0 -56
  271. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  272. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  273. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  274. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  275. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  276. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  277. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  278. package/lib/modules/BookingContext/utils/resources.js +0 -377
  279. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  280. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  281. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  282. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  283. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  284. package/lib/modules/Order/utils/manualProductDiscount.js +0 -206
  285. package/lib/modules/SurchargeList/index.d.ts +0 -16
  286. package/lib/modules/SurchargeList/index.js +0 -89
  287. package/lib/modules/SurchargeList/types.d.ts +0 -11
  288. package/lib/modules/SurchargeList/types.js +0 -17
  289. package/lib/server/modules/payment/index.d.ts +0 -28
  290. package/lib/server/modules/payment/index.js +0 -192
  291. package/lib/server/modules/payment/types.d.ts +0 -9
  292. package/lib/server/modules/payment/types.js +0 -17
  293. package/lib/server/test.json +0 -713
  294. package/lib/server/utils/small-ticket.d.ts +0 -71
  295. package/lib/server/utils/small-ticket.js +0 -781
  296. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
  297. package/lib/solution/BaseSales/utils/cartPromotion.js +0 -992
  298. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  299. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
  300. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
  301. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
  302. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
  303. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +0 -125
  304. package/lib/solution/BookingTicket/utils/exampleData.d.ts +0 -123
  305. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  306. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
  307. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -254
  308. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
  309. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -168
  310. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
  311. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -51
  312. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
  313. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +0 -127
  314. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
  315. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +0 -85
@@ -37,10 +37,9 @@ import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProduc
37
37
  * IndexDB 存储名称
38
38
  */
39
39
  var INDEXDB_STORE_NAME = 'products';
40
+
40
41
  /** 商品同步防抖时间(毫秒) */
41
42
  var PRODUCT_SYNC_DEBOUNCE_MS = 10000;
42
- /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
43
- var PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
44
43
 
45
44
  /**
46
45
  * Products 模块 - 用于获取和管理完整的商品详细数据
@@ -74,19 +73,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
74
73
  // 普通层 QuotationModule 桥接器:本地计算报价单价格,替代 /product/query/price
75
74
  _defineProperty(_assertThisInitialized(_this), "quotationPriceBridge", void 0);
76
75
  _defineProperty(_assertThisInitialized(_this), "quotationBridgeChannel", void 0);
77
- _defineProperty(_assertThisInitialized(_this), "quotationBridgeLoadedKey", '');
76
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeCustomerId", void 0);
78
77
  _defineProperty(_assertThisInitialized(_this), "quotationBridgeRefreshPromise", void 0);
79
78
  _defineProperty(_assertThisInitialized(_this), "quotationBridgeRefreshKey", void 0);
80
79
  // ---- 商品数据同步相关 ----
81
80
  _defineProperty(_assertThisInitialized(_this), "productDataSource", void 0);
82
81
  _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
83
82
  _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
84
- /** 最近一次 SSE 全量拉取完成时间 */
85
- _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
86
- /** 最近一次 preload 完成时间(含 IndexDB 命中) */
87
- _defineProperty(_assertThisInitialized(_this), "lastPreloadCompletedAtMs", 0);
88
- /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
89
- _defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
90
83
  return _this;
91
84
  }
92
85
  _createClass(ProductsModule, [{
@@ -284,7 +277,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
284
277
  value: (function () {
285
278
  var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
286
279
  var _this$otherParams;
287
- var channel, quotation, scheduleCache, hasLoadedScheduleList;
280
+ var channel, quotation, _params$scheduleModul, _params$scheduleModul2, scheduleList, scheduleMap;
288
281
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
289
282
  while (1) switch (_context3.prev = _context3.next) {
290
283
  case 0:
@@ -308,32 +301,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
308
301
  this.quotationPriceBridge = quotation;
309
302
  case 10:
310
303
  if (params.scheduleModule) {
311
- scheduleCache = new Map();
312
- hasLoadedScheduleList = false;
304
+ scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
305
+ scheduleMap = new Map(scheduleList.map(function (schedule) {
306
+ return [schedule.id, schedule];
307
+ }));
313
308
  this.quotationPriceBridge.setScheduleResolver(function (id) {
314
- var _params$scheduleModul3, _params$scheduleModul4, _params$scheduleModul5, _params$scheduleModul6;
315
- var scheduleId = String(id);
316
- if (scheduleCache.has(scheduleId)) return scheduleCache.get(scheduleId);
317
- if (!hasLoadedScheduleList) {
318
- var _params$scheduleModul, _params$scheduleModul2;
319
- var scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
320
- var _iterator = _createForOfIteratorHelper(scheduleList),
321
- _step;
322
- try {
323
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
324
- var schedule = _step.value;
325
- scheduleCache.set(String(schedule.id), schedule);
326
- }
327
- } catch (err) {
328
- _iterator.e(err);
329
- } finally {
330
- _iterator.f();
331
- }
332
- hasLoadedScheduleList = true;
333
- }
334
- if (scheduleCache.has(scheduleId)) return scheduleCache.get(scheduleId);
335
- var schedules = ((_params$scheduleModul3 = (_params$scheduleModul4 = params.scheduleModule).getScheduleListByIds) === null || _params$scheduleModul3 === void 0 ? void 0 : _params$scheduleModul3.call(_params$scheduleModul4, [id])) || ((_params$scheduleModul5 = (_params$scheduleModul6 = params.scheduleModule).getScheduleByIds) === null || _params$scheduleModul5 === void 0 ? void 0 : _params$scheduleModul5.call(_params$scheduleModul6, [id])) || [];
336
- if (schedules[0]) scheduleCache.set(scheduleId, schedules[0]);
309
+ var _params$scheduleModul3, _params$scheduleModul4;
310
+ if (scheduleMap.has(id)) return scheduleMap.get(id);
311
+ var schedules = ((_params$scheduleModul3 = (_params$scheduleModul4 = params.scheduleModule).getScheduleByIds) === null || _params$scheduleModul3 === void 0 ? void 0 : _params$scheduleModul3.call(_params$scheduleModul4, [id])) || [];
337
312
  return schedules[0];
338
313
  });
339
314
  }
@@ -361,7 +336,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
361
336
  value: (function () {
362
337
  var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
363
338
  var _this3 = this;
364
- var refreshKey;
339
+ var customerId, refreshKey;
365
340
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
366
341
  while (1) switch (_context4.prev = _context4.next) {
367
342
  case 0:
@@ -371,35 +346,37 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
371
346
  }
372
347
  return _context4.abrupt("return");
373
348
  case 2:
374
- refreshKey = this.getQuotationBridgeScopeKey();
349
+ customerId = params && 'customer_id' in params ? params.customer_id : this.quotationBridgeCustomerId;
350
+ refreshKey = this.getQuotationBridgeScopeKey(customerId);
375
351
  if (!(this.quotationBridgeRefreshPromise && this.quotationBridgeRefreshKey === refreshKey)) {
376
- _context4.next = 7;
352
+ _context4.next = 8;
377
353
  break;
378
354
  }
379
- _context4.next = 6;
355
+ _context4.next = 7;
380
356
  return this.quotationBridgeRefreshPromise;
381
- case 6:
382
- return _context4.abrupt("return");
383
357
  case 7:
358
+ return _context4.abrupt("return");
359
+ case 8:
384
360
  if (!this.quotationBridgeRefreshPromise) {
385
- _context4.next = 10;
361
+ _context4.next = 11;
386
362
  break;
387
363
  }
388
- _context4.next = 10;
364
+ _context4.next = 11;
389
365
  return this.quotationBridgeRefreshPromise;
390
- case 10:
366
+ case 11:
391
367
  this.quotationBridgeRefreshKey = refreshKey;
392
368
  this.quotationBridgeRefreshPromise = this.quotationPriceBridge.loadQuotations({
393
- channel: this.quotationBridgeChannel
369
+ channel: this.quotationBridgeChannel,
370
+ customer_id: customerId
394
371
  }).then(function () {
395
- _this3.quotationBridgeLoadedKey = refreshKey;
372
+ _this3.quotationBridgeCustomerId = customerId;
396
373
  }).finally(function () {
397
374
  _this3.quotationBridgeRefreshPromise = undefined;
398
375
  _this3.quotationBridgeRefreshKey = undefined;
399
376
  });
400
- _context4.next = 14;
377
+ _context4.next = 15;
401
378
  return this.quotationBridgeRefreshPromise;
402
- case 14:
379
+ case 15:
403
380
  case "end":
404
381
  return _context4.stop();
405
382
  }
@@ -437,7 +414,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
437
414
  _context5.next = 7;
438
415
  return this.quotationBridgeRefreshPromise;
439
416
  case 7:
440
- if (!(this.getQuotationBridgeScopeKey() !== this.quotationBridgeLoadedKey)) {
417
+ if (!(this.getQuotationBridgeScopeKey(customerId) !== this.getQuotationBridgeScopeKey(this.quotationBridgeCustomerId))) {
441
418
  _context5.next = 10;
442
419
  break;
443
420
  }
@@ -458,24 +435,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
458
435
  }()
459
436
  }, {
460
437
  key: "getQuotationBridgeScopeKey",
461
- value: function getQuotationBridgeScopeKey() {
462
- return this.quotationBridgeChannel || '';
438
+ value: function getQuotationBridgeScopeKey(customerId) {
439
+ return "".concat(this.quotationBridgeChannel || '', ":").concat(customerId !== null && customerId !== void 0 ? customerId : '');
463
440
  }
464
441
  }, {
465
442
  key: "buildPriceDataFromQuotation",
466
443
  value: function buildPriceDataFromQuotation(product, datetime, customerId) {
467
- var _this$quotationPriceB, _ref2, _ref3;
444
+ var _this$quotationPriceB, _ref2, _product$base_price;
468
445
  var quotedPrice = (_this$quotationPriceB = this.quotationPriceBridge) === null || _this$quotationPriceB === void 0 ? void 0 : _this$quotationPriceB.getPriceForProduct({
469
446
  productId: product.id,
470
447
  datetime: datetime,
471
448
  customer_id: customerId
472
449
  });
473
450
  var productPrice = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.price;
474
- var productBasePrice = (_ref2 = (_ref3 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.base_price) !== null && _ref3 !== void 0 ? _ref3 : product.price) !== null && _ref2 !== void 0 ? _ref2 : 0;
475
451
  return {
476
452
  id: product.id,
477
453
  price: String(productPrice !== null && productPrice !== void 0 ? productPrice : 0),
478
- base_price: String(productBasePrice),
454
+ base_price: String((_ref2 = (_product$base_price = product.base_price) !== null && _product$base_price !== void 0 ? _product$base_price : product.price) !== null && _ref2 !== void 0 ? _ref2 : 0),
479
455
  variant: this.buildVariantPriceData(product, datetime, customerId),
480
456
  bundle_group: this.buildBundleGroupPriceData(product, datetime, customerId)
481
457
  };
@@ -486,15 +462,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
486
462
  var _this4 = this;
487
463
  if (!Array.isArray(product.variant)) return [];
488
464
  return product.variant.map(function (variant) {
489
- var _this4$quotationPrice, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _variant$product_id;
465
+ var _this4$quotationPrice, _ref3, _ref4, _ref5, _ref6, _ref7, _variant$base_price, _variant$product_id;
490
466
  var quotedPrice = (_this4$quotationPrice = _this4.quotationPriceBridge) === null || _this4$quotationPrice === void 0 ? void 0 : _this4$quotationPrice.getPriceForProduct({
491
467
  productId: product.id,
492
468
  variantId: Number(variant.id),
493
469
  datetime: datetime,
494
470
  customer_id: customerId
495
471
  });
496
- var price = (_ref4 = (_ref5 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref5 !== void 0 ? _ref5 : product.price) !== null && _ref4 !== void 0 ? _ref4 : 0;
497
- var basePrice = (_ref6 = (_ref7 = (_ref8 = (_ref9 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.base_price) !== null && _ref9 !== void 0 ? _ref9 : variant.price) !== null && _ref8 !== void 0 ? _ref8 : product.base_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : 0;
472
+ var price = (_ref3 = (_ref4 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref4 !== void 0 ? _ref4 : product.price) !== null && _ref3 !== void 0 ? _ref3 : 0;
473
+ var basePrice = (_ref5 = (_ref6 = (_ref7 = (_variant$base_price = variant.base_price) !== null && _variant$base_price !== void 0 ? _variant$base_price : variant.price) !== null && _ref7 !== void 0 ? _ref7 : product.base_price) !== null && _ref6 !== void 0 ? _ref6 : product.price) !== null && _ref5 !== void 0 ? _ref5 : 0;
498
474
  return {
499
475
  id: Number(variant.id),
500
476
  product_id: Number((_variant$product_id = variant.product_id) !== null && _variant$product_id !== void 0 ? _variant$product_id : product.id),
@@ -512,7 +488,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
512
488
  return {
513
489
  id: Number(group.id),
514
490
  bundle_item: (group.bundle_item || []).map(function (item) {
515
- var _this5$quotationPrice, _ref10, _ref11, _ref12, _item$product_id, _item$group_id;
491
+ var _this5$quotationPrice, _ref8, _ref9, _item$base_price, _item$product_id, _item$group_id;
516
492
  var bundleProductId = Number(item.bundle_product_id);
517
493
  var bundleVariantId = Number(item.bundle_variant_id || 0);
518
494
  var quotedPrice = (_this5$quotationPrice = _this5.quotationPriceBridge) === null || _this5$quotationPrice === void 0 ? void 0 : _this5$quotationPrice.getPriceForProduct({
@@ -521,8 +497,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
521
497
  datetime: datetime,
522
498
  customer_id: customerId
523
499
  });
524
- var price = (_ref10 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0;
525
- var basePrice = (_ref11 = (_ref12 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.base_price) !== null && _ref12 !== void 0 ? _ref12 : item.price) !== null && _ref11 !== void 0 ? _ref11 : 0;
500
+ var price = (_ref8 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref8 !== void 0 ? _ref8 : 0;
501
+ var basePrice = (_ref9 = (_item$base_price = item.base_price) !== null && _item$base_price !== void 0 ? _item$base_price : item.price) !== null && _ref9 !== void 0 ? _ref9 : 0;
526
502
  return {
527
503
  id: Number(item.id),
528
504
  product_id: Number((_item$product_id = item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : product.id),
@@ -555,7 +531,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
555
531
  value: (function () {
556
532
  var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schedule_date, extraContext, options) {
557
533
  var _options$changedIds;
558
- var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator2, _step2, p, _iterator3, _step3, _p, errorMessage, result;
534
+ var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator, _step, p, _iterator2, _step2, _p, errorMessage, result;
559
535
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
560
536
  while (1) switch (_context6.prev = _context6.next) {
561
537
  case 0:
@@ -596,10 +572,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
596
572
  return [p.id, p];
597
573
  }));
598
574
  mergedCache = [];
599
- _iterator2 = _createForOfIteratorHelper(cachedProducts);
575
+ _iterator = _createForOfIteratorHelper(cachedProducts);
600
576
  try {
601
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
602
- p = _step2.value;
577
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
578
+ p = _step.value;
603
579
  if (updatedMap.has(p.id)) {
604
580
  mergedCache.push(updatedMap.get(p.id));
605
581
  updatedMap.delete(p.id);
@@ -609,20 +585,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
609
585
  }
610
586
  // 剩余的是新增商品(create 场景)
611
587
  } catch (err) {
612
- _iterator2.e(err);
588
+ _iterator.e(err);
613
589
  } finally {
614
- _iterator2.f();
590
+ _iterator.f();
615
591
  }
616
- _iterator3 = _createForOfIteratorHelper(updatedMap.values());
592
+ _iterator2 = _createForOfIteratorHelper(updatedMap.values());
617
593
  try {
618
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
619
- _p = _step3.value;
594
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
595
+ _p = _step2.value;
620
596
  mergedCache.push(_p);
621
597
  }
622
598
  } catch (err) {
623
- _iterator3.e(err);
599
+ _iterator2.e(err);
624
600
  } finally {
625
- _iterator3.f();
601
+ _iterator2.f();
626
602
  }
627
603
  this.productsPriceCache.set(cacheKey, mergedCache);
628
604
  this.logInfo('增量更新完成', {
@@ -857,25 +833,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
857
833
  }
858
834
  if (productIds.length === 0 && collectionIds.length === 0) return [];
859
835
  var result = new Set();
860
- var _iterator4 = _createForOfIteratorHelper(productIds),
861
- _step4;
836
+ var _iterator3 = _createForOfIteratorHelper(productIds),
837
+ _step3;
862
838
  try {
863
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
864
- var id = _step4.value;
839
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
840
+ var id = _step3.value;
865
841
  if (this.store.map.has(id)) result.add(id);
866
842
  }
867
843
  } catch (err) {
868
- _iterator4.e(err);
844
+ _iterator3.e(err);
869
845
  } finally {
870
- _iterator4.f();
846
+ _iterator3.f();
871
847
  }
872
848
  if (collectionIds.length === 0) return Array.from(result);
873
849
  var collectionIdSet = new Set(collectionIds);
874
- var _iterator5 = _createForOfIteratorHelper(this.getProductsRef()),
875
- _step5;
850
+ var _iterator4 = _createForOfIteratorHelper(this.getProductsRef()),
851
+ _step4;
876
852
  try {
877
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
878
- var product = _step5.value;
853
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
854
+ var product = _step4.value;
879
855
  if (result.has(product.id)) continue;
880
856
  if (!Array.isArray(product.collection)) continue;
881
857
  var isInCollection = product.collection.some(function (collection) {
@@ -884,9 +860,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
884
860
  if (isInCollection) result.add(product.id);
885
861
  }
886
862
  } catch (err) {
887
- _iterator5.e(err);
863
+ _iterator4.e(err);
888
864
  } finally {
889
- _iterator5.f();
865
+ _iterator4.f();
890
866
  }
891
867
  return Array.from(result);
892
868
  }
@@ -1124,18 +1100,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1124
1100
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1125
1101
  });
1126
1102
  _context9.next = 15;
1127
- return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
1103
+ return this.saveProductsToIndexDB(list);
1128
1104
  case 15:
1129
- this.lastServerFullFetchAtMs = Date.now();
1130
- _context9.next = 18;
1105
+ _context9.next = 17;
1131
1106
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
1132
- case 18:
1107
+ case 17:
1133
1108
  perfMark('loadProductsByServer', performance.now() - t0, {
1134
1109
  count: list.length
1135
1110
  });
1136
1111
  return _context9.abrupt("return", list);
1137
- case 22:
1138
- _context9.prev = 22;
1112
+ case 21:
1113
+ _context9.prev = 21;
1139
1114
  _context9.t0 = _context9["catch"](5);
1140
1115
  duration = Math.round(performance.now() - t0);
1141
1116
  errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
@@ -1145,11 +1120,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1145
1120
  error: errorMessage
1146
1121
  });
1147
1122
  return _context9.abrupt("return", []);
1148
- case 29:
1123
+ case 28:
1149
1124
  case "end":
1150
1125
  return _context9.stop();
1151
1126
  }
1152
- }, _callee9, this, [[5, 22]]);
1127
+ }, _callee9, this, [[5, 21]]);
1153
1128
  }));
1154
1129
  function loadProductsByServer() {
1155
1130
  return _loadProductsByServer.apply(this, arguments);
@@ -1166,11 +1141,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1166
1141
  key: "fetchProductsByHttp",
1167
1142
  value: (function () {
1168
1143
  var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1169
- var _ref13, _ref13$category_ids, category_ids, _ref13$product_ids, product_ids, _ref13$collection, collection, customer_id, cacheId, startTime, _this$otherParams3, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1144
+ var _ref10, _ref10$category_ids, category_ids, _ref10$product_ids, product_ids, _ref10$collection, collection, customer_id, cacheId, startTime, _this$otherParams3, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1170
1145
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1171
1146
  while (1) switch (_context10.prev = _context10.next) {
1172
1147
  case 0:
1173
- _ref13 = params || {}, _ref13$category_ids = _ref13.category_ids, category_ids = _ref13$category_ids === void 0 ? [] : _ref13$category_ids, _ref13$product_ids = _ref13.product_ids, product_ids = _ref13$product_ids === void 0 ? [] : _ref13$product_ids, _ref13$collection = _ref13.collection, collection = _ref13$collection === void 0 ? [] : _ref13$collection, customer_id = _ref13.customer_id, cacheId = _ref13.cacheId;
1148
+ _ref10 = params || {}, _ref10$category_ids = _ref10.category_ids, category_ids = _ref10$category_ids === void 0 ? [] : _ref10$category_ids, _ref10$product_ids = _ref10.product_ids, product_ids = _ref10$product_ids === void 0 ? [] : _ref10$product_ids, _ref10$collection = _ref10.collection, collection = _ref10$collection === void 0 ? [] : _ref10$collection, customer_id = _ref10.customer_id, cacheId = _ref10.cacheId;
1174
1149
  this.logInfo('fetchProductsByHttp: 开始请求', {
1175
1150
  categoryIdsCount: category_ids.length,
1176
1151
  productIdsCount: product_ids.length,
@@ -1250,18 +1225,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1250
1225
  case 2:
1251
1226
  productList = _context11.sent;
1252
1227
  if (!(productList.length > 0)) {
1253
- _context11.next = 9;
1228
+ _context11.next = 8;
1254
1229
  break;
1255
1230
  }
1256
1231
  _context11.next = 6;
1257
- return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
1232
+ return this.saveProductsToIndexDB(productList);
1258
1233
  case 6:
1259
- this.lastServerFullFetchAtMs = Date.now();
1260
- _context11.next = 9;
1234
+ _context11.next = 8;
1261
1235
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
1262
- case 9:
1236
+ case 8:
1263
1237
  return _context11.abrupt("return", productList);
1264
- case 10:
1238
+ case 9:
1265
1239
  case "end":
1266
1240
  return _context11.stop();
1267
1241
  }
@@ -1319,18 +1293,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1319
1293
  key: "getProductsRefByIds",
1320
1294
  value: function getProductsRefByIds(ids) {
1321
1295
  var products = [];
1322
- var _iterator6 = _createForOfIteratorHelper(ids),
1323
- _step6;
1296
+ var _iterator5 = _createForOfIteratorHelper(ids),
1297
+ _step5;
1324
1298
  try {
1325
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1326
- var id = _step6.value;
1299
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1300
+ var id = _step5.value;
1327
1301
  var product = this.store.map.get(id);
1328
1302
  if (product) products.push(product);
1329
1303
  }
1330
1304
  } catch (err) {
1331
- _iterator6.e(err);
1305
+ _iterator5.e(err);
1332
1306
  } finally {
1333
- _iterator6.f();
1307
+ _iterator5.f();
1334
1308
  }
1335
1309
  return products;
1336
1310
  }
@@ -1369,7 +1343,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1369
1343
  key: "removeProductsByIds",
1370
1344
  value: (function () {
1371
1345
  var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(ids) {
1372
- var idSet, _iterator7, _step7, _id, _iterator8, _step8, id, errorMessage, _iterator9, _step9, _step9$value, dateKey, cachedProducts;
1346
+ var idSet, _iterator6, _step6, _id, _iterator7, _step7, id, errorMessage, _iterator8, _step8, _step8$value, dateKey, cachedProducts;
1373
1347
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1374
1348
  while (1) switch (_context14.prev = _context14.next) {
1375
1349
  case 0:
@@ -1381,31 +1355,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1381
1355
  this.store.list = this.store.list.filter(function (p) {
1382
1356
  return !idSet.has(p.id);
1383
1357
  });
1384
- _iterator7 = _createForOfIteratorHelper(ids);
1358
+ _iterator6 = _createForOfIteratorHelper(ids);
1385
1359
  try {
1386
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1387
- _id = _step7.value;
1360
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1361
+ _id = _step6.value;
1388
1362
  this.store.map.delete(_id);
1389
1363
  }
1390
1364
  } catch (err) {
1391
- _iterator7.e(err);
1365
+ _iterator6.e(err);
1392
1366
  } finally {
1393
- _iterator7.f();
1367
+ _iterator6.f();
1394
1368
  }
1395
1369
  if (!this.dbManager) {
1396
1370
  _context14.next = 30;
1397
1371
  break;
1398
1372
  }
1399
1373
  _context14.prev = 6;
1400
- _iterator8 = _createForOfIteratorHelper(ids);
1374
+ _iterator7 = _createForOfIteratorHelper(ids);
1401
1375
  _context14.prev = 8;
1402
- _iterator8.s();
1376
+ _iterator7.s();
1403
1377
  case 10:
1404
- if ((_step8 = _iterator8.n()).done) {
1378
+ if ((_step7 = _iterator7.n()).done) {
1405
1379
  _context14.next = 16;
1406
1380
  break;
1407
1381
  }
1408
- id = _step8.value;
1382
+ id = _step7.value;
1409
1383
  _context14.next = 14;
1410
1384
  return this.dbManager.delete(INDEXDB_STORE_NAME, id);
1411
1385
  case 14:
@@ -1417,10 +1391,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1417
1391
  case 18:
1418
1392
  _context14.prev = 18;
1419
1393
  _context14.t0 = _context14["catch"](8);
1420
- _iterator8.e(_context14.t0);
1394
+ _iterator7.e(_context14.t0);
1421
1395
  case 21:
1422
1396
  _context14.prev = 21;
1423
- _iterator8.f();
1397
+ _iterator7.f();
1424
1398
  return _context14.finish(21);
1425
1399
  case 24:
1426
1400
  _context14.next = 30;
@@ -1434,18 +1408,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1434
1408
  error: errorMessage
1435
1409
  });
1436
1410
  case 30:
1437
- _iterator9 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1411
+ _iterator8 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1438
1412
  try {
1439
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1440
- _step9$value = _slicedToArray(_step9.value, 2), dateKey = _step9$value[0], cachedProducts = _step9$value[1];
1413
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1414
+ _step8$value = _slicedToArray(_step8.value, 2), dateKey = _step8$value[0], cachedProducts = _step8$value[1];
1441
1415
  this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
1442
1416
  return !idSet.has(p.id);
1443
1417
  }));
1444
1418
  }
1445
1419
  } catch (err) {
1446
- _iterator9.e(err);
1420
+ _iterator8.e(err);
1447
1421
  } finally {
1448
- _iterator9.f();
1422
+ _iterator8.f();
1449
1423
  }
1450
1424
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1451
1425
  this.logInfo('removeProductsByIds 完成', {
@@ -1615,243 +1589,64 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1615
1589
  return loadProductsFromIndexDB;
1616
1590
  }()
1617
1591
  /**
1618
- * 串行执行商品 IndexDB 写入,避免快照替换与增量 patch 并发交错。
1619
- *
1620
- * @example
1621
- * await this.runInProductIndexDBSaveQueue(async () => {
1622
- * await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products)
1623
- * })
1592
+ * 保存商品数据到 IndexDB(平铺存储)
1593
+ * @private
1624
1594
  */
1625
1595
  )
1626
1596
  }, {
1627
- key: "runInProductIndexDBSaveQueue",
1597
+ key: "saveProductsToIndexDB",
1628
1598
  value: (function () {
1629
- var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(task) {
1630
- var queuedTask;
1599
+ var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(products) {
1600
+ var t0, errorMessage;
1631
1601
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1632
1602
  while (1) switch (_context18.prev = _context18.next) {
1633
- case 0:
1634
- queuedTask = this.productIndexDBSaveQueue.then(task, task);
1635
- this.productIndexDBSaveQueue = queuedTask.then(function () {
1636
- return undefined;
1637
- }, function () {
1638
- return undefined;
1639
- });
1640
- return _context18.abrupt("return", queuedTask);
1641
- case 3:
1642
- case "end":
1643
- return _context18.stop();
1644
- }
1645
- }, _callee18, this);
1646
- }));
1647
- function runInProductIndexDBSaveQueue(_x19) {
1648
- return _runInProductIndexDBSaveQueue.apply(this, arguments);
1649
- }
1650
- return runInProductIndexDBSaveQueue;
1651
- }()
1652
- /**
1653
- * 全量快照写入 IndexDB:clear + bulkUpdate,仅用于 SSE/HTTP 全量拉取。
1654
- *
1655
- * @example
1656
- * await this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer')
1657
- */
1658
- )
1659
- }, {
1660
- key: "replaceProductsSnapshotInIndexDB",
1661
- value: (function () {
1662
- var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(products, source) {
1663
- var _this6 = this;
1664
- var errorMessage;
1665
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1666
- while (1) switch (_context20.prev = _context20.next) {
1667
1603
  case 0:
1668
1604
  if (this.dbManager) {
1669
- _context20.next = 3;
1605
+ _context18.next = 3;
1670
1606
  break;
1671
1607
  }
1672
- this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
1673
- return _context20.abrupt("return");
1608
+ this.logWarning('saveProductsToIndexDB: dbManager 不可用');
1609
+ return _context18.abrupt("return");
1674
1610
  case 3:
1675
- _context20.prev = 3;
1676
- _context20.next = 6;
1677
- return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1678
- var t0;
1679
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1680
- while (1) switch (_context19.prev = _context19.next) {
1681
- case 0:
1682
- _this6.logInfo('replaceProductsSnapshotInIndexDB 开始', {
1683
- source: source,
1684
- productCount: products.length
1685
- });
1686
- t0 = performance.now();
1687
- _context19.next = 4;
1688
- return _this6.dbManager.clear(INDEXDB_STORE_NAME);
1689
- case 4:
1690
- if (!(products.length > 0)) {
1691
- _context19.next = 7;
1692
- break;
1693
- }
1694
- _context19.next = 7;
1695
- return _this6.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1696
- case 7:
1697
- perfMark('replaceProductsSnapshotInIndexDB', performance.now() - t0, {
1698
- count: products.length
1699
- });
1700
- _this6.logInfo('replaceProductsSnapshotInIndexDB 完成', {
1701
- source: source,
1702
- productCount: products.length
1703
- });
1704
- case 9:
1705
- case "end":
1706
- return _context19.stop();
1707
- }
1708
- }, _callee19);
1709
- })));
1710
- case 6:
1711
- _context20.next = 12;
1712
- break;
1611
+ this.logInfo('开始保存商品数据到 IndexDB', {
1612
+ productCount: products.length
1613
+ });
1614
+ _context18.prev = 4;
1615
+ t0 = performance.now();
1616
+ _context18.next = 8;
1617
+ return this.dbManager.clear(INDEXDB_STORE_NAME);
1713
1618
  case 8:
1714
- _context20.prev = 8;
1715
- _context20.t0 = _context20["catch"](3);
1716
- errorMessage = _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0);
1717
- this.logError('全量保存商品到 IndexDB 失败', {
1718
- source: source,
1719
- productCount: products.length,
1720
- error: errorMessage
1619
+ _context18.next = 10;
1620
+ return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1621
+ case 10:
1622
+ perfMark('saveProductsToIndexDB', performance.now() - t0, {
1623
+ count: products.length
1721
1624
  });
1722
- case 12:
1723
- case "end":
1724
- return _context20.stop();
1725
- }
1726
- }, _callee20, this, [[3, 8]]);
1727
- }));
1728
- function replaceProductsSnapshotInIndexDB(_x20, _x21) {
1729
- return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
1730
- }
1731
- return replaceProductsSnapshotInIndexDB;
1732
- }()
1733
- /**
1734
- * 增量 upsert 商品到 IndexDB,不清空表;用于 pubsub 批次合并后的变更商品。
1735
- *
1736
- * @example
1737
- * await this.patchProductsInIndexDB(changedProducts, 'pubsub.processProductSyncMessages', mergeActions)
1738
- */
1739
- )
1740
- }, {
1741
- key: "patchProductsInIndexDB",
1742
- value: (function () {
1743
- var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(products, source) {
1744
- var _this7 = this;
1745
- var mergeActions,
1746
- validProducts,
1747
- errorMessage,
1748
- _args22 = arguments;
1749
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1750
- while (1) switch (_context22.prev = _context22.next) {
1751
- case 0:
1752
- mergeActions = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
1753
- if (!(!this.dbManager || products.length === 0)) {
1754
- _context22.next = 3;
1755
- break;
1756
- }
1757
- return _context22.abrupt("return");
1758
- case 3:
1759
- validProducts = products.filter(function (p) {
1760
- return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
1625
+ console.log("[Products] \u5DF2\u5C06 ".concat(products.length, " \u4E2A\u5546\u54C1\u5E73\u94FA\u4FDD\u5B58\u5230 IndexDB"));
1626
+ this.logInfo('商品数据已保存到 IndexDB', {
1627
+ productCount: products.length
1761
1628
  });
1762
- if (!(validProducts.length === 0)) {
1763
- _context22.next = 6;
1764
- break;
1765
- }
1766
- return _context22.abrupt("return");
1767
- case 6:
1768
- _context22.prev = 6;
1769
- _context22.next = 9;
1770
- return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1771
- var t0, _iterator10, _step10, product;
1772
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1773
- while (1) switch (_context21.prev = _context21.next) {
1774
- case 0:
1775
- _this7.logInfo('patchProductsInIndexDB 开始', {
1776
- source: source,
1777
- count: validProducts.length
1778
- });
1779
- t0 = performance.now();
1780
- if (!(typeof _this7.dbManager.bulkUpdate === 'function')) {
1781
- _context21.next = 7;
1782
- break;
1783
- }
1784
- _context21.next = 5;
1785
- return _this7.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
1786
- case 5:
1787
- _context21.next = 25;
1788
- break;
1789
- case 7:
1790
- if (!(typeof _this7.dbManager.update === 'function')) {
1791
- _context21.next = 25;
1792
- break;
1793
- }
1794
- _iterator10 = _createForOfIteratorHelper(validProducts);
1795
- _context21.prev = 9;
1796
- _iterator10.s();
1797
- case 11:
1798
- if ((_step10 = _iterator10.n()).done) {
1799
- _context21.next = 17;
1800
- break;
1801
- }
1802
- product = _step10.value;
1803
- _context21.next = 15;
1804
- return _this7.dbManager.update(INDEXDB_STORE_NAME, product);
1805
- case 15:
1806
- _context21.next = 11;
1807
- break;
1808
- case 17:
1809
- _context21.next = 22;
1810
- break;
1811
- case 19:
1812
- _context21.prev = 19;
1813
- _context21.t0 = _context21["catch"](9);
1814
- _iterator10.e(_context21.t0);
1815
- case 22:
1816
- _context21.prev = 22;
1817
- _iterator10.f();
1818
- return _context21.finish(22);
1819
- case 25:
1820
- perfMark('patchProductsInIndexDB', performance.now() - t0, {
1821
- count: validProducts.length
1822
- });
1823
- _this7.logInfo('patchProductsInIndexDB 完成', {
1824
- source: source,
1825
- count: validProducts.length
1826
- });
1827
- case 27:
1828
- case "end":
1829
- return _context21.stop();
1830
- }
1831
- }, _callee21, null, [[9, 19, 22, 25]]);
1832
- })));
1833
- case 9:
1834
- _context22.next = 15;
1629
+ _context18.next = 20;
1835
1630
  break;
1836
- case 11:
1837
- _context22.prev = 11;
1838
- _context22.t0 = _context22["catch"](6);
1839
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1840
- this.logError('增量保存商品到 IndexDB 失败', {
1841
- source: source,
1842
- error: errorMessage,
1843
- productCount: validProducts.length
1844
- });
1845
1631
  case 15:
1632
+ _context18.prev = 15;
1633
+ _context18.t0 = _context18["catch"](4);
1634
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1635
+ console.error('[Products] 保存数据到 IndexDB 失败:', _context18.t0);
1636
+ this.logError('保存数据到 IndexDB 失败', {
1637
+ productCount: products.length,
1638
+ error: errorMessage
1639
+ });
1640
+ case 20:
1846
1641
  case "end":
1847
- return _context22.stop();
1642
+ return _context18.stop();
1848
1643
  }
1849
- }, _callee22, this, [[6, 11]]);
1644
+ }, _callee18, this, [[4, 15]]);
1850
1645
  }));
1851
- function patchProductsInIndexDB(_x22, _x23) {
1852
- return _patchProductsInIndexDB.apply(this, arguments);
1646
+ function saveProductsToIndexDB(_x19) {
1647
+ return _saveProductsToIndexDB.apply(this, arguments);
1853
1648
  }
1854
- return patchProductsInIndexDB;
1649
+ return saveProductsToIndexDB;
1855
1650
  }()
1856
1651
  /**
1857
1652
  * 同步更新商品 Map 缓存
@@ -1864,17 +1659,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1864
1659
  value: function syncProductsMap() {
1865
1660
  var t0 = performance.now();
1866
1661
  this.store.map.clear();
1867
- var _iterator11 = _createForOfIteratorHelper(this.store.list),
1868
- _step11;
1662
+ var _iterator9 = _createForOfIteratorHelper(this.store.list),
1663
+ _step9;
1869
1664
  try {
1870
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1871
- var product = _step11.value;
1665
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1666
+ var product = _step9.value;
1872
1667
  this.store.map.set(product.id, product);
1873
1668
  }
1874
1669
  } catch (err) {
1875
- _iterator11.e(err);
1670
+ _iterator9.e(err);
1876
1671
  } finally {
1877
- _iterator11.f();
1672
+ _iterator9.f();
1878
1673
  }
1879
1674
  perfMark('syncProductsMap', performance.now() - t0, {
1880
1675
  count: this.store.map.size
@@ -1888,26 +1683,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1888
1683
  }, {
1889
1684
  key: "preload",
1890
1685
  value: (function () {
1891
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1686
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1892
1687
  var _products$length3;
1893
1688
  var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
1894
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1895
- while (1) switch (_context23.prev = _context23.next) {
1689
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1690
+ while (1) switch (_context19.prev = _context19.next) {
1896
1691
  case 0:
1897
1692
  console.log('[Products] 开始预加载数据...');
1898
1693
  tTotal = performance.now();
1899
1694
  this.logInfo('开始预加载数据');
1900
- _context23.prev = 3;
1695
+ _context19.prev = 3;
1901
1696
  tIndexDB = performance.now();
1902
- _context23.next = 7;
1697
+ _context19.next = 7;
1903
1698
  return this.loadProductsFromIndexDB();
1904
1699
  case 7:
1905
- cachedData = _context23.sent;
1700
+ cachedData = _context19.sent;
1906
1701
  perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1907
1702
  count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
1908
1703
  });
1909
1704
  if (!(cachedData && cachedData.length > 0)) {
1910
- _context23.next = 20;
1705
+ _context19.next = 19;
1911
1706
  break;
1912
1707
  }
1913
1708
  console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
@@ -1928,27 +1723,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1928
1723
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1929
1724
  source: 'IndexDB'
1930
1725
  });
1931
- this.lastPreloadCompletedAtMs = Date.now();
1932
- return _context23.abrupt("return");
1933
- case 20:
1726
+ return _context19.abrupt("return");
1727
+ case 19:
1934
1728
  console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
1935
1729
  this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
1936
- _context23.next = 29;
1730
+ _context19.next = 28;
1937
1731
  break;
1938
- case 24:
1939
- _context23.prev = 24;
1940
- _context23.t0 = _context23["catch"](3);
1941
- errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
1942
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context23.t0);
1732
+ case 23:
1733
+ _context19.prev = 23;
1734
+ _context19.t0 = _context19["catch"](3);
1735
+ errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0);
1736
+ console.warn('[Products] 从 IndexDB 加载数据失败:', _context19.t0);
1943
1737
  this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
1944
1738
  error: errorMessage
1945
1739
  });
1946
- case 29:
1740
+ case 28:
1947
1741
  tServer = performance.now();
1948
- _context23.next = 32;
1742
+ _context19.next = 31;
1949
1743
  return this.loadProductsByServer();
1950
- case 32:
1951
- products = _context23.sent;
1744
+ case 31:
1745
+ products = _context19.sent;
1952
1746
  perfMark('preload.loadFromServer', performance.now() - tServer, {
1953
1747
  count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
1954
1748
  });
@@ -1970,7 +1764,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1970
1764
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1971
1765
  source: 'Server'
1972
1766
  });
1973
- this.lastPreloadCompletedAtMs = Date.now();
1974
1767
  } else {
1975
1768
  perfMark('preload(empty)', performance.now() - tTotal, {
1976
1769
  source: 'empty'
@@ -1979,11 +1772,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1979
1772
  duration: "".concat(Math.round(performance.now() - tTotal), "ms")
1980
1773
  });
1981
1774
  }
1982
- case 35:
1775
+ case 34:
1983
1776
  case "end":
1984
- return _context23.stop();
1777
+ return _context19.stop();
1985
1778
  }
1986
- }, _callee23, this, [[3, 24]]);
1779
+ }, _callee19, this, [[3, 23]]);
1987
1780
  }));
1988
1781
  function preload() {
1989
1782
  return _preload.apply(this, arguments);
@@ -2018,7 +1811,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2018
1811
  }, {
2019
1812
  key: "setupProductSync",
2020
1813
  value: function setupProductSync() {
2021
- var _this8 = this;
1814
+ var _this6 = this;
2022
1815
  if (!this.productDataSource) {
2023
1816
  this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
2024
1817
  return;
@@ -2028,30 +1821,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2028
1821
  var data = (message === null || message === void 0 ? void 0 : message.data) || message;
2029
1822
  if (!data) return;
2030
1823
  console.log("[ProductsModule] \u6536\u5230\u540C\u6B65\u6D88\u606F [".concat(channelKey, "]:"), data);
2031
- _this8.logInfo('收到同步消息', {
1824
+ _this6.logInfo('收到同步消息', {
2032
1825
  channelKey: channelKey,
2033
1826
  action: data.action,
2034
1827
  id: data.id,
2035
1828
  action_filed: data.action_filed
2036
1829
  });
2037
- _this8.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
1830
+ _this6.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
2038
1831
  _channelKey: channelKey
2039
1832
  }));
2040
- if (_this8.syncTimer) {
2041
- clearTimeout(_this8.syncTimer);
1833
+ if (_this6.syncTimer) {
1834
+ clearTimeout(_this6.syncTimer);
2042
1835
  }
2043
- _this8.syncTimer = setTimeout(function () {
2044
- _this8.processProductSyncMessages();
1836
+ _this6.syncTimer = setTimeout(function () {
1837
+ _this6.processProductSyncMessages();
2045
1838
  }, PRODUCT_SYNC_DEBOUNCE_MS);
2046
1839
  };
2047
1840
  };
2048
1841
  this.productDataSource.run({
2049
1842
  pubsub: {
2050
1843
  callback: function callback(res) {
2051
- // console.log('sse_products_callback', res)
2052
- // this.logInfo('sse_products_callback: 收到同步消息', {
2053
- // data: res?.data,
2054
- // });
1844
+ console.log('sse_products_callback', res);
1845
+ _this6.logInfo('sse_products_callback: 收到同步消息', {
1846
+ data: res === null || res === void 0 ? void 0 : res.data
1847
+ });
2055
1848
  if (!(res !== null && res !== void 0 && res.data)) return;
2056
1849
  var data = res.data;
2057
1850
  var channelKey = data.module || 'product';
@@ -2059,7 +1852,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2059
1852
  }
2060
1853
  }
2061
1854
  }).catch(function (err) {
2062
- _this8.logError('setupProductSync: DataSource run 出错', {
1855
+ _this6.logError('setupProductSync: DataSource run 出错', {
2063
1856
  error: err instanceof Error ? err.message : String(err)
2064
1857
  });
2065
1858
  });
@@ -2087,18 +1880,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2087
1880
  }, {
2088
1881
  key: "processProductSyncMessages",
2089
1882
  value: (function () {
2090
- var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2091
- var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator12, _step12, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator13, _step13, product, freshProducts, mergeResult, _iterator14, _step14, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
2092
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2093
- while (1) switch (_context24.prev = _context24.next) {
1883
+ var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1884
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator10, _step10, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, freshProducts, allChangedIds, hasChanges, errorMessage;
1885
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1886
+ while (1) switch (_context20.prev = _context20.next) {
2094
1887
  case 0:
2095
1888
  messages = _toConsumableArray(this.pendingSyncMessages);
2096
1889
  this.pendingSyncMessages = [];
2097
1890
  if (!(messages.length === 0)) {
2098
- _context24.next = 4;
1891
+ _context20.next = 4;
2099
1892
  break;
2100
1893
  }
2101
- return _context24.abrupt("return");
1894
+ return _context20.abrupt("return");
2102
1895
  case 4:
2103
1896
  this.logInfo('processProductSyncMessages: 开始处理', {
2104
1897
  count: messages.length
@@ -2108,18 +1901,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2108
1901
  sseRefreshIds = [];
2109
1902
  priceRefreshIds = [];
2110
1903
  shouldClearPriceCache = false;
2111
- _iterator12 = _createForOfIteratorHelper(messages);
2112
- _context24.prev = 11;
2113
- _iterator12.s();
1904
+ _iterator10 = _createForOfIteratorHelper(messages);
1905
+ _context20.prev = 11;
1906
+ _iterator10.s();
2114
1907
  case 13:
2115
- if ((_step12 = _iterator12.n()).done) {
2116
- _context24.next = 36;
1908
+ if ((_step10 = _iterator10.n()).done) {
1909
+ _context20.next = 36;
2117
1910
  break;
2118
1911
  }
2119
- msg = _step12.value;
1912
+ msg = _step10.value;
2120
1913
  channelKey = msg._channelKey || msg.module || 'product';
2121
1914
  if (!(channelKey === 'product')) {
2122
- _context24.next = 33;
1915
+ _context20.next = 33;
2123
1916
  break;
2124
1917
  }
2125
1918
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
@@ -2127,14 +1920,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2127
1920
  }
2128
1921
  // 1. 删除场景:operation === 'delete' 或 action === 'delete'
2129
1922
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
2130
- _context24.next = 21;
1923
+ _context20.next = 21;
2131
1924
  break;
2132
1925
  }
2133
1926
  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);
2134
- return _context24.abrupt("continue", 34);
1927
+ return _context20.abrupt("continue", 34);
2135
1928
  case 21:
2136
1929
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
2137
- _context24.next = 26;
1930
+ _context20.next = 26;
2138
1931
  break;
2139
1932
  }
2140
1933
  ids = msg.ids || (msg.id ? [msg.id] : []);
@@ -2143,15 +1936,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2143
1936
  bodyId = msg.body.id;
2144
1937
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
2145
1938
  }
2146
- return _context24.abrupt("continue", 34);
1939
+ return _context20.abrupt("continue", 34);
2147
1940
  case 26:
2148
1941
  if (!msg.body) {
2149
- _context24.next = 30;
1942
+ _context20.next = 30;
2150
1943
  break;
2151
1944
  }
2152
1945
  _bodyId = msg.body.id || msg.id;
2153
1946
  if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
2154
- return _context24.abrupt("continue", 34);
1947
+ return _context20.abrupt("continue", 34);
2155
1948
  case 30:
2156
1949
  // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
2157
1950
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
@@ -2159,7 +1952,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2159
1952
  } else if (msg.id) {
2160
1953
  sseRefreshIds.push(msg.id);
2161
1954
  }
2162
- _context24.next = 34;
1955
+ _context20.next = 34;
2163
1956
  break;
2164
1957
  case 33:
2165
1958
  if (channelKey === 'product_quotation') {
@@ -2174,111 +1967,57 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2174
1967
  }
2175
1968
  }
2176
1969
  case 34:
2177
- _context24.next = 13;
1970
+ _context20.next = 13;
2178
1971
  break;
2179
1972
  case 36:
2180
- _context24.next = 41;
1973
+ _context20.next = 41;
2181
1974
  break;
2182
1975
  case 38:
2183
- _context24.prev = 38;
2184
- _context24.t0 = _context24["catch"](11);
2185
- _iterator12.e(_context24.t0);
1976
+ _context20.prev = 38;
1977
+ _context20.t0 = _context20["catch"](11);
1978
+ _iterator10.e(_context20.t0);
2186
1979
  case 41:
2187
- _context24.prev = 41;
2188
- _iterator12.f();
2189
- return _context24.finish(41);
1980
+ _context20.prev = 41;
1981
+ _iterator10.f();
1982
+ return _context20.finish(41);
2190
1983
  case 44:
2191
1984
  uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
2192
1985
  uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
2193
1986
  uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
2194
1987
  if (!(uniqueDeleteIds.length > 0)) {
2195
- _context24.next = 50;
1988
+ _context20.next = 50;
2196
1989
  break;
2197
1990
  }
2198
- _context24.next = 50;
1991
+ _context20.next = 50;
2199
1992
  return this.removeProductsByIds(uniqueDeleteIds);
2200
1993
  case 50:
2201
- /** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
2202
- patchProductMap = new Map();
2203
- patchMergeActions = {};
2204
- storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
2205
1994
  if (!(bodyUpdates.size > 0)) {
2206
- _context24.next = 60;
1995
+ _context20.next = 53;
2207
1996
  break;
2208
1997
  }
2209
- _context24.next = 56;
2210
- return this.applyBodyUpdatesToStore(bodyUpdates, {
2211
- skipIndexDB: true,
2212
- skipEmit: true
2213
- });
2214
- case 56:
2215
- bodyResult = _context24.sent;
2216
- _iterator13 = _createForOfIteratorHelper(bodyResult.changedProducts);
2217
- try {
2218
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
2219
- product = _step13.value;
2220
- patchProductMap.set(product.id, product);
2221
- patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
2222
- }
2223
- } catch (err) {
2224
- _iterator13.e(err);
2225
- } finally {
2226
- _iterator13.f();
2227
- }
2228
- storeMutated = true;
2229
- case 60:
2230
- // 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
2231
- freshProducts = [];
1998
+ _context20.next = 53;
1999
+ return this.applyBodyUpdatesToStore(bodyUpdates);
2000
+ case 53:
2232
2001
  if (!(uniqueSSEIds.length > 0)) {
2233
- _context24.next = 73;
2002
+ _context20.next = 61;
2234
2003
  break;
2235
2004
  }
2236
- _context24.next = 64;
2005
+ _context20.next = 56;
2237
2006
  return this.fetchProductsBySSE(uniqueSSEIds);
2238
- case 64:
2239
- freshProducts = _context24.sent;
2007
+ case 56:
2008
+ freshProducts = _context20.sent;
2240
2009
  if (!(freshProducts.length > 0)) {
2241
- _context24.next = 72;
2010
+ _context20.next = 60;
2242
2011
  break;
2243
2012
  }
2244
- _context24.next = 68;
2245
- return this.mergeProductsToStore(freshProducts, {
2246
- skipIndexDB: true,
2247
- skipEmit: true
2248
- });
2249
- case 68:
2250
- mergeResult = _context24.sent;
2251
- _iterator14 = _createForOfIteratorHelper(mergeResult.changedProducts);
2252
- try {
2253
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2254
- _product = _step14.value;
2255
- patchProductMap.set(_product.id, _product);
2256
- patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
2257
- }
2258
- } catch (err) {
2259
- _iterator14.e(err);
2260
- } finally {
2261
- _iterator14.f();
2262
- }
2263
- storeMutated = true;
2264
- case 72:
2013
+ _context20.next = 60;
2014
+ return this.mergeProductsToStore(freshProducts);
2015
+ case 60:
2265
2016
  this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
2266
2017
  requestedCount: uniqueSSEIds.length,
2267
2018
  receivedCount: freshProducts.length
2268
2019
  });
2269
- case 73:
2270
- patchProducts = _toConsumableArray(patchProductMap.values());
2271
- if (!(patchProducts.length > 0)) {
2272
- _context24.next = 77;
2273
- break;
2274
- }
2275
- _context24.next = 77;
2276
- return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
2277
- case 77:
2278
- if (storeMutated) {
2279
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2280
- }
2281
-
2020
+ case 61:
2282
2021
  // 收集所有非 delete 的变更 IDs(body + SSE + price),用于增量更新价格缓存
2283
2022
  allChangedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(Array.from(bodyUpdates.keys())), _toConsumableArray(uniqueSSEIds), _toConsumableArray(uniquePriceIds))));
2284
2023
  this.logInfo('processProductSyncMessages: 处理完成123', {
@@ -2291,41 +2030,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2291
2030
  });
2292
2031
  hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
2293
2032
  if (hasChanges) {
2294
- _context24.next = 84;
2033
+ _context20.next = 67;
2295
2034
  break;
2296
2035
  }
2297
2036
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
2298
- return _context24.abrupt("return");
2299
- case 84:
2037
+ return _context20.abrupt("return");
2038
+ case 67:
2300
2039
  if (!shouldClearPriceCache) {
2301
- _context24.next = 95;
2040
+ _context20.next = 78;
2302
2041
  break;
2303
2042
  }
2304
- _context24.prev = 85;
2305
- _context24.next = 88;
2043
+ _context20.prev = 68;
2044
+ _context20.next = 71;
2306
2045
  return this.refreshQuotationPriceBridge();
2307
- case 88:
2308
- _context24.next = 94;
2046
+ case 71:
2047
+ _context20.next = 77;
2309
2048
  break;
2310
- case 90:
2311
- _context24.prev = 90;
2312
- _context24.t1 = _context24["catch"](85);
2313
- errorMessage = _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1);
2049
+ case 73:
2050
+ _context20.prev = 73;
2051
+ _context20.t1 = _context20["catch"](68);
2052
+ errorMessage = _context20.t1 instanceof Error ? _context20.t1.message : String(_context20.t1);
2314
2053
  this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
2315
2054
  error: errorMessage
2316
2055
  });
2317
- case 94:
2056
+ case 77:
2318
2057
  this.clearPriceCache();
2319
- case 95:
2320
- _context24.next = 97;
2058
+ case 78:
2059
+ _context20.next = 80;
2321
2060
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
2322
2061
  changedIds: allChangedIds
2323
2062
  });
2324
- case 97:
2063
+ case 80:
2325
2064
  case "end":
2326
- return _context24.stop();
2065
+ return _context20.stop();
2327
2066
  }
2328
- }, _callee24, this, [[11, 38, 41, 44], [85, 90]]);
2067
+ }, _callee20, this, [[11, 38, 41, 44], [68, 73]]);
2329
2068
  }));
2330
2069
  function processProductSyncMessages() {
2331
2070
  return _processProductSyncMessages.apply(this, arguments);
@@ -2340,25 +2079,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2340
2079
  }, {
2341
2080
  key: "fetchProductsBySSE",
2342
2081
  value: (function () {
2343
- var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(ids) {
2082
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(ids) {
2344
2083
  var t0, productList, list, errorMessage;
2345
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2346
- while (1) switch (_context25.prev = _context25.next) {
2084
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2085
+ while (1) switch (_context21.prev = _context21.next) {
2347
2086
  case 0:
2348
2087
  if (this.productDataSource) {
2349
- _context25.next = 3;
2088
+ _context21.next = 3;
2350
2089
  break;
2351
2090
  }
2352
2091
  this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
2353
- return _context25.abrupt("return", []);
2092
+ return _context21.abrupt("return", []);
2354
2093
  case 3:
2355
2094
  this.logInfo('fetchProductsBySSE: 开始', {
2356
2095
  ids: ids,
2357
2096
  count: ids.length
2358
2097
  });
2359
2098
  t0 = performance.now();
2360
- _context25.prev = 5;
2361
- _context25.next = 8;
2099
+ _context21.prev = 5;
2100
+ _context21.next = 8;
2362
2101
  return this.productDataSource.run({
2363
2102
  sse: {
2364
2103
  query: {
@@ -2368,7 +2107,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2368
2107
  }
2369
2108
  });
2370
2109
  case 8:
2371
- productList = _context25.sent;
2110
+ productList = _context21.sent;
2372
2111
  list = productList || [];
2373
2112
  perfMark('fetchProductsBySSE', performance.now() - t0, {
2374
2113
  count: list.length
@@ -2378,23 +2117,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2378
2117
  receivedCount: list.length,
2379
2118
  duration: "".concat(Math.round(performance.now() - t0), "ms")
2380
2119
  });
2381
- return _context25.abrupt("return", list);
2120
+ return _context21.abrupt("return", list);
2382
2121
  case 15:
2383
- _context25.prev = 15;
2384
- _context25.t0 = _context25["catch"](5);
2385
- errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
2122
+ _context21.prev = 15;
2123
+ _context21.t0 = _context21["catch"](5);
2124
+ errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
2386
2125
  this.logError('fetchProductsBySSE: 失败', {
2387
2126
  ids: ids,
2388
2127
  error: errorMessage
2389
2128
  });
2390
- return _context25.abrupt("return", []);
2129
+ return _context21.abrupt("return", []);
2391
2130
  case 20:
2392
2131
  case "end":
2393
- return _context25.stop();
2132
+ return _context21.stop();
2394
2133
  }
2395
- }, _callee25, this, [[5, 15]]);
2134
+ }, _callee21, this, [[5, 15]]);
2396
2135
  }));
2397
- function fetchProductsBySSE(_x24) {
2136
+ function fetchProductsBySSE(_x20) {
2398
2137
  return _fetchProductsBySSE.apply(this, arguments);
2399
2138
  }
2400
2139
  return fetchProductsBySSE;
@@ -2402,84 +2141,63 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2402
2141
  /**
2403
2142
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
2404
2143
  * 已存在的 → 直接替换;不存在的 → 追加
2405
- *
2406
- * @example
2407
- * await this.applyBodyUpdatesToStore(bodyUpdates, { skipIndexDB: true })
2144
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
2145
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
2408
2146
  */
2409
2147
  )
2410
2148
  }, {
2411
2149
  key: "applyBodyUpdatesToStore",
2412
2150
  value: (function () {
2413
- var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(bodyUpdates, options) {
2414
- var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator15, _step15, _step15$value, id, body;
2415
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2416
- while (1) switch (_context26.prev = _context26.next) {
2151
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(bodyUpdates) {
2152
+ var updatedCount, newCount, appliedIds, _iterator11, _step11, _step11$value, id, body;
2153
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2154
+ while (1) switch (_context22.prev = _context22.next) {
2417
2155
  case 0:
2418
- changedProductIds = _toConsumableArray(bodyUpdates.keys());
2419
2156
  this.logInfo('applyBodyUpdatesToStore: 开始', {
2420
2157
  count: bodyUpdates.size
2421
2158
  });
2422
2159
  updatedCount = 0;
2423
2160
  newCount = 0;
2424
2161
  appliedIds = new Set();
2425
- mergeActions = {};
2426
- changedProducts = [];
2427
2162
  this.store.list = this.store.list.map(function (p) {
2428
2163
  if (bodyUpdates.has(p.id)) {
2429
2164
  updatedCount++;
2430
2165
  appliedIds.add(p.id);
2431
- mergeActions[p.id] = 'update';
2432
- var next = bodyUpdates.get(p.id);
2433
- changedProducts.push(next);
2434
- return next;
2166
+ return bodyUpdates.get(p.id);
2435
2167
  }
2436
2168
  return p;
2437
2169
  });
2438
- _iterator15 = _createForOfIteratorHelper(bodyUpdates);
2170
+ _iterator11 = _createForOfIteratorHelper(bodyUpdates);
2439
2171
  try {
2440
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2441
- _step15$value = _slicedToArray(_step15.value, 2), id = _step15$value[0], body = _step15$value[1];
2172
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
2173
+ _step11$value = _slicedToArray(_step11.value, 2), id = _step11$value[0], body = _step11$value[1];
2442
2174
  if (!appliedIds.has(id)) {
2443
2175
  this.store.list.push(body);
2444
2176
  newCount++;
2445
- mergeActions[id] = 'insert';
2446
- changedProducts.push(body);
2447
2177
  }
2448
2178
  }
2449
2179
  } catch (err) {
2450
- _iterator15.e(err);
2180
+ _iterator11.e(err);
2451
2181
  } finally {
2452
- _iterator15.f();
2182
+ _iterator11.f();
2453
2183
  }
2454
2184
  this.syncProductsMap();
2455
- if (options !== null && options !== void 0 && options.skipIndexDB) {
2456
- _context26.next = 14;
2457
- break;
2458
- }
2459
- _context26.next = 14;
2460
- return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
2461
- case 14:
2462
- if (!(options !== null && options !== void 0 && options.skipEmit)) {
2463
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2464
- }
2185
+ _context22.next = 10;
2186
+ return this.saveProductsToIndexDB(this.store.list);
2187
+ case 10:
2188
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2465
2189
  this.logInfo('applyBodyUpdatesToStore: 完成', {
2466
2190
  updatedCount: updatedCount,
2467
2191
  newCount: newCount,
2468
2192
  totalCount: this.store.list.length
2469
2193
  });
2470
- return _context26.abrupt("return", {
2471
- changedProducts: changedProducts,
2472
- mergeActions: mergeActions,
2473
- updatedCount: updatedCount,
2474
- newCount: newCount
2475
- });
2476
- case 17:
2194
+ case 12:
2477
2195
  case "end":
2478
- return _context26.stop();
2196
+ return _context22.stop();
2479
2197
  }
2480
- }, _callee26, this);
2198
+ }, _callee22, this);
2481
2199
  }));
2482
- function applyBodyUpdatesToStore(_x25, _x26) {
2200
+ function applyBodyUpdatesToStore(_x21) {
2483
2201
  return _applyBodyUpdatesToStore.apply(this, arguments);
2484
2202
  }
2485
2203
  return applyBodyUpdatesToStore;
@@ -2487,91 +2205,68 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2487
2205
  /**
2488
2206
  * 将增量拉取的商品合并到 store
2489
2207
  * 已存在的 → 替换;新的 → 追加
2490
- *
2491
- * @example
2492
- * await this.mergeProductsToStore(freshProducts, { skipIndexDB: true })
2208
+ * 同时更新 store.map、IndexDB,触发 onProductsChanged
2493
2209
  */
2494
2210
  )
2495
2211
  }, {
2496
2212
  key: "mergeProductsToStore",
2497
2213
  value: (function () {
2498
- var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(freshProducts, options) {
2499
- var freshMap, _iterator16, _step16, p, mergeActions, changedProducts, updatedList, newCount, _iterator17, _step17, _p2, updatedCount, changedProductIds;
2500
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2501
- while (1) switch (_context27.prev = _context27.next) {
2214
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(freshProducts) {
2215
+ var freshMap, _iterator12, _step12, p, updatedList, newCount, _iterator13, _step13, _p2, updatedCount;
2216
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2217
+ while (1) switch (_context23.prev = _context23.next) {
2502
2218
  case 0:
2503
2219
  freshMap = new Map();
2504
- _iterator16 = _createForOfIteratorHelper(freshProducts);
2220
+ _iterator12 = _createForOfIteratorHelper(freshProducts);
2505
2221
  try {
2506
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2507
- p = _step16.value;
2222
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
2223
+ p = _step12.value;
2508
2224
  freshMap.set(p.id, p);
2509
2225
  }
2510
2226
  } catch (err) {
2511
- _iterator16.e(err);
2227
+ _iterator12.e(err);
2512
2228
  } finally {
2513
- _iterator16.f();
2229
+ _iterator12.f();
2514
2230
  }
2515
- mergeActions = {};
2516
- changedProducts = [];
2517
2231
  updatedList = this.store.list.map(function (p) {
2518
2232
  if (freshMap.has(p.id)) {
2519
2233
  var fresh = freshMap.get(p.id);
2520
2234
  freshMap.delete(p.id);
2521
- mergeActions[p.id] = 'update';
2522
- changedProducts.push(fresh);
2523
2235
  return fresh;
2524
2236
  }
2525
2237
  return p;
2526
2238
  }); // freshMap 中剩余的是新商品(create 场景)
2527
2239
  newCount = freshMap.size;
2528
- _iterator17 = _createForOfIteratorHelper(freshMap.values());
2240
+ _iterator13 = _createForOfIteratorHelper(freshMap.values());
2529
2241
  try {
2530
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2531
- _p2 = _step17.value;
2242
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
2243
+ _p2 = _step13.value;
2532
2244
  updatedList.push(_p2);
2533
- mergeActions[_p2.id] = 'insert';
2534
- changedProducts.push(_p2);
2535
2245
  }
2536
2246
  } catch (err) {
2537
- _iterator17.e(err);
2247
+ _iterator13.e(err);
2538
2248
  } finally {
2539
- _iterator17.f();
2249
+ _iterator13.f();
2540
2250
  }
2541
2251
  updatedCount = freshProducts.length - newCount;
2542
- changedProductIds = freshProducts.map(function (p) {
2543
- return p.id;
2544
- });
2545
2252
  this.store.list = updatedList;
2546
2253
  this.syncProductsMap();
2547
- if (options !== null && options !== void 0 && options.skipIndexDB) {
2548
- _context27.next = 16;
2549
- break;
2550
- }
2551
- _context27.next = 16;
2552
- return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
2553
- case 16:
2554
- if (!(options !== null && options !== void 0 && options.skipEmit)) {
2555
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2556
- }
2254
+ _context23.next = 12;
2255
+ return this.saveProductsToIndexDB(this.store.list);
2256
+ case 12:
2557
2257
  this.logInfo('mergeProductsToStore: 合并完成', {
2558
2258
  updatedCount: updatedCount,
2559
2259
  newCount: newCount,
2560
2260
  totalCount: this.store.list.length
2561
2261
  });
2562
- return _context27.abrupt("return", {
2563
- changedProducts: changedProducts,
2564
- mergeActions: mergeActions,
2565
- updatedCount: updatedCount,
2566
- newCount: newCount
2567
- });
2568
- case 19:
2262
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2263
+ case 14:
2569
2264
  case "end":
2570
- return _context27.stop();
2265
+ return _context23.stop();
2571
2266
  }
2572
- }, _callee27, this);
2267
+ }, _callee23, this);
2573
2268
  }));
2574
- function mergeProductsToStore(_x27, _x28) {
2269
+ function mergeProductsToStore(_x22) {
2575
2270
  return _mergeProductsToStore.apply(this, arguments);
2576
2271
  }
2577
2272
  return mergeProductsToStore;
@@ -2585,65 +2280,56 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2585
2280
  }, {
2586
2281
  key: "silentRefresh",
2587
2282
  value: (function () {
2588
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2589
- var t0, now, elapsedSincePreload, elapsedSinceFullFetch, products, errorMessage;
2590
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2591
- while (1) switch (_context28.prev = _context28.next) {
2283
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2284
+ var t0, products, errorMessage;
2285
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2286
+ while (1) switch (_context24.prev = _context24.next) {
2592
2287
  case 0:
2593
2288
  t0 = performance.now();
2594
- now = Date.now();
2595
- elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
2596
- elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
2597
- if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
2598
- _context28.next = 6;
2599
- break;
2600
- }
2601
- return _context28.abrupt("return", this.store.list);
2602
- case 6:
2603
2289
  this.logInfo('silentRefresh 开始');
2604
- _context28.prev = 7;
2605
- _context28.next = 10;
2290
+ _context24.prev = 2;
2291
+ _context24.next = 5;
2606
2292
  return this.loadProductsByServer();
2607
- case 10:
2608
- products = _context28.sent;
2293
+ case 5:
2294
+ products = _context24.sent;
2609
2295
  if (!(products && products.length > 0)) {
2610
- _context28.next = 21;
2296
+ _context24.next = 16;
2611
2297
  break;
2612
2298
  }
2613
2299
  this.store.list = products;
2614
2300
  this.syncProductsMap();
2615
2301
  this.clearPriceCache();
2616
2302
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2617
- _context28.next = 18;
2303
+ _context24.next = 13;
2618
2304
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
2619
- case 18:
2305
+ case 13:
2620
2306
  this.logInfo('silentRefresh 完成', {
2621
2307
  productCount: products.length,
2622
2308
  duration: "".concat(Math.round(performance.now() - t0), "ms")
2623
2309
  });
2624
- _context28.next = 22;
2310
+ _context24.next = 17;
2625
2311
  break;
2626
- case 21:
2312
+ case 16:
2627
2313
  this.logWarning('silentRefresh: 服务器未返回数据');
2628
- case 22:
2314
+ case 17:
2629
2315
  perfMark('silentRefresh', performance.now() - t0, {
2630
2316
  count: this.store.list.length
2631
2317
  });
2632
- return _context28.abrupt("return", this.store.list);
2633
- case 26:
2634
- _context28.prev = 26;
2635
- _context28.t0 = _context28["catch"](7);
2636
- errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0);
2318
+ return _context24.abrupt("return", this.store.list);
2319
+ case 21:
2320
+ _context24.prev = 21;
2321
+ _context24.t0 = _context24["catch"](2);
2322
+ errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
2637
2323
  this.logError('silentRefresh 失败', {
2638
2324
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
2639
2325
  error: errorMessage
2640
2326
  });
2641
- return _context28.abrupt("return", this.store.list);
2642
- case 31:
2327
+ return _context24.abrupt("return", this.store.list);
2328
+ case 26:
2643
2329
  case "end":
2644
- return _context28.stop();
2330
+ return _context24.stop();
2645
2331
  }
2646
- }, _callee28, this, [[7, 26]]);
2332
+ }, _callee24, this, [[2, 21]]);
2647
2333
  }));
2648
2334
  function silentRefresh() {
2649
2335
  return _silentRefresh.apply(this, arguments);