@pisell/pisellos 0.0.15 → 0.0.16

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 (43) hide show
  1. package/dist/modules/AccountList/index.d.ts +5 -1
  2. package/dist/modules/AccountList/index.js +82 -36
  3. package/dist/modules/AccountList/types.d.ts +1 -0
  4. package/dist/modules/BaseModule.d.ts +6 -0
  5. package/dist/modules/BaseModule.js +41 -0
  6. package/dist/modules/Cart/index.d.ts +4 -0
  7. package/dist/modules/Cart/index.js +33 -6
  8. package/dist/modules/Date/index.d.ts +5 -0
  9. package/dist/modules/Date/index.js +35 -2
  10. package/dist/modules/Discount/index.d.ts +4 -0
  11. package/dist/modules/Discount/index.js +32 -4
  12. package/dist/modules/Discount/types.d.ts +3 -0
  13. package/dist/modules/Rules/index.js +7 -4
  14. package/dist/modules/Step/index.d.ts +4 -0
  15. package/dist/modules/Step/index.js +29 -1
  16. package/dist/modules/Summary/index.d.ts +4 -0
  17. package/dist/modules/Summary/index.js +28 -2
  18. package/dist/solution/BookingByStep/index.d.ts +12 -1
  19. package/dist/solution/BookingByStep/index.js +112 -17
  20. package/dist/solution/BookingByStep/types.js +0 -3
  21. package/dist/solution/ShopDiscount/index.js +24 -3
  22. package/lib/modules/AccountList/index.d.ts +5 -1
  23. package/lib/modules/AccountList/index.js +33 -1
  24. package/lib/modules/AccountList/types.d.ts +1 -0
  25. package/lib/modules/BaseModule.d.ts +6 -0
  26. package/lib/modules/BaseModule.js +37 -0
  27. package/lib/modules/Cart/index.d.ts +4 -0
  28. package/lib/modules/Cart/index.js +19 -1
  29. package/lib/modules/Date/index.d.ts +5 -0
  30. package/lib/modules/Date/index.js +21 -0
  31. package/lib/modules/Discount/index.d.ts +4 -0
  32. package/lib/modules/Discount/index.js +19 -0
  33. package/lib/modules/Discount/types.d.ts +3 -0
  34. package/lib/modules/Rules/index.js +9 -4
  35. package/lib/modules/Step/index.d.ts +4 -0
  36. package/lib/modules/Step/index.js +19 -0
  37. package/lib/modules/Summary/index.d.ts +4 -0
  38. package/lib/modules/Summary/index.js +17 -0
  39. package/lib/solution/BookingByStep/index.d.ts +12 -1
  40. package/lib/solution/BookingByStep/index.js +55 -5
  41. package/lib/solution/BookingByStep/types.js +0 -3
  42. package/lib/solution/ShopDiscount/index.js +21 -3
  43. package/package.json +1 -1
@@ -26,18 +26,34 @@ export var StepModule = /*#__PURE__*/function (_BaseModule) {
26
26
  _defineProperty(_assertThisInitialized(_this), "defaultName", "step");
27
27
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
28
28
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
29
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
30
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
31
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
29
32
  return _this;
30
33
  }
