@pisell/pisellos 0.0.324 → 0.0.326
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/effects/index.d.ts +2 -2
- package/dist/modules/Account/index.js +2 -3
- package/dist/modules/BaseModule.d.ts +3 -0
- package/dist/modules/BaseModule.js +15 -0
- package/dist/modules/Customer/index.js +9 -10
- package/dist/modules/Customer/types.d.ts +1 -1
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Guests/index.js +9 -9
- package/dist/modules/Payment/index.js +18 -18
- package/dist/modules/Payment/types.d.ts +7 -7
- package/dist/modules/Payment/walletpass.js +4 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -3
- package/dist/modules/Resource/index.js +1 -1
- package/dist/modules/Rules/index.js +2 -3
- package/dist/modules/Rules/types.d.ts +1 -1
- package/dist/modules/Schedule/type.d.ts +7 -7
- package/dist/modules/Schedule/types.d.ts +9 -9
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +2 -2
- package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +7 -7
- package/dist/solution/BuyTickets/index.js +7 -8
- package/dist/solution/Checkout/index.js +29 -29
- package/dist/solution/ShopDiscount/index.js +1 -1
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/task.d.ts +2 -2
- package/dist/utils/watch.d.ts +2 -2
- package/lib/core/index.js +28 -27
- package/lib/effects/index.d.ts +2 -2
- package/lib/effects/index.js +7 -3
- package/lib/modules/Account/index.js +12 -12
- package/lib/modules/AccountList/index.js +11 -14
- package/lib/modules/BaseModule.d.ts +3 -0
- package/lib/modules/BaseModule.js +12 -6
- package/lib/modules/Cart/index.js +9 -14
- package/lib/modules/Cart/utils/cartProduct.js +6 -3
- package/lib/modules/Customer/constants.js +1 -1
- package/lib/modules/Customer/index.js +24 -28
- package/lib/modules/Customer/types.d.ts +1 -1
- package/lib/modules/Date/index.js +6 -10
- package/lib/modules/Date/types.js +0 -1
- package/lib/modules/Discount/index.js +7 -12
- package/lib/modules/Guests/index.js +24 -19
- package/lib/modules/Order/index.js +9 -11
- package/lib/modules/Payment/cash.js +1 -1
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +1 -1
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.js +86 -97
- package/lib/modules/Payment/types.d.ts +7 -7
- package/lib/modules/Payment/utils.js +6 -3
- package/lib/modules/Payment/walletpass.js +34 -32
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/index.js +5 -6
- package/lib/modules/ProductList/index.js +5 -8
- package/lib/modules/Resource/index.js +13 -9
- package/lib/modules/Rules/index.js +19 -15
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +5 -8
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +4 -2
- package/lib/modules/Step/index.js +4 -7
- package/lib/modules/Summary/index.js +4 -9
- package/lib/plugins/request.js +33 -34
- package/lib/plugins/window.js +113 -101
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +105 -71
- package/lib/solution/BookingByStep/utils/capacity.js +15 -10
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +8 -4
- package/lib/solution/BookingByStep/utils/stock.js +6 -3
- package/lib/solution/BookingByStep/utils/timeslots.js +27 -24
- package/lib/solution/BookingTicket/index.js +20 -25
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +3 -3
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +6 -6
- package/lib/solution/BookingTicket/utils/scan/index.js +1 -3
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +9 -10
- package/lib/solution/BuyTickets/index.js +22 -23
- package/lib/solution/Checkout/index.js +227 -234
- package/lib/solution/Checkout/utils/index.js +22 -18
- package/lib/solution/ShopDiscount/index.js +12 -16
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/task.d.ts +2 -2
- package/lib/utils/task.js +3 -3
- package/lib/utils/watch.d.ts +2 -2
- package/lib/utils/watch.js +7 -5
- package/package.json +1 -1
|
@@ -43,7 +43,8 @@ function calculateResourceAvailableTime({
|
|
|
43
43
|
const matchingTimes = resource.times.filter((time) => {
|
|
44
44
|
return (0, import_dayjs.default)(time.start_at).isSame((0, import_dayjs.default)(timeSlots.start_at), "day");
|
|
45
45
|
});
|
|
46
|
-
if (matchingTimes.length === 0)
|
|
46
|
+
if (matchingTimes.length === 0)
|
|
47
|
+
return 0;
|
|
47
48
|
const overlaps = [];
|
|
48
49
|
for (const time of matchingTimes) {
|
|
49
50
|
const overlapStart = (0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) ? (0, import_dayjs.default)(time.start_at) : (0, import_dayjs.default)(timeSlots.start_at);
|
|
@@ -52,7 +53,8 @@ function calculateResourceAvailableTime({
|
|
|
52
53
|
overlaps.push({ start: overlapStart, end: overlapEnd });
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
if (overlaps.length === 0)
|
|
56
|
+
if (overlaps.length === 0)
|
|
57
|
+
return 0;
|
|
56
58
|
overlaps.sort((a, b) => a.start.diff(b.start));
|
|
57
59
|
const merged = [];
|
|
58
60
|
let current = overlaps[0];
|
|
@@ -81,7 +83,7 @@ function findFastestAvailableResource({
|
|
|
81
83
|
const currentTime = (0, import_dayjs.default)();
|
|
82
84
|
let fastestTime = null;
|
|
83
85
|
let fastestResources = [];
|
|
84
|
-
console.log("[TimeslotUtils]
|
|
86
|
+
console.log("[TimeslotUtils] 查找最快可用资源:", {
|
|
85
87
|
currentTime: currentTime.format("YYYY-MM-DD HH:mm:ss"),
|
|
86
88
|
resourceCount: resources.length,
|
|
87
89
|
currentCapacity,
|
|
@@ -94,14 +96,14 @@ function findFastestAvailableResource({
|
|
|
94
96
|
return isToday && isStillWorking;
|
|
95
97
|
});
|
|
96
98
|
if (todayTimes.length === 0) {
|
|
97
|
-
console.log(`[TimeslotUtils]
|
|
99
|
+
console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}) 今日无可用时间段`);
|
|
98
100
|
continue;
|
|
99
101
|
}
|
|
100
102
|
for (const time of todayTimes) {
|
|
101
103
|
const workStartTime = (0, import_dayjs.default)(time.start_at);
|
|
102
104
|
const workEndTime = (0, import_dayjs.default)(time.end_at);
|
|
103
105
|
let nextAvailableTime = currentTime.isBefore(workStartTime) ? workStartTime : currentTime;
|
|
104
|
-
console.log(`[TimeslotUtils]
|
|
106
|
+
console.log(`[TimeslotUtils] 检查资源 ${resource.id}(${resource.main_field}):`, {
|
|
105
107
|
workTime: `${workStartTime.format("HH:mm")}-${workEndTime.format("HH:mm")}`,
|
|
106
108
|
checkStartTime: nextAvailableTime.format("HH:mm:ss"),
|
|
107
109
|
eventCount: ((_a = time.event_list) == null ? void 0 : _a.length) || 0
|
|
@@ -117,7 +119,7 @@ function findFastestAvailableResource({
|
|
|
117
119
|
for (const event of relevantEvents) {
|
|
118
120
|
const eventStart = (0, import_dayjs.default)(event.start_at);
|
|
119
121
|
const eventEnd = (0, import_dayjs.default)(event.end_at);
|
|
120
|
-
console.log(`[TimeslotUtils]
|
|
122
|
+
console.log(`[TimeslotUtils] 检查事件冲突:`, {
|
|
121
123
|
resourceId: resource.id,
|
|
122
124
|
eventTime: `${eventStart.format("HH:mm")}-${eventEnd.format("HH:mm")}`,
|
|
123
125
|
checkTime: finalAvailableTime.format("HH:mm:ss"),
|
|
@@ -126,7 +128,7 @@ function findFastestAvailableResource({
|
|
|
126
128
|
if (resource.resourceType === "single" || (resource.capacity || 1) === 1) {
|
|
127
129
|
if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(30, "minute"))) {
|
|
128
130
|
finalAvailableTime = eventEnd;
|
|
129
|
-
console.log(`[TimeslotUtils]
|
|
131
|
+
console.log(`[TimeslotUtils] 发现时间冲突,调整到: ${finalAvailableTime.format("HH:mm:ss")}`);
|
|
130
132
|
}
|
|
131
133
|
} else {
|
|
132
134
|
const totalCapacity = resource.capacity || 0;
|
|
@@ -136,46 +138,47 @@ function findFastestAvailableResource({
|
|
|
136
138
|
const totalRequiredCapacity = currentUsedCapacity + currentCapacity + eventUsedCapacity;
|
|
137
139
|
if (totalRequiredCapacity > totalCapacity) {
|
|
138
140
|
finalAvailableTime = eventEnd;
|
|
139
|
-
console.log(`[TimeslotUtils]
|
|
141
|
+
console.log(`[TimeslotUtils] 容量不足,调整到: ${finalAvailableTime.format("HH:mm:ss")}`);
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
if (finalAvailableTime.isAfter(workEndTime)) {
|
|
145
|
-
console.log(`[TimeslotUtils]
|
|
147
|
+
console.log(`[TimeslotUtils] 资源 ${resource.id} 可用时间超出工作时间,跳过`);
|
|
146
148
|
continue;
|
|
147
149
|
}
|
|
148
|
-
console.log(`[TimeslotUtils]
|
|
150
|
+
console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}) 最快可用时间: ${finalAvailableTime.format("HH:mm:ss")}`);
|
|
149
151
|
if (!fastestTime || finalAvailableTime.isBefore(fastestTime)) {
|
|
150
152
|
fastestTime = finalAvailableTime;
|
|
151
153
|
fastestResources = [resource];
|
|
152
|
-
console.log(`[TimeslotUtils]
|
|
154
|
+
console.log(`[TimeslotUtils] 更新最快时间: ${fastestTime.format("HH:mm:ss")}, 资源: ${resource.main_field}`);
|
|
153
155
|
} else if (finalAvailableTime.isSame(fastestTime)) {
|
|
154
156
|
fastestResources.push(resource);
|
|
155
|
-
console.log(`[TimeslotUtils]
|
|
157
|
+
console.log(`[TimeslotUtils] 添加相同时间资源: ${resource.main_field}`);
|
|
156
158
|
}
|
|
157
159
|
break;
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
if (!fastestTime || fastestResources.length === 0) {
|
|
161
|
-
console.log("[TimeslotUtils]
|
|
163
|
+
console.log("[TimeslotUtils] 未找到可用资源");
|
|
162
164
|
return null;
|
|
163
165
|
}
|
|
164
|
-
console.log(`[TimeslotUtils]
|
|
166
|
+
console.log(`[TimeslotUtils] 找到 ${fastestResources.length} 个最快可用资源,时间: ${fastestTime.format("HH:mm:ss")}`);
|
|
165
167
|
if (fastestResources.length === 1) {
|
|
166
|
-
console.log(`[TimeslotUtils]
|
|
168
|
+
console.log(`[TimeslotUtils] 返回唯一最快资源: ${fastestResources[0].main_field}`);
|
|
167
169
|
return fastestResources[0];
|
|
168
170
|
}
|
|
169
171
|
let selectedResource = fastestResources[0];
|
|
170
172
|
let maxIdleTime = 0;
|
|
171
|
-
console.log(`[TimeslotUtils]
|
|
173
|
+
console.log(`[TimeslotUtils] 比较 ${fastestResources.length} 个资源的空闲时间:`);
|
|
172
174
|
for (const resource of fastestResources) {
|
|
173
175
|
const workingTime = resource.times.find((time) => {
|
|
174
176
|
const isToday = (0, import_dayjs.default)(time.start_at).isSame(fastestTime, "day");
|
|
175
177
|
const isStillWorking = (0, import_dayjs.default)(time.end_at).isAfter(fastestTime);
|
|
176
178
|
return isToday && isStillWorking;
|
|
177
179
|
});
|
|
178
|
-
if (!workingTime)
|
|
180
|
+
if (!workingTime)
|
|
181
|
+
continue;
|
|
179
182
|
const workEndTime = (0, import_dayjs.default)(workingTime.end_at);
|
|
180
183
|
let totalIdleTime = workEndTime.diff(fastestTime, "minute");
|
|
181
184
|
const relevantEvents = ((_c = workingTime.event_list) == null ? void 0 : _c.filter((event) => {
|
|
@@ -189,19 +192,19 @@ function findFastestAvailableResource({
|
|
|
189
192
|
const eventDuration = eventEnd.diff(eventStart, "minute");
|
|
190
193
|
totalIdleTime -= eventDuration;
|
|
191
194
|
}
|
|
192
|
-
console.log(`[TimeslotUtils]
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}):`, {
|
|
196
|
+
工作结束时间: workEndTime.format("HH:mm"),
|
|
197
|
+
总工作时长: workEndTime.diff(fastestTime, "minute") + "分钟",
|
|
198
|
+
预约占用时长: workEndTime.diff(fastestTime, "minute") - totalIdleTime + "分钟",
|
|
199
|
+
实际空闲时长: totalIdleTime + "分钟"
|
|
197
200
|
});
|
|
198
201
|
if (totalIdleTime > maxIdleTime) {
|
|
199
202
|
maxIdleTime = totalIdleTime;
|
|
200
203
|
selectedResource = resource;
|
|
201
|
-
console.log(`[TimeslotUtils]
|
|
204
|
+
console.log(`[TimeslotUtils] 更新最佳选择: ${resource.main_field} (空闲${totalIdleTime}分钟)`);
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
|
-
console.log(`[TimeslotUtils]
|
|
207
|
+
console.log(`[TimeslotUtils] 最终选择资源: ${selectedResource.main_field} (最长空闲${maxIdleTime}分钟)`);
|
|
205
208
|
return selectedResource;
|
|
206
209
|
}
|
|
207
210
|
function filterConditionTimeSlots(times, startTime, endTime) {
|
|
@@ -41,32 +41,27 @@ var import_handleScan = require("./utils/scan/handleScan");
|
|
|
41
41
|
var import_scanCache = __toESM(require("./utils/scan/scanCache"));
|
|
42
42
|
__reExport(BookingTicket_exports, require("./types"), module.exports);
|
|
43
43
|
var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
otherParams = {};
|
|
52
|
-
cacheId;
|
|
53
|
-
platform;
|
|
54
|
-
// 平台类型,用于判断是 PC / H5
|
|
55
|
-
scan;
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments);
|
|
46
|
+
this.defaultName = "bookingTicket";
|
|
47
|
+
this.defaultVersion = "1.0.0";
|
|
48
|
+
this.isSolution = true;
|
|
49
|
+
this.otherParams = {};
|
|
50
|
+
}
|
|
56
51
|
async initialize(core, options) {
|
|
57
52
|
var _a, _b, _c;
|
|
58
53
|
this.core = core;
|
|
59
54
|
this.store = options.store || {};
|
|
60
55
|
this.otherParams = options.otherParams || {};
|
|
61
|
-
console.log("[BookingTicket]
|
|
56
|
+
console.log("[BookingTicket] 初始化完成");
|
|
62
57
|
this.request = core.getPlugin("request");
|
|
63
58
|
this.window = core.getPlugin("window");
|
|
64
59
|
this.shopStore = core.getPlugin("shopStore");
|
|
65
60
|
if (!this.request) {
|
|
66
|
-
throw new Error("bookingTicket
|
|
61
|
+
throw new Error("bookingTicket解决方案需要 request 插件支持");
|
|
67
62
|
}
|
|
68
63
|
if (!this.shopStore) {
|
|
69
|
-
throw new Error("bookingTicket
|
|
64
|
+
throw new Error("bookingTicket解决方案需要 shopStore 插件支持");
|
|
70
65
|
}
|
|
71
66
|
let targetCacheData = {};
|
|
72
67
|
this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
|
|
@@ -101,10 +96,10 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
101
96
|
}
|
|
102
97
|
});
|
|
103
98
|
} else {
|
|
104
|
-
throw new Error(
|
|
99
|
+
throw new Error(`模块 ${step} 不存在`);
|
|
105
100
|
}
|
|
106
101
|
});
|
|
107
|
-
this.core.effects.emit(
|
|
102
|
+
this.core.effects.emit(`${this.name}:onInited`, {});
|
|
108
103
|
}
|
|
109
104
|
/**
|
|
110
105
|
* 获取商品列表
|
|
@@ -120,7 +115,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
120
115
|
...params,
|
|
121
116
|
cacheId: this.cacheId
|
|
122
117
|
});
|
|
123
|
-
this.core.effects.emit(
|
|
118
|
+
this.core.effects.emit(`${this.name}:onProductsLoaded`, result);
|
|
124
119
|
return result;
|
|
125
120
|
} catch (error) {
|
|
126
121
|
console.error("Failed to load products:", error);
|
|
@@ -154,7 +149,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
154
149
|
*/
|
|
155
150
|
setActiveCustomer(customer) {
|
|
156
151
|
this.store.customer.setSelectedCustomer(customer);
|
|
157
|
-
this.core.effects.emit(
|
|
152
|
+
this.core.effects.emit(`${this.name}:onCustomerSelected`, {
|
|
158
153
|
customer
|
|
159
154
|
});
|
|
160
155
|
}
|
|
@@ -173,7 +168,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
173
168
|
const customer = this.store.customer.getCustomerById(customerId);
|
|
174
169
|
if (customer) {
|
|
175
170
|
this.store.customer.setSelectedCustomer(customer);
|
|
176
|
-
this.core.effects.emit(
|
|
171
|
+
this.core.effects.emit(`${this.name}:onCustomerSelected`, {
|
|
177
172
|
customer
|
|
178
173
|
});
|
|
179
174
|
}
|
|
@@ -253,7 +248,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
253
248
|
async loadMoreCustomers() {
|
|
254
249
|
try {
|
|
255
250
|
const result = await this.store.customer.loadMoreCustomers();
|
|
256
|
-
this.core.effects.emit(
|
|
251
|
+
this.core.effects.emit(`${this.name}:onCustomerListUpdate`, result);
|
|
257
252
|
return result;
|
|
258
253
|
} catch (error) {
|
|
259
254
|
console.error("Failed to load more customers:", error);
|
|
@@ -268,7 +263,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
268
263
|
async resetAndLoadCustomers(params = {}) {
|
|
269
264
|
try {
|
|
270
265
|
const result = await this.store.customer.resetAndLoadCustomers(params);
|
|
271
|
-
this.core.effects.emit(
|
|
266
|
+
this.core.effects.emit(`${this.name}:onCustomerListReset`, result);
|
|
272
267
|
return result;
|
|
273
268
|
} catch (error) {
|
|
274
269
|
console.error("Failed to reset and load customers:", error);
|
|
@@ -307,7 +302,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
307
302
|
try {
|
|
308
303
|
callback(d);
|
|
309
304
|
} catch (error) {
|
|
310
|
-
console.error("scanGlobalListener
|
|
305
|
+
console.error("scanGlobalListener传入的回调函数异常", error);
|
|
311
306
|
}
|
|
312
307
|
};
|
|
313
308
|
const listener = { key: "global", callback: safeCallback };
|
|
@@ -324,7 +319,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
324
319
|
try {
|
|
325
320
|
callback(d);
|
|
326
321
|
} catch (error) {
|
|
327
|
-
console.error("scanCustomerListener
|
|
322
|
+
console.error("scanCustomerListener传入的回调函数异常", error);
|
|
328
323
|
}
|
|
329
324
|
};
|
|
330
325
|
const listener = { key: "customer", callback: safeCallback };
|
|
@@ -343,7 +338,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
343
338
|
callback(d);
|
|
344
339
|
} catch (error) {
|
|
345
340
|
console.error(
|
|
346
|
-
`scanUniversalListener
|
|
341
|
+
`scanUniversalListener传入的回调函数异常, key: ${key}`,
|
|
347
342
|
error
|
|
348
343
|
);
|
|
349
344
|
}
|
|
@@ -57,7 +57,7 @@ var searchWalletPass = async (request, code) => {
|
|
|
57
57
|
if ((res == null ? void 0 : res.code) == 200 && !!(res == null ? void 0 : res.data)) {
|
|
58
58
|
return { searchType: "walletPass", response: res };
|
|
59
59
|
}
|
|
60
|
-
throw new Error("
|
|
60
|
+
throw new Error("没有找到对应的识别码");
|
|
61
61
|
} catch (error) {
|
|
62
62
|
throw error;
|
|
63
63
|
}
|
|
@@ -72,7 +72,7 @@ var searchWallet = async (request, code) => {
|
|
|
72
72
|
if ((res == null ? void 0 : res.code) == 200 && !!(res == null ? void 0 : res.data)) {
|
|
73
73
|
return { searchType: "wallet", response: res };
|
|
74
74
|
}
|
|
75
|
-
throw new Error("
|
|
75
|
+
throw new Error("没有找到对应的识别码");
|
|
76
76
|
} catch (error) {
|
|
77
77
|
throw error;
|
|
78
78
|
}
|
|
@@ -104,7 +104,7 @@ var searchProduct = async (request, code) => {
|
|
|
104
104
|
if ((res == null ? void 0 : res.code) == 200 && ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) > 0) {
|
|
105
105
|
return { searchType: "product", response: res };
|
|
106
106
|
}
|
|
107
|
-
throw new Error("
|
|
107
|
+
throw new Error("没有找到对应的识别码");
|
|
108
108
|
} catch (error) {
|
|
109
109
|
throw error;
|
|
110
110
|
}
|
|
@@ -66,28 +66,28 @@ var handleScanFn = (getRequestList, localSearch) => {
|
|
|
66
66
|
try {
|
|
67
67
|
const localResult = localSearch == null ? void 0 : localSearch(value);
|
|
68
68
|
if ((localResult == null ? void 0 : localResult.length) > 0) {
|
|
69
|
-
console.log("
|
|
69
|
+
console.log("本地搜索到数据>>>>>>>", localResult);
|
|
70
70
|
return {
|
|
71
71
|
searchType: "local_product",
|
|
72
72
|
response: { data: { list: localResult } }
|
|
73
73
|
};
|
|
74
74
|
} else {
|
|
75
|
-
console.log("
|
|
75
|
+
console.log("本地搜索无数据>>>>>>>");
|
|
76
76
|
}
|
|
77
77
|
} catch (error) {
|
|
78
|
-
console.error("
|
|
78
|
+
console.error("本地搜索到数据失败>>>>>>>", error);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
try {
|
|
82
82
|
if (import_scanCache.default.has(value)) {
|
|
83
83
|
const result = import_scanCache.default.get(value);
|
|
84
|
-
console.log("
|
|
84
|
+
console.log("缓存中搜索到数据>>>>>>>", result);
|
|
85
85
|
return result;
|
|
86
86
|
} else {
|
|
87
|
-
console.log("
|
|
87
|
+
console.log("缓存中无数据>>>>>>>");
|
|
88
88
|
}
|
|
89
89
|
} catch (error) {
|
|
90
|
-
console.error("
|
|
90
|
+
console.error("缓存中搜索数据失败>>>>>>>", error);
|
|
91
91
|
}
|
|
92
92
|
const requestList = (getRequestList == null ? void 0 : getRequestList(value)) || [];
|
|
93
93
|
if (requestList.length === 0) {
|
|
@@ -35,10 +35,8 @@ module.exports = __toCommonJS(scan_exports);
|
|
|
35
35
|
var import_watch = __toESM(require("../../../../utils/watch"));
|
|
36
36
|
var import_task = __toESM(require("../../../../utils/task"));
|
|
37
37
|
var Scan = class {
|
|
38
|
-
solution;
|
|
39
|
-
watchKey;
|
|
40
|
-
listenerConfig = /* @__PURE__ */ new Map();
|
|
41
38
|
constructor(solution, watchKey) {
|
|
39
|
+
this.listenerConfig = /* @__PURE__ */ new Map();
|
|
42
40
|
var _a, _b, _c, _d, _e;
|
|
43
41
|
this.solution = solution;
|
|
44
42
|
this.watchKey = watchKey;
|
|
@@ -29,7 +29,7 @@ var compressData = (data) => {
|
|
|
29
29
|
}
|
|
30
30
|
return JSON.stringify(data);
|
|
31
31
|
} catch (error) {
|
|
32
|
-
console.warn("
|
|
32
|
+
console.warn("数据压缩失败:", error);
|
|
33
33
|
return JSON.stringify(data);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
@@ -40,19 +40,17 @@ var decompressData = (compressedData) => {
|
|
|
40
40
|
}
|
|
41
41
|
return JSON.parse(compressedData);
|
|
42
42
|
} catch (error) {
|
|
43
|
-
console.warn("
|
|
43
|
+
console.warn("数据解压缩失败:", error);
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
var LRUCache = class {
|
|
48
|
-
head = null;
|
|
49
|
-
// 最久未使用的节点
|
|
50
|
-
tail = null;
|
|
51
|
-
// 最近使用的节点
|
|
52
|
-
keyMap = /* @__PURE__ */ new Map();
|
|
53
|
-
// key到节点的映射(只存储引用)
|
|
54
|
-
maxSize;
|
|
55
48
|
constructor(maxSize = 100) {
|
|
49
|
+
this.head = null;
|
|
50
|
+
// 最久未使用的节点
|
|
51
|
+
this.tail = null;
|
|
52
|
+
// 最近使用的节点
|
|
53
|
+
this.keyMap = /* @__PURE__ */ new Map();
|
|
56
54
|
this.maxSize = maxSize;
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
@@ -60,7 +58,8 @@ var LRUCache = class {
|
|
|
60
58
|
* @param node 要移动的节点
|
|
61
59
|
*/
|
|
62
60
|
moveToTail(node) {
|
|
63
|
-
if (this.tail === node)
|
|
61
|
+
if (this.tail === node)
|
|
62
|
+
return;
|
|
64
63
|
if (node.prev) {
|
|
65
64
|
node.prev.next = node.next;
|
|
66
65
|
}
|
|
@@ -24,35 +24,31 @@ __export(BuyTickets_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(BuyTickets_exports);
|
|
26
26
|
var import_modules = require("../../modules/");
|
|
27
|
-
var import_types = require("./types");
|
|
28
27
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
29
28
|
__reExport(BuyTickets_exports, require("./types"), module.exports);
|
|
30
29
|
var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
31
|
-
// 提供给 baseModule 用的默认名称 和 默认版本
|
|
32
|
-
defaultName = "buyTickets";
|
|
33
|
-
defaultVersion = "1.0.0";
|
|
34
|
-
isSolution = true;
|
|
35
|
-
request;
|
|
36
|
-
window;
|
|
37
|
-
store;
|
|
38
|
-
otherParams = {};
|
|
39
30
|
constructor(name, version) {
|
|
40
31
|
super(name, version);
|
|
32
|
+
// 提供给 baseModule 用的默认名称 和 默认版本
|
|
33
|
+
this.defaultName = "buyTickets";
|
|
34
|
+
this.defaultVersion = "1.0.0";
|
|
35
|
+
this.isSolution = true;
|
|
36
|
+
this.otherParams = {};
|
|
41
37
|
}
|
|
42
38
|
async initialize(core, options) {
|
|
43
39
|
this.core = core;
|
|
44
40
|
this.store = options.store || {};
|
|
45
41
|
this.otherParams = options.otherParams || {};
|
|
46
|
-
console.log("[BuyTickets]
|
|
42
|
+
console.log("[BuyTickets] 初始化完成");
|
|
47
43
|
this.request = core.getPlugin("request");
|
|
48
44
|
this.window = core.getPlugin("window");
|
|
49
45
|
if (!this.request) {
|
|
50
|
-
throw new Error("
|
|
46
|
+
throw new Error("购物车模块需要 request 插件支持");
|
|
51
47
|
}
|
|
52
48
|
if (this.otherParams.prodctIds) {
|
|
53
49
|
await this.loadProductsByIds(this.otherParams.prodctIds);
|
|
54
50
|
}
|
|
55
|
-
await this.core.effects.emit(
|
|
51
|
+
await this.core.effects.emit(`${this.name}:onInited`, {});
|
|
56
52
|
}
|
|
57
53
|
// 通过 ids 获取产品,在当前解决方案下,获取到的就是主商品
|
|
58
54
|
async loadProductsByIds(ids) {
|
|
@@ -72,21 +68,21 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
|
72
68
|
}
|
|
73
69
|
});
|
|
74
70
|
this.store.mainProducts = mainProducts;
|
|
75
|
-
await this.core.effects.emit(
|
|
71
|
+
await this.core.effects.emit(`${this.name}:onMainProductsLoaded`, {});
|
|
76
72
|
}
|
|
77
73
|
// 通过 ids 获取产品,在当前解决方案下,获取到的就是其他商品
|
|
78
74
|
async loadProductsByCategory(categoryId) {
|
|
79
75
|
}
|
|
80
76
|
async destroy() {
|
|
81
|
-
await this.core.effects.emit(
|
|
82
|
-
console.log("[BuyTickets]
|
|
77
|
+
await this.core.effects.emit(`${this.name}:onDestroy`, {});
|
|
78
|
+
console.log("[BuyTickets] 已销毁");
|
|
83
79
|
}
|
|
84
80
|
// 获取当前绑定的所有商品
|
|
85
81
|
async getProducts() {
|
|
86
82
|
var _a;
|
|
87
83
|
const mainData = await this.store.mainProducts.getProducts() || [];
|
|
88
84
|
const otherData = await ((_a = this.store.otherProducts) == null ? void 0 : _a.getProducts()) || [];
|
|
89
|
-
await this.core.effects.emit(
|
|
85
|
+
await this.core.effects.emit(`${this.name}:onGetProducts`, [
|
|
90
86
|
...mainData,
|
|
91
87
|
...otherData
|
|
92
88
|
]);
|
|
@@ -97,33 +93,36 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
|
97
93
|
var _a, _b;
|
|
98
94
|
const mainProduct = await ((_a = this.store.mainProducts) == null ? void 0 : _a.getProduct(id));
|
|
99
95
|
const otherProduct = await ((_b = this.store.otherProducts) == null ? void 0 : _b.getProduct(id));
|
|
100
|
-
if (mainProduct)
|
|
101
|
-
|
|
96
|
+
if (mainProduct)
|
|
97
|
+
return mainProduct;
|
|
98
|
+
if (otherProduct)
|
|
99
|
+
return otherProduct;
|
|
102
100
|
throw new Error(`Product not found: ${id}`);
|
|
103
101
|
}
|
|
104
102
|
// 商品列表页提交
|
|
105
103
|
async listSubmit(data) {
|
|
106
|
-
const res = await this.core.effects.emit(
|
|
104
|
+
const res = await this.core.effects.emit(`${this.name}:onListSubmit`, {
|
|
107
105
|
...data,
|
|
108
106
|
products: this.getProducts()
|
|
109
107
|
});
|
|
110
|
-
if (res.status === false)
|
|
108
|
+
if (res.status === false)
|
|
109
|
+
return res;
|
|
111
110
|
this.window.localStorage.setItem(
|
|
112
111
|
"buyTickets:listSubmit",
|
|
113
112
|
JSON.stringify({ ...data, products: this.getProducts() })
|
|
114
113
|
);
|
|
115
|
-
console.log("listSubmit
|
|
114
|
+
console.log("listSubmit 应该走逻辑层的 API 发请求了");
|
|
116
115
|
}
|
|
117
116
|
// 购物车提交
|
|
118
117
|
async cartSubmit(data) {
|
|
119
|
-
await this.core.effects.emit(
|
|
118
|
+
await this.core.effects.emit(`${this.name}:onCartSubmit`, {
|
|
120
119
|
...data,
|
|
121
120
|
products: this.getProducts()
|
|
122
121
|
});
|
|
123
122
|
}
|
|
124
123
|
// 结算提交
|
|
125
124
|
async checkoutSubmit(data) {
|
|
126
|
-
await this.core.effects.emit(
|
|
125
|
+
await this.core.effects.emit(`${this.name}:onCheckoutSubmit`, {
|
|
127
126
|
...data,
|
|
128
127
|
products: this.getProducts()
|
|
129
128
|
});
|