@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
@@ -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
  }
@@ -36,23 +36,49 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
36
36
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'accountList');
37
37
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
38
38
  _defineProperty(_assertThisInitialized(_this), "store", {
39
+ accountList: [],
40
+ // 账号的纯数据列表
39
41
  accounts: [],
42
+ // 账号的 module 列表
40
43
  isLoading: false,
41
44
  error: null
42
45
  });
46
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
47
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
48
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
43
49
  return _this;
44
50
  }
45
51
  _createClass(AccountListModule, [{
46
52
  key: "initialize",
47
53
  value: function () {
48
54
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
55
+ var _options$initialState,
56
+ _this2 = this,
57
+ _options$otherParams,
58
+ _options$otherParams2;
59
+ var recordList;
49
60
  return _regeneratorRuntime().wrap(function _callee$(_context) {
50
61
  while (1) switch (_context.prev = _context.next) {
51
62
  case 0:
52
63
  this.core = core;
53
64
  this.store = options === null || options === void 0 ? void 0 : options.store;
54
65
  this.store.accounts = [];
55
- case 3:
66
+ if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.accountList)) {
67
+ recordList = options.initialState.accountList || [];
68
+ recordList.forEach(function (account) {
69
+ _this2.addAccount(account);
70
+ });
71
+ } else {
72
+ this.store.accountList = [];
73
+ }
74
+ if (options !== null && options !== void 0 && (_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
75
+ this.openCache = options.otherParams.openCache;
76
+ this.cacheId = options.otherParams.cacheId;
77
+ }
78
+ if (options !== null && options !== void 0 && (_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
79
+ this.fatherModule = options.otherParams.fatherModule;
80
+ }
81
+ case 6:
56
82
  case "end":
57
83
  return _context.stop();
58
84
  }
@@ -82,34 +108,35 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
82
108
  }
83
109
  throw new Error("Account with id ".concat(account.id, " already exists"));
84
110
  case 5:
111
+ this.store.accountList.push(account);
85
112
  accountModule = new AccountModule("account_".concat(account.id));
86
113
  this.core.registerModule(accountModule);
87
114
  accountModule.setAccountInfo(account);
88
115
  this.store.accounts = [].concat(_toConsumableArray(this.store.accounts), [accountModule]);
89
- _context2.next = 11;
116
+ _context2.next = 12;
90
117
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
91
- case 11:
118
+ case 12:
92
119
  if (this.store.accounts.length === 1) {
93
120
  this.setActiveAccount(accountModule.getId());
94
121
  }
95
- _context2.next = 20;
122
+ _context2.next = 21;
96
123
  break;
97
- case 14:
98
- _context2.prev = 14;
124
+ case 15:
125
+ _context2.prev = 15;
99
126
  _context2.t0 = _context2["catch"](0);
100
127
  console.error(_context2.t0);
101
128
  this.store.error = _context2.t0 instanceof Error ? _context2.t0.message : 'Failed to add account';
102
- _context2.next = 20;
129
+ _context2.next = 21;
103
130
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
104
- case 20:
105
- _context2.prev = 20;
131
+ case 21:
132
+ _context2.prev = 21;
106
133
  this.store.isLoading = false;
107
- return _context2.finish(20);
108
- case 23:
134
+ return _context2.finish(21);
135
+ case 24:
109
136
  case "end":
110
137
  return _context2.stop();
111
138
  }
112
- }, _callee2, this, [[0, 14, 20, 23]]);
139
+ }, _callee2, this, [[0, 15, 21, 24]]);
113
140
  }));
114
141
  function addAccount(_x3) {
115
142
  return _addAccount.apply(this, arguments);
@@ -134,28 +161,32 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
134
161
  }
135
162
  throw new Error("Account with id ".concat(id, " not found"));
136
163
  case 6:
137
- // Update the account module directly
138
- Object.assign(account, updates);
139
- _context3.next = 9;
164
+ account.setAccountInfo(updates);
165
+ this.store.accountList.forEach(function (account) {
166
+ if (account.id === id) {
167
+ Object.assign(account, updates);
168
+ }
169
+ });
170
+ _context3.next = 10;
140
171
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
141
- case 9:
142
- _context3.next = 16;
172
+ case 10:
173
+ _context3.next = 17;
143
174
  break;
