@pisell/pisellos 0.0.14 → 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.
- package/dist/modules/AccountList/index.d.ts +5 -1
- package/dist/modules/AccountList/index.js +82 -36
- 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 +10 -2
- package/dist/modules/Cart/index.js +71 -34
- package/dist/modules/Cart/types.d.ts +2 -2
- package/dist/modules/Cart/utils.d.ts +12 -0
- package/dist/modules/Cart/utils.js +49 -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 +7 -4
- 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/modules/Summary/utils.js +4 -5
- package/dist/solution/BookingByStep/index.d.ts +23 -4
- package/dist/solution/BookingByStep/index.js +152 -31
- 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 +33 -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 +10 -2
- package/lib/modules/Cart/index.js +42 -14
- package/lib/modules/Cart/types.d.ts +2 -2
- package/lib/modules/Cart/utils.d.ts +12 -0
- package/lib/modules/Cart/utils.js +33 -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 +9 -4
- 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/modules/Summary/utils.js +4 -5
- package/lib/solution/BookingByStep/index.d.ts +23 -4
- package/lib/solution/BookingByStep/index.js +82 -21
- 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,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
|
-
|
|
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 =
|
|
116
|
+
_context2.next = 12;
|
|
90
117
|
return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
|
|
91
|
-
case
|
|
118
|
+
case 12:
|
|
92
119
|
if (this.store.accounts.length === 1) {
|
|
93
120
|
this.setActiveAccount(accountModule.getId());
|
|
94
121
|
}
|
|
95
|
-
_context2.next =
|
|
122
|
+
_context2.next = 21;
|
|
96
123
|
break;
|
|
97
|
-
case
|
|
98
|
-
_context2.prev =
|
|
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 =
|
|
129
|
+
_context2.next = 21;
|
|
103
130
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
104
|
-
case
|
|
105
|
-
_context2.prev =
|
|
131
|
+
case 21:
|
|
132
|
+
_context2.prev = 21;
|
|
106
133
|
this.store.isLoading = false;
|
|
107
|
-
return _context2.finish(
|
|
108
|
-
case
|
|
134
|
+
return _context2.finish(21);
|
|
135
|
+
case 24:
|
|
109
136
|
case "end":
|
|
110
137
|
return _context2.stop();
|
|
111
138
|
}
|
|
112
|
-
}, _callee2, this, [[0,
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|
142
|
-
_context3.next =
|
|
172
|
+
case 10:
|
|
173
|
+
_context3.next = 17;
|
|
143
174
|
break;
|
|
144
|
-
case
|
|
145
|
-
_context3.prev =
|
|
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 =
|
|
179
|
+
_context3.next = 17;
|
|
149
180
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
150
|
-
case
|
|
151
|
-
_context3.prev =
|
|
181
|
+
case 17:
|
|
182
|
+
_context3.prev = 17;
|
|
152
183
|
this.store.isLoading = false;
|
|
153
|
-
return _context3.finish(
|
|
154
|
-
case
|
|
184
|
+
return _context3.finish(17);
|
|
185
|
+
case 20:
|
|
155
186
|
case "end":
|
|
156
187
|
return _context3.stop();
|
|
157
188
|
}
|
|
158
|
-
}, _callee3, this, [[0,
|
|
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
|
-
|
|
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
|
|
190
|
-
_context4.next =
|
|
223
|
+
case 11:
|
|
224
|
+
_context4.next = 18;
|
|
191
225
|
break;
|
|
192
|
-
case
|
|
193
|
-
_context4.prev =
|
|
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 =
|
|
230
|
+
_context4.next = 18;
|
|
197
231
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
198
|
-
case
|
|
199
|
-
_context4.prev =
|
|
232
|
+
case 18:
|
|
233
|
+
_context4.prev = 18;
|
|
200
234
|
this.store.isLoading = false;
|
|
201
|
-
return _context4.finish(
|
|
202
|
-
case
|
|
235
|
+
return _context4.finish(18);
|
|
236
|
+
case 21:
|
|
203
237
|
case "end":
|
|
204
238
|
return _context4.stop();
|
|
205
239
|
}
|
|
206
|
-
}, _callee4, this, [[0,
|
|
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);
|
|
@@ -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
|
+
getCartByAccount(account_id: string | number): CartItem[];
|
|
39
46
|
/**
|
|
40
47
|
* 移除购物车商品
|
|
41
48
|
*/
|
|
@@ -45,11 +52,12 @@ export declare class CartModule extends BaseModule implements Module, CartModule
|
|
|
45
52
|
*/
|
|
46
53
|
clearCartByAccount(account_id: string): void;
|
|
47
54
|
/**
|
|
48
|
-
*
|
|
55
|
+
* 清除购物车商品中的信息
|
|
49
56
|
*/
|
|
50
|
-
|
|
57
|
+
deleteCartItemInfo(types: "resource" | "time"): void;
|
|
51
58
|
/**
|
|
52
59
|
* 清除购物车
|
|
53
60
|
*/
|
|
54
61
|
clear(): void;
|
|
62
|
+
storeChange(): void;
|
|
55
63
|
}
|
|
@@ -22,8 +22,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
22
22
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
23
23
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
24
|
import { BaseModule } from "../BaseModule";
|
|
25
|
-
import {
|
|
26
|
-
import { createCartItemOrigin, formatAccountToCartItem, formatDiscountToCartItem, formatNoteToCartItem, formatProductToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
|
|
25
|
+
import { createCartItemOrigin, deleteResourceFromCartItem, deleteTimeFromCartItem, formatAccountToCartItem, formatDiscountToCartItem, formatNoteToCartItem, formatProductToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
|
|
27
26
|
import { cloneDeep } from "lodash-es";
|
|
28
27
|
export * from "./types";
|
|
29
28
|
|
|
@@ -43,6 +42,9 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
43
42
|
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
44
43
|
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
45
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);
|
|
46
48
|
return _this;
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -53,31 +55,43 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
53
55
|
key: "initialize",
|
|
54
56
|
value: (function () {
|
|
55
57
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
58
|
+
var _options$initialState, _options$otherParams, _options$otherParams2;
|
|
56
59
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
57
60
|
while (1) switch (_context.prev = _context.next) {
|
|
58
61
|
case 0:
|
|
59
62
|
this.core = core;
|
|
60
63
|
this.store = options.store;
|
|
61
|
-
|
|
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
|
+
}
|
|
62
76
|
|
|
63
77
|
// 获取依赖的插件
|
|
64
78
|
this.request = core.getPlugin("request");
|
|
65
79
|
this.window = core.getPlugin("window");
|
|
66
80
|
if (this.request) {
|
|
67
|
-
_context.next =
|
|
81
|
+
_context.next = 9;
|
|
68
82
|
break;
|
|
69
83
|
}
|
|
70
84
|
throw new Error("购物车模块需要 request 插件支持");
|
|
71
|
-
case
|
|
85
|
+
case 9:
|
|
72
86
|
if (this.window) {
|
|
73
|
-
_context.next =
|
|
87
|
+
_context.next = 11;
|
|
74
88
|
break;
|
|
75
89
|
}
|
|
76
90
|
throw new Error("购物车模块需要 window 插件支持");
|
|
77
|
-
case 9:
|
|
78
|
-
this.store.temp = {};
|
|
79
|
-
console.log("[CartModule] 初始化完成");
|
|
80
91
|
case 11:
|
|
92
|
+
// this.store.temp = {};
|
|
93
|
+
console.log("[CartModule] 初始化完成");
|
|
94
|
+
case 12:
|
|
81
95
|
case "end":
|
|
82
96
|
return _context.stop();
|
|
83
97
|
}
|
|
@@ -127,11 +141,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
127
141
|
|
|
128
142
|
// 触发事件
|
|
129
143
|
_context2.next = 8;
|
|
130
|
-
return this.core.effects.emit(
|
|
144
|
+
return this.core.effects.emit("".concat(this.name, ":onAddItem"), cartItem);
|
|
131
145
|
case 8:
|
|
132
|
-
_context2.next = 10;
|
|
133
|
-
return this.core.effects.emit("".concat(this.name, ":changed"), items);
|
|
134
|
-
case 10:
|
|
135
146
|
case "end":
|
|
136
147
|
return _context2.stop();
|
|
137
148
|
}
|
|
@@ -165,22 +176,19 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
165
176
|
this.store.list = _toConsumableArray(items);
|
|
166
177
|
// 触发事件
|
|
167
178
|
_context3.next = 6;
|
|
168
|
-
return this.core.effects.emit(
|
|
179
|
+
return this.core.effects.emit("".concat(this.name, ":onUpdateItem"), tempCartItem);
|
|
169
180
|
case 6:
|
|
170
|
-
_context3.next =
|
|
171
|
-
return this.core.effects.emit("".concat(this.name, ":changed"), items);
|
|
172
|
-
case 8:
|
|
173
|
-
_context3.next = 13;
|
|
181
|
+
_context3.next = 11;
|
|
174
182
|
break;
|
|
175
|
-
case
|
|
176
|
-
_context3.prev =
|
|
183
|
+
case 8:
|
|
184
|
+
_context3.prev = 8;
|
|
177
185
|
_context3.t0 = _context3["catch"](0);
|
|
178
186
|
console.error("[CartModule] 更新购物车商品失败", _context3.t0);
|
|
179
|
-
case
|
|
187
|
+
case 11:
|
|
180
188
|
case "end":
|
|
181
189
|
return _context3.stop();
|
|
182
190
|
}
|
|
183
|
-
}, _callee3, this, [[0,
|
|
191
|
+
}, _callee3, this, [[0, 8]]);
|
|
184
192
|
}));
|
|
185
193
|
function updateItem(_x4) {
|
|
186
194
|
return _updateItem.apply(this, arguments);
|
|
@@ -254,11 +262,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
254
262
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
255
263
|
while (1) switch (_context4.prev = _context4.next) {
|
|
256
264
|
case 0:
|
|
257
|
-
this.store.list = items || [];
|
|
258
|
-
|
|
259
|
-
_context4.next = 3;
|
|
260
|
-
return this.core.effects.emit("".concat(this.name, ":changed"), items);
|
|
261
|
-
case 3:
|
|
265
|
+
this.store.list = _toConsumableArray(items || []);
|
|
266
|
+
case 1:
|
|
262
267
|
case "end":
|
|
263
268
|
return _context4.stop();
|
|
264
269
|
}
|
|
@@ -279,6 +284,17 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
279
284
|
return this.store.list;
|
|
280
285
|
}
|
|
281
286
|
|
|
287
|
+
/**
|
|
288
|
+
* 根据账户ID获取购物车
|
|
289
|
+
*/
|
|
290
|
+
}, {
|
|
291
|
+
key: "getCartByAccount",
|
|
292
|
+
value: function getCartByAccount(account_id) {
|
|
293
|
+
return this.store.list.filter(function (item) {
|
|
294
|
+
return item.holder_id === account_id;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
282
298
|
/**
|
|
283
299
|
* 移除购物车商品
|
|
284
300
|
*/
|
|
@@ -295,7 +311,7 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
295
311
|
});
|
|
296
312
|
this.store.list = items;
|
|
297
313
|
_context5.next = 4;
|
|
298
|
-
return this.core.effects.emit(
|
|
314
|
+
return this.core.effects.emit("".concat(this.name, ":onRemoveItem"), items);
|
|
299
315
|
case 4:
|
|
300
316
|
case "end":
|
|
301
317
|
return _context5.stop();
|
|
@@ -314,20 +330,29 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
314
330
|
}, {
|
|
315
331
|
key: "clearCartByAccount",
|
|
316
332
|
value: function clearCartByAccount(account_id) {
|
|
317
|
-
|
|
333
|
+
var items = this.store.list.filter(function (item) {
|
|
318
334
|
return item.holder_id !== account_id;
|
|
319
335
|
});
|
|
336
|
+
this.store.list = _toConsumableArray(items || []);
|
|
320
337
|
}
|
|
321
338
|
|
|
322
339
|
/**
|
|
323
|
-
*
|
|
340
|
+
* 清除购物车商品中的信息
|
|
324
341
|
*/
|
|
325
342
|
}, {
|
|
326
|
-
key: "
|
|
327
|
-
value: function
|
|
328
|
-
|
|
329
|
-
|
|
343
|
+
key: "deleteCartItemInfo",
|
|
344
|
+
value: function deleteCartItemInfo(types) {
|
|
345
|
+
var list = this.store.list.map(function (item) {
|
|
346
|
+
// 清除购物车商品中的资源信息
|
|
347
|
+
if (types === "resource") {
|
|
348
|
+
item = deleteResourceFromCartItem(item);
|
|
349
|
+
} else if (types === "time") {
|
|
350
|
+
// 清除购物车商品中的时间信息
|
|
351
|
+
item = deleteTimeFromCartItem(item);
|
|
352
|
+
}
|
|
353
|
+
return item;
|
|
330
354
|
});
|
|
355
|
+
this.store.list = _toConsumableArray(list);
|
|
331
356
|
}
|
|
332
357
|
|
|
333
358
|
/**
|
|
@@ -338,6 +363,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
338
363
|
value: function clear() {
|
|
339
364
|
this.store.list = [];
|
|
340
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
|
+
}
|
|
341
378
|
}]);
|
|
342
379
|
return CartModule;
|
|
343
380
|
}(BaseModule);
|
|
@@ -88,14 +88,14 @@ export interface CartItem {
|
|
|
88
88
|
_origin: any;
|
|
89
89
|
/** 商品原始数据 */
|
|
90
90
|
_productOrigin?: ProductData;
|
|
91
|
+
/** 资源原始数据 */
|
|
92
|
+
_resourceOrigin?: Resource[];
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
95
|
* 购物车状态接口
|
|
94
96
|
*/
|
|
95
97
|
export interface CartState {
|
|
96
98
|
list: CartItem[];
|
|
97
|
-
total: number;
|
|
98
|
-
temp: Record<string, any>;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* 添加商品到购物车参数
|
|
@@ -90,6 +90,18 @@ export declare const formatResourceToCartItemOrigin: (params: {
|
|
|
90
90
|
cartItem: CartItem;
|
|
91
91
|
resources: Resource[];
|
|
92
92
|
}) => any;
|
|
93
|
+
/**
|
|
94
|
+
* 从购物车中删除资源相关信息
|
|
95
|
+
* @param cartItem 购物车
|
|
96
|
+
* @returns 删除后的购物车
|
|
97
|
+
*/
|
|
98
|
+
export declare const deleteResourceFromCartItem: (cartItem: CartItem) => CartItem;
|
|
99
|
+
/**
|
|
100
|
+
* 从购物车中删除时间
|
|
101
|
+
* @param cartItem 购物车
|
|
102
|
+
* @returns 删除后的购物车
|
|
103
|
+
*/
|
|
104
|
+
export declare const deleteTimeFromCartItem: (cartItem: CartItem) => CartItem;
|
|
93
105
|
/**
|
|
94
106
|
* 格式化备注到购物车
|
|
95
107
|
* @param params 参数
|
|
@@ -209,6 +209,7 @@ export var formatResourceToCartItem = function formatResourceToCartItem(params)
|
|
|
209
209
|
}
|
|
210
210
|
var oringin = formatResourceToCartItemOrigin(params);
|
|
211
211
|
cartItem._origin = oringin;
|
|
212
|
+
cartItem._resourceOrigin = resources;
|
|
212
213
|
return cartItem;
|
|
213
214
|
};
|
|
214
215
|
export var formatResourceToCartItemOrigin = function formatResourceToCartItemOrigin(params) {
|
|
@@ -244,6 +245,54 @@ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOri
|
|
|
244
245
|
return origin;
|
|
245
246
|
};
|
|
246
247
|
|
|
248
|
+
/**
|
|
249
|
+
* 从购物车中删除资源相关信息
|
|
250
|
+
* @param cartItem 购物车
|
|
251
|
+
* @returns 删除后的购物车
|
|
252
|
+
*/
|
|
253
|
+
export var deleteResourceFromCartItem = function deleteResourceFromCartItem(cartItem) {
|
|
254
|
+
// 删除UI层的数据
|
|
255
|
+
cartItem.resource_id = undefined;
|
|
256
|
+
cartItem.relation_form_name = undefined;
|
|
257
|
+
cartItem.start_date = undefined;
|
|
258
|
+
cartItem.start_time = undefined;
|
|
259
|
+
cartItem.end_date = undefined;
|
|
260
|
+
cartItem.end_time = undefined;
|
|
261
|
+
|
|
262
|
+
// 删除资源原始数据
|
|
263
|
+
delete cartItem._resourceOrigin;
|
|
264
|
+
|
|
265
|
+
// 删除原始数据
|
|
266
|
+
cartItem._origin.resources = null;
|
|
267
|
+
cartItem._origin.select_date = null;
|
|
268
|
+
cartItem._origin.start_date = null;
|
|
269
|
+
cartItem._origin.start_time = null;
|
|
270
|
+
cartItem._origin.end_date = null;
|
|
271
|
+
cartItem._origin.end_time = null;
|
|
272
|
+
return cartItem;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 从购物车中删除时间
|
|
277
|
+
* @param cartItem 购物车
|
|
278
|
+
* @returns 删除后的购物车
|
|
279
|
+
*/
|
|
280
|
+
export var deleteTimeFromCartItem = function deleteTimeFromCartItem(cartItem) {
|
|
281
|
+
// 删除UI层的数据
|
|
282
|
+
cartItem.start_date = undefined;
|
|
283
|
+
cartItem.start_time = undefined;
|
|
284
|
+
cartItem.end_date = undefined;
|
|
285
|
+
cartItem.end_time = undefined;
|
|
286
|
+
|
|
287
|
+
// 删除原始数据
|
|
288
|
+
cartItem._origin.select_date = null;
|
|
289
|
+
cartItem._origin.start_date = null;
|
|
290
|
+
cartItem._origin.start_time = null;
|
|
291
|
+
cartItem._origin.end_date = null;
|
|
292
|
+
cartItem._origin.end_time = null;
|
|
293
|
+
return cartItem;
|
|
294
|
+
};
|
|
295
|
+
|
|
247
296
|
/**
|
|
248
297
|
* 格式化备注到购物车
|
|
249
298
|
* @param params 参数
|
|
@@ -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
|
}
|