@pisell/pisellos 2.1.4 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/dist/core/index.js +2 -1
  2. package/dist/effects/index.d.ts +4 -3
  3. package/dist/effects/index.js +15 -6
  4. package/dist/modules/AccountList/index.d.ts +7 -1
  5. package/dist/modules/AccountList/index.js +81 -14
  6. package/dist/modules/AccountList/types.d.ts +28 -0
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/Cart/index.js +1 -1
  9. package/dist/modules/Customer/constants.d.ts +7 -0
  10. package/dist/modules/Customer/constants.js +12 -0
  11. package/dist/modules/Customer/index.d.ts +122 -0
  12. package/dist/modules/Customer/index.js +697 -0
  13. package/dist/modules/Customer/types.d.ts +146 -0
  14. package/dist/modules/Customer/types.js +41 -0
  15. package/dist/modules/Discount/index.d.ts +1 -0
  16. package/dist/modules/Order/index.d.ts +25 -1
  17. package/dist/modules/Order/index.js +224 -2
  18. package/dist/modules/Order/types.d.ts +45 -0
  19. package/dist/modules/Order/types.js +8 -0
  20. package/dist/modules/Payment/cash.d.ts +19 -0
  21. package/dist/modules/Payment/cash.js +97 -0
  22. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  23. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  24. package/dist/modules/Payment/eftpos.d.ts +11 -0
  25. package/dist/modules/Payment/eftpos.js +80 -0
  26. package/dist/modules/Payment/index.d.ts +184 -9
  27. package/dist/modules/Payment/index.js +2012 -108
  28. package/dist/modules/Payment/mx51.d.ts +0 -0
  29. package/dist/modules/Payment/mx51.js +0 -0
  30. package/dist/modules/Payment/types.d.ts +750 -30
  31. package/dist/modules/Payment/types.js +236 -12
  32. package/dist/modules/Payment/utils.d.ts +17 -0
  33. package/dist/modules/Payment/utils.js +62 -0
  34. package/dist/modules/Payment/walletpass.d.ts +99 -0
  35. package/dist/modules/Payment/walletpass.js +701 -0
  36. package/dist/modules/Product/index.d.ts +1 -1
  37. package/dist/modules/ProductList/index.d.ts +12 -1
  38. package/dist/modules/ProductList/index.js +27 -3
  39. package/dist/modules/Rules/index.d.ts +2 -0
  40. package/dist/modules/Rules/index.js +39 -17
  41. package/dist/modules/Rules/types.d.ts +1 -0
  42. package/dist/modules/Schedule/index.d.ts +9 -0
  43. package/dist/modules/Schedule/index.js +68 -0
  44. package/dist/modules/index.d.ts +1 -0
  45. package/dist/modules/index.js +1 -0
  46. package/dist/plugins/app-types/app/app.d.ts +83 -0
  47. package/dist/plugins/app-types/app/const.d.ts +4 -0
  48. package/dist/plugins/app-types/app/index.d.ts +14 -0
  49. package/dist/plugins/app-types/applicationManager/application.d.ts +50 -0
  50. package/dist/plugins/app-types/applicationManager/index.d.ts +13 -0
  51. package/dist/plugins/app-types/config.d.ts +3 -0
  52. package/dist/plugins/app-types/cookie/index.d.ts +13 -0
  53. package/dist/plugins/app-types/data/index.d.ts +8 -0
  54. package/dist/plugins/app-types/history/config.d.ts +24 -0
  55. package/dist/plugins/app-types/history/index.d.ts +20 -0
  56. package/dist/plugins/app-types/history/type.d.ts +2 -0
  57. package/dist/plugins/app-types/hooks/index.d.ts +12 -0
  58. package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  59. package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  60. package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  61. package/dist/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  62. package/dist/plugins/app-types/index.d.ts +6 -0
  63. package/dist/plugins/app-types/indexDB/index.d.ts +178 -0
  64. package/dist/plugins/app-types/locales/en.d.ts +3 -0
  65. package/dist/plugins/app-types/locales/index.d.ts +37 -0
  66. package/dist/plugins/app-types/locales/original.d.ts +3 -0
  67. package/dist/plugins/app-types/locales/type.d.ts +19 -0
  68. package/dist/plugins/app-types/locales/zh-CN.d.ts +3 -0
  69. package/dist/plugins/app-types/locales/zh-HK.d.ts +3 -0
  70. package/dist/plugins/app-types/logger/feishu.d.ts +11 -0
  71. package/dist/plugins/app-types/logger/index.d.ts +122 -0
  72. package/dist/plugins/app-types/menuManager/hooks.d.ts +17 -0
  73. package/dist/plugins/app-types/menuManager/index.d.ts +28 -0
  74. package/dist/plugins/app-types/models/global.d.ts +32 -0
  75. package/dist/plugins/app-types/models/index.d.ts +45 -0
  76. package/dist/plugins/app-types/models/type.d.ts +2 -0
  77. package/dist/plugins/app-types/package.json +15 -0
  78. package/dist/plugins/app-types/plugin/index.d.ts +0 -0
  79. package/dist/plugins/app-types/pubsub/example.d.ts +5 -0
  80. package/dist/plugins/app-types/pubsub/index.d.ts +63 -0
  81. package/dist/plugins/app-types/request/cache.d.ts +46 -0
  82. package/dist/plugins/app-types/request/cancelToken.d.ts +38 -0
  83. package/dist/plugins/app-types/request/config.d.ts +3 -0
  84. package/dist/plugins/app-types/request/constants.d.ts +2 -0
  85. package/dist/plugins/app-types/request/index.d.ts +24 -0
  86. package/dist/plugins/app-types/request/pisell2Request.d.ts +6 -0
  87. package/dist/plugins/app-types/request/type.d.ts +41 -0
  88. package/dist/plugins/app-types/request/utils.d.ts +46 -0
  89. package/dist/plugins/app-types/routes/config.d.ts +7 -0
  90. package/dist/plugins/app-types/routes/index.d.ts +28 -0
  91. package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  92. package/dist/plugins/app-types/socket/components/index.d.ts +2 -0
  93. package/dist/plugins/app-types/socket/constants.d.ts +33 -0
  94. package/dist/plugins/app-types/socket/events.d.ts +31 -0
  95. package/dist/plugins/app-types/socket/heartbeat.d.ts +66 -0
  96. package/dist/plugins/app-types/socket/index.d.ts +61 -0
  97. package/dist/plugins/app-types/socket/monitor.d.ts +169 -0
  98. package/dist/plugins/app-types/socket/reconnect.d.ts +61 -0
  99. package/dist/plugins/app-types/socket/socket.d.ts +129 -0
  100. package/dist/plugins/app-types/socket/types.d.ts +85 -0
  101. package/dist/plugins/app-types/storage/index.d.ts +17 -0
  102. package/dist/plugins/app-types/tasks/index.d.ts +77 -0
  103. package/dist/plugins/app-types/tasks/type.d.ts +62 -0
  104. package/dist/plugins/app-types/tasks/useTasks.d.ts +5 -0
  105. package/dist/plugins/app-types/type.d.ts +2 -0
  106. package/dist/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  107. package/dist/plugins/app-types/variables/config.d.ts +3 -0
  108. package/dist/plugins/app-types/variables/index.d.ts +6 -0
  109. package/dist/plugins/app-types/variables/type.d.ts +2 -0
  110. package/dist/plugins/app-types/website/index.d.ts +6 -0
  111. package/dist/plugins/app.d.ts +8 -0
  112. package/dist/plugins/app.js +1 -0
  113. package/dist/plugins/window.d.ts +1 -0
  114. package/dist/solution/BookingByStep/index.d.ts +1 -1
  115. package/dist/solution/BookingByStep/index.js +1 -1
  116. package/dist/solution/BookingTicket/index.d.ts +180 -0
  117. package/dist/solution/BookingTicket/index.js +689 -0
  118. package/dist/solution/BookingTicket/types.d.ts +68 -0
  119. package/dist/solution/BookingTicket/types.js +43 -0
  120. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  121. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
  122. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +22 -0
  123. package/dist/solution/BookingTicket/utils/scan/handleScan.js +189 -0
  124. package/dist/solution/BookingTicket/utils/scan/index.d.ts +81 -0
  125. package/dist/solution/BookingTicket/utils/scan/index.js +285 -0
  126. package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  127. package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
  128. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  129. package/dist/solution/Checkout/index.d.ts +509 -0
  130. package/dist/solution/Checkout/index.js +4874 -0
  131. package/dist/solution/Checkout/types.d.ts +923 -0
  132. package/dist/solution/Checkout/types.js +148 -0
  133. package/dist/solution/Checkout/utils/index.d.ts +117 -0
  134. package/dist/solution/Checkout/utils/index.js +549 -0
  135. package/dist/solution/ShopDiscount/index.d.ts +4 -9
  136. package/dist/solution/ShopDiscount/index.js +106 -54
  137. package/dist/solution/ShopDiscount/types.d.ts +10 -1
  138. package/dist/solution/index.d.ts +2 -0
  139. package/dist/solution/index.js +3 -1
  140. package/dist/types/index.d.ts +3 -1
  141. package/dist/utils/task.d.ts +40 -0
  142. package/dist/utils/task.js +171 -0
  143. package/dist/utils/watch.d.ts +102 -0
  144. package/dist/utils/watch.js +294 -0
  145. package/lib/core/index.js +1 -1
  146. package/lib/effects/index.d.ts +4 -3
  147. package/lib/effects/index.js +4 -1
  148. package/lib/modules/AccountList/index.d.ts +7 -1
  149. package/lib/modules/AccountList/index.js +27 -0
  150. package/lib/modules/AccountList/types.d.ts +28 -0
  151. package/lib/modules/Cart/index.js +1 -1
  152. package/lib/modules/Customer/constants.d.ts +7 -0
  153. package/lib/modules/Customer/constants.js +39 -0
  154. package/lib/modules/Customer/index.d.ts +122 -0
  155. package/lib/modules/Customer/index.js +440 -0
  156. package/lib/modules/Customer/types.d.ts +146 -0
  157. package/lib/modules/Customer/types.js +37 -0
  158. package/lib/modules/Discount/index.d.ts +1 -0
  159. package/lib/modules/Order/index.d.ts +25 -1
  160. package/lib/modules/Order/index.js +182 -0
  161. package/lib/modules/Order/types.d.ts +45 -0
  162. package/lib/modules/Payment/cash.d.ts +19 -0
  163. package/lib/modules/Payment/cash.js +64 -0
  164. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  165. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  166. package/lib/modules/Payment/eftpos.d.ts +11 -0
  167. package/lib/modules/Payment/eftpos.js +51 -0
  168. package/lib/modules/Payment/index.d.ts +184 -9
  169. package/lib/modules/Payment/index.js +1044 -50
  170. package/lib/modules/Payment/mx51.d.ts +0 -0
  171. package/lib/modules/Payment/mx51.js +0 -0
  172. package/lib/modules/Payment/types.d.ts +750 -30
  173. package/lib/modules/Payment/types.js +79 -6
  174. package/lib/modules/Payment/utils.d.ts +17 -0
  175. package/lib/modules/Payment/utils.js +67 -0
  176. package/lib/modules/Payment/walletpass.d.ts +99 -0
  177. package/lib/modules/Payment/walletpass.js +468 -0
  178. package/lib/modules/Product/index.d.ts +1 -1
  179. package/lib/modules/ProductList/index.d.ts +12 -1
  180. package/lib/modules/ProductList/index.js +29 -2
  181. package/lib/modules/Rules/index.d.ts +2 -0
  182. package/lib/modules/Rules/index.js +32 -15
  183. package/lib/modules/Rules/types.d.ts +1 -0
  184. package/lib/modules/Schedule/index.d.ts +9 -0
  185. package/lib/modules/Schedule/index.js +51 -0
  186. package/lib/modules/index.d.ts +1 -0
  187. package/lib/modules/index.js +2 -0
  188. package/lib/plugins/app-types/app/app.d.ts +83 -0
  189. package/lib/plugins/app-types/app/const.d.ts +4 -0
  190. package/lib/plugins/app-types/app/index.d.ts +14 -0
  191. package/lib/plugins/app-types/applicationManager/application.d.ts +50 -0
  192. package/lib/plugins/app-types/applicationManager/index.d.ts +13 -0
  193. package/lib/plugins/app-types/config.d.ts +3 -0
  194. package/lib/plugins/app-types/cookie/index.d.ts +13 -0
  195. package/lib/plugins/app-types/data/index.d.ts +8 -0
  196. package/lib/plugins/app-types/history/config.d.ts +24 -0
  197. package/lib/plugins/app-types/history/index.d.ts +20 -0
  198. package/lib/plugins/app-types/history/type.d.ts +2 -0
  199. package/lib/plugins/app-types/hooks/index.d.ts +12 -0
  200. package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  201. package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  202. package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  203. package/lib/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  204. package/lib/plugins/app-types/index.d.ts +6 -0
  205. package/lib/plugins/app-types/indexDB/index.d.ts +178 -0
  206. package/lib/plugins/app-types/locales/en.d.ts +3 -0
  207. package/lib/plugins/app-types/locales/index.d.ts +37 -0
  208. package/lib/plugins/app-types/locales/original.d.ts +3 -0
  209. package/lib/plugins/app-types/locales/type.d.ts +19 -0
  210. package/lib/plugins/app-types/locales/zh-CN.d.ts +3 -0
  211. package/lib/plugins/app-types/locales/zh-HK.d.ts +3 -0
  212. package/lib/plugins/app-types/logger/feishu.d.ts +11 -0
  213. package/lib/plugins/app-types/logger/index.d.ts +122 -0
  214. package/lib/plugins/app-types/menuManager/hooks.d.ts +17 -0
  215. package/lib/plugins/app-types/menuManager/index.d.ts +28 -0
  216. package/lib/plugins/app-types/models/global.d.ts +32 -0
  217. package/lib/plugins/app-types/models/index.d.ts +45 -0
  218. package/lib/plugins/app-types/models/type.d.ts +2 -0
  219. package/lib/plugins/app-types/package.json +15 -0
  220. package/lib/plugins/app-types/plugin/index.d.ts +0 -0
  221. package/lib/plugins/app-types/pubsub/example.d.ts +5 -0
  222. package/lib/plugins/app-types/pubsub/index.d.ts +63 -0
  223. package/lib/plugins/app-types/request/cache.d.ts +46 -0
  224. package/lib/plugins/app-types/request/cancelToken.d.ts +38 -0
  225. package/lib/plugins/app-types/request/config.d.ts +3 -0
  226. package/lib/plugins/app-types/request/constants.d.ts +2 -0
  227. package/lib/plugins/app-types/request/index.d.ts +24 -0
  228. package/lib/plugins/app-types/request/pisell2Request.d.ts +6 -0
  229. package/lib/plugins/app-types/request/type.d.ts +41 -0
  230. package/lib/plugins/app-types/request/utils.d.ts +46 -0
  231. package/lib/plugins/app-types/routes/config.d.ts +7 -0
  232. package/lib/plugins/app-types/routes/index.d.ts +28 -0
  233. package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  234. package/lib/plugins/app-types/socket/components/index.d.ts +2 -0
  235. package/lib/plugins/app-types/socket/constants.d.ts +33 -0
  236. package/lib/plugins/app-types/socket/events.d.ts +31 -0
  237. package/lib/plugins/app-types/socket/heartbeat.d.ts +66 -0
  238. package/lib/plugins/app-types/socket/index.d.ts +61 -0
  239. package/lib/plugins/app-types/socket/monitor.d.ts +169 -0
  240. package/lib/plugins/app-types/socket/reconnect.d.ts +61 -0
  241. package/lib/plugins/app-types/socket/socket.d.ts +129 -0
  242. package/lib/plugins/app-types/socket/types.d.ts +85 -0
  243. package/lib/plugins/app-types/storage/index.d.ts +17 -0
  244. package/lib/plugins/app-types/tasks/index.d.ts +77 -0
  245. package/lib/plugins/app-types/tasks/type.d.ts +62 -0
  246. package/lib/plugins/app-types/tasks/useTasks.d.ts +5 -0
  247. package/lib/plugins/app-types/type.d.ts +2 -0
  248. package/lib/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  249. package/lib/plugins/app-types/variables/config.d.ts +3 -0
  250. package/lib/plugins/app-types/variables/index.d.ts +6 -0
  251. package/lib/plugins/app-types/variables/type.d.ts +2 -0
  252. package/lib/plugins/app-types/website/index.d.ts +6 -0
  253. package/lib/plugins/app.d.ts +8 -0
  254. package/lib/plugins/app.js +17 -0
  255. package/lib/plugins/window.d.ts +1 -0
  256. package/lib/solution/BookingByStep/index.d.ts +1 -1
  257. package/lib/solution/BookingByStep/index.js +1 -2
  258. package/lib/solution/BookingTicket/index.d.ts +180 -0
  259. package/lib/solution/BookingTicket/index.js +420 -0
  260. package/lib/solution/BookingTicket/types.d.ts +68 -0
  261. package/lib/solution/BookingTicket/types.js +72 -0
  262. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  263. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
  264. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +22 -0
  265. package/lib/solution/BookingTicket/utils/scan/handleScan.js +132 -0
  266. package/lib/solution/BookingTicket/utils/scan/index.d.ts +81 -0
  267. package/lib/solution/BookingTicket/utils/scan/index.js +210 -0
  268. package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  269. package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
  270. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  271. package/lib/solution/Checkout/index.d.ts +509 -0
  272. package/lib/solution/Checkout/index.js +3002 -0
  273. package/lib/solution/Checkout/types.d.ts +923 -0
  274. package/lib/solution/Checkout/types.js +87 -0
  275. package/lib/solution/Checkout/utils/index.d.ts +117 -0
  276. package/lib/solution/Checkout/utils/index.js +403 -0
  277. package/lib/solution/ShopDiscount/index.d.ts +4 -9
  278. package/lib/solution/ShopDiscount/index.js +41 -13
  279. package/lib/solution/ShopDiscount/types.d.ts +10 -1
  280. package/lib/solution/index.d.ts +2 -0
  281. package/lib/solution/index.js +5 -1
  282. package/lib/types/index.d.ts +3 -1
  283. package/lib/utils/task.d.ts +40 -0
  284. package/lib/utils/task.js +109 -0
  285. package/lib/utils/watch.d.ts +102 -0
  286. package/lib/utils/watch.js +217 -0
  287. package/package.json +4 -2
