feat: 添加mock数据
This commit is contained in:
@@ -155,5 +155,190 @@ export const conceptHandlers = [
|
||||
total: stocks.length,
|
||||
concept_id: conceptId
|
||||
});
|
||||
}),
|
||||
|
||||
// 获取最新交易日期
|
||||
http.get('http://111.198.58.126:16801/price/latest', async () => {
|
||||
await delay(200);
|
||||
|
||||
const today = new Date();
|
||||
const dateStr = today.toISOString().split('T')[0].replace(/-/g, '');
|
||||
|
||||
console.log('[Mock Concept] 获取最新交易日期:', dateStr);
|
||||
|
||||
return HttpResponse.json({
|
||||
latest_date: dateStr,
|
||||
timestamp: today.toISOString()
|
||||
});
|
||||
}),
|
||||
|
||||
// 搜索概念(硬编码 URL)
|
||||
http.post('http://111.198.58.126:16801/search', async ({ request }) => {
|
||||
await delay(300);
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { query = '', size = 20, page = 1, sort_by = 'change_pct' } = body;
|
||||
|
||||
console.log('[Mock Concept] 搜索概念 (硬编码URL):', { query, size, page, sort_by });
|
||||
|
||||
let results = generatePopularConcepts(size);
|
||||
|
||||
if (query) {
|
||||
results = results.filter(item =>
|
||||
item.concept.toLowerCase().includes(query.toLowerCase())
|
||||
);
|
||||
}
|
||||
|
||||
if (sort_by === 'change_pct') {
|
||||
results.sort((a, b) => b.price_info.avg_change_pct - a.price_info.avg_change_pct);
|
||||
} else if (sort_by === 'stock_count') {
|
||||
results.sort((a, b) => b.stock_count - a.stock_count);
|
||||
} else if (sort_by === 'hot_score') {
|
||||
results.sort((a, b) => b.hot_score - a.hot_score);
|
||||
}
|
||||
|
||||
return HttpResponse.json({
|
||||
results,
|
||||
total: results.length,
|
||||
page,
|
||||
size,
|
||||
message: '搜索成功'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[Mock Concept] 搜索失败:', error);
|
||||
return HttpResponse.json(
|
||||
{ results: [], total: 0, error: '搜索失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}),
|
||||
|
||||
// 获取统计数据
|
||||
http.get('http://111.198.58.126:16801/statistics', async ({ request }) => {
|
||||
await delay(300);
|
||||
|
||||
const url = new URL(request.url);
|
||||
const minStockCount = parseInt(url.searchParams.get('min_stock_count') || '3');
|
||||
const days = parseInt(url.searchParams.get('days') || '7');
|
||||
|
||||
console.log('[Mock Concept] 获取统计数据:', { minStockCount, days });
|
||||
|
||||
return HttpResponse.json({
|
||||
total_concepts: 150,
|
||||
active_concepts: 120,
|
||||
avg_stock_count: 25,
|
||||
top_concepts: generatePopularConcepts(10),
|
||||
min_stock_count: minStockCount,
|
||||
days: days,
|
||||
updated_at: new Date().toISOString()
|
||||
});
|
||||
}),
|
||||
|
||||
// 获取概念价格时间序列
|
||||
http.get('http://111.198.58.126:16801/concept/:conceptId/price-timeseries', async ({ params, request }) => {
|
||||
await delay(300);
|
||||
|
||||
const { conceptId } = params;
|
||||
const url = new URL(request.url);
|
||||
const startDate = url.searchParams.get('start_date');
|
||||
const endDate = url.searchParams.get('end_date');
|
||||
|
||||
console.log('[Mock Concept] 获取价格时间序列:', { conceptId, startDate, endDate });
|
||||
|
||||
// 生成时间序列数据
|
||||
const timeseries = [];
|
||||
const start = new Date(startDate || '2024-01-01');
|
||||
const end = new Date(endDate || new Date());
|
||||
const daysDiff = Math.ceil((end - start) / (1000 * 60 * 60 * 24));
|
||||
|
||||
for (let i = 0; i <= daysDiff; i++) {
|
||||
const date = new Date(start);
|
||||
date.setDate(date.getDate() + i);
|
||||
|
||||
// 跳过周末
|
||||
if (date.getDay() !== 0 && date.getDay() !== 6) {
|
||||
timeseries.push({
|
||||
date: date.toISOString().split('T')[0],
|
||||
avg_change_pct: (Math.random() * 8 - 2).toFixed(2),
|
||||
stock_count: Math.floor(Math.random() * 30) + 10,
|
||||
volume: Math.floor(Math.random() * 1000000000)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return HttpResponse.json({
|
||||
concept_id: conceptId,
|
||||
timeseries: timeseries,
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
});
|
||||
}),
|
||||
|
||||
// 获取概念相关新闻
|
||||
http.get('http://111.198.58.126:21891/news', async ({ request }) => {
|
||||
await delay(300);
|
||||
|
||||
const url = new URL(request.url);
|
||||
const conceptName = url.searchParams.get('concept_name');
|
||||
const startDate = url.searchParams.get('start_date');
|
||||
const endDate = url.searchParams.get('end_date');
|
||||
|
||||
console.log('[Mock Concept] 获取概念新闻:', { conceptName, startDate, endDate });
|
||||
|
||||
const news = [];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - i);
|
||||
|
||||
news.push({
|
||||
id: `news_${i}`,
|
||||
title: `${conceptName || '概念'}相关新闻标题 ${i + 1}`,
|
||||
content: `这是关于${conceptName || '概念'}的新闻内容摘要...`,
|
||||
source: ['新浪财经', '东方财富', '财联社', '证券时报'][Math.floor(Math.random() * 4)],
|
||||
publish_time: date.toISOString(),
|
||||
url: `https://example.com/news/${i}`
|
||||
});
|
||||
}
|
||||
|
||||
return HttpResponse.json({
|
||||
news: news,
|
||||
total: news.length,
|
||||
concept_name: conceptName
|
||||
});
|
||||
}),
|
||||
|
||||
// 获取概念相关研报
|
||||
http.get('http://111.198.58.126:8811/reports', async ({ request }) => {
|
||||
await delay(300);
|
||||
|
||||
const url = new URL(request.url);
|
||||
const conceptName = url.searchParams.get('concept_name');
|
||||
const startDate = url.searchParams.get('start_date');
|
||||
const endDate = url.searchParams.get('end_date');
|
||||
|
||||
console.log('[Mock Concept] 获取概念研报:', { conceptName, startDate, endDate });
|
||||
|
||||
const reports = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - i * 2);
|
||||
|
||||
reports.push({
|
||||
id: `report_${i}`,
|
||||
title: `${conceptName || '概念'}行业研究报告 ${i + 1}`,
|
||||
abstract: `本报告深入分析了${conceptName || '概念'}行业的发展趋势和投资机会...`,
|
||||
author: ['中信证券', '国泰君安', '华泰证券', '招商证券'][Math.floor(Math.random() * 4)],
|
||||
publish_time: date.toISOString(),
|
||||
rating: ['买入', '增持', '中性'][Math.floor(Math.random() * 3)],
|
||||
url: `https://example.com/report/${i}`
|
||||
});
|
||||
}
|
||||
|
||||
return HttpResponse.json({
|
||||
reports: reports,
|
||||
total: reports.length,
|
||||
concept_name: conceptName
|
||||
});
|
||||
})
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user