fix(mock): 修复事件数据和 API 返回格式

- events.js: 增强搜索支持股票名称/代码,修复字段名
- event.js: 返回结构调整为 { data, pagination }

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zdl
2025-12-16 20:37:20 +08:00
parent 4954373b5b
commit b52b54347d
2 changed files with 28 additions and 15 deletions

View File

@@ -874,8 +874,20 @@ export function generateMockEvents(params = {}) {
e.title.toLowerCase().includes(query) || e.title.toLowerCase().includes(query) ||
e.description.toLowerCase().includes(query) || e.description.toLowerCase().includes(query) ||
// keywords 是对象数组 { concept, score, ... },需要访问 concept 属性 // keywords 是对象数组 { concept, score, ... },需要访问 concept 属性
e.keywords.some(k => k.concept && k.concept.toLowerCase().includes(query)) e.keywords.some(k => k.concept && k.concept.toLowerCase().includes(query)) ||
// 搜索 related_stocks 中的股票名称和代码
(e.related_stocks && e.related_stocks.some(stock =>
(stock.stock_name && stock.stock_name.toLowerCase().includes(query)) ||
(stock.stock_code && stock.stock_code.toLowerCase().includes(query))
)) ||
// 搜索行业
(e.industry && e.industry.toLowerCase().includes(query))
); );
// 如果搜索结果为空,返回所有事件(宽松模式)
if (filteredEvents.length === 0) {
filteredEvents = allEvents;
}
} }
// 行业筛选 // 行业筛选
@@ -1042,7 +1054,7 @@ function generateTransmissionChain(industry, index) {
let nodeName; let nodeName;
if (nodeType === 'company' && industryStock) { if (nodeType === 'company' && industryStock) {
nodeName = industryStock.name; nodeName = industryStock.stock_name;
} else if (nodeType === 'industry') { } else if (nodeType === 'industry') {
nodeName = `${industry}产业`; nodeName = `${industry}产业`;
} else if (nodeType === 'policy') { } else if (nodeType === 'policy') {
@@ -1133,7 +1145,7 @@ export function generateDynamicNewsEvents(timeRange = null, count = 30) {
const stock = industryStocks[j % industryStocks.length]; const stock = industryStocks[j % industryStocks.length];
relatedStocks.push({ relatedStocks.push({
stock_code: stock.stock_code, stock_code: stock.stock_code,
stock_name: stock.name, stock_name: stock.stock_name,
relation_desc: relationDescriptions[j % relationDescriptions.length] relation_desc: relationDescriptions[j % relationDescriptions.length]
}); });
} }
@@ -1145,7 +1157,7 @@ export function generateDynamicNewsEvents(timeRange = null, count = 30) {
if (!relatedStocks.some(s => s.stock_code === randomStock.stock_code)) { if (!relatedStocks.some(s => s.stock_code === randomStock.stock_code)) {
relatedStocks.push({ relatedStocks.push({
stock_code: randomStock.stock_code, stock_code: randomStock.stock_code,
stock_name: randomStock.name, stock_name: randomStock.stock_name,
relation_desc: relationDescriptions[relatedStocks.length % relationDescriptions.length] relation_desc: relationDescriptions[relatedStocks.length % relationDescriptions.length]
}); });
} }

View File

@@ -119,9 +119,12 @@ export const eventHandlers = [
try { try {
const result = generateMockEvents(params); const result = generateMockEvents(params);
// 返回格式兼容 NewsPanel 期望的结构
// NewsPanel 期望: { success, data: [], pagination: {} }
return HttpResponse.json({ return HttpResponse.json({
success: true, success: true,
data: result, data: result.events, // 事件数组
pagination: result.pagination, // 分页信息
message: '获取成功' message: '获取成功'
}); });
} catch (error) { } catch (error) {
@@ -135,16 +138,14 @@ export const eventHandlers = [
{ {
success: false, success: false,
error: '获取事件列表失败', error: '获取事件列表失败',
data: { data: [],
events: [], pagination: {
pagination: { page: 1,
page: 1, per_page: 10,
per_page: 10, total: 0,
total: 0, pages: 0,
pages: 0, // ← 对齐后端字段名 has_prev: false,
has_prev: false, // ← 对齐后端 has_next: false
has_next: false // ← 对齐后端
}
} }
}, },
{ status: 500 } { status: 500 }