@@ -29,6 +29,7 @@ import { ShopDiscountHooks } from "./types";
29
29
  import { DiscountModule } from "../../modules/Discount";
30
30
  import { RulesModule } from "../../modules/Rules";
31
31
  import Decimal from 'decimal.js';
32
+ import { isBoolean } from 'lodash-es';
32
33
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
33
34
  _inherits(ShopDiscountImpl, _BaseModule);
34
35
  var _super = _createSuper(ShopDiscountImpl);
@@ -49,7 +50,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
49
50
  customer: null,
50
51
  productList: [],
51
52
  discount: null,
52
- rules: null
53
+ rules: null,
54
+ originalDiscountList: []
53
55
  };
54
56
  return _this;
55
57
  }
@@ -265,19 +267,38 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
265
267
  // 设置优惠券使用状态
266
268
  }, {
267
269
  key: "setDiscountSelected",
268
- value: function setDiscountSelected(_ref2) {
269
- var discountId = _ref2.discountId,
270
- isSelected = _ref2.isSelected;
270
+ value: function setDiscountSelected(params) {
271
271
  // 获取当前优惠券列表
272
272
  var discountList = this.getDiscountList();
273
273
 
274
+ // 构建选择操作列表
275
+ var selectionOperations = [];
276
+
277
+ // 主要操作
278
+ selectionOperations.push({
279
+ discountId: params.discountId,
280
+ isSelected: params.isSelected
281
+ });
282
+
283
+ // 如果有批量操作列表,添加到操作列表中
284
+ if (params.selectedList && params.selectedList.length > 0) {
285
+ selectionOperations.push.apply(selectionOperations, _toConsumableArray(params.selectedList));
286
+ }
287
+
288
+ // 创建选择状态映射(去重处理,后面的操作会覆盖前面的)
289
+ var selectionMap = new Map();
290
+ selectionOperations.forEach(function (operation) {
291
+ selectionMap.set(operation.discountId, operation.isSelected);
292
+ });
293
+
274
294
  // 找到需要修改状态的优惠券
275
295
  var newDiscountList = discountList.map(function (discount) {
276
- if (discount.id === discountId) {
296
+ if (selectionMap.has(discount.id)) {
297
+ var targetIsSelected = selectionMap.get(discount.id);
277
298
  return _objectSpread(_objectSpread({}, discount), {}, {
278
- isSelected: isSelected,
299
+ isSelected: targetIsSelected,
279
300
  // 手动设置不使用
280
- isManualSelect: !isSelected
301
+ isManualSelect: !targetIsSelected
281
302
  });
282
303
  }
283
304
  return _objectSpread(_objectSpread({}, discount), {}, {
@@ -287,12 +308,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
287
308
 
288
309
  // 更新优惠券列表
289
310
  this.setDiscountList(newDiscountList);
290
-
291
- // 如果取消选择优惠券,需要重新计算其他可用优惠券
292
- return this.calcDiscount(this.store.productList || [], {
293
- discountId: discountId,
294
- isSelected: isSelected
295
- });
311
+ return this.calcDiscount(this.store.productList || [], params);
296
312
  }
297
313
  }, {
298
314
  key: "setProductList",
@@ -305,7 +321,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
305
321
  key: "scanCode",
306
322
  value: function () {
307
323
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
308
- var _this$store$discount3, resultDiscountList, rulesModule, withScanList, _ref3, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
324
+ var _this$store$discount3, resultDiscountList, rulesModule, withScanList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
309
325
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
310
326
  while (1) switch (_context5.prev = _context5.next) {
311
327
  case 0:
@@ -349,7 +365,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
349
365
  isScan: true
350
366
  });
351
367
  });
352
- _ref3 = rulesModule.isDiscountListAvailable({
368
+ _ref2 = rulesModule.isDiscountListAvailable({
353
369
  productList: this.store.productList || [],
354
370
  oldDiscountList: this.getDiscountList(),
355
371
  newDiscountList: withScanList
@@ -357,28 +373,29 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
357
373
  isAvailable: false,
358
374
  productList: this.store.productList || [],
359
375
  discountList: this.getDiscountList()
360
- }, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable;
376
+ }, newProductList = _ref2.productList, newDiscountList = _ref2.discountList, isAvailable = _ref2.isAvailable;
361
377
  if (!isAvailable) {
362
- _context5.next = 20;
378
+ _context5.next = 21;
363
379
  break;
364
380
  }
365
381
  this.setDiscountList(newDiscountList || []);
382
+ this.store.originalDiscountList = newDiscountList || [];
366
383
  this.setProductList(newProductList || []);
367
384
  if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
368
- _context5.next = 20;
385
+ _context5.next = 21;
369
386
  break;
370
387
  }
371
- _context5.next = 20;
388
+ _context5.next = 21;
372
389
  return this.getCustomerWallet(resultDiscountList[0].customer_id);
373
- case 20:
390
+ case 21:
374
391
  return _context5.abrupt("return", {
375
392
  type: "clientCalc",
376
393
  isAvailable: isAvailable || false,
377
394
  productList: newProductList || this.store.productList || [],
378
395
  discountList: newDiscountList || this.getDiscountList()
379
396
  });
380
- case 23:
381
- _context5.prev = 23;
397
+ case 24:
398
+ _context5.prev = 24;
382
399
  _context5.t1 = _context5["catch"](0);
383
400
  console.error('[ShopDiscount] 扫码出错:', _context5.t1);
384
401
  return _context5.abrupt("return", {
@@ -387,11 +404,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
387
404
  productList: this.store.productList || [],
388
405
  discountList: this.getDiscountList()
389
406
  });
390
- case 27:
407
+ case 28:
391
408
  case "end":
392
409
  return _context5.stop();
393
410
  }
394
- }, _callee5, this, [[0, 23]]);
411
+ }, _callee5, this, [[0, 24]]);
395
412
  }));