31
34
  _createClass(StepModule, [{
32
35
  key: "initialize",
33
36
  value: function () {
34
37
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
38
+ var _options$otherParams, _options$otherParams2;
35
39
  return _regeneratorRuntime().wrap(function _callee$(_context) {
36
40
  while (1) switch (_context.prev = _context.next) {
37
41
  case 0:
38
42
  this.core = core;
39
43
  this.store = options.store;
40
- case 2:
44
+ if (options.initialState) {
45
+ this.store.stepList = options.initialState.stepList;
46
+ this.store.currentStep = options.initialState.currentStep;
47
+ this.store.currentStepIndex = options.initialState.currentStepIndex;
48
+ }
49
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
50
+ this.openCache = options.otherParams.openCache;
51
+ this.cacheId = options.otherParams.cacheId;
52
+ }
53
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
54
+ this.fatherModule = options.otherParams.fatherModule;
55
+ }
56
+ case 5:
41
57
  case "end":
42
58
  return _context.stop();
43
59
  }
@@ -102,6 +118,18 @@ export var StepModule = /*#__PURE__*/function (_BaseModule) {
102
118
  value: function gotoStep(stepIndex) {
103
119
  this.setCurrentStep(stepIndex);
104
120
  }
121
+ }, {
122
+ key: "storeChange",
123
+ value: function storeChange() {
124
+ if (this.openCache) {
125
+ this.checkSaveCache({
126
+ cacheId: this.cacheId,
127
+ fatherModule: this.fatherModule,
128
+ store: this.store,
129
+ cacheKey: ['currentStepIndex', 'currentStep', 'stepList']
130
+ });
131
+ }
132
+ }
105
133
  }]);
106
134
  return StepModule;
107
135
  }(BaseModule);
@@ -7,7 +7,11 @@ export declare class SummaryModule extends BaseModule implements Module, ISummar
7
7
  protected defaultVersion: string;
8
8
  private shopStore;
9
9
  private store;
10
+ private cacheId;
11
+ private openCache;
12
+ private fatherModule;
10
13
  constructor(name?: string, version?: string);
11
14
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
12
15
  getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
16
+ storeChange(): void;
13
17
  }
@@ -28,24 +28,38 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
28
28
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
29
29
  _defineProperty(_assertThisInitialized(_this), "shopStore", void 0);
30
30
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
33
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
31
34
  return _this;
32
35
  }
33
36
  _createClass(SummaryModule, [{
34
37
  key: "initialize",
35
38
  value: function () {
36
39
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
40
+ var _options$otherParams, _options$otherParams2;
37
41
  return _regeneratorRuntime().wrap(function _callee$(_context) {
38
42
  while (1) switch (_context.prev = _context.next) {
39
43
  case 0:
40
44
  this.core = core;
41
45
  this.store = options.store;
42
46
  this.shopStore = this.core.getPlugin("shopStore");
47
+ if (options.initialState) {
48
+ this.store.summary = options.initialState.summary;
49
+ }
50
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
51
+ this.openCache = options.otherParams.openCache;
52
+ this.cacheId = options.otherParams.cacheId;
53
+ }
54
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
55
+ this.fatherModule = options.otherParams.fatherModule;
56
+ }
43
57
  if (this.shopStore) {
44
- _context.next = 5;
58
+ _context.next = 8;
45
59
  break;
46
60
  }
47
61
  throw new Error("SummaryModule 需要 shopStore 插件支持");
48
- case 5:
62
+ case 8:
49
63
  case "end":
50
64
  return _context.stop();
51
65
  }
@@ -80,6 +94,18 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
80
94
  }
81
95
  return getSummary;
82
96
  }()
97
+ }, {
98
+ key: "storeChange",
99
+ value: function storeChange() {
100
+ if (this.openCache) {
101
+ this.checkSaveCache({
102
+ cacheId: this.cacheId,
103
+ fatherModule: this.fatherModule,
104
+ store: this.store,
105
+ cacheKey: ['summary']
106
+ });
107
+ }
108
+ }
83
109
  }]);
84
110
  return SummaryModule;
85
111
  }(BaseModule);
@@ -38,7 +38,8 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
38
38
  getActiveAccount(): Account | null;
39
39
  removeAccount(id: string): void;
40
40
  setDateRange(dateRange: ITime[]): Promise<void>;
41
- getRangeDate(): Promise<string>;
41
+ clearDateRange(): void;
42
+ getDateRange(): Promise<ITime[]>;
42
43
  getCart(): Promise<CartItem[]>;
