From 5bac525147884cc464698d89496ee66330cb1d3b Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Wed, 29 Oct 2025 19:41:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20mock=E6=95=B0=E6=8D=AE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mocks/handlers/event.js | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/mocks/handlers/event.js b/src/mocks/handlers/event.js index 91daa8e0..81247fa0 100644 --- a/src/mocks/handlers/event.js +++ b/src/mocks/handlers/event.js @@ -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 }) => { await delay(500);