@pisell/pisellos 2.1.36 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/core/index.d.ts +8 -1
  2. package/dist/core/index.js +116 -42
  3. package/dist/effects/index.d.ts +1 -0
  4. package/dist/effects/index.js +29 -6
  5. package/dist/modules/Account/index.js +2 -3
  6. package/dist/modules/BaseModule.d.ts +3 -0
  7. package/dist/modules/BaseModule.js +15 -0
  8. package/dist/modules/Customer/index.js +9 -10
  9. package/dist/modules/Customer/types.d.ts +2 -2
  10. package/dist/modules/Customer/types.js +2 -2
  11. package/dist/modules/Discount/index.js +1 -1
  12. package/dist/modules/Guests/index.js +9 -9
  13. package/dist/modules/Order/index.js +1 -1
  14. package/dist/modules/Payment/index.js +63 -73
  15. package/dist/modules/Payment/walletpass.js +4 -1
  16. package/dist/modules/Product/types.d.ts +19 -0
  17. package/dist/modules/ProductList/index.js +5 -14
  18. package/dist/modules/Resource/index.js +1 -1
  19. package/dist/modules/Rules/index.js +2 -3
  20. package/dist/modules/Schedule/types.d.ts +2 -0
  21. package/dist/plugins/request.d.ts +1 -0
  22. package/dist/server/index.d.ts +152 -0
  23. package/dist/server/index.js +946 -0
  24. package/dist/server/modules/index.d.ts +16 -0
  25. package/dist/server/modules/index.js +21 -0
  26. package/dist/server/modules/menu/index.d.ts +63 -0
  27. package/dist/server/modules/menu/index.js +476 -0
  28. package/dist/server/modules/menu/types.d.ts +68 -0
  29. package/dist/server/modules/menu/types.js +16 -0
  30. package/dist/server/modules/products/index.d.ts +141 -0
  31. package/dist/server/modules/products/index.js +768 -0
  32. package/dist/server/modules/products/types.d.ts +94 -0
  33. package/dist/server/modules/products/types.js +43 -0
  34. package/dist/server/modules/quotation/index.d.ts +47 -0
  35. package/dist/server/modules/quotation/index.js +367 -0
  36. package/dist/server/modules/quotation/types.d.ts +50 -0
  37. package/dist/server/modules/quotation/types.js +20 -0
  38. package/dist/server/modules/schedule/index.d.ts +62 -0
  39. package/dist/server/modules/schedule/index.js +431 -0
  40. package/dist/server/modules/schedule/types.d.ts +1 -0
  41. package/dist/server/modules/schedule/types.js +2 -0
  42. package/dist/server/modules/schedule/utils.d.ts +32 -0
  43. package/dist/server/modules/schedule/utils.js +747 -0
  44. package/dist/server/types.d.ts +64 -0
  45. package/dist/server/types.js +1 -0
  46. package/dist/server/utils/index.d.ts +5 -0
  47. package/dist/server/utils/index.js +6 -0
  48. package/dist/server/utils/product.d.ts +18 -0
  49. package/dist/server/utils/product.js +339 -0
  50. package/dist/server/utils/schedule.d.ts +14 -0
  51. package/dist/server/utils/schedule.js +108 -0
  52. package/dist/server/utils/time.d.ts +18 -0
  53. package/dist/server/utils/time.js +53 -0
  54. package/dist/solution/BookingByStep/index.d.ts +0 -16
  55. package/dist/solution/BookingByStep/index.js +57 -508
  56. package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
  57. package/dist/solution/BookingByStep/utils/capacity.js +8 -24
  58. package/dist/solution/BookingTicket/index.d.ts +12 -0
  59. package/dist/solution/BookingTicket/index.js +122 -79
  60. package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  61. package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
  62. package/dist/solution/BuyTickets/index.js +7 -8
  63. package/dist/solution/Checkout/index.d.ts +1 -46
  64. package/dist/solution/Checkout/index.js +530 -850
  65. package/dist/solution/ShopDiscount/index.js +9 -10
  66. package/dist/types/index.d.ts +27 -0
  67. package/lib/core/index.d.ts +8 -1
  68. package/lib/core/index.js +48 -1
  69. package/lib/effects/index.d.ts +1 -0
  70. package/lib/effects/index.js +13 -0
  71. package/lib/modules/Account/index.js +2 -3
  72. package/lib/modules/BaseModule.d.ts +3 -0
  73. package/lib/modules/BaseModule.js +9 -0
  74. package/lib/modules/Customer/index.js +9 -10
  75. package/lib/modules/Customer/types.d.ts +2 -2
  76. package/lib/modules/Customer/types.js +2 -2
  77. package/lib/modules/Discount/index.js +1 -1
  78. package/lib/modules/Guests/index.js +9 -9
  79. package/lib/modules/Order/index.js +1 -1
  80. package/lib/modules/Payment/index.js +56 -43
  81. package/lib/modules/Payment/walletpass.js +3 -1
  82. package/lib/modules/Product/types.d.ts +19 -0
  83. package/lib/modules/ProductList/index.js +4 -13
  84. package/lib/modules/Resource/index.js +1 -1
  85. package/lib/modules/Rules/index.js +2 -3
  86. package/lib/modules/Schedule/types.d.ts +2 -0
  87. package/lib/plugins/request.d.ts +1 -0
  88. package/lib/server/index.d.ts +152 -0
  89. package/lib/server/index.js +555 -0
  90. package/lib/server/modules/index.d.ts +16 -0
  91. package/lib/server/modules/index.js +47 -0
  92. package/lib/server/modules/menu/index.d.ts +63 -0
  93. package/lib/server/modules/menu/index.js +234 -0
  94. package/lib/server/modules/menu/types.d.ts +68 -0
  95. package/lib/server/modules/menu/types.js +33 -0
  96. package/lib/server/modules/products/index.d.ts +141 -0
  97. package/lib/server/modules/products/index.js +434 -0
  98. package/lib/server/modules/products/types.d.ts +94 -0
  99. package/lib/server/modules/products/types.js +35 -0
  100. package/lib/server/modules/quotation/index.d.ts +47 -0
  101. package/lib/server/modules/quotation/index.js +177 -0
  102. package/lib/server/modules/quotation/types.d.ts +50 -0
  103. package/lib/server/modules/quotation/types.js +33 -0
  104. package/lib/server/modules/schedule/index.d.ts +62 -0
  105. package/lib/server/modules/schedule/index.js +231 -0
  106. package/lib/server/modules/schedule/types.d.ts +1 -0
  107. package/lib/server/modules/schedule/types.js +23 -0
  108. package/lib/server/modules/schedule/utils.d.ts +32 -0
  109. package/lib/server/modules/schedule/utils.js +451 -0
  110. package/lib/server/types.d.ts +64 -0
  111. package/lib/server/types.js +17 -0
  112. package/lib/server/utils/index.d.ts +5 -0
  113. package/lib/server/utils/index.js +25 -0
  114. package/lib/server/utils/product.d.ts +18 -0
  115. package/lib/server/utils/product.js +262 -0
  116. package/lib/server/utils/schedule.d.ts +14 -0
  117. package/lib/server/utils/schedule.js +88 -0
  118. package/lib/server/utils/time.d.ts +18 -0
  119. package/lib/server/utils/time.js +70 -0
  120. package/lib/solution/BookingByStep/index.d.ts +0 -16
  121. package/lib/solution/BookingByStep/index.js +44 -316
  122. package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
  123. package/lib/solution/BookingByStep/utils/capacity.js +8 -21
  124. package/lib/solution/BookingTicket/index.d.ts +12 -0
  125. package/lib/solution/BookingTicket/index.js +25 -6
  126. package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  127. package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
  128. package/lib/solution/BuyTickets/index.js +7 -8
  129. package/lib/solution/Checkout/index.d.ts +1 -46
  130. package/lib/solution/Checkout/index.js +92 -289
  131. package/lib/solution/ShopDiscount/index.js +10 -11
  132. package/lib/types/index.d.ts +27 -0
  133. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { Plugin, PluginOptions, Module, ModuleOptions, PisellCore, PisellOSOptions, BusinessContext, ModuleContextConfig } from '../types';