144
- case 11:
145
- _context3.prev = 11;
175
+ case 12:
176
+ _context3.prev = 12;
146
177
  _context3.t0 = _context3["catch"](0);
147
178
  this.store.error = _context3.t0 instanceof Error ? _context3.t0.message : 'Failed to update account';
148
- _context3.next = 16;
179
+ _context3.next = 17;
149
180
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
150
- case 16:
151
- _context3.prev = 16;
181
+ case 17:
182
+ _context3.prev = 17;
152
183
  this.store.isLoading = false;
153
- return _context3.finish(16);
154
- case 19:
184
+ return _context3.finish(17);
185
+ case 20:
155
186
  case "end":
156
187
  return _context3.stop();
157
188
  }
158
- }, _callee3, this, [[0, 11, 16, 19]]);
189
+ }, _callee3, this, [[0, 12, 17, 20]]);
159
190
  }));
160
191
  function updateAccount(_x4, _x5) {
161
192
  return _updateAccount.apply(this, arguments);
@@ -184,26 +215,29 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
184
215
  case 6:
185
216
  this.store.accounts[index].destory();
186
217
  this.store.accounts = [].concat(_toConsumableArray(this.store.accounts.slice(0, index)), _toConsumableArray(this.store.accounts.slice(index + 1)));
187
- _context4.next = 10;
218
+ this.store.accountList = this.store.accountList.filter(function (account) {
219
+ return account.id !== id;
220
+ });
221
+ _context4.next = 11;
188
222
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
189
- case 10:
190
- _context4.next = 17;
223
+ case 11:
224
+ _context4.next = 18;
191
225
  break;
192
- case 12:
193
- _context4.prev = 12;
226
+ case 13:
227
+ _context4.prev = 13;
194
228
  _context4.t0 = _context4["catch"](0);
195
229
  this.store.error = _context4.t0 instanceof Error ? _context4.t0.message : 'Failed to remove account';
196
- _context4.next = 17;
230
+ _context4.next = 18;
197
231
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
198
- case 17:
199
- _context4.prev = 17;
232
+ case 18:
233
+ _context4.prev = 18;
200
234
  this.store.isLoading = false;
201
- return _context4.finish(17);
202
- case 20:
235
+ return _context4.finish(18);
236
+ case 21:
203
237
  case "end":
204
238
  return _context4.stop();
205
239
  }
206
- }, _callee4, this, [[0, 12, 17, 20]]);
240
+ }, _callee4, this, [[0, 13, 18, 21]]);
207
241
  }));
208
242
  function removeAccount(_x6) {
209
243
  return _removeAccount.apply(this, arguments);
@@ -282,6 +316,18 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
282
316
  return account.isActive();
283
317
  }) || null;
284
318
  }
319
+ }, {
320
+ key: "storeChange",
321
+ value: function storeChange() {
322
+ if (this.openCache) {
323
+ this.checkSaveCache({
324
+ cacheId: this.cacheId,
325
+ fatherModule: this.fatherModule,
326
+ store: this.store,
327
+ cacheKey: ['accounts', 'accountList']
328
+ });
329
+ }
330
+ }
285
331
  }]);
286
332
  return AccountListModule;
287
333
  }(BaseModule);
@@ -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
  }
@@ -23,6 +23,47 @@ export var BaseModule = /*#__PURE__*/function () {
23
23
  this.core.effects.offByModuleDestroy(this.name);
24
24
  this.core.unregisterModule(this);
25
25
  }
