@pisell/pisellos 0.0.568 → 0.10.1

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 (588) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +24 -96
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +2 -2
  13. package/dist/modules/BaseModule.js +12 -14
  14. package/dist/modules/BookingContext/index.d.ts +48 -0
  15. package/dist/modules/BookingContext/index.js +566 -0
  16. package/dist/modules/BookingContext/types.d.ts +102 -0
  17. package/dist/modules/BookingContext/types.js +51 -0
  18. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  19. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  20. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  21. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  22. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  23. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  24. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  25. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  26. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  27. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  28. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  29. package/dist/modules/BookingContext/utils/index.js +11 -0
  30. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  31. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  32. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  33. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  34. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  35. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  36. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  37. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  38. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  39. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  40. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  41. package/dist/modules/BookingContext/utils/resources.js +486 -0
  42. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  43. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  44. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  45. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  46. package/dist/modules/Cart/index.js +3 -0
  47. package/dist/modules/Cart/utils/cartProduct.js +27 -5
  48. package/dist/modules/Cart/utils/cartResource.js +0 -2
  49. package/dist/modules/Cart/utils/changePrice.js +11 -11
  50. package/dist/modules/Customer/index.d.ts +20 -0
  51. package/dist/modules/Customer/index.js +172 -83
  52. package/dist/modules/Customer/types.d.ts +2 -0
  53. package/dist/modules/Date/index.js +5 -1
  54. package/dist/modules/Discount/index.d.ts +2 -2
  55. package/dist/modules/Discount/index.js +43 -30
  56. package/dist/modules/Discount/types.d.ts +1 -1
  57. package/dist/modules/OpenData/index.d.ts +8 -0
  58. package/dist/modules/OpenData/index.js +38 -16
  59. package/dist/modules/Order/index.d.ts +449 -24
  60. package/dist/modules/Order/index.js +5460 -574
  61. package/dist/modules/Order/types.d.ts +693 -88
  62. package/dist/modules/Order/types.js +68 -1
  63. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  64. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  65. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  66. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  67. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  68. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  69. package/dist/modules/Order/utils.d.ts +167 -18
  70. package/dist/modules/Order/utils.js +960 -165
  71. package/dist/modules/Payment/index.d.ts +10 -9
  72. package/dist/modules/Payment/index.js +573 -746
  73. package/dist/modules/Payment/types.d.ts +44 -24
  74. package/dist/modules/Payment/utils.d.ts +1 -1
  75. package/dist/modules/Payment/utils.js +4 -3
  76. package/dist/modules/Payment/walletpass.d.ts +0 -2
  77. package/dist/modules/Payment/walletpass.js +49 -33
  78. package/dist/modules/Product/types.d.ts +29 -7
  79. package/dist/modules/ProductList/index.d.ts +17 -13
  80. package/dist/modules/ProductList/index.js +182 -81
  81. package/dist/modules/ProductList/types.d.ts +16 -0
  82. package/dist/modules/Quotation/index.d.ts +22 -2
  83. package/dist/modules/Quotation/index.js +108 -42
  84. package/dist/modules/Quotation/types.d.ts +19 -0
  85. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  86. package/dist/modules/ResourcePlanner/index.js +181 -0
  87. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  88. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  89. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  90. package/dist/modules/ResourcePlanner/types.js +1 -0
  91. package/dist/modules/Rules/index.d.ts +8 -10
  92. package/dist/modules/Rules/index.js +324 -513
  93. package/dist/modules/Rules/types.d.ts +14 -3
  94. package/dist/modules/SalesSummary/index.d.ts +23 -26
  95. package/dist/modules/SalesSummary/index.js +152 -46
  96. package/dist/modules/SalesSummary/types.d.ts +9 -1
  97. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  98. package/dist/modules/SalesSummary/utils.js +804 -165
  99. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -12
  100. package/dist/modules/Schedule/index.d.ts +18 -5
  101. package/dist/modules/Schedule/index.js +79 -24
  102. package/dist/modules/Schedule/types.d.ts +2 -0
  103. package/dist/modules/Schedule/utils.js +1 -0
  104. package/dist/modules/Step/index.js +1 -0
  105. package/dist/modules/Summary/index.js +4 -3
  106. package/dist/modules/Summary/utils.js +22 -43
  107. package/dist/modules/SurchargeList/index.d.ts +18 -0
  108. package/dist/modules/SurchargeList/index.js +185 -0
  109. package/dist/modules/SurchargeList/types.d.ts +15 -0
  110. package/dist/modules/SurchargeList/types.js +1 -0
  111. package/dist/modules/index.d.ts +3 -0
  112. package/dist/modules/index.js +4 -1
  113. package/dist/plugins/app.d.ts +2 -0
  114. package/dist/plugins/request.d.ts +1 -0
  115. package/dist/plugins/request.js +4 -1
  116. package/dist/plugins/window.js +6 -2
  117. package/dist/server/index.d.ts +462 -8
  118. package/dist/server/index.js +6168 -680
  119. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  120. package/dist/server/modules/floor-plan/index.js +595 -0
  121. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  122. package/dist/server/modules/floor-plan/types.js +13 -0
  123. package/dist/server/modules/index.d.ts +7 -2
  124. package/dist/server/modules/index.js +6 -0
  125. package/dist/server/modules/menu/index.js +41 -32
  126. package/dist/server/modules/order/index.d.ts +207 -14
  127. package/dist/server/modules/order/index.js +2328 -379
  128. package/dist/server/modules/order/types.d.ts +76 -5
  129. package/dist/server/modules/order/types.js +14 -1
  130. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  131. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  132. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  133. package/dist/server/modules/payment/index.d.ts +28 -0
  134. package/dist/server/modules/payment/index.js +305 -0
  135. package/dist/server/modules/payment/types.d.ts +9 -0
  136. package/dist/server/modules/payment/types.js +1 -0
  137. package/dist/server/modules/products/index.d.ts +105 -14
  138. package/dist/server/modules/products/index.js +1416 -521
  139. package/dist/server/modules/products/types.d.ts +34 -1
  140. package/dist/server/modules/products/types.js +4 -0
  141. package/dist/server/modules/quotation/index.d.ts +39 -0
  142. package/dist/server/modules/quotation/index.js +298 -77
  143. package/dist/server/modules/resource/index.d.ts +2 -3
  144. package/dist/server/modules/resource/index.js +109 -86
  145. package/dist/server/modules/schedule/index.d.ts +6 -4
  146. package/dist/server/modules/schedule/index.js +145 -106
  147. package/dist/server/test.json +713 -0
  148. package/dist/server/types.d.ts +2 -0
  149. package/dist/server/utils/product.js +3 -2
  150. package/dist/server/utils/small-ticket.d.ts +71 -0
  151. package/dist/server/utils/small-ticket.js +963 -0
  152. package/dist/solution/BaseSales/index.d.ts +378 -0
  153. package/dist/solution/BaseSales/index.js +4009 -0
  154. package/dist/solution/BaseSales/types.d.ts +394 -0
  155. package/dist/solution/BaseSales/types.js +40 -0
  156. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  157. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  158. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  159. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  160. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  161. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  162. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  163. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  164. package/dist/solution/BaseSales/utils.d.ts +40 -0
  165. package/dist/solution/BaseSales/utils.js +263 -0
  166. package/dist/solution/BookingByStep/index.d.ts +1 -1
  167. package/dist/solution/BookingByStep/index.js +60 -11
  168. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  169. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  170. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  171. package/dist/solution/BookingTicket/index.d.ts +393 -24
  172. package/dist/solution/BookingTicket/index.js +2508 -443
  173. package/dist/solution/BookingTicket/types.d.ts +191 -6
  174. package/dist/solution/BookingTicket/types.js +83 -10
  175. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  176. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  177. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  178. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  179. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  180. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  181. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  182. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  183. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  184. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  185. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  186. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  187. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  188. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  189. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  190. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  191. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  192. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +42 -1
  193. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  194. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  195. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  196. package/dist/solution/BookingTicket/utils/scan/handleScan.js +42 -28
  197. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  198. package/dist/solution/BookingTicket/utils/scan/index.js +30 -14
  199. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  200. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  201. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  202. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  203. package/dist/solution/BuyTickets/index.js +12 -9
  204. package/dist/solution/Checkout/index.d.ts +1 -0
  205. package/dist/solution/Checkout/index.js +275 -209
  206. package/dist/solution/Checkout/utils/index.js +20 -8
  207. package/dist/solution/RegisterAndLogin/config.js +2 -10
  208. package/dist/solution/RegisterAndLogin/index.js +76 -30
  209. package/dist/solution/Sales/index.d.ts +50 -5
  210. package/dist/solution/Sales/index.js +484 -92
  211. package/dist/solution/Sales/types.d.ts +26 -2
  212. package/dist/solution/ScanOrder/index.d.ts +27 -21
  213. package/dist/solution/ScanOrder/index.js +519 -444
  214. package/dist/solution/ScanOrder/types.d.ts +33 -11
  215. package/dist/solution/ScanOrder/types.js +4 -5
  216. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  217. package/dist/solution/ScanOrder/utils.js +109 -34
  218. package/dist/solution/ShopDiscount/index.js +18 -19
  219. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  220. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  221. package/dist/solution/ShopDiscount/utils.js +0 -9
  222. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  223. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  224. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  225. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  226. package/dist/solution/VenueBooking/index.d.ts +32 -51
  227. package/dist/solution/VenueBooking/index.js +741 -808
  228. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  229. package/dist/solution/VenueBooking/types.d.ts +1 -3
  230. package/dist/solution/VenueBooking/types.js +0 -1
  231. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  232. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  233. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  234. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  235. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  236. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  237. package/dist/solution/index.d.ts +2 -0
  238. package/dist/solution/index.js +3 -1
  239. package/dist/types/index.d.ts +12 -2
  240. package/dist/utils/task.js +18 -15
  241. package/dist/utils/watch.js +1 -0
  242. package/lib/apis/picoding.js +0 -2
  243. package/lib/core/index.js +132 -130
  244. package/lib/effects/index.js +57 -46
  245. package/lib/index.d.ts +0 -1
  246. package/lib/index.js +50 -92
  247. package/lib/model/index.js +21 -14
  248. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  249. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  250. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  251. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  252. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  253. package/lib/model/strategy/adapter/index.js +64 -100
  254. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  255. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  256. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  257. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  258. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  259. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  260. package/lib/model/strategy/adapter/promotion/evaluator.js +233 -382
  261. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  262. package/lib/model/strategy/adapter/promotion/index.js +0 -1
  263. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  264. package/lib/model/strategy/adapter/type.js +16 -4
  265. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  266. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  267. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  268. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  269. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  270. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  271. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  272. package/lib/model/strategy/adapter/walletPass/utils.js +383 -676
  273. package/lib/model/strategy/engine.js +168 -270
  274. package/lib/model/strategy/index.js +34 -49
  275. package/lib/model/strategy/strategy-example.js +239 -243
  276. package/lib/model/strategy/type.js +40 -100
  277. package/lib/modules/Account/index.js +53 -39
  278. package/lib/modules/Account/types.js +33 -20
  279. package/lib/modules/AccountList/index.js +154 -116
  280. package/lib/modules/AccountList/types.js +31 -30
  281. package/lib/modules/AccountList/utils.js +30 -18
  282. package/lib/modules/BaseModule.d.ts +2 -2
  283. package/lib/modules/BaseModule.js +50 -29
  284. package/lib/modules/BookingContext/index.d.ts +48 -0
  285. package/lib/modules/BookingContext/index.js +368 -0
  286. package/lib/modules/BookingContext/types.d.ts +102 -0
  287. package/lib/modules/BookingContext/types.js +34 -0
  288. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  289. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +298 -0
  290. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  291. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +155 -0
  292. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  293. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +222 -0
  294. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  295. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  296. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  297. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  298. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  299. package/lib/modules/BookingContext/utils/index.js +43 -0
  300. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  301. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  302. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  303. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  304. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  305. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  306. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  307. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  308. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  309. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  310. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  311. package/lib/modules/BookingContext/utils/resources.js +377 -0
  312. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  313. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  314. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  315. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  316. package/lib/modules/Cart/index.js +124 -170
  317. package/lib/modules/Cart/types.js +51 -46
  318. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  319. package/lib/modules/Cart/utils/cartDate.js +61 -56
  320. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  321. package/lib/modules/Cart/utils/cartNote.js +32 -27
  322. package/lib/modules/Cart/utils/cartProduct.js +261 -309
  323. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  324. package/lib/modules/Cart/utils/cartResource.js +78 -72
  325. package/lib/modules/Cart/utils/changePrice.js +59 -31
  326. package/lib/modules/Cart/utils/index.js +48 -106
  327. package/lib/modules/Customer/constants.js +34 -13
  328. package/lib/modules/Customer/index.d.ts +20 -0
  329. package/lib/modules/Customer/index.js +207 -217
  330. package/lib/modules/Customer/types.d.ts +2 -0
  331. package/lib/modules/Customer/types.js +35 -38
  332. package/lib/modules/Date/index.js +115 -116
  333. package/lib/modules/Date/types.js +28 -16
  334. package/lib/modules/Date/utils.js +123 -174
  335. package/lib/modules/Discount/index.d.ts +2 -2
  336. package/lib/modules/Discount/index.js +133 -119
  337. package/lib/modules/Discount/types.d.ts +1 -1
  338. package/lib/modules/Discount/types.js +31 -9
  339. package/lib/modules/Guests/index.js +56 -30
  340. package/lib/modules/Guests/types.js +33 -23
  341. package/lib/modules/Holder/index.js +189 -209
  342. package/lib/modules/Holder/types.js +16 -4
  343. package/lib/modules/Holder/utils.js +49 -20
  344. package/lib/modules/OpenData/index.d.ts +8 -0
  345. package/lib/modules/OpenData/index.js +88 -63
  346. package/lib/modules/OpenData/types.js +16 -4
  347. package/lib/modules/OpenData/utils.js +78 -44
  348. package/lib/modules/Order/index.d.ts +449 -24
  349. package/lib/modules/Order/index.js +4184 -514
  350. package/lib/modules/Order/types.d.ts +693 -88
  351. package/lib/modules/Order/types.js +35 -24
  352. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  353. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  354. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  355. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  356. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  357. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  358. package/lib/modules/Order/utils.d.ts +167 -18
  359. package/lib/modules/Order/utils.js +1085 -414
  360. package/lib/modules/Payment/cash.js +33 -20
  361. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  362. package/lib/modules/Payment/eftpos.js +30 -16
  363. package/lib/modules/Payment/index.d.ts +10 -9
  364. package/lib/modules/Payment/index.js +402 -636
  365. package/lib/modules/Payment/mx51.js +0 -1
  366. package/lib/modules/Payment/types.d.ts +44 -24
  367. package/lib/modules/Payment/types.js +107 -216
  368. package/lib/modules/Payment/utils.d.ts +1 -1
  369. package/lib/modules/Payment/utils.js +50 -52
  370. package/lib/modules/Payment/walletpass.d.ts +0 -2
  371. package/lib/modules/Payment/walletpass.js +216 -221
  372. package/lib/modules/Product/index.js +46 -51
  373. package/lib/modules/Product/types.d.ts +29 -7
  374. package/lib/modules/Product/types.js +16 -4
  375. package/lib/modules/Product/utils.js +33 -32
  376. package/lib/modules/ProductList/index.d.ts +17 -13
  377. package/lib/modules/ProductList/index.js +161 -120
  378. package/lib/modules/ProductList/types.d.ts +16 -0
  379. package/lib/modules/ProductList/types.js +31 -9
  380. package/lib/modules/Quotation/index.d.ts +22 -2
  381. package/lib/modules/Quotation/index.js +154 -64
  382. package/lib/modules/Quotation/types.d.ts +19 -0
  383. package/lib/modules/Quotation/types.js +16 -4
  384. package/lib/modules/Resource/index.js +59 -27
  385. package/lib/modules/Resource/types.js +32 -22
  386. package/lib/modules/Resource/utils.js +38 -30
  387. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  388. package/lib/modules/ResourcePlanner/index.js +148 -0
  389. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  390. package/lib/modules/ResourcePlanner/planner.js +933 -0
  391. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  392. package/lib/modules/ResourcePlanner/types.js +17 -0
  393. package/lib/modules/Rules/index.d.ts +8 -10
  394. package/lib/modules/Rules/index.js +960 -1440
  395. package/lib/modules/Rules/types.d.ts +14 -3
  396. package/lib/modules/Rules/types.js +40 -17
  397. package/lib/modules/SalesSummary/index.d.ts +23 -26
  398. package/lib/modules/SalesSummary/index.js +134 -61
  399. package/lib/modules/SalesSummary/types.d.ts +9 -1
  400. package/lib/modules/SalesSummary/types.js +16 -4
  401. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  402. package/lib/modules/SalesSummary/utils.js +814 -233
  403. package/lib/modules/ScanOrderLogger/index.js +79 -59
  404. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  405. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  406. package/lib/modules/ScanOrderLogger/types.js +16 -4
  407. package/lib/modules/Schedule/getDateIsInSchedule.js +169 -338
  408. package/lib/modules/Schedule/index.d.ts +18 -5
  409. package/lib/modules/Schedule/index.js +153 -104
  410. package/lib/modules/Schedule/type.js +16 -4
  411. package/lib/modules/Schedule/types.d.ts +2 -0
  412. package/lib/modules/Schedule/types.js +16 -4
  413. package/lib/modules/Schedule/utils.js +291 -433
  414. package/lib/modules/Step/index.js +52 -40
  415. package/lib/modules/Step/tyeps.js +16 -4
  416. package/lib/modules/Summary/index.js +71 -66
  417. package/lib/modules/Summary/types.js +16 -4
  418. package/lib/modules/Summary/utils.js +418 -791
  419. package/lib/modules/SurchargeList/index.d.ts +18 -0
  420. package/lib/modules/SurchargeList/index.js +109 -0
  421. package/lib/modules/SurchargeList/types.d.ts +15 -0
  422. package/lib/modules/SurchargeList/types.js +17 -0
  423. package/lib/modules/index.d.ts +3 -0
  424. package/lib/modules/index.js +63 -212
  425. package/lib/plugins/app.d.ts +2 -0
  426. package/lib/plugins/app.js +16 -4
  427. package/lib/plugins/index.js +25 -36
  428. package/lib/plugins/request.d.ts +1 -0
  429. package/lib/plugins/request.js +126 -137
  430. package/lib/plugins/shopStore.js +16 -4
  431. package/lib/plugins/user.js +16 -4
  432. package/lib/plugins/window.js +179 -171
  433. package/lib/server/index.d.ts +462 -8
  434. package/lib/server/index.js +4520 -1162
  435. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  436. package/lib/server/modules/floor-plan/index.js +327 -0
  437. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  438. package/lib/server/modules/floor-plan/types.js +34 -0
  439. package/lib/server/modules/index.d.ts +7 -2
  440. package/lib/server/modules/index.js +67 -84
  441. package/lib/server/modules/menu/index.js +122 -146
  442. package/lib/server/modules/menu/types.js +31 -18
  443. package/lib/server/modules/order/index.d.ts +207 -14
  444. package/lib/server/modules/order/index.js +1543 -285
  445. package/lib/server/modules/order/types.d.ts +76 -5
  446. package/lib/server/modules/order/types.js +32 -107
  447. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  448. package/lib/server/modules/order/utils/filterBookings.js +259 -176
  449. package/lib/server/modules/order/utils/filterOrders.js +293 -94
  450. package/lib/server/modules/payment/index.d.ts +28 -0
  451. package/lib/server/modules/payment/index.js +192 -0
  452. package/lib/server/modules/payment/types.d.ts +9 -0
  453. package/lib/server/modules/payment/types.js +17 -0
  454. package/lib/server/modules/products/index.d.ts +105 -14
  455. package/lib/server/modules/products/index.js +850 -475
  456. package/lib/server/modules/products/types.d.ts +34 -1
  457. package/lib/server/modules/products/types.js +34 -41
  458. package/lib/server/modules/quotation/index.d.ts +39 -0
  459. package/lib/server/modules/quotation/index.js +254 -75
  460. package/lib/server/modules/quotation/types.js +31 -21
  461. package/lib/server/modules/resource/index.d.ts +2 -3
  462. package/lib/server/modules/resource/index.js +240 -243
  463. package/lib/server/modules/resource/types.js +33 -42
  464. package/lib/server/modules/schedule/index.d.ts +6 -4
  465. package/lib/server/modules/schedule/index.js +146 -147
  466. package/lib/server/modules/schedule/types.js +21 -14
  467. package/lib/server/modules/schedule/utils.js +163 -334
  468. package/lib/server/test.json +713 -0
  469. package/lib/server/types.d.ts +2 -0
  470. package/lib/server/types.js +16 -4
  471. package/lib/server/utils/index.js +23 -25
  472. package/lib/server/utils/product.js +140 -197
  473. package/lib/server/utils/schedule.js +41 -34
  474. package/lib/server/utils/small-ticket.d.ts +71 -0
  475. package/lib/server/utils/small-ticket.js +904 -0
  476. package/lib/server/utils/time.js +49 -40
  477. package/lib/solution/BaseSales/index.d.ts +378 -0
  478. package/lib/solution/BaseSales/index.js +2533 -0
  479. package/lib/solution/BaseSales/types.d.ts +394 -0
  480. package/lib/solution/BaseSales/types.js +43 -0
  481. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  482. package/lib/solution/BaseSales/utils/cartPromotion.js +1004 -0
  483. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  484. package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
  485. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  486. package/lib/solution/BaseSales/utils/quotationPrice.js +289 -0
  487. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  488. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +256 -0
  489. package/lib/solution/BaseSales/utils.d.ts +40 -0
  490. package/lib/solution/BaseSales/utils.js +244 -0
  491. package/lib/solution/BookingByStep/index.d.ts +1 -1
  492. package/lib/solution/BookingByStep/index.js +1340 -1530
  493. package/lib/solution/BookingByStep/types.js +99 -40
  494. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  495. package/lib/solution/BookingByStep/utils/products.js +52 -42
  496. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  497. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  498. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  499. package/lib/solution/BookingTicket/index.d.ts +393 -24
  500. package/lib/solution/BookingTicket/index.js +1374 -184
  501. package/lib/solution/BookingTicket/types.d.ts +191 -6
  502. package/lib/solution/BookingTicket/types.js +79 -40
  503. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  504. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  505. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  506. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
  507. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  508. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -0
  509. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  510. package/lib/solution/BookingTicket/utils/cartView.js +184 -0
  511. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  512. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  513. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  514. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  515. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  516. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
  517. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  518. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
  519. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  520. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +97 -64
  521. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  522. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  523. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  524. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -82
  525. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  526. package/lib/solution/BookingTicket/utils/scan/index.js +109 -91
  527. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  528. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  529. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  530. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  531. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
  532. package/lib/solution/BuyTickets/index.js +70 -67
  533. package/lib/solution/BuyTickets/types.js +38 -22
  534. package/lib/solution/Checkout/index.d.ts +1 -0
  535. package/lib/solution/Checkout/index.js +1169 -1463
  536. package/lib/solution/Checkout/types.js +61 -91
  537. package/lib/solution/Checkout/utils/index.js +156 -228
  538. package/lib/solution/PlaceOrder/index.js +0 -55
  539. package/lib/solution/RegisterAndLogin/config.js +462 -503
  540. package/lib/solution/RegisterAndLogin/index.js +630 -633
  541. package/lib/solution/RegisterAndLogin/types.js +76 -189
  542. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  543. package/lib/solution/Sales/index.d.ts +50 -5
  544. package/lib/solution/Sales/index.js +498 -238
  545. package/lib/solution/Sales/types.d.ts +26 -2
  546. package/lib/solution/Sales/types.js +33 -27
  547. package/lib/solution/ScanOrder/index.d.ts +27 -21
  548. package/lib/solution/ScanOrder/index.js +936 -864
  549. package/lib/solution/ScanOrder/types.d.ts +33 -11
  550. package/lib/solution/ScanOrder/types.js +34 -34
  551. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  552. package/lib/solution/ScanOrder/utils.js +422 -385
  553. package/lib/solution/ShopDiscount/index.js +233 -235
  554. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  555. package/lib/solution/ShopDiscount/types.js +37 -15
  556. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  557. package/lib/solution/ShopDiscount/utils.js +172 -309
  558. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  559. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  560. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  561. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  562. package/lib/solution/VenueBooking/index.d.ts +32 -51
  563. package/lib/solution/VenueBooking/index.js +1008 -984
  564. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  565. package/lib/solution/VenueBooking/types.d.ts +1 -3
  566. package/lib/solution/VenueBooking/types.js +39 -20
  567. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  568. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  569. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  570. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  571. package/lib/solution/VenueBooking/utils/slotMerge.js +109 -90
  572. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  573. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  574. package/lib/solution/VenueBooking/utils.js +67 -130
  575. package/lib/solution/index.d.ts +2 -0
  576. package/lib/solution/index.js +41 -102
  577. package/lib/store/createStore.js +29 -32
  578. package/lib/types/index.d.ts +12 -2
  579. package/lib/types/index.js +16 -4
  580. package/lib/utils/task.js +36 -36
  581. package/lib/utils/watch.js +47 -81
  582. package/package.json +2 -4
  583. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  584. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  585. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  586. package/lib/solution/Checkout/appointmentDemo.json +0 -1
  587. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  588. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,12 +1,12 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