1
+ import { Plugin, PluginOptions, Module, ModuleOptions, PisellCore, PisellOSOptions, BusinessContext, ModuleContextConfig, InitializeServerOptions } from '../types';
2
2
  import { EffectsManager } from '../effects';
3
3
  /**
4
4
  * pisell OS 核心实现
@@ -10,8 +10,15 @@ declare class PisellOSCore implements PisellCore {
10
10
  effects: EffectsManager;
11
11
  private debug;
12
12
  context: BusinessContext;
13
+ server: any;
14
+ private serverOptions?;
13
15
  constructor(options?: PisellOSOptions);
14
16
  private initialize;
17
+ /**
18
+ * 初始化 Server(公开方法,需要外部显式调用并等待)
19
+ * Server 配置从构造函数传入的 options.server 中获取
20
+ */
21
+ initializeServer(options?: InitializeServerOptions): Promise<void>;
15
22
  private log;
16
23
  registerPlugin(plugin: Plugin, options?: PluginOptions): void;
17
24
  getPlugin<T extends Plugin>(name: string): T | null;
@@ -1,16 +1,16 @@
1
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
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
4
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
5
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- 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); } }
8
- 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); }); }; }
9
6
  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; }
10
7
  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; }
11
8
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
12
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
10
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ 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; }
12
+ 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); } }
13
+ 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); }); }; }
14
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
15
  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); } }
