@pisell/pisellos 3.0.74 → 3.0.76
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 +2 -1
- package/dist/effects/index.d.ts +5 -3
- package/dist/effects/index.js +40 -8
- package/dist/modules/Account/index.js +2 -3
- package/dist/modules/AccountList/index.d.ts +7 -1
- package/dist/modules/AccountList/index.js +81 -14
- package/dist/modules/AccountList/types.d.ts +28 -0
- package/dist/modules/AccountList/types.js +8 -0
- package/dist/modules/BaseModule.d.ts +3 -0
- package/dist/modules/BaseModule.js +15 -0
- package/dist/modules/Cart/index.d.ts +1 -0
- package/dist/modules/Cart/index.js +2 -1
- package/dist/modules/Cart/utils/cartProduct.js +21 -4
- package/dist/modules/Customer/constants.d.ts +7 -0
- package/dist/modules/Customer/constants.js +12 -0
- package/dist/modules/Customer/index.d.ts +122 -0
- package/dist/modules/Customer/index.js +696 -0
- package/dist/modules/Customer/types.d.ts +146 -0
- package/dist/modules/Customer/types.js +41 -0
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +3 -3
- package/dist/modules/Discount/types.d.ts +9 -0
- package/dist/modules/Guests/index.js +9 -9
- package/dist/modules/Order/index.d.ts +25 -1
- package/dist/modules/Order/index.js +224 -3
- package/dist/modules/Order/types.d.ts +45 -0
- package/dist/modules/Order/types.js +8 -0
- package/dist/modules/Order/utils.js +1 -1
- package/dist/modules/Payment/cash.d.ts +19 -0
- package/dist/modules/Payment/cash.js +97 -0
- package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
- package/dist/modules/Payment/eftpos.d.ts +11 -0
- package/dist/modules/Payment/eftpos.js +80 -0
- package/dist/modules/Payment/index.d.ts +184 -9
- package/dist/modules/Payment/index.js +2084 -109
- package/dist/modules/Payment/mx51.d.ts +0 -0
- package/dist/modules/Payment/mx51.js +0 -0
- package/dist/modules/Payment/types.d.ts +772 -30
- package/dist/modules/Payment/types.js +236 -12
- package/dist/modules/Payment/utils.d.ts +17 -0
- package/dist/modules/Payment/utils.js +62 -0
- package/dist/modules/Payment/walletpass.d.ts +99 -0
- package/dist/modules/Payment/walletpass.js +711 -0
- package/dist/modules/ProductList/index.d.ts +12 -1
- package/dist/modules/ProductList/index.js +37 -15
- package/dist/modules/Resource/index.js +1 -1
- package/dist/modules/Rules/index.d.ts +2 -1
- package/dist/modules/Rules/index.js +470 -127
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/Schedule/index.d.ts +9 -0
- package/dist/modules/Schedule/index.js +77 -0
- package/dist/modules/Summary/utils.d.ts +5 -0
- package/dist/modules/Summary/utils.js +36 -1
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/app-types/app/app.d.ts +83 -0
- package/dist/plugins/app-types/app/const.d.ts +4 -0
- package/dist/plugins/app-types/app/index.d.ts +14 -0
- package/dist/plugins/app-types/applicationManager/application.d.ts +50 -0
- package/dist/plugins/app-types/applicationManager/index.d.ts +13 -0
- package/dist/plugins/app-types/config.d.ts +3 -0
- package/dist/plugins/app-types/cookie/index.d.ts +13 -0
- package/dist/plugins/app-types/data/index.d.ts +8 -0
- package/dist/plugins/app-types/history/config.d.ts +24 -0
- package/dist/plugins/app-types/history/index.d.ts +20 -0
- package/dist/plugins/app-types/history/type.d.ts +2 -0
- package/dist/plugins/app-types/hooks/index.d.ts +12 -0
- package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
- package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
- package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
- package/dist/plugins/app-types/hooks/useStore/index.d.ts +6 -0
- package/dist/plugins/app-types/index.d.ts +6 -0
- package/dist/plugins/app-types/indexDB/index.d.ts +178 -0
- package/dist/plugins/app-types/locales/en.d.ts +3 -0
- package/dist/plugins/app-types/locales/index.d.ts +37 -0
- package/dist/plugins/app-types/locales/original.d.ts +3 -0
- package/dist/plugins/app-types/locales/type.d.ts +19 -0
- package/dist/plugins/app-types/locales/zh-CN.d.ts +3 -0
- package/dist/plugins/app-types/locales/zh-HK.d.ts +3 -0
- package/dist/plugins/app-types/logger/feishu.d.ts +11 -0
- package/dist/plugins/app-types/logger/index.d.ts +122 -0
- package/dist/plugins/app-types/menuManager/hooks.d.ts +17 -0
- package/dist/plugins/app-types/menuManager/index.d.ts +28 -0
- package/dist/plugins/app-types/models/global.d.ts +32 -0
- package/dist/plugins/app-types/models/index.d.ts +45 -0
- package/dist/plugins/app-types/models/type.d.ts +2 -0
- package/dist/plugins/app-types/package.json +15 -0
- package/dist/plugins/app-types/plugin/index.d.ts +0 -0
- package/dist/plugins/app-types/pubsub/example.d.ts +5 -0
- package/dist/plugins/app-types/pubsub/index.d.ts +63 -0
- package/dist/plugins/app-types/request/cache.d.ts +46 -0
- package/dist/plugins/app-types/request/cancelToken.d.ts +38 -0
- package/dist/plugins/app-types/request/config.d.ts +3 -0
- package/dist/plugins/app-types/request/constants.d.ts +2 -0
- package/dist/plugins/app-types/request/index.d.ts +24 -0
- package/dist/plugins/app-types/request/pisell2Request.d.ts +6 -0
- package/dist/plugins/app-types/request/type.d.ts +41 -0
- package/dist/plugins/app-types/request/utils.d.ts +46 -0
- package/dist/plugins/app-types/routes/config.d.ts +7 -0
- package/dist/plugins/app-types/routes/index.d.ts +28 -0
- package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
- package/dist/plugins/app-types/socket/components/index.d.ts +2 -0
- package/dist/plugins/app-types/socket/constants.d.ts +33 -0
- package/dist/plugins/app-types/socket/events.d.ts +31 -0
- package/dist/plugins/app-types/socket/heartbeat.d.ts +66 -0
- package/dist/plugins/app-types/socket/index.d.ts +61 -0
- package/dist/plugins/app-types/socket/monitor.d.ts +169 -0
- package/dist/plugins/app-types/socket/reconnect.d.ts +61 -0
- package/dist/plugins/app-types/socket/socket.d.ts +129 -0
- package/dist/plugins/app-types/socket/types.d.ts +85 -0
- package/dist/plugins/app-types/storage/index.d.ts +17 -0
- package/dist/plugins/app-types/tasks/index.d.ts +77 -0
- package/dist/plugins/app-types/tasks/type.d.ts +62 -0
- package/dist/plugins/app-types/tasks/useTasks.d.ts +5 -0
- package/dist/plugins/app-types/type.d.ts +2 -0
- package/dist/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
- package/dist/plugins/app-types/variables/config.d.ts +3 -0
- package/dist/plugins/app-types/variables/index.d.ts +6 -0
- package/dist/plugins/app-types/variables/type.d.ts +2 -0
- package/dist/plugins/app-types/website/index.d.ts +6 -0
- package/dist/plugins/app.d.ts +8 -0
- package/dist/plugins/app.js +1 -0
- package/dist/plugins/window.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +43 -13
- package/dist/solution/BookingByStep/utils/capacity.js +1 -1
- package/dist/solution/BookingByStep/utils/products.d.ts +6 -0
- package/dist/solution/BookingByStep/utils/products.js +10 -0
- package/dist/solution/BookingTicket/index.d.ts +184 -0
- package/dist/solution/BookingTicket/index.js +698 -0
- package/dist/solution/BookingTicket/types.d.ts +68 -0
- package/dist/solution/BookingTicket/types.js +43 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +22 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +189 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +85 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +294 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
- package/dist/solution/BuyTickets/index.js +7 -8
- package/dist/solution/Checkout/appointmentDemo.json +1 -0
- package/dist/solution/Checkout/index.d.ts +432 -0
- package/dist/solution/Checkout/index.js +4452 -0
- package/dist/solution/Checkout/types.d.ts +727 -0
- package/dist/solution/Checkout/types.js +104 -0
- package/dist/solution/Checkout/utils/index.d.ts +121 -0
- package/dist/solution/Checkout/utils/index.js +511 -0
- package/dist/solution/ShopDiscount/index.d.ts +10 -10
- package/dist/solution/ShopDiscount/index.js +111 -60
- package/dist/solution/ShopDiscount/types.d.ts +8 -0
- package/dist/solution/ShopDiscount/utils.d.ts +24 -0
- package/dist/solution/ShopDiscount/utils.js +135 -1
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/utils/task.d.ts +40 -0
- package/dist/utils/task.js +171 -0
- package/dist/utils/watch.d.ts +102 -0
- package/dist/utils/watch.js +294 -0
- package/lib/core/index.js +1 -1
- package/lib/effects/index.d.ts +5 -3
- package/lib/effects/index.js +17 -1
- package/lib/modules/Account/index.js +2 -3
- package/lib/modules/AccountList/index.d.ts +7 -1
- package/lib/modules/AccountList/index.js +27 -0
- package/lib/modules/AccountList/types.d.ts +28 -0
- package/lib/modules/BaseModule.d.ts +3 -0
- package/lib/modules/BaseModule.js +9 -0
- package/lib/modules/Cart/index.d.ts +1 -0
- package/lib/modules/Cart/index.js +5 -2
- package/lib/modules/Cart/utils/cartProduct.js +22 -6
- package/lib/modules/Customer/constants.d.ts +7 -0
- package/lib/modules/Customer/constants.js +39 -0
- package/lib/modules/Customer/index.d.ts +122 -0
- package/lib/modules/Customer/index.js +439 -0
- package/lib/modules/Customer/types.d.ts +146 -0
- package/lib/modules/Customer/types.js +37 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +3 -3
- package/lib/modules/Discount/types.d.ts +9 -0
- package/lib/modules/Guests/index.js +9 -9
- package/lib/modules/Order/index.d.ts +25 -1
- package/lib/modules/Order/index.js +186 -1
- package/lib/modules/Order/types.d.ts +45 -0
- package/lib/modules/Order/utils.js +1 -1
- package/lib/modules/Payment/cash.d.ts +19 -0
- package/lib/modules/Payment/cash.js +64 -0
- package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
- package/lib/modules/Payment/eftpos.d.ts +11 -0
- package/lib/modules/Payment/eftpos.js +51 -0
- package/lib/modules/Payment/index.d.ts +184 -9
- package/lib/modules/Payment/index.js +1084 -51
- package/lib/modules/Payment/mx51.d.ts +0 -0
- package/lib/modules/Payment/mx51.js +0 -0
- package/lib/modules/Payment/types.d.ts +772 -30
- package/lib/modules/Payment/types.js +79 -6
- package/lib/modules/Payment/utils.d.ts +17 -0
- package/lib/modules/Payment/utils.js +67 -0
- package/lib/modules/Payment/walletpass.d.ts +99 -0
- package/lib/modules/Payment/walletpass.js +484 -0
- package/lib/modules/ProductList/index.d.ts +12 -1
- package/lib/modules/ProductList/index.js +31 -12
- package/lib/modules/Resource/index.js +1 -1
- package/lib/modules/Rules/index.d.ts +2 -1
- package/lib/modules/Rules/index.js +318 -72
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/Schedule/index.d.ts +9 -0
- package/lib/modules/Schedule/index.js +60 -0
- package/lib/modules/Summary/utils.d.ts +5 -0
- package/lib/modules/Summary/utils.js +27 -3
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -0
- package/lib/plugins/app-types/app/app.d.ts +83 -0
- package/lib/plugins/app-types/app/const.d.ts +4 -0
- package/lib/plugins/app-types/app/index.d.ts +14 -0
- package/lib/plugins/app-types/applicationManager/application.d.ts +50 -0
- package/lib/plugins/app-types/applicationManager/index.d.ts +13 -0
- package/lib/plugins/app-types/config.d.ts +3 -0
- package/lib/plugins/app-types/cookie/index.d.ts +13 -0
- package/lib/plugins/app-types/data/index.d.ts +8 -0
- package/lib/plugins/app-types/history/config.d.ts +24 -0
- package/lib/plugins/app-types/history/index.d.ts +20 -0
- package/lib/plugins/app-types/history/type.d.ts +2 -0
- package/lib/plugins/app-types/hooks/index.d.ts +12 -0
- package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
- package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
- package/lib/plugins/app-types/hooks/useStore/index.d.ts +6 -0
- package/lib/plugins/app-types/index.d.ts +6 -0
- package/lib/plugins/app-types/indexDB/index.d.ts +178 -0
- package/lib/plugins/app-types/locales/en.d.ts +3 -0
- package/lib/plugins/app-types/locales/index.d.ts +37 -0
- package/lib/plugins/app-types/locales/original.d.ts +3 -0
- package/lib/plugins/app-types/locales/type.d.ts +19 -0
- package/lib/plugins/app-types/locales/zh-CN.d.ts +3 -0
- package/lib/plugins/app-types/locales/zh-HK.d.ts +3 -0
- package/lib/plugins/app-types/logger/feishu.d.ts +11 -0
- package/lib/plugins/app-types/logger/index.d.ts +122 -0
- package/lib/plugins/app-types/menuManager/hooks.d.ts +17 -0
- package/lib/plugins/app-types/menuManager/index.d.ts +28 -0
- package/lib/plugins/app-types/models/global.d.ts +32 -0
- package/lib/plugins/app-types/models/index.d.ts +45 -0
- package/lib/plugins/app-types/models/type.d.ts +2 -0
- package/lib/plugins/app-types/package.json +15 -0
- package/lib/plugins/app-types/plugin/index.d.ts +0 -0
- package/lib/plugins/app-types/pubsub/example.d.ts +5 -0
- package/lib/plugins/app-types/pubsub/index.d.ts +63 -0
- package/lib/plugins/app-types/request/cache.d.ts +46 -0
- package/lib/plugins/app-types/request/cancelToken.d.ts +38 -0
- package/lib/plugins/app-types/request/config.d.ts +3 -0
- package/lib/plugins/app-types/request/constants.d.ts +2 -0
- package/lib/plugins/app-types/request/index.d.ts +24 -0
- package/lib/plugins/app-types/request/pisell2Request.d.ts +6 -0
- package/lib/plugins/app-types/request/type.d.ts +41 -0
- package/lib/plugins/app-types/request/utils.d.ts +46 -0
- package/lib/plugins/app-types/routes/config.d.ts +7 -0
- package/lib/plugins/app-types/routes/index.d.ts +28 -0
- package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/plugins/app-types/socket/components/index.d.ts +2 -0
- package/lib/plugins/app-types/socket/constants.d.ts +33 -0
- package/lib/plugins/app-types/socket/events.d.ts +31 -0
- package/lib/plugins/app-types/socket/heartbeat.d.ts +66 -0
- package/lib/plugins/app-types/socket/index.d.ts +61 -0
- package/lib/plugins/app-types/socket/monitor.d.ts +169 -0
- package/lib/plugins/app-types/socket/reconnect.d.ts +61 -0
- package/lib/plugins/app-types/socket/socket.d.ts +129 -0
- package/lib/plugins/app-types/socket/types.d.ts +85 -0
- package/lib/plugins/app-types/storage/index.d.ts +17 -0
- package/lib/plugins/app-types/tasks/index.d.ts +77 -0
- package/lib/plugins/app-types/tasks/type.d.ts +62 -0
- package/lib/plugins/app-types/tasks/useTasks.d.ts +5 -0
- package/lib/plugins/app-types/type.d.ts +2 -0
- package/lib/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
- package/lib/plugins/app-types/variables/config.d.ts +3 -0
- package/lib/plugins/app-types/variables/index.d.ts +6 -0
- package/lib/plugins/app-types/variables/type.d.ts +2 -0
- package/lib/plugins/app-types/website/index.d.ts +6 -0
- package/lib/plugins/app.d.ts +8 -0
- package/lib/plugins/app.js +17 -0
- package/lib/plugins/window.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +18 -6
- package/lib/solution/BookingByStep/utils/capacity.js +1 -1
- package/lib/solution/BookingByStep/utils/products.d.ts +6 -0
- package/lib/solution/BookingByStep/utils/products.js +8 -2
- package/lib/solution/BookingTicket/index.d.ts +184 -0
- package/lib/solution/BookingTicket/index.js +426 -0
- package/lib/solution/BookingTicket/types.d.ts +68 -0
- package/lib/solution/BookingTicket/types.js +72 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +22 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +132 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +85 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +216 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
- package/lib/solution/BuyTickets/index.js +7 -8
- package/lib/solution/Checkout/appointmentDemo.json +1 -0
- package/lib/solution/Checkout/index.d.ts +432 -0
- package/lib/solution/Checkout/index.js +2776 -0
- package/lib/solution/Checkout/types.d.ts +727 -0
- package/lib/solution/Checkout/types.js +63 -0
- package/lib/solution/Checkout/utils/index.d.ts +121 -0
- package/lib/solution/Checkout/utils/index.js +362 -0
- package/lib/solution/ShopDiscount/index.d.ts +10 -10
- package/lib/solution/ShopDiscount/index.js +53 -27
- package/lib/solution/ShopDiscount/types.d.ts +8 -0
- package/lib/solution/ShopDiscount/utils.d.ts +24 -0
- package/lib/solution/ShopDiscount/utils.js +88 -1
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/lib/types/index.d.ts +4 -1
- package/lib/utils/task.d.ts +40 -0
- package/lib/utils/task.js +109 -0
- package/lib/utils/watch.d.ts +102 -0
- package/lib/utils/watch.js +217 -0
- package/package.json +3 -1
|
@@ -34,11 +34,11 @@ __export(ShopDiscount_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(ShopDiscount_exports);
|
|
36
36
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
|
-
var import_types = require("./types");
|
|
38
37
|
var import_Discount = require("../../modules/Discount");
|
|
39
38
|
var import_Rules = require("../../modules/Rules");
|
|
40
39
|
var import_utils = require("./utils");
|
|
41
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
|
+
var import_lodash_es = require("lodash-es");
|
|
42
42
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
43
43
|
constructor(name, version) {
|
|
44
44
|
super(name, version);
|
|
@@ -77,7 +77,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
77
77
|
(_a = this.store.discount) == null ? void 0 : _a.destroy();
|
|
78
78
|
(_b = this.store.rules) == null ? void 0 : _b.destroy();
|
|
79
79
|
this.core.effects.offByModuleDestroy(this.name);
|
|
80
|
-
await this.core.effects.emit(
|
|
80
|
+
await this.core.effects.emit(`${this.name}:onDestroy`, {});
|
|
81
81
|
console.log("[ShopDiscount] 已销毁");
|
|
82
82
|
}
|
|
83
83
|
async clear() {
|
|
@@ -127,8 +127,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
127
127
|
this.store.rules = rules;
|
|
128
128
|
}
|
|
129
129
|
registerEventListeners() {
|
|
130
|
-
this.core.effects.
|
|
131
|
-
|
|
130
|
+
this.core.effects.only(
|
|
131
|
+
`${this.name}:onCustomerChange`,
|
|
132
132
|
(customer) => {
|
|
133
133
|
var _a;
|
|
134
134
|
if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
|
|
@@ -188,7 +188,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
188
188
|
if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
|
|
189
189
|
this.store.customer = customer;
|
|
190
190
|
await this.core.effects.emit(
|
|
191
|
-
|
|
191
|
+
`${this.name}:onCustomerChange`,
|
|
192
192
|
customer
|
|
193
193
|
);
|
|
194
194
|
}
|
|
@@ -226,27 +226,34 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
// 设置优惠券使用状态
|
|
229
|
-
setDiscountSelected({
|
|
230
|
-
discountId,
|
|
231
|
-
isSelected
|
|
232
|
-
}) {
|
|
229
|
+
setDiscountSelected(params) {
|
|
233
230
|
const discountList = this.getDiscountList();
|
|
231
|
+
const selectionOperations = [];
|
|
232
|
+
selectionOperations.push({
|
|
233
|
+
discountId: params.discountId,
|
|
234
|
+
isSelected: params.isSelected
|
|
235
|
+
});
|
|
236
|
+
if (params.selectedList && params.selectedList.length > 0) {
|
|
237
|
+
selectionOperations.push(...params.selectedList);
|
|
238
|
+
}
|
|
239
|
+
const selectionMap = /* @__PURE__ */ new Map();
|
|
240
|
+
selectionOperations.forEach((operation) => {
|
|
241
|
+
selectionMap.set(operation.discountId, operation.isSelected);
|
|
242
|
+
});
|
|
234
243
|
const newDiscountList = discountList.map((discount) => {
|
|
235
|
-
if (discount.id
|
|
244
|
+
if (selectionMap.has(discount.id)) {
|
|
245
|
+
const targetIsSelected = selectionMap.get(discount.id);
|
|
236
246
|
return {
|
|
237
247
|
...discount,
|
|
238
|
-
isSelected,
|
|
248
|
+
isSelected: targetIsSelected,
|
|
239
249
|
// 手动设置不使用
|
|
240
|
-
isManualSelect: !
|
|
250
|
+
isManualSelect: !targetIsSelected
|
|
241
251
|
};
|
|
242
252
|
}
|
|
243
253
|
return { ...discount, isManualSelect: !(discount == null ? void 0 : discount.isSelected) };
|
|
244
254
|
});
|
|
245
255
|
this.setDiscountList(newDiscountList);
|
|
246
|
-
return this.calcDiscount(this.store.productList || [],
|
|
247
|
-
discountId,
|
|
248
|
-
isSelected
|
|
249
|
-
});
|
|
256
|
+
return this.calcDiscount(this.store.productList || [], params);
|
|
250
257
|
}
|
|
251
258
|
setProductList(productList) {
|
|
252
259
|
this.store.productList = productList;
|
|
@@ -305,6 +312,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
305
312
|
};
|
|
306
313
|
if (isAvailable) {
|
|
307
314
|
this.setDiscountList(newDiscountList || []);
|
|
315
|
+
this.store.originalDiscountList = newDiscountList || [];
|
|
308
316
|
this.setProductList(newProductList || []);
|
|
309
317
|
if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop") {
|
|
310
318
|
await this.getCustomerWallet(
|
|
@@ -347,7 +355,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
347
355
|
// 触发优惠列表变更事件
|
|
348
356
|
async emitDiscountListChange(discountList) {
|
|
349
357
|
await this.core.effects.emit(
|
|
350
|
-
|
|
358
|
+
`${this.name}:onDiscountListChange`,
|
|
351
359
|
discountList
|
|
352
360
|
);
|
|
353
361
|
}
|
|
@@ -361,7 +369,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
361
369
|
if (item.booking_id) {
|
|
362
370
|
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
|
|
363
371
|
(item.discount_list || []).forEach((discount) => {
|
|
364
|
-
var _a3, _b, _c;
|
|
372
|
+
var _a3, _b, _c, _d, _e;
|
|
365
373
|
if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
|
|
366
374
|
const index = editModeDiscountList.findIndex((n) => {
|
|
367
375
|
var _a4;
|
|
@@ -371,7 +379,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
371
379
|
editModeDiscountList[index] = {
|
|
372
380
|
...editModeDiscountList[index],
|
|
373
381
|
amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
374
|
-
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
382
|
+
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_a3 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a3.product_discount_difference) || 0).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
375
383
|
};
|
|
376
384
|
} else {
|
|
377
385
|
if (discount.type && !discount.tag) {
|
|
@@ -379,15 +387,16 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
379
387
|
}
|
|
380
388
|
editModeDiscountList.push({
|
|
381
389
|
...discount,
|
|
390
|
+
name: discount.name || discount.discount.title.auto,
|
|
382
391
|
isEditMode: true,
|
|
383
392
|
limited_relation_product_data: {},
|
|
384
|
-
savedAmount: discount.amount
|
|
393
|
+
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0).toNumber(),
|
|
385
394
|
isAvailable: true,
|
|
386
|
-
id: ((
|
|
387
|
-
format_title: ((
|
|
395
|
+
id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
|
|
396
|
+
format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
|
|
388
397
|
isDisabled: true,
|
|
389
398
|
isSelected: true,
|
|
390
|
-
product_id: ((
|
|
399
|
+
product_id: ((_e = discount.discount) == null ? void 0 : _e.product_id) || discount.product_id
|
|
391
400
|
});
|
|
392
401
|
}
|
|
393
402
|
}
|
|
@@ -404,7 +413,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
404
413
|
if (!targetProduct)
|
|
405
414
|
return false;
|
|
406
415
|
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
407
|
-
return Number(product == null ? void 0 : product.total)
|
|
416
|
+
return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
|
|
408
417
|
};
|
|
409
418
|
const allUsedProductIds = newDiscountList.filter((item) => !(item == null ? void 0 : item.isEditMode)).map((n) => {
|
|
410
419
|
var _a2;
|
|
@@ -446,7 +455,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
446
455
|
const { ...customer } = result.data;
|
|
447
456
|
this.setCustomer(customer);
|
|
448
457
|
await this.core.effects.emit(
|
|
449
|
-
|
|
458
|
+
`${this.name}:onScanCustomerChange`,
|
|
450
459
|
customer
|
|
451
460
|
);
|
|
452
461
|
}
|
|
@@ -454,6 +463,23 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
454
463
|
console.error("[ShopDiscount] 获取客户钱包信息出错:", error);
|
|
455
464
|
}
|
|
456
465
|
}
|
|
466
|
+
async bestDiscount(cb) {
|
|
467
|
+
var _a;
|
|
468
|
+
const newDiscountList = this.store.originalDiscountList;
|
|
469
|
+
this.setDiscountList(newDiscountList);
|
|
470
|
+
if ((_a = this.store.productList) == null ? void 0 : _a.length) {
|
|
471
|
+
const result = this.calcDiscount(this.store.productList);
|
|
472
|
+
cb == null ? void 0 : cb(result);
|
|
473
|
+
await this.core.effects.emit(
|
|
474
|
+
`${this.name}:onLoadPrepareCalcResult`,
|
|
475
|
+
result
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
await this.core.effects.emit(
|
|
479
|
+
`${this.name}:onLoadDiscountList`,
|
|
480
|
+
newDiscountList
|
|
481
|
+
);
|
|
482
|
+
}
|
|
457
483
|
// 加载准备配置
|
|
458
484
|
async loadPrepareConfig(params) {
|
|
459
485
|
var _a, _b, _c, _d, _e;
|
|
@@ -480,12 +506,12 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
480
506
|
if ((_e = this.store.productList) == null ? void 0 : _e.length) {
|
|
481
507
|
const result = this.calcDiscount(this.store.productList);
|
|
482
508
|
await this.core.effects.emit(
|
|
483
|
-
|
|
509
|
+
`${this.name}:onLoadPrepareCalcResult`,
|
|
484
510
|
result
|
|
485
511
|
);
|
|
486
512
|
}
|
|
487
513
|
await this.core.effects.emit(
|
|
488
|
-
|
|
514
|
+
`${this.name}:onLoadDiscountList`,
|
|
489
515
|
filteredDiscountList
|
|
490
516
|
);
|
|
491
517
|
} catch (error) {
|
|
@@ -65,3 +65,27 @@ export declare const getDateIsInSchedule: (dateTime: string, scheduleList: Sched
|
|
|
65
65
|
* @returns 过滤后的优惠券列表
|
|
66
66
|
*/
|
|
67
67
|
export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
|
|
68
|
+
/**
|
|
69
|
+
* 判断是否是订单级别的固定金额折扣卡
|
|
70
|
+
* @param discount 折扣
|
|
71
|
+
* @returns 是否是订单级别的固定金额折扣卡
|
|
72
|
+
*/
|
|
73
|
+
export declare const isOrderLevelFixedAmountDiscount: (discount: Discount) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 计算订单级别固定金额折扣卡的分摊结果
|
|
76
|
+
* @param discount 折扣卡
|
|
77
|
+
* @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
|
|
78
|
+
* @returns 分摊结果 Map<productId, { discountAmount, difference }>
|
|
79
|
+
* 注意:
|
|
80
|
+
* - discountAmount 是单价折扣金额(不是总折扣金额)
|
|
81
|
+
* - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
|
|
82
|
+
*/
|
|
83
|
+
export declare const calculateOrderLevelDiscountAllocation: (discount: Discount, applicableProducts: Array<{
|
|
84
|
+
productId: string | number;
|
|
85
|
+
amount: number;
|
|
86
|
+
quantity: number;
|
|
87
|
+
parentQuantity?: number;
|
|
88
|
+
}>) => Map<string | number, {
|
|
89
|
+
discountAmount: number;
|
|
90
|
+
difference: number;
|
|
91
|
+
}>;
|
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/solution/ShopDiscount/utils.ts
|
|
30
30
|
var utils_exports = {};
|
|
31
31
|
__export(utils_exports, {
|
|
32
|
+
calculateOrderLevelDiscountAllocation: () => calculateOrderLevelDiscountAllocation,
|
|
32
33
|
filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
|
|
33
34
|
getDateIsInSchedule: () => getDateIsInSchedule,
|
|
34
35
|
getDiscountAmount: () => getDiscountAmount,
|
|
@@ -36,6 +37,7 @@ __export(utils_exports, {
|
|
|
36
37
|
getDiscountListAmountTotal: () => getDiscountListAmountTotal,
|
|
37
38
|
isAllNormalProduct: () => isAllNormalProduct,
|
|
38
39
|
isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
|
|
40
|
+
isOrderLevelFixedAmountDiscount: () => isOrderLevelFixedAmountDiscount,
|
|
39
41
|
uniqueById: () => uniqueById
|
|
40
42
|
});
|
|
41
43
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -59,7 +61,7 @@ var getDiscountAmount = (discount, total, price) => {
|
|
|
59
61
|
}
|
|
60
62
|
const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
|
|
61
63
|
if (isFixedAmount) {
|
|
62
|
-
return Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
|
|
64
|
+
return Math.max(new import_decimal.default(price).minus(new import_decimal.default((discount.amount ?? discount.par_value) || 0)).toNumber(), 0);
|
|
63
65
|
}
|
|
64
66
|
return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
|
|
65
67
|
};
|
|
@@ -306,8 +308,92 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
|
306
308
|
}
|
|
307
309
|
});
|
|
308
310
|
};
|
|
311
|
+
var isOrderLevelFixedAmountDiscount = (discount) => {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
return discount.tag === "product_discount_card" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.discount_calculation_mode) === "order_level";
|
|
314
|
+
};
|
|
315
|
+
var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
|
|
316
|
+
const result = /* @__PURE__ */ new Map();
|
|
317
|
+
if (applicableProducts.length === 0) {
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
const totalAmount = applicableProducts.reduce((acc, product) => {
|
|
321
|
+
return new import_decimal.default(acc).plus(new import_decimal.default(product.amount).mul(product.quantity)).toNumber();
|
|
322
|
+
}, 0);
|
|
323
|
+
if (totalAmount <= 0) {
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
const fixedAmount = new import_decimal.default(discount.par_value || 0).toNumber();
|
|
327
|
+
const actualDiscountTotal = Math.min(fixedAmount, totalAmount);
|
|
328
|
+
let allocatedTotal = new import_decimal.default(0);
|
|
329
|
+
applicableProducts.forEach((product) => {
|
|
330
|
+
const rawDiscountPerItem = new import_decimal.default(product.amount).div(totalAmount).mul(actualDiscountTotal);
|
|
331
|
+
const discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
|
|
332
|
+
result.set(product.productId, {
|
|
333
|
+
discountAmount: discountAmountPerItem,
|
|
334
|
+
// 单价折扣金额
|
|
335
|
+
difference: 0
|
|
336
|
+
// 默认差值为0
|
|
337
|
+
});
|
|
338
|
+
allocatedTotal = allocatedTotal.plus(
|
|
339
|
+
new import_decimal.default(discountAmountPerItem).mul(product.quantity)
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
const totalDifference = new import_decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
343
|
+
if (totalDifference > 0) {
|
|
344
|
+
const isSingleQuantity = (product) => {
|
|
345
|
+
if (product.parentQuantity !== void 0) {
|
|
346
|
+
return product.quantity === 1 && product.parentQuantity === 1;
|
|
347
|
+
}
|
|
348
|
+
return product.quantity === 1;
|
|
349
|
+
};
|
|
350
|
+
const singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
|
|
351
|
+
if (singleQuantityProducts.length > 0) {
|
|
352
|
+
const productsWithEnoughSpace = singleQuantityProducts.filter((product) => {
|
|
353
|
+
const allocation = result.get(product.productId);
|
|
354
|
+
if (!allocation)
|
|
355
|
+
return false;
|
|
356
|
+
const remainingSpace = new import_decimal.default(product.amount).minus(allocation.discountAmount).toNumber();
|
|
357
|
+
return remainingSpace >= totalDifference;
|
|
358
|
+
});
|
|
359
|
+
if (productsWithEnoughSpace.length > 0) {
|
|
360
|
+
productsWithEnoughSpace.sort((a, b) => b.amount - a.amount);
|
|
361
|
+
const targetProduct = productsWithEnoughSpace[0];
|
|
362
|
+
const targetAllocation = result.get(targetProduct.productId);
|
|
363
|
+
if (targetAllocation) {
|
|
364
|
+
result.set(targetProduct.productId, {
|
|
365
|
+
discountAmount: new import_decimal.default(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
|
|
366
|
+
difference: 0
|
|
367
|
+
// 不需要存储差值
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
singleQuantityProducts.sort((a, b) => b.amount - a.amount);
|
|
372
|
+
const targetProduct = singleQuantityProducts[0];
|
|
373
|
+
const targetAllocation = result.get(targetProduct.productId);
|
|
374
|
+
if (targetAllocation) {
|
|
375
|
+
result.set(targetProduct.productId, {
|
|
376
|
+
...targetAllocation,
|
|
377
|
+
difference: totalDifference
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
} else {
|
|
382
|
+
const lastProduct = applicableProducts[applicableProducts.length - 1];
|
|
383
|
+
const lastProductAllocation = result.get(lastProduct.productId);
|
|
384
|
+
if (lastProductAllocation) {
|
|
385
|
+
result.set(lastProduct.productId, {
|
|
386
|
+
...lastProductAllocation,
|
|
387
|
+
difference: totalDifference
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
};
|
|
309
394
|
// Annotate the CommonJS export names for ESM import in node:
|
|
310
395
|
0 && (module.exports = {
|
|
396
|
+
calculateOrderLevelDiscountAllocation,
|
|
311
397
|
filterDiscountListByBookingTime,
|
|
312
398
|
getDateIsInSchedule,
|
|
313
399
|
getDiscountAmount,
|
|
@@ -315,5 +401,6 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
|
315
401
|
getDiscountListAmountTotal,
|
|
316
402
|
isAllNormalProduct,
|
|
317
403
|
isNormalProductByDurationSchedule,
|
|
404
|
+
isOrderLevelFixedAmountDiscount,
|
|
318
405
|
uniqueById
|
|
319
406
|
});
|
package/lib/solution/index.d.ts
CHANGED
package/lib/solution/index.js
CHANGED
|
@@ -18,12 +18,16 @@ var solution_exports = {};
|
|
|
18
18
|
module.exports = __toCommonJS(solution_exports);
|
|
19
19
|
__reExport(solution_exports, require("./BuyTickets"), module.exports);
|
|
20
20
|
__reExport(solution_exports, require("./BookingByStep"), module.exports);
|
|
21
|
+
__reExport(solution_exports, require("./BookingTicket"), module.exports);
|
|
21
22
|
__reExport(solution_exports, require("./ShopDiscount"), module.exports);
|
|
22
23
|
__reExport(solution_exports, require("./RegisterAndLogin"), module.exports);
|
|
24
|
+
__reExport(solution_exports, require("./Checkout"), module.exports);
|
|
23
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24
26
|
0 && (module.exports = {
|
|
25
27
|
...require("./BuyTickets"),
|
|
26
28
|
...require("./BookingByStep"),
|
|
29
|
+
...require("./BookingTicket"),
|
|
27
30
|
...require("./ShopDiscount"),
|
|
28
|
-
...require("./RegisterAndLogin")
|
|
31
|
+
...require("./RegisterAndLogin"),
|
|
32
|
+
...require("./Checkout")
|
|
29
33
|
});
|
package/lib/types/index.d.ts
CHANGED
|
@@ -38,7 +38,10 @@ export interface PisellCore {
|
|
|
38
38
|
getModuleExports: <T = any>(name: string) => T | null;
|
|
39
39
|
hasModule: (name: string) => boolean;
|
|
40
40
|
effects: {
|
|
41
|
-
on: (event: string, callback: (payload: any) => void) => void;
|
|
41
|
+
on: (event: string, callback: (payload: any) => void) => () => void;
|
|
42
|
+
once: (event: string, callback: (payload: any) => void) => () => void;
|
|
43
|
+
only: (event: string, callback: (payload: any) => void) => () => void;
|
|
44
|
+
off: (event: string, callback: (payload: any) => void) => void;
|
|
42
45
|
emit: (event: string, payload: any, value?: any) => Promise<{
|
|
43
46
|
status: boolean;
|
|
44
47
|
data: any;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type Action = (...args: any[]) => Promise<any>;
|
|
2
|
+
type Task = {
|
|
3
|
+
uuid: string;
|
|
4
|
+
type: string;
|
|
5
|
+
actionParams?: Record<string, any>;
|
|
6
|
+
};
|
|
7
|
+
declare class Tasks {
|
|
8
|
+
private actions;
|
|
9
|
+
private taskQueue;
|
|
10
|
+
isRunning: boolean;
|
|
11
|
+
constructor(actions?: Map<string, Action>);
|
|
12
|
+
/**
|
|
13
|
+
* 清空所有任务
|
|
14
|
+
*/
|
|
15
|
+
clear(): void;
|
|
16
|
+
/**
|
|
17
|
+
* 清空任务执行队列
|
|
18
|
+
*/
|
|
19
|
+
clearTaskQueue(): void;
|
|
20
|
+
/**
|
|
21
|
+
* 添加action
|
|
22
|
+
* @param name action名称
|
|
23
|
+
* @param action action函数
|
|
24
|
+
*/
|
|
25
|
+
addAction(name: string, action: Action): void;
|
|
26
|
+
/**
|
|
27
|
+
* 添加任务
|
|
28
|
+
* @param task 任务
|
|
29
|
+
*/
|
|
30
|
+
addTask(task: Task): void;
|
|
31
|
+
/**
|
|
32
|
+
* 执行任务
|
|
33
|
+
*/
|
|
34
|
+
run(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* 判定当前的任务是否依然存在
|
|
37
|
+
*/
|
|
38
|
+
isTaskExist(uuid: string): boolean;
|
|
39
|
+
}
|
|
40
|
+
export default Tasks;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/task.ts
|
|
20
|
+
var task_exports = {};
|
|
21
|
+
__export(task_exports, {
|
|
22
|
+
default: () => task_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(task_exports);
|
|
25
|
+
var Tasks = class {
|
|
26
|
+
constructor(actions) {
|
|
27
|
+
this.actions = /* @__PURE__ */ new Map();
|
|
28
|
+
this.taskQueue = [];
|
|
29
|
+
this.isRunning = false;
|
|
30
|
+
if (actions) {
|
|
31
|
+
this.actions = actions;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 清空所有任务
|
|
36
|
+
*/
|
|
37
|
+
clear() {
|
|
38
|
+
this.actions.clear();
|
|
39
|
+
this.taskQueue = [];
|
|
40
|
+
this.isRunning = false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 清空任务执行队列
|
|
44
|
+
*/
|
|
45
|
+
clearTaskQueue() {
|
|
46
|
+
this.taskQueue = [];
|
|
47
|
+
this.isRunning = false;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 添加action
|
|
51
|
+
* @param name action名称
|
|
52
|
+
* @param action action函数
|
|
53
|
+
*/
|
|
54
|
+
addAction(name, action) {
|
|
55
|
+
this.actions.set(name, action);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 添加任务
|
|
59
|
+
* @param task 任务
|
|
60
|
+
*/
|
|
61
|
+
addTask(task) {
|
|
62
|
+
this.taskQueue.push(task);
|
|
63
|
+
this.run();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 执行任务
|
|
67
|
+
*/
|
|
68
|
+
async run() {
|
|
69
|
+
var _a;
|
|
70
|
+
if (this.isRunning) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (this.taskQueue.length === 0) {
|
|
74
|
+
this.isRunning = false;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.isRunning = true;
|
|
78
|
+
while (this.taskQueue.length > 0) {
|
|
79
|
+
const task = (_a = this.taskQueue) == null ? void 0 : _a[0];
|
|
80
|
+
if (!task) {
|
|
81
|
+
this.isRunning = false;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const action = this.actions.get(task.type);
|
|
85
|
+
if (action) {
|
|
86
|
+
try {
|
|
87
|
+
await action({ ...(task == null ? void 0 : task.actionParams) || {}, uuid: task == null ? void 0 : task.uuid });
|
|
88
|
+
console.log("task_success>>>>>>>", task);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error("task_error>>>>>>>", error);
|
|
91
|
+
} finally {
|
|
92
|
+
const _task = this.taskQueue.shift();
|
|
93
|
+
console.log("task_shift>>>>>>>", _task);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
const _task = this.taskQueue.shift();
|
|
97
|
+
console.log("task_action_not_found>>>>>>>", _task);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.isRunning = false;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 判定当前的任务是否依然存在
|
|
104
|
+
*/
|
|
105
|
+
isTaskExist(uuid) {
|
|
106
|
+
return this.taskQueue.some((task) => (task == null ? void 0 : task.uuid) === uuid);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var task_default = Tasks;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 监听模块
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
export type WatchEventCallback = (...args: any[]) => void;
|
|
6
|
+
export type WatchEventItem = {
|
|
7
|
+
key: string;
|
|
8
|
+
callback: WatchEventCallback;
|
|
9
|
+
};
|
|
10
|
+
export interface WatchEventSubscription {
|
|
11
|
+
unsubscribe: () => void;
|
|
12
|
+
}
|
|
13
|
+
declare class Watch {
|
|
14
|
+
private events;
|
|
15
|
+
private enableListMap;
|
|
16
|
+
/**
|
|
17
|
+
* 订阅事件
|
|
18
|
+
* @param event 事件名称
|
|
19
|
+
* @param callback 回调函数
|
|
20
|
+
* @returns 订阅对象,可用于取消订阅
|
|
21
|
+
*/
|
|
22
|
+
subscribe(watchKey: string, event: WatchEventItem): WatchEventSubscription;
|
|
23
|
+
/**
|
|
24
|
+
* 启用事件
|
|
25
|
+
* @param watchKey 监听的key
|
|
26
|
+
* @param event 事件名称
|
|
27
|
+
*/
|
|
28
|
+
enableEvent(watchKey: string, eventKey: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* 禁用某个事件
|
|
31
|
+
* @param watchKey 监听的key
|
|
32
|
+
* @param eventKey 事件名称
|
|
33
|
+
*/
|
|
34
|
+
disableEvent(watchKey: string, eventKey: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* 冻结某个监听下的所有事件
|
|
37
|
+
* @param watchKey 监听的key
|
|
38
|
+
*/
|
|
39
|
+
disabledAllEventByWatchKey(watchKey: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* 启用某个监听下的所有事件
|
|
42
|
+
* @param watchKey 监听的key
|
|
43
|
+
*/
|
|
44
|
+
enableAllEventByWatchKey(watchKey: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 取消订阅事件
|
|
47
|
+
* @param event 事件名称
|
|
48
|
+
* @param callback 回调函数
|
|
49
|
+
* @returns 是否成功取消订阅
|
|
50
|
+
*/
|
|
51
|
+
unsubscribe(watchKey: string, event: WatchEventItem): void;
|
|
52
|
+
/**
|
|
53
|
+
* 发布事件
|
|
54
|
+
* @param event 事件名称
|
|
55
|
+
* @param args 事件参数
|
|
56
|
+
*/
|
|
57
|
+
publish(watchKey: string, ...args: any[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* 根据事件名称发布事件
|
|
60
|
+
* @param watchKey 监听的key
|
|
61
|
+
* @param eventKey 事件名称
|
|
62
|
+
* @param args 事件参数
|
|
63
|
+
*/
|
|
64
|
+
publishByEventKey(watchKey: string, eventKey: string, ...args: any[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* 获取最后一个启用的事件
|
|
67
|
+
* @param watchKey 监听的key
|
|
68
|
+
* @returns 最后一个启用的事件
|
|
69
|
+
*/
|
|
70
|
+
getLastEnableEventKey(watchKey: string): WatchEventItem['key'] | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* 移除某个事件的所有订阅
|
|
73
|
+
* @param event 事件名称
|
|
74
|
+
* @returns 是否成功移除
|
|
75
|
+
*/
|
|
76
|
+
clearEvent(watchKey: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* 移除所有事件订阅
|
|
79
|
+
*/
|
|
80
|
+
clearAllEvents(): void;
|
|
81
|
+
/**
|
|
82
|
+
* 获取事件的订阅数量
|
|
83
|
+
* @param event 事件名称
|
|
84
|
+
* @returns 订阅数量
|
|
85
|
+
*/
|
|
86
|
+
getSubscriberCount(event: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* 检查事件是否有订阅者
|
|
89
|
+
* @param event 事件名称
|
|
90
|
+
* @returns 是否有订阅者
|
|
91
|
+
*/
|
|
92
|
+
hasSubscribers(event: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* 一次性订阅事件,事件触发后自动取消订阅
|
|
95
|
+
* @param event 事件名称
|
|
96
|
+
* @param callback 回调函数
|
|
97
|
+
* @returns 订阅对象,可用于取消订阅
|
|
98
|
+
*/
|
|
99
|
+
once(watchKey: string, event: WatchEventItem): WatchEventSubscription;
|
|
100
|
+
}
|
|
101
|
+
declare const watch: Watch;
|
|
102
|
+
export default watch;
|