@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
|
@@ -48,6 +48,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
48
48
|
this.otherParams = {};
|
|
49
49
|
}
|
|
50
50
|
async initialize(core, options) {
|
|
51
|
+
var _a;
|
|
51
52
|
this.core = core;
|
|
52
53
|
this.store = options.store || {};
|
|
53
54
|
this.otherParams = options.otherParams || {};
|
|
@@ -58,22 +59,35 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
58
59
|
if (!this.request) {
|
|
59
60
|
throw new Error("bookingByStep解决方案需要 request 插件支持");
|
|
60
61
|
}
|
|
62
|
+
let targetCacheData = {};
|
|
63
|
+
if ((_a = this.otherParams) == null ? void 0 : _a.cacheId) {
|
|
64
|
+
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
65
|
+
if (sessionData) {
|
|
66
|
+
const data = JSON.parse(sessionData);
|
|
67
|
+
targetCacheData = data[this.otherParams.cacheId];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
61
70
|
const moduleArr = [
|
|
71
|
+
"accountList",
|
|
62
72
|
"cart",
|
|
63
73
|
"summary",
|
|
64
74
|
"step",
|
|
65
75
|
"products",
|
|
66
|
-
"guests",
|
|
67
76
|
"date",
|
|
68
|
-
"accountList",
|
|
69
77
|
"order",
|
|
70
78
|
"payment"
|
|
71
79
|
];
|
|
72
80
|
moduleArr.forEach((step) => {
|
|
81
|
+
var _a2, _b;
|
|
73
82
|
const targetModule = (0, import_types.createModule)(step, this.name);
|
|
74
83
|
if (targetModule) {
|
|
75
84
|
this.store[step] = targetModule;
|
|
76
|
-
this.core.registerModule(targetModule
|
|
85
|
+
this.core.registerModule(targetModule, { initialState: targetCacheData[targetModule.name], otherParams: {
|
|
86
|
+
...this.otherParams,
|
|
87
|
+
fatherModule: this.name,
|
|
88
|
+
openCache: ((_a2 = this.otherParams) == null ? void 0 : _a2.cacheId) ? true : false,
|
|
89
|
+
cacheId: (_b = this.otherParams) == null ? void 0 : _b.cacheId
|
|
90
|
+
} });
|
|
77
91
|
} else {
|
|
78
92
|
throw new Error(`模块 ${step} 不存在`);
|
|
79
93
|
}
|
|
@@ -126,7 +140,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
126
140
|
category_ids,
|
|
127
141
|
ids: product_ids,
|
|
128
142
|
collection
|
|
129
|
-
});
|
|
143
|
+
}, { useCache: true });
|
|
130
144
|
this.store.products.addProduct(productsData.data.list);
|
|
131
145
|
return productsData.data.list;
|
|
132
146
|
}
|
|
@@ -174,11 +188,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
174
188
|
async setDateRange(dateRange) {
|
|
175
189
|
this.store.date.setDateRange(dateRange);
|
|
176
190
|
}
|
|
191
|
+
clearDateRange() {
|
|
192
|
+
this.store.date.clearDateRange();
|
|
193
|
+
}
|
|
177
194
|
// 获取日期模块里选中的日期
|
|
178
|
-
async
|
|
179
|
-
return
|
|
195
|
+
async getDateRange() {
|
|
196
|
+
return this.store.date.getDateRange();
|
|
180
197
|
}
|
|
181
|
-
|
|
198
|
+
getCart() {
|
|
182
199
|
return this.store.cart.getItems();
|
|
183
200
|
}
|
|
184
201
|
// 获取商品/服务的可用日期
|
|
@@ -270,6 +287,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
270
287
|
// 更新购物车
|
|
271
288
|
updateCart(params) {
|
|
272
289
|
this.store.cart.updateItem(params);
|
|
290
|
+
const targetCartItem = this.store.cart.getItem(params._id);
|
|
291
|
+
if (!targetCartItem) {
|
|
292
|
+
throw new Error(`没有找到${params._id}购物车商品`);
|
|
293
|
+
}
|
|
294
|
+
const cartItems = this.store.cart.getItems();
|
|
295
|
+
cartItems.forEach((item) => {
|
|
296
|
+
var _a;
|
|
297
|
+
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
298
|
+
const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter(
|
|
299
|
+
(m) => !targetCartItem._origin.resources.some((targetRes) => targetRes.id === m.id)
|
|
300
|
+
);
|
|
301
|
+
this.store.cart.updateItem({
|
|
302
|
+
_id: item._id,
|
|
303
|
+
resources
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
});
|
|
273
307
|
}
|
|
274
308
|
// 删除购物车里某个商品
|
|
275
309
|
deleteCart(cartItemId) {
|
|
@@ -337,6 +371,35 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
337
371
|
});
|
|
338
372
|
return arr;
|
|
339
373
|
}
|
|
374
|
+
// 给单个购物车里的商品获取资源列表
|
|
375
|
+
getResourcesListByCartItem(id) {
|
|
376
|
+
const cartItems = this.store.cart.getItems();
|
|
377
|
+
const dateRange = this.store.date.getDateRange();
|
|
378
|
+
const resources = [];
|
|
379
|
+
dateRange.forEach((n) => {
|
|
380
|
+
if (n.resource)
|
|
381
|
+
resources.push(...n.resource);
|
|
382
|
+
});
|
|
383
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
384
|
+
const arr = [];
|
|
385
|
+
const targetCartItem = cartItems.find((n) => n._id === id);
|
|
386
|
+
if (!targetCartItem) {
|
|
387
|
+
throw new Error(`没有找到${id}购物车商品`);
|
|
388
|
+
}
|
|
389
|
+
const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, targetCartItem, cartItems);
|
|
390
|
+
if (productResources) {
|
|
391
|
+
return {
|
|
392
|
+
id: targetCartItem.id,
|
|
393
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
394
|
+
_id: targetCartItem._id,
|
|
395
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
396
|
+
product: targetCartItem._productOrigin,
|
|
397
|
+
resources: productResources,
|
|
398
|
+
holder_id: targetCartItem.holder_id,
|
|
399
|
+
holder_name: targetCartItem.holder_title
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
340
403
|
// 通过资源列表和指定的资源 id,获取指定资源的时间切片
|
|
341
404
|
getResourceTimeSlot({
|
|
342
405
|
product,
|
|
@@ -612,6 +675,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
612
675
|
});
|
|
613
676
|
});
|
|
614
677
|
}
|
|
678
|
+
clearCache() {
|
|
679
|
+
}
|
|
680
|
+
clearCacheByModule(module2) {
|
|
681
|
+
}
|
|
615
682
|
};
|
|
616
683
|
// Annotate the CommonJS export names for ESM import in node:
|
|
617
684
|
0 && (module.exports = {
|
|
@@ -26,7 +26,6 @@ module.exports = __toCommonJS(types_exports);
|
|
|
26
26
|
var import_modules = require("../../modules");
|
|
27
27
|
var import_AccountList = require("../../modules/AccountList");
|
|
28
28
|
var import_Date = require("../../modules/Date");
|
|
29
|
-
var import_Guests = require("../../modules/Guests");
|
|
30
29
|
var import_Order = require("../../modules/Order");
|
|
31
30
|
var import_Payment = require("../../modules/Payment");
|
|
32
31
|
var import_Step = require("../../modules/Step");
|
|
@@ -41,8 +40,6 @@ function createModule(moduleName, solutionName, name, version) {
|
|
|
41
40
|
return new import_Step.StepModule(`${solutionName}_${name || moduleName}`, version);
|
|
42
41
|
case "products":
|
|
43
42
|
return new import_modules.ProductList(`${solutionName}_${name || moduleName}`, version);
|
|
44
|
-
case "guests":
|
|
45
|
-
return new import_Guests.GuestListModule(`${solutionName}_${name || moduleName}`, version);
|
|
46
43
|
case "date":
|
|
47
44
|
return new import_Date.DateModule(`${solutionName}_${name || moduleName}`, version);
|
|
48
45
|
case "accountList":
|
|
@@ -82,15 +82,29 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
registerDependentModules() {
|
|
85
|
-
var _a, _b, _c, _d;
|
|
85
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
86
|
+
let targetCacheData = {};
|
|
87
|
+
if ((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) {
|
|
88
|
+
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
89
|
+
if (sessionData) {
|
|
90
|
+
const data = JSON.parse(sessionData);
|
|
91
|
+
targetCacheData = data[this.options.otherParams.cacheId];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
86
94
|
const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
|
|
87
95
|
this.core.registerModule(discount, {
|
|
88
|
-
|
|
96
|
+
initialState: targetCacheData[discount.name],
|
|
97
|
+
hooks: (_c = (_b = this.options.otherParams) == null ? void 0 : _b.discount) == null ? void 0 : _c.hooks,
|
|
98
|
+
otherParams: {
|
|
99
|
+
fatherModule: this.name,
|
|
100
|
+
openCache: ((_d = this.options.otherParams) == null ? void 0 : _d.cacheId) ? true : false,
|
|
101
|
+
cacheId: (_e = this.options.otherParams) == null ? void 0 : _e.cacheId
|
|
102
|
+
}
|
|
89
103
|
});
|
|
90
104
|
this.store.discount = discount;
|
|
91
105
|
const rules = new import_Rules.RulesModule(`${this.name}_rules`);
|
|
92
106
|
this.core.registerModule(rules, {
|
|
93
|
-
hooks: (
|
|
107
|
+
hooks: (_g = (_f = this.options.otherParams) == null ? void 0 : _f.rules) == null ? void 0 : _g.hooks
|
|
94
108
|
});
|
|
95
109
|
this.store.rules = rules;
|
|
96
110
|
}
|
|
@@ -98,6 +112,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
98
112
|
this.core.effects.on(
|
|
99
113
|
import_types.ShopDiscountHooks.onCustomerChange,
|
|
100
114
|
(customer) => {
|
|
115
|
+
var _a;
|
|
116
|
+
if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
101
119
|
this.loadPrepareConfig({
|
|
102
120
|
customerId: customer.id,
|
|
103
121
|
action: "create",
|