@pisell/pisellos 2.2.31 → 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/modules/Product/index.d.ts +1 -1
- package/dist/modules/Summary/utils.d.ts +1 -1
- 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/BookingTicket/index.d.ts +1 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Summary/utils.d.ts +1 -1
- 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/BookingTicket/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -48,6 +48,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
48
48
|
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
49
49
|
_defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
|
|
50
50
|
// IndexDBManager 实例
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
|
52
|
+
// LoggerManager 实例
|
|
51
53
|
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
52
54
|
// 商品价格缓存:Map<日期, 应用了价格的商品列表>
|
|
53
55
|
_defineProperty(_assertThisInitialized(_this), "productsPriceCache", new Map());
|
|
@@ -83,11 +85,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
83
85
|
}
|
|
84
86
|
this.request = core.getPlugin('request');
|
|
85
87
|
|
|
86
|
-
// 获取并存储 dbManager
|
|
88
|
+
// 获取并存储 dbManager 和 logger
|
|
87
89
|
appPlugin = core.getPlugin('app');
|
|
88
90
|
if (appPlugin) {
|
|
89
91
|
app = appPlugin.getApp();
|
|
90
92
|
this.dbManager = app.dbManager;
|
|
93
|
+
this.logger = app.logger;
|
|
91
94
|
if (this.dbManager) {
|
|
92
95
|
console.log('[Products] IndexDB Manager 已初始化');
|
|
93
96
|
} else {
|
|
@@ -97,7 +100,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
97
100
|
|
|
98
101
|
// 注册内置的价格格式化器(作为第一个格式化器)
|
|
99
102
|
this.registerBuiltinPriceFormatter();
|
|
100
|
-
|
|
103
|
+
this.logInfo('模块初始化完成', {
|
|
104
|
+
hasDbManager: !!this.dbManager,
|
|
105
|
+
hasLogger: !!this.logger,
|
|
106
|
+
initialProductCount: this.store.list.length
|
|
107
|
+
});
|
|
108
|
+
case 9:
|
|
101
109
|
case "end":
|
|
102
110
|
return _context.stop();
|
|
103
111
|
}
|
|
@@ -108,6 +116,69 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
108
116
|
}
|
|
109
117
|
return initialize;
|
|
110
118
|
}()
|
|
119
|
+
/**
|
|
120
|
+
* 记录信息日志
|
|
121
|
+
* @param title 日志标题
|
|
122
|
+
* @param metadata 日志元数据
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "logInfo",
|
|
126
|
+
value: function logInfo(title, metadata) {
|
|
127
|
+
try {
|
|
128
|
+
if (this.logger) {
|
|
129
|
+
this.logger.addLog({
|
|
130
|
+
type: 'info',
|
|
131
|
+
title: "[ProductsModule] ".concat(title),
|
|
132
|
+
metadata: metadata || {}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
} catch (_unused) {
|
|
136
|
+
// 日志记录失败不影响主流程
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 记录警告日志
|
|
142
|
+
* @param title 日志标题
|
|
143
|
+
* @param metadata 日志元数据
|
|
144
|
+
*/
|
|
145
|
+
}, {
|
|
146
|
+
key: "logWarning",
|
|
147
|
+
value: function logWarning(title, metadata) {
|
|
148
|
+
try {
|
|
149
|
+
if (this.logger) {
|
|
150
|
+
this.logger.addLog({
|
|
151
|
+
type: 'warning',
|
|
152
|
+
title: "[ProductsModule] ".concat(title),
|
|
153
|
+
metadata: metadata || {}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
} catch (_unused2) {
|
|
157
|
+
// 日志记录失败不影响主流程
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 记录错误日志
|
|
163
|
+
* @param title 日志标题
|
|
164
|
+
* @param metadata 日志元数据
|
|
165
|
+
*/
|
|
166
|
+
}, {
|
|
167
|
+
key: "logError",
|
|
168
|
+
value: function logError(title, metadata) {
|
|
169
|
+
try {
|
|
170
|
+
if (this.logger) {
|
|
171
|
+
this.logger.addLog({
|
|
172
|
+
type: 'error',
|
|
173
|
+
title: "[ProductsModule] ".concat(title),
|
|
174
|
+
metadata: metadata || {}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
} catch (_unused3) {
|
|
178
|
+
// 日志记录失败不影响主流程
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
111
182
|
/**
|
|
112
183
|
* 加载商品价格(原始方法,不带缓存)
|
|
113
184
|
* @private
|
|
@@ -116,12 +187,19 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
116
187
|
key: "loadProductsPrice",
|
|
117
188
|
value: (function () {
|
|
118
189
|
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
119
|
-
var _ref$ids, ids, customer_id, schedule_date, productsData;
|
|
190
|
+
var _ref$ids, ids, customer_id, schedule_date, startTime, _productsData$data$le, _productsData$data, productsData, duration, _duration, errorMessage;
|
|
120
191
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
121
192
|
while (1) switch (_context2.prev = _context2.next) {
|
|
122
193
|
case 0:
|
|
123
194
|
_ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date;
|
|
124
|
-
|
|
195
|
+
this.logInfo('开始加载商品价格', {
|
|
196
|
+
productCount: ids.length,
|
|
197
|
+
schedule_date: schedule_date,
|
|
198
|
+
customer_id: customer_id
|
|
199
|
+
});
|
|
200
|
+
startTime = Date.now();
|
|
201
|
+
_context2.prev = 3;
|
|
202
|
+
_context2.next = 6;
|
|
125
203
|
return this.request.post("/product/query/price", {
|
|
126
204
|
ids: ids,
|
|
127
205
|
customer_id: customer_id,
|
|
@@ -132,14 +210,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
132
210
|
type: "indexDB"
|
|
133
211
|
}
|
|
134
212
|
});
|
|
135
|
-
case
|
|
213
|
+
case 6:
|
|
136
214
|
productsData = _context2.sent;
|
|
215
|
+
duration = Date.now() - startTime;
|
|
216
|
+
this.logInfo('加载商品价格成功', {
|
|
217
|
+
productCount: ids.length,
|
|
218
|
+
priceDataCount: (_productsData$data$le = (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.length) !== null && _productsData$data$le !== void 0 ? _productsData$data$le : 0,
|
|
219
|
+
duration: "".concat(duration, "ms")
|
|
220
|
+
});
|
|
137
221
|
return _context2.abrupt("return", productsData.data);
|
|
138
|
-
case
|
|
222
|
+
case 12:
|
|
223
|
+
_context2.prev = 12;
|
|
224
|
+
_context2.t0 = _context2["catch"](3);
|
|
225
|
+
_duration = Date.now() - startTime;
|
|
226
|
+
errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
|
|
227
|
+
this.logError('加载商品价格失败', {
|
|
228
|
+
productCount: ids.length,
|
|
229
|
+
duration: "".concat(_duration, "ms"),
|
|
230
|
+
error: errorMessage
|
|
231
|
+
});
|
|
232
|
+
throw _context2.t0;
|
|
233
|
+
case 18:
|
|
139
234
|
case "end":
|
|
140
235
|
return _context2.stop();
|
|
141
236
|
}
|
|
142
|
-
}, _callee2, this);
|
|
237
|
+
}, _callee2, this, [[3, 12]]);
|
|
143
238
|
}));
|
|
144
239
|
function loadProductsPrice(_x3) {
|
|
145
240
|
return _loadProductsPrice.apply(this, arguments);
|
|
@@ -159,32 +254,46 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
159
254
|
key: "getProductsWithPrice",
|
|
160
255
|
value: (function () {
|
|
161
256
|
var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext) {
|
|
162
|
-
var cacheKey, result;
|
|
257
|
+
var cacheKey, cachedProducts, startTime, result, duration;
|
|
163
258
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
164
259
|
while (1) switch (_context3.prev = _context3.next) {
|
|
165
260
|
case 0:
|
|
166
261
|
cacheKey = schedule_date; // 检查缓存
|
|
167
262
|
if (!this.productsPriceCache.has(cacheKey)) {
|
|
168
|
-
_context3.next =
|
|
263
|
+
_context3.next = 6;
|
|
169
264
|
break;
|
|
170
265
|
}
|
|
171
266
|
console.log("[ProductsModule] \uD83D\uDCB0 \u5546\u54C1\u4EF7\u683C\u7F13\u5B58\u547D\u4E2D: ".concat(cacheKey));
|
|
172
|
-
|
|
173
|
-
|
|
267
|
+
cachedProducts = this.productsPriceCache.get(cacheKey);
|
|
268
|
+
this.logInfo('商品价格缓存命中', {
|
|
269
|
+
cacheKey: cacheKey,
|
|
270
|
+
productCount: cachedProducts.length
|
|
271
|
+
});
|
|
272
|
+
return _context3.abrupt("return", cachedProducts);
|
|
273
|
+
case 6:
|
|
174
274
|
// 发起新请求并应用价格
|
|
175
275
|
console.log("[ProductsModule] \uD83C\uDF10 \u83B7\u53D6\u5546\u54C1\u5E76\u5E94\u7528\u4EF7\u683C: ".concat(cacheKey));
|
|
176
|
-
|
|
276
|
+
this.logInfo('商品价格缓存未命中,准备获取', {
|
|
277
|
+
cacheKey: cacheKey
|
|
278
|
+
});
|
|
279
|
+
startTime = Date.now();
|
|
280
|
+
_context3.next = 11;
|
|
177
281
|
return this.prepareProductsWithPrice(schedule_date, extraContext);
|
|
178
|
-
case
|
|
282
|
+
case 11:
|
|
179
283
|
result = _context3.sent;
|
|
180
|
-
// 存入缓存
|
|
284
|
+
duration = Date.now() - startTime; // 存入缓存
|
|
181
285
|
this.productsPriceCache.set(cacheKey, result);
|
|
182
286
|
console.log("[ProductsModule] \u2705 \u5546\u54C1\u4EF7\u683C\u5DF2\u7F13\u5B58: ".concat(cacheKey, ", \u5171 ").concat(result.length, " \u4E2A\u5546\u54C1"));
|
|
287
|
+
this.logInfo('商品价格已缓存', {
|
|
288
|
+
cacheKey: cacheKey,
|
|
289
|
+
productCount: result.length,
|
|
290
|
+
duration: "".concat(duration, "ms")
|
|
291
|
+
});
|
|
183
292
|
|
|
184
293
|
// 清理过期缓存
|
|
185
294
|
this.cleanExpiredPriceCache();
|
|
186
295
|
return _context3.abrupt("return", result);
|
|
187
|
-
case
|
|
296
|
+
case 18:
|
|
188
297
|
case "end":
|
|
189
298
|
return _context3.stop();
|
|
190
299
|
}
|
|
@@ -207,18 +316,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
207
316
|
key: "prepareProductsWithPrice",
|
|
208
317
|
value: (function () {
|
|
209
318
|
var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext) {
|
|
210
|
-
var allProducts, priceData, context, processedProducts;
|
|
319
|
+
var _priceData$length, allProducts, priceData, context, processedProducts, errorMessage;
|
|
211
320
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
212
321
|
while (1) switch (_context4.prev = _context4.next) {
|
|
213
322
|
case 0:
|
|
214
|
-
|
|
215
|
-
|
|
323
|
+
this.logInfo('prepareProductsWithPrice 开始处理', {
|
|
324
|
+
schedule_date: schedule_date
|
|
325
|
+
});
|
|
326
|
+
_context4.prev = 1;
|
|
327
|
+
_context4.next = 4;
|
|
216
328
|
return this.getProducts();
|
|
217
|
-
case
|
|
329
|
+
case 4:
|
|
218
330
|
allProducts = _context4.sent;
|
|
331
|
+
this.logInfo('获取到商品列表', {
|
|
332
|
+
productCount: allProducts.length
|
|
333
|
+
});
|
|
219
334
|
console.log("[ProductsModule] \uD83C\uDF10 \u5F00\u59CB\u83B7\u53D6\u5546\u54C1\u62A5\u4EF7\u5355\u4EF7\u683C");
|
|
220
335
|
// 2. 获取价格数据
|
|
221
|
-
_context4.next =
|
|
336
|
+
_context4.next = 9;
|
|
222
337
|
return this.loadProductsPrice({
|
|
223
338
|
ids: allProducts.map(function (product) {
|
|
224
339
|
return product.id;
|
|
@@ -227,37 +342,56 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
227
342
|
}),
|
|
228
343
|
schedule_date: schedule_date
|
|
229
344
|
});
|
|
230
|
-
case
|
|
345
|
+
case 9:
|
|
231
346
|
priceData = _context4.sent;
|
|
232
347
|
console.log("[ProductsModule] \uD83C\uDF10 \u83B7\u53D6\u5546\u54C1\u62A5\u4EF7\u5355\u4EF7\u683C\u6210\u529F", priceData);
|
|
348
|
+
this.logInfo('获取商品报价单价格成功', {
|
|
349
|
+
priceDataCount: (_priceData$length = priceData === null || priceData === void 0 ? void 0 : priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
|
|
350
|
+
});
|
|
351
|
+
|
|
233
352
|
// 3. 构建上下文(包含价格数据,合并外部传入的额外上下文)
|
|
234
353
|
context = _objectSpread({
|
|
235
354
|
schedule_date: schedule_date,
|
|
236
355
|
priceData: priceData
|
|
237
356
|
}, extraContext);
|
|
238
357
|
console.log("[ProductsModule] \uD83C\uDF10 \u901A\u8FC7\u683C\u5F0F\u5316\u5668\u6D41\u7A0B\u5904\u7406\u5546\u54C1\uFF08\u5305\u62EC\u4EF7\u683C\u5E94\u7528\u3001\u5B57\u6BB5\u6269\u5C55\u7B49\uFF09");
|
|
358
|
+
this.logInfo('开始通过格式化器流程处理商品', {
|
|
359
|
+
formatterCount: this.formatters.length
|
|
360
|
+
});
|
|
361
|
+
|
|
239
362
|
// 4. 通过格式化器流程处理商品(包括价格应用、字段扩展等)
|
|
240
|
-
_context4.next =
|
|
363
|
+
_context4.next = 17;
|
|
241
364
|
return this.applyFormatters(allProducts, context);
|
|
242
|
-
case
|
|
365
|
+
case 17:
|
|
243
366
|
processedProducts = _context4.sent;
|
|
244
367
|
console.log("[ProductsModule] \uD83C\uDF10 \u901A\u8FC7\u683C\u5F0F\u5316\u5668\u6D41\u7A0B\u5904\u7406\u5546\u54C1\uFF08\u5305\u62EC\u4EF7\u683C\u5E94\u7528\u3001\u5B57\u6BB5\u6269\u5C55\u7B49\uFF09\u6210\u529F", processedProducts);
|
|
368
|
+
this.logInfo('prepareProductsWithPrice 处理完成', {
|
|
369
|
+
originalProductCount: allProducts.length,
|
|
370
|
+
processedProductCount: processedProducts.length,
|
|
371
|
+
formatterCount: this.formatters.length
|
|
372
|
+
});
|
|
373
|
+
|
|
245
374
|
// 5. 触发钩子事件(用于外部监听)
|
|
246
|
-
_context4.next =
|
|
375
|
+
_context4.next = 22;
|
|
247
376
|
return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
|
|
248
|
-
case
|
|
377
|
+
case 22:
|
|
249
378
|
return _context4.abrupt("return", processedProducts);
|
|
250
|
-
case
|
|
251
|
-
_context4.prev =
|
|
252
|
-
_context4.t0 = _context4["catch"](
|
|
379
|
+
case 25:
|
|
380
|
+
_context4.prev = 25;
|
|
381
|
+
_context4.t0 = _context4["catch"](1);
|
|
382
|
+
errorMessage = _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0);
|
|
253
383
|
console.log("[ProductsModule] \uD83C\uDF10 ERROR", _context4.t0);
|
|
254
|
-
|
|
384
|
+
this.logError('prepareProductsWithPrice 处理失败', {
|
|
385
|
+
schedule_date: schedule_date,
|
|
386
|
+
error: errorMessage
|
|
387
|
+
});
|
|
388
|
+
case 30:
|
|
255
389
|
return _context4.abrupt("return", []);
|
|
256
|
-
case
|
|
390
|
+
case 31:
|
|
257
391
|
case "end":
|
|
258
392
|
return _context4.stop();
|
|
259
393
|
}
|
|
260
|
-
}, _callee4, this, [[
|
|
394
|
+
}, _callee4, this, [[1, 25]]);
|
|
261
395
|
}));
|
|
262
396
|
function prepareProductsWithPrice(_x6, _x7) {
|
|
263
397
|
return _prepareProductsWithPrice.apply(this, arguments);
|
|
@@ -276,50 +410,69 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
276
410
|
key: "applyFormatters",
|
|
277
411
|
value: (function () {
|
|
278
412
|
var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products, context) {
|
|
279
|
-
var result, i, formatter;
|
|
413
|
+
var result, i, formatter, errorMessage;
|
|
280
414
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
281
415
|
while (1) switch (_context5.prev = _context5.next) {
|
|
282
416
|
case 0:
|
|
283
417
|
result = products;
|
|
284
418
|
if (!(this.formatters.length === 0)) {
|
|
285
|
-
_context5.next =
|
|
419
|
+
_context5.next = 5;
|
|
286
420
|
break;
|
|
287
421
|
}
|
|
288
422
|
console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
|
|
423
|
+
this.logWarning('没有注册任何格式化器', {
|
|
424
|
+
productCount: products.length
|
|
425
|
+
});
|
|
289
426
|
return _context5.abrupt("return", result);
|
|
290
|
-
case 4:
|
|
291
|
-
i = 0;
|
|
292
427
|
case 5:
|
|
428
|
+
this.logInfo('开始应用格式化器', {
|
|
429
|
+
productCount: products.length,
|
|
430
|
+
formatterCount: this.formatters.length
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// 依次应用每个格式化器
|
|
434
|
+
i = 0;
|
|
435
|
+
case 7:
|
|
293
436
|
if (!(i < this.formatters.length)) {
|
|
294
|
-
_context5.next =
|
|
437
|
+
_context5.next = 24;
|
|
295
438
|
break;
|
|
296
439
|
}
|
|
297
440
|
formatter = this.formatters[i];
|
|
298
|
-
_context5.prev =
|
|
441
|
+
_context5.prev = 9;
|
|
299
442
|
console.log("[ProductsModule] \uD83D\uDCDD \u5E94\u7528\u683C\u5F0F\u5316\u5668 ".concat(i + 1, "/").concat(this.formatters.length));
|
|
300
|
-
_context5.next =
|
|
443
|
+
_context5.next = 13;
|
|
301
444
|
return formatter(result, context);
|
|
302
|
-
case
|
|
445
|
+
case 13:
|
|
303
446
|
result = _context5.sent;
|
|
304
|
-
_context5.next =
|
|
447
|
+
_context5.next = 21;
|
|
305
448
|
break;
|
|
306
|
-
case
|
|
307
|
-
_context5.prev =
|
|
308
|
-
_context5.t0 = _context5["catch"](
|
|
449
|
+
case 16:
|
|
450
|
+
_context5.prev = 16;
|
|
451
|
+
_context5.t0 = _context5["catch"](9);
|
|
452
|
+
errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
|
|
309
453
|
console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context5.t0);
|
|
454
|
+
this.logError("\u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25"), {
|
|
455
|
+
formatterIndex: i + 1,
|
|
456
|
+
totalFormatters: this.formatters.length,
|
|
457
|
+
error: errorMessage
|
|
458
|
+
});
|
|
310
459
|
// 继续执行后续格式化器,不中断流程
|
|
311
|
-
case
|
|
460
|
+
case 21:
|
|
312
461
|
i++;
|
|
313
|
-
_context5.next =
|
|
462
|
+
_context5.next = 7;
|
|
314
463
|
break;
|
|
315
|
-
case
|
|
464
|
+
case 24:
|
|
316
465
|
console.log("[ProductsModule] \u2705 \u6240\u6709\u683C\u5F0F\u5316\u5668\u5DF2\u5E94\u7528\uFF0C\u5171 ".concat(this.formatters.length, " \u4E2A"));
|
|
466
|
+
this.logInfo('所有格式化器已应用', {
|
|
467
|
+
formatterCount: this.formatters.length,
|
|
468
|
+
resultProductCount: result.length
|
|
469
|
+
});
|
|
317
470
|
return _context5.abrupt("return", result);
|
|
318
|
-
case
|
|
471
|
+
case 27:
|
|
319
472
|
case "end":
|
|
320
473
|
return _context5.stop();
|
|
321
474
|
}
|
|
322
|
-
}, _callee5, this, [[
|
|
475
|
+
}, _callee5, this, [[9, 16]]);
|
|
323
476
|
}));
|
|
324
477
|
function applyFormatters(_x8, _x9) {
|
|
325
478
|
return _applyFormatters.apply(this, arguments);
|
|
@@ -445,13 +598,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
445
598
|
key: "loadProductsByServer",
|
|
446
599
|
value: (function () {
|
|
447
600
|
var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
448
|
-
var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, _this$otherParams, _productsData$
|
|
601
|
+
var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, startTime, _this$otherParams, _productsData$data2, productsData, productList, duration, _duration2, errorMessage;
|
|
449
602
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
450
603
|
while (1) switch (_context6.prev = _context6.next) {
|
|
451
604
|
case 0:
|
|
452
605
|
_ref2 = params || {}, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids, _ref2$product_ids = _ref2.product_ids, product_ids = _ref2$product_ids === void 0 ? [] : _ref2$product_ids, _ref2$collection = _ref2.collection, collection = _ref2$collection === void 0 ? [] : _ref2$collection, customer_id = _ref2.customer_id, cacheId = _ref2.cacheId;
|
|
453
|
-
|
|
454
|
-
|
|
606
|
+
this.logInfo('开始从服务器加载商品列表', {
|
|
607
|
+
categoryIdsCount: category_ids.length,
|
|
608
|
+
productIdsCount: product_ids.length,
|
|
609
|
+
collectionCount: Array.isArray(collection) ? collection.length : collection ? 1 : 0,
|
|
610
|
+
customer_id: customer_id
|
|
611
|
+
});
|
|
612
|
+
startTime = Date.now();
|
|
613
|
+
_context6.prev = 3;
|
|
614
|
+
_context6.next = 6;
|
|
455
615
|
return this.request.post("/product/query", {
|
|
456
616
|
open_bundle: 1,
|
|
457
617
|
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
@@ -479,25 +639,39 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
479
639
|
}, {
|
|
480
640
|
cache: undefined
|
|
481
641
|
});
|
|
482
|
-
case
|
|
642
|
+
case 6:
|
|
483
643
|
productsData = _context6.sent;
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
644
|
+
productList = (productsData === null || productsData === void 0 || (_productsData$data2 = productsData.data) === null || _productsData$data2 === void 0 ? void 0 : _productsData$data2.list) || [];
|
|
645
|
+
duration = Date.now() - startTime;
|
|
646
|
+
this.logInfo('从服务器加载商品列表成功', {
|
|
647
|
+
productCount: productList.length,
|
|
648
|
+
duration: "".concat(duration, "ms")
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// 保存到 IndexDB
|
|
652
|
+
_context6.next = 12;
|
|
653
|
+
return this.saveProductsToIndexDB(productList);
|
|
654
|
+
case 12:
|
|
655
|
+
_context6.next = 14;
|
|
488
656
|
return this.core.effects.emit(ProductsHooks.onProductsLoaded, productsData.data.list);
|
|
489
|
-
case
|
|
657
|
+
case 14:
|
|
490
658
|
return _context6.abrupt("return", productsData.data.list);
|
|
491
|
-
case
|
|
492
|
-
_context6.prev =
|
|
493
|
-
_context6.t0 = _context6["catch"](
|
|
659
|
+
case 17:
|
|
660
|
+
_context6.prev = 17;
|
|
661
|
+
_context6.t0 = _context6["catch"](3);
|
|
662
|
+
_duration2 = Date.now() - startTime;
|
|
663
|
+
errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
|
|
494
664
|
console.error('[Products] 加载商品数据失败:', _context6.t0);
|
|
665
|
+
this.logError('从服务器加载商品列表失败', {
|
|
666
|
+
duration: "".concat(_duration2, "ms"),
|
|
667
|
+
error: errorMessage
|
|
668
|
+
});
|
|
495
669
|
return _context6.abrupt("return", []);
|
|
496
|
-
case
|
|
670
|
+
case 24:
|
|
497
671
|
case "end":
|
|
498
672
|
return _context6.stop();
|
|
499
673
|
}
|
|
500
|
-
}, _callee6, this, [[
|
|
674
|
+
}, _callee6, this, [[3, 17]]);
|
|
501
675
|
}));
|
|
502
676
|
function loadProductsByServer(_x10) {
|
|
503
677
|
return _loadProductsByServer.apply(this, arguments);
|
|
@@ -561,35 +735,46 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
561
735
|
key: "clear",
|
|
562
736
|
value: (function () {
|
|
563
737
|
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
738
|
+
var errorMessage;
|
|
564
739
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
565
740
|
while (1) switch (_context9.prev = _context9.next) {
|
|
566
741
|
case 0:
|
|
742
|
+
this.logInfo('开始清空缓存', {
|
|
743
|
+
currentProductCount: this.store.list.length,
|
|
744
|
+
priceCacheCount: this.productsPriceCache.size
|
|
745
|
+
});
|
|
567
746
|
this.store.list = [];
|
|
568
747
|
this.store.map.clear();
|
|
569
748
|
|
|
570
749
|
// 同时清空 IndexDB 中的所有数据(包括商品和元数据)
|
|
571
750
|
if (!this.dbManager) {
|
|
572
|
-
_context9.next =
|
|
751
|
+
_context9.next = 16;
|
|
573
752
|
break;
|
|
574
753
|
}
|
|
575
|
-
_context9.prev =
|
|
576
|
-
_context9.next =
|
|
754
|
+
_context9.prev = 4;
|
|
755
|
+
_context9.next = 7;
|
|
577
756
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
578
|
-
case
|
|
757
|
+
case 7:
|
|
579
758
|
console.log('[Products] IndexDB 缓存已清空');
|
|
580
|
-
|
|
759
|
+
this.logInfo('IndexDB 缓存已清空');
|
|
760
|
+
_context9.next = 16;
|
|
581
761
|
break;
|
|
582
|
-
case
|
|
583
|
-
_context9.prev =
|
|
584
|
-
_context9.t0 = _context9["catch"](
|
|
762
|
+
case 11:
|
|
763
|
+
_context9.prev = 11;
|
|
764
|
+
_context9.t0 = _context9["catch"](4);
|
|
765
|
+
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
585
766
|
console.error('[Products] 清空 IndexDB 缓存失败:', _context9.t0);
|
|
586
|
-
|
|
767
|
+
this.logError('清空 IndexDB 缓存失败', {
|
|
768
|
+
error: errorMessage
|
|
769
|
+
});
|
|
770
|
+
case 16:
|
|
587
771
|
console.log('[Products] 缓存已清空');
|
|
588
|
-
|
|
772
|
+
this.logInfo('缓存清空完成');
|
|
773
|
+
case 18:
|
|
589
774
|
case "end":
|
|
590
775
|
return _context9.stop();
|
|
591
776
|
}
|
|
592
|
-
}, _callee9, this, [[
|
|
777
|
+
}, _callee9, this, [[4, 11]]);
|
|
593
778
|
}));
|
|
594
779
|
function clear() {
|
|
595
780
|
return _clear.apply(this, arguments);
|
|
@@ -605,32 +790,40 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
605
790
|
key: "loadProductsFromIndexDB",
|
|
606
791
|
value: (function () {
|
|
607
792
|
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
608
|
-
var products;
|
|
793
|
+
var _products$length, products, errorMessage;
|
|
609
794
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
610
795
|
while (1) switch (_context10.prev = _context10.next) {
|
|
611
796
|
case 0:
|
|
612
797
|
if (this.dbManager) {
|
|
613
|
-
_context10.next =
|
|
798
|
+
_context10.next = 3;
|
|
614
799
|
break;
|
|
615
800
|
}
|
|
801
|
+
this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
|
|
616
802
|
return _context10.abrupt("return", []);
|
|
617
|
-
case
|
|
618
|
-
_context10.prev =
|
|
619
|
-
_context10.next =
|
|
803
|
+
case 3:
|
|
804
|
+
_context10.prev = 3;
|
|
805
|
+
_context10.next = 6;
|
|
620
806
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
621
|
-
case
|
|
807
|
+
case 6:
|
|
622
808
|
products = _context10.sent;
|
|
809
|
+
this.logInfo('从 IndexDB 加载商品数据', {
|
|
810
|
+
productCount: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
|
|
811
|
+
});
|
|
623
812
|
return _context10.abrupt("return", products || []);
|
|
624
|
-
case
|
|
625
|
-
_context10.prev =
|
|
626
|
-
_context10.t0 = _context10["catch"](
|
|
813
|
+
case 11:
|
|
814
|
+
_context10.prev = 11;
|
|
815
|
+
_context10.t0 = _context10["catch"](3);
|
|
816
|
+
errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
|
|
627
817
|
console.error('[Products] 从 IndexDB 读取数据失败:', _context10.t0);
|
|
818
|
+
this.logError('从 IndexDB 读取数据失败', {
|
|
819
|
+
error: errorMessage
|
|
820
|
+
});
|
|
628
821
|
return _context10.abrupt("return", []);
|
|
629
|
-
case
|
|
822
|
+
case 17:
|
|
630
823
|
case "end":
|
|
631
824
|
return _context10.stop();
|
|
632
825
|
}
|
|
633
|
-
}, _callee10, this, [[
|
|
826
|
+
}, _callee10, this, [[3, 11]]);
|
|
634
827
|
}));
|
|
635
828
|
function loadProductsFromIndexDB() {
|
|
636
829
|
return _loadProductsFromIndexDB.apply(this, arguments);
|
|
@@ -647,39 +840,51 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
647
840
|
value: (function () {
|
|
648
841
|
var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(products) {
|
|
649
842
|
var _this2 = this;
|
|
650
|
-
var savePromises;
|
|
843
|
+
var savePromises, errorMessage;
|
|
651
844
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
652
845
|
while (1) switch (_context11.prev = _context11.next) {
|
|
653
846
|
case 0:
|
|
654
847
|
if (this.dbManager) {
|
|
655
|
-
_context11.next =
|
|
848
|
+
_context11.next = 3;
|
|
656
849
|
break;
|
|
657
850
|
}
|
|
851
|
+
this.logWarning('saveProductsToIndexDB: dbManager 不可用');
|
|
658
852
|
return _context11.abrupt("return");
|
|
659
|
-
case
|
|
660
|
-
|
|
661
|
-
|
|
853
|
+
case 3:
|
|
854
|
+
this.logInfo('开始保存商品数据到 IndexDB', {
|
|
855
|
+
productCount: products.length
|
|
856
|
+
});
|
|
857
|
+
_context11.prev = 4;
|
|
858
|
+
_context11.next = 7;
|
|
662
859
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
663
|
-
case
|
|
860
|
+
case 7:
|
|
664
861
|
// 逐个保存商品(每个商品是独立的记录)
|
|
665
862
|
savePromises = products.map(function (product) {
|
|
666
863
|
return _this2.dbManager.add(INDEXDB_STORE_NAME, product);
|
|
667
864
|
});
|
|
668
|
-
_context11.next =
|
|
865
|
+
_context11.next = 10;
|
|
669
866
|
return Promise.all(savePromises);
|
|
670
|
-
case
|
|
867
|
+
case 10:
|
|
671
868
|
console.log("[Products] \u5DF2\u5C06 ".concat(products.length, " \u4E2A\u5546\u54C1\u5E73\u94FA\u4FDD\u5B58\u5230 IndexDB"));
|
|
672
|
-
|
|
869
|
+
this.logInfo('商品数据已保存到 IndexDB', {
|
|
870
|
+
productCount: products.length
|
|
871
|
+
});
|
|
872
|
+
_context11.next = 19;
|
|
673
873
|
break;
|
|
674
|
-
case 11:
|
|
675
|
-
_context11.prev = 11;
|
|
676
|
-
_context11.t0 = _context11["catch"](2);
|
|
677
|
-
console.error('[Products] 保存数据到 IndexDB 失败:', _context11.t0);
|
|
678
874
|
case 14:
|
|
875
|
+
_context11.prev = 14;
|
|
876
|
+
_context11.t0 = _context11["catch"](4);
|
|
877
|
+
errorMessage = _context11.t0 instanceof Error ? _context11.t0.message : String(_context11.t0);
|
|
878
|
+
console.error('[Products] 保存数据到 IndexDB 失败:', _context11.t0);
|
|
879
|
+
this.logError('保存数据到 IndexDB 失败', {
|
|
880
|
+
productCount: products.length,
|
|
881
|
+
error: errorMessage
|
|
882
|
+
});
|
|
883
|
+
case 19:
|
|
679
884
|
case "end":
|
|
680
885
|
return _context11.stop();
|
|
681
886
|
}
|
|
682
|
-
}, _callee11, this, [[
|
|
887
|
+
}, _callee11, this, [[4, 14]]);
|
|
683
888
|
}));
|
|
684
889
|
function saveProductsToIndexDB(_x12) {
|
|
685
890
|
return _saveProductsToIndexDB.apply(this, arguments);
|
|
@@ -719,18 +924,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
719
924
|
key: "preload",
|
|
720
925
|
value: (function () {
|
|
721
926
|
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
722
|
-
var cachedData, products;
|
|
927
|
+
var startTime, cachedData, duration, errorMessage, products, _duration3, _duration4;
|
|
723
928
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
724
929
|
while (1) switch (_context12.prev = _context12.next) {
|
|
725
930
|
case 0:
|
|
726
931
|
console.log('[Products] 开始预加载数据...');
|
|
727
|
-
|
|
728
|
-
|
|
932
|
+
startTime = Date.now();
|
|
933
|
+
this.logInfo('开始预加载数据');
|
|
934
|
+
_context12.prev = 3;
|
|
935
|
+
_context12.next = 6;
|
|
729
936
|
return this.loadProductsFromIndexDB();
|
|
730
|
-
case
|
|
937
|
+
case 6:
|
|
731
938
|
cachedData = _context12.sent;
|
|
732
939
|
if (!(cachedData && cachedData.length > 0)) {
|
|
733
|
-
_context12.next =
|
|
940
|
+
_context12.next = 15;
|
|
734
941
|
break;
|
|
735
942
|
}
|
|
736
943
|
console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
|
|
@@ -739,36 +946,60 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
739
946
|
// 同步更新 Map 缓存
|
|
740
947
|
this.syncProductsMap();
|
|
741
948
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
949
|
+
duration = Date.now() - startTime;
|
|
950
|
+
this.logInfo('预加载完成(从 IndexDB)', {
|
|
951
|
+
productCount: cachedData.length,
|
|
952
|
+
duration: "".concat(duration, "ms"),
|
|
953
|
+
source: 'IndexDB'
|
|
954
|
+
});
|
|
742
955
|
return _context12.abrupt("return");
|
|
743
|
-
case
|
|
956
|
+
case 15:
|
|
744
957
|
console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
|
|
745
|
-
|
|
958
|
+
this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
|
|
959
|
+
_context12.next = 24;
|
|
746
960
|
break;
|
|
747
|
-
case
|
|
748
|
-
_context12.prev =
|
|
749
|
-
_context12.t0 = _context12["catch"](
|
|
961
|
+
case 19:
|
|
962
|
+
_context12.prev = 19;
|
|
963
|
+
_context12.t0 = _context12["catch"](3);
|
|
964
|
+
errorMessage = _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0);
|
|
750
965
|
console.warn('[Products] 从 IndexDB 加载数据失败:', _context12.t0);
|
|
751
|
-
|
|
752
|
-
|
|
966
|
+
this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
|
|
967
|
+
error: errorMessage
|
|
968
|
+
});
|
|
969
|
+
case 24:
|
|
970
|
+
_context12.next = 26;
|
|
753
971
|
return this.loadProductsByServer();
|
|
754
|
-
case
|
|
972
|
+
case 26:
|
|
755
973
|
products = _context12.sent;
|
|
756
974
|
if (!(products && products.length > 0)) {
|
|
757
|
-
_context12.next =
|
|
975
|
+
_context12.next = 37;
|
|
758
976
|
break;
|
|
759
977
|
}
|
|
760
|
-
_context12.next =
|
|
978
|
+
_context12.next = 30;
|
|
761
979
|
return this.saveProductsToIndexDB(products);
|
|
762
|
-
case
|
|
980
|
+
case 30:
|
|
763
981
|
this.store.list = cloneDeep(products);
|
|
764
982
|
// 同步更新 Map 缓存
|
|
765
983
|
this.syncProductsMap();
|
|
766
984
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
767
|
-
|
|
985
|
+
_duration3 = Date.now() - startTime;
|
|
986
|
+
this.logInfo('预加载完成(从服务器)', {
|
|
987
|
+
productCount: products.length,
|
|
988
|
+
duration: "".concat(_duration3, "ms"),
|
|
989
|
+
source: 'Server'
|
|
990
|
+
});
|
|
991
|
+
_context12.next = 39;
|
|
992
|
+
break;
|
|
993
|
+
case 37:
|
|
994
|
+
_duration4 = Date.now() - startTime;
|
|
995
|
+
this.logWarning('预加载完成但未获取到数据', {
|
|
996
|
+
duration: "".concat(_duration4, "ms")
|
|
997
|
+
});
|
|
998
|
+
case 39:
|
|
768
999
|
case "end":
|
|
769
1000
|
return _context12.stop();
|
|
770
1001
|
}
|
|
771
|
-
}, _callee12, this, [[
|
|
1002
|
+
}, _callee12, this, [[3, 19]]);
|
|
772
1003
|
}));
|
|
773
1004
|
function preload() {
|
|
774
1005
|
return _preload.apply(this, arguments);
|