43
44
  getAvailableDate(params?: {
44
45
  products?: ProductData[];
@@ -79,6 +80,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
79
80
  deleteCartItemInfo(types: "resource" | "time"): void;
80
81
  destory(): void;
81
82
  getResourcesList(): any[];
83
+ getResourcesListByCartItem(id: string | number): {
84
+ id: number | undefined;
85
+ _id: string;
86
+ product: ProductData | undefined;
87
+ resources: import("./utils/resources").ResourceItem[];
88
+ holder_id: string | number | undefined;
89
+ holder_name: string | undefined;
90
+ } | undefined;
82
91
  getResourceTimeSlot({ product, resources, currentResourceId, }: {
83
92
  product: ProductData;
84
93
  resources: any[];
@@ -111,4 +120,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
111
120
  };
112
121
  getTimeSlotByAllResources(resources_code: string): any[];
113
122
  submitTimeSlot(timeSlots: TimeSliceItem): void;
123
+ clearCache(): void;
124
+ clearCacheByModule(module: string): void;
114
125
  }
@@ -6,9 +6,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
6
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
8
  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; }
9
+ 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; }
9
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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
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
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"); } }
@@ -55,8 +55,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
55
55
  key: "initialize",
56
56
  value: function () {
57
57
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
58
- var _this2 = this;
59
- var moduleArr;
58
+ var _this$otherParams,
59
+ _this2 = this;
60
+ var targetCacheData, sessionData, data, moduleArr;
60
61
  return _regeneratorRuntime().wrap(function _callee$(_context) {
61
62
  while (1) switch (_context.prev = _context.next) {
62
63
  case 0:
@@ -74,18 +75,64 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
74
75
  }
75
76
  throw new Error("bookingByStep解决方案需要 request 插件支持");
76
77
  case 9:
77
- moduleArr = ["cart", "summary", "step", "products", "guests", "date", "accountList", "order", "payment"];
78
+ // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
79
+ // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
80
+ targetCacheData = {};
81
+ if ((_this$otherParams = this.otherParams) !== null && _this$otherParams !== void 0 && _this$otherParams.cacheId) {
82
+ sessionData = this.window.sessionStorage.getItem(this.name);
83
+ if (sessionData) {
84
+ data = JSON.parse(sessionData); // sessionData 格式:
85
+ // {
86
+ // "123123123": {
87
+ // "step": {
88
+ // stepList: [],
89
+ // currentStep: {},
90
+ // currentStepIndex: 0
91
+ // }
92
+ // "cart": {
93
+ // "list": []
94
+ // },
95
+ // "accountList": {
96
+ // "accounts": []
97
+ // },
98
+ // "date": {
99
+ // "dateList": [],
100
+ // "dateRange": []
101
+ // },
102
+ // "summary": {
103
+ // "subtotal": 1,
104
+ // "total": 1,
105
+ // "taxTitle": 1;
106
+ // "totalTaxFee": 1
107
+ // "isPriceIncludeTax": 1
108
+ // }
109
+ // }
110
+ // }
111
+ // 匹配 cacheid,如果匹配不到,直接把 sessionData 清掉即可
112
+ // 如果匹配到了,则把 sessionData 里的数据按模块塞到 store 里去
113
+ targetCacheData = data[this.otherParams.cacheId];
114
+ }
115
+ }
116
+ moduleArr = ["cart", "summary", "step", "products", "date", "accountList", "order", "payment"];
78
117
  moduleArr.forEach(function (step) {
79
118
  var targetModule = createModule(step, _this2.name);
80
119
  if (targetModule) {
120
+ var _this2$otherParams, _this2$otherParams2;
81
121
  _this2.store[step] = targetModule;
82
- _this2.core.registerModule(targetModule);
122
+ _this2.core.registerModule(targetModule, {
123
+ initialState: targetCacheData[targetModule.name],
124
+ otherParams: _objectSpread(_objectSpread({}, _this2.otherParams), {}, {
125
+ fatherModule: _this2.name,
126
+ openCache: (_this2$otherParams = _this2.otherParams) !== null && _this2$otherParams !== void 0 && _this2$otherParams.cacheId ? true : false,
127
+ cacheId: (_this2$otherParams2 = _this2.otherParams) === null || _this2$otherParams2 === void 0 ? void 0 : _this2$otherParams2.cacheId
128
+ })
129
+ });
83
130
  } else {
84
131
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
85
132
  }
86
133
  });
87
134
  this.core.effects.emit(BookingByStepHooks.onInited, {});
88
- case 12:
135
+ case 14:
89
136
  case "end":
90
137
  return _context.stop();
91
138
  }
@@ -163,6 +210,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
163
210
  category_ids: category_ids,
164
211
  ids: product_ids,
165
212
  collection: collection
213
+ }, {
214
+ useCache: true
166
215
  });