3
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
9
4
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
12
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
@@ -29,17 +29,17 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
29
29
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
30
30
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
31
31
  import { BaseModule } from "../../../modules/BaseModule";
32
- import { RequestModeENUM } from "../../../plugins";
32
+ import { QuotationModule as ClientQuotationModule } from "../../../modules/Quotation";
33
33
  import { ProductsHooks } from "./types";
34
34
  import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
35
-
36
35
  /**
37
36
  * IndexDB 存储名称
38
37
  */
39
38
  var INDEXDB_STORE_NAME = 'products';
40
-
41
39
  /** 商品同步防抖时间(毫秒) */
42
40
  var PRODUCT_SYNC_DEBOUNCE_MS = 10000;
41
+ /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
42
+ var PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
43
43
 
44
44
  /**
45
45
  * Products 模块 - 用于获取和管理完整的商品详细数据
@@ -68,12 +68,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
68
68
  // 最多缓存7天
69
69
  // 商品格式化器列表
70
70
  _defineProperty(_assertThisInitialized(_this), "formatters", []);
71
- // 是否已注册内置价格格式化器
72
- _defineProperty(_assertThisInitialized(_this), "isPriceFormatterRegistered", false);
71
+ // 是否已注册内置商品格式化器
72
+ _defineProperty(_assertThisInitialized(_this), "isBuiltinFormatterRegistered", false);
73
+ // 旧报价单格式化器默认关闭,仅显式开启时作为兼容兜底注册
74
+ _defineProperty(_assertThisInitialized(_this), "isLegacyPriceFormatterEnabled", false);
75
+ // 普通层 QuotationModule 桥接器:本地计算报价单价格,替代 /product/query/price
76
+ _defineProperty(_assertThisInitialized(_this), "quotationPriceBridge", void 0);
77
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeChannel", void 0);
78
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeLoadedKey", '');
79
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeRefreshPromise", void 0);
80
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeRefreshKey", void 0);
81
+ _defineProperty(_assertThisInitialized(_this), "quotationScheduleCache", new Map());
82
+ _defineProperty(_assertThisInitialized(_this), "quotationScheduleCacheSource", null);
83
+ _defineProperty(_assertThisInitialized(_this), "quotationScheduleCacheLoaded", false);
73
84
  // ---- 商品数据同步相关 ----
74
85
  _defineProperty(_assertThisInitialized(_this), "productDataSource", void 0);
75
86
  _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
76
87
  _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
88
+ /** 最近一次 SSE 全量拉取完成时间 */
89
+ _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
90
+ /** 最近一次 preload 完成时间(含 IndexDB 命中) */
91
+ _defineProperty(_assertThisInitialized(_this), "lastPreloadCompletedAtMs", 0);
92
+ /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
93
+ _defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
94
+ /** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
95
+ _defineProperty(_assertThisInitialized(_this), "lastScheduleTimePoints", []);
77
96
  return _this;
78
97
  }
79
98
  _createClass(ProductsModule, [{
@@ -105,13 +124,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
105
124
  app = appPlugin.getApp();
106
125
  this.dbManager = app.dbManager;
107
126
  this.logger = app.logger;
108
- if (this.dbManager) {} else {
127
+ if (this.dbManager) {
128
+ console.log('[Products] IndexDB Manager 已初始化');
129
+ } else {
109
130
  console.warn('[Products] IndexDB Manager 未找到');
110
131
  }
111
132
  }
112
133
 
113
- // 注册内置的价格格式化器(作为第一个格式化器)
114
- this.registerBuiltinPriceFormatter();
134
+ // 注册内置商品格式化器;智能定价默认替代报价单价格逻辑
135
+ this.registerBuiltinProductFormatters();
115
136
 
116
137
  // 初始化 ProductDataSource 实例
117
138
  this.initProductDataSource();
@@ -205,41 +226,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
205
226
  key: "loadProductsPrice",
206
227
  value: (function () {
207
228
  var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
208
- var _ref$ids, ids, customer_id, schedule_date, startTime, _productsData$data$le, _productsData$data, productsData, duration, _duration, errorMessage;
229
+ var _this2 = this;
230
+ var _ref$ids, ids, schedule_date, schedule_datetime, customer_id, startTime, datetime, idSet, products, priceData, duration, _duration, errorMessage;
209
231
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
210
232
  while (1) switch (_context2.prev = _context2.next) {
211
233
  case 0:
212
- _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date;
234
+ _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, schedule_date = _ref.schedule_date, schedule_datetime = _ref.schedule_datetime, customer_id = _ref.customer_id;
213
235
  this.logInfo('开始加载商品价格', {
214
236
  productCount: ids.length,
215
237
  schedule_date: schedule_date,
238
+ schedule_datetime: schedule_datetime,
216
239
  customer_id: customer_id
217
240
  });
218
241
  startTime = Date.now();
219
- _context2.prev = 3;
220
- _context2.next = 6;
221
- return this.request.post("/product/query/price", {
222
- ids: ids,
223
- customer_id: customer_id,
224
- schedule_date: schedule_date
225
- }, {
226
- cache: {
227
- mode: RequestModeENUM.REMOTE_LOCAL,
228
- type: "memory"
229
- }
242
+ datetime = schedule_datetime || schedule_date;
243
+ _context2.prev = 4;
244
+ _context2.next = 7;
245
+ return this.ensureQuotationBridgeReady(customer_id);
246
+ case 7:
247
+ idSet = new Set(ids);
248
+ products = this.getProductsRef().filter(function (product) {
249
+ return idSet.has(product.id);
250
+ });
251
+ priceData = products.map(function (product) {
252
+ return _this2.buildPriceDataFromQuotation(product, datetime, customer_id);
230
253
  });
231
- case 6:
232
- productsData = _context2.sent;
233
254
  duration = Date.now() - startTime;
234
255
  this.logInfo('加载商品价格成功', {
235
256
  productCount: ids.length,
236
- priceDataCount: (_productsData$data$le = (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.length) !== null && _productsData$data$le !== void 0 ? _productsData$data$le : 0,
257
+ priceDataCount: priceData.length,
237
258
  duration: "".concat(duration, "ms")
238
259
  });
239
- return _context2.abrupt("return", productsData.data);
240
- case 12:
241
- _context2.prev = 12;
242
- _context2.t0 = _context2["catch"](3);
260
+ return _context2.abrupt("return", priceData);
261
+ case 15:
262
+ _context2.prev = 15;
263
+ _context2.t0 = _context2["catch"](4);
243
264
  _duration = Date.now() - startTime;
244
265
  errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
245
266
  this.logError('加载商品价格失败', {
@@ -248,17 +269,310 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
248
269
  error: errorMessage
249
270
  });
250
271
  return _context2.abrupt("return", []);
251
- case 18:
272
+ case 21:
252
273
  case "end":
253
274
  return _context2.stop();
254
275
  }
255
- }, _callee2, this, [[3, 12]]);
276
+ }, _callee2, this, [[4, 15]]);
256
277
  }));
257
278
  function loadProductsPrice(_x3) {
258
279
  return _loadProductsPrice.apply(this, arguments);
259
280
  }
260
281
  return loadProductsPrice;
261
282
  }()
283
+ /**
284
+ * 设置报价单价格桥接器。
285
+ * Server 层负责传入完整 schedule 模块,Products 只负责把报价单计算结果转成价格响应形状。
286
+ */
287
+ )
288
+ }, {
289
+ key: "setupQuotationPriceBridge",
290
+ value: (function () {
291
+ var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
292
+ var _this$otherParams,
293
+ _this3 = this;
294
+ var channel, quotation;
295
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
296
+ while (1) switch (_context3.prev = _context3.next) {
297
+ case 0:
298
+ if (this.core) {
299
+ _context3.next = 3;
300
+ break;
301
+ }
302
+ this.logWarning('setupQuotationPriceBridge: core 尚未初始化');
303
+ return _context3.abrupt("return");
304
+ case 3:
305
+ channel = params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel);
306
+ this.quotationBridgeChannel = channel;
307
+ if (this.quotationPriceBridge) {
308
+ _context3.next = 10;
309
+ break;
310
+ }
311
+ quotation = new ClientQuotationModule("".concat(this.name, "_quotation_price_bridge"));
312
+ _context3.next = 9;
313
+ return quotation.initialize(this.core, {});
314
+ case 9:
315
+ this.quotationPriceBridge = quotation;
316
+ case 10:
317
+ if (params.scheduleModule) {
318
+ if (this.quotationScheduleCacheSource !== params.scheduleModule) {
319
+ this.quotationScheduleCache.clear();
320
+ this.quotationScheduleCacheLoaded = false;
321
+ this.quotationScheduleCacheSource = params.scheduleModule;
322
+ }
323
+ this.quotationPriceBridge.setScheduleResolver(function (id) {
324
+ var _params$scheduleModul3, _params$scheduleModul4, _params$scheduleModul5, _params$scheduleModul6;
325
+ var scheduleId = String(id);
326
+ if (_this3.quotationScheduleCache.has(scheduleId)) {
327
+ return _this3.quotationScheduleCache.get(scheduleId);
328
+ }
329
+ if (!_this3.quotationScheduleCacheLoaded) {
330
+ var _params$scheduleModul, _params$scheduleModul2;
331
+ var scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
332
+ var _iterator = _createForOfIteratorHelper(scheduleList),
333
+ _step;
334
+ try {
335
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
336
+ var schedule = _step.value;
337
+ _this3.quotationScheduleCache.set(String(schedule.id), schedule);
338
+ }
339
+ } catch (err) {
340
+ _iterator.e(err);
341
+ } finally {
342
+ _iterator.f();
343
+ }
344
+ _this3.quotationScheduleCacheLoaded = true;
345
+ }
346
+ if (_this3.quotationScheduleCache.has(scheduleId)) {
347
+ return _this3.quotationScheduleCache.get(scheduleId);
348
+ }
349
+ 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])) || [];
350
+ if (schedules[0]) _this3.quotationScheduleCache.set(scheduleId, schedules[0]);
351
+ return schedules[0];
352
+ });
353
+ }
354
+ _context3.next = 13;
355
+ return this.refreshQuotationPriceBridge({
356
+ customer_id: params.customer_id
357
+ });
358
+ case 13:
359
+ case "end":
360
+ return _context3.stop();
361
+ }
362
+ }, _callee3, this);
363
+ }));
364
+ function setupQuotationPriceBridge(_x4) {
365
+ return _setupQuotationPriceBridge.apply(this, arguments);
366
+ }
367
+ return setupQuotationPriceBridge;
368
+ }()
369
+ /**
370
+ * 刷新桥接器内的报价单列表。
371
+ */
372
+ )
373
+ }, {
374
+ key: "refreshQuotationPriceBridge",
375
+ value: (function () {
376
+ var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
377
+ var _this4 = this;
378
+ var refreshKey;
379
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
380
+ while (1) switch (_context4.prev = _context4.next) {
381
+ case 0:
382
+ if (this.quotationPriceBridge) {
383
+ _context4.next = 2;
384
+ break;
385
+ }
386
+ return _context4.abrupt("return");
387
+ case 2:
388
+ refreshKey = this.getQuotationBridgeScopeKey();
389
+ if (!(this.quotationBridgeRefreshPromise && this.quotationBridgeRefreshKey === refreshKey)) {
390
+ _context4.next = 7;
391
+ break;
392
+ }
393
+ _context4.next = 6;
394
+ return this.quotationBridgeRefreshPromise;
395
+ case 6:
396
+ return _context4.abrupt("return");
397
+ case 7:
398
+ if (!this.quotationBridgeRefreshPromise) {
399
+ _context4.next = 10;
400
+ break;
401
+ }
402
+ _context4.next = 10;
403
+ return this.quotationBridgeRefreshPromise;
404
+ case 10:
405
+ this.quotationBridgeRefreshKey = refreshKey;
406
+ this.quotationBridgeRefreshPromise = this.quotationPriceBridge.loadQuotations({
407
+ channel: this.quotationBridgeChannel
408
+ }).then(function () {
409
+ _this4.quotationBridgeLoadedKey = refreshKey;
410
+ }).finally(function () {
411
+ _this4.quotationBridgeRefreshPromise = undefined;
412
+ _this4.quotationBridgeRefreshKey = undefined;
413
+ });
414
+ _context4.next = 14;
415
+ return this.quotationBridgeRefreshPromise;
416
+ case 14:
417
+ case "end":
418
+ return _context4.stop();
419
+ }
420
+ }, _callee4, this);
421
+ }));
422
+ function refreshQuotationPriceBridge(_x5) {
423
+ return _refreshQuotationPriceBridge.apply(this, arguments);
424
+ }
425
+ return refreshQuotationPriceBridge;
426
+ }())
427
+ }, {
428
+ key: "ensureQuotationBridgeReady",
429
+ value: function () {
430
+ var _ensureQuotationBridgeReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(customerId) {
431
+ var _this$otherParams2;
432
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
433
+ while (1) switch (_context5.prev = _context5.next) {
434
+ case 0:
435
+ if (this.quotationPriceBridge) {
436
+ _context5.next = 4;
437
+ break;
438
+ }
439
+ _context5.next = 3;
440
+ return this.setupQuotationPriceBridge({
441
+ channel: (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel,
442
+ customer_id: customerId
443
+ });
444
+ case 3:
445
+ return _context5.abrupt("return");
446
+ case 4:
447
+ if (!this.quotationBridgeRefreshPromise) {
448
+ _context5.next = 7;
449
+ break;
450
+ }
451
+ _context5.next = 7;
452
+ return this.quotationBridgeRefreshPromise;
453
+ case 7:
454
+ if (!(this.getQuotationBridgeScopeKey() !== this.quotationBridgeLoadedKey)) {
455
+ _context5.next = 10;
456
+ break;
457
+ }
458
+ _context5.next = 10;
459
+ return this.refreshQuotationPriceBridge({
460
+ customer_id: customerId
461
+ });
462
+ case 10:
463
+ case "end":
464
+ return _context5.stop();
465
+ }
466
+ }, _callee5, this);
467
+ }));
468
+ function ensureQuotationBridgeReady(_x6) {
469
+ return _ensureQuotationBridgeReady.apply(this, arguments);
470
+ }
471
+ return ensureQuotationBridgeReady;
472
+ }()
473
+ }, {
474
+ key: "getQuotationBridgeScopeKey",
475
+ value: function getQuotationBridgeScopeKey() {
476
+ return this.quotationBridgeChannel || '';
477
+ }
478
+ }, {
479
+ key: "getQuotedPrice",
480
+ value: function getQuotedPrice(params) {
481
+ var quotation = this.quotationPriceBridge;
482
+ if (!quotation) return null;
483
+ var query = {
484
+ productId: params.productId,
485
+ variantId: params.variantId,
486
+ datetime: params.datetime,
487
+ customer_id: params.customerId
488
+ };
489
+ if (typeof quotation.getQuotationMatchForProduct === 'function') {
490
+ var _quotation$getQuotati, _quotation$getQuotati2;
491
+ return (_quotation$getQuotati = (_quotation$getQuotati2 = quotation.getQuotationMatchForProduct(query)) === null || _quotation$getQuotati2 === void 0 ? void 0 : _quotation$getQuotati2.price) !== null && _quotation$getQuotati !== void 0 ? _quotation$getQuotati : null;
492
+ }
493
+ if (typeof quotation.getPriceForProduct === 'function') {
494
+ return quotation.getPriceForProduct(query);
495
+ }
496
+ return null;
497
+ }
498
+ }, {
499
+ key: "buildPriceDataFromQuotation",
500
+ value: function buildPriceDataFromQuotation(product, datetime, customerId) {
501
+ var _ref2, _ref3;
502
+ var quotedPrice = this.getQuotedPrice({
503
+ productId: product.id,
504
+ datetime: datetime,
505
+ customerId: customerId
506
+ });
507
+ var productPrice = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.price;
508
+ 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;
509
+ return {
510
+ id: product.id,
511
+ price: String(productPrice !== null && productPrice !== void 0 ? productPrice : 0),
512
+ base_price: String(productBasePrice),
513
+ variant: this.buildVariantPriceData(product, datetime, customerId),
514
+ bundle_group: this.buildBundleGroupPriceData(product, datetime, customerId)
515
+ };
516
+ }
517
+ }, {
518
+ key: "buildVariantPriceData",
519
+ value: function buildVariantPriceData(product, datetime, customerId) {
520
+ var _this5 = this;
521
+ if (!Array.isArray(product.variant)) return [];
522
+ return product.variant.map(function (variant) {
523
+ var _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _variant$product_id;
524
+ var quotedPrice = _this5.getQuotedPrice({
525
+ productId: product.id,
526
+ variantId: Number(variant.id),
527
+ datetime: datetime,
528
+ customerId: customerId
529
+ });
530
+ 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;
531
+ 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;
532
+ return {
533
+ id: Number(variant.id),
534
+ product_id: Number((_variant$product_id = variant.product_id) !== null && _variant$product_id !== void 0 ? _variant$product_id : product.id),
535
+ base_price: Number(basePrice),
536
+ price: Number(price)
537
+ };
538
+ });
539
+ }
540
+ }, {
541
+ key: "buildBundleGroupPriceData",
542
+ value: function buildBundleGroupPriceData(product, datetime, customerId) {
543
+ var _this6 = this;
544
+ if (!Array.isArray(product.bundle_group)) return [];
545
+ return product.bundle_group.map(function (group) {
546
+ return {
547
+ id: Number(group.id),
548
+ bundle_item: (group.bundle_item || []).map(function (item) {
549
+ var _ref10, _ref11, _ref12, _item$product_id, _item$group_id;
550
+ var bundleProductId = Number(item.bundle_product_id);
551
+ var bundleVariantId = Number(item.bundle_variant_id || 0);
552
+ var quotedPrice = _this6.getQuotedPrice({
553
+ productId: bundleProductId,
554
+ variantId: bundleVariantId,
555
+ datetime: datetime,
556
+ customerId: customerId
557
+ });
558
+ var price = (_ref10 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0;
559
+ 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;
560
+ return {
561
+ id: Number(item.id),
562
+ product_id: Number((_item$product_id = item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : product.id),
563
+ group_id: Number((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group.id),
564
+ bundle_product_id: bundleProductId,
565
+ bundle_variant_id: bundleVariantId,
566
+ price: Number(price),
567
+ base_price: basePrice,
568
+ price_type: item.price_type,
569
+ price_type_ext: item.price_type_ext
570
+ };
571
+ })
572
+ };
573
+ });
574
+ }
575
+
262
576
  /**
263
577
  * 获取应用了价格的商品列表(带缓存)
264
578
  * 使用日期作为缓存 key,同一天的商品价格会被缓存
@@ -267,27 +581,32 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
267
581
  * @param extraContext 额外的上下文数据(可选,由 Server 层传入)
268
582
  * @param options 可选参数
269
583
  * @param options.changedIds 变更的商品 IDs,非空时仅对这些商品增量执行 prepare 并更新缓存
584
+ * @param options.productIds 指定商品 IDs,仅对这些商品执行价格计算;不传则处理全量
270
585
  * @returns 应用了价格的商品列表
271
586
  */
272
- )
273
587
  }, {
274
588
  key: "getProductsWithPrice",
275
589
  value: (function () {
276
- var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext, options) {
277
- var t0, cacheKey, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator, _step, p, _iterator2, _step2, _p, errorMessage, result;
278
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
279
- while (1) switch (_context3.prev = _context3.next) {
590
+ var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schedule_date, extraContext, options) {
591
+ var _options$changedIds;
592
+ var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator2, _step2, p, _iterator3, _step3, _p, errorMessage, result;
593
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
594
+ while (1) switch (_context6.prev = _context6.next) {
280
595
  case 0:
281
596
  t0 = performance.now();
282
- cacheKey = schedule_date;
283
- changedIds = options === null || options === void 0 ? void 0 : options.changedIds;
597
+ scopedProductIds = this.normalizeProductIds(options === null || options === void 0 ? void 0 : options.productIds);
598
+ cacheKey = this.getProductsPriceCacheKey(schedule_date, extraContext, scopedProductIds);
599
+ scopedProductIdSet = scopedProductIds ? new Set(scopedProductIds) : undefined;
600
+ changedIds = scopedProductIdSet ? options === null || options === void 0 || (_options$changedIds = options.changedIds) === null || _options$changedIds === void 0 ? void 0 : _options$changedIds.filter(function (id) {
601
+ return scopedProductIdSet.has(id);
602
+ }) : options === null || options === void 0 ? void 0 : options.changedIds;
284
603
  if (!this.productsPriceCache.has(cacheKey)) {
285
- _context3.next = 33;
604
+ _context6.next = 35;
286
605
  break;
287
606
  }
288
607
  cachedProducts = this.productsPriceCache.get(cacheKey); // 有变更的商品 → 增量 prepare 后 merge 回缓存
289
608
  if (!(changedIds && changedIds.length > 0)) {
290
- _context3.next = 30;
609
+ _context6.next = 32;
291
610
  break;
292
611
  }
293
612
  this.logInfo('商品价格缓存命中,增量更新变更商品', {
@@ -295,15 +614,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
295
614
  changedIds: changedIds,
296
615
  cachedProductCount: cachedProducts.length
297
616
  });
298
- _context3.prev = 7;
299
- _context3.next = 10;
617
+ _context6.prev = 9;
618
+ _context6.next = 12;
300
619
  return this.prepareProductsWithPrice(schedule_date, extraContext, {
301
620
  productIds: changedIds
302
621
  });
303
- case 10:
304
- updatedProducts = _context3.sent;
622
+ case 12:
623
+ updatedProducts = _context6.sent;
305
624
  if (!(updatedProducts.length > 0)) {
306
- _context3.next = 22;
625
+ _context6.next = 24;
307
626
  break;
308
627
  }
309
628
  // merge:用更新结果替换缓存中对应的商品,新增的追加
@@ -311,10 +630,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
311
630
  return [p.id, p];
312
631
  }));
313
632
  mergedCache = [];
314
- _iterator = _createForOfIteratorHelper(cachedProducts);
633
+ _iterator2 = _createForOfIteratorHelper(cachedProducts);
315
634
  try {
316
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
317
- p = _step.value;
635
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
636
+ p = _step2.value;
318
637
  if (updatedMap.has(p.id)) {
319
638
  mergedCache.push(updatedMap.get(p.id));
320
639
  updatedMap.delete(p.id);
@@ -324,20 +643,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
324
643
  }
325
644
  // 剩余的是新增商品(create 场景)
326
645
  } catch (err) {
327
- _iterator.e(err);
646
+ _iterator2.e(err);
328
647
  } finally {
329
- _iterator.f();
648
+ _iterator2.f();
330
649
  }
331
- _iterator2 = _createForOfIteratorHelper(updatedMap.values());
650
+ _iterator3 = _createForOfIteratorHelper(updatedMap.values());
332
651
  try {
333
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
334
- _p = _step2.value;
652
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
653
+ _p = _step3.value;
335
654
  mergedCache.push(_p);
336
655
  }
337
656
  } catch (err) {
338
- _iterator2.e(err);
657
+ _iterator3.e(err);
339
658
  } finally {
340
- _iterator2.f();
659
+ _iterator3.f();
341
660
  }
342
661
  this.productsPriceCache.set(cacheKey, mergedCache);
343
662
  this.logInfo('增量更新完成', {
@@ -350,27 +669,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
350
669
  changedCount: changedIds.length,
351
670
  count: mergedCache.length
352
671
  });
353
- return _context3.abrupt("return", mergedCache);
354
- case 22:
355
- _context3.next = 28;
356
- break;
672
+ return _context6.abrupt("return", mergedCache);
357
673
  case 24:
358
- _context3.prev = 24;
359
- _context3.t0 = _context3["catch"](7);
360
- errorMessage = _context3.t0 instanceof Error ? _context3.t0.message : String(_context3.t0);
674
+ _context6.next = 30;
675
+ break;
676
+ case 26:
677
+ _context6.prev = 26;
678
+ _context6.t0 = _context6["catch"](9);
679
+ errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
361
680
  this.logError('增量更新失败,返回现有缓存', {
362
681
  cacheKey: cacheKey,
363
682
  changedIds: changedIds,
364
683
  error: errorMessage
365
684
  });
366
- case 28:
685
+ case 30:
367
686
  perfMark('getProductsWithPrice(incrementalUpdate)', performance.now() - t0, {
368
687
  cacheKey: cacheKey,
369
688
  changedCount: changedIds.length,
370
689
  count: cachedProducts.length
371
690
  });
372
- return _context3.abrupt("return", cachedProducts);
373
- case 30:
691
+ return _context6.abrupt("return", cachedProducts);
692
+ case 32:
374
693
  perfMark('getProductsWithPrice(cacheHit)', performance.now() - t0, {
375
694
  cacheKey: cacheKey,
376
695
  count: cachedProducts.length
@@ -379,15 +698,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
379
698
  cacheKey: cacheKey,
380
699
  productCount: cachedProducts.length
381
700
  });
382
- return _context3.abrupt("return", cachedProducts);
383
- case 33:
701
+ return _context6.abrupt("return", cachedProducts);
702
+ case 35:
384
703
  this.logInfo('商品价格缓存未命中,准备获取', {
385
- cacheKey: cacheKey
704
+ cacheKey: cacheKey,
705
+ scopedProductCount: scopedProductIds === null || scopedProductIds === void 0 ? void 0 : scopedProductIds.length
386
706
  });
387
- _context3.next = 36;
388
- return this.prepareProductsWithPrice(schedule_date, extraContext);
389
- case 36:
390
- result = _context3.sent;
707
+ _context6.next = 38;
708
+ return this.prepareProductsWithPrice(schedule_date, extraContext, scopedProductIds ? {
709
+ productIds: scopedProductIds
710
+ } : undefined);
711
+ case 38:
712
+ result = _context6.sent;
391
713
  this.productsPriceCache.set(cacheKey, result);
392
714
  this.logInfo('商品价格已缓存', {
393
715
  cacheKey: cacheKey,
@@ -398,14 +720,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
398
720
  cacheKey: cacheKey,
399
721
  count: result.length
400
722
  });
401
- return _context3.abrupt("return", result);
402
- case 42:
723
+ return _context6.abrupt("return", result);
724
+ case 44:
403
725
  case "end":
404
- return _context3.stop();
726
+ return _context6.stop();
405
727
  }
406
- }, _callee3, this, [[7, 24]]);
728
+ }, _callee6, this, [[9, 26]]);
407
729
  }));