16
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -24,6 +24,8 @@ import { EffectsManager } from "../effects";
24
24
  * pisell OS 核心实现
25
25
  */
26
26
  var PisellOSCore = /*#__PURE__*/function () {
27
+ // 保存 Server 配置
28
+
27
29
  function PisellOSCore(options) {
28
30
  _classCallCheck(this, PisellOSCore);
29
31
  _defineProperty(this, "plugins", new Map());
@@ -32,8 +34,16 @@ var PisellOSCore = /*#__PURE__*/function () {
32
34
  _defineProperty(this, "effects", new EffectsManager());
33
35
  _defineProperty(this, "debug", false);
34
36
  _defineProperty(this, "context", {});
37
+ _defineProperty(this, "server", void 0);
38
+ // Server 实例
39
+ _defineProperty(this, "serverOptions", void 0);
35
40
  this.debug = (options === null || options === void 0 ? void 0 : options.debug) || false;
36
41
  this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
42
+
43
+ // 保存 Server 配置但不初始化
44
+ if (options !== null && options !== void 0 && options.server) {
45
+ this.serverOptions = options.server;
46
+ }
37
47
  this.initialize(options);
38
48
  }
39
49
  _createClass(PisellOSCore, [{
@@ -50,10 +60,74 @@ var PisellOSCore = /*#__PURE__*/function () {
50
60
  _this.registerModule(item.module, item.options);
51
61
  });
52
62
  }
53
- this.log('PisellOS 核心初始化完成');
63
+ this.log('[PisellOS] 核心初始化完成');
54
64
  }
55
65
 
56
- // 日志方法
66
+ /**
67
+ * 初始化 Server(公开方法,需要外部显式调用并等待)
68
+ * Server 配置从构造函数传入的 options.server 中获取
69
+ */
70
+ }, {
71
+ key: "initializeServer",
72
+ value: (function () {
73
+ var _initializeServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
74
+ var ServerModule, Server;
75
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
76
+ while (1) switch (_context.prev = _context.next) {
77
+ case 0:
78
+ if (!this.server) {
79
+ _context.next = 3;
80
+ break;
81
+ }
82
+ this.log('Server 已经初始化,跳过重复初始化', 'warn');
83
+ return _context.abrupt("return");
84
+ case 3:
85
+ if (this.serverOptions) {
86
+ _context.next = 6;
87
+ break;
88
+ }
89
+ this.log('未提供 Server 配置,无法初始化', 'warn');
90
+ return _context.abrupt("return");
91
+ case 6:
92
+ _context.prev = 6;
93
+ _context.next = 9;
94
+ return import("../server");
95
+ case 9:
96
+ ServerModule = _context.sent;
97
+ Server = ServerModule.default; // 创建 Server 实例
98
+ this.server = new Server(this);
99
+ this.log('Server 实例已创建');
100
+
101
+ // 初始化模块并预加载数据
102
+ if (!this.serverOptions.modules) {
103
+ _context.next = 16;
104
+ break;
105
+ }
106
+ _context.next = 16;
107
+ return this.server.initialize(this.serverOptions.modules, this.serverOptions.autoInitData !== false, options);
108
+ case 16:
109
+ console.log('[PisellOS] ✅ Server 初始化完成,所有数据已预加载');
110
+ this.log('[PisellOS] Server 初始化完成');
111
+ _context.next = 25;
112
+ break;
113
+ case 20:
114
+ _context.prev = 20;
115
+ _context.t0 = _context["catch"](6);
116
+ console.error('[PisellOS] ❌ Server 初始化失败:', _context.t0);
117
+ this.log("Server \u521D\u59CB\u5316\u5931\u8D25: ".concat(_context.t0), 'error');
118
+ throw _context.t0;
119
+ case 25:
120
+ case "end":
121
+ return _context.stop();
122
+ }
123
+ }, _callee, this, [[6, 20]]);
124
+ }));
125
+ function initializeServer(_x) {
126
+ return _initializeServer.apply(this, arguments);
127
+ }
128
+ return initializeServer;
129
+ }() // 日志方法
130
+ )
57
131
  }, {
58
132
  key: "log",
59
133
  value: function log(message) {
@@ -229,100 +303,100 @@ var PisellOSCore = /*#__PURE__*/function () {
229
303
  }, {
230
304
  key: "destroy",
231
305
  value: function () {
232
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
306
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
233
307
  var _iterator4, _step4, _step4$value, name, module, _iterator5, _step5, _step5$value, _name, plugin;
234
- return _regeneratorRuntime().wrap(function _callee$(_context) {
235
- while (1) switch (_context.prev = _context.next) {
308
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
309
+ while (1) switch (_context2.prev = _context2.next) {
236
310
  case 0:
237
311
  // 先销毁模块
238
312
  _iterator4 = _createForOfIteratorHelper(this.modules.entries());
239
- _context.prev = 1;
313
+ _context2.prev = 1;
240
314
  _iterator4.s();
241
315
  case 3:
242
316
  if ((_step4 = _iterator4.n()).done) {
243
- _context.next = 17;
317
+ _context2.next = 17;
244
318
  break;
245
319
  }
246
320
  _step4$value = _slicedToArray(_step4.value, 2), name = _step4$value[0], module = _step4$value[1];
247
321
  if (!module.destroy) {
248
- _context.next = 15;
322
+ _context2.next = 15;
249
323
  break;
250
324
  }
251
- _context.prev = 6;
252
- _context.next = 9;
325
+ _context2.prev = 6;
326
+ _context2.next = 9;
253
327
  return Promise.resolve(module.destroy());
254
328
  case 9:
255
329
  this.log("\u6A21\u5757 ".concat(name, " \u5DF2\u9500\u6BC1"));
256
- _context.next = 15;
330
+ _context2.next = 15;
257
331
  break;
258
332
  case 12:
259
- _context.prev = 12;
260
- _context.t0 = _context["catch"](6);
261
- this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context.t0), 'error');
333
+ _context2.prev = 12;
334
+ _context2.t0 = _context2["catch"](6);
335
+ this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context2.t0), 'error');
262
336
  case 15:
263
- _context.next = 3;
337
+ _context2.next = 3;
264
338
  break;
265
339
  case 17:
266
- _context.next = 22;
340
+ _context2.next = 22;
267
341
  break;
268
342
  case 19:
269
- _context.prev = 19;
270
- _context.t1 = _context["catch"](1);
271
- _iterator4.e(_context.t1);
343
+ _context2.prev = 19;
344
+ _context2.t1 = _context2["catch"](1);
345
+ _iterator4.e(_context2.t1);
272
346
  case 22:
273
- _context.prev = 22;
347
+ _context2.prev = 22;
274
348
  _iterator4.f();
275
- return _context.finish(22);
349
+ return _context2.finish(22);
276
350
  case 25:
277
351
  this.modules.clear();
278
352
 
279
353
  // 再销毁插件
280
354
  _iterator5 = _createForOfIteratorHelper(this.plugins.entries());
281
- _context.prev = 27;
355
+ _context2.prev = 27;
282
356
  _iterator5.s();
283
357
  case 29:
284
358
  if ((_step5 = _iterator5.n()).done) {
285
- _context.next = 43;
359
+ _context2.next = 43;
286
360
  break;
287
361
  }
288
362
  _step5$value = _slicedToArray(_step5.value, 2), _name = _step5$value[0], plugin = _step5$value[1];
289
363
  if (!plugin.destroy) {
290
- _context.next = 41;
364
+ _context2.next = 41;
291
365
  break;
292
366
  }
293
- _context.prev = 32;
294
- _context.next = 35;
367
+ _context2.prev = 32;
368
+ _context2.next = 35;
295
369
  return Promise.resolve(plugin.destroy());
296
370
  case 35:
297
371
  this.log("\u63D2\u4EF6 ".concat(_name, " \u5DF2\u9500\u6BC1"));
298
- _context.next = 41;
372
+ _context2.next = 41;
299
373
  break;
300
374
  case 38:
301
- _context.prev = 38;
302
- _context.t2 = _context["catch"](32);
303
- this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context.t2), 'error');
375
+ _context2.prev = 38;
376
+ _context2.t2 = _context2["catch"](32);
377
+ this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context2.t2), 'error');
304
378
  case 41:
305
- _context.next = 29;
379
+ _context2.next = 29;
306
380
  break;
307
381
  case 43:
308
- _context.next = 48;
382
+ _context2.next = 48;
309
383
  break;
310
384
  case 45:
311
- _context.prev = 45;
312
- _context.t3 = _context["catch"](27);
313
- _iterator5.e(_context.t3);
385
+ _context2.prev = 45;
386
+ _context2.t3 = _context2["catch"](27);
387
+ _iterator5.e(_context2.t3);
314
388
  case 48:
315
- _context.prev = 48;
389
+ _context2.prev = 48;
316
390
  _iterator5.f();
317
- return _context.finish(48);
391
+ return _context2.finish(48);
318
392
  case 51:
319
393
  this.plugins.clear();
320
394
  this.log('PisellOS 核心已销毁');
321
395
  case 53:
322
396
  case "end":
323
- return _context.stop();
397
+ return _context2.stop();
324
398
  }
325
- }, _callee, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
399
+ }, _callee2, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
326
400
  }));
327
401
  function destroy() {
328
402
  return _destroy.apply(this, arguments);
@@ -6,6 +6,7 @@ type UnsubscribeFunction = () => void;
6
6
  declare class EffectsManager {
7
7
  private listeners;
8
8
  on(event: string, callback: EffectCallback): UnsubscribeFunction;
9
+ only(event: string, callback: EffectCallback): UnsubscribeFunction;
9
10
  off(event: string, callback: EffectCallback): void;
10
11
  offByModuleDestroy(module: string): void;
11
12
  once(event: string, callback: EffectCallback): UnsubscribeFunction;
@@ -30,28 +30,51 @@ var EffectsManager = /*#__PURE__*/function () {
30
30
  _this.off(event, callback);
31
31
  };
32
32
  }
33
+
34
+ // 设置单例监听器,只能存在一个,新的会替换旧的
35
+ }, {
36
+ key: "only",
37
+ value: function only(event, callback) {
38
+ var _this$listeners$get3,
39
+ _this2 = this;
40
+ // 清除该事件的所有现有监听器
41
+ if (this.listeners.has(event)) {
42
+ var _this$listeners$get2;
43
+ (_this$listeners$get2 = this.listeners.get(event)) === null || _this$listeners$get2 === void 0 || _this$listeners$get2.clear();
44
+ } else {
45
+ this.listeners.set(event, new Set());
46
+ }
47
+
48
+ // 添加新的监听器
49
+ (_this$listeners$get3 = this.listeners.get(event)) === null || _this$listeners$get3 === void 0 || _this$listeners$get3.add(callback);
50
+
51
+ // 返回取消函数
52
+ return function () {
53
+ _this2.off(event, callback);
54
+ };
55
+ }
33
56
  }, {
34
57
  key: "off",
35
58
  value: function off(event, callback) {
36
- var _this$listeners$get2;
37
- (_this$listeners$get2 = this.listeners.get(event)) === null || _this$listeners$get2 === void 0 || _this$listeners$get2.delete(callback);
59
+ var _this$listeners$get4;
60
+ (_this$listeners$get4 = this.listeners.get(event)) === null || _this$listeners$get4 === void 0 || _this$listeners$get4.delete(callback);
38
61
  }
39
62
 
40
63
  // 模块销毁时,删除所有以模块名开头的监听
41
64
  }, {
42
65
  key: "offByModuleDestroy",
43
66
  value: function offByModuleDestroy(module) {
44
- var _this2 = this;
67
+ var _this3 = this;
45
68
  Array.from(this.listeners.keys()).forEach(function (item) {
46
69
  if (item.startsWith(module)) {
47
- _this2.listeners.delete(item);
70
+ _this3.listeners.delete(item);
48
71
  }
49
72
  });
50
73
  }
51
74
  }, {
52
75
  key: "once",
53
76
  value: function once(event, callback) {
54
- var _this3 = this;
77
+ var _this4 = this;
55
78
  var wrapper = /*#__PURE__*/function () {
56
79
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload) {
57
80
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -60,7 +83,7 @@ var EffectsManager = /*#__PURE__*/function () {
60
83
  _context.next = 2;
61
84
  return callback(payload);
62
85
  case 2:
63
- _this3.off(event, wrapper);
86
+ _this4.off(event, wrapper);
64
87
  case 3:
65
88
  case "end":
66
89
  return _context.stop();
@@ -18,7 +18,6 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
18
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
19
  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); }
20
20
  import { BaseModule } from "../BaseModule";
21
- import { AccountHooks } from "./types";
22
21
  export * from "./types";
23
22
  export var AccountModule = /*#__PURE__*/function (_BaseModule) {
24
23
  _inherits(AccountModule, _BaseModule);
@@ -85,7 +84,7 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
85
84
  this.store.accountInfo = account;
86
85
  this.store.isLoggedIn = true;
87
86
  _context2.next = 5;
88
- return this.core.effects.emit(AccountHooks.OnLogin, account);
87
+ return this.core.effects.emit("".concat(this.name, ":onLogin"), account);
89
88
  case 5:
90
89
  case "end":
91
90
  return _context2.stop();
@@ -117,7 +116,7 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
117
116
  case 2:
118
117
  this.store.accountInfo = _objectSpread(_objectSpread({}, this.store.accountInfo), updates);
119
118
  _context3.next = 5;
120
- return this.core.effects.emit(AccountHooks.OnProfileUpdate, this.store.accountInfo);
119
+ return this.core.effects.emit("".concat(this.name, ":onProfileUpdate"), this.store.accountInfo);
121
120
  case 5:
122
121
  case "end":
123
122
  return _context3.stop();
@@ -14,4 +14,7 @@ export declare class BaseModule {
14
14
  store: any;
15
15
  cacheKey: string[];
16
16
  }): void;
17
+ effectsOn(eventType: string, callback: (payload: any) => void): () => void;
18
+ effectsOff(eventType: string, callback: (payload: any) => void): void;
19
+ effectsOnce(eventType: string, callback: (payload: any) => void): () => void;
17
20
  }
@@ -64,6 +64,21 @@ export var BaseModule = /*#__PURE__*/function () {
64
64
  }
65
65
  }
