import * as React from 'react'; import { Card, Statistic, Row, Col, Progress, Badge, Avatar, Tag, Button, Tooltip, Spin, } from 'antd'; import { UserOutlined, ShoppingCartOutlined, DollarOutlined, TrophyOutlined, FireOutlined, ThunderboltOutlined, StarOutlined, HeartOutlined, EyeOutlined, LikeOutlined, } from '@ant-design/icons'; import './style.scss'; interface DataDashboardProps { title: string; theme: 'dark' | 'light' | 'gradient'; showAnimations: boolean; data?: any; } interface MockData { totalUsers: number; totalOrders: number; totalRevenue: number; conversionRate: number; activeUsers: number; topProducts: Array<{ name: string; sales: number; growth: number; color: string; }>; recentActivities: Array<{ id: string; user: string; action: string; time: string; avatar: string; }>; performanceMetrics: Array<{ name: string; value: number; target: number; color: string; }>; } export default class DataDashboard extends React.PureComponent { private animationTimer: NodeJS.Timeout | null = null; private dataUpdateTimer: NodeJS.Timeout | null = null; constructor(props: DataDashboardProps) { super(props); this.state = { currentData: this.generateMockData(), isAnimating: false, loading: false, }; } componentDidMount() { if (this.props.showAnimations) { this.startDataAnimation(); } } componentWillUnmount() { if (this.animationTimer) { clearInterval(this.animationTimer); } if (this.dataUpdateTimer) { clearInterval(this.dataUpdateTimer); } } generateMockData = (): MockData => ({ totalUsers: Math.floor(Math.random() * 50000) + 10000, totalOrders: Math.floor(Math.random() * 10000) + 2000, totalRevenue: Math.floor(Math.random() * 1000000) + 500000, conversionRate: Math.floor(Math.random() * 30) + 5, activeUsers: Math.floor(Math.random() * 5000) + 1000, topProducts: [ { name: '智能手表', sales: 1250, growth: 15.6, color: '#1890ff' }, { name: '无线耳机', sales: 980, growth: 8.2, color: '#52c41a' }, { name: '智能音箱', sales: 756, growth: -2.1, color: '#faad14' }, { name: '平板电脑', sales: 634, growth: 12.8, color: '#f5222d' }, { name: '智能手环', sales: 520, growth: 25.3, color: '#722ed1' }, ], recentActivities: [ { id: '1', user: '张三', action: '购买了智能手表', time: '2分钟前', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=1', }, { id: '2', user: '李四', action: '完成了订单支付', time: '5分钟前', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=2', }, { id: '3', user: '王五', action: '添加了商品到购物车', time: '8分钟前', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=3', }, { id: '4', user: '赵六', action: '发表了产品评价', time: '12分钟前', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=4', }, { id: '5', user: '钱七', action: '分享了产品链接', time: '15分钟前', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=5', }, ], performanceMetrics: [ { name: '页面加载速度', value: 85, target: 90, color: '#1890ff' }, { name: '用户满意度', value: 92, target: 95, color: '#52c41a' }, { name: '系统稳定性', value: 98, target: 99, color: '#faad14' }, { name: '数据准确性', value: 96, target: 98, color: '#f5222d' }, ], }); startDataAnimation = () => { this.dataUpdateTimer = setInterval(() => { this.setState({ loading: true }); setTimeout(() => { this.setState({ currentData: this.generateMockData(), loading: false, isAnimating: true, }); setTimeout(() => { this.setState({ isAnimating: false }); }, 1000); }, 500); }, 10000); }; formatNumber = (num: number): string => { if (num >= 1000000) { return `${(num / 1000000).toFixed(1)}M`; } if (num >= 1000) { return `${(num / 1000).toFixed(1)}K`; } return num.toString(); }; render() { const { title, theme, showAnimations } = this.props; const { currentData, isAnimating, loading } = this.state as any; const curAmisData = this.props.data || {}; const userInfo = curAmisData.__AmisCurrentUser; const systemInfo = curAmisData.__AmisSystemInfo || {}; return (

{title || '数据仪表板'} {systemInfo.tenantName && ( 【{systemInfo.tenantName}】 )}

{userInfo && (
} /> {userInfo.name}
)}
{/* 核心指标卡片 */} this.formatNumber(value as number)} prefix={} valueStyle={{ color: '#1890ff' }} />
较上月
this.formatNumber(value as number)} prefix={} valueStyle={{ color: '#52c41a' }} />
较上月
`¥${this.formatNumber(value as number)}` } prefix={} valueStyle={{ color: '#faad14' }} />
较上月
} valueStyle={{ color: '#f5222d' }} />
较上月
{/* 热门产品和活动动态 */} 热门产品 } className="products-card" extra={} >
{currentData.topProducts.map( (product: any, index: number) => (
{product.name}
{product.sales} 销量
0 ? 'green' : 'red'}> {product.growth > 0 ? '+' : ''} {product.growth}%
), )}
实时动态 } className="activities-card" extra={} >
{currentData.recentActivities.map((activity: any) => (
} />
{activity.user} {activity.action}
{activity.time}
))}
{/* 性能指标 */} 性能指标 } className="performance-card" > {currentData.performanceMetrics.map( (metric: any, index: number) => (
{metric.name} {metric.value}%
目标: {metric.target}%
), )}
{/* 活跃用户统计 */} 活跃用户统计 } className="active-users-card" >
{this.formatNumber(currentData.activeUsers)} 活跃用户
当前在线用户数量,实时更新
{Array.from({ length: 8 }, (_, i) => ( ))}
); } }