408
- function getProductsWithPrice(_x4, _x5, _x6) {
730
+ function getProductsWithPrice(_x7, _x8, _x9) {
409
731
  return _getProductsWithPrice.apply(this, arguments);
410
732
  }
411
733
  return getProductsWithPrice;
@@ -423,27 +745,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
423
745
  }, {
424
746
  key: "prepareProductsWithPrice",
425
747
  value: (function () {
426
- var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext, options) {
427
- var tTotal, targetIds, isIncremental, _priceData$length, _this$core, products, ids, idSet, tIds, i, tPrice, priceData, context, tFormat, processedProducts, errorMessage;
428
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
429
- while (1) switch (_context4.prev = _context4.next) {
748
+ var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(schedule_date, extraContext, options) {
749
+ var tTotal, targetIds, isIncremental, _this$core, _this$core2, products, ids, tIds, i, priceData, _priceData$length, _priceData, tPrice, context, tFormat, processedProducts, errorMessage;
750
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
751
+ while (1) switch (_context7.prev = _context7.next) {
430
752
  case 0:
431
753
  tTotal = performance.now();
432
754
  targetIds = options === null || options === void 0 ? void 0 : options.productIds;
433
- isIncremental = targetIds && targetIds.length > 0;
755
+ isIncremental = Array.isArray(targetIds);
434
756
  this.logInfo('prepareProductsWithPrice 开始处理', {
435
757
  schedule_date: schedule_date,
436
758
  mode: isIncremental ? 'incremental' : 'full',
437
759
  targetIdsCount: targetIds === null || targetIds === void 0 ? void 0 : targetIds.length
438
760
  });
439
- _context4.prev = 4;
761
+ _context7.prev = 4;
440
762
  // 1. 获取商品列表:指定 IDs 时从 store 取子集,否则取全量
441
763
 
442
764
  if (isIncremental) {
443
- idSet = new Set(targetIds);
444
- products = this.getProductsRef().filter(function (p) {
445
- return idSet.has(p.id);
446
- });
765
+ products = this.getProductsRefByIds(targetIds);
447
766
  ids = products.map(function (p) {
448
767
  return p.id;
449
768
  });
@@ -462,31 +781,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
462
781
  productCount: products.length
463
782
  });
464
783
 
465
- // 2. 获取价格数据(网络请求)
784
+ // 2. 仅在 legacy 报价单 formatter 启用时加载报价单价格;默认由智能定价覆盖商品价格。
785
+ priceData = [];
786
+ if (!this.isLegacyPriceFormatterEnabled) {
787
+ _context7.next = 15;
788
+ break;
789
+ }
466
790
  tPrice = performance.now();
467
- _context4.next = 10;
791
+ _context7.next = 12;
468
792
  return this.loadProductsPrice({
469
793
  ids: ids,
470
- schedule_date: schedule_date
794
+ schedule_date: schedule_date,
795
+ schedule_datetime: extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime,
796
+ customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id
471
797
  });
472
- case 10:
473
- priceData = _context4.sent;
798
+ case 12:
799
+ priceData = _context7.sent;
474
800
  perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
475
801
  count: ids.length
476
802
  });
477
803
  this.logInfo('获取商品报价单价格成功', {
478
- priceDataCount: (_priceData$length = priceData === null || priceData === void 0 ? void 0 : priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
804
+ priceDataCount: (_priceData$length = (_priceData = priceData) === null || _priceData === void 0 ? void 0 : _priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
479
805
  });
806
+ case 15:
480
807
  context = _objectSpread({
481
808
  schedule_date: schedule_date,
809
+ schedule_datetime: extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime,
810
+ customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id,
482
811
  priceData: priceData,
483
- locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale
812
+ locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale,
813
+ dataVariantEvaluator: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.dataVariantEvaluator) || ((_this$core2 = this.core) === null || _this$core2 === void 0 || (_this$core2 = _this$core2.context) === null || _this$core2 === void 0 ? void 0 : _this$core2.dataVariantEvaluator),
814
+ menuList: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.menuList) || [],
815
+ scheduleList: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.scheduleList) || [],
816
+ strategy_context: extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context
484
817
  }, extraContext); // 3. 通过格式化器流程处理商品
485
818
  tFormat = performance.now();
486
- _context4.next = 17;
819
+ _context7.next = 19;
487
820
  return this.applyFormatters(products, context);
488
- case 17:
489
- processedProducts = _context4.sent;
821
+ case 19:
822
+ processedProducts = _context7.sent;
490
823
  perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
491
824
  count: products.length,
492
825
  formatterCount: this.formatters.length
@@ -498,39 +831,130 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
498
831
  formatterCount: this.formatters.length
499
832
  });