396
413
  function scanCode(_x4, _x5) {
397
414
  return _scanCode.apply(this, arguments);
@@ -495,8 +512,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
495
512
  return n.id === id;
496
513
  });
497
514
  var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
498
- // 如果 product.total 0有可能是她已经用过商品券或者折扣卡导致的 0,所以此时还需要判断 origin_total 是否为 0
499
- return Number(product === null || product === void 0 ? void 0 : product.total) === 0 && (Number(product === null || product === void 0 ? void 0 : product.origin_total) === 0 || !(product !== null && product !== void 0 && product.origin_total));
515
+ // 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
516
+ // 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
517
+ return Number(product === null || product === void 0 ? void 0 : product.total) <= 0 && (Number(product === null || product === void 0 ? void 0 : product.origin_total) <= 0 || !(product !== null && product !== void 0 && product.origin_total)) || isBoolean(product === null || product === void 0 ? void 0 : product.vouchersApplicable) && !(product !== null && product !== void 0 && product.vouchersApplicable);
500
518
  };
501
519
  var allUsedProductIds = newDiscountList.map(function (n) {
502
520
  var _n$appliedProductDeta;
@@ -542,7 +560,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
542
560
  key: "getCustomerWallet",
543
561
  value: function () {
544
562
  var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
545
- var result, customer;
563
+ var _result, customer;
546
564
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
547
565
  while (1) switch (_context7.prev = _context7.next) {
548
566
  case 0:
@@ -552,12 +570,12 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
552
570
  with_trashed: 1
553
571
  });
554
572
  case 3:
555
- result = _context7.sent;
556
- if (!(result !== null && result !== void 0 && result.data)) {
573
+ _result = _context7.sent;
574
+ if (!(_result !== null && _result !== void 0 && _result.data)) {
557
575
  _context7.next = 9;
558
576
  break;
559
577
  }
560
- customer = Object.assign({}, (_objectDestructuringEmpty(result.data), result.data));
578
+ customer = Object.assign({}, (_objectDestructuringEmpty(_result.data), _result.data));
561
579
  this.setCustomer(customer);
562
580
  _context7.next = 9;
563
581
  return this.core.effects.emit(ShopDiscountHooks.onScanCustomerChange, customer);
@@ -578,20 +596,53 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
578
596
  return _getCustomerWallet.apply(this, arguments);
579
597
  }
580
598
  return getCustomerWallet;
581
- }() // 加载准备配置
599
+ }()
582
600
  }, {
583
- key: "loadPrepareConfig",
601
+ key: "bestDiscount",
584
602
  value: function () {
585
- var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
586
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, result;
603
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(cb) {
604
+ var _this$store$productLi;
605
+ var newDiscountList, _result2;
587
606
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
588
607
  while (1) switch (_context8.prev = _context8.next) {
589
608
  case 0:
590
- _context8.prev = 0;
609
+ newDiscountList = this.store.originalDiscountList;
610
+ this.setDiscountList(newDiscountList);
611
+ if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
612
+ _context8.next = 7;
613
+ break;
614
+ }
615
+ _result2 = this.calcDiscount(this.store.productList);
616
+ cb === null || cb === void 0 || cb(_result2);
617
+ _context8.next = 7;
618
+ return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, _result2);
619
+ case 7:
620
+ _context8.next = 9;
621
+ return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
622
+ case 9:
623
+ case "end":
624
+ return _context8.stop();
625
+ }
626
+ }, _callee8, this);
627
+ }));
628
+ function bestDiscount(_x8) {
629
+ return _bestDiscount.apply(this, arguments);
630
+ }
631
+ return bestDiscount;
632
+ }() // 加载准备配置
633
+ }, {
634
+ key: "loadPrepareConfig",
635
+ value: function () {
636
+ var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
637
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, _result3;
638
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
639
+ while (1) switch (_context9.prev = _context9.next) {
640
+ case 0:
641
+ _context9.prev = 0;
591
642
  customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
592
643
  // return
593
644
  // }
594
- _context8.next = 4;
645
+ _context9.next = 4;
595
646
  return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
596
647
  customer_id: customerId,
597
648
  action: 'create',
@@ -599,7 +650,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
599
650
  with_discount_card: 1
600
651
  });
601
652
  case 4:
602
- goodPassList = _context8.sent;
653
+ goodPassList = _context9.sent;
603
654
  scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
604
655
  return item.isScan;
605
656
  }); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
