@pisell/pisellos 0.0.9 → 0.0.11
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/core/index.js +4 -1
- package/dist/effects/index.d.ts +1 -1
- package/dist/effects/index.js +3 -3
- package/dist/modules/Account/index.d.ts +5 -3
- package/dist/modules/Account/index.js +23 -36
- package/dist/modules/Account/types.d.ts +2 -1
- package/dist/modules/AccountList/index.d.ts +2 -0
- package/dist/modules/AccountList/index.js +34 -11
- package/dist/modules/Cart/index.d.ts +17 -11
- package/dist/modules/Cart/index.js +179 -121
- package/dist/modules/Cart/types.d.ts +98 -9
- package/dist/modules/Cart/types.js +8 -0
- package/dist/modules/Cart/utils.d.ts +114 -0
- package/dist/modules/Cart/utils.js +345 -0
- package/dist/modules/Date/index.d.ts +11 -12
- package/dist/modules/Date/index.js +104 -60
- package/dist/modules/Date/types.d.ts +51 -20
- package/dist/modules/Date/types.js +2 -5
- package/dist/modules/Date/utils.d.ts +35 -0
- package/dist/modules/Date/utils.js +211 -0
- package/dist/modules/Discount/index.d.ts +26 -0
- package/dist/modules/Discount/index.js +234 -0
- package/dist/modules/Discount/types.d.ts +66 -0
- package/dist/modules/Discount/types.js +5 -0
- package/dist/modules/Order/index.d.ts +16 -12
- package/dist/modules/Order/index.js +38 -166
- package/dist/modules/Order/types.d.ts +18 -41
- package/dist/modules/Order/types.js +0 -14
- package/dist/modules/Payment/index.d.ts +0 -2
- package/dist/modules/Payment/index.js +45 -76
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Product/types.d.ts +50 -1
- package/dist/modules/ProductList/index.d.ts +1 -0
- package/dist/modules/ProductList/index.js +23 -2
- package/dist/modules/ProductList/types.d.ts +1 -0
- package/dist/modules/Resource/types.d.ts +6 -2
- package/dist/modules/Rules/index.d.ts +32 -0
- package/dist/modules/Rules/index.js +423 -0
- package/dist/modules/Rules/types.d.ts +46 -0
- package/dist/modules/Rules/types.js +5 -0
- package/dist/modules/Summary/index.d.ts +13 -0
- package/dist/modules/Summary/index.js +80 -0
- package/dist/modules/Summary/types.d.ts +13 -0
- package/dist/modules/Summary/types.js +1 -0
- package/dist/modules/Summary/utils.d.ts +19 -0
- package/dist/modules/Summary/utils.js +56 -0
- package/dist/plugins/index.d.ts +3 -2
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/request.d.ts +4 -3
- package/dist/plugins/request.js +30 -30
- package/dist/plugins/shopStore.d.ts +4 -0
- package/dist/plugins/shopStore.js +1 -0
- package/dist/solution/BookingByStep/index.d.ts +73 -10
- package/dist/solution/BookingByStep/index.js +641 -74
- package/dist/solution/BookingByStep/types.d.ts +2 -0
- package/dist/solution/BookingByStep/types.js +11 -8
- package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/products.js +47 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/dist/solution/BookingByStep/utils/resources.js +144 -79
- package/dist/solution/ShopDiscount/index.d.ts +50 -0
- package/dist/solution/ShopDiscount/index.js +546 -0
- package/dist/solution/ShopDiscount/types.d.ts +24 -0
- package/dist/solution/ShopDiscount/types.js +10 -0
- package/dist/solution/ShopDiscount/utils.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +7 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/core/index.js +1 -1
- package/lib/effects/index.d.ts +1 -1
- package/lib/effects/index.js +1 -1
- package/lib/modules/Account/index.d.ts +5 -3
- package/lib/modules/Account/index.js +14 -3
- package/lib/modules/Account/types.d.ts +2 -1
- package/lib/modules/AccountList/index.d.ts +2 -0
- package/lib/modules/AccountList/index.js +17 -0
- package/lib/modules/Cart/index.d.ts +17 -11
- package/lib/modules/Cart/index.js +72 -21
- package/lib/modules/Cart/types.d.ts +98 -9
- package/lib/modules/Cart/utils.d.ts +114 -0
- package/lib/modules/Cart/utils.js +320 -0
- package/lib/modules/Date/index.d.ts +11 -12
- package/lib/modules/Date/index.js +50 -31
- package/lib/modules/Date/types.d.ts +51 -20
- package/lib/modules/Date/types.js +0 -4
- package/lib/modules/Date/utils.d.ts +35 -0
- package/lib/modules/Date/utils.js +167 -0
- package/lib/modules/Discount/index.d.ts +26 -0
- package/lib/modules/Discount/index.js +118 -0
- package/lib/modules/Discount/types.d.ts +66 -0
- package/lib/modules/Discount/types.js +33 -0
- package/lib/modules/Order/index.d.ts +16 -12
- package/lib/modules/Order/index.js +23 -51
- package/lib/modules/Order/types.d.ts +18 -41
- package/lib/modules/Payment/index.d.ts +0 -2
- package/lib/modules/Payment/index.js +6 -17
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Product/types.d.ts +50 -1
- package/lib/modules/ProductList/index.d.ts +1 -0
- package/lib/modules/ProductList/index.js +6 -1
- package/lib/modules/ProductList/types.d.ts +1 -0
- package/lib/modules/Resource/types.d.ts +6 -2
- package/lib/modules/Rules/index.d.ts +32 -0
- package/lib/modules/Rules/index.js +283 -0
- package/lib/modules/Rules/types.d.ts +46 -0
- package/lib/modules/Rules/types.js +33 -0
- package/lib/modules/Summary/index.d.ts +13 -0
- package/lib/modules/Summary/index.js +49 -0
- package/lib/modules/Summary/types.d.ts +13 -0
- package/lib/modules/Summary/types.js +17 -0
- package/lib/modules/Summary/utils.d.ts +19 -0
- package/lib/modules/Summary/utils.js +79 -0
- package/lib/plugins/index.d.ts +3 -2
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/request.d.ts +4 -3
- package/lib/plugins/request.js +4 -20
- package/lib/plugins/shopStore.d.ts +4 -0
- package/lib/plugins/shopStore.js +17 -0
- package/lib/solution/BookingByStep/index.d.ts +73 -10
- package/lib/solution/BookingByStep/index.js +452 -20
- package/lib/solution/BookingByStep/types.d.ts +2 -0
- package/lib/solution/BookingByStep/types.js +3 -0
- package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/products.js +60 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/lib/solution/BookingByStep/utils/resources.js +106 -49
- package/lib/solution/ShopDiscount/index.d.ts +50 -0
- package/lib/solution/ShopDiscount/index.js +321 -0
- package/lib/solution/ShopDiscount/types.d.ts +24 -0
- package/lib/solution/ShopDiscount/types.js +38 -0
- package/lib/solution/ShopDiscount/utils.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +32 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +3 -1
- package/package.json +8 -7
|
@@ -23,6 +23,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
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
25
|
import { CartHooks } from "./types";
|
|
26
|
+
import { createCartItemOrigin, formatAccountToCartItem, formatProductToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
|
|
26
27
|
export * from "./types";
|
|
27
28
|
|
|
28
29
|
/**
|
|
@@ -36,8 +37,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
36
37
|
_classCallCheck(this, CartModule);
|
|
37
38
|
_this = _super.call(this, name, version);
|
|
38
39
|
// 提供给 baseModule 用的默认名称 和 默认版本
|
|
39
|
-
_defineProperty(_assertThisInitialized(_this), "defaultName",
|
|
40
|
-
_defineProperty(_assertThisInitialized(_this), "defaultVersion",
|
|
40
|
+
_defineProperty(_assertThisInitialized(_this), "defaultName", "cart");
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
|
|
41
42
|
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
42
43
|
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
43
44
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
@@ -65,25 +66,26 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
65
66
|
case 0:
|
|
66
67
|
this.core = core;
|
|
67
68
|
this.store = options.store;
|
|
69
|
+
this.store.list = [];
|
|
68
70
|
|
|
69
71
|
// 获取依赖的插件
|
|
70
|
-
this.request = core.getPlugin(
|
|
71
|
-
this.window = core.getPlugin(
|
|
72
|
+
this.request = core.getPlugin("request");
|
|
73
|
+
this.window = core.getPlugin("window");
|
|
72
74
|
if (this.request) {
|
|
73
|
-
_context.next =
|
|
75
|
+
_context.next = 7;
|
|
74
76
|
break;
|
|
75
77
|
}
|
|
76
|
-
throw new Error(
|
|
77
|
-
case
|
|
78
|
+
throw new Error("购物车模块需要 request 插件支持");
|
|
79
|
+
case 7:
|
|
78
80
|
if (this.window) {
|
|
79
|
-
_context.next =
|
|
81
|
+
_context.next = 9;
|
|
80
82
|
break;
|
|
81
83
|
}
|
|
82
|
-
throw new Error(
|
|
83
|
-
case
|
|
84
|
+
throw new Error("购物车模块需要 window 插件支持");
|
|
85
|
+
case 9:
|
|
84
86
|
this.store.temp = {};
|
|
85
|
-
console.log(
|
|
86
|
-
case
|
|
87
|
+
console.log("[CartModule] 初始化完成");
|
|
88
|
+
case 11:
|
|
87
89
|
case "end":
|
|
88
90
|
return _context.stop();
|
|
89
91
|
}
|
|
@@ -95,139 +97,191 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
95
97
|
return initialize;
|
|
96
98
|
}()
|
|
97
99
|
/**
|
|
98
|
-
*
|
|
100
|
+
* 添加商品到购物车
|
|
99
101
|
*/
|
|
100
102
|
)
|
|
101
103
|
}, {
|
|
102
|
-
key: "
|
|
104
|
+
key: "addItem",
|
|
103
105
|
value: (function () {
|
|
104
|
-
var
|
|
106
|
+
var _addItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
107
|
+
var account, product, bundle, options, cartItem, items;
|
|
105
108
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
106
109
|
while (1) switch (_context2.prev = _context2.next) {
|
|
107
110
|
case 0:
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
account = params.account, product = params.product, bundle = params.bundle, options = params.options; // 生成一个唯一的 ID
|
|
112
|
+
cartItem = {
|
|
113
|
+
_id: getUniqueId(),
|
|
114
|
+
_origin: createCartItemOrigin(),
|
|
115
|
+
_productOrigin: product
|
|
116
|
+
};
|
|
117
|
+
if (product) {
|
|
118
|
+
cartItem = formatProductToCartItem({
|
|
119
|
+
cartItem: cartItem,
|
|
120
|
+
product: product,
|
|
121
|
+
bundle: bundle,
|
|
122
|
+
options: options
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (account) {
|
|
126
|
+
cartItem = formatAccountToCartItem({
|
|
127
|
+
cartItem: cartItem,
|
|
128
|
+
account: account
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 更新购物车数据
|
|
133
|
+
items = [].concat(_toConsumableArray(this.store.list), [cartItem]);
|
|
134
|
+
this.store.list = items;
|
|
135
|
+
|
|
136
|
+
// 触发事件
|
|
137
|
+
_context2.next = 8;
|
|
138
|
+
return this.core.effects.emit(CartHooks.OnAddItem, cartItem);
|
|
139
|
+
case 8:
|
|
140
|
+
_context2.next = 10;
|
|
141
|
+
return this.core.effects.emit("".concat(this.name, ":changed"), items);
|
|
142
|
+
case 10:
|
|
110
143
|
case "end":
|
|
111
144
|
return _context2.stop();
|
|
112
145
|
}
|
|
113
|
-
}, _callee2);
|
|
146
|
+
}, _callee2, this);
|
|
114
147
|
}));
|
|
115
|
-
function
|
|
116
|
-
return
|
|
148
|
+
function addItem(_x3) {
|
|
149
|
+
return _addItem.apply(this, arguments);
|
|
117
150
|
}
|
|
118
|
-
return
|
|
151
|
+
return addItem;
|
|
119
152
|
}()
|
|
120
153
|
/**
|
|
121
|
-
*
|
|
154
|
+
* 更新购物车信息
|
|
122
155
|
*/
|
|
123
156
|
)
|
|
124
157
|
}, {
|
|
125
|
-
key: "
|
|
158
|
+
key: "updateItem",
|
|
126
159
|
value: (function () {
|
|
127
|
-
var
|
|
128
|
-
var
|
|
160
|
+
var _updateItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
161
|
+
var _tempCartItem$_origin;
|
|
162
|
+
var _id, cartItem, account, product, resources, note, tempCartItem, items;
|
|
129
163
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
130
164
|
while (1) switch (_context3.prev = _context3.next) {
|
|
131
165
|
case 0:
|
|
132
|
-
|
|
166
|
+
_id = params._id, cartItem = params.cartItem, account = params.account, product = params.product, resources = params.resources, note = params.note;
|
|
167
|
+
tempCartItem = this.store.list.find(function (i) {
|
|
168
|
+
return i._id === _id;
|
|
169
|
+
});
|
|
170
|
+
if (tempCartItem) {
|
|
171
|
+
_context3.next = 5;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
console.warn("[CartModule] 更新购物车商品失败,商品不存在");
|
|
175
|
+
return _context3.abrupt("return");
|
|
176
|
+
case 5:
|
|
177
|
+
if (cartItem) {
|
|
178
|
+
tempCartItem = cartItem;
|
|
179
|
+
}
|
|
180
|
+
if (product) {
|
|
181
|
+
tempCartItem = formatProductToCartItem({
|
|
182
|
+
cartItem: tempCartItem,
|
|
183
|
+
product: product
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (account) {
|
|
187
|
+
tempCartItem = formatAccountToCartItem({
|
|
188
|
+
cartItem: tempCartItem,
|
|
189
|
+
account: account
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (resources) {
|
|
193
|
+
tempCartItem = formatResourceToCartItem({
|
|
194
|
+
cartItem: tempCartItem,
|
|
195
|
+
resources: resources
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (note && (_tempCartItem$_origin = tempCartItem._origin) !== null && _tempCartItem$_origin !== void 0 && _tempCartItem$_origin.product) {
|
|
199
|
+
tempCartItem.note = note;
|
|
200
|
+
tempCartItem._origin.product.note = note;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 更新购物车数据
|
|
204
|
+
items = this.store.list.map(function (item) {
|
|
205
|
+
var _tempCartItem;
|
|
206
|
+
if (item._id === ((_tempCartItem = tempCartItem) === null || _tempCartItem === void 0 ? void 0 : _tempCartItem._id)) {
|
|
207
|
+
return tempCartItem;
|
|
208
|
+
}
|
|
209
|
+
return item;
|
|
210
|
+
});
|
|
133
211
|
this.store.list = items;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
case 6:
|
|
212
|
+
|
|
213
|
+
// 触发事件
|
|
214
|
+
_context3.next = 14;
|
|
215
|
+
return this.core.effects.emit("".concat(this.name, ":changed"), items);
|
|
216
|
+
case 14:
|
|
140
217
|
case "end":
|
|
141
218
|
return _context3.stop();
|
|
142
219
|
}
|
|
143
220
|
}, _callee3, this);
|
|
144
221
|
}));
|
|
145
|
-
function
|
|
146
|
-
return
|
|
222
|
+
function updateItem(_x4) {
|
|
223
|
+
return _updateItem.apply(this, arguments);
|
|
147
224
|
}
|
|
148
|
-
return
|
|
149
|
-
}()
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}, {
|
|
156
|
-
key: "getTotalPrice",
|
|
157
|
-
value: function getTotalPrice() {
|
|
158
|
-
return this.store.list.reduce(function (total, item) {
|
|
159
|
-
return total + item.price * item.quantity;
|
|
160
|
-
}, 0);
|
|
161
|
-
}
|
|
225
|
+
return updateItem;
|
|
226
|
+
}()
|
|
227
|
+
/**
|
|
228
|
+
* 批量设置购物车数据
|
|
229
|
+
*/
|
|
230
|
+
)
|
|
162
231
|
}, {
|
|
163
|
-
key: "
|
|
164
|
-
value: function () {
|
|
165
|
-
var
|
|
232
|
+
key: "batchSetItems",
|
|
233
|
+
value: (function () {
|
|
234
|
+
var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(items) {
|
|
166
235
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
167
236
|
while (1) switch (_context4.prev = _context4.next) {
|
|
168
237
|
case 0:
|
|
169
|
-
|
|
238
|
+
this.store.list = items || [];
|
|
170
239
|
case 1:
|
|
171
240
|
case "end":
|
|
172
241
|
return _context4.stop();
|
|
173
242
|
}
|
|
174
243
|
}, _callee4, this);
|
|
175
244
|
}));
|
|
176
|
-
function
|
|
177
|
-
return
|
|
245
|
+
function batchSetItems(_x5) {
|
|
246
|
+
return _batchSetItems.apply(this, arguments);
|
|
178
247
|
}
|
|
179
|
-
return
|
|
180
|
-
}()
|
|
248
|
+
return batchSetItems;
|
|
249
|
+
}())
|
|
181
250
|
}, {
|
|
182
|
-
key: "
|
|
183
|
-
value: function () {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
items[itemIndex] = item;
|
|
198
|
-
this.store.list = items;
|
|
199
|
-
_context5.next = 7;
|
|
200
|
-
return this.core.effects.emit(CartHooks.OnCartUpdateItem, items);
|
|
201
|
-
case 7:
|
|
202
|
-
case "end":
|
|
203
|
-
return _context5.stop();
|
|
204
|
-
}
|
|
205
|
-
}, _callee5, this);
|
|
206
|
-
}));
|
|
207
|
-
function updateItem(_x4, _x5) {
|
|
208
|
-
return _updateItem.apply(this, arguments);
|
|
209
|
-
}
|
|
210
|
-
return updateItem;
|
|
211
|
-
}()
|
|
251
|
+
key: "getItemCount",
|
|
252
|
+
value: function getItemCount() {
|
|
253
|
+
return this.store.list.length;
|
|
254
|
+
}
|
|
255
|
+
}, {
|
|
256
|
+
key: "getTotalPrice",
|
|
257
|
+
value: function getTotalPrice() {
|
|
258
|
+
// return this.store.list.reduce((total: number, item: CartItem) => total + item.price * item.quantity, 0);
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
}, {
|
|
262
|
+
key: "getItems",
|
|
263
|
+
value: function getItems() {
|
|
264
|
+
return this.store.list;
|
|
265
|
+
}
|
|
212
266
|
}, {
|
|
213
267
|
key: "removeItem",
|
|
214
268
|
value: function () {
|
|
215
|
-
var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
269
|
+
var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
|
|
216
270
|
var items;
|
|
217
|
-
return _regeneratorRuntime().wrap(function
|
|
218
|
-
while (1) switch (
|
|
271
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
272
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
219
273
|
case 0:
|
|
220
274
|
items = this.store.list.filter(function (i) {
|
|
221
|
-
return i.
|
|
275
|
+
return i._id !== id;
|
|
222
276
|
});
|
|
223
277
|
this.store.list = items;
|
|
224
|
-
|
|
278
|
+
_context5.next = 4;
|
|
225
279
|
return this.core.effects.emit(CartHooks.OnCartRemove, items);
|
|
226
280
|
case 4:
|
|
227
281
|
case "end":
|
|
228
|
-
return
|
|
282
|
+
return _context5.stop();
|
|
229
283
|
}
|
|
230
|
-
},
|
|
284
|
+
}, _callee5, this);
|
|
231
285
|
}));
|
|
232
286
|
function removeItem(_x6) {
|
|
233
287
|
return _removeItem.apply(this, arguments);
|
|
@@ -237,16 +291,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
237
291
|
}, {
|
|
238
292
|
key: "storeTemp",
|
|
239
293
|
value: function () {
|
|
240
|
-
var _storeTemp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
241
|
-
return _regeneratorRuntime().wrap(function
|
|
242
|
-
while (1) switch (
|
|
294
|
+
var _storeTemp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(key, value) {
|
|
295
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
296
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
243
297
|
case 0:
|
|
244
298
|
this.store.temp[key] = value;
|
|
245
|
-
|
|
299
|
+
_context6.next = 3;
|
|
300
|
+
return this.core.effects.emit("".concat(this.name, ":changed"), this.store.temp);
|
|
301
|
+
case 3:
|
|
246
302
|
case "end":
|
|
247
|
-
return
|
|
303
|
+
return _context6.stop();
|
|
248
304
|
}
|
|
249
|
-
},
|
|
305
|
+
}, _callee6, this);
|
|
250
306
|
}));
|
|
251
307
|
function storeTemp(_x7, _x8) {
|
|
252
308
|
return _storeTemp.apply(this, arguments);
|
|
@@ -255,29 +311,31 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
255
311
|
}()
|
|
256
312
|
}, {
|
|
257
313
|
key: "getTemp",
|
|
258
|
-
value: function () {
|
|
259
|
-
|
|
260
|
-
return
|
|
261
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
262
|
-
case 0:
|
|
263
|
-
if (key) {
|
|
264
|
-
_context8.next = 2;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
return _context8.abrupt("return", this.store.temp);
|
|
268
|
-
case 2:
|
|
269
|
-
return _context8.abrupt("return", this.store.temp[key]);
|
|
270
|
-
case 3:
|
|
271
|
-
case "end":
|
|
272
|
-
return _context8.stop();
|
|
273
|
-
}
|
|
274
|
-
}, _callee8, this);
|
|
275
|
-
}));
|
|
276
|
-
function getTemp(_x9) {
|
|
277
|
-
return _getTemp.apply(this, arguments);
|
|
314
|
+
value: function getTemp(key) {
|
|
315
|
+
if (!key) {
|
|
316
|
+
return this.store.temp;
|
|
278
317
|
}
|
|
279
|
-
return
|
|
280
|
-
}
|
|
318
|
+
return this.store.temp[key];
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
key: "clear",
|
|
322
|
+
value: function clear() {
|
|
323
|
+
this.store.list = [];
|
|
324
|
+
}
|
|
325
|
+
}, {
|
|
326
|
+
key: "clearCartByAccount",
|
|
327
|
+
value: function clearCartByAccount(account_id) {
|
|
328
|
+
this.store.list = this.store.list.filter(function (item) {
|
|
329
|
+
return item.holder_id !== account_id;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}, {
|
|
333
|
+
key: "getCartByAccount",
|
|
334
|
+
value: function getCartByAccount(account_id) {
|
|
335
|
+
return this.store.list.filter(function (item) {
|
|
336
|
+
return item.holder_id === account_id;
|
|
337
|
+
});
|
|
338
|
+
}
|
|
281
339
|
}]);
|
|
282
340
|
return CartModule;
|
|
283
341
|
}(BaseModule);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ProductData } from
|
|
1
|
+
import { ProductData } from "../Product/types";
|
|
2
|
+
import { Account } from "../Account/types";
|
|
3
|
+
import { Resource } from "../Resource/types";
|
|
2
4
|
export declare enum CartHooks {
|
|
3
5
|
OnAddItem = "card:onAddItem",
|
|
4
6
|
OnCartChange = "card:onCartChange",
|
|
@@ -9,16 +11,69 @@ export declare enum CartHooks {
|
|
|
9
11
|
* 购物车商品接口
|
|
10
12
|
*/
|
|
11
13
|
export interface CartItem {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** 购物车ID */
|
|
15
|
+
_id: string;
|
|
16
|
+
/** 商品ID */
|
|
17
|
+
id?: number;
|
|
18
|
+
/** 商品名称 */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** 商品价格 */
|
|
21
|
+
price?: number | string;
|
|
22
|
+
/** 商品总价 */
|
|
23
|
+
total?: number | string;
|
|
24
|
+
/** 商品原价总价,排除原始价格为0的场景 */
|
|
25
|
+
origin_total?: number | string;
|
|
26
|
+
/** 商品数量 */
|
|
27
|
+
num?: number;
|
|
28
|
+
/** 商品图片 */
|
|
29
|
+
image?: string;
|
|
30
|
+
/** 商品时长 */
|
|
31
|
+
duration?: {
|
|
32
|
+
type: string;
|
|
33
|
+
value: number;
|
|
34
|
+
};
|
|
35
|
+
/** 是否显示备注 */
|
|
36
|
+
isShowNote?: boolean;
|
|
37
|
+
/** 备注 */
|
|
38
|
+
note?: string;
|
|
39
|
+
/** 点赞状态 */
|
|
40
|
+
like_status?: "like" | "common";
|
|
41
|
+
/** 用户名称 */
|
|
42
|
+
holder_title?: string;
|
|
43
|
+
/** 用户ID */
|
|
44
|
+
holder_id?: number | string;
|
|
45
|
+
/** 符号 */
|
|
46
|
+
symbol?: string;
|
|
47
|
+
/** 开始日期 */
|
|
48
|
+
start_date?: string;
|
|
49
|
+
/** 开始时间 */
|
|
50
|
+
start_time?: string;
|
|
51
|
+
/** 结束日期 */
|
|
52
|
+
end_date?: string;
|
|
53
|
+
/** 结束时间 */
|
|
54
|
+
end_time?: string;
|
|
55
|
+
/** 是否收取税费 */
|
|
56
|
+
is_charge_tax?: number;
|
|
57
|
+
/** 商品套餐信息 */
|
|
58
|
+
bundle?: any[];
|
|
59
|
+
/** 商品规格信息 */
|
|
60
|
+
options?: any[];
|
|
61
|
+
/** 是否为普通商品 */
|
|
62
|
+
isNormalProduct?: boolean;
|
|
63
|
+
/** 资源ID */
|
|
64
|
+
resource_id?: string | number;
|
|
65
|
+
/** 资源名称 */
|
|
66
|
+
relation_form_name?: string;
|
|
67
|
+
/** 原始数据 */
|
|
68
|
+
_origin: any;
|
|
69
|
+
/** 商品原始数据 */
|
|
70
|
+
_productOrigin: ProductData;
|
|
16
71
|
}
|
|
17
72
|
/**
|
|
18
73
|
* 购物车状态接口
|
|
19
74
|
*/
|
|
20
75
|
export interface CartState {
|
|
21
|
-
list:
|
|
76
|
+
list: CartItem[];
|
|
22
77
|
total: number;
|
|
23
78
|
temp: Record<string, any>;
|
|
24
79
|
}
|
|
@@ -26,10 +81,44 @@ export interface CartState {
|
|
|
26
81
|
* 购物车模块 API
|
|
27
82
|
*/
|
|
28
83
|
export interface CartModuleAPI {
|
|
29
|
-
addItem: (item:
|
|
84
|
+
addItem: (item: IAddItemParams) => Promise<void>;
|
|
30
85
|
getItemCount: () => number;
|
|
31
86
|
getTotalPrice: () => number;
|
|
32
|
-
getItems: () =>
|
|
33
|
-
updateItem: (
|
|
87
|
+
getItems: () => CartItem[];
|
|
88
|
+
updateItem: (params: IUpdateItemParams) => Promise<void>;
|
|
34
89
|
removeItem: (id: string) => Promise<void>;
|
|
35
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* 添加商品到购物车参数
|
|
93
|
+
*/
|
|
94
|
+
export interface IAddItemParams {
|
|
95
|
+
/** 账户 */
|
|
96
|
+
account: Account;
|
|
97
|
+
/** 商品 */
|
|
98
|
+
product: ProductData;
|
|
99
|
+
/** 数量 */
|
|
100
|
+
quantity?: number;
|
|
101
|
+
/** 商品套餐信息 */
|
|
102
|
+
bundle?: any[];
|
|
103
|
+
/** 商品规格信息 */
|
|
104
|
+
options?: any[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 更新购物车信息参数
|
|
108
|
+
*/
|
|
109
|
+
export interface IUpdateItemParams {
|
|
110
|
+
/** 购物车_id字段 */
|
|
111
|
+
_id?: string;
|
|
112
|
+
/** 购物车商品 */
|
|
113
|
+
cartItem?: CartItem;
|
|
114
|
+
/** 账户 */
|
|
115
|
+
account?: Account;
|
|
116
|
+
/** 商品 */
|
|
117
|
+
product?: ProductData;
|
|
118
|
+
/** 数量 */
|
|
119
|
+
quantity?: number;
|
|
120
|
+
/** 资源 */
|
|
121
|
+
resources?: Resource[];
|
|
122
|
+
/** 备注 */
|
|
123
|
+
note?: string;
|
|
124
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Account } from "../Account";
|
|
2
|
+
import { ProductData } from "../Product/types";
|
|
3
|
+
import { Resource } from "../Resource/types";
|
|
4
|
+
import { CartItem } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* 生成一个唯一的 ID
|
|
7
|
+
*/
|
|
8
|
+
export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
|
|
9
|
+
/**
|
|
10
|
+
* 创建购物车原始数据
|
|
11
|
+
*/
|
|
12
|
+
export declare const createCartItemOrigin: () => {
|
|
13
|
+
id: number;
|
|
14
|
+
number: number;
|
|
15
|
+
registration_type: string;
|
|
16
|
+
relation_products: never[];
|
|
17
|
+
is_all: boolean;
|
|
18
|
+
product: null;
|
|
19
|
+
sub_type: null;
|
|
20
|
+
duration: null;
|
|
21
|
+
like_status: string;
|
|
22
|
+
relation_type: string;
|
|
23
|
+
resources: null;
|
|
24
|
+
schedule_id: number;
|
|
25
|
+
start_date: null;
|
|
26
|
+
start_time: null;
|
|
27
|
+
select_date: null;
|
|
28
|
+
end_time: null;
|
|
29
|
+
end_date: null;
|
|
30
|
+
metadata: {};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 格式化商品到购物车
|
|
34
|
+
* @param product 商品
|
|
35
|
+
* @returns 格式化后的商品
|
|
36
|
+
*/
|
|
37
|
+
export declare const formatProductToCartItem: (params: {
|
|
38
|
+
cartItem: CartItem;
|
|
39
|
+
product: ProductData;
|
|
40
|
+
bundle?: any;
|
|
41
|
+
options?: any;
|
|
42
|
+
}) => CartItem;
|
|
43
|
+
export declare const formatProductToCartItemOrigin: (params: {
|
|
44
|
+
cartItem: CartItem;
|
|
45
|
+
product: ProductData;
|
|
46
|
+
bundle?: any;
|
|
47
|
+
options?: any;
|
|
48
|
+
}) => any;
|
|
49
|
+
/**
|
|
50
|
+
* 格式化账户到购物车
|
|
51
|
+
* @param account 账户
|
|
52
|
+
* @returns 格式化后的账户
|
|
53
|
+
*/
|
|
54
|
+
export declare const formatAccountToCartItem: (params: {
|
|
55
|
+
cartItem: CartItem;
|
|
56
|
+
account: Account;
|
|
57
|
+
}) => CartItem;
|
|
58
|
+
export declare const formatAccountToCartItemOrigin: (params: {
|
|
59
|
+
cartItem: CartItem;
|
|
60
|
+
account: Account;
|
|
61
|
+
}) => any;
|
|
62
|
+
/**
|
|
63
|
+
* 格式化资源到购物车
|
|
64
|
+
* @param resource 资源
|
|
65
|
+
* @returns 格式化后的资源
|
|
66
|
+
*/
|
|
67
|
+
export declare const formatResourceToCartItem: (params: {
|
|
68
|
+
cartItem: CartItem;
|
|
69
|
+
resources: Resource[];
|
|
70
|
+
}) => CartItem;
|
|
71
|
+
export declare const formatResourceToCartItemOrigin: (params: {
|
|
72
|
+
cartItem: CartItem;
|
|
73
|
+
resources: Resource[];
|
|
74
|
+
}) => any;
|
|
75
|
+
/**
|
|
76
|
+
* 格式化套餐规格信息
|
|
77
|
+
* @param options 套餐规格信息
|
|
78
|
+
* @returns 格式化后的套餐规格信息
|
|
79
|
+
*/
|
|
80
|
+
export declare const formatOptions: (options: any) => any;
|
|
81
|
+
export declare const formatOptionsToOrigin: (options: any) => any;
|
|
82
|
+
/**
|
|
83
|
+
* 格式化商品套餐信息
|
|
84
|
+
* @param bundle 商品套餐信息
|
|
85
|
+
* @returns 格式化后的商品套餐信息
|
|
86
|
+
*/
|
|
87
|
+
export declare const formatBundle: (bundle: any) => any;
|
|
88
|
+
export declare const formatBundleToOrigin: (bundle: any) => any;
|
|
89
|
+
/**
|
|
90
|
+
* 判断是否是普通商品
|
|
91
|
+
* @param product 商品
|
|
92
|
+
* @returns 是否是普通商品
|
|
93
|
+
*/
|
|
94
|
+
export declare const isNormalProduct: (product: any) => boolean;
|
|
95
|
+
/**
|
|
96
|
+
* 获取商品总价
|
|
97
|
+
* @param item 商品
|
|
98
|
+
* @returns 商品总价
|
|
99
|
+
*/
|
|
100
|
+
export declare const getProductTotalPrice: (params: {
|
|
101
|
+
product: ProductData;
|
|
102
|
+
bundle?: any;
|
|
103
|
+
options?: any;
|
|
104
|
+
}) => number;
|
|
105
|
+
/**
|
|
106
|
+
* 获取商品原始总价
|
|
107
|
+
* @param item 商品
|
|
108
|
+
* @returns 商品原始总价
|
|
109
|
+
*/
|
|
110
|
+
export declare const getProductOriginTotalPrice: (params: {
|
|
111
|
+
product: ProductData;
|
|
112
|
+
bundle?: any;
|
|
113
|
+
options?: any;
|
|
114
|
+
}) => number | undefined;
|