26
+
27
+ // 提供统一的缓存 module 里的数据的方法
28
+ }, {
29
+ key: "checkSaveCache",
30
+ value: function checkSaveCache(_ref) {
31
+ var _this = this;
32
+ var cacheId = _ref.cacheId,
33
+ fatherModule = _ref.fatherModule,
34
+ store = _ref.store,
35
+ cacheKey = _ref.cacheKey;
36
+ var window = this.core.getPlugin("window");
37
+ if (cacheId) {
38
+ if (fatherModule) {
39
+ var currentCacheData = window.sessionStorage.getItem(fatherModule);
40
+ var currentCacheDataObj = JSON.parse(currentCacheData || '{}');
41
+ if (!currentCacheData || !currentCacheDataObj[cacheId]) {
42
+ currentCacheDataObj = _defineProperty({}, cacheId, _defineProperty({}, this.name, {}));
43
+ }
44
+ if (!currentCacheDataObj[cacheId][this.name]) {
45
+ currentCacheDataObj[cacheId][this.name] = {};
46
+ }
47
+ cacheKey.forEach(function (key) {
48
+ currentCacheDataObj[cacheId][_this.name][key] = store === null || store === void 0 ? void 0 : store[key];
49
+ });
50
+ window.sessionStorage.setItem(fatherModule, JSON.stringify(currentCacheDataObj));
51
+ } else {
52
+ var _currentCacheData = window.sessionStorage.getItem(cacheId);
53
+ var _currentCacheDataObj2 = JSON.parse(_currentCacheData || '{}');
54
+ if (!_currentCacheDataObj2) {
55
+ _currentCacheDataObj2 = {};
56
+ }
57
+ if (!_currentCacheDataObj2[this.name]) {
58
+ _currentCacheDataObj2[this.name] = {};
59
+ }
60
+ cacheKey.forEach(function (key) {
61
+ _currentCacheDataObj2[_this.name][key] = store[key];
62
+ });
63
+ window.sessionStorage.setItem(cacheId, JSON.stringify(_currentCacheDataObj2));
64
+ }
65
+ }
66
+ }
26
67
  }]);
27
68
  return BaseModule;
28
69
  }();
@@ -11,6 +11,9 @@ export declare class CartModule extends BaseModule implements Module, CartModule
11
11
  private request;
12
12
  private window;
13
13
  private store;
14
+ private cacheId;
15
+ private openCache;
16
+ private fatherModule;
14
17
  constructor(name?: string, version?: string);
15
18
  /**
16
19
  * 初始化购物车模块
@@ -56,4 +59,5 @@ export declare class CartModule extends BaseModule implements Module, CartModule
56
59
  * 清除购物车
57
60
  */
58
61
  clear(): void;
62
+ storeChange(): void;
59
63
  }
@@ -42,6 +42,9 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
42
42
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
43
43
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
44
44
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
45
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
46
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
47
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
45
48
  return _this;
46
49
  }
47
50
 
@@ -52,31 +55,43 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
52
55
  key: "initialize",
53
56
  value: (function () {
54
57
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
58
+ var _options$initialState, _options$otherParams, _options$otherParams2;
55
59
  return _regeneratorRuntime().wrap(function _callee$(_context) {
56
60
  while (1) switch (_context.prev = _context.next) {
57
61
  case 0:
58
62
  this.core = core;
59
63
  this.store = options.store;
60
- this.store.list = [];
64
+ if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
65
+ this.store.list = options.initialState.list;
66
+ } else {
67
+ this.store.list = [];
68
+ }
69
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
70
+ this.openCache = options.otherParams.openCache;
71
+ this.cacheId = options.otherParams.cacheId;
72
+ }
73
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
74
+ this.fatherModule = options.otherParams.fatherModule;
75
+ }
61
76
 
62
77
  // 获取依赖的插件
63
78
  this.request = core.getPlugin("request");
64
79
  this.window = core.getPlugin("window");
65
80
  if (this.request) {
66
- _context.next = 7;
81
+ _context.next = 9;
67
82
  break;
68
83
  }
69
84
  throw new Error("购物车模块需要 request 插件支持");
70
- case 7:
85
+ case 9:
71
86
  if (this.window) {
72
- _context.next = 9;
87
+ _context.next = 11;
73
88
  break;
74
89
  }
75
90
  throw new Error("购物车模块需要 window 插件支持");
76
- case 9:
91
+ case 11:
77
92
  // this.store.temp = {};
78
93
  console.log("[CartModule] 初始化完成");
79
- case 10:
94
+ case 12:
80
95
  case "end":
81
96
  return _context.stop();
82
97
  }
@@ -348,6 +363,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
348
363
  value: function clear() {
349
364
  this.store.list = [];
350
365
  }
366
+ }, {
367
+ key: "storeChange",
368
+ value: function storeChange() {
369
+ if (this.openCache) {
370
+ this.checkSaveCache({
371
+ cacheId: this.cacheId,
372
+ fatherModule: this.fatherModule,
373
+ store: this.store,
374
+ cacheKey: ['list']
375
+ });
376
+ }
377
+ }
351
378
  }]);