@@ -610,31 +661,32 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
610
661
  return !scanDiscountIds.includes(n.id);
611
662
  });
612
663
  newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
664
+ this.store.originalDiscountList = newDiscountList;
613
665
  this.setDiscountList(newDiscountList || []);
614
- if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
615
- _context8.next = 14;
666
+ if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
667
+ _context9.next = 15;
616
668
  break;
617
669
  }
618
- result = this.calcDiscount(this.store.productList);
619
- _context8.next = 14;
620
- return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
621
- case 14:
622
- _context8.next = 16;
670
+ _result3 = this.calcDiscount(this.store.productList);
671
+ _context9.next = 15;
672
+ return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, _result3);
673
+ case 15:
674
+ _context9.next = 17;
623
675
  return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
624
- case 16:
625
- _context8.next = 21;
676
+ case 17:
677
+ _context9.next = 22;
626
678
  break;
627
- case 18:
628
- _context8.prev = 18;
629
- _context8.t0 = _context8["catch"](0);
630
- console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
631
- case 21:
679
+ case 19:
680
+ _context9.prev = 19;
681
+ _context9.t0 = _context9["catch"](0);
682
+ console.error('[ShopDiscount] 加载准备配置出错:', _context9.t0);
683
+ case 22:
632
684
  case "end":