500
833
  if (isIncremental) {
501
- _context4.next = 23;
834
+ _context7.next = 25;
502
835
  break;
503
836
  }
504
- _context4.next = 23;
837
+ _context7.next = 25;
505
838
  return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
506
- case 23:
839
+ case 25:
507
840
  perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
508
841
  productCount: products.length,
509
842
  formatterCount: this.formatters.length,
510
843
  mode: isIncremental ? 'incremental' : 'full'
511
844
  });
512
- return _context4.abrupt("return", processedProducts);
513
- case 27:
514
- _context4.prev = 27;
515
- _context4.t0 = _context4["catch"](4);
516
- errorMessage = _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0);
845
+ return _context7.abrupt("return", processedProducts);
846
+ case 29:
847
+ _context7.prev = 29;
848
+ _context7.t0 = _context7["catch"](4);
849
+ errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
850
+ console.log("[ProductsModule] \uD83C\uDF10 ERROR", _context7.t0);
517
851
  this.logError('prepareProductsWithPrice 处理失败', {
518
852
  schedule_date: schedule_date,
519
853
  error: errorMessage
520
854
  });
521
- case 31:
522
- return _context4.abrupt("return", []);
523
- case 32:
855
+ case 34:
856
+ return _context7.abrupt("return", []);
857
+ case 35:
524
858
  case "end":
525
- return _context4.stop();
859
+ return _context7.stop();
526
860
  }
527
- }, _callee4, this, [[4, 27]]);
861
+ }, _callee7, this, [[4, 29]]);
528
862
  }));
529
- function prepareProductsWithPrice(_x7, _x8, _x9) {
863
+ function prepareProductsWithPrice(_x10, _x11, _x12) {
530
864
  return _prepareProductsWithPrice.apply(this, arguments);
531
865
  }
532
866
  return prepareProductsWithPrice;
533
- }()
867
+ }())
868
+ }, {
869
+ key: "getProductsPriceCacheKey",
870
+ value: function getProductsPriceCacheKey(schedule_date, extraContext, productIds) {
871
+ var _extraContext$custome;
872
+ var datetime = (extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime) || schedule_date;
873
+ var productScope = productIds ? ":products:".concat(productIds.join(',')) : '';
874
+ var strategyScope = this.stringifyStable((extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context) || {});
875
+ return "".concat(datetime, ":customer:").concat((_extraContext$custome = extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id) !== null && _extraContext$custome !== void 0 ? _extraContext$custome : '', ":strategy:").concat(strategyScope).concat(productScope);
876
+ }
877
+
878
+ /**
879
+ * 稳定序列化策略上下文,避免对象 key 顺序不同导致缓存 key 抖动。
880
+ */
881
+ }, {
882
+ key: "stringifyStable",
883
+ value: function stringifyStable(value) {
884
+ var _this7 = this;
885
+ if (value == null) return '';
886
+ if (Array.isArray(value)) return "[".concat(value.map(function (item) {
887
+ return _this7.stringifyStable(item);
888
+ }).join(','), "]");
889
+ if (_typeof(value) === 'object') {
890
+ return "{".concat(Object.keys(value).sort().map(function (key) {
891
+ return "".concat(key, ":").concat(_this7.stringifyStable(value[key]));
892
+ }).join(','), "}");
893
+ }
894
+ return String(value);
895
+ }
896
+ }, {
897
+ key: "normalizeProductIds",
898
+ value: function normalizeProductIds(productIds) {
899
+ if (!Array.isArray(productIds)) return undefined;
900
+ return Array.from(new Set(productIds.map(function (id) {
901
+ return Number(id);
902
+ }).filter(function (id) {
903
+ return Number.isFinite(id);
904
+ }))).sort(function (a, b) {
905
+ return a - b;
906
+ });
907
+ }
908
+
909
+ /**
910
+ * 按轻量范围返回商品 ID,不做 structuredClone。
911
+ */
912
+ }, {
913
+ key: "getProductIdsByScope",
914
+ value: function getProductIdsByScope(scope) {
915
+ var productIds = this.normalizeProductIds(scope.productIds) || [];
916
+ var collectionIds = this.normalizeProductIds(scope.collectionIds) || [];
917
+ if (scope.isAllProducts) {
918
+ return this.getProductsRef().map(function (product) {
919
+ return product.id;
920
+ });
921
+ }
922
+ if (productIds.length === 0 && collectionIds.length === 0) return [];
923
+ var result = new Set();
924
+ var _iterator4 = _createForOfIteratorHelper(productIds),
925
+ _step4;
926
+ try {
927
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
928
+ var id = _step4.value;
929
+ if (this.store.map.has(id)) result.add(id);
930
+ }
931
+ } catch (err) {
932
+ _iterator4.e(err);
933
+ } finally {
934
+ _iterator4.f();
935
+ }
936
+ if (collectionIds.length === 0) return Array.from(result);
937
+ var collectionIdSet = new Set(collectionIds);
938
+ var _iterator5 = _createForOfIteratorHelper(this.getProductsRef()),
939
+ _step5;
940
+ try {
941
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
942
+ var product = _step5.value;
943
+ if (result.has(product.id)) continue;
944
+ if (!Array.isArray(product.collection)) continue;
945
+ var isInCollection = product.collection.some(function (collection) {
946
+ return collectionIdSet.has(collection.id);
947
+ });
948
+ if (isInCollection) result.add(product.id);
949
+ }
950
+ } catch (err) {
951
+ _iterator5.e(err);
952
+ } finally {
953
+ _iterator5.f();
954
+ }
955
+ return Array.from(result);
956
+ }
957
+
534
958
  /**
535
959
  * 应用所有已注册的格式化器
536
960
  * @param products 商品列表
@@ -538,25 +962,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
538
962
  * @returns 格式化后的商品列表
539
963
  * @private
540
964
  */
541
- )
542
965
  }, {
543
966
  key: "applyFormatters",
544
967
  value: (function () {
545
- var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products, context) {
968
+ var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(products, context) {
546
969
  var result, i, formatter, tF, errorMessage;
547
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
548
- while (1) switch (_context5.prev = _context5.next) {
970
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
971
+ while (1) switch (_context8.prev = _context8.next) {
549
972
  case 0:
550
973
  result = products;
551
974
  if (!(this.formatters.length === 0)) {
552
- _context5.next = 5;
975
+ _context8.next = 5;
553
976
  break;
554
977
  }
555
978
  console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
556
979
  this.logWarning('没有注册任何格式化器', {
557
980
  productCount: products.length
558
981
  });
559
- return _context5.abrupt("return", result);
982
+ return _context8.abrupt("return", result);
560
983
  case 5:
561
984
  this.logInfo('开始应用格式化器', {
562
985
  productCount: products.length,
@@ -565,28 +988,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
565
988
  i = 0;
566
989
  case 7:
567
990
  if (!(i < this.formatters.length)) {
568
- _context5.next = 25;
991
+ _context8.next = 25;
569
992
  break;
570
993
  }
571
994
  formatter = this.formatters[i];
572
- _context5.prev = 9;
995
+ _context8.prev = 9;
573
996
  tF = performance.now();
574
- _context5.next = 13;
997
+ _context8.next = 13;
575
998
  return formatter(result, context);
576
999
  case 13:
577
- result = _context5.sent;
1000
+ result = _context8.sent;
578
1001
  perfMark("applyFormatters[".concat(i, "]"), performance.now() - tF, {
579
1002
  index: i,
580
1003
  total: this.formatters.length,
581
1004
  productCount: result.length
582
1005
  });
583
- _context5.next = 22;
1006
+ _context8.next = 22;
584
1007
  break;
585
1008
  case 17:
586
- _context5.prev = 17;
587
- _context5.t0 = _context5["catch"](9);
588
- errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
589
- console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context5.t0);
1009
+ _context8.prev = 17;
1010
+ _context8.t0 = _context8["catch"](9);
1011
+ errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
1012
+ console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context8.t0);
590
1013
  this.logError("\u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25"), {
591
1014
  formatterIndex: i + 1,
592
1015
  totalFormatters: this.formatters.length,
@@ -594,44 +1017,76 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
594
1017
  });
595
1018
  case 22:
596
1019
  i++;
597
- _context5.next = 7;
1020
+ _context8.next = 7;
598
1021
  break;
599
1022
  case 25:
600
1023
  this.logInfo('所有格式化器已应用', {
601
1024
  formatterCount: this.formatters.length,
602
1025
  resultProductCount: result.length
603
1026
  });
604
- return _context5.abrupt("return", result);
1027
+ return _context8.abrupt("return", result);
605
1028
  case 27:
606
1029
  case "end":
607
- return _context5.stop();
1030
+ return _context8.stop();
608
1031
  }
609
- }, _callee5, this, [[9, 17]]);
1032
+ }, _callee8, this, [[9, 17]]);
610
1033
  }));
611
- function applyFormatters(_x10, _x11) {
1034
+ function applyFormatters(_x13, _x14) {
612
1035
  return _applyFormatters.apply(this, arguments);
613
1036
  }
614
1037
  return applyFormatters;
615
1038
  }()
616
1039
  /**
617
- * 注册内置的价格格式化器
618
- * 这个格式化器负责将价格数据应用到商品上
1040
+ * 注册内置商品格式化器。
1041
+ *
1042
+ * 智能定价默认替代报价单逻辑;报价单 formatter 仅在 enableLegacyPriceFormatter=true 时启用。
619
1043
  * @private
620
1044
  */
621
1045
  )
