@pisell/pisellos 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/AccountList/index.d.ts +5 -1
- package/dist/modules/AccountList/index.js +92 -39
- package/dist/modules/AccountList/types.d.ts +1 -0
- package/dist/modules/BaseModule.d.ts +6 -0
- package/dist/modules/BaseModule.js +41 -0
- package/dist/modules/Cart/index.d.ts +8 -0
- package/dist/modules/Cart/index.js +45 -6
- package/dist/modules/Cart/utils.js +14 -0
- package/dist/modules/Date/index.d.ts +5 -0
- package/dist/modules/Date/index.js +35 -2
- package/dist/modules/Discount/index.d.ts +4 -0
- package/dist/modules/Discount/index.js +32 -4
- package/dist/modules/Discount/types.d.ts +3 -0
- package/dist/modules/Rules/index.js +8 -5
- package/dist/modules/Step/index.d.ts +4 -0
- package/dist/modules/Step/index.js +29 -1
- package/dist/modules/Summary/index.d.ts +4 -0
- package/dist/modules/Summary/index.js +28 -2
- package/dist/solution/BookingByStep/index.d.ts +13 -2
- package/dist/solution/BookingByStep/index.js +194 -117
- package/dist/solution/BookingByStep/types.js +0 -3
- package/dist/solution/ShopDiscount/index.js +24 -3
- package/lib/modules/AccountList/index.d.ts +5 -1
- package/lib/modules/AccountList/index.js +34 -1
- package/lib/modules/AccountList/types.d.ts +1 -0
- package/lib/modules/BaseModule.d.ts +6 -0
- package/lib/modules/BaseModule.js +37 -0
- package/lib/modules/Cart/index.d.ts +8 -0
- package/lib/modules/Cart/index.js +26 -1
- package/lib/modules/Cart/utils.js +14 -0
- package/lib/modules/Date/index.d.ts +5 -0
- package/lib/modules/Date/index.js +21 -0
- package/lib/modules/Discount/index.d.ts +4 -0
- package/lib/modules/Discount/index.js +19 -0
- package/lib/modules/Discount/types.d.ts +3 -0
- package/lib/modules/Rules/index.js +10 -5
- package/lib/modules/Step/index.d.ts +4 -0
- package/lib/modules/Step/index.js +19 -0
- package/lib/modules/Summary/index.d.ts +4 -0
- package/lib/modules/Summary/index.js +17 -0
- package/lib/solution/BookingByStep/index.d.ts +13 -2
- package/lib/solution/BookingByStep/index.js +74 -7
- package/lib/solution/BookingByStep/types.js +0 -3
- package/lib/solution/ShopDiscount/index.js +21 -3
- 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:
|
|
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,50 @@ 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
|
-
|
|
66
|
+
this.store.accountList = [];
|
|
67
|
+
if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.accountList)) {
|
|
68
|
+
recordList = options.initialState.accountList || [];
|
|
69
|
+
recordList.forEach(function (account) {
|
|
70
|
+
_this2.addAccount(account);
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
this.store.accountList = [];
|
|
74
|
+
}
|
|
75
|
+
if (options !== null && options !== void 0 && (_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
|
|
76
|
+
this.openCache = options.otherParams.openCache;
|
|
77
|
+
this.cacheId = options.otherParams.cacheId;
|
|
78
|
+
}
|
|
79
|
+
if (options !== null && options !== void 0 && (_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
|
|
80
|
+
this.fatherModule = options.otherParams.fatherModule;
|
|
81
|
+
}
|
|
82
|
+
case 7:
|
|
56
83
|
case "end":
|
|
57
84
|
return _context.stop();
|
|
58
85
|
}
|
|
@@ -77,39 +104,40 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
77
104
|
if (!this.store.accounts.some(function (a) {
|
|
78
105
|
return a.getId() === account.id;
|
|
79
106
|
})) {
|
|
80
|
-
_context2.next =
|
|
107
|
+
_context2.next = 6;
|
|
81
108
|
break;
|
|
82
109
|
}
|
|
83
110
|
throw new Error("Account with id ".concat(account.id, " already exists"));
|
|
84
|
-
case
|
|
111
|
+
case 6:
|
|
112
|
+
this.store.accountList.push(account);
|
|
85
113
|
accountModule = new AccountModule("account_".concat(account.id));
|
|
86
114
|
this.core.registerModule(accountModule);
|
|
87
115
|
accountModule.setAccountInfo(account);
|
|
88
116
|
this.store.accounts = [].concat(_toConsumableArray(this.store.accounts), [accountModule]);
|
|
89
|
-
_context2.next =
|
|
117
|
+
_context2.next = 13;
|
|
90
118
|
return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
|
|
91
|
-
case
|
|
119
|
+
case 13:
|
|
92
120
|
if (this.store.accounts.length === 1) {
|
|
93
121
|
this.setActiveAccount(accountModule.getId());
|
|
94
122
|
}
|
|
95
|
-
_context2.next =
|
|
123
|
+
_context2.next = 22;
|
|
96
124
|
break;
|
|
97
|
-
case
|
|
98
|
-
_context2.prev =
|
|
125
|
+
case 16:
|
|
126
|
+
_context2.prev = 16;
|
|
99
127
|
_context2.t0 = _context2["catch"](0);
|
|
100
128
|
console.error(_context2.t0);
|
|
101
129
|
this.store.error = _context2.t0 instanceof Error ? _context2.t0.message : 'Failed to add account';
|
|
102
|
-
_context2.next =
|
|
130
|
+
_context2.next = 22;
|
|
103
131
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
104
|
-
case
|
|
105
|
-
_context2.prev =
|
|
132
|
+
case 22:
|
|
133
|
+
_context2.prev = 22;
|
|
106
134
|
this.store.isLoading = false;
|
|
107
|
-
return _context2.finish(
|
|
108
|
-
case
|
|
135
|
+
return _context2.finish(22);
|
|
136
|
+
case 25:
|
|
109
137
|
case "end":
|
|
110
138
|
return _context2.stop();
|
|
111
139
|
}
|
|
112
|
-
}, _callee2, this, [[0,
|
|
140
|
+
}, _callee2, this, [[0, 16, 22, 25]]);
|
|
113
141
|
}));
|
|
114
142
|
function addAccount(_x3) {
|
|
115
143
|
return _addAccount.apply(this, arguments);
|
|
@@ -120,7 +148,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
120
148
|
key: "updateAccount",
|
|
121
149
|
value: function () {
|
|
122
150
|
var _updateAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(id, updates) {
|
|
123
|
-
var account;
|
|
151
|
+
var account, index;
|
|
124
152
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
125
153
|
while (1) switch (_context3.prev = _context3.next) {
|
|
126
154
|
case 0:
|
|
@@ -134,28 +162,38 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
134
162
|
}
|
|
135
163
|
throw new Error("Account with id ".concat(id, " not found"));
|
|
136
164
|
case 6:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
165
|
+
account.setAccountInfo(updates);
|
|
166
|
+
// this.store.accountList.forEach(account => {
|
|
167
|
+
// if (account.id === id) {
|
|
168
|
+
// Object.assign(account, updates)
|
|
169
|
+
// }
|
|
170
|
+
// })
|
|
171
|
+
index = this.store.accountList.findIndex(function (account) {
|
|
172
|
+
return account.id === id;
|
|
173
|
+
});
|
|
174
|
+
if (index !== -1) {
|
|
175
|
+
this.store.accountList[index] = updates;
|
|
176
|
+
}
|
|
177
|
+
_context3.next = 11;
|
|
140
178
|
return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
|
|
141
|
-
case 9:
|
|
142
|
-
_context3.next = 16;
|
|
143
|
-
break;
|
|
144
179
|
case 11:
|
|
145
|
-
_context3.
|
|
180
|
+
_context3.next = 18;
|
|
181
|
+
break;
|
|
182
|
+
case 13:
|
|
183
|
+
_context3.prev = 13;
|
|
146
184
|
_context3.t0 = _context3["catch"](0);
|
|
147
185
|
this.store.error = _context3.t0 instanceof Error ? _context3.t0.message : 'Failed to update account';
|
|
148
|
-
_context3.next =
|
|
186
|
+
_context3.next = 18;
|
|
149
187
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
150
|
-
case
|
|
151
|
-
_context3.prev =
|
|
188
|
+
case 18:
|
|
189
|
+
_context3.prev = 18;
|
|
152
190
|
this.store.isLoading = false;
|
|
153
|
-
return _context3.finish(
|
|
154
|
-
case
|
|
191
|
+
return _context3.finish(18);
|
|
192
|
+
case 21:
|
|
155
193
|
case "end":
|
|
156
194
|
return _context3.stop();
|
|
157
195
|
}
|
|
158
|
-
}, _callee3, this, [[0,
|
|
196
|
+
}, _callee3, this, [[0, 13, 18, 21]]);
|
|
159
197
|
}));
|
|
160
198
|
function updateAccount(_x4, _x5) {
|
|
161
199
|
return _updateAccount.apply(this, arguments);
|
|
@@ -184,26 +222,29 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
184
222
|
case 6:
|
|
185
223
|
this.store.accounts[index].destory();
|
|
186
224
|
this.store.accounts = [].concat(_toConsumableArray(this.store.accounts.slice(0, index)), _toConsumableArray(this.store.accounts.slice(index + 1)));
|
|
187
|
-
|
|
225
|
+
this.store.accountList = this.store.accountList.filter(function (account) {
|
|
226
|
+
return account.id !== id;
|
|
227
|
+
});
|
|
228
|
+
_context4.next = 11;
|
|
188
229
|
return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
|
|
189
|
-
case
|
|
190
|
-
_context4.next =
|
|
230
|
+
case 11:
|
|
231
|
+
_context4.next = 18;
|
|
191
232
|
break;
|
|
192
|
-
case
|
|
193
|
-
_context4.prev =
|
|
233
|
+
case 13:
|
|
234
|
+
_context4.prev = 13;
|
|
194
235
|
_context4.t0 = _context4["catch"](0);
|
|
195
236
|
this.store.error = _context4.t0 instanceof Error ? _context4.t0.message : 'Failed to remove account';
|
|
196
|
-
_context4.next =
|
|
237
|
+
_context4.next = 18;
|
|
197
238
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
198
|
-
case
|
|
199
|
-
_context4.prev =
|
|
239
|
+
case 18:
|
|
240
|
+
_context4.prev = 18;
|
|
200
241
|
this.store.isLoading = false;
|
|
201
|
-
return _context4.finish(
|
|
202
|
-
case
|
|
242
|
+
return _context4.finish(18);
|
|
243
|
+
case 21:
|
|
203
244
|
case "end":
|
|
204
245
|
return _context4.stop();
|
|
205
246
|
}
|
|
206
|
-
}, _callee4, this, [[0,
|
|
247
|
+
}, _callee4, this, [[0, 13, 18, 21]]);
|
|
207
248
|
}));
|
|
208
249
|
function removeAccount(_x6) {
|
|
209
250
|
return _removeAccount.apply(this, arguments);
|
|
@@ -282,6 +323,18 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
282
323
|
return account.isActive();
|
|
283
324
|
}) || null;
|
|
284
325
|
}
|
|
326
|
+
}, {
|
|
327
|
+
key: "storeChange",
|
|
328
|
+
value: function storeChange() {
|
|
329
|
+
if (this.openCache) {
|
|
330
|
+
this.checkSaveCache({
|
|
331
|
+
cacheId: this.cacheId,
|
|
332
|
+
fatherModule: this.fatherModule,
|
|
333
|
+
store: this.store,
|
|
334
|
+
cacheKey: ['accounts', 'accountList']
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
285
338
|
}]);
|
|
286
339
|
return AccountListModule;
|
|
287
340
|
}(BaseModule);
|
|
@@ -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
|
* 初始化购物车模块
|
|
@@ -36,6 +39,10 @@ export declare class CartModule extends BaseModule implements Module, CartModule
|
|
|
36
39
|
* 获取购物车商品
|
|
37
40
|
*/
|
|
38
41
|
getItems(): CartItem[];
|
|
42
|
+
/**
|
|
43
|
+
* 获取购物车商品--通过购物车 id 获取单条
|
|
44
|
+
*/
|
|
45
|
+
getItem(id: string): CartItem | undefined;
|
|
39
46
|
/**
|
|
40
47
|
* 根据账户ID获取购物车
|
|
41
48
|
*/
|
|
@@ -56,4 +63,5 @@ export declare class CartModule extends BaseModule implements Module, CartModule
|
|
|
56
63
|
* 清除购物车
|
|
57
64
|
*/
|
|
58
65
|
clear(): void;
|
|
66
|
+
storeChange(): void;
|
|
59
67
|
}
|
|
@@ -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,44 @@ 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
|
-
|
|
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
|
+
this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
|
|
67
|
+
} else {
|
|
68
|
+
this.store.list = [];
|
|
69
|
+
}
|
|
70
|
+
if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
|
|
71
|
+
this.openCache = options.otherParams.openCache;
|
|
72
|
+
this.cacheId = options.otherParams.cacheId;
|
|
73
|
+
}
|
|
74
|
+
if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
|
|
75
|
+
this.fatherModule = options.otherParams.fatherModule;
|
|
76
|
+
}
|
|
61
77
|
|
|
62
78
|
// 获取依赖的插件
|
|
63
79
|
this.request = core.getPlugin("request");
|
|
64
80
|
this.window = core.getPlugin("window");
|
|
65
81
|
if (this.request) {
|
|
66
|
-
_context.next =
|
|
82
|
+
_context.next = 9;
|
|
67
83
|
break;
|
|
68
84
|
}
|
|
69
85
|
throw new Error("购物车模块需要 request 插件支持");
|
|
70
|
-
case
|
|
86
|
+
case 9:
|
|
71
87
|
if (this.window) {
|
|
72
|
-
_context.next =
|
|
88
|
+
_context.next = 11;
|
|
73
89
|
break;
|
|
74
90
|
}
|
|
75
91
|
throw new Error("购物车模块需要 window 插件支持");
|
|
76
|
-
case
|
|
92
|
+
case 11:
|
|
77
93
|
// this.store.temp = {};
|
|
78
94
|
console.log("[CartModule] 初始化完成");
|
|
79
|
-
case
|
|
95
|
+
case 12:
|
|
80
96
|
case "end":
|
|
81
97
|
return _context.stop();
|
|
82
98
|
}
|
|
@@ -269,6 +285,17 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
269
285
|
return this.store.list;
|
|
270
286
|
}
|
|
271
287
|
|
|
288
|
+
/**
|
|
289
|
+
* 获取购物车商品--通过购物车 id 获取单条
|
|
290
|
+
*/
|
|
291
|
+
}, {
|
|
292
|
+
key: "getItem",
|
|
293
|
+
value: function getItem(id) {
|
|
294
|
+
return this.store.list.find(function (item) {
|
|
295
|
+
return item._id === id;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
272
299
|
/**
|
|
273
300
|
* 根据账户ID获取购物车
|
|
274
301
|
*/
|
|
@@ -348,6 +375,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
348
375
|
value: function clear() {
|
|
349
376
|
this.store.list = [];
|
|
350
377
|
}
|
|
378
|
+
}, {
|
|
379
|
+
key: "storeChange",
|
|
380
|
+
value: function storeChange() {
|
|
381
|
+
if (this.openCache) {
|
|
382
|
+
this.checkSaveCache({
|
|
383
|
+
cacheId: this.cacheId,
|
|
384
|
+
fatherModule: this.fatherModule,
|
|
385
|
+
store: this.store,
|
|
386
|
+
cacheKey: ['list']
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
351
390
|
}]);
|
|
352
391
|
return CartModule;
|
|
353
392
|
}(BaseModule);
|
|
@@ -206,6 +206,13 @@ export var formatResourceToCartItem = function formatResourceToCartItem(params)
|
|
|
206
206
|
cartItem.end_date = dayjs(firstResource.endTime).format("YYYY-MM-DD");
|
|
207
207
|
cartItem.end_time = dayjs(firstResource.endTime).format("HH:mm");
|
|
208
208
|
}
|
|
209
|
+
} else {
|
|
210
|
+
cartItem.resource_id = undefined;
|
|
211
|
+
cartItem.relation_form_name = undefined;
|
|
212
|
+
cartItem.start_date = undefined;
|
|
213
|
+
cartItem.start_time = undefined;
|
|
214
|
+
cartItem.end_date = undefined;
|
|
215
|
+
cartItem.end_time = undefined;
|
|
209
216
|
}
|
|
210
217
|
var oringin = formatResourceToCartItemOrigin(params);
|
|
211
218
|
cartItem._origin = oringin;
|
|
@@ -241,6 +248,13 @@ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOri
|
|
|
241
248
|
origin.end_date = dayjs(endTime).format("YYYY-MM-DD");
|
|
242
249
|
origin.end_time = dayjs(endTime).format("HH:mm");
|
|
243
250
|
}
|
|
251
|
+
} else if ((resources === null || resources === void 0 ? void 0 : resources.length) === 0) {
|
|
252
|
+
origin.resources = [];
|
|
253
|
+
origin.select_date = null;
|
|
254
|
+
origin.start_date = null;
|
|
255
|
+
origin.start_time = null;
|
|
256
|
+
origin.end_date = null;
|
|
257
|
+
origin.end_time = null;
|
|
244
258
|
}
|
|
245
259
|
return origin;
|
|
246
260
|
};
|
|
@@ -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 =
|
|
53
|
+
_context.next = 6;
|
|
46
54
|
break;
|
|
47
55
|
}
|
|
48
56
|
throw new Error("DateModule 需要 request 插件支持");
|
|
49
|
-
case
|
|
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 =
|
|
65
|
+
_context.next = 9;
|
|
50
66
|
break;
|
|
51
67
|
}
|
|
52
68
|
throw new Error("discount模块需要 request 插件支持");
|
|
53
|
-
case
|
|
69
|
+
case 9:
|
|
54
70
|
if (this.window) {
|
|
55
|
-
_context.next =
|
|
71
|
+
_context.next = 11;
|
|
56
72
|
break;
|
|
57
73
|
}
|
|
58
74
|
throw new Error("discount模块需要 window 插件支持");
|
|
59
|
-
case
|
|
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);
|