633
- return _context8.stop();
685
+ return _context9.stop();
634
686
  }
635
- }, _callee8, this, [[0, 18]]);
687
+ }, _callee9, this, [[0, 19]]);
636
688
  }));
637
- function loadPrepareConfig(_x8) {
689
+ function loadPrepareConfig(_x9) {
638
690
  return _loadPrepareConfig.apply(this, arguments);
639
691
  }
640
692
  return loadPrepareConfig;
@@ -1,4 +1,4 @@
1
- import { DiscountModule } from '../../modules/Discount';
1
+ import { DiscountModule, Discount } from '../../modules/Discount';
2
2
  import { RulesModule } from '../../modules/Rules';
3
3
  export declare enum ShopDiscountHooks {
4
4
  onInited = "shopDiscount:onInited",
@@ -22,4 +22,13 @@ export interface ShopDiscountState {
22
22
  discount: DiscountModule | null;
23
23
  rules: RulesModule | null;
24
24
  productList: Record<string, any>[];
25
+ originalDiscountList: Discount[];
26
+ }
27
+ export interface SetDiscountSelectedParams {
28
+ discountId: number;
29
+ isSelected: boolean;
30
+ selectedList?: {
31
+ discountId: number;
32
+ isSelected: boolean;
33
+ }[];
25
34
  }
@@ -1,3 +1,5 @@
1
1
  export * from './BuyTickets';
2
2
  export * from './BookingByStep';
3
+ export * from './BookingTicket';
3
4
  export * from './ShopDiscount';
5
+ export * from './Checkout';
@@ -1,3 +1,5 @@
1
1
  export * from "./BuyTickets";
2
2
  export * from "./BookingByStep";
3
- export * from "./ShopDiscount";
3
+ export * from "./BookingTicket";
4
+ export * from "./ShopDiscount";
5
+ export * from "./Checkout";
@@ -38,7 +38,9 @@ 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
+ off: (event: string, callback: (payload: any) => void) => void;
42
44
  emit: (event: string, payload: any, value?: any) => Promise<{
43
45
  status: boolean;
44
46
  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,171 @@
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ 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; }
4
+ 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; }
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ 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); }
13
+ var Tasks = /*#__PURE__*/function () {
14
+ function Tasks(actions) {
15
+ _classCallCheck(this, Tasks);
16
+ _defineProperty(this, "actions", new Map());
17
+ _defineProperty(this, "taskQueue", []);
18
+ _defineProperty(this, "isRunning", false);
19
+ if (actions) {
20
+ this.actions = actions;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * 清空所有任务
26
+ */
27
+ _createClass(Tasks, [{
28
+ key: "clear",
29
+ value: function clear() {
30
+ this.actions.clear();
31
+ this.taskQueue = [];
32
+ this.isRunning = false;
33
+ }
34
+
35
+ /**
36
+ * 清空任务执行队列
37
+ */
38
+ }, {
39
+ key: "clearTaskQueue",
40
+ value: function clearTaskQueue() {
41
+ this.taskQueue = [];
42
+ this.isRunning = false;
43
+ }
44
+
45
+ /**
46
+ * 添加action
47
+ * @param name action名称
48
+ * @param action action函数
49
+ */
50
+ }, {
51
+ key: "addAction",
52
+ value: function addAction(name, action) {
53
+ this.actions.set(name, action);
54
+ }
55
+
56
+ /**
57
+ * 添加任务
58
+ * @param task 任务
59
+ */
60
+ }, {
61
+ key: "addTask",
62
+ value: function addTask(task) {
63
+ this.taskQueue.push(task);
64
+ // 添加后自动执行
65
+ this.run();
66
+ }
67
+
68
+ /**
69
+ * 执行任务
70
+ */
71
+ }, {
72
+ key: "run",
73
+ value: (function () {
74
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
75
+ var _this$taskQueue, task, action, _task, _task2;
76
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
77
+ while (1) switch (_context.prev = _context.next) {
78
+ case 0:
79
+ if (!this.isRunning) {
80
+ _context.next = 2;
81
+ break;
82
+ }
83
+ return _context.abrupt("return");
84
+ case 2:
85
+ if (!(this.taskQueue.length === 0)) {
86
+ _context.next = 5;
87
+ break;
88
+ }
89
+ this.isRunning = false;
90
+ return _context.abrupt("return");
91
+ case 5:
92
+ // 设置正在运行 加锁
93
+ this.isRunning = true;
94
+ // 遍历任务队列
95
+ case 6:
96
+ if (!(this.taskQueue.length > 0)) {
97
+ _context.next = 32;
98
+ break;
99
+ }
100
+ // 获取任务,但是不删除
101
+ task = (_this$taskQueue = this.taskQueue) === null || _this$taskQueue === void 0 ? void 0 : _this$taskQueue[0]; // 如果没有任务则直接结束
102
+ if (task) {
103
+ _context.next = 11;
104
+ break;
105
+ }
106
+ this.isRunning = false;
107
+ return _context.abrupt("return");
108
+ case 11:
109
+ // 获取任务对应的action
110
+ action = this.actions.get(task.type); // 如果找到对应的action,则执行
111
+ if (!action) {
112
+ _context.next = 28;
113
+ break;
114
+ }
115
+ _context.prev = 13;
116
+ _context.next = 16;
117
+ return action(_objectSpread(_objectSpread({}, (task === null || task === void 0 ? void 0 : task.actionParams) || {}), {}, {
118
+ uuid: task === null || task === void 0 ? void 0 : task.uuid
119
+ }));
120
+ case 16:
121
+ console.log('task_success>>>>>>>', task);
122
+ _context.next = 22;
123
+ break;
124
+ case 19:
125
+ _context.prev = 19;
126
+ _context.t0 = _context["catch"](13);
127
+ console.error('task_error>>>>>>>', _context.t0);
128
+ case 22:
129
+ _context.prev = 22;
130
+ // 将任务删除
131
+ _task = this.taskQueue.shift();
132
+ console.log('task_shift>>>>>>>', _task);
133
+ return _context.finish(22);
134
+ case 26:
135
+ _context.next = 30;
136
+ break;
137
+ case 28:
138
+ // 如果找不到对应的action,则删除任务
139
+ _task2 = this.taskQueue.shift();
140
+ console.log('task_action_not_found>>>>>>>', _task2);
141
+ case 30:
142
+ _context.next = 6;
143
+ break;
144
+ case 32:
145
+ this.isRunning = false;
146
+ case 33:
147
+ case "end":
148
+ return _context.stop();
149
+ }
150
+ }, _callee, this, [[13, 19, 22, 26]]);
151
+ }));
152
+ function run() {
153
+ return _run.apply(this, arguments);
154
+ }
155
+ return run;
156
+ }()
157
+ /**
158
+ * 判定当前的任务是否依然存在
159
+ */
160
+ )
161
+ }, {
162
+ key: "isTaskExist",
163
+ value: function isTaskExist(uuid) {
164
+ return this.taskQueue.some(function (task) {
165
+ return (task === null || task === void 0 ? void 0 : task.uuid) === uuid;
166
+ });
167
+ }
168
+ }]);
169
+ return Tasks;
170
+ }();
171
+ export default Tasks;