622
1046
  }, {
623
- key: "registerBuiltinPriceFormatter",
624
- value: function registerBuiltinPriceFormatter() {
625
- if (this.isPriceFormatterRegistered) {
626
- console.warn('[ProductsModule] 内置价格格式化器已注册,跳过');
1047
+ key: "registerBuiltinProductFormatters",
1048
+ value: function registerBuiltinProductFormatters() {
1049
+ var _this8 = this;
1050
+ if (this.isBuiltinFormatterRegistered) {
1051
+ console.warn('[ProductsModule] 内置商品格式化器已注册,跳过');
627
1052
  return;
628
1053
  }
1054
+ this.isLegacyPriceFormatterEnabled = this.shouldEnableLegacyPriceFormatter();
1055
+ var dataVariantFormatter = function dataVariantFormatter(products, context) {
1056
+ var _this8$core, _strategyContext$busi;
1057
+ var evaluator = context.dataVariantEvaluator || ((_this8$core = _this8.core) === null || _this8$core === void 0 || (_this8$core = _this8$core.context) === null || _this8$core === void 0 ? void 0 : _this8$core.dataVariantEvaluator);
1058
+ if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
1059
+ _this8.lastScheduleTimePoints = [];
1060
+ _this8.logWarning('智能定价评估器未注入,跳过 DataVariant 格式化', {
1061
+ productCount: products.length
1062
+ });
1063
+ return products;
1064
+ }
1065
+ var strategyContext = context.strategy_context || {};
1066
+ var businessData = {
1067
+ products: products,
1068
+ scheduleDateTime: context.schedule_datetime || context.schedule_date,
1069
+ scheduleList: context.scheduleList || [],
1070
+ menuList: context.menuList || [],
1071
+ customerId: context.customer_id,
1072
+ channel: strategyContext.channel,
1073
+ orderType: strategyContext.orderType || strategyContext.order_type,
1074
+ businessCode: (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : strategyContext.businessCode,
1075
+ availableWalletIds: strategyContext.available_wallet_ids,
1076
+ custom: strategyContext
1077
+ };
1078
+ var result = evaluator.resolveProducts(businessData);
1079
+ _this8.lastScheduleTimePoints = Array.isArray(result === null || result === void 0 ? void 0 : result.scheduleTimePoints) ? _toConsumableArray(result.scheduleTimePoints) : [];
1080
+ return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
1081
+ };
629
1082
 
630
- // 创建价格格式化器
631
- var priceFormatter = function priceFormatter(products, context) {
1083
+ // 创建 legacy 报价单格式化器
1084
+ var legacyPriceFormatter = function legacyPriceFormatter(products, context) {
632
1085
  if (!context.priceData || context.priceData.length === 0) {
1086
+ console.log('[ProductsModule] 💰 没有价格数据,跳过 legacy 报价单价格应用');
633
1087
  return products;
634
1088
  }
1089
+ console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528 legacy \u62A5\u4EF7\u5355\u4EF7\u683C\u5230 ".concat(products.length, " \u4E2A\u5546\u54C1"));
635
1090
  return applyPriceDataToProducts(products, context.priceData);
636
1091
  };
637
1092
  var i18nFormatter = function i18nFormatter(products, context) {
@@ -640,17 +1095,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
640
1095
  var detailValueFormatter = function detailValueFormatter(products, context) {
641
1096
  return applyDetailValueToProducts(products, context);
642
1097
  };
643
-
644
- // 将价格格式化器注册为第一个格式化器
645
- this.formatters.unshift(priceFormatter);
1098
+ if (this.isLegacyPriceFormatterEnabled) {
1099
+ this.formatters.push(legacyPriceFormatter);
1100
+ }
1101
+ this.formatters.push(dataVariantFormatter);
646
1102
  this.formatters.push(i18nFormatter);
647
1103
  this.formatters.push(detailValueFormatter);
648
- this.isPriceFormatterRegistered = true;
1104
+ this.isBuiltinFormatterRegistered = true;
1105
+ console.log('[ProductsModule] ✅ 内置商品格式化器已注册(智能定价优先)');
1106
+ }
1107
+
1108
+ /**
1109
+ * 是否启用旧报价单价格 formatter。
1110
+ *
1111
+ * 默认关闭,避免报价单逻辑覆盖智能定价结果。
1112
+ */
1113
+ }, {
1114
+ key: "shouldEnableLegacyPriceFormatter",
1115
+ value: function shouldEnableLegacyPriceFormatter() {
1116
+ var _this$otherParams3, _this$core3;
1117
+ return ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.enableLegacyPriceFormatter) === true || ((_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.enableLegacyPriceFormatter) === true;
1118
+ }
1119
+
1120
+ /**
1121
+ * 返回最近一次 prepareProductsWithPrice / DataVariant 评估提取的变价时间点(HH:mm)。
1122
+ * 供 OS Server 商品 query 订阅定时刷新使用。
1123
+ */
1124
+ }, {
1125
+ key: "getLastScheduleTimePoints",
1126
+ value: function getLastScheduleTimePoints() {
1127
+ return _toConsumableArray(this.lastScheduleTimePoints);
649
1128
  }
650
1129
 
651
1130
  /**
652
1131
  * 注册商品格式化器
653
- * 格式化器会按注册顺序依次执行(内置价格格式化器始终是第一个)
1132
+ * 格式化器会按注册顺序依次执行;legacy 启用时先兜底报价,再由智能定价覆盖。
654
1133
  * @param formatter 格式化函数
655
1134
  * @param prepend 是否插入到队列开头(默认 false,追加到末尾)
656
1135
  * @example
@@ -668,29 +1147,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
668
1147
  value: function registerFormatter(formatter) {
669
1148
  var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
670
1149
  if (prepend) {
671
- // 插入到价格格式化器之后(索引 1 的位置)
672
- var insertIndex = this.isPriceFormatterRegistered ? 1 : 0;
1150
+ // 插入到内置智能定价格式化器之后;legacy 报价单启用时需跳过它。
1151
+ var insertIndex = this.isBuiltinFormatterRegistered ? this.isLegacyPriceFormatterEnabled ? 2 : 1 : 0;
673
1152
  this.formatters.splice(insertIndex, 0, formatter);
1153
+ console.log("[ProductsModule] \uD83D\uDCCC \u5DF2\u5728\u4F4D\u7F6E ".concat(insertIndex + 1, " \u63D2\u5165\u683C\u5F0F\u5316\u5668\uFF0C\u5F53\u524D\u5171 ").concat(this.formatters.length, " \u4E2A"));
674
1154
  } else {
675
1155
  // 追加到末尾
676
1156
  this.formatters.push(formatter);
1157
+ console.log("[ProductsModule] \uD83D\uDCCC \u5DF2\u6CE8\u518C\u683C\u5F0F\u5316\u5668\uFF0C\u5F53\u524D\u5171 ".concat(this.formatters.length, " \u4E2A"));
677
1158
  }
678
1159
  }
679
1160
 
680
1161
  /**
681
- * 清空所有格式化器(包括内置价格格式化器)
682
- * @param keepBuiltin 是否保留内置价格格式化器(默认 true)
1162
+ * 清空所有格式化器(包括内置智能定价格式化器)
1163
+ * @param keepBuiltin 是否保留内置智能定价格式化器(默认 true)
683
1164
  */
684
1165
  }, {
685
1166
  key: "clearFormatters",
686
1167
  value: function clearFormatters() {
687
1168
  var keepBuiltin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
688
- if (keepBuiltin && this.isPriceFormatterRegistered) {
689
- // 只保留第一个格式化器(内置价格格式化器)
690
- this.formatters = [this.formatters[0]];
1169
+ if (keepBuiltin && this.isBuiltinFormatterRegistered) {
1170
+ // 保留 legacy 兜底(如果启用)和智能定价格式化器。
1171
+ var builtinCount = this.isLegacyPriceFormatterEnabled ? 2 : 1;
1172
+ this.formatters = this.formatters.slice(0, builtinCount);
1173
+ console.log('[ProductsModule] 🧹 已清空自定义格式化器,保留内置智能定价格式化器');
691
1174
  } else {
692
1175
  this.formatters = [];
693
- this.isPriceFormatterRegistered = false;
1176
+ this.isBuiltinFormatterRegistered = false;
1177
+ console.log('[ProductsModule] 🧹 已清空所有格式化器');
694
1178
  }
695
1179
  }
696
1180
 
@@ -706,6 +1190,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
706
1190
  var keys = Array.from(this.productsPriceCache.keys());
707
1191
  var oldestKey = keys[0];
708
1192
  this.productsPriceCache.delete(oldestKey);
1193
+ console.log("[ProductsModule] \uD83E\uDDF9 \u6E05\u7406\u8FC7\u671F\u5546\u54C1\u4EF7\u683C\u7F13\u5B58: ".concat(oldestKey));
709
1194
  }
710
1195
  }
711
1196
 
@@ -717,6 +1202,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
717
1202
  key: "clearPriceCache",
718
1203
  value: function clearPriceCache() {
719
1204
  this.productsPriceCache.clear();
1205
+ console.log('[ProductsModule] 🗑️ 商品价格缓存已清空');
720
1206
  }
721
1207
 
722
1208
  /**
@@ -725,28 +1211,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
725
1211
  }, {
726
1212
  key: "loadProductsByServer",
727
1213
  value: (function () {
728
- var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1214
+ var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
729
1215
  var t0, tSSE, productList, list, duration, errorMessage;
730
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
731
- while (1) switch (_context6.prev = _context6.next) {
1216
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1217
+ while (1) switch (_context9.prev = _context9.next) {
732
1218
  case 0:
733
1219
  if (this.productDataSource) {
734
- _context6.next = 3;
1220
+ _context9.next = 3;
735
1221
  break;
736
1222
  }
737
1223
  this.logWarning('loadProductsByServer: ProductDataSource 不可用');
738
- return _context6.abrupt("return", []);
1224
+ return _context9.abrupt("return", []);
739
1225
  case 3:
740
1226
  this.logInfo('开始通过 DataSource SSE 加载商品列表');
741
1227
  t0 = performance.now();
742
- _context6.prev = 5;
1228
+ _context9.prev = 5;
743
1229
  tSSE = performance.now();
744
- _context6.next = 9;
1230
+ _context9.next = 9;
745
1231
  return this.productDataSource.run({
746
1232
  sse: {}
747
1233
  });
748
1234
  case 9:
749
- productList = _context6.sent;
1235
+ productList = _context9.sent;
750
1236
  list = productList || [];
751
1237
  perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
752
1238
  count: list.length
@@ -755,32 +1241,33 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
755
1241
  productCount: list.length,
756
1242
  duration: "".concat(Math.round(performance.now() - t0), "ms")
757
1243
  });
758
- _context6.next = 15;
759
- return this.saveProductsToIndexDB(list);
1244
+ _context9.next = 15;
1245
+ return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
760
1246
  case 15:
761
- _context6.next = 17;
1247
+ this.lastServerFullFetchAtMs = Date.now();
1248
+ _context9.next = 18;
762
1249
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
763
- case 17:
1250
+ case 18:
764
1251
  perfMark('loadProductsByServer', performance.now() - t0, {
765
1252
  count: list.length
766
1253
  });
767
- return _context6.abrupt("return", list);
768
- case 21:
769
- _context6.prev = 21;
770
- _context6.t0 = _context6["catch"](5);
1254
+ return _context9.abrupt("return", list);
1255
+ case 22:
1256
+ _context9.prev = 22;
1257
+ _context9.t0 = _context9["catch"](5);
771
1258
  duration = Math.round(performance.now() - t0);
772
- errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
773
- console.error('[Products] 加载商品数据失败:', _context6.t0);
1259
+ errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1260
+ console.error('[Products] 加载商品数据失败:', _context9.t0);
774
1261
  this.logError('通过 DataSource SSE 加载商品列表失败', {
775
1262
  duration: "".concat(duration, "ms"),
776
1263
  error: errorMessage
777
1264
  });
778
- return _context6.abrupt("return", []);
779
- case 28:
1265
+ return _context9.abrupt("return", []);
1266
+ case 29:
780
1267
  case "end":
781
- return _context6.stop();
1268
+ return _context9.stop();
782
1269
  }
783
- }, _callee6, this, [[5, 21]]);
1270
+ }, _callee9, this, [[5, 22]]);
784
1271
  }));
785
1272
  function loadProductsByServer() {
786
1273
  return _loadProductsByServer.apply(this, arguments);
@@ -796,12 +1283,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
796
1283
  }, {
797
1284
  key: "fetchProductsByHttp",
798
1285
  value: (function () {
799
- var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
800
- var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, startTime, _this$otherParams, _productsData$data2, productsData, productList, duration, _duration2, errorMessage;
801
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
802
- while (1) switch (_context7.prev = _context7.next) {
1286
+ var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1287
+ var _ref13, _ref13$category_ids, category_ids, _ref13$product_ids, product_ids, _ref13$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1288
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1289
+ while (1) switch (_context10.prev = _context10.next) {
803
1290
  case 0:
804
- _ref2 = params || {}, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids, _ref2$product_ids = _ref2.product_ids, product_ids = _ref2$product_ids === void 0 ? [] : _ref2$product_ids, _ref2$collection = _ref2.collection, collection = _ref2$collection === void 0 ? [] : _ref2$collection, customer_id = _ref2.customer_id, cacheId = _ref2.cacheId;
1291
+ _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;
805
1292
  this.logInfo('fetchProductsByHttp: 开始请求', {
806
1293
  categoryIdsCount: category_ids.length,
807
1294
  productIdsCount: product_ids.length,
@@ -809,13 +1296,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
809
1296
  customer_id: customer_id
810
1297
  });
811
1298
  startTime = Date.now();
812
- _context7.prev = 3;
813
- _context7.next = 6;
1299
+ _context10.prev = 3;
1300
+ _context10.next = 6;
814
1301
  return this.request.post("/product/query", {
815
1302
  open_bundle: 1,
816
1303
  exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
817
1304
  force_ignore_cache_flag: 1,
818
- with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem'],
1305
+ with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem', 'dataVariants'],
819
1306
  open_deposit: 1,
820
1307
  is_append_product_description: 1,
821
1308
  with_count: ['bundleGroup', 'optionGroup'],
@@ -827,37 +1314,37 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
827
1314
  ids: product_ids,
828
1315
  collection: collection,
829
1316
  front_end_cache_id: cacheId,
830
- application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel
1317
+ application_code: (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.channel
831
1318
  }, {
832
1319
  cache: undefined
833
1320
  });
834
1321
  case 6:
835
- productsData = _context7.sent;
836
- productList = (productsData === null || productsData === void 0 || (_productsData$data2 = productsData.data) === null || _productsData$data2 === void 0 ? void 0 : _productsData$data2.list) || [];
1322
+ productsData = _context10.sent;
1323
+ productList = (productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || [];
837
1324
  duration = Date.now() - startTime;
838
1325
  this.logInfo('fetchProductsByHttp: 请求成功', {
839
1326
  productCount: productList.length,
840
1327
  duration: "".concat(duration, "ms")
841
1328
  });
842
- return _context7.abrupt("return", productList);
1329
+ return _context10.abrupt("return", productList);
843
1330
  case 13:
844
- _context7.prev = 13;
845
- _context7.t0 = _context7["catch"](3);
1331
+ _context10.prev = 13;
1332
+ _context10.t0 = _context10["catch"](3);
846
1333
  _duration2 = Date.now() - startTime;
847
- errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
848
- console.error('[Products] fetchProductsByHttp 失败:', _context7.t0);
1334
+ errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1335
+ console.error('[Products] fetchProductsByHttp 失败:', _context10.t0);
849
1336
  this.logError('fetchProductsByHttp: 请求失败', {
850
1337
  duration: "".concat(_duration2, "ms"),
851
1338
  error: errorMessage
852
1339
  });
853
- return _context7.abrupt("return", []);
1340
+ return _context10.abrupt("return", []);
854
1341
  case 20:
855
1342
  case "end":
856
- return _context7.stop();
1343
+ return _context10.stop();
857
1344
  }
858
- }, _callee7, this, [[3, 13]]);
1345
+ }, _callee10, this, [[3, 13]]);
859
1346
  }));
860
- function fetchProductsByHttp(_x12) {
1347
+ function fetchProductsByHttp(_x15) {
861
1348
  return _fetchProductsByHttp.apply(this, arguments);
862
1349
  }
863
1350
  return fetchProductsByHttp;
@@ -871,33 +1358,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
871
1358
  }, {
872
1359
  key: "loadProductsByServerHttp",
873
1360
  value: (function () {
874
- var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1361
+ var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
875
1362
  var productList;
876
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
877
- while (1) switch (_context8.prev = _context8.next) {
1363
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1364
+ while (1) switch (_context11.prev = _context11.next) {
878
1365
  case 0:
879
- _context8.next = 2;
1366
+ _context11.next = 2;
880
1367
  return this.fetchProductsByHttp(params);
881
1368
  case 2:
882
- productList = _context8.sent;
1369
+ productList = _context11.sent;
883
1370
  if (!(productList.length > 0)) {
884
- _context8.next = 8;
1371
+ _context11.next = 9;
885
1372
  break;
886
1373
  }
887
- _context8.next = 6;
888
- return this.saveProductsToIndexDB(productList);
1374
+ _context11.next = 6;
1375
+ return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
889
1376
  case 6:
890
- _context8.next = 8;
1377
+ this.lastServerFullFetchAtMs = Date.now();
1378
+ _context11.next = 9;
891
1379
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
892
- case 8:
893
- return _context8.abrupt("return", productList);
894
1380
  case 9:
1381
+ return _context11.abrupt("return", productList);
1382
+ case 10:
895
1383
  case "end":
896
- return _context8.stop();
1384
+ return _context11.stop();
897
1385
  }
898
- }, _callee8, this);
1386
+ }, _callee11, this);
899
1387
  }));
900
- function loadProductsByServerHttp(_x13) {
1388
+ function loadProductsByServerHttp(_x16) {
901
1389
  return _loadProductsByServerHttp.apply(this, arguments);
902
1390
  }
903
1391
  return loadProductsByServerHttp;
@@ -909,27 +1397,95 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
909
1397
  }, {
910
1398
  key: "getProducts",
911
1399
  value: (function () {
912
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1400
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
913
1401
  var t0, result;
914
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
915
- while (1) switch (_context9.prev = _context9.next) {
1402
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1403
+ while (1) switch (_context12.prev = _context12.next) {
916
1404
  case 0:
917
1405
  t0 = performance.now();
918
1406
  result = structuredClone(this.store.list);
919
1407
  perfMark('ProductsModule.getProducts(structuredClone)', performance.now() - t0, {
920
1408
  count: result.length
921
1409
  });
922
- return _context9.abrupt("return", result);
1410
+ return _context12.abrupt("return", result);
923
1411
  case 4:
924
1412
  case "end":
925
- return _context9.stop();
1413
+ return _context12.stop();
1414
+ }
1415
+ }, _callee12, this);
1416
+ }));
1417
+ function getProducts() {
1418
+ return _getProducts.apply(this, arguments);
1419
+ }
1420
+ return getProducts;
1421
+ }()
1422
+ /**
1423
+ * 批量获取商品轻量快照,供订单详情等响应补齐展示协议字段。
1424
+ */
1425
+ )
1426
+ }, {
1427
+ key: "getProductSnapshotsByIds",
1428
+ value: (function () {
1429
+ var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1430
+ var snapshots, seen, _iterator6, _step6, id, product;
1431
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1432
+ while (1) switch (_context13.prev = _context13.next) {
1433
+ case 0:
1434
+ snapshots = {};
1435
+ seen = new Set();
1436
+ _iterator6 = _createForOfIteratorHelper(ids);
1437
+ _context13.prev = 3;
1438
+ _iterator6.s();
1439
+ case 5:
1440
+ if ((_step6 = _iterator6.n()).done) {
1441
+ _context13.next = 16;
1442
+ break;
1443
+ }
1444
+ id = _step6.value;
1445
+ if (!(!Number.isFinite(id) || seen.has(id))) {
1446
+ _context13.next = 9;
1447
+ break;
1448
+ }
1449
+ return _context13.abrupt("continue", 14);
1450
+ case 9:
1451
+ seen.add(id);
1452
+ product = this.store.map.get(id);
1453
+ if (product) {
1454
+ _context13.next = 13;
1455
+ break;
1456
+ }
1457
+ return _context13.abrupt("continue", 14);
1458
+ case 13:
1459
+ snapshots[String(id)] = {
1460
+ cover: product.cover,
1461
+ holder_config: product.holder_config
1462
+ };
1463
+ case 14:
1464
+ _context13.next = 5;
1465
+ break;
1466
+ case 16:
1467
+ _context13.next = 21;
1468
+ break;
1469
+ case 18:
1470
+ _context13.prev = 18;
1471
+ _context13.t0 = _context13["catch"](3);
1472
+ _iterator6.e(_context13.t0);
1473
+ case 21:
1474
+ _context13.prev = 21;
1475
+ _iterator6.f();
1476
+ return _context13.finish(21);
1477
+ case 24:
1478
+ return _context13.abrupt("return", snapshots);
1479
+ case 25:
1480
+ case "end":
1481
+ return _context13.stop();
926
1482
  }
927
- }, _callee9, this);
1483
+ }, _callee13, this, [[3, 18, 21, 24]]);
928
1484
  }));
929
- function getProducts() {
930
- return _getProducts.apply(this, arguments);
1485
+ function getProductSnapshotsByIds(_x17) {
1486
+ return _getProductSnapshotsByIds.apply(this, arguments);
931
1487
  }
932
- return getProducts;
1488
+ return getProductSnapshotsByIds;
933
1489
  }()
