// src/views/TradingSimulation/components/AccountOverview.js - 账户概览组件(现代化版本) import React from 'react'; import { Grid, GridItem, Stat, StatLabel, StatNumber, StatHelpText, StatArrow, Box, Text, Badge, VStack, HStack, Progress, useColorModeValue, Icon, Flex, SimpleGrid, Card, CardBody, CardHeader } from '@chakra-ui/react'; import { FiTrendingUp, FiTrendingDown, FiDollarSign, FiPieChart, FiTarget, FiActivity } from 'react-icons/fi'; // 导入图表组件 import { AssetAllocationChart } from './AssetAllocationChart'; import IconBox from '../../../components/Icons/IconBox'; export default function AccountOverview({ account, tradingEvents }) { // tradingEvents 已传递,可用于将来添加的账户重置等功能 // 例如: tradingEvents.trackAccountReset(beforeResetData) const textColor = useColorModeValue('gray.700', 'white'); const secondaryColor = useColorModeValue('gray.500', 'gray.400'); const profitColor = account?.totalProfit >= 0 ? 'green.500' : 'red.500'; const profitBg = useColorModeValue( account?.totalProfit >= 0 ? 'green.50' : 'red.50', account?.totalProfit >= 0 ? 'green.900' : 'red.900' ); if (!account) { return ( 暂无账户数据 ); } // 安全地计算资产配置比例 const cashRatio = account?.totalAssets > 0 ? (account.availableCash / account.totalAssets) * 100 : 0; const stockRatio = account?.totalAssets > 0 ? (account.marketValue / account.totalAssets) * 100 : 0; // 格式化数字 const formatCurrency = (amount) => { return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(amount || 0); }; const formatPercent = (percent) => { return `${(percent || 0) >= 0 ? '+' : ''}${(percent || 0).toFixed(2)}%`; }; return ( {/* 左侧:主要资产数据 */} {/* 核心资产指标 */} {/* 总资产卡片 */} 总资产 {formatCurrency(account?.totalAssets)} } /> {/* 总收益卡片 */} 总收益 {formatCurrency(account?.totalProfit)} = 0 ? 'increase' : 'decrease'} color={profitColor} ml={2} /> {formatPercent(account?.totalProfitPercent)} = 0 ? "linear-gradient(90deg, #4FD1C7 0%, #81E6D9 100%)" : "linear-gradient(90deg, #FEB2B2 0%, #F56565 100%)" } icon={ = 0 ? FiTrendingUp : FiTrendingDown} color="white" w="24px" h="24px" /> } /> {/* 可用资金卡片 */} 可用资金 {formatCurrency(account?.availableCash)} 现金占比: {(cashRatio || 0).toFixed(1)}% } /> {/* 持仓市值卡片 */} 持仓市值 {formatCurrency(account?.marketValue)} 持仓占比: {(stockRatio || 0).toFixed(1)}% } /> {/* 风险等级和账户状态 */} } /> 账户状态 风险等级: 中等 = 0 ? 'green' : 'red'} variant="solid" borderRadius="full" px={3} py={1} > {(account?.totalProfit || 0) >= 0 ? '盈利中' : '亏损中'} 创建时间: {account?.createdAt ? new Date(account.createdAt).toLocaleDateString('zh-CN') : '-'} 最后更新: {account?.lastUpdated ? new Date(account.lastUpdated).toLocaleString('zh-CN') : '-'} {/* 右侧:资产配置图表 */} 资产配置 实时更新 {/* 详细配置信息 */} 现金资产 {formatCurrency(account?.availableCash)} 股票资产 {formatCurrency(account?.marketValue)} ); }