167
216
  case 3:
168
217
  productsData = _context2.sent;
@@ -307,25 +356,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
307
356
  return _setDateRange.apply(this, arguments);
308
357
  }
309
358
  return setDateRange;
310
- }() // 获取日期模块里选中的日期
359
+ }()
311
360
  }, {
312
- key: "getRangeDate",
361
+ key: "clearDateRange",
362
+ value: function clearDateRange() {
363
+ this.store.date.clearDateRange();
364
+ }
365
+
366
+ // 获取日期模块里选中的日期
367
+ }, {
368
+ key: "getDateRange",
313
369
  value: function () {
314
- var _getRangeDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
370
+ var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
315
371
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
316
372
  while (1) switch (_context7.prev = _context7.next) {
317
373
  case 0:
318
- return _context7.abrupt("return", "2024-01-01");
374
+ return _context7.abrupt("return", this.store.date.getDateRange());
319
375
  case 1:
320
376
  case "end":
321
377
  return _context7.stop();
322
378
  }
323
- }, _callee7);
379
+ }, _callee7, this);
324
380
  }));
325
- function getRangeDate() {
326
- return _getRangeDate.apply(this, arguments);
381
+ function getDateRange() {
382
+ return _getDateRange.apply(this, arguments);
327
383
  }
328
- return getRangeDate;
384
+ return getDateRange;
329
385
  }()
330
386
  }, {
331
387
  key: "getCart",
@@ -350,7 +406,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
350
406
  key: "getAvailableDate",
351
407
  value: function () {
352
408
  var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
353
- var _this$otherParams, _this$otherParams2;
409
+ var _this$otherParams2, _this$otherParams3;
354
410
  var params,
355
411
  products,
356
412
  startDate,
@@ -373,8 +429,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
373
429
  tempProducts = products || this.store.cart.getItems().map(function (p) {
374
430
  return p._productOrigin;
375
431
  });
376
- tempStartDate = startDate || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 || (_this$otherParams = _this$otherParams.dateRange) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams[0]);
377
- tempEndDate = endDate || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 || (_this$otherParams2 = _this$otherParams2.dateRange) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2[1]);
432
+ tempStartDate = startDate || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 || (_this$otherParams2 = _this$otherParams2.dateRange) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2[0]);
433
+ tempEndDate = endDate || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 || (_this$otherParams3 = _this$otherParams3.dateRange) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3[1]);
378
434
  if (tempProducts.length) {
379
435
  _context9.next = 7;
380
436
  break;
@@ -720,6 +776,39 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
720
776
  return arr;
721
777
  }
722
778
 
779
+ // 给单个购物车里的商品获取资源列表
780
+ }, {
781
+ key: "getResourcesListByCartItem",
782
+ value: function getResourcesListByCartItem(id) {
783
+ var cartItems = this.store.cart.getItems();
784
+ var dateRange = this.store.date.getDateRange();
785
+ var resources = [];
786
+ dateRange.forEach(function (n) {
787
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
788
+ });
789
+ var resourcesMap = getResourcesMap(resources);
790
+ var arr = [];
791
+ var targetCartItem = cartItems.find(function (n) {
792
+ return n._id === id;
793
+ });
794
+ if (!targetCartItem) {
795
+ throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
796
+ }
797
+ var productResources = getResourcesByProduct(resourcesMap, targetCartItem, cartItems);
798
+ if (productResources) {
799
+ return {
800
+ id: targetCartItem.id,
801
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
802
+ _id: targetCartItem._id,
803
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
804
+ product: targetCartItem._productOrigin,
805
+ resources: productResources,
806
+ holder_id: targetCartItem.holder_id,
807
+ holder_name: targetCartItem.holder_title
808
+ };
809
+ }
810
+ }
811
+
723
812
  // 通过资源列表和指定的资源 id,获取指定资源的时间切片
724
813
  }, {
725
814
  key: "getResourceTimeSlot",
@@ -1065,6 +1154,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1065
1154
  });