934
1490
  /**
935
1491
  * 内部获取商品列表的直接引用(无拷贝)
@@ -942,6 +1498,29 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
942
1498
  return this.store.list;
943
1499
  }
944
1500
 
1501
+ /**
1502
+ * 按 ID 从 Map 取商品引用,供内部 formatter 流程使用。
1503
+ */
1504
+ }, {
1505
+ key: "getProductsRefByIds",
1506
+ value: function getProductsRefByIds(ids) {
1507
+ var products = [];
1508
+ var _iterator7 = _createForOfIteratorHelper(ids),
1509
+ _step7;
1510
+ try {
1511
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1512
+ var id = _step7.value;
1513
+ var product = this.store.map.get(id);
1514
+ if (product) products.push(product);
1515
+ }
1516
+ } catch (err) {
1517
+ _iterator7.e(err);
1518
+ } finally {
1519
+ _iterator7.f();
1520
+ }
1521
+ return products;
1522
+ }
1523
+
945
1524
  /**
946
1525
  * 根据ID获取单个商品(从内存缓存)
947
1526
  * 使用 Map 快速查询,时间复杂度 O(1)
@@ -949,20 +1528,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
949
1528
  }, {
950
1529
  key: "getProductById",
951
1530
  value: (function () {
952
- var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(id) {
1531
+ var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(id) {
953
1532
  var product;
954
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
955
- while (1) switch (_context10.prev = _context10.next) {
1533
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1534
+ while (1) switch (_context14.prev = _context14.next) {
956
1535
  case 0:
957
1536
  product = this.store.map.get(id);
958
- return _context10.abrupt("return", product ? structuredClone(product) : undefined);
1537
+ return _context14.abrupt("return", product ? structuredClone(product) : undefined);
959
1538
  case 2:
960
1539
  case "end":
961
- return _context10.stop();
1540
+ return _context14.stop();
962
1541
  }
963
- }, _callee10, this);
1542
+ }, _callee14, this);
964
1543
  }));
965
- function getProductById(_x14) {
1544
+ function getProductById(_x18) {
966
1545
  return _getProductById.apply(this, arguments);
967
1546
  }
968
1547
  return getProductById;
@@ -975,10 +1554,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
975
1554
  }, {
976
1555
  key: "removeProductsByIds",
977
1556
  value: (function () {
978
- var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(ids) {
979
- var idSet, _iterator3, _step3, _id, _iterator4, _step4, id, errorMessage, _iterator5, _step5, _step5$value, dateKey, cachedProducts;
980
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
981
- while (1) switch (_context11.prev = _context11.next) {
1557
+ var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
1558
+ var idSet, _iterator8, _step8, _id, _iterator9, _step9, id, errorMessage, _iterator10, _step10, _step10$value, dateKey, cachedProducts;
1559
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1560
+ while (1) switch (_context15.prev = _context15.next) {
982
1561
  case 0:
983
1562
  idSet = new Set(ids);
984
1563
  this.logInfo('removeProductsByIds', {
@@ -988,71 +1567,71 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
988
1567
  this.store.list = this.store.list.filter(function (p) {
989
1568
  return !idSet.has(p.id);
990
1569
  });
991
- _iterator3 = _createForOfIteratorHelper(ids);
1570
+ _iterator8 = _createForOfIteratorHelper(ids);
992
1571
  try {
993
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
994
- _id = _step3.value;
1572
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1573
+ _id = _step8.value;
995
1574
  this.store.map.delete(_id);
996
1575
  }
997
1576
  } catch (err) {
998
- _iterator3.e(err);
1577
+ _iterator8.e(err);
999
1578
  } finally {
1000
- _iterator3.f();
1579
+ _iterator8.f();
1001
1580
  }
1002
1581
  if (!this.dbManager) {
1003
- _context11.next = 30;
1582
+ _context15.next = 30;
1004
1583
  break;
1005
1584
  }
1006
- _context11.prev = 6;
1007
- _iterator4 = _createForOfIteratorHelper(ids);
1008
- _context11.prev = 8;
1009
- _iterator4.s();
1585
+ _context15.prev = 6;
1586
+ _iterator9 = _createForOfIteratorHelper(ids);
1587
+ _context15.prev = 8;
1588
+ _iterator9.s();
1010
1589
  case 10:
1011
- if ((_step4 = _iterator4.n()).done) {
1012
- _context11.next = 16;
1590
+ if ((_step9 = _iterator9.n()).done) {
1591
+ _context15.next = 16;
1013
1592
  break;
1014
1593
  }
1015
- id = _step4.value;
1016
- _context11.next = 14;
1594
+ id = _step9.value;
1595
+ _context15.next = 14;
1017
1596
  return this.dbManager.delete(INDEXDB_STORE_NAME, id);
1018
1597
  case 14:
1019
- _context11.next = 10;
1598
+ _context15.next = 10;
1020
1599
  break;
1021
1600
  case 16:
1022
- _context11.next = 21;
1601
+ _context15.next = 21;
1023
1602
  break;
1024
1603
  case 18:
1025
- _context11.prev = 18;
1026
- _context11.t0 = _context11["catch"](8);
1027
- _iterator4.e(_context11.t0);
1604
+ _context15.prev = 18;
1605
+ _context15.t0 = _context15["catch"](8);
1606
+ _iterator9.e(_context15.t0);
1028
1607
  case 21:
1029
- _context11.prev = 21;
1030
- _iterator4.f();
1031
- return _context11.finish(21);
1608
+ _context15.prev = 21;
1609
+ _iterator9.f();
1610
+ return _context15.finish(21);
1032
1611
  case 24:
1033
- _context11.next = 30;
1612
+ _context15.next = 30;
1034
1613
  break;
1035
1614
  case 26:
1036
- _context11.prev = 26;
1037
- _context11.t1 = _context11["catch"](6);
1038
- errorMessage = _context11.t1 instanceof Error ? _context11.t1.message : String(_context11.t1);
1615
+ _context15.prev = 26;
1616
+ _context15.t1 = _context15["catch"](6);
1617
+ errorMessage = _context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1);
1039
1618
  this.logError('removeProductsByIds: IndexDB 删除失败', {
1040
1619
  ids: ids,
1041
1620
  error: errorMessage
1042
1621
  });
1043
1622
  case 30:
1044
- _iterator5 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1623
+ _iterator10 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1045
1624
  try {
1046
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1047
- _step5$value = _slicedToArray(_step5.value, 2), dateKey = _step5$value[0], cachedProducts = _step5$value[1];
1625
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1626
+ _step10$value = _slicedToArray(_step10.value, 2), dateKey = _step10$value[0], cachedProducts = _step10$value[1];
1048
1627
  this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
1049
1628
  return !idSet.has(p.id);
1050
1629
  }));
1051
1630
  }
1052
1631
  } catch (err) {
1053
- _iterator5.e(err);
1632
+ _iterator10.e(err);
1054
1633
  } finally {
1055
- _iterator5.f();
1634
+ _iterator10.f();
1056
1635
  }
1057
1636
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1058
1637
  this.logInfo('removeProductsByIds 完成', {
@@ -1060,11 +1639,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1060
1639
  });
1061
1640
  case 34:
1062
1641
  case "end":
1063
- return _context11.stop();
1642
+ return _context15.stop();
1064
1643
  }
1065
- }, _callee11, this, [[6, 26], [8, 18, 21, 24]]);
1644
+ }, _callee15, this, [[6, 26], [8, 18, 21, 24]]);
1066
1645
  }));
1067
- function removeProductsByIds(_x15) {
1646
+ function removeProductsByIds(_x19) {
1068
1647
  return _removeProductsByIds.apply(this, arguments);
1069
1648
  }
1070
1649
  return removeProductsByIds;
@@ -1077,17 +1656,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1077
1656
  }, {
1078
1657
  key: "refreshProducts",
1079
1658
  value: (function () {
1080
- var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1659
+ var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1081
1660
  var tTotal, products;
1082
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1083
- while (1) switch (_context12.prev = _context12.next) {
1661
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1662
+ while (1) switch (_context16.prev = _context16.next) {
1084
1663
  case 0:
1085
1664
  tTotal = performance.now();
1086
1665
  this.logInfo('refreshProducts 开始');
1087
- _context12.next = 4;
1666
+ _context16.next = 4;
1088
1667
  return this.loadProductsByServer();
1089
1668
  case 4:
1090
- products = _context12.sent;
1669
+ products = _context16.sent;
1091
1670
  if (products && products.length > 0) {
1092
1671
  // 服务器返回的数据已经是全新的,无需 cloneDeep
1093
1672
  this.store.list = products;
@@ -1102,12 +1681,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1102
1681
  perfMark('refreshProducts', performance.now() - tTotal, {
1103
1682
  count: this.store.list.length
1104
1683
  });
1105
- return _context12.abrupt("return", this.store.list);
1684
+ return _context16.abrupt("return", this.store.list);
1106
1685
  case 8:
1107
1686
  case "end":
1108
- return _context12.stop();
1687
+ return _context16.stop();
1109
1688
  }
1110
- }, _callee12, this);
1689
+ }, _callee16, this);
1111
1690
  }));
1112
1691
  function refreshProducts() {
1113
1692
  return _refreshProducts.apply(this, arguments);
@@ -1121,10 +1700,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1121
1700
  }, {
1122
1701
  key: "clear",
1123
1702
  value: (function () {
1124
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1703
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1125
1704
  var errorMessage;
1126
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1127
- while (1) switch (_context13.prev = _context13.next) {
1705
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1706
+ while (1) switch (_context17.prev = _context17.next) {
1128
1707
  case 0:
1129
1708
  this.logInfo('开始清空缓存', {
1130
1709
  currentProductCount: this.store.list.length,
@@ -1135,31 +1714,33 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1135
1714
 
1136
1715
  // 同时清空 IndexDB 中的所有数据(包括商品和元数据)
1137
1716
  if (!this.dbManager) {
1138
- _context13.next = 15;
1717
+ _context17.next = 16;
1139
1718
  break;
1140
1719
  }
1141
- _context13.prev = 4;
1142
- _context13.next = 7;
1720
+ _context17.prev = 4;
1721
+ _context17.next = 7;
1143
1722
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1144
1723
  case 7:
1724
+ console.log('[Products] IndexDB 缓存已清空');
1145
1725
  this.logInfo('IndexDB 缓存已清空');
1146
- _context13.next = 15;
1726
+ _context17.next = 16;
1147
1727
  break;
1148
- case 10:
1149
- _context13.prev = 10;
1150
- _context13.t0 = _context13["catch"](4);
1151
- errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1152
- console.error('[Products] 清空 IndexDB 缓存失败:', _context13.t0);
1728
+ case 11:
1729
+ _context17.prev = 11;
1730
+ _context17.t0 = _context17["catch"](4);
1731
+ errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
1732
+ console.error('[Products] 清空 IndexDB 缓存失败:', _context17.t0);
1153
1733
  this.logError('清空 IndexDB 缓存失败', {
1154
1734
  error: errorMessage
1155
1735
  });
1156
- case 15:
1157
- this.logInfo('缓存清空完成');
1158
1736
  case 16:
1737
+ console.log('[Products] 缓存已清空');
1738
+ this.logInfo('缓存清空完成');
1739
+ case 18:
1159
1740
  case "end":
1160
- return _context13.stop();
1741
+ return _context17.stop();
1161
1742
  }
1162
- }, _callee13, this, [[4, 10]]);
1743
+ }, _callee17, this, [[4, 11]]);
1163
1744
  }));
1164
1745
  function clear() {
1165
1746
  return _clear.apply(this, arguments);
@@ -1174,45 +1755,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1174
1755
  }, {
1175
1756
  key: "loadProductsFromIndexDB",
1176
1757
  value: (function () {
1177
- var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1758
+ var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1178
1759
  var _products$length, _products$length2, t0, products, errorMessage;
1179
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1180
- while (1) switch (_context14.prev = _context14.next) {
1760
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1761
+ while (1) switch (_context18.prev = _context18.next) {
1181
1762
  case 0:
1182
1763
  if (this.dbManager) {
1183
- _context14.next = 3;
1764
+ _context18.next = 3;
1184
1765
  break;
1185
1766
  }
1186
1767
  this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
1187
- return _context14.abrupt("return", []);
1768
+ return _context18.abrupt("return", []);
1188
1769
  case 3:
1189
- _context14.prev = 3;
1770
+ _context18.prev = 3;
1190
1771
  t0 = performance.now();
1191
- _context14.next = 7;
1772
+ _context18.next = 7;
1192
1773
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
1193
1774
  case 7:
1194
- products = _context14.sent;
1775
+ products = _context18.sent;
1195
1776
  perfMark('loadProductsFromIndexDB', performance.now() - t0, {
1196
1777
  count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
1197
1778
  });
1198
1779
  this.logInfo('从 IndexDB 加载商品数据', {
1199
1780
  productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
1200
1781
  });
1201
- return _context14.abrupt("return", products || []);
1782
+ return _context18.abrupt("return", products || []);
1202
1783
  case 13:
1203
- _context14.prev = 13;
1204
- _context14.t0 = _context14["catch"](3);
1205
- errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
1206
- console.error('[Products] 从 IndexDB 读取数据失败:', _context14.t0);
1784
+ _context18.prev = 13;
1785
+ _context18.t0 = _context18["catch"](3);
1786
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1787
+ console.error('[Products] 从 IndexDB 读取数据失败:', _context18.t0);
1207
1788
  this.logError('从 IndexDB 读取数据失败', {
1208
1789
  error: errorMessage
1209
1790
  });
1210
- return _context14.abrupt("return", []);
1791
+ return _context18.abrupt("return", []);
1211
1792
  case 19:
1212
1793
  case "end":
1213
- return _context14.stop();
1794
+ return _context18.stop();
1214
1795
  }
1215
- }, _callee14, this, [[3, 13]]);
1796
+ }, _callee18, this, [[3, 13]]);
1216
1797
  }));
1217
1798
  function loadProductsFromIndexDB() {
1218
1799
  return _loadProductsFromIndexDB.apply(this, arguments);
@@ -1220,63 +1801,243 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1220
1801
  return loadProductsFromIndexDB;
1221
1802
  }()
1222
1803
  /**
1223
- * 保存商品数据到 IndexDB(平铺存储)
1224
- * @private
1804
+ * 串行执行商品 IndexDB 写入,避免快照替换与增量 patch 并发交错。
1805
+ *
1806
+ * @example
1807
+ * await this.runInProductIndexDBSaveQueue(async () => {
1808
+ * await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products)
1809
+ * })
1225
1810
  */
1226
1811
  )
1227
1812
  }, {
1228
- key: "saveProductsToIndexDB",
1813
+ key: "runInProductIndexDBSaveQueue",
1229
1814
  value: (function () {
1230
- var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(products) {
1231
- var t0, errorMessage;
1232
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1233
- while (1) switch (_context15.prev = _context15.next) {
1815
+ var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(task) {
1816
+ var queuedTask;
1817
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1818
+ while (1) switch (_context19.prev = _context19.next) {
1819
+ case 0:
1820
+ queuedTask = this.productIndexDBSaveQueue.then(task, task);
1821
+ this.productIndexDBSaveQueue = queuedTask.then(function () {
1822
+ return undefined;
1823
+ }, function () {
1824
+ return undefined;
1825
+ });
1826
+ return _context19.abrupt("return", queuedTask);
1827
+ case 3:
1828
+ case "end":
1829
+ return _context19.stop();
1830
+ }
1831
+ }, _callee19, this);
1832
+ }));
1833
+ function runInProductIndexDBSaveQueue(_x20) {
1834
+ return _runInProductIndexDBSaveQueue.apply(this, arguments);
1835
+ }
1836
+ return runInProductIndexDBSaveQueue;
1837
+ }()
1838
+ /**
1839
+ * 全量快照写入 IndexDB:clear + bulkUpdate,仅用于 SSE/HTTP 全量拉取。
1840
+ *
1841
+ * @example
1842
+ * await this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer')
1843
+ */
1844
+ )
1845
+ }, {
1846
+ key: "replaceProductsSnapshotInIndexDB",
1847
+ value: (function () {
1848
+ var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(products, source) {
1849
+ var _this9 = this;
1850
+ var errorMessage;
1851
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1852
+ while (1) switch (_context21.prev = _context21.next) {
1234
1853
  case 0:
1235
1854
  if (this.dbManager) {
1236
- _context15.next = 3;
1855
+ _context21.next = 3;
1237
1856
  break;
1238
1857
  }
1239
- this.logWarning('saveProductsToIndexDB: dbManager 不可用');
1240
- return _context15.abrupt("return");
1858
+ this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
1859
+ return _context21.abrupt("return");
1241
1860
  case 3:
1242
- this.logInfo('开始保存商品数据到 IndexDB', {
1243
- productCount: products.length
1244
- });
1245
- _context15.prev = 4;
1246
- t0 = performance.now();
1247
- _context15.next = 8;
1248
- return this.dbManager.clear(INDEXDB_STORE_NAME);
1861
+ _context21.prev = 3;
1862
+ _context21.next = 6;
1863
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1864
+ var t0;
1865
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1866
+ while (1) switch (_context20.prev = _context20.next) {
1867
+ case 0:
1868
+ _this9.logInfo('replaceProductsSnapshotInIndexDB 开始', {
1869
+ source: source,
1870
+ productCount: products.length
1871
+ });
1872
+ t0 = performance.now();
1873
+ _context20.next = 4;
1874
+ return _this9.dbManager.clear(INDEXDB_STORE_NAME);
1875
+ case 4:
1876
+ if (!(products.length > 0)) {
1877
+ _context20.next = 7;
1878
+ break;
1879
+ }
1880
+ _context20.next = 7;
1881
+ return _this9.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1882
+ case 7:
1883
+ perfMark('replaceProductsSnapshotInIndexDB', performance.now() - t0, {
1884
+ count: products.length
1885
+ });
1886
+ _this9.logInfo('replaceProductsSnapshotInIndexDB 完成', {
1887
+ source: source,
1888
+ productCount: products.length
1889
+ });
1890
+ case 9:
1891
+ case "end":
1892
+ return _context20.stop();
1893
+ }
1894
+ }, _callee20);
1895
+ })));
1896
+ case 6:
1897
+ _context21.next = 12;
1898
+ break;
1249
1899
  case 8:
1250
- _context15.next = 10;
1251
- return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1252
- case 10:
1253
- perfMark('saveProductsToIndexDB', performance.now() - t0, {
1254
- count: products.length
1900
+ _context21.prev = 8;
1901
+ _context21.t0 = _context21["catch"](3);
1902
+ errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
1903
+ this.logError('全量保存商品到 IndexDB 失败', {
1904
+ source: source,
1905
+ productCount: products.length,
1906
+ error: errorMessage
1255
1907
  });
1256
- this.logInfo('商品数据已保存到 IndexDB', {
1257
- productCount: products.length
1908
+ case 12:
1909
+ case "end":
1910
+ return _context21.stop();
1911
+ }
1912
+ }, _callee21, this, [[3, 8]]);
1913
+ }));
1914
+ function replaceProductsSnapshotInIndexDB(_x21, _x22) {
1915
+ return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
1916
+ }
1917
+ return replaceProductsSnapshotInIndexDB;
1918
+ }()
1919
+ /**
1920
+ * 增量 upsert 商品到 IndexDB,不清空表;用于 pubsub 批次合并后的变更商品。
1921
+ *
1922
+ * @example
1923
+ * await this.patchProductsInIndexDB(changedProducts, 'pubsub.processProductSyncMessages', mergeActions)
1924
+ */
1925
+ )
1926
+ }, {
1927
+ key: "patchProductsInIndexDB",
1928
+ value: (function () {
1929
+ var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(products, source) {
1930
+ var _this10 = this;
1931
+ var mergeActions,
1932
+ validProducts,
1933
+ errorMessage,
1934
+ _args23 = arguments;
1935
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1936
+ while (1) switch (_context23.prev = _context23.next) {
1937
+ case 0:
1938
+ mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
1939
+ if (!(!this.dbManager || products.length === 0)) {
1940
+ _context23.next = 3;
1941
+ break;
1942
+ }
1943
+ return _context23.abrupt("return");
1944
+ case 3:
1945
+ validProducts = products.filter(function (p) {
1946
+ return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
1258
1947
  });
1259
- _context15.next = 19;
1948
+ if (!(validProducts.length === 0)) {
1949
+ _context23.next = 6;
1950
+ break;
1951
+ }
1952
+ return _context23.abrupt("return");
1953
+ case 6:
1954
+ _context23.prev = 6;
1955
+ _context23.next = 9;
1956
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1957
+ var t0, _iterator11, _step11, product;
1958
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1959
+ while (1) switch (_context22.prev = _context22.next) {
1960
+ case 0:
1961
+ _this10.logInfo('patchProductsInIndexDB 开始', {
1962
+ source: source,
1963
+ count: validProducts.length
1964
+ });
1965
+ t0 = performance.now();
1966
+ if (!(typeof _this10.dbManager.bulkUpdate === 'function')) {
1967
+ _context22.next = 7;
1968
+ break;
1969
+ }
1970
+ _context22.next = 5;
1971
+ return _this10.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
1972
+ case 5:
1973
+ _context22.next = 25;
1974
+ break;
1975
+ case 7:
1976
+ if (!(typeof _this10.dbManager.update === 'function')) {
1977
+ _context22.next = 25;
1978
+ break;
1979
+ }
1980
+ _iterator11 = _createForOfIteratorHelper(validProducts);
1981
+ _context22.prev = 9;
1982
+ _iterator11.s();
1983
+ case 11:
1984
+ if ((_step11 = _iterator11.n()).done) {
1985
+ _context22.next = 17;
1986
+ break;
1987
+ }
1988
+ product = _step11.value;
1989
+ _context22.next = 15;
1990
+ return _this10.dbManager.update(INDEXDB_STORE_NAME, product);
1991
+ case 15:
1992
+ _context22.next = 11;
1993
+ break;
1994
+ case 17:
1995
+ _context22.next = 22;
1996
+ break;
1997
+ case 19:
1998
+ _context22.prev = 19;
1999
+ _context22.t0 = _context22["catch"](9);
2000
+ _iterator11.e(_context22.t0);
2001
+ case 22:
2002
+ _context22.prev = 22;
2003
+ _iterator11.f();
2004
+ return _context22.finish(22);
2005
+ case 25:
2006
+ perfMark('patchProductsInIndexDB', performance.now() - t0, {
2007
+ count: validProducts.length
2008
+ });
2009
+ _this10.logInfo('patchProductsInIndexDB 完成', {
2010
+ source: source,
2011
+ count: validProducts.length
2012
+ });
2013
+ case 27:
2014
+ case "end":
2015
+ return _context22.stop();
2016
+ }
2017
+ }, _callee22, null, [[9, 19, 22, 25]]);
2018
+ })));
2019
+ case 9:
2020
+ _context23.next = 15;
1260
2021
  break;
