feat:修复mock数据
This commit is contained in:
@@ -275,70 +275,102 @@ export const conceptHandlers = [
|
||||
});
|
||||
}),
|
||||
|
||||
// 获取概念相关新闻
|
||||
http.get('http://111.198.58.126:21891/news', async ({ request }) => {
|
||||
// 获取概念相关新闻 (search_china_news)
|
||||
http.get('http://111.198.58.126:21891/search_china_news', async ({ request }) => {
|
||||
await delay(300);
|
||||
|
||||
const url = new URL(request.url);
|
||||
const conceptName = url.searchParams.get('concept_name');
|
||||
const query = url.searchParams.get('query');
|
||||
const exactMatch = url.searchParams.get('exact_match');
|
||||
const startDate = url.searchParams.get('start_date');
|
||||
const endDate = url.searchParams.get('end_date');
|
||||
const topK = parseInt(url.searchParams.get('top_k') || '100');
|
||||
|
||||
console.log('[Mock Concept] 获取概念新闻:', { conceptName, startDate, endDate });
|
||||
console.log('[Mock Concept] 搜索中国新闻:', { query, exactMatch, startDate, endDate, topK });
|
||||
|
||||
// 生成新闻数据
|
||||
const news = [];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const newsCount = Math.min(topK, Math.floor(Math.random() * 15) + 5); // 5-20 条新闻
|
||||
|
||||
for (let i = 0; i < newsCount; i++) {
|
||||
const daysAgo = Math.floor(Math.random() * 100); // 0-100 天前
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - i);
|
||||
date.setDate(date.getDate() - daysAgo);
|
||||
|
||||
const hour = Math.floor(Math.random() * 24);
|
||||
const minute = Math.floor(Math.random() * 60);
|
||||
const publishedTime = `${date.toISOString().split('T')[0]} ${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}:00`;
|
||||
|
||||
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}`
|
||||
title: `${query || '概念'}板块动态:${['利好政策发布', '行业景气度提升', '龙头企业业绩超预期', '技术突破进展', '市场需求旺盛'][i % 5]}`,
|
||||
detail: `${query || '概念'}相关新闻详细内容。近期${query || '概念'}板块表现活跃,市场关注度持续上升。多家券商研报指出,${query || '概念'}行业前景广阔,建议重点关注龙头企业投资机会。`,
|
||||
description: `${query || '概念'}板块最新动态摘要...`,
|
||||
source: ['新浪财经', '东方财富网', '财联社', '证券时报', '中国证券报', '上海证券报'][Math.floor(Math.random() * 6)],
|
||||
published_time: publishedTime,
|
||||
url: `https://finance.sina.com.cn/stock/news/${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}/news_${i}.html`
|
||||
});
|
||||
}
|
||||
|
||||
return HttpResponse.json({
|
||||
news: news,
|
||||
total: news.length,
|
||||
concept_name: conceptName
|
||||
});
|
||||
// 按时间降序排序
|
||||
news.sort((a, b) => new Date(b.published_time) - new Date(a.published_time));
|
||||
|
||||
// 返回数组(不是对象)
|
||||
return HttpResponse.json(news);
|
||||
}),
|
||||
|
||||
// 获取概念相关研报
|
||||
http.get('http://111.198.58.126:8811/reports', async ({ request }) => {
|
||||
// 获取概念相关研报 (search)
|
||||
http.get('http://111.198.58.126:8811/search', async ({ request }) => {
|
||||
await delay(300);
|
||||
|
||||
const url = new URL(request.url);
|
||||
const conceptName = url.searchParams.get('concept_name');
|
||||
const query = url.searchParams.get('query');
|
||||
const mode = url.searchParams.get('mode');
|
||||
const exactMatch = url.searchParams.get('exact_match');
|
||||
const size = parseInt(url.searchParams.get('size') || '30');
|
||||
const startDate = url.searchParams.get('start_date');
|
||||
const endDate = url.searchParams.get('end_date');
|
||||
|
||||
console.log('[Mock Concept] 获取概念研报:', { conceptName, startDate, endDate });
|
||||
console.log('[Mock Concept] 搜索研报:', { query, mode, exactMatch, size, startDate });
|
||||
|
||||
// 生成研报数据
|
||||
const reports = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const reportCount = Math.min(size, Math.floor(Math.random() * 10) + 3); // 3-12 份研报
|
||||
|
||||
const publishers = ['中信证券', '国泰君安', '华泰证券', '招商证券', '海通证券', '广发证券', '申万宏源', '兴业证券'];
|
||||
const authors = ['张明', '李华', '王强', '刘洋', '陈杰', '赵敏'];
|
||||
const ratings = ['买入', '增持', '中性', '减持', '强烈推荐'];
|
||||
const securityNames = ['行业研究', '公司研究', '策略研究', '宏观研究', '固收研究'];
|
||||
|
||||
for (let i = 0; i < reportCount; i++) {
|
||||
const daysAgo = Math.floor(Math.random() * 100); // 0-100 天前
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - i * 2);
|
||||
date.setDate(date.getDate() - daysAgo);
|
||||
|
||||
const declareDate = `${date.toISOString().split('T')[0]} ${String(Math.floor(Math.random() * 24)).padStart(2, '0')}:${String(Math.floor(Math.random() * 60)).padStart(2, '0')}:00`;
|
||||
|
||||
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}`
|
||||
report_title: `${query || '概念'}行业${['深度研究报告', '投资策略分析', '行业景气度跟踪', '估值分析报告', '竞争格局研究'][i % 5]}`,
|
||||
content: `${query || '概念'}行业研究报告内容摘要。\n\n核心观点:\n1. ${query || '概念'}行业景气度持续向好,市场规模预计将保持高速增长。\n2. 龙头企业凭借技术优势和规模效应,市场份额有望进一步提升。\n3. 政策支持力度加大,为行业发展提供有力保障。\n\n投资建议:建议重点关注行业龙头企业,给予"${ratings[Math.floor(Math.random() * ratings.length)]}"评级。`,
|
||||
abstract: `本报告深入分析了${query || '概念'}行业的发展趋势、竞争格局和投资机会,认为行业具备良好的成长性...`,
|
||||
publisher: publishers[Math.floor(Math.random() * publishers.length)],
|
||||
author: authors[Math.floor(Math.random() * authors.length)],
|
||||
declare_date: declareDate,
|
||||
rating: ratings[Math.floor(Math.random() * ratings.length)],
|
||||
security_name: securityNames[Math.floor(Math.random() * securityNames.length)],
|
||||
content_url: `https://pdf.dfcfw.com/pdf/H3_${1000000 + i}_1_${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}.pdf`
|
||||
});
|
||||
}
|
||||
|
||||
// 按时间降序排序
|
||||
reports.sort((a, b) => new Date(b.declare_date) - new Date(a.declare_date));
|
||||
|
||||
// 返回符合组件期望的格式
|
||||
return HttpResponse.json({
|
||||
reports: reports,
|
||||
results: reports,
|
||||
total: reports.length,
|
||||
concept_name: conceptName
|
||||
query: query,
|
||||
mode: mode
|
||||
});
|
||||
})
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user