66
66
  }
67
+ }, {
68
+ key: "effectsOn",
69
+ value: function effectsOn(eventType, callback) {
70
+ return this.core.effects.on("".concat(this.name, ":").concat(eventType), callback);
71
+ }
72
+ }, {
73
+ key: "effectsOff",
74
+ value: function effectsOff(eventType, callback) {
75
+ return this.core.effects.off("".concat(this.name, ":").concat(eventType), callback);
76
+ }
77
+ }, {
78
+ key: "effectsOnce",
79
+ value: function effectsOnce(eventType, callback) {
80
+ return this.core.effects.once("".concat(this.name, ":").concat(eventType), callback);
81
+ }
67
82
  }]);
68
83
  return BaseModule;
69
84
  }();
@@ -29,7 +29,6 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
29
29
  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); }
30
30
  import { cloneDeep } from 'lodash-es';
31
31
  import { BaseModule } from "../BaseModule";
32
- import { CustomerHooks } from "./types";
33
32
  import { DEFAULT_CUSTOMER, DEFAULT_PAGE_SIZE, SORT_BY } from "./constants";
34
33
  export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
35
34
  _inherits(CustomerModule, _BaseModule);
@@ -203,7 +202,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
203
202
  console.error("Failed to ".concat(operation, ":"), error);
