feat: 新增实时要闻·动态追踪与市场复盘功能,优化导航体验
新增功能: - 实时要闻·动态追踪横向滚动卡片(DynamicNewsCard) - 动态新闻事件卡片组件(DynamicNewsEventCard) - 市场复盘卡片组件(MarketReviewCard) - 股票涨跌幅指标组件(StockChangeIndicators) - 交易时间工具函数(tradingTimeUtils) - Mock API 支持动态新闻数据生成 UI 优化: - EventFollowButton 改用 react-icons 星星图标,实现真正的空心/实心效果 - 关注按钮添加半透明白色背景(whiteAlpha.500),悬停效果更明显 - 事件卡片标题添加右侧留白,防止关注按钮遮挡文字 性能优化: - 禁用 Router v7_startTransition 特性,解决路由切换延迟 2 秒问题 - 调整导航菜单点击顺序(先跳转后关闭),提升响应速度 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
92
src/components/StockChangeIndicators.js
Normal file
92
src/components/StockChangeIndicators.js
Normal file
@@ -0,0 +1,92 @@
|
||||
// src/components/StockChangeIndicators.js
|
||||
// 股票涨跌幅指标组件(通用)
|
||||
|
||||
import React from 'react';
|
||||
import { Flex, Box, Text, useColorModeValue } from '@chakra-ui/react';
|
||||
|
||||
/**
|
||||
* 股票涨跌幅指标组件(3分天下布局)
|
||||
* @param {Object} props
|
||||
* @param {number} props.avgChange - 平均涨跌幅
|
||||
* @param {number} props.maxChange - 最大涨跌幅
|
||||
* @param {number} props.weekChange - 周涨跌幅
|
||||
*/
|
||||
const StockChangeIndicators = ({
|
||||
avgChange,
|
||||
maxChange,
|
||||
weekChange,
|
||||
}) => {
|
||||
// 根据涨跌幅获取数字颜色
|
||||
const getNumberColor = (value) => {
|
||||
if (value == null) {
|
||||
return useColorModeValue('gray.600', 'gray.400');
|
||||
}
|
||||
|
||||
const absValue = Math.abs(value);
|
||||
const isPositive = value > 0;
|
||||
|
||||
// 5%以上:深色
|
||||
if (absValue >= 5) {
|
||||
return isPositive ? 'red.600' : 'green.600';
|
||||
}
|
||||
// 1-5%:正常色
|
||||
if (absValue >= 1) {
|
||||
return isPositive ? 'red.500' : 'green.500';
|
||||
}
|
||||
// 0-1%:淡色
|
||||
return isPositive ? 'red.400' : 'green.400';
|
||||
};
|
||||
|
||||
// 渲染单个指标
|
||||
const renderIndicator = (label, value) => {
|
||||
if (value == null) return null;
|
||||
|
||||
const sign = value > 0 ? '+' : '';
|
||||
const numStr = Math.abs(value).toFixed(1);
|
||||
const numberColor = getNumberColor(value);
|
||||
const labelColor = useColorModeValue('gray.600', 'gray.400');
|
||||
|
||||
return (
|
||||
<Box
|
||||
borderWidth="2px"
|
||||
borderColor={numberColor}
|
||||
borderRadius="md"
|
||||
px={2}
|
||||
py={1}
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
>
|
||||
<Text fontSize="xs" lineHeight="1.2">
|
||||
<Text as="span" color={labelColor}>
|
||||
{label}
|
||||
</Text>
|
||||
<Text as="span" color={labelColor}>
|
||||
{sign}
|
||||
</Text>
|
||||
<Text as="span" fontWeight="bold" color={numberColor} fontSize="sm">
|
||||
{value < 0 ? '-' : ''}{numStr}
|
||||
</Text>
|
||||
<Text as="span" color={labelColor}>
|
||||
%
|
||||
</Text>
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
// 如果没有任何数据,不渲染
|
||||
if (avgChange == null && maxChange == null && weekChange == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Flex width="100%" justify="space-between" align="center" gap={1}>
|
||||
{renderIndicator('均 ', avgChange)}
|
||||
{renderIndicator('最 ', maxChange)}
|
||||
{renderIndicator('周 ', weekChange)}
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
||||
export default StockChangeIndicators;
|
||||
Reference in New Issue
Block a user