From e31e4118a052e167e255e591c5b7f96f268ee1b3 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Mon, 3 Nov 2025 14:18:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=A6=82=E5=BF=B5=E7=BB=84=E4=BB=B6=E4=BB=A5=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E7=9C=9F=E5=AE=9EAPI=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改内容: - SimpleConceptCard.js: 改用 concept.concept 和 concept.score 字段 - DetailedConceptCard.js: 改用 concept.concept、concept.score 和 concept.price_info.avg_change_pct - RelatedConceptsSection/index.js: 导航时使用 concept.concept 字段 - events.js mock数据: 更新keywords生成函数,使用concept/score/price_info结构 数据结构变更: - name → concept (概念名称) - relevance (0-100) → score (0-1) - avg_change_pct → price_info.avg_change_pct (嵌套结构) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/mocks/data/events.js | 29 ++++++++++++------- .../DetailedConceptCard.js | 11 ++++--- .../SimpleConceptCard.js | 7 +++-- .../RelatedConceptsSection/index.js | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) 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 (