204
203
  this.store.error = error instanceof Error ? error.message : "Failed to ".concat(operation);
205
204
  _context3.next = 4;
206
- return this.core.effects.emit(CustomerHooks.OnCustomerListError, this.store.error);
205
+ return this.core.effects.emit("".concat(this.name, ":onCustomerListError"), this.store.error);
207
206
  case 4:
208
207
  case "end":
209
208
  return _context3.stop();
@@ -266,7 +265,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
266
265
  // 设置客户列表(替换模式)
267
266
  this.store.customerList = cloneDeep(customerList);
268
267
  _context4.next = 20;
269
- return this.core.effects.emit(CustomerHooks.OnCustomerListUpdate, this.store);
268
+ return this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
270
269
  case 20:
271
270
  // 触发分页变化事件
272
271
  this.triggerPaginationChange({
@@ -329,7 +328,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
329
328
  key: "setSelectedCustomer",
330
329
  value: function setSelectedCustomer(customer) {
331
330
  this.store.selectedCustomer = !customer ? DEFAULT_CUSTOMER : cloneDeep(customer);
332
- this.core.effects.emit(CustomerHooks.OnCustomerSelected, this.store.selectedCustomer);
331
+ this.core.effects.emit("".concat(this.name, ":onCustomerSelected"), this.store.selectedCustomer);
333
332
  this.storeChange();
334
333
  }
335
334
 
@@ -380,7 +379,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
380
379
  this.store.hasMore = true;
381
380
  this.store.loadingMore = false;
382
381
  this.store.searchParams = {};
383
- this.core.effects.emit(CustomerHooks.OnCustomerListUpdate, this.store);
382
+ this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
384
383
  this.storeChange();
385
384
  }
386
385
 
@@ -401,7 +400,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
401
400
  this.store.total += 1;
402
401
 
403
402
  // 触发客户列表更新事件
404
- this.core.effects.emit(CustomerHooks.OnCustomerListUpdate, this.store);
403
+ this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
405
404
 
406
405
  // 保存状态变化
407
406
  this.storeChange();
@@ -439,7 +438,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
439
438
  }, {
440
439
  key: "triggerPaginationChange",
441
440
  value: function triggerPaginationChange(pagination) {
442
- this.core.effects.emit(CustomerHooks.OnPaginationChange, pagination);
441
+ this.core.effects.emit("".concat(this.name, ":onPaginationChange"), pagination);
443
442
  }
444
443
 
445
444
  /**
@@ -552,7 +551,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
552
551
 
553
552
  // 触发滚动加载特定事件
554
553
  _context6.next = 20;
555
- return this.core.effects.emit(CustomerHooks.OnScrollLoadMore, {
554
+ return this.core.effects.emit("".concat(this.name, ":onScrollLoadMore"), {
556
555
  newCustomers: newCustomers,
557
556
  allCustomers: this.store.customerList,
558
557
  currentPage: page,
@@ -560,7 +559,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
560
559
  });
561
560
  case 20:
562
561
  _context6.next = 22;
563
- return this.core.effects.emit(CustomerHooks.OnCustomerListUpdate, this.store);
562
+ return this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
564
563
  case 22:
565
564
  // 触发分页变化事件
566
565
  this.triggerPaginationChange({
@@ -634,7 +633,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
634
633
  case 8:
635
634
  response = _context7.sent;
636
635
  _context7.next = 11;
637
- return this.core.effects.emit(CustomerHooks.OnScrollLoadComplete, {
636
+ return this.core.effects.emit("".concat(this.name, ":onScrollLoadComplete"), {
638
637
  customers: this.store.customerList,
639
638
  total: this.store.total,
640
639
  hasMore: this.store.hasMore
@@ -1,8 +1,8 @@
1
1
  import { ICustomer } from "../AccountList/types";
2
2
  export declare enum CustomerHooks {
3
- OnCustomerListUpdate = "customer:onUpdate",
3
+ OnCustomerListUpdate = "customer:onCustomerListUpdate",
4
4
  OnCustomerListError = "customer:onError",
5
- OnCustomerSelected = "customer:onSelected",
5
+ OnCustomerSelected = "customer:onCustomerSelected",
6
6
  OnPaginationChange = "customer:onPaginationChange",
7
7
  OnScrollLoadMore = "customer:onScrollLoadMore",
8
8
  OnScrollLoadComplete = "customer:onScrollLoadComplete"
@@ -1,7 +1,7 @@
1
1
  export var CustomerHooks = /*#__PURE__*/function (CustomerHooks) {
2
- CustomerHooks["OnCustomerListUpdate"] = "customer:onUpdate";
2
+ CustomerHooks["OnCustomerListUpdate"] = "customer:onCustomerListUpdate";
3
3
  CustomerHooks["OnCustomerListError"] = "customer:onError";
4
- CustomerHooks["OnCustomerSelected"] = "customer:onSelected";
4
+ CustomerHooks["OnCustomerSelected"] = "customer:onCustomerSelected";
5
5
  CustomerHooks["OnPaginationChange"] = "customer:onPaginationChange";
6
6
  CustomerHooks["OnScrollLoadMore"] = "customer:onScrollLoadMore";
7
7
  CustomerHooks["OnScrollLoadComplete"] = "customer:onScrollLoadComplete";
@@ -283,7 +283,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
283
283
  this.store.discountList = [];
284
284
  this.core.effects.offByModuleDestroy(this.name);
285
285
  _context5.next = 4;
286
- return this.core.effects.emit(DiscountHooks.OnDestroy, {});
286
+ return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
287
287
  case 4:
288
288
  console.log('[Discount] 已销毁');
289
289
  case 5: