diff --git a/src/views/Community/components/HeroPanel.js b/src/views/Community/components/HeroPanel.js index 3312d18f..42693b04 100644 --- a/src/views/Community/components/HeroPanel.js +++ b/src/views/Community/components/HeroPanel.js @@ -1,55 +1,29 @@ // src/views/Community/components/HeroPanel.js -// 顶部说明面板组件:产品功能介绍 + 沪深指数折线图 + 热门概念词云图 +// 顶部说明面板组件 - 驹形克己风格设计 +// 特点:极简留白、柔和几何、淡雅配色、层叠透明、诗意简洁 import React, { useEffect, useState, useMemo, useCallback } from 'react'; - -// 定义 pulse 动画 -const pulseAnimation = ` - @keyframes pulse { - 0%, 100% { - opacity: 1; - transform: scale(1); - } - 50% { - opacity: 0.6; - transform: scale(1.1); - } - } -`; - -// 注入样式到页面 -if (typeof document !== 'undefined') { - const styleSheet = document.createElement('style'); - styleSheet.type = 'text/css'; - styleSheet.innerText = pulseAnimation; - document.head.appendChild(styleSheet); -} import { Box, - Card, - CardBody, Flex, VStack, HStack, Text, - Heading, - useColorModeValue, - SimpleGrid, - Icon, Spinner, Center, + Tooltip, + Collapse, + useDisclosure, } from '@chakra-ui/react'; -import { TrendingUp, Activity, Globe, Zap } from 'lucide-react'; +import { Info, ChevronDown, ChevronUp } from 'lucide-react'; import ReactECharts from 'echarts-for-react'; import { logger } from '../../../utils/logger'; -import { PROFESSIONAL_COLORS } from '../../../constants/professionalTheme'; /** * 获取指数行情数据(日线数据) */ const fetchIndexKline = async (indexCode) => { try { - // 使用日线数据,获取最近60个交易日 const response = await fetch(`/api/index/${indexCode}/kline?type=daily`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); @@ -64,33 +38,19 @@ const fetchIndexKline = async (indexCode) => { }; /** - * 获取热门概念数据(用于流动动画) + * 获取热门概念数据 */ const fetchPopularConcepts = async () => { try { const response = await fetch('/concept-api/search', { method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: '', - size: 60, // 获取前60个概念 - page: 1, - sort_by: 'change_pct' - }) + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ query: '', size: 30, page: 1, sort_by: 'change_pct' }) }); - const data = await response.json(); - logger.debug('HeroPanel', 'fetchPopularConcepts response', { - total: data.total, - resultsCount: data.results?.length - }); - if (data.results && data.results.length > 0) { return data.results.map(item => ({ name: item.concept, - value: Math.abs(item.price_info?.avg_change_pct || 1) + 5, // 使用涨跌幅绝对值 + 基础权重 change_pct: item.price_info?.avg_change_pct || 0, })); } @@ -109,1069 +69,490 @@ const isInTradingTime = () => { const hours = now.getHours(); const minutes = now.getMinutes(); const timeInMinutes = hours * 60 + minutes; - - // 9:30 - 15:00 (570分钟 - 900分钟) return timeInMinutes >= 570 && timeInMinutes <= 900; }; /** - * 迷你K线图组件(支持实时更新) + * 极简指数卡片 - 驹形克己风格 */ -const MiniIndexChart = ({ indexCode, indexName }) => { +const MinimalIndexCard = ({ indexCode, indexName, accentColor }) => { const [chartData, setChartData] = useState(null); const [loading, setLoading] = useState(true); const [latestData, setLatestData] = useState(null); - const [currentDate, setCurrentDate] = useState(''); - const chartBg = useColorModeValue('transparent', 'transparent'); - // 中国市场惯例:涨红跌绿 - const upColor = '#ec0000'; // 上涨:红色 - const downColor = '#00da3c'; // 下跌:绿色 - - // 加载日线数据 - const loadDailyData = useCallback(async () => { + const loadData = useCallback(async () => { const data = await fetchIndexKline(indexCode); - - if (data && data.data && data.data.length > 0) { - // 取最近一个交易日的数据 + if (data?.data?.length > 0) { const latest = data.data[data.data.length - 1]; const prevClose = latest.prev_close || latest.close; - setLatestData({ close: latest.close, change: prevClose ? (((latest.close - prevClose) / prevClose) * 100).toFixed(2) : '0.00', isPositive: latest.close >= prevClose }); - - setCurrentDate(latest.time); - - // 准备K线图数据(最近60个交易日) - const recentData = data.data.slice(-60); + const recentData = data.data.slice(-30); setChartData({ dates: recentData.map(item => item.time), - klineData: recentData.map(item => [ - item.open, - item.close, - item.low, - item.high - ]), - rawData: recentData // 保存原始数据用于 tooltip + values: recentData.map(item => item.close), }); } - setLoading(false); }, [indexCode]); - // 加载分钟线数据(仅在交易时间) - const loadMinuteData = useCallback(async () => { - try { - const response = await fetch(`/api/index/${indexCode}/kline?type=minute`); - if (!response.ok) return; - - const data = await response.json(); - - if (data && data.data && data.data.length > 0) { - // 取最新分钟数据 - const latest = data.data[data.data.length - 1]; - // 分钟线没有 prev_close,使用第一条数据的 open 作为开盘价 - const dayOpen = data.data[0].open; - - setLatestData({ - close: latest.close, - change: dayOpen ? (((latest.close - dayOpen) / dayOpen) * 100).toFixed(2) : '0.00', - isPositive: latest.close >= dayOpen - }); - - logger.debug('HeroPanel', 'Minute data updated', { - indexCode, - close: latest.close, - time: latest.time, - change: (((latest.close - dayOpen) / dayOpen) * 100).toFixed(2) - }); - } - } catch (error) { - logger.error('HeroPanel', 'loadMinuteData error', error); - } - }, [indexCode]); - - // 初始加载和定时更新 useEffect(() => { - let isMounted = true; - let intervalId = null; - - const init = async () => { - setLoading(true); - await loadDailyData(); - - if (isMounted) { - // 如果在交易时间,立即加载一次分钟数据 - if (isInTradingTime()) { - await loadMinuteData(); - } - setLoading(false); - } - }; - - init(); - - // 设置定时器:交易时间内每分钟更新 - if (isInTradingTime()) { - intervalId = setInterval(() => { - if (isInTradingTime()) { - loadMinuteData(); - } else { - // 如果超出交易时间,清除定时器 - if (intervalId) { - clearInterval(intervalId); - } - } - }, 60000); // 每60秒更新一次 - } - - return () => { - isMounted = false; - if (intervalId) { - clearInterval(intervalId); - } - }; - }, [indexCode, loadDailyData, loadMinuteData]); + loadData(); + }, [loadData]); const chartOption = useMemo(() => { if (!chartData) return {}; - return { - backgroundColor: chartBg, - grid: { - left: 10, - right: 10, - top: 5, - bottom: 20, - containLabel: false - }, - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'cross', - lineStyle: { - color: 'rgba(255, 215, 0, 0.5)', - width: 1, - type: 'dashed' - } - }, - backgroundColor: 'rgba(20, 20, 20, 0.95)', - borderColor: '#FFD700', - borderWidth: 1, - textStyle: { - color: '#fff', - fontSize: 11, - fontFamily: 'monospace' - }, - padding: [8, 12], - formatter: function (params) { - const dataIndex = params[0].dataIndex; - const rawDataItem = chartData.rawData[dataIndex]; - - if (!rawDataItem) return ''; - - const open = rawDataItem.open; - const high = rawDataItem.high; - const low = rawDataItem.low; - const close = rawDataItem.close; - const prevClose = rawDataItem.prev_close || open; - const change = close - prevClose; - const changePct = prevClose ? ((change / prevClose) * 100).toFixed(2) : '0.00'; - const isUp = close >= prevClose; - - // Bloomberg 风格格式化(涨红跌绿) - const changeColor = isUp ? '#ec0000' : '#00da3c'; - const changeSign = isUp ? '+' : ''; - - return ` -