352
379
  return CartModule;
353
380
  }(BaseModule);
@@ -6,6 +6,9 @@ export declare class DateModule extends BaseModule implements Module, DateModule
6
6
  protected defaultVersion: string;
7
7
  private store;
8
8
  private request;
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
  setDateRange(dateRange: ITime[]): void;
@@ -13,4 +16,6 @@ export declare class DateModule extends BaseModule implements Module, DateModule
13
16
  getMonthDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
14
17
  getDateList(): Promise<ITime[]>;
15
18
  getAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
19
+ clearDateRange(): void;
20
+ storeChange(): void;
16
21
  }
@@ -29,24 +29,40 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
29
29
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
30
30
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
31
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
34
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
32
35
  return _this;
33
36
  }
34
37
  _createClass(DateModule, [{
35
38
  key: "initialize",
36
39
  value: function () {
37
40
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
41
+ var _options$otherParams, _options$otherParams2;
38
42
  return _regeneratorRuntime().wrap(function _callee$(_context) {
39
43
  while (1) switch (_context.prev = _context.next) {
40
44
  case 0:
41
45
  this.core = core;
42
46
  this.store = options.store;
43
47
  this.request = this.core.getPlugin("request");
48
+ if (options.initialState) {
49
+ this.store.dateRange = options.initialState.dateRange;
50
+ this.store.dateList = options.initialState.dateList;
51
+ }
44
52
  if (this.request) {
45
- _context.next = 5;
53
+ _context.next = 6;
46
54
  break;
47
55
  }
48
56
  throw new Error("DateModule 需要 request 插件支持");
49
- case 5:
57
+ case 6:
58
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
59
+ this.openCache = options.otherParams.openCache;
60
+ this.cacheId = options.otherParams.cacheId;
61
+ }
62
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
63
+ this.fatherModule = options.otherParams.fatherModule;
64
+ }
65
+ case 8:
50
66
  case "end":
51
67
  return _context.stop();
52
68
  }
@@ -177,6 +193,23 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
177
193
  }
178
194
  return getAvailableTimeList;
179
195
  }()
196
+ }, {
197
+ key: "clearDateRange",
198
+ value: function clearDateRange() {
199
+ this.store.dateRange = [];
200
+ }
201
+ }, {
202
+ key: "storeChange",
203
+ value: function storeChange() {
204
+ if (this.openCache) {
205
+ this.checkSaveCache({
206
+ cacheId: this.cacheId,
207
+ fatherModule: this.fatherModule,
208
+ store: this.store,
209
+ cacheKey: ['dateRange', 'dateList']
210
+ });
211
+ }
212
+ }
180
213
  }]);
181
214
  return DateModule;
182
215
  }(BaseModule);
@@ -7,6 +7,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
7
7
  private request;
8
8
  private window;
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
  setDiscountList(discountList: Discount[]): Promise<void>;
@@ -23,4 +26,5 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
23
26
  calcDiscountApplicableProductTotalPrice(discount: Discount): number;
24
27
  destroy(): Promise<void>;
25
28
  clear(): Promise<void>;
29
+ storeChange(): void;
26
30
  }
@@ -30,33 +30,49 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
30
30
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
31
31
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
32
32
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
35
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
33
36
  return _this;
34
37
  }