1261
- case 14:
1262
- _context15.prev = 14;
1263
- _context15.t0 = _context15["catch"](4);
1264
- errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
1265
- console.error('[Products] 保存数据到 IndexDB 失败:', _context15.t0);
1266
- this.logError('保存数据到 IndexDB 失败', {
1267
- productCount: products.length,
1268
- error: errorMessage
2022
+ case 11:
2023
+ _context23.prev = 11;
2024
+ _context23.t0 = _context23["catch"](6);
2025
+ errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
2026
+ this.logError('增量保存商品到 IndexDB 失败', {
2027
+ source: source,
2028
+ error: errorMessage,
2029
+ productCount: validProducts.length
1269
2030
  });
1270
- case 19:
2031
+ case 15:
1271
2032
  case "end":
1272
- return _context15.stop();
2033
+ return _context23.stop();
1273
2034
  }
1274
- }, _callee15, this, [[4, 14]]);
2035
+ }, _callee23, this, [[6, 11]]);
1275
2036
  }));
1276
- function saveProductsToIndexDB(_x16) {
1277
- return _saveProductsToIndexDB.apply(this, arguments);
2037
+ function patchProductsInIndexDB(_x23, _x24) {
2038
+ return _patchProductsInIndexDB.apply(this, arguments);
1278
2039
  }
1279
- return saveProductsToIndexDB;
2040
+ return patchProductsInIndexDB;
1280
2041
  }()
1281
2042
  /**
1282
2043
  * 同步更新商品 Map 缓存
@@ -1289,17 +2050,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1289
2050
  value: function syncProductsMap() {
1290
2051
  var t0 = performance.now();
1291
2052
  this.store.map.clear();
1292
- var _iterator6 = _createForOfIteratorHelper(this.store.list),
1293
- _step6;
2053
+ var _iterator12 = _createForOfIteratorHelper(this.store.list),
2054
+ _step12;
1294
2055
  try {
1295
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1296
- var product = _step6.value;
2056
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
2057
+ var product = _step12.value;
1297
2058
  this.store.map.set(product.id, product);
1298
2059
  }
1299
2060
  } catch (err) {
1300
- _iterator6.e(err);
2061
+ _iterator12.e(err);
1301
2062
  } finally {
1302
- _iterator6.f();
2063
+ _iterator12.f();
1303
2064
  }
1304
2065
  perfMark('syncProductsMap', performance.now() - t0, {
1305
2066
  count: this.store.map.size
@@ -1313,27 +2074,29 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1313
2074
  }, {
1314
2075
  key: "preload",
1315
2076
  value: (function () {
1316
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2077
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1317
2078
  var _products$length3;
1318
2079
  var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
1319
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1320
- while (1) switch (_context16.prev = _context16.next) {
2080
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2081
+ while (1) switch (_context24.prev = _context24.next) {
1321
2082
  case 0:
2083
+ console.log('[Products] 开始预加载数据...');
1322
2084
  tTotal = performance.now();
1323
2085
  this.logInfo('开始预加载数据');
1324
- _context16.prev = 2;
2086
+ _context24.prev = 3;
1325
2087
  tIndexDB = performance.now();
1326
- _context16.next = 6;
2088
+ _context24.next = 7;
1327
2089
  return this.loadProductsFromIndexDB();
1328
- case 6:
1329
- cachedData = _context16.sent;
2090
+ case 7:
2091
+ cachedData = _context24.sent;
1330
2092
  perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1331
2093
  count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
1332
2094
  });
1333
2095
  if (!(cachedData && cachedData.length > 0)) {
1334
- _context16.next = 17;
2096
+ _context24.next = 20;
1335
2097
  break;
1336
2098
  }
2099
+ console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
1337
2100
  // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
1338
2101
  this.store.list = cachedData;
1339
2102
  tSync = performance.now();
@@ -1351,25 +2114,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1351
2114
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1352
2115
  source: 'IndexDB'
1353
2116
  });
1354
- return _context16.abrupt("return");
1355
- case 17:
2117
+ this.lastPreloadCompletedAtMs = Date.now();
2118
+ return _context24.abrupt("return");
2119
+ case 20:
2120
+ console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
1356
2121
  this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
1357
- _context16.next = 25;
2122
+ _context24.next = 29;
1358
2123
  break;
1359
- case 20:
1360
- _context16.prev = 20;
1361
- _context16.t0 = _context16["catch"](2);
1362
- errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
1363
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context16.t0);
2124
+ case 24:
2125
+ _context24.prev = 24;
2126
+ _context24.t0 = _context24["catch"](3);
2127
+ errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
2128
+ console.warn('[Products] 从 IndexDB 加载数据失败:', _context24.t0);
1364
2129
  this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
1365
2130
  error: errorMessage
1366
2131
  });
1367
- case 25:
2132
+ case 29:
1368
2133
  tServer = performance.now();
1369
- _context16.next = 28;
2134
+ _context24.next = 32;
1370
2135
  return this.loadProductsByServer();
1371
- case 28:
1372
- products = _context16.sent;
2136
+ case 32:
2137
+ products = _context24.sent;
1373
2138
  perfMark('preload.loadFromServer', performance.now() - tServer, {
1374
2139
  count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
1375
2140
  });
@@ -1391,6 +2156,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1391
2156
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1392
2157
  source: 'Server'
1393
2158
  });
2159
+ this.lastPreloadCompletedAtMs = Date.now();
1394
2160
  } else {
1395
2161
  perfMark('preload(empty)', performance.now() - tTotal, {
1396
2162
  source: 'empty'
@@ -1399,11 +2165,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1399
2165
  duration: "".concat(Math.round(performance.now() - tTotal), "ms")
1400
2166
  });
1401
2167
  }
1402
- case 31:
2168
+ case 35:
1403
2169
  case "end":
1404
- return _context16.stop();
2170
+ return _context24.stop();
1405
2171
  }
1406
- }, _callee16, this, [[2, 20]]);
2172
+ }, _callee24, this, [[3, 24]]);
1407
2173
  }));
1408
2174
  function preload() {
1409
2175
  return _preload.apply(this, arguments);
@@ -1438,7 +2204,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1438
2204
  }, {
1439
2205
  key: "setupProductSync",
1440
2206
  value: function setupProductSync() {
1441
- var _this2 = this;
2207
+ var _this11 = this;
1442
2208
  if (!this.productDataSource) {
1443
2209
  this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
1444
2210
  return;
@@ -1447,29 +2213,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1447
2213
  return function (message) {
1448
2214
  var data = (message === null || message === void 0 ? void 0 : message.data) || message;
1449
2215
  if (!data) return;
1450
- _this2.logInfo('收到同步消息', {
2216
+ console.log("[ProductsModule] \u6536\u5230\u540C\u6B65\u6D88\u606F [".concat(channelKey, "]:"), data);
2217
+ _this11.logInfo('收到同步消息', {
1451
2218
  channelKey: channelKey,
1452
2219
  action: data.action,
1453
2220
  id: data.id,
1454
2221
  action_filed: data.action_filed
1455
2222
  });
1456
- _this2.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
2223
+ _this11.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
1457
2224
  _channelKey: channelKey
1458
2225
  }));
1459
- if (_this2.syncTimer) {
1460
- clearTimeout(_this2.syncTimer);
2226
+ if (_this11.syncTimer) {
2227
+ clearTimeout(_this11.syncTimer);
1461
2228
  }
1462
- _this2.syncTimer = setTimeout(function () {
1463
- _this2.processProductSyncMessages();
2229
+ _this11.syncTimer = setTimeout(function () {
2230
+ _this11.processProductSyncMessages();
1464
2231
  }, PRODUCT_SYNC_DEBOUNCE_MS);
1465
2232
  };
1466
2233
  };
1467
2234
  this.productDataSource.run({
1468
2235
  pubsub: {
1469
2236
  callback: function callback(res) {
1470
- _this2.logInfo('sse_products_callback: 收到同步消息', {
1471
- data: res === null || res === void 0 ? void 0 : res.data
1472
- });
2237
+ // console.log('sse_products_callback', res)
2238
+ // this.logInfo('sse_products_callback: 收到同步消息', {
2239
+ // data: res?.data,
2240
+ // });
1473
2241
  if (!(res !== null && res !== void 0 && res.data)) return;
1474
2242
  var data = res.data;
1475
2243
  var channelKey = data.module || 'product';
@@ -1477,7 +2245,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1477
2245
  }
1478
2246
  }
1479
2247
  }).catch(function (err) {
1480
- _this2.logError('setupProductSync: DataSource run 出错', {
2248
+ _this11.logError('setupProductSync: DataSource run 出错', {
1481
2249
  error: err instanceof Error ? err.message : String(err)
1482
2250
  });
1483
2251
  });
@@ -1505,18 +2273,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1505
2273
  }, {
1506
2274
  key: "processProductSyncMessages",
1507
2275
  value: (function () {
1508
- var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1509
- var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator7, _step7, 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;
1510
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1511
- while (1) switch (_context17.prev = _context17.next) {
2276
+ var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2277
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator13, _step13, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator14, _step14, product, freshProducts, mergeResult, _iterator15, _step15, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
2278
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2279
+ while (1) switch (_context25.prev = _context25.next) {
1512
2280
  case 0:
1513
2281
  messages = _toConsumableArray(this.pendingSyncMessages);
1514
2282
  this.pendingSyncMessages = [];
1515
2283
  if (!(messages.length === 0)) {
1516
- _context17.next = 4;
2284
+ _context25.next = 4;
1517
2285
  break;
1518
2286
  }
1519
- return _context17.abrupt("return");
2287
+ return _context25.abrupt("return");
1520
2288
  case 4:
1521
2289
  this.logInfo('processProductSyncMessages: 开始处理', {
1522
2290
  count: messages.length
@@ -1526,18 +2294,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1526
2294
  sseRefreshIds = [];
1527
2295
  priceRefreshIds = [];
1528
2296
  shouldClearPriceCache = false;
1529
- _iterator7 = _createForOfIteratorHelper(messages);
1530
- _context17.prev = 11;
1531
- _iterator7.s();
2297
+ _iterator13 = _createForOfIteratorHelper(messages);
2298
+ _context25.prev = 11;
2299
+ _iterator13.s();
1532
2300
  case 13:
1533
- if ((_step7 = _iterator7.n()).done) {
1534
- _context17.next = 36;
2301
+ if ((_step13 = _iterator13.n()).done) {
2302
+ _context25.next = 36;
1535
2303
  break;
1536
2304
  }
1537
- msg = _step7.value;
2305
+ msg = _step13.value;
1538
2306
  channelKey = msg._channelKey || msg.module || 'product';
1539
2307
  if (!(channelKey === 'product')) {
1540
- _context17.next = 33;
2308
+ _context25.next = 33;
1541
2309
  break;
1542
2310
  }
1543
2311
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
@@ -1545,14 +2313,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1545
2313
  }
1546
2314
  // 1. 删除场景:operation === 'delete' 或 action === 'delete'
1547
2315
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
1548
- _context17.next = 21;
2316
+ _context25.next = 21;
1549
2317
  break;
1550
2318
  }
1551
2319
  if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
1552
- return _context17.abrupt("continue", 34);
2320
+ return _context25.abrupt("continue", 34);
1553
2321
  case 21:
1554
2322
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
1555
- _context17.next = 26;
2323
+ _context25.next = 26;
1556
2324
  break;
1557
2325
  }
1558
2326
  ids = msg.ids || (msg.id ? [msg.id] : []);
@@ -1561,15 +2329,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1561
2329
  bodyId = msg.body.id;
1562
2330
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
1563
2331
  }
1564
- return _context17.abrupt("continue", 34);
2332
+ return _context25.abrupt("continue", 34);
1565
2333
  case 26:
1566
2334
  if (!msg.body) {
1567
- _context17.next = 30;
2335
+ _context25.next = 30;
1568
2336
  break;
1569
2337
  }
1570
2338
  _bodyId = msg.body.id || msg.id;
1571
2339
  if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
1572
- return _context17.abrupt("continue", 34);
2340
+ return _context25.abrupt("continue", 34);
1573
2341
  case 30:
1574
2342
  // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1575
2343
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
@@ -1577,7 +2345,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1577
2345
  } else if (msg.id) {
1578
2346
  sseRefreshIds.push(msg.id);
1579
2347
  }
1580
- _context17.next = 34;
2348
+ _context25.next = 34;
1581
2349
  break;
1582
2350
  case 33:
1583
2351
  if (channelKey === 'product_quotation') {
@@ -1590,59 +2358,117 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1590
2358
  if ((_msg$relation_product3 = msg.relation_product_ids) !== null && _msg$relation_product3 !== void 0 && _msg$relation_product3.length) {
1591
2359
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1592
2360
  }
2361
+ } else if (['product_data_variant'].includes(channelKey)) {
2362
+ if ((_msg$product_ids = msg.product_ids) !== null && _msg$product_ids !== void 0 && _msg$product_ids.length) {
2363
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.product_ids));
2364
+ }
1593
2365
  }
1594
2366
  case 34:
1595
- _context17.next = 13;
2367
+ _context25.next = 13;
1596
2368
  break;
1597
2369
  case 36:
1598
- _context17.next = 41;
2370
+ _context25.next = 41;
1599
2371
  break;
1600
2372
  case 38:
1601
- _context17.prev = 38;
1602
- _context17.t0 = _context17["catch"](11);
1603
- _iterator7.e(_context17.t0);
2373
+ _context25.prev = 38;
2374
+ _context25.t0 = _context25["catch"](11);
2375
+ _iterator13.e(_context25.t0);
1604
2376
  case 41:
1605
- _context17.prev = 41;
1606
- _iterator7.f();
1607
- return _context17.finish(41);
2377
+ _context25.prev = 41;
2378
+ _iterator13.f();
2379
+ return _context25.finish(41);
1608
2380
  case 44:
1609
2381
  uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
1610
2382
  uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
1611
2383
  uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
1612
2384
  if (!(uniqueDeleteIds.length > 0)) {
1613
- _context17.next = 50;
2385
+ _context25.next = 50;
1614
2386
  break;
1615
2387
  }
1616
- _context17.next = 50;
2388
+ _context25.next = 50;
1617
2389
  return this.removeProductsByIds(uniqueDeleteIds);
1618
2390
  case 50:
2391
+ /** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
2392
+ patchProductMap = new Map();
2393
+ patchMergeActions = {};
2394
+ storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
1619
2395
  if (!(bodyUpdates.size > 0)) {
1620
- _context17.next = 53;
2396
+ _context25.next = 60;
1621
2397
  break;
1622
2398
  }
1623
- _context17.next = 53;
1624
- return this.applyBodyUpdatesToStore(bodyUpdates);
1625
- case 53:
2399
+ _context25.next = 56;
2400
+ return this.applyBodyUpdatesToStore(bodyUpdates, {
2401
+ skipIndexDB: true,
2402
+ skipEmit: true
2403
+ });
2404
+ case 56:
2405
+ bodyResult = _context25.sent;
2406
+ _iterator14 = _createForOfIteratorHelper(bodyResult.changedProducts);
2407
+ try {
2408
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2409
+ product = _step14.value;
2410
+ patchProductMap.set(product.id, product);
2411
+ patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
2412
+ }
2413
+ } catch (err) {
2414
+ _iterator14.e(err);
2415
+ } finally {
2416
+ _iterator14.f();
2417
+ }
2418
+ storeMutated = true;
2419
+ case 60:
2420
+ // 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
2421
+ freshProducts = [];
1626
2422
  if (!(uniqueSSEIds.length > 0)) {
1627
- _context17.next = 61;
2423
+ _context25.next = 73;
1628
2424
  break;
1629
2425
  }
1630
- _context17.next = 56;
2426
+ _context25.next = 64;
1631
2427
  return this.fetchProductsBySSE(uniqueSSEIds);
1632
- case 56:
1633
- freshProducts = _context17.sent;
2428
+ case 64:
2429
+ freshProducts = _context25.sent;
1634
2430
  if (!(freshProducts.length > 0)) {
1635
- _context17.next = 60;
2431
+ _context25.next = 72;
1636
2432
  break;
1637
2433
  }
1638
- _context17.next = 60;
1639
- return this.mergeProductsToStore(freshProducts);
1640
- case 60:
2434
+ _context25.next = 68;
2435
+ return this.mergeProductsToStore(freshProducts, {
2436
+ skipIndexDB: true,
2437
+ skipEmit: true
2438
+ });
2439
+ case 68:
2440
+ mergeResult = _context25.sent;
2441
+ _iterator15 = _createForOfIteratorHelper(mergeResult.changedProducts);
2442
+ try {
2443
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2444
+ _product = _step15.value;
2445
+ patchProductMap.set(_product.id, _product);
2446
+ patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
2447
+ }
2448
+ } catch (err) {
2449
+ _iterator15.e(err);
2450
+ } finally {
2451
+ _iterator15.f();
2452
+ }
2453
+ storeMutated = true;
2454
+ case 72:
1641
2455
  this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
1642
2456
  requestedCount: uniqueSSEIds.length,
1643
2457
  receivedCount: freshProducts.length
1644
2458
  });
1645
- case 61:
2459
+ case 73:
2460
+ patchProducts = _toConsumableArray(patchProductMap.values());
2461
+ if (!(patchProducts.length > 0)) {
2462
+ _context25.next = 77;
2463
+ break;
2464
+ }
2465
+ _context25.next = 77;
2466
+ return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
2467
+ case 77:
2468
+ if (storeMutated) {
2469
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2470
+ }
2471
+
1646
2472
  // 收集所有非 delete 的变更 IDs(body + SSE + price),用于增量更新价格缓存
1647
2473
  allChangedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(Array.from(bodyUpdates.keys())), _toConsumableArray(uniqueSSEIds), _toConsumableArray(uniquePriceIds))));
1648
2474
  this.logInfo('processProductSyncMessages: 处理完成123', {
@@ -1655,25 +2481,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1655
2481
  });
1656
2482
  hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
1657
2483
  if (hasChanges) {
1658
- _context17.next = 67;
2484
+ _context25.next = 84;
1659
2485
  break;
1660
2486
  }
1661
2487
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
1662
- return _context17.abrupt("return");
1663
- case 67:
1664
- // 报价单变更 → 清除全量价格缓存,后续走全量重建
1665
- if (shouldClearPriceCache) {
1666
- this.clearPriceCache();
2488
+ return _context25.abrupt("return");
2489
+ case 84:
2490
+ if (!shouldClearPriceCache) {
2491
+ _context25.next = 95;
2492
+ break;
1667
2493
  }
1668
- _context17.next = 70;
2494
+ _context25.prev = 85;
2495
+ _context25.next = 88;
2496
+ return this.refreshQuotationPriceBridge();
2497
+ case 88:
2498
+ _context25.next = 94;
2499
+ break;
2500
+ case 90:
2501
+ _context25.prev = 90;
2502
+ _context25.t1 = _context25["catch"](85);
2503
+ errorMessage = _context25.t1 instanceof Error ? _context25.t1.message : String(_context25.t1);
2504
+ this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
2505
+ error: errorMessage
2506
+ });
2507
+ case 94:
2508
+ this.clearPriceCache();
2509
+ case 95:
2510
+ _context25.next = 97;
1669
2511
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
1670
2512
  changedIds: allChangedIds
1671
2513
  });
1672
- case 70:
2514
+ case 97:
1673
2515
  case "end":
1674
- return _context17.stop();
2516
+ return _context25.stop();
1675
2517
  }
1676
- }, _callee17, this, [[11, 38, 41, 44]]);
2518
+ }, _callee25, this, [[11, 38, 41, 44], [85, 90]]);
1677
2519
  }));
1678
2520
  function processProductSyncMessages() {
1679
2521
  return _processProductSyncMessages.apply(this, arguments);
@@ -1688,25 +2530,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1688
2530
  }, {
1689
2531
  key: "fetchProductsBySSE",
1690
2532
  value: (function () {
1691
- var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
2533
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(ids) {
1692
2534
  var t0, productList, list, errorMessage;
1693
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1694
- while (1) switch (_context18.prev = _context18.next) {
2535
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2536
+ while (1) switch (_context26.prev = _context26.next) {
1695
2537
  case 0:
1696
2538
  if (this.productDataSource) {
1697
- _context18.next = 3;
2539
+ _context26.next = 3;
1698
2540
  break;
1699
2541
  }
1700
2542
  this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
1701
- return _context18.abrupt("return", []);
2543
+ return _context26.abrupt("return", []);
1702
2544
  case 3:
1703
2545
  this.logInfo('fetchProductsBySSE: 开始', {
1704
2546
  ids: ids,
1705
2547
  count: ids.length
1706
2548
  });
1707
2549
  t0 = performance.now();
1708
- _context18.prev = 5;
1709
- _context18.next = 8;
2550
+ _context26.prev = 5;
2551
+ _context26.next = 8;
1710
2552
  return this.productDataSource.run({
1711
2553
  sse: {
1712
2554
  query: {
@@ -1716,7 +2558,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1716
2558
  }
1717
2559
  });
1718
2560
  case 8:
1719
- productList = _context18.sent;
2561
+ productList = _context26.sent;
1720
2562
  list = productList || [];
1721
2563
  perfMark('fetchProductsBySSE', performance.now() - t0, {
1722
2564
  count: list.length
@@ -1726,23 +2568,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1726
2568
  receivedCount: list.length,
1727
2569
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1728
2570
  });
1729
- return _context18.abrupt("return", list);
2571
+ return _context26.abrupt("return", list);
1730
2572
  case 15:
1731
- _context18.prev = 15;
1732
- _context18.t0 = _context18["catch"](5);
1733
- errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
2573
+ _context26.prev = 15;
2574
+ _context26.t0 = _context26["catch"](5);
2575
+ errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
1734
2576
  this.logError('fetchProductsBySSE: 失败', {
1735
2577
  ids: ids,
1736
2578
  error: errorMessage
1737
2579
  });
1738
- return _context18.abrupt("return", []);
2580
+ return _context26.abrupt("return", []);
1739
2581
  case 20:
1740
2582
  case "end":
1741
- return _context18.stop();
2583
+ return _context26.stop();
1742
2584
  }
1743
- }, _callee18, this, [[5, 15]]);
2585
+ }, _callee26, this, [[5, 15]]);
1744
2586
  }));
1745
- function fetchProductsBySSE(_x17) {
2587
+ function fetchProductsBySSE(_x25) {
1746
2588
  return _fetchProductsBySSE.apply(this, arguments);
1747
2589
  }
1748
2590
  return fetchProductsBySSE;
@@ -1750,63 +2592,84 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1750
2592
  /**
1751
2593
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
1752
2594
  * 已存在的 → 直接替换;不存在的 → 追加
1753
- * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
1754
- * 价格缓存由 processProductSyncMessages 末尾统一清除
2595
+ *
2596
+ * @example
2597
+ * await this.applyBodyUpdatesToStore(bodyUpdates, { skipIndexDB: true })
1755
2598
  */
