@pisell/pisellos 2.2.30 → 2.2.32
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/server/index.d.ts +20 -0
- package/dist/server/index.js +508 -125
- package/dist/server/modules/menu/index.d.ts +19 -0
- package/dist/server/modules/menu/index.js +220 -70
- package/dist/server/modules/products/index.d.ts +19 -0
- package/dist/server/modules/products/index.js +347 -116
- package/dist/server/modules/schedule/index.d.ts +19 -0
- package/dist/server/modules/schedule/index.js +227 -66
- package/dist/solution/Checkout/index.js +63 -55
- package/lib/server/index.d.ts +20 -0
- package/lib/server/index.js +288 -5
- package/lib/server/modules/menu/index.d.ts +19 -0
- package/lib/server/modules/menu/index.js +120 -1
- package/lib/server/modules/products/index.d.ts +19 -0
- package/lib/server/modules/products/index.js +203 -17
- package/lib/server/modules/schedule/index.d.ts +19 -0
- package/lib/server/modules/schedule/index.js +140 -11
- package/lib/solution/Checkout/index.js +8 -2
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -26,9 +26,14 @@ import { extractScheduleIdsFromMenus, extractTimePointsFromSchedules } from "./u
|
|
|
26
26
|
*/
|
|
27
27
|
var Server = /*#__PURE__*/function () {
|
|
28
28
|
function Server(core) {
|
|
29
|
-
var _this = this
|
|
29
|
+
var _this = this,
|
|
30
|
+
_this$app;
|
|
30
31
|
_classCallCheck(this, Server);
|
|
31
32
|
_defineProperty(this, "core", void 0);
|
|
33
|
+
_defineProperty(this, "app", void 0);
|
|
34
|
+
// App instance
|
|
35
|
+
_defineProperty(this, "logger", void 0);
|
|
36
|
+
// LoggerManager instance
|
|
32
37
|
// 模块实例
|
|
33
38
|
_defineProperty(this, "products", void 0);
|
|
34
39
|
_defineProperty(this, "menu", void 0);
|
|
@@ -89,18 +94,28 @@ var Server = /*#__PURE__*/function () {
|
|
|
89
94
|
*/
|
|
90
95
|
_defineProperty(this, "handleProductQuery", /*#__PURE__*/function () {
|
|
91
96
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
92
|
-
var
|
|
97
|
+
var _menu_list_ids$length;
|
|
98
|
+
var url, method, data, config, menu_list_ids, schedule_datetime, schedule_date, activeMenuList, menuList, _menu_list_ids$length2, allProductsWithPrice, filteredProducts;
|
|
93
99
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
94
100
|
while (1) switch (_context.prev = _context.next) {
|
|
95
101
|
case 0:
|
|
96
102
|
url = _ref.url, method = _ref.method, data = _ref.data, config = _ref.config;
|
|
97
103
|
console.log('[Server] handleProductQuery:', url, method, data, config);
|
|
98
|
-
menu_list_ids = data.menu_list_ids, schedule_datetime = data.schedule_datetime, schedule_date = data.schedule_date;
|
|
104
|
+
menu_list_ids = data.menu_list_ids, schedule_datetime = data.schedule_datetime, schedule_date = data.schedule_date;
|
|
105
|
+
_this.logInfo('handleProductQuery 开始处理', {
|
|
106
|
+
menuListIdsCount: (_menu_list_ids$length = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length !== void 0 ? _menu_list_ids$length : 0,
|
|
107
|
+
schedule_datetime: schedule_datetime,
|
|
108
|
+
schedule_date: schedule_date,
|
|
109
|
+
menu_list_ids: menu_list_ids
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// 检查必要的模块是否已注册
|
|
99
113
|
if (_this.products) {
|
|
100
|
-
_context.next =
|
|
114
|
+
_context.next = 8;
|
|
101
115
|
break;
|
|
102
116
|
}
|
|
103
117
|
console.error('[Server] Products 模块未注册');
|
|
118
|
+
_this.logError('handleProductQuery: Products 模块未注册');
|
|
104
119
|
return _context.abrupt("return", {
|
|
105
120
|
message: 'Products 模块未注册',
|
|
106
121
|
data: {
|
|
@@ -108,12 +123,13 @@ var Server = /*#__PURE__*/function () {
|
|
|
108
123
|
count: 0
|
|
109
124
|
}
|
|
110
125
|
});
|
|
111
|
-
case
|
|
126
|
+
case 8:
|
|
112
127
|
if (_this.menu) {
|
|
113
|
-
_context.next =
|
|
128
|
+
_context.next = 12;
|
|
114
129
|
break;
|
|
115
130
|
}
|
|
116
131
|
console.error('[Server] Menu 模块未注册');
|
|
132
|
+
_this.logError('handleProductQuery: Menu 模块未注册');
|
|
117
133
|
return _context.abrupt("return", {
|
|
118
134
|
message: 'Menu 模块未注册',
|
|
119
135
|
data: {
|
|
@@ -121,12 +137,13 @@ var Server = /*#__PURE__*/function () {
|
|
|
121
137
|
count: 0
|
|
122
138
|
}
|
|
123
139
|
});
|
|
124
|
-
case
|
|
140
|
+
case 12:
|
|
125
141
|
if (_this.schedule) {
|
|
126
|
-
_context.next =
|
|
142
|
+
_context.next = 16;
|
|
127
143
|
break;
|
|
128
144
|
}
|
|
129
145
|
console.error('[Server] Schedule 模块未注册');
|
|
146
|
+
_this.logError('handleProductQuery: Schedule 模块未注册');
|
|
130
147
|
return _context.abrupt("return", {
|
|
131
148
|
message: 'Schedule 模块未注册',
|
|
132
149
|
data: {
|
|
@@ -134,32 +151,66 @@ var Server = /*#__PURE__*/function () {
|
|
|
134
151
|
count: 0
|
|
135
152
|
}
|
|
136
153
|
});
|
|
137
|
-
case
|
|
154
|
+
case 16:
|
|
138
155
|
// 生效的餐牌列表
|
|
139
156
|
activeMenuList = []; // 如果有 menu_list_ids,获取对应的餐牌详情
|
|
140
157
|
if (menu_list_ids && Array.isArray(menu_list_ids) && menu_list_ids.length > 0) {
|
|
141
158
|
console.log('[Server] 获取餐牌详情,IDs:', menu_list_ids);
|
|
159
|
+
_this.logInfo('handleProductQuery: 获取餐牌详情', {
|
|
160
|
+
menuListIdsCount: menu_list_ids.length,
|
|
161
|
+
menu_list_ids: menu_list_ids
|
|
162
|
+
});
|
|
142
163
|
|
|
143
164
|
// 从 Menu 模块获取餐牌详情
|
|
144
165
|
menuList = _this.menu.getMenuByIds(menu_list_ids);
|
|
166
|
+
_this.logInfo('handleProductQuery: 获取到餐牌列表', {
|
|
167
|
+
requestedCount: menu_list_ids.length,
|
|
168
|
+
foundCount: menuList.length,
|
|
169
|
+
menu_list_ids: menu_list_ids,
|
|
170
|
+
menuList: menuList
|
|
171
|
+
});
|
|
145
172
|
activeMenuList = menuList.filter(function (menu) {
|
|
146
173
|
var _this$schedule;
|
|
147
|
-
|
|
174
|
+
var isInSchedule = ((_this$schedule = _this.schedule) === null || _this$schedule === void 0 ? void 0 : _this$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
|
|
175
|
+
return isInSchedule;
|
|
176
|
+
});
|
|
177
|
+
_this.logInfo('handleProductQuery: 过滤生效餐牌', {
|
|
178
|
+
totalMenuCount: menuList.length,
|
|
179
|
+
activeMenuCount: activeMenuList.length,
|
|
180
|
+
schedule_datetime: schedule_datetime,
|
|
181
|
+
menuList: menuList,
|
|
182
|
+
activeMenuList: activeMenuList
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
_this.logWarning('handleProductQuery: 未提供有效的 menu_list_ids', {
|
|
186
|
+
menuListIdsCount: (_menu_list_ids$length2 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length2 !== void 0 ? _menu_list_ids$length2 : 0,
|
|
187
|
+
menu_list_ids: menu_list_ids
|
|
148
188
|
});
|
|
149
189
|
}
|
|
150
190
|
console.log(activeMenuList, 'activeMenuList');
|
|
151
191
|
|
|
152
192
|
// 获取应用了价格的商品列表(带缓存,同一天直接返回缓存的商品)
|
|
153
193
|
// 传入 scheduleList 以便格式化器计算商品的可用时间段
|
|
154
|
-
|
|
194
|
+
_this.logInfo('handleProductQuery: 开始获取商品列表', {
|
|
195
|
+
schedule_date: schedule_date
|
|
196
|
+
});
|
|
197
|
+
_context.next = 22;
|
|
155
198
|
return _this.products.getProductsWithPrice(data.schedule_date, {
|
|
156
199
|
scheduleModule: _this.getSchedule()
|
|
157
200
|
});
|
|
158
|
-
case
|
|
201
|
+
case 22:
|
|
159
202
|
allProductsWithPrice = _context.sent;
|
|
203
|
+
_this.logInfo('handleProductQuery: 获取到商品列表', {
|
|
204
|
+
productCount: allProductsWithPrice.length,
|
|
205
|
+
schedule_date: schedule_date
|
|
206
|
+
});
|
|
160
207
|
console.log(allProductsWithPrice, 'allProductsWithPrice');
|
|
161
208
|
|
|
162
209
|
//根据生效的餐牌配置过滤商品
|
|
210
|
+
_this.logInfo('handleProductQuery: 开始按餐牌配置过滤商品', {
|
|
211
|
+
totalProducts: allProductsWithPrice.length,
|
|
212
|
+
activeMenuCount: activeMenuList.length
|
|
213
|
+
});
|
|
163
214
|
filteredProducts = _this.filterProductsByMenuConfig(allProductsWithPrice, activeMenuList); // 排序:优先使用 sort 排序,如果相同则使用 title 排序
|
|
164
215
|
filteredProducts = filteredProducts.sort(function (a, b) {
|
|
165
216
|
var sortDiff = Number(b.sort) - Number(a.sort);
|
|
@@ -172,6 +223,13 @@ var Server = /*#__PURE__*/function () {
|
|
|
172
223
|
console.log('[Server] 原始商品数量:', allProductsWithPrice.length);
|
|
173
224
|
console.log('[Server] 过滤后商品数量:', filteredProducts.length);
|
|
174
225
|
console.log(filteredProducts, 'filteredProducts');
|
|
226
|
+
_this.logInfo('handleProductQuery 处理完成', {
|
|
227
|
+
originalProductCount: allProductsWithPrice.length,
|
|
228
|
+
filteredProductCount: filteredProducts.length,
|
|
229
|
+
activeMenuCount: activeMenuList.length,
|
|
230
|
+
schedule_date: schedule_date,
|
|
231
|
+
schedule_datetime: schedule_datetime
|
|
232
|
+
});
|
|
175
233
|
|
|
176
234
|
// 返回组合后的数据
|
|
177
235
|
return _context.abrupt("return", {
|
|
@@ -183,7 +241,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
183
241
|
message: '',
|
|
184
242
|
status: true
|
|
185
243
|
});
|
|
186
|
-
case
|
|
244
|
+
case 33:
|
|
187
245
|
case "end":
|
|
188
246
|
return _context.stop();
|
|
189
247
|
}
|
|
@@ -199,103 +257,150 @@ var Server = /*#__PURE__*/function () {
|
|
|
199
257
|
*/
|
|
200
258
|
_defineProperty(this, "handleGetScheduleTimePoints", /*#__PURE__*/function () {
|
|
201
259
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
|
|
202
|
-
var
|
|
260
|
+
var _menu_list_ids$length3;
|
|
261
|
+
var url, method, data, config, menu_list_ids, _menu_list_ids$length4, menuList, scheduleIds, scheduleList, timePoints, errorMessage;
|
|
203
262
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
204
263
|
while (1) switch (_context2.prev = _context2.next) {
|
|
205
264
|
case 0:
|
|
206
265
|
url = _ref3.url, method = _ref3.method, data = _ref3.data, config = _ref3.config;
|
|
207
266
|
console.log('[Server] handleGetScheduleTimePoints:', url, method, data, config);
|
|
208
|
-
menu_list_ids = data.menu_list_ids;
|
|
267
|
+
menu_list_ids = data.menu_list_ids;
|
|
268
|
+
_this.logInfo('handleGetScheduleTimePoints 开始处理', {
|
|
269
|
+
menuListIdsCount: (_menu_list_ids$length3 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length3 !== void 0 ? _menu_list_ids$length3 : 0,
|
|
270
|
+
menu_list_ids: menu_list_ids
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// 检查必要的模块是否已注册
|
|
209
274
|
if (_this.menu) {
|
|
210
|
-
_context2.next =
|
|
275
|
+
_context2.next = 8;
|
|
211
276
|
break;
|
|
212
277
|
}
|
|
213
278
|
console.error('[Server] Menu 模块未注册');
|
|
279
|
+
_this.logError('handleGetScheduleTimePoints: Menu 模块未注册');
|
|
214
280
|
return _context2.abrupt("return", {
|
|
215
281
|
code: 500,
|
|
216
282
|
message: 'Menu 模块未注册',
|
|
217
283
|
data: [],
|
|
218
284
|
status: false
|
|
219
285
|
});
|
|
220
|
-
case
|
|
286
|
+
case 8:
|
|
221
287
|
if (_this.schedule) {
|
|
222
|
-
_context2.next =
|
|
288
|
+
_context2.next = 12;
|
|
223
289
|
break;
|
|
224
290
|
}
|
|
225
291
|
console.error('[Server] Schedule 模块未注册');
|
|
292
|
+
_this.logError('handleGetScheduleTimePoints: Schedule 模块未注册');
|
|
226
293
|
return _context2.abrupt("return", {
|
|
227
294
|
code: 500,
|
|
228
295
|
message: 'Schedule 模块未注册',
|
|
229
296
|
data: [],
|
|
230
297
|
status: false
|
|
231
298
|
});
|
|
232
|
-
case
|
|
299
|
+
case 12:
|
|
233
300
|
if (!(!menu_list_ids || !Array.isArray(menu_list_ids) || menu_list_ids.length === 0)) {
|
|
234
|
-
_context2.next =
|
|
301
|
+
_context2.next = 16;
|
|
235
302
|
break;
|
|
236
303
|
}
|
|
237
304
|
console.error('[Server] menu_list_ids 参数无效');
|
|
305
|
+
_this.logWarning('handleGetScheduleTimePoints: menu_list_ids 参数无效', {
|
|
306
|
+
menuListIdsCount: (_menu_list_ids$length4 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length4 !== void 0 ? _menu_list_ids$length4 : 0,
|
|
307
|
+
menu_list_ids: menu_list_ids
|
|
308
|
+
});
|
|
238
309
|
return _context2.abrupt("return", {
|
|
239
310
|
code: 400,
|
|
240
311
|
message: 'menu_list_ids 参数无效',
|
|
241
312
|
data: [],
|
|
242
313
|
status: false
|
|
243
314
|
});
|
|
244
|
-
case
|
|
245
|
-
_context2.prev =
|
|
315
|
+
case 16:
|
|
316
|
+
_context2.prev = 16;
|
|
246
317
|
// 1. 获取餐牌列表
|
|
247
318
|
menuList = _this.menu.getMenuByIds(menu_list_ids);
|
|
248
319
|
console.log("[Server] \u627E\u5230 ".concat(menuList.length, " \u4E2A\u9910\u724C"));
|
|
320
|
+
_this.logInfo('handleGetScheduleTimePoints: 获取到餐牌列表', {
|
|
321
|
+
requestedCount: menu_list_ids.length,
|
|
322
|
+
foundCount: menuList.length,
|
|
323
|
+
menu_list_ids: menu_list_ids,
|
|
324
|
+
menuList: menuList
|
|
325
|
+
});
|
|
249
326
|
|
|
250
327
|
// 2. 提取所有的 schedule IDs
|
|
251
328
|
scheduleIds = extractScheduleIdsFromMenus(menuList);
|
|
252
329
|
console.log("[Server] \u63D0\u53D6\u5230 ".concat(scheduleIds.length, " \u4E2A\u65E5\u7A0BID:"), scheduleIds);
|
|
330
|
+
_this.logInfo('handleGetScheduleTimePoints: 提取到日程 IDs', {
|
|
331
|
+
scheduleCount: scheduleIds.length
|
|
332
|
+
});
|
|
253
333
|
if (!(scheduleIds.length === 0)) {
|
|
254
|
-
_context2.next =
|
|
334
|
+
_context2.next = 26;
|
|
255
335
|
break;
|
|
256
336
|
}
|
|
337
|
+
_this.logInfo('handleGetScheduleTimePoints: 没有找到相关日程', {
|
|
338
|
+
menuListIdsCount: menu_list_ids.length
|
|
339
|
+
});
|
|
257
340
|
return _context2.abrupt("return", {
|
|
258
341
|
code: 200,
|
|
259
342
|
message: '没有找到相关日程',
|
|
260
343
|
data: [],
|
|
261
344
|
status: true
|
|
262
345
|
});
|
|
263
|
-
case
|
|
346
|
+
case 26:
|
|
264
347
|
// 3. 获取日程详情
|
|
265
348
|
scheduleList = _this.schedule.getScheduleByIds(scheduleIds);
|
|
266
349
|
console.log("[Server] \u627E\u5230 ".concat(scheduleList.length, " \u4E2A\u65E5\u7A0B"));
|
|
350
|
+
_this.logInfo('handleGetScheduleTimePoints: 获取到日程详情', {
|
|
351
|
+
requestedCount: scheduleIds.length,
|
|
352
|
+
foundCount: scheduleList.length
|
|
353
|
+
});
|
|
267
354
|
|
|
268
355
|
// 4. 提取时间点
|
|
269
356
|
timePoints = extractTimePointsFromSchedules(scheduleList);
|
|
270
357
|
console.log("[Server] \u63D0\u53D6\u5230 ".concat(timePoints.length, " \u4E2A\u65F6\u95F4\u70B9:"), timePoints);
|
|
358
|
+
_this.logInfo('handleGetScheduleTimePoints 处理完成', {
|
|
359
|
+
menuListIdsCount: menu_list_ids.length,
|
|
360
|
+
menuCount: menuList.length,
|
|
361
|
+
scheduleCount: scheduleList.length,
|
|
362
|
+
timePointCount: timePoints.length
|
|
363
|
+
});
|
|
271
364
|
return _context2.abrupt("return", {
|
|
272
365
|
code: 200,
|
|
273
366
|
message: '获取成功',
|
|
274
367
|
data: timePoints,
|
|
275
368
|
status: true
|
|
276
369
|
});
|
|
277
|
-
case
|
|
278
|
-
_context2.prev =
|
|
279
|
-
_context2.t0 = _context2["catch"](
|
|
370
|
+
case 35:
|
|
371
|
+
_context2.prev = 35;
|
|
372
|
+
_context2.t0 = _context2["catch"](16);
|
|
373
|
+
errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : '未知错误';
|
|
280
374
|
console.error('[Server] 获取日程时间点失败:', _context2.t0);
|
|
375
|
+
_this.logError('handleGetScheduleTimePoints: 获取日程时间点失败', {
|
|
376
|
+
menuListIdsCount: menu_list_ids.length,
|
|
377
|
+
error: errorMessage
|
|
378
|
+
});
|
|
281
379
|
return _context2.abrupt("return", {
|
|
282
380
|
code: 500,
|
|
283
|
-
message: "\u83B7\u53D6\u5931\u8D25: ".concat(
|
|
381
|
+
message: "\u83B7\u53D6\u5931\u8D25: ".concat(errorMessage),
|
|
284
382
|
data: [],
|
|
285
383
|
status: false
|
|
286
384
|
});
|
|
287
|
-
case
|
|
385
|
+
case 41:
|
|
288
386
|
case "end":
|
|
289
387
|
return _context2.stop();
|
|
290
388
|
}
|
|
291
|
-
}, _callee2, null, [[
|
|
389
|
+
}, _callee2, null, [[16, 35]]);
|
|
292
390
|
}));
|
|
293
391
|
return function (_x2) {
|
|
294
392
|
return _ref4.apply(this, arguments);
|
|
295
393
|
};
|
|
296
394
|
}());
|
|
297
395
|
this.core = core;
|
|
396
|
+
var appPlugin = core.getPlugin('app');
|
|
397
|
+
this.app = (appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp()) || null;
|
|
398
|
+
this.logger = ((_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.logger) || null;
|
|
298
399
|
console.log('[Server] Server 初始化');
|
|
400
|
+
this.logInfo('Server 初始化', {
|
|
401
|
+
hasApp: !!this.app,
|
|
402
|
+
hasLogger: !!this.logger
|
|
403
|
+
});
|
|
299
404
|
}
|
|
300
405
|
|
|
301
406
|
/**
|
|
@@ -312,15 +417,27 @@ var Server = /*#__PURE__*/function () {
|
|
|
312
417
|
handler = route.handler;
|
|
313
418
|
if (!_this2.router[method]) {
|
|
314
419
|
console.warn("[Server] \u4E0D\u652F\u6301\u7684 HTTP \u65B9\u6CD5: ".concat(method));
|
|
420
|
+
_this2.logWarning("\u4E0D\u652F\u6301\u7684 HTTP \u65B9\u6CD5", {
|
|
421
|
+
method: method,
|
|
422
|
+
path: path
|
|
423
|
+
});
|
|
315
424
|
return;
|
|
316
425
|
}
|
|
317
426
|
|
|
318
427
|
// 检查路由是否已存在
|
|
319
428
|
if (_this2.router[method][path]) {
|
|
320
429
|
console.warn("[Server] \u8DEF\u7531\u5DF2\u5B58\u5728\uFF0C\u5C06\u88AB\u8986\u76D6: ".concat(method.toUpperCase(), " ").concat(path));
|
|
430
|
+
_this2.logWarning("\u8DEF\u7531\u5DF2\u5B58\u5728\uFF0C\u5C06\u88AB\u8986\u76D6", {
|
|
431
|
+
method: method,
|
|
432
|
+
path: path
|
|
433
|
+
});
|
|
321
434
|
}
|
|
322
435
|
_this2.router[method][path] = handler;
|
|
323
436
|
console.log("[Server] \uD83D\uDCDD \u6CE8\u518C\u8DEF\u7531: ".concat(method.toUpperCase(), " ").concat(path));
|
|
437
|
+
_this2.logInfo("\u6CE8\u518C\u8DEF\u7531", {
|
|
438
|
+
method: method.toUpperCase(),
|
|
439
|
+
path: path
|
|
440
|
+
});
|
|
324
441
|
});
|
|
325
442
|
}
|
|
326
443
|
|
|
@@ -338,19 +455,32 @@ var Server = /*#__PURE__*/function () {
|
|
|
338
455
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
339
456
|
while (1) switch (_context3.prev = _context3.next) {
|
|
340
457
|
case 0:
|
|
341
|
-
|
|
458
|
+
this.logInfo("\u5F00\u59CB\u6CE8\u518C\u6A21\u5757: ".concat(moduleName), {
|
|
459
|
+
moduleName: moduleName,
|
|
460
|
+
options: options
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// 注册模块到 Core
|
|
464
|
+
_context3.next = 3;
|
|
342
465
|
return this.core.registerModule(module, options);
|
|
343
|
-
case
|
|
466
|
+
case 3:
|
|
344
467
|
console.log("[Server] \u2705 ".concat(moduleName, " \u6A21\u5757\u5DF2\u6CE8\u518C"));
|
|
468
|
+
this.logInfo("\u6A21\u5757\u6CE8\u518C\u6210\u529F: ".concat(moduleName), {
|
|
469
|
+
moduleName: moduleName
|
|
470
|
+
});
|
|
345
471
|
|
|
346
472
|
// 自动注册模块的路由
|
|
347
473
|
if (typeof module.getRoutes === 'function') {
|
|
348
474
|
routes = module.getRoutes();
|
|
349
475
|
if (routes && routes.length > 0) {
|
|
350
476
|
this.registerRoutes(routes);
|
|
477
|
+
this.logInfo("\u6A21\u5757\u8DEF\u7531\u5DF2\u6CE8\u518C: ".concat(moduleName), {
|
|
478
|
+
moduleName: moduleName,
|
|
479
|
+
routesCount: routes.length
|
|
480
|
+
});
|
|
351
481
|
}
|
|
352
482
|
}
|
|
353
|
-
case
|
|
483
|
+
case 6:
|
|
354
484
|
case "end":
|
|
355
485
|
return _context3.stop();
|
|
356
486
|
}
|
|
@@ -377,31 +507,46 @@ var Server = /*#__PURE__*/function () {
|
|
|
377
507
|
// 解析配置
|
|
378
508
|
moduleName = typeof moduleConfig === 'string' ? moduleConfig : moduleConfig.name;
|
|
379
509
|
shouldPreload = _typeof(moduleConfig) === 'object' ? moduleConfig.preload !== false : true;
|
|
380
|
-
customConfig = _typeof(moduleConfig) === 'object' ? moduleConfig.config : {};
|
|
510
|
+
customConfig = _typeof(moduleConfig) === 'object' ? moduleConfig.config : {};
|
|
511
|
+
this.logInfo("\u89E3\u6790\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
|
|
512
|
+
moduleName: moduleName,
|
|
513
|
+
shouldPreload: shouldPreload,
|
|
514
|
+
customConfig: customConfig
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
// 查找模块配置
|
|
381
518
|
registryConfig = this.moduleRegistry[moduleName];
|
|
382
519
|
if (registryConfig) {
|
|
383
|
-
_context4.next =
|
|
520
|
+
_context4.next = 8;
|
|
384
521
|
break;
|
|
385
522
|
}
|
|
523
|
+
this.logError("\u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
|
|
524
|
+
moduleName: moduleName
|
|
525
|
+
});
|
|
386
526
|
throw new Error("[Server] \u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName));
|
|
387
|
-
case
|
|
527
|
+
case 8:
|
|
388
528
|
// 创建模块实例
|
|
389
529
|
ModuleClass = registryConfig.moduleClass;
|
|
390
530
|
moduleInstance = new ModuleClass(registryConfig.moduleName, registryConfig.version); // 合并配置
|
|
391
531
|
moduleOptions = _objectSpread({
|
|
392
532
|
store: _objectSpread({}, registryConfig.defaultStore)
|
|
393
533
|
}, customConfig); // 注册模块和路由
|
|
394
|
-
_context4.next =
|
|
534
|
+
_context4.next = 13;
|
|
395
535
|
return this.registerModuleWithRoutes(moduleInstance, moduleOptions, moduleName.charAt(0).toUpperCase() + moduleName.slice(1));
|
|
396
|
-
case
|
|
536
|
+
case 13:
|
|
397
537
|
// 保存模块实例
|
|
398
538
|
this[moduleName] = moduleInstance;
|
|
539
|
+
this.logInfo("\u6A21\u5757\u6CE8\u518C\u5B8C\u6210: ".concat(moduleName), {
|
|
540
|
+
moduleName: moduleName,
|
|
541
|
+
shouldPreload: shouldPreload,
|
|
542
|
+
version: registryConfig.version
|
|
543
|
+
});
|
|
399
544
|
return _context4.abrupt("return", {
|
|
400
545
|
module: moduleInstance,
|
|
401
546
|
config: registryConfig,
|
|
402
547
|
shouldPreload: shouldPreload
|
|
403
548
|
});
|
|
404
|
-
case
|
|
549
|
+
case 16:
|
|
405
550
|
case "end":
|
|
406
551
|
return _context4.stop();
|
|
407
552
|
}
|
|
@@ -421,7 +566,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
421
566
|
key: "registerModules",
|
|
422
567
|
value: (function () {
|
|
423
568
|
var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(moduleConfigs) {
|
|
424
|
-
var configs, registeredModules, _iterator, _step, config, result;
|
|
569
|
+
var configs, registeredModules, _iterator, _step, config, configName, result, errorMessage;
|
|
425
570
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
426
571
|
while (1) switch (_context5.prev = _context5.next) {
|
|
427
572
|
case 0:
|
|
@@ -429,51 +574,68 @@ var Server = /*#__PURE__*/function () {
|
|
|
429
574
|
|
|
430
575
|
// 如果没有指定模块,则注册所有模块
|
|
431
576
|
configs = moduleConfigs || Object.keys(this.moduleRegistry);
|
|
577
|
+
this.logInfo('开始批量注册模块', {
|
|
578
|
+
moduleConfigs: configs,
|
|
579
|
+
totalCount: configs.length
|
|
580
|
+
});
|
|
432
581
|
registeredModules = [];
|
|
433
582
|
_iterator = _createForOfIteratorHelper(configs);
|
|
434
|
-
_context5.prev =
|
|
583
|
+
_context5.prev = 5;
|
|
435
584
|
_iterator.s();
|
|
436
|
-
case
|
|
585
|
+
case 7:
|
|
437
586
|
if ((_step = _iterator.n()).done) {
|
|
438
|
-
_context5.next =
|
|
587
|
+
_context5.next = 25;
|
|
439
588
|
break;
|
|
440
589
|
}
|
|
441
590
|
config = _step.value;
|
|
442
|
-
|
|
443
|
-
_context5.
|
|
591
|
+
configName = typeof config === 'string' ? config : config.name;
|
|
592
|
+
_context5.prev = 10;
|
|
593
|
+
_context5.next = 13;
|
|
444
594
|
return this.registerModuleByName(config);
|
|
445
|
-
case
|
|
595
|
+
case 13:
|
|
446
596
|
result = _context5.sent;
|
|
447
597
|
registeredModules.push(result);
|
|
448
|
-
_context5.next =
|
|
598
|
+
_context5.next = 23;
|
|
449
599
|
break;
|
|
450
|
-
case
|
|
451
|
-
_context5.prev =
|
|
452
|
-
_context5.t0 = _context5["catch"](
|
|
600
|
+
case 17:
|
|
601
|
+
_context5.prev = 17;
|
|
602
|
+
_context5.t0 = _context5["catch"](10);
|
|
603
|
+
errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
|
|
604
|
+
this.logError("\u6A21\u5757\u6CE8\u518C\u5931\u8D25: ".concat(configName), {
|
|
605
|
+
moduleName: configName,
|
|
606
|
+
error: errorMessage
|
|
607
|
+
});
|
|
453
608
|
console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context5.t0);
|
|
454
609
|
throw _context5.t0;
|
|
455
|
-
case
|
|
456
|
-
_context5.next =
|
|
610
|
+
case 23:
|
|
611
|
+
_context5.next = 7;
|
|
457
612
|
break;
|
|
458
|
-
case
|
|
459
|
-
_context5.next =
|
|
613
|
+
case 25:
|
|
614
|
+
_context5.next = 30;
|
|
460
615
|
break;
|
|
461
|
-
case
|
|
462
|
-
_context5.prev =
|
|
463
|
-
_context5.t1 = _context5["catch"](
|
|
616
|
+
case 27:
|
|
617
|
+
_context5.prev = 27;
|
|
618
|
+
_context5.t1 = _context5["catch"](5);
|
|
464
619
|
_iterator.e(_context5.t1);
|
|
465
|
-
case
|
|
466
|
-
_context5.prev =
|
|
620
|
+
case 30:
|
|
621
|
+
_context5.prev = 30;
|
|
467
622
|
_iterator.f();
|
|
468
|
-
return _context5.finish(
|
|
469
|
-
case
|
|
623
|
+
return _context5.finish(30);
|
|
624
|
+
case 33:
|
|
470
625
|
console.log('[Server] ✅ 所有模块注册完成');
|
|
626
|
+
this.logInfo('所有模块注册完成', {
|
|
627
|
+
registeredCount: registeredModules.length,
|
|
628
|
+
moduleNames: registeredModules.map(function (m) {
|
|
629
|
+
var _m$config;
|
|
630
|
+
return m === null || m === void 0 || (_m$config = m.config) === null || _m$config === void 0 ? void 0 : _m$config.name;
|
|
631
|
+
})
|
|
632
|
+
});
|
|
471
633
|
return _context5.abrupt("return", registeredModules);
|
|
472
|
-
case
|
|
634
|
+
case 36:
|
|
473
635
|
case "end":
|
|
474
636
|
return _context5.stop();
|
|
475
637
|
}
|
|
476
|
-
}, _callee5, this, [[
|
|
638
|
+
}, _callee5, this, [[5, 27, 30, 33], [10, 17]]);
|
|
477
639
|
}));
|
|
478
640
|
function registerModules(_x7) {
|
|
479
641
|
return _registerModules.apply(this, arguments);
|
|
@@ -489,70 +651,121 @@ var Server = /*#__PURE__*/function () {
|
|
|
489
651
|
key: "preloadModulesData",
|
|
490
652
|
value: (function () {
|
|
491
653
|
var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(registeredModules, options) {
|
|
492
|
-
var _iterator2, _step2, _step2$value, module, config, shouldPreload, _options$onModuleLoad, _options$onModuleLoad2;
|
|
654
|
+
var modulesToPreload, preloadResults, _iterator2, _step2, _step2$value, module, config, shouldPreload, startTime, _options$onModuleLoad, _options$onModuleLoad2, duration, _duration, errorMessage, successCount, failCount;
|
|
493
655
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
494
656
|
while (1) switch (_context6.prev = _context6.next) {
|
|
495
657
|
case 0:
|
|
496
658
|
console.log('[Server] 开始预加载模块数据...');
|
|
659
|
+
modulesToPreload = registeredModules.filter(function (m) {
|
|
660
|
+
return m.shouldPreload;
|
|
661
|
+
});
|
|
662
|
+
this.logInfo('开始预加载模块数据', {
|
|
663
|
+
totalModules: registeredModules.length,
|
|
664
|
+
preloadCount: modulesToPreload.length,
|
|
665
|
+
modulesToPreload: modulesToPreload
|
|
666
|
+
});
|
|
667
|
+
preloadResults = [];
|
|
497
668
|
_iterator2 = _createForOfIteratorHelper(registeredModules);
|
|
498
|
-
_context6.prev =
|
|
669
|
+
_context6.prev = 5;
|
|
499
670
|
_iterator2.s();
|
|
500
|
-
case
|
|
671
|
+
case 7:
|
|
501
672
|
if ((_step2 = _iterator2.n()).done) {
|
|
502
|
-
_context6.next =
|
|
673
|
+
_context6.next = 40;
|
|
503
674
|
break;
|
|
504
675
|
}
|
|
505
676
|
_step2$value = _step2.value, module = _step2$value.module, config = _step2$value.config, shouldPreload = _step2$value.shouldPreload;
|
|
506
677
|
if (shouldPreload) {
|
|
507
|
-
_context6.next =
|
|
678
|
+
_context6.next = 13;
|
|
508
679
|
break;
|
|
509
680
|
}
|
|
510
681
|
console.log("[Server] \u23ED\uFE0F \u8DF3\u8FC7 ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D"));
|
|
511
|
-
|
|
512
|
-
|
|
682
|
+
this.logInfo("\u8DF3\u8FC7\u6A21\u5757\u9884\u52A0\u8F7D: ".concat(config.name), {
|
|
683
|
+
moduleName: config.name,
|
|
684
|
+
reason: 'shouldPreload=false'
|
|
685
|
+
});
|
|
686
|
+
return _context6.abrupt("continue", 38);
|
|
687
|
+
case 13:
|
|
513
688
|
if (!(typeof module.preload === 'function')) {
|
|
514
|
-
_context6.next =
|
|
689
|
+
_context6.next = 36;
|
|
515
690
|
break;
|
|
516
691
|
}
|
|
517
|
-
|
|
692
|
+
startTime = Date.now();
|
|
693
|
+
_context6.prev = 15;
|
|
694
|
+
this.logInfo("\u5F00\u59CB\u9884\u52A0\u8F7D\u6A21\u5757: ".concat(config.name), {
|
|
695
|
+
moduleName: config.name
|
|
696
|
+
});
|
|
518
697
|
options === null || options === void 0 || (_options$onModuleLoad = options.onModuleLoad) === null || _options$onModuleLoad === void 0 || _options$onModuleLoad.call(options, config.name);
|
|
519
|
-
_context6.next =
|
|
698
|
+
_context6.next = 20;
|
|
520
699
|
return module.preload();
|
|
521
|
-
case
|
|
700
|
+
case 20:
|
|
522
701
|
options === null || options === void 0 || (_options$onModuleLoad2 = options.onModuleLoadComplete) === null || _options$onModuleLoad2 === void 0 || _options$onModuleLoad2.call(options, config.name);
|
|
702
|
+
duration = Date.now() - startTime;
|
|
523
703
|
console.log("[Server] \u2705 ".concat(config.name, " \u6A21\u5757\u6570\u636E\u5DF2\u9884\u52A0\u8F7D"));
|
|
524
|
-
|
|
704
|
+
this.logInfo("\u6A21\u5757\u9884\u52A0\u8F7D\u6210\u529F: ".concat(config.name), {
|
|
705
|
+
moduleName: config.name,
|
|
706
|
+
duration: "".concat(duration, "ms")
|
|
707
|
+
});
|
|
708
|
+
preloadResults.push({
|
|
709
|
+
name: config.name,
|
|
710
|
+
success: true
|
|
711
|
+
});
|
|
712
|
+
_context6.next = 34;
|
|
525
713
|
break;
|
|
526
|
-
case
|
|
527
|
-
_context6.prev =
|
|
528
|
-
_context6.t0 = _context6["catch"](
|
|
714
|
+
case 27:
|
|
715
|
+
_context6.prev = 27;
|
|
716
|
+
_context6.t0 = _context6["catch"](15);
|
|
717
|
+
_duration = Date.now() - startTime;
|
|
718
|
+
errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
|
|
529
719
|
console.error("[Server] \u274C ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25:"), _context6.t0);
|
|
530
|
-
|
|
531
|
-
|
|
720
|
+
this.logError("\u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25: ".concat(config.name), {
|
|
721
|
+
moduleName: config.name,
|
|
722
|
+
duration: "".concat(_duration, "ms"),
|
|
723
|
+
error: errorMessage
|
|
724
|
+
});
|
|
725
|
+
preloadResults.push({
|
|
726
|
+
name: config.name,
|
|
727
|
+
success: false,
|
|
728
|
+
error: errorMessage
|
|
729
|
+
});
|
|
730
|
+
case 34:
|
|
731
|
+
_context6.next = 38;
|
|
532
732
|
break;
|
|
533
|
-
case
|
|
733
|
+
case 36:
|
|
534
734
|
console.log("[Server] \u26A0\uFE0F ".concat(config.name, " \u6A21\u5757\u672A\u5B9E\u73B0 preload() \u65B9\u6CD5"));
|
|
535
|
-
|
|
536
|
-
|
|
735
|
+
this.logWarning("\u6A21\u5757\u672A\u5B9E\u73B0 preload \u65B9\u6CD5: ".concat(config.name), {
|
|
736
|
+
moduleName: config.name
|
|
737
|
+
});
|
|
738
|
+
case 38:
|
|
739
|
+
_context6.next = 7;
|
|
537
740
|
break;
|
|
538
|
-
case
|
|
539
|
-
_context6.next =
|
|
741
|
+
case 40:
|
|
742
|
+
_context6.next = 45;
|
|
540
743
|
break;
|
|
541
|
-
case
|
|
542
|
-
_context6.prev =
|
|
543
|
-
_context6.t1 = _context6["catch"](
|
|
744
|
+
case 42:
|
|
745
|
+
_context6.prev = 42;
|
|
746
|
+
_context6.t1 = _context6["catch"](5);
|
|
544
747
|
_iterator2.e(_context6.t1);
|
|
545
|
-
case
|
|
546
|
-
_context6.prev =
|
|
748
|
+
case 45:
|
|
749
|
+
_context6.prev = 45;
|
|
547
750
|
_iterator2.f();
|
|
548
|
-
return _context6.finish(
|
|
549
|
-
case
|
|
751
|
+
return _context6.finish(45);
|
|
752
|
+
case 48:
|
|
753
|
+
successCount = preloadResults.filter(function (r) {
|
|
754
|
+
return r.success;
|
|
755
|
+
}).length;
|
|
756
|
+
failCount = preloadResults.filter(function (r) {
|
|
757
|
+
return !r.success;
|
|
758
|
+
}).length;
|
|
550
759
|
console.log('[Server] ✅ 所有模块数据预加载完成');
|
|
551
|
-
|
|
760
|
+
this.logInfo('所有模块预加载完成', {
|
|
761
|
+
successCount: successCount,
|
|
762
|
+
failCount: failCount
|
|
763
|
+
});
|
|
764
|
+
case 52:
|
|
552
765
|
case "end":
|
|
553
766
|
return _context6.stop();
|
|
554
767
|
}
|
|
555
|
-
}, _callee6,
|
|
768
|
+
}, _callee6, this, [[5, 42, 45, 48], [15, 27]]);
|
|
556
769
|
}));
|
|
557
770
|
function preloadModulesData(_x8, _x9) {
|
|
558
771
|
return _preloadModulesData.apply(this, arguments);
|
|
@@ -569,32 +782,54 @@ var Server = /*#__PURE__*/function () {
|
|
|
569
782
|
key: "initialize",
|
|
570
783
|
value: (function () {
|
|
571
784
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(moduleConfigs) {
|
|
785
|
+
var _moduleConfigs$length;
|
|
572
786
|
var autoPreload,
|
|
573
787
|
options,
|
|
788
|
+
startTime,
|
|
574
789
|
registeredModules,
|
|
790
|
+
duration,
|
|
575
791
|
_args7 = arguments;
|
|
576
792
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
577
793
|
while (1) switch (_context7.prev = _context7.next) {
|
|
578
794
|
case 0:
|
|
579
795
|
autoPreload = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : true;
|
|
580
796
|
options = _args7.length > 2 ? _args7[2] : undefined;
|
|
797
|
+
startTime = Date.now();
|
|
798
|
+
this.logInfo('Server 初始化开始', {
|
|
799
|
+
moduleConfigCount: (_moduleConfigs$length = moduleConfigs === null || moduleConfigs === void 0 ? void 0 : moduleConfigs.length) !== null && _moduleConfigs$length !== void 0 ? _moduleConfigs$length : 'all',
|
|
800
|
+
autoPreload: autoPreload,
|
|
801
|
+
moduleConfigs: moduleConfigs
|
|
802
|
+
});
|
|
803
|
+
|
|
581
804
|
// 注册 Server 层的业务路由
|
|
582
805
|
this.registerServerRoutes();
|
|
583
806
|
|
|
584
807
|
// 注册模块
|
|
585
|
-
_context7.next =
|
|
808
|
+
_context7.next = 7;
|
|
586
809
|
return this.registerModules(moduleConfigs);
|
|
587
|
-
case
|
|
810
|
+
case 7:
|
|
588
811
|
registeredModules = _context7.sent;
|
|
589
812
|
if (!autoPreload) {
|
|
590
|
-
_context7.next =
|
|
813
|
+
_context7.next = 13;
|
|
591
814
|
break;
|
|
592
815
|
}
|
|
593
|
-
_context7.next =
|
|
816
|
+
_context7.next = 11;
|
|
594
817
|
return this.preloadModulesData(registeredModules, options);
|
|
595
|
-
case
|
|
818
|
+
case 11:
|
|
819
|
+
_context7.next = 14;
|
|
820
|
+
break;
|
|
821
|
+
case 13:
|
|
822
|
+
this.logInfo('跳过自动预加载', {
|
|
823
|
+
autoPreload: autoPreload
|
|
824
|
+
});
|
|
825
|
+
case 14:
|
|
826
|
+
duration = Date.now() - startTime;
|
|
827
|
+
this.logInfo('Server 初始化完成', {
|
|
828
|
+
duration: "".concat(duration, "ms"),
|
|
829
|
+
registeredModuleCount: registeredModules.length
|
|
830
|
+
});
|
|
596
831
|
return _context7.abrupt("return", registeredModules);
|
|
597
|
-
case
|
|
832
|
+
case 17:
|
|
598
833
|
case "end":
|
|
599
834
|
return _context7.stop();
|
|
600
835
|
}
|
|
@@ -664,11 +899,12 @@ var Server = /*#__PURE__*/function () {
|
|
|
664
899
|
key: "clearAllIndexDB",
|
|
665
900
|
value: (function () {
|
|
666
901
|
var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
667
|
-
var clearTasks, moduleNames;
|
|
902
|
+
var clearTasks, moduleNames, errorMessage;
|
|
668
903
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
669
904
|
while (1) switch (_context8.prev = _context8.next) {
|
|
670
905
|
case 0:
|
|
671
906
|
console.log('[Server] 开始清空所有模块的IndexedDB缓存...');
|
|
907
|
+
this.logInfo('开始清空所有模块的 IndexedDB 缓存');
|
|
672
908
|
clearTasks = [];
|
|
673
909
|
moduleNames = []; // 收集所有模块的清空任务
|
|
674
910
|
if (this.products) {
|
|
@@ -688,29 +924,41 @@ var Server = /*#__PURE__*/function () {
|
|
|
688
924
|
moduleNames.push('Schedule');
|
|
689
925
|
}
|
|
690
926
|
if (!(clearTasks.length === 0)) {
|
|
691
|
-
_context8.next =
|
|
927
|
+
_context8.next = 12;
|
|
692
928
|
break;
|
|
693
929
|
}
|
|
694
930
|
console.warn('[Server] 没有找到已注册的模块,无需清空');
|
|
931
|
+
this.logWarning('没有找到已注册的模块,无需清空 IndexedDB');
|
|
695
932
|
return _context8.abrupt("return");
|
|
696
|
-
case
|
|
697
|
-
|
|
698
|
-
|
|
933
|
+
case 12:
|
|
934
|
+
this.logInfo('准备清空模块缓存', {
|
|
935
|
+
moduleNames: moduleNames
|
|
936
|
+
});
|
|
937
|
+
_context8.prev = 13;
|
|
938
|
+
_context8.next = 16;
|
|
699
939
|
return Promise.all(clearTasks);
|
|
700
|
-
case
|
|
940
|
+
case 16:
|
|
701
941
|
console.log("[Server] \u2705 \u5DF2\u6210\u529F\u6E05\u7A7A\u6240\u6709\u6A21\u5757\u7684IndexedDB\u7F13\u5B58: ".concat(moduleNames.join(', ')));
|
|
702
|
-
|
|
942
|
+
this.logInfo('成功清空所有模块的 IndexedDB 缓存', {
|
|
943
|
+
moduleNames: moduleNames
|
|
944
|
+
});
|
|
945
|
+
_context8.next = 26;
|
|
703
946
|
break;
|
|
704
|
-
case
|
|
705
|
-
_context8.prev =
|
|
706
|
-
_context8.t0 = _context8["catch"](
|
|
947
|
+
case 20:
|
|
948
|
+
_context8.prev = 20;
|
|
949
|
+
_context8.t0 = _context8["catch"](13);
|
|
950
|
+
errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
|
|
707
951
|
console.error('[Server] ❌ 清空IndexedDB缓存时发生错误:', _context8.t0);
|
|
952
|
+
this.logError('清空 IndexedDB 缓存时发生错误', {
|
|
953
|
+
moduleNames: moduleNames,
|
|
954
|
+
error: errorMessage
|
|
955
|
+
});
|
|
708
956
|
throw _context8.t0;
|
|
709
|
-
case
|
|
957
|
+
case 26:
|
|
710
958
|
case "end":
|
|
711
959
|
return _context8.stop();
|
|
712
960
|
}
|
|
713
|
-
}, _callee8, this, [[
|
|
961
|
+
}, _callee8, this, [[13, 20]]);
|
|
714
962
|
}));
|
|
715
963
|
function clearAllIndexDB() {
|
|
716
964
|
return _clearAllIndexDB.apply(this, arguments);
|
|
@@ -762,33 +1010,62 @@ var Server = /*#__PURE__*/function () {
|
|
|
762
1010
|
key: "handleRoute",
|
|
763
1011
|
value: (function () {
|
|
764
1012
|
var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(method, path, params) {
|
|
765
|
-
var handler;
|
|
1013
|
+
var startTime, handler, result, duration, _duration2, errorMessage;
|
|
766
1014
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
767
1015
|
while (1) switch (_context9.prev = _context9.next) {
|
|
768
1016
|
case 0:
|
|
1017
|
+
startTime = Date.now();
|
|
769
1018
|
console.log(method, path, params, 'method, path, params');
|
|
1019
|
+
this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5F00\u59CB: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1020
|
+
method: method.toUpperCase(),
|
|
1021
|
+
path: path,
|
|
1022
|
+
url: params.url,
|
|
1023
|
+
data: params.data
|
|
1024
|
+
});
|
|
770
1025
|
handler = this.getRouteHandler(method, path);
|
|
771
1026
|
if (handler) {
|
|
772
|
-
_context9.next =
|
|
1027
|
+
_context9.next = 7;
|
|
773
1028
|
break;
|
|
774
1029
|
}
|
|
1030
|
+
this.logError("\u8DEF\u7531\u672A\u627E\u5230: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1031
|
+
method: method,
|
|
1032
|
+
path: path
|
|
1033
|
+
});
|
|
775
1034
|
throw new Error("Route not found: ".concat(method.toUpperCase(), " ").concat(path));
|
|
776
|
-
case 4:
|
|
777
|
-
_context9.prev = 4;
|
|
778
|
-
_context9.next = 7;
|
|
779
|
-
return handler(params);
|
|
780
1035
|
case 7:
|
|
781
|
-
|
|
1036
|
+
_context9.prev = 7;
|
|
1037
|
+
_context9.next = 10;
|
|
1038
|
+
return handler(params);
|
|
782
1039
|
case 10:
|
|
783
|
-
|
|
784
|
-
|
|
1040
|
+
result = _context9.sent;
|
|
1041
|
+
duration = Date.now() - startTime;
|
|
1042
|
+
this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5B8C\u6210: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1043
|
+
method: method.toUpperCase(),
|
|
1044
|
+
path: path,
|
|
1045
|
+
duration: "".concat(duration, "ms"),
|
|
1046
|
+
resultCode: result === null || result === void 0 ? void 0 : result.code,
|
|
1047
|
+
resultStatus: result === null || result === void 0 ? void 0 : result.status
|
|
1048
|
+
});
|
|
1049
|
+
return _context9.abrupt("return", result);
|
|
1050
|
+
case 16:
|
|
1051
|
+
_context9.prev = 16;
|
|
1052
|
+
_context9.t0 = _context9["catch"](7);
|
|
1053
|
+
_duration2 = Date.now() - startTime;
|
|
1054
|
+
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
1055
|
+
this.logError("\u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1056
|
+
method: method.toUpperCase(),
|
|
1057
|
+
path: path,
|
|
1058
|
+
duration: "".concat(_duration2, "ms"),
|
|
1059
|
+
error: errorMessage,
|
|
1060
|
+
data: params.data
|
|
1061
|
+
});
|
|
785
1062
|
console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context9.t0);
|
|
786
1063
|
throw _context9.t0;
|
|
787
|
-
case
|
|
1064
|
+
case 23:
|
|
788
1065
|
case "end":
|
|
789
1066
|
return _context9.stop();
|
|
790
1067
|
}
|
|
791
|
-
}, _callee9, this, [[
|
|
1068
|
+
}, _callee9, this, [[7, 16]]);
|
|
792
1069
|
}));
|
|
793
1070
|
function handleRoute(_x11, _x12, _x13) {
|
|
794
1071
|
return _handleRoute.apply(this, arguments);
|
|
@@ -850,6 +1127,10 @@ var Server = /*#__PURE__*/function () {
|
|
|
850
1127
|
// 如果没有生效的餐牌,返回空数组
|
|
851
1128
|
if (!activeMenuList || activeMenuList.length === 0) {
|
|
852
1129
|
console.log('[Server] 没有生效的餐牌,返回空数组');
|
|
1130
|
+
this.logInfo('filterProductsByMenuConfig: 没有生效的餐牌,返回空数组', {
|
|
1131
|
+
productCount: products.length,
|
|
1132
|
+
activeMenuCount: 0
|
|
1133
|
+
});
|
|
853
1134
|
return [];
|
|
854
1135
|
}
|
|
855
1136
|
|
|
@@ -865,12 +1146,21 @@ var Server = /*#__PURE__*/function () {
|
|
|
865
1146
|
var config = menu.partyroom_package;
|
|
866
1147
|
if (!config) {
|
|
867
1148
|
console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
|
|
1149
|
+
this.logWarning('filterProductsByMenuConfig: 餐牌缺少 partyroom_package 配置', {
|
|
1150
|
+
menuId: menu.form_record_id,
|
|
1151
|
+
menuName: menu.name
|
|
1152
|
+
});
|
|
868
1153
|
continue;
|
|
869
1154
|
}
|
|
870
1155
|
|
|
871
1156
|
// 如果有任何一个餐牌是 product_all,则返回所有商品
|
|
872
1157
|
if (config.type === 'product_all') {
|
|
873
1158
|
console.log('[Server] 餐牌允许所有商品:', menu.name);
|
|
1159
|
+
this.logInfo('filterProductsByMenuConfig: 餐牌允许所有商品', {
|
|
1160
|
+
menuId: menu.form_record_id,
|
|
1161
|
+
menuName: menu.name,
|
|
1162
|
+
configType: config.type
|
|
1163
|
+
});
|
|
874
1164
|
hasProductAll = true;
|
|
875
1165
|
break;
|
|
876
1166
|
}
|
|
@@ -884,6 +1174,12 @@ var Server = /*#__PURE__*/function () {
|
|
|
884
1174
|
return id && allowedProductIds.add(id);
|
|
885
1175
|
});
|
|
886
1176
|
console.log('[Server] 餐牌允许指定商品 (product_ids):', menu.name, productIds);
|
|
1177
|
+
this.logInfo('filterProductsByMenuConfig: 餐牌允许指定商品', {
|
|
1178
|
+
menuId: menu.form_record_id,
|
|
1179
|
+
menuName: menu.name,
|
|
1180
|
+
configType: config.type,
|
|
1181
|
+
productIdsCount: productIds.length
|
|
1182
|
+
});
|
|
887
1183
|
}
|
|
888
1184
|
|
|
889
1185
|
// 如果是 product_collection 类型,从 ProductItemType 中提取 product_collection_id
|
|
@@ -895,6 +1191,12 @@ var Server = /*#__PURE__*/function () {
|
|
|
895
1191
|
return id && allowedCollectionIds.add(id);
|
|
896
1192
|
});
|
|
897
1193
|
console.log('[Server] 餐牌允许商品集合 (product_collection):', menu.name, collectionIds);
|
|
1194
|
+
this.logInfo('filterProductsByMenuConfig: 餐牌允许商品集合', {
|
|
1195
|
+
menuId: menu.form_record_id,
|
|
1196
|
+
menuName: menu.name,
|
|
1197
|
+
configType: config.type,
|
|
1198
|
+
collectionIdsCount: collectionIds.length
|
|
1199
|
+
});
|
|
898
1200
|
}
|
|
899
1201
|
}
|
|
900
1202
|
|
|
@@ -905,16 +1207,29 @@ var Server = /*#__PURE__*/function () {
|
|
|
905
1207
|
_iterator3.f();
|
|
906
1208
|
}
|
|
907
1209
|
if (hasProductAll) {
|
|
1210
|
+
this.logInfo('filterProductsByMenuConfig: 返回所有商品(product_all)', {
|
|
1211
|
+
productCount: products.length
|
|
1212
|
+
});
|
|
908
1213
|
return products;
|
|
909
1214
|
}
|
|
910
1215
|
|
|
911
1216
|
// 如果没有收集到任何商品 ID 和集合 ID,返回空数组
|
|
912
1217
|
if (allowedProductIds.size === 0 && allowedCollectionIds.size === 0) {
|
|
913
1218
|
console.log('[Server] 没有允许的商品和集合');
|
|
1219
|
+
this.logWarning('filterProductsByMenuConfig: 没有允许的商品和集合', {
|
|
1220
|
+
productCount: products.length,
|
|
1221
|
+
activeMenuCount: activeMenuList.length
|
|
1222
|
+
});
|
|
914
1223
|
return [];
|
|
915
1224
|
}
|
|
916
|
-
|
|
917
|
-
|
|
1225
|
+
var allowedProductIdsArray = Array.from(allowedProductIds);
|
|
1226
|
+
var allowedCollectionIdsArray = Array.from(allowedCollectionIds);
|
|
1227
|
+
console.log('[Server] 允许的商品 IDs:', allowedProductIdsArray);
|
|
1228
|
+
console.log('[Server] 允许的集合 IDs:', allowedCollectionIdsArray);
|
|
1229
|
+
this.logInfo('filterProductsByMenuConfig: 收集到的允许规则', {
|
|
1230
|
+
allowedProductCount: allowedProductIds.size,
|
|
1231
|
+
allowedCollectionCount: allowedCollectionIds.size
|
|
1232
|
+
});
|
|
918
1233
|
|
|
919
1234
|
// 过滤商品
|
|
920
1235
|
var filteredProducts = products.filter(function (product) {
|
|
@@ -935,8 +1250,76 @@ var Server = /*#__PURE__*/function () {
|
|
|
935
1250
|
return false;
|
|
936
1251
|
});
|
|
937
1252
|
console.log('[Server] 过滤结果: 原始 %d 个,过滤后 %d 个', products.length, filteredProducts.length);
|
|
1253
|
+
this.logInfo('filterProductsByMenuConfig: 过滤完成', {
|
|
1254
|
+
originalCount: products.length,
|
|
1255
|
+
filteredCount: filteredProducts.length,
|
|
1256
|
+
removedCount: products.length - filteredProducts.length
|
|
1257
|
+
});
|
|
938
1258
|
return filteredProducts;
|
|
939
1259
|
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* 记录信息日志
|
|
1263
|
+
* @param title 日志标题
|
|
1264
|
+
* @param metadata 日志元数据
|
|
1265
|
+
*/
|
|
1266
|
+
}, {
|
|
1267
|
+
key: "logInfo",
|
|
1268
|
+
value: function logInfo(title, metadata) {
|
|
1269
|
+
try {
|
|
1270
|
+
if (this.logger) {
|
|
1271
|
+
this.logger.addLog({
|
|
1272
|
+
type: 'info',
|
|
1273
|
+
title: "[Server] ".concat(title),
|
|
1274
|
+
metadata: metadata || {}
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
} catch (_unused) {
|
|
1278
|
+
// 日志记录失败不影响主流程
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* 记录警告日志
|
|
1284
|
+
* @param title 日志标题
|
|
1285
|
+
* @param metadata 日志元数据
|
|
1286
|
+
*/
|
|
1287
|
+
}, {
|
|
1288
|
+
key: "logWarning",
|
|
1289
|
+
value: function logWarning(title, metadata) {
|
|
1290
|
+
try {
|
|
1291
|
+
if (this.logger) {
|
|
1292
|
+
this.logger.addLog({
|
|
1293
|
+
type: 'warning',
|
|
1294
|
+
title: "[Server] ".concat(title),
|
|
1295
|
+
metadata: metadata || {}
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
} catch (_unused2) {
|
|
1299
|
+
// 日志记录失败不影响主流程
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* 记录错误日志
|
|
1305
|
+
* @param title 日志标题
|
|
1306
|
+
* @param metadata 日志元数据
|
|
1307
|
+
*/
|
|
1308
|
+
}, {
|
|
1309
|
+
key: "logError",
|
|
1310
|
+
value: function logError(title, metadata) {
|
|
1311
|
+
try {
|
|
1312
|
+
if (this.logger) {
|
|
1313
|
+
this.logger.addLog({
|
|
1314
|
+
type: 'error',
|
|
1315
|
+
title: "[Server] ".concat(title),
|
|
1316
|
+
metadata: metadata || {}
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
} catch (_unused3) {
|
|
1320
|
+
// 日志记录失败不影响主流程
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
940
1323
|
}]);
|
|
941
1324
|
return Server;
|
|
942
1325
|
}();
|