35
38
  _createClass(DiscountModule, [{
36
39
  key: "initialize",
37
40
  value: function () {
38
41
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
42
+ var _options$initialState, _options$otherParams, _options$otherParams2;
39
43
  return _regeneratorRuntime().wrap(function _callee$(_context) {
40
44
  while (1) switch (_context.prev = _context.next) {
41
45
  case 0:
42
46
  this.core = core;
43
47
  this.store = options === null || options === void 0 ? void 0 : options.store;
48
+ if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.discountList)) {
49
+ this.store.discountList = options === null || options === void 0 ? void 0 : options.initialState.discountList;
50
+ } else {
51
+ this.store.discountList = [];
52
+ }
53
+ if (options !== null && options !== void 0 && (_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
54
+ this.openCache = options.otherParams.openCache;
55
+ this.cacheId = options.otherParams.cacheId;
56
+ }
57
+ if (options !== null && options !== void 0 && (_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
58
+ this.fatherModule = options.otherParams.fatherModule;
59
+ }
44
60
 
45
61
  // 获取依赖的插件
46
62
  this.request = core.getPlugin("request");
47
63
  this.window = core.getPlugin("window");
48
64
  if (this.request) {
49
- _context.next = 6;
65
+ _context.next = 9;
50
66
  break;
51
67
  }
52
68
  throw new Error("discount模块需要 request 插件支持");
53
- case 6:
69
+ case 9:
54
70
  if (this.window) {
55
- _context.next = 8;
71
+ _context.next = 11;
56
72
  break;
57
73
  }
58
74
  throw new Error("discount模块需要 window 插件支持");
59
- case 8:
75
+ case 11:
60
76
  case "end":
61
77
  return _context.stop();
62
78
  }
@@ -229,6 +245,18 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
229
245
  }
230
246
  return clear;
231
247
  }()
248
+ }, {
249
+ key: "storeChange",
250
+ value: function storeChange() {
251
+ if (this.openCache) {
252
+ this.checkSaveCache({
253
+ cacheId: this.cacheId,
254
+ fatherModule: this.fatherModule,
255
+ store: this.store,
256
+ cacheKey: ['discountList']
257
+ });
258
+ }
259
+ }
232
260
  }]);
233
261
  return DiscountModule;
234
262
  }(BaseModule);
@@ -47,6 +47,9 @@ export interface Discount {
47
47
  resource_id?: number;
48
48
  savedAmount?: number;
49
49
  isEditMode?: boolean;
50
+ discount?: {
51
+ resource_id: number;
52
+ };
50
53
  isManualSelect?: boolean;
51
54
  isDisabled?: boolean;
52
55
  isSelected?: boolean;
@@ -125,7 +125,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
125
125
  if (discount_list && discount_list.length > 0) {
126
126
  // 检查是否有使用新折扣的情况
127
127
  var usedNewDiscount = discount_list.some(function (discount) {
128
- return newDiscountIds.includes(discount.resource_id);
128
+ var _discount$discount;
129
+ return newDiscountIds.includes(discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id);
129
130
  });
130
131
  if (usedNewDiscount) {
131
132
  hasApplicableDiscount = true;
@@ -217,9 +218,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
217
218
  applicableProducts.push({
218
219
  amount: product.price,
219
220
  type: discount.tag,
220
- resource_id: discount.id,
221
- title: discount.format_title,
222
- original_amount: product.origin_total
221
+ discount: {
222
+ resource_id: discount.id,
223
+ title: discount.format_title,
224
+ original_amount: product.origin_total
225
+ }
223
226
  });
224
227
  discountApplicableProducts.set(discount.id, applicableProducts);
225
228
  }
@@ -5,6 +5,9 @@ export declare class StepModule extends BaseModule implements Module, IStepModul
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
7
  private store;
8
+ private cacheId;
9
+ private openCache;
10
+ private fatherModule;
8
11
  constructor(name?: string, version?: string);
9
12
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
10
13
  init(steps: IStep[]): void;
@@ -16,4 +19,5 @@ export declare class StepModule extends BaseModule implements Module, IStepModul
16
19
  prevStep(): void;
17
20
  nextStep(): void;
18
21
  gotoStep(stepIndex: number): void;
22
+ storeChange(): void;
19
23
  }