feat: mock数据添加
This commit is contained in:
@@ -926,6 +926,85 @@ export const eventHandlers = [
|
|||||||
|
|
||||||
// ==================== 历史事件对比相关 ====================
|
// ==================== 历史事件对比相关 ====================
|
||||||
|
|
||||||
|
// 获取历史事件列表
|
||||||
|
http.get('/api/events/:eventId/historical', async ({ params }) => {
|
||||||
|
await delay(400);
|
||||||
|
|
||||||
|
const { eventId } = params;
|
||||||
|
|
||||||
|
console.log('[Mock] 获取历史事件列表, eventId:', eventId);
|
||||||
|
|
||||||
|
// 生成历史事件数据
|
||||||
|
const generateHistoricalEvents = (count = 5) => {
|
||||||
|
const events = [];
|
||||||
|
const eventTitles = [
|
||||||
|
'芯片产业链政策扶持升级',
|
||||||
|
'新能源汽车销量创历史新高',
|
||||||
|
'人工智能大模型技术突破',
|
||||||
|
'半导体设备国产化加速',
|
||||||
|
'数字经济政策利好发布',
|
||||||
|
'新能源产业链整合提速',
|
||||||
|
'医药创新药获批上市',
|
||||||
|
'5G应用场景扩展',
|
||||||
|
'智能驾驶技术迭代升级',
|
||||||
|
'储能行业景气度上行'
|
||||||
|
];
|
||||||
|
|
||||||
|
const importanceLevels = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const daysAgo = Math.floor(Math.random() * 180) + 30; // 30-210 天前
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() - daysAgo);
|
||||||
|
|
||||||
|
const importance = importanceLevels[Math.floor(Math.random() * importanceLevels.length)];
|
||||||
|
|
||||||
|
events.push({
|
||||||
|
id: `hist_event_${i + 1}`,
|
||||||
|
title: eventTitles[i % eventTitles.length],
|
||||||
|
description: `${eventTitles[i % eventTitles.length]}的详细描述。该事件对相关产业链产生重要影响,市场关注度高,相关概念股表现活跃。`,
|
||||||
|
date: date.toISOString().split('T')[0],
|
||||||
|
importance: importance,
|
||||||
|
similarity: parseFloat((Math.random() * 0.3 + 0.7).toFixed(2)), // 0.7-1.0
|
||||||
|
impact_sectors: [
|
||||||
|
['半导体', '芯片设计', 'EDA'],
|
||||||
|
['新能源汽车', '锂电池', '充电桩'],
|
||||||
|
['人工智能', '算力', '大模型'],
|
||||||
|
['半导体设备', '国产替代', '集成电路'],
|
||||||
|
['数字经济', '云计算', '大数据']
|
||||||
|
][i % 5],
|
||||||
|
affected_stocks_count: Math.floor(Math.random() * 30) + 10, // 10-40 只股票
|
||||||
|
avg_change_pct: parseFloat((Math.random() * 10 - 2).toFixed(2)), // -2% to +8%
|
||||||
|
created_at: date.toISOString()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按日期降序排序
|
||||||
|
return events.sort((a, b) => new Date(b.date) - new Date(a.date));
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const historicalEvents = generateHistoricalEvents(5);
|
||||||
|
|
||||||
|
return HttpResponse.json({
|
||||||
|
success: true,
|
||||||
|
data: historicalEvents,
|
||||||
|
total: historicalEvents.length,
|
||||||
|
message: '获取历史事件列表成功'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Mock] 获取历史事件列表失败:', error);
|
||||||
|
return HttpResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
error: '获取历史事件列表失败',
|
||||||
|
data: []
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
// 获取历史事件相关股票
|
// 获取历史事件相关股票
|
||||||
http.get('/api/historical-events/:eventId/stocks', async ({ params }) => {
|
http.get('/api/historical-events/:eventId/stocks', async ({ params }) => {
|
||||||
await delay(500);
|
await delay(500);
|
||||||
|
|||||||
Reference in New Issue
Block a user