1066
1155
  });
1067
1156
  }
1157
+ }, {
1158
+ key: "clearCache",
1159
+ value: function clearCache() {}
1160
+ }, {
1161
+ key: "clearCacheByModule",
1162
+ value: function clearCacheByModule(module) {}
1068
1163
  }]);
1069
1164
  return BookingByStepImpl;
1070
1165
  }(BaseModule);
@@ -1,7 +1,6 @@
1
1
  import { ProductList, CartModule } from "../../modules";
2
2
  import { AccountListModule } from "../../modules/AccountList";
3
3
  import { DateModule } from "../../modules/Date";
4
- import { GuestListModule } from "../../modules/Guests";
5
4
  import { OrderModule } from "../../modules/Order";
6
5
  import { PaymentModule } from "../../modules/Payment";
7
6
  import { StepModule } from "../../modules/Step";
@@ -16,8 +15,6 @@ export function createModule(moduleName, solutionName, name, version) {
16
15
  return new StepModule("".concat(solutionName, "_").concat(name || moduleName), version);
17
16
  case "products":
18
17
  return new ProductList("".concat(solutionName, "_").concat(name || moduleName), version);
19
- case "guests":
20
- return new GuestListModule("".concat(solutionName, "_").concat(name || moduleName), version);
21
18
  case "date":
22
19
  return new DateModule("".concat(solutionName, "_").concat(name || moduleName), version);
23
20
  case "accountList":
@@ -154,18 +154,35 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
154
154
  }, {
155
155
  key: "registerDependentModules",
156
156
  value: function registerDependentModules() {
157
- var _this$options$otherPa, _this$options$otherPa2;
157
+ var _this$options$otherPa, _this$options$otherPa2, _this$options$otherPa3, _this$options$otherPa4, _this$options$otherPa5;
158
+ // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
159
+ // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
160
+ var targetCacheData = {};
161
+ if ((_this$options$otherPa = this.options.otherParams) !== null && _this$options$otherPa !== void 0 && _this$options$otherPa.cacheId) {
162
+ var sessionData = this.window.sessionStorage.getItem(this.name);
163
+ if (sessionData) {
164
+ var data = JSON.parse(sessionData);
165
+ targetCacheData = data[this.options.otherParams.cacheId];
166
+ }
167
+ }
168
+
158
169
  // 注册优惠模块
159
170
  var discount = new DiscountModule("".concat(this.name, "_discount"));
160
171
  this.core.registerModule(discount, {
161
- hooks: (_this$options$otherPa = this.options.otherParams) === null || _this$options$otherPa === void 0 || (_this$options$otherPa = _this$options$otherPa.discount) === null || _this$options$otherPa === void 0 ? void 0 : _this$options$otherPa.hooks
172
+ initialState: targetCacheData[discount.name],
173
+ hooks: (_this$options$otherPa2 = this.options.otherParams) === null || _this$options$otherPa2 === void 0 || (_this$options$otherPa2 = _this$options$otherPa2.discount) === null || _this$options$otherPa2 === void 0 ? void 0 : _this$options$otherPa2.hooks,
174
+ otherParams: {
175
+ fatherModule: this.name,
176
+ openCache: (_this$options$otherPa3 = this.options.otherParams) !== null && _this$options$otherPa3 !== void 0 && _this$options$otherPa3.cacheId ? true : false,
177
+ cacheId: (_this$options$otherPa4 = this.options.otherParams) === null || _this$options$otherPa4 === void 0 ? void 0 : _this$options$otherPa4.cacheId
178
+ }
162
179
  });
163
180
  this.store.discount = discount;
164
181
 
165
182
  // 注册规则模块
166
183
  var rules = new RulesModule("".concat(this.name, "_rules"));
167
184
  this.core.registerModule(rules, {
168
- hooks: (_this$options$otherPa2 = this.options.otherParams) === null || _this$options$otherPa2 === void 0 || (_this$options$otherPa2 = _this$options$otherPa2.rules) === null || _this$options$otherPa2 === void 0 ? void 0 : _this$options$otherPa2.hooks
185
+ hooks: (_this$options$otherPa5 = this.options.otherParams) === null || _this$options$otherPa5 === void 0 || (_this$options$otherPa5 = _this$options$otherPa5.rules) === null || _this$options$otherPa5 === void 0 ? void 0 : _this$options$otherPa5.hooks
169
186
  });
170
187
  this.store.rules = rules;
171
188
  }
@@ -174,6 +191,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
174
191
  value: function registerEventListeners() {
175
192
  var _this2 = this;
176
193
  this.core.effects.on(ShopDiscountHooks.onCustomerChange, function (customer) {
194
+ var _this2$options$otherP;
195
+ if ((_this2$options$otherP = _this2.options.otherParams) !== null && _this2$options$otherP !== void 0 && _this2$options$otherP.cacheId && _this2.getDiscountList().length) {
196
+ return;
197
+ }
177
198
  _this2.loadPrepareConfig({
178
199
  customerId: customer.id,
179
200
  action: "create",
@@ -6,10 +6,13 @@ export declare class AccountListModule extends BaseModule implements Module {
6
6
  protected defaultName: string;
7
7
  protected defaultVersion: string;
8
8
  private store;
9
+ private cacheId;
10
+ private openCache;
11
+ private fatherModule;
9
12
  constructor(name?: string, version?: string);
10
13
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
11
14
  addAccount(account: Account): Promise<void>;
12
- updateAccount(id: string, updates: Partial<Account>): Promise<void>;
15
+ updateAccount(id: string, updates: Account): Promise<void>;
13
16
  removeAccount(id: string): Promise<void>;
14
17
  getAccounts(): AccountModule[];
15
18
  getAccount(id: string): AccountModule | null;
@@ -17,4 +20,5 @@ export declare class AccountListModule extends BaseModule implements Module {
17
20
  getState(): AccountListState;
18
21
  setActiveAccount(id: string | number): void;
19
22
  getActiveAccount(): AccountModule | null;
23
+ storeChange(): void;
20
24
  }
@@ -31,15 +31,35 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
31
31
  this.defaultName = "accountList";
32
32
  this.defaultVersion = "1.0.0";
33
33
  this.store = {
34
+ accountList: [],
35
+ // 账号的纯数据列表
34
36
  accounts: [],
37
+ // 账号的 module 列表
35
38
  isLoading: false,
36
39
  error: null
37
40
  };
41
+ this.openCache = false;
38
42
  }
39
43
  async initialize(core, options) {
44
+ var _a, _b, _c;
40
45
  this.core = core;
41
46
  this.store = options == null ? void 0 : options.store;
42
47
  this.store.accounts = [];
48
+ if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.accountList)) {
49
+ const recordList = options.initialState.accountList || [];
50
+ recordList.forEach((account) => {
51
+ this.addAccount(account);
52
+ });
53
+ } else {
54
+ this.store.accountList = [];
55
+ }
56
+ if ((_b = options == null ? void 0 : options.otherParams) == null ? void 0 : _b.cacheId) {
57
+ this.openCache = options.otherParams.openCache;
58
+ this.cacheId = options.otherParams.cacheId;
59
+ }
60
+ if ((_c = options == null ? void 0 : options.otherParams) == null ? void 0 : _c.fatherModule) {
61
+ this.fatherModule = options.otherParams.fatherModule;
62
+ }
43
63
  }
44
64
  async addAccount(account) {
45
65
  try {
@@ -48,6 +68,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
48
68
  if (this.store.accounts.some((a) => a.getId() === account.id)) {
49
69
  throw new Error(`Account with id ${account.id} already exists`);
50
70
  }
71
+ this.store.accountList.push(account);
51
72
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
52
73
  this.core.registerModule(accountModule);
53
74
  accountModule.setAccountInfo(account);
@@ -72,7 +93,12 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
72
93
  if (!account) {
73
94
  throw new Error(`Account with id ${id} not found`);
74
95
  }
75
- Object.assign(account, updates);
96
+ account.setAccountInfo(updates);
97
+ this.store.accountList.forEach((account2) => {
98
+ if (account2.id === id) {
99
+ Object.assign(account2, updates);
100
+ }
101
+ });
76
102
  await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
77
103
  } catch (error) {
78
104
  this.store.error = error instanceof Error ? error.message : "Failed to update account";
@@ -94,6 +120,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
94
120
  ...this.store.accounts.slice(0, index),
95
121
  ...this.store.accounts.slice(index + 1)
96
122
  ];
123
+ this.store.accountList = this.store.accountList.filter((account) => account.id !== id);
97
124
  await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
98
125
  } catch (error) {
99
126
  this.store.error = error instanceof Error ? error.message : "Failed to remove account";
@@ -136,6 +163,11 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
136
163
  getActiveAccount() {
137
164
  return this.store.accounts.find((account) => account.isActive()) || null;
138
165
  }
166
+ storeChange() {
167
+ if (this.openCache) {
168
+ this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["accounts", "accountList"] });
169
+ }
170
+ }
139
171
  };
140
172
  // Annotate the CommonJS export names for ESM import in node:
141
173
  0 && (module.exports = {
@@ -19,6 +19,7 @@ export interface AccountListQuery {
19
19
  */
20
20
  export interface AccountListState {
21
21
  accounts: AccountModule[];
22
+ accountList: Account[];
22
23
  isLoading: boolean;
23
24
  error: string | null;
24
25
  }
@@ -8,4 +8,10 @@ export declare class BaseModule {
8
8
  protected core: PisellCore;
9
9
  constructor(name?: string, version?: string);
10
10
  destory(): void;
11
+ checkSaveCache({ cacheId, fatherModule, store, cacheKey }: {
12
+ cacheId: string | undefined;
13
+ fatherModule: string | undefined;
14
+ store: any;
15
+ cacheKey: string[];
16
+ }): void;
11
17
  }
@@ -34,6 +34,43 @@ var BaseModule = class {
34
34
  this.core.effects.offByModuleDestroy(this.name);
35
35
  this.core.unregisterModule(this);
36
36
  }
37
+ // 提供统一的缓存 module 里的数据的方法
38
+ checkSaveCache({ cacheId, fatherModule, store, cacheKey }) {
39
+ const window = this.core.getPlugin("window");
40
+ if (cacheId) {
41
+ if (fatherModule) {
42
+ const currentCacheData = window.sessionStorage.getItem(fatherModule);
43
+ let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
44
+ if (!currentCacheData || !currentCacheDataObj[cacheId]) {
45
+ currentCacheDataObj = {
46
+ [cacheId]: {
47
+ [this.name]: {}
48
+ }
49
+ };
50
+ }
51
+ if (!currentCacheDataObj[cacheId][this.name]) {
52
+ currentCacheDataObj[cacheId][this.name] = {};
53
+ }
54
+ cacheKey.forEach((key) => {
55
+ currentCacheDataObj[cacheId][this.name][key] = store == null ? void 0 : store[key];
56
+ });
57
+ window.sessionStorage.setItem(fatherModule, JSON.stringify(currentCacheDataObj));
58
+ } else {
59
+ let currentCacheData = window.sessionStorage.getItem(cacheId);
60
+ let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
61
+ if (!currentCacheDataObj) {
62
+ currentCacheDataObj = {};
63
+ }
64
+ if (!currentCacheDataObj[this.name]) {
65
+ currentCacheDataObj[this.name] = {};
66
+ }
67
+ cacheKey.forEach((key) => {
68
+ currentCacheDataObj[this.name][key] = store[key];
69
+ });
70
+ window.sessionStorage.setItem(cacheId, JSON.stringify(currentCacheDataObj));
71
+ }
72
+ }
73
+ }
37
74
  };
38
75
  // Annotate the CommonJS export names for ESM import in node:
39
76
  0 && (module.exports = {