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