diff --git a/src/mocks/data/events.js b/src/mocks/data/events.js index 021d57f1..fd439ae2 100644 --- a/src/mocks/data/events.js +++ b/src/mocks/data/events.js @@ -696,17 +696,24 @@ function generateKeywords(industry, seed) { return selectedStocks; }; - // 将字符串数组转换为对象数组,包含完整字段 - return keywordNames.map((name, index) => ({ - name: name, - stock_count: 10 + Math.floor((seed + index) % 30), // 10-39个相关股票 - relevance: 70 + Math.floor((seed * 7 + index * 11) % 30), // 70-99的相关度 - description: descriptionTemplates[name] || `${name}相关概念,市场关注度较高,具有一定的投资价值。`, - avg_change_pct: (Math.random() * 15 - 5).toFixed(2), // -5% ~ +10% 的涨跌幅 - match_type: matchTypes[(seed + index) % 3], // 随机匹配类型 - happened_times: generateHappenedTimes(seed + index), // 历史触发时间 - stocks: generateRelatedStocks(name, seed + index) // 核心相关股票 - })); + // 将字符串数组转换为对象数组,匹配真实API数据结构 + return keywordNames.map((name, index) => { + const score = (70 + Math.floor((seed * 7 + index * 11) % 30)) / 100; // 0.70-0.99的分数 + const avgChangePct = (Math.random() * 15 - 5).toFixed(2); // -5% ~ +10% 的涨跌幅 + + return { + concept: name, // 使用 concept 字段而不是 name + stock_count: 10 + Math.floor((seed + index) % 30), // 10-39个相关股票 + score: parseFloat(score.toFixed(2)), // 0-1之间的分数,而不是0-100 + description: descriptionTemplates[name] || `${name}相关概念,市场关注度较高,具有一定的投资价值。`, + price_info: { // 将 avg_change_pct 嵌套在 price_info 对象中 + avg_change_pct: parseFloat(avgChangePct) + }, + match_type: matchTypes[(seed + index) % 3], // 随机匹配类型 + happened_times: generateHappenedTimes(seed + index), // 历史触发时间 + stocks: generateRelatedStocks(name, seed + index) // 核心相关股票 + }; + }); } /** diff --git a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/DetailedConceptCard.js b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/DetailedConceptCard.js index 21a97aff..4d2c4986 100644 --- a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/DetailedConceptCard.js +++ b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/DetailedConceptCard.js @@ -35,8 +35,11 @@ const DetailedConceptCard = ({ concept, onClick }) => { const headingColor = useColorModeValue('gray.700', 'gray.200'); const stockCountColor = useColorModeValue('gray.500', 'gray.400'); + // 计算相关度百分比 + const relevanceScore = Math.round((concept.score || 0) * 100); + // 计算涨跌幅颜色 - const changePct = parseFloat(concept.avg_change_pct); + const changePct = parseFloat(concept.price_info?.avg_change_pct); const changeColor = changePct > 0 ? 'red' : changePct < 0 ? 'green' : 'gray'; const changeSymbol = changePct > 0 ? '+' : ''; @@ -61,11 +64,11 @@ const DetailedConceptCard = ({ concept, onClick }) => { {/* 左侧:概念名称 + Badge */} - {concept.name} + {concept.concept} - 相关度: {concept.relevance}% + 相关度: {relevanceScore}% {concept.stock_count} 只股票 @@ -74,7 +77,7 @@ const DetailedConceptCard = ({ concept, onClick }) => { {/* 右侧:涨跌幅 */} - {concept.avg_change_pct && ( + {concept.price_info?.avg_change_pct && ( 平均涨跌幅 diff --git a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/SimpleConceptCard.js b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/SimpleConceptCard.js index 6d09ecea..d9086717 100644 --- a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/SimpleConceptCard.js +++ b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/SimpleConceptCard.js @@ -24,7 +24,8 @@ const SimpleConceptCard = ({ concept, onClick, getRelevanceColor }) => { const conceptNameColor = useColorModeValue('gray.800', 'gray.100'); const borderColor = useColorModeValue('gray.300', 'gray.600'); - const relevanceColors = getRelevanceColor(concept.relevance); + const relevanceScore = Math.round((concept.score || 0) * 100); + const relevanceColors = getRelevanceColor(relevanceScore); return ( { > {/* 左侧:概念名 + 数量 */} - {concept.name}{' '} + {concept.concept}{' '} ({concept.stock_count}) @@ -63,7 +64,7 @@ const SimpleConceptCard = ({ concept, onClick, getRelevanceColor }) => { flexShrink={0} > - 相关度: {concept.relevance}% + 相关度: {relevanceScore}% diff --git a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js index f0355d7f..acc9e471 100644 --- a/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js +++ b/src/views/Community/components/DynamicNewsDetail/RelatedConceptsSection/index.js @@ -63,7 +63,7 @@ const RelatedConceptsSection = ({ keywords, effectiveTradingDate, eventTime }) = */ const handleConceptClick = (concept) => { // 跳转到概念中心,并搜索该概念 - navigate(`/concepts?q=${encodeURIComponent(concept.name)}`); + navigate(`/concepts?q=${encodeURIComponent(concept.concept)}`); }; return (