1756
2599
  )
1757
2600
  }, {
1758
2601
  key: "applyBodyUpdatesToStore",
1759
2602
  value: (function () {
1760
- var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(bodyUpdates) {
1761
- var updatedCount, newCount, appliedIds, _iterator8, _step8, _step8$value, id, body;
1762
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1763
- while (1) switch (_context19.prev = _context19.next) {
2603
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(bodyUpdates, options) {
2604
+ var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator16, _step16, _step16$value, id, body;
2605
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2606
+ while (1) switch (_context27.prev = _context27.next) {
1764
2607
  case 0:
2608
+ changedProductIds = _toConsumableArray(bodyUpdates.keys());
1765
2609
  this.logInfo('applyBodyUpdatesToStore: 开始', {
1766
2610
  count: bodyUpdates.size
1767
2611
  });
1768
2612
  updatedCount = 0;
1769
2613
  newCount = 0;
1770
2614
  appliedIds = new Set();
2615
+ mergeActions = {};
2616
+ changedProducts = [];
1771
2617
  this.store.list = this.store.list.map(function (p) {
1772
2618
  if (bodyUpdates.has(p.id)) {
1773
2619
  updatedCount++;
1774
2620
  appliedIds.add(p.id);
1775
- return bodyUpdates.get(p.id);
2621
+ mergeActions[p.id] = 'update';
2622
+ var next = bodyUpdates.get(p.id);
2623
+ changedProducts.push(next);
2624
+ return next;
1776
2625
  }
1777
2626
  return p;
1778
2627
  });
1779
- _iterator8 = _createForOfIteratorHelper(bodyUpdates);
2628
+ _iterator16 = _createForOfIteratorHelper(bodyUpdates);
1780
2629
  try {
1781
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1782
- _step8$value = _slicedToArray(_step8.value, 2), id = _step8$value[0], body = _step8$value[1];
2630
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2631
+ _step16$value = _slicedToArray(_step16.value, 2), id = _step16$value[0], body = _step16$value[1];
1783
2632
  if (!appliedIds.has(id)) {
1784
2633
  this.store.list.push(body);
1785
2634
  newCount++;
2635
+ mergeActions[id] = 'insert';
2636
+ changedProducts.push(body);
1786
2637
  }
1787
2638
  }
1788
2639
  } catch (err) {
1789
- _iterator8.e(err);
2640
+ _iterator16.e(err);
1790
2641
  } finally {
1791
- _iterator8.f();
2642
+ _iterator16.f();
1792
2643
  }
1793
2644
  this.syncProductsMap();
1794
- _context19.next = 10;
1795
- return this.saveProductsToIndexDB(this.store.list);
1796
- case 10:
1797
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2645
+ if (options !== null && options !== void 0 && options.skipIndexDB) {
2646
+ _context27.next = 14;
2647
+ break;
2648
+ }
2649
+ _context27.next = 14;
2650
+ return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
2651
+ case 14:
2652
+ if (!(options !== null && options !== void 0 && options.skipEmit)) {
2653
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2654
+ }
1798
2655
  this.logInfo('applyBodyUpdatesToStore: 完成', {
1799
2656
  updatedCount: updatedCount,
1800
2657
  newCount: newCount,
1801
2658
  totalCount: this.store.list.length
1802
2659
  });
1803
- case 12:
2660
+ return _context27.abrupt("return", {
2661
+ changedProducts: changedProducts,
2662
+ mergeActions: mergeActions,
2663
+ updatedCount: updatedCount,
2664
+ newCount: newCount
2665
+ });
2666
+ case 17:
1804
2667
  case "end":
1805
- return _context19.stop();
2668
+ return _context27.stop();
1806
2669
  }
1807
- }, _callee19, this);
2670
+ }, _callee27, this);
1808
2671
  }));
1809
- function applyBodyUpdatesToStore(_x18) {
2672
+ function applyBodyUpdatesToStore(_x26, _x27) {
1810
2673
  return _applyBodyUpdatesToStore.apply(this, arguments);
1811
2674
  }
1812
2675
  return applyBodyUpdatesToStore;
@@ -1814,68 +2677,91 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1814
2677
  /**
1815
2678
  * 将增量拉取的商品合并到 store
1816
2679
  * 已存在的 → 替换;新的 → 追加
1817
- * 同时更新 store.map、IndexDB,触发 onProductsChanged
2680
+ *
2681
+ * @example
2682
+ * await this.mergeProductsToStore(freshProducts, { skipIndexDB: true })
1818
2683
  */
1819
2684
  )
1820
2685
  }, {
1821
2686
  key: "mergeProductsToStore",
1822
2687
  value: (function () {
1823
- var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshProducts) {
1824
- var freshMap, _iterator9, _step9, p, updatedList, newCount, _iterator10, _step10, _p2, updatedCount;
1825
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1826
- while (1) switch (_context20.prev = _context20.next) {
2688
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(freshProducts, options) {
2689
+ var freshMap, _iterator17, _step17, p, mergeActions, changedProducts, updatedList, newCount, _iterator18, _step18, _p2, updatedCount, changedProductIds;
2690
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2691
+ while (1) switch (_context28.prev = _context28.next) {
1827
2692
  case 0:
1828
2693
  freshMap = new Map();
1829
- _iterator9 = _createForOfIteratorHelper(freshProducts);
2694
+ _iterator17 = _createForOfIteratorHelper(freshProducts);
1830
2695
  try {
1831
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1832
- p = _step9.value;
2696
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2697
+ p = _step17.value;
1833
2698
  freshMap.set(p.id, p);
1834
2699
  }
1835
2700
  } catch (err) {
1836
- _iterator9.e(err);
2701
+ _iterator17.e(err);
1837
2702
  } finally {
1838
- _iterator9.f();
2703
+ _iterator17.f();
1839
2704
  }
2705
+ mergeActions = {};
2706
+ changedProducts = [];
1840
2707
  updatedList = this.store.list.map(function (p) {
1841
2708
  if (freshMap.has(p.id)) {
1842
2709
  var fresh = freshMap.get(p.id);
1843
2710
  freshMap.delete(p.id);
2711
+ mergeActions[p.id] = 'update';
2712
+ changedProducts.push(fresh);
1844
2713
  return fresh;
1845
2714
  }
1846
2715
  return p;
1847
2716
  }); // freshMap 中剩余的是新商品(create 场景)
1848
2717
  newCount = freshMap.size;
1849
- _iterator10 = _createForOfIteratorHelper(freshMap.values());
2718
+ _iterator18 = _createForOfIteratorHelper(freshMap.values());
1850
2719
  try {
1851
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1852
- _p2 = _step10.value;
2720
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2721
+ _p2 = _step18.value;
1853
2722
  updatedList.push(_p2);
2723
+ mergeActions[_p2.id] = 'insert';
2724
+ changedProducts.push(_p2);
1854
2725
  }
1855
2726
  } catch (err) {
1856
- _iterator10.e(err);
2727
+ _iterator18.e(err);
1857
2728
  } finally {
1858
- _iterator10.f();
2729
+ _iterator18.f();
1859
2730
  }
1860
2731
  updatedCount = freshProducts.length - newCount;
2732
+ changedProductIds = freshProducts.map(function (p) {
2733
+ return p.id;
2734
+ });
1861
2735
  this.store.list = updatedList;
1862
2736
  this.syncProductsMap();
1863
- _context20.next = 12;
1864
- return this.saveProductsToIndexDB(this.store.list);
1865
- case 12:
2737
+ if (options !== null && options !== void 0 && options.skipIndexDB) {
2738
+ _context28.next = 16;
2739
+ break;
2740
+ }
2741
+ _context28.next = 16;
2742
+ return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
2743
+ case 16:
2744
+ if (!(options !== null && options !== void 0 && options.skipEmit)) {
2745
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2746
+ }
1866
2747
  this.logInfo('mergeProductsToStore: 合并完成', {
1867
2748
  updatedCount: updatedCount,
1868
2749
  newCount: newCount,
1869
2750
  totalCount: this.store.list.length
1870
2751
  });
1871
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1872
- case 14:
2752
+ return _context28.abrupt("return", {
2753
+ changedProducts: changedProducts,
2754
+ mergeActions: mergeActions,
2755
+ updatedCount: updatedCount,
2756
+ newCount: newCount
2757
+ });
2758
+ case 19:
1873
2759
  case "end":
1874
- return _context20.stop();
2760
+ return _context28.stop();
1875
2761
  }
1876
- }, _callee20, this);
2762
+ }, _callee28, this);
1877
2763
  }));
1878
- function mergeProductsToStore(_x19) {
2764
+ function mergeProductsToStore(_x28, _x29) {
1879
2765
  return _mergeProductsToStore.apply(this, arguments);
1880
2766
  }
1881
2767
  return mergeProductsToStore;
@@ -1889,56 +2775,65 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1889
2775
  }, {
1890
2776
  key: "silentRefresh",
1891
2777
  value: (function () {
1892
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1893
- var t0, products, errorMessage;
1894
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1895
- while (1) switch (_context21.prev = _context21.next) {
2778
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2779
+ var t0, now, elapsedSincePreload, elapsedSinceFullFetch, products, errorMessage;
2780
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2781
+ while (1) switch (_context29.prev = _context29.next) {
1896
2782
  case 0:
1897
2783
  t0 = performance.now();
2784
+ now = Date.now();
2785
+ elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
2786
+ elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
2787
+ if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
2788
+ _context29.next = 6;
2789
+ break;
2790
+ }
2791
+ return _context29.abrupt("return", this.store.list);
2792
+ case 6:
1898
2793
  this.logInfo('silentRefresh 开始');
1899
- _context21.prev = 2;
1900
- _context21.next = 5;
2794
+ _context29.prev = 7;
2795
+ _context29.next = 10;
1901
2796
  return this.loadProductsByServer();
1902
- case 5:
1903
- products = _context21.sent;
2797
+ case 10:
2798
+ products = _context29.sent;
1904
2799
  if (!(products && products.length > 0)) {
1905
- _context21.next = 16;
2800
+ _context29.next = 21;
1906
2801
  break;
1907
2802
  }
1908
2803
  this.store.list = products;
1909
2804
  this.syncProductsMap();
1910
2805
  this.clearPriceCache();
1911
2806
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1912
- _context21.next = 13;
2807
+ _context29.next = 18;
1913
2808
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1914
- case 13:
2809
+ case 18:
1915
2810
  this.logInfo('silentRefresh 完成', {
1916
2811
  productCount: products.length,
1917
2812
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1918
2813
  });
1919
- _context21.next = 17;
2814
+ _context29.next = 22;
1920
2815
  break;
1921
- case 16:
2816
+ case 21:
1922
2817
  this.logWarning('silentRefresh: 服务器未返回数据');
1923
- case 17:
2818
+ case 22:
1924
2819
  perfMark('silentRefresh', performance.now() - t0, {
1925
2820
  count: this.store.list.length
1926
2821
  });
1927
- return _context21.abrupt("return", this.store.list);
1928
- case 21:
1929
- _context21.prev = 21;
1930
- _context21.t0 = _context21["catch"](2);
1931
- errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
2822
+ return _context29.abrupt("return", this.store.list);
2823
+ case 26:
2824
+ _context29.prev = 26;
2825
+ _context29.t0 = _context29["catch"](7);
2826
+ errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
1932
2827
  this.logError('silentRefresh 失败', {
1933
2828
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
1934
2829
  error: errorMessage
1935
2830
  });
1936
- return _context21.abrupt("return", this.store.list);
1937
- case 26:
2831
+ return _context29.abrupt("return", this.store.list);
2832
+ case 31:
1938
2833
  case "end":
1939
- return _context21.stop();
2834
+ return _context29.stop();
1940
2835
  }
1941
- }, _callee21, this, [[2, 21]]);
2836
+ }, _callee29, this, [[7, 26]]);
1942
2837
  }));
1943
2838
  function silentRefresh() {
1944
2839
  return _silentRefresh.apply(this, arguments);