diff --git a/src/pages/HomePage/index.tsx b/src/pages/HomePage/index.tsx index f58a5d2..da99b7a 100644 --- a/src/pages/HomePage/index.tsx +++ b/src/pages/HomePage/index.tsx @@ -1,22 +1,42 @@ import { PageContainer, ProCard } from '@ant-design/pro-components'; -import { Card, Col, Row, Statistic } from 'antd'; +import { Card, Col, Row, Statistic, Space, Tag, Progress } from 'antd'; import React, { useEffect, useState } from 'react'; import ReactECharts from 'echarts-for-react'; -import { useModel } from '@@/exports'; +import { + LineChartOutlined, + BarChartOutlined, + PieChartOutlined, + DotChartOutlined, + UserOutlined, + CheckCircleOutlined, + ClockCircleOutlined, + TeamOutlined, +} from '@ant-design/icons'; const HomePage: React.FC = () => { - const { initialState } = useModel('@@initialState'); - const { currentUser } = initialState ?? {}; const [loading, setLoading] = useState(true); - // TODO : 获取统计数据 + // 统计数据 const [statisticsData] = useState({ totalCharts: 126, successRate: 95, todayGenerated: 28, totalUsers: 1580, + activeUsers: 320, + avgGenerationTime: 2.5, }); + // 图表类型分布 - 用于显示图标的数据 + const chartTypes = [ + { value: 35, name: '折线图', icon: }, + { value: 30, name: '柱状图', icon: }, + { value: 20, name: '饼图', icon: }, + { value: 15, name: '散点图', icon: }, + ]; + + // 为ECharts准备的数据,不包含React组件 + const chartTypesForEcharts = chartTypes.map(({ value, name }) => ({ value, name })); + const chartOptions = { title: { text: '近期图表生成趋势', @@ -24,13 +44,35 @@ const HomePage: React.FC = () => { }, tooltip: { trigger: 'axis', + formatter: '{b}: {c} 个图表', + }, + grid: { + left: '3%', + right: '4%', + bottom: '3%', + containLabel: true, }, xAxis: { type: 'category', data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], + axisLine: { + lineStyle: { + color: '#d9d9d9', + }, + }, }, yAxis: { type: 'value', + axisLine: { + lineStyle: { + color: '#d9d9d9', + }, + }, + splitLine: { + lineStyle: { + color: '#f0f0f0', + }, + }, }, series: [ { @@ -41,6 +83,12 @@ const HomePage: React.FC = () => { areaStyle: { opacity: 0.1, }, + itemStyle: { + color: '#1890ff', + }, + lineStyle: { + width: 3, + }, }, ], }; @@ -48,29 +96,42 @@ const HomePage: React.FC = () => { const pieOptions = { tooltip: { trigger: 'item', + formatter: '{b}: {c} ({d}%)', }, legend: { orient: 'vertical', left: 'left', + textStyle: { + color: '#666', + }, }, series: [ { name: '图表类型分布', type: 'pie', - radius: '50%', - data: [ - { value: 35, name: '折线图' }, - { value: 30, name: '柱状图' }, - { value: 20, name: '饼图' }, - { value: 15, name: '散点图' }, - ], + radius: ['40%', '70%'], + avoidLabelOverlap: false, + itemStyle: { + borderRadius: 10, + borderColor: '#fff', + borderWidth: 2, + }, + label: { + show: false, + position: 'center', + }, emphasis: { - itemStyle: { - shadowBlur: 10, - shadowOffsetX: 0, - shadowColor: 'rgba(0, 0, 0, 0.5)', + label: { + show: true, + fontSize: '18', + fontWeight: 'bold', }, }, + labelLine: { + show: false, + }, + // 这里使用过滤后的数据,不包含React组件 + data: chartTypesForEcharts, }, ], }; @@ -84,46 +145,162 @@ const HomePage: React.FC = () => { return ( - + - - - - - - + + + 总图表数 + + } + value={statisticsData.totalCharts} + valueStyle={{ color: '#1890ff' }} + /> + - - + + + + 生成成功率 + + } + value={statisticsData.successRate} + suffix="%" + precision={2} + valueStyle={{ color: '#52c41a' }} + /> + - - + + + + 今日生成 + + } + value={statisticsData.todayGenerated} + valueStyle={{ color: '#faad14' }} + /> + + + + + + + + 总用户数 + + } + value={statisticsData.totalUsers} + valueStyle={{ color: '#722ed1' }} + /> + - + - + + 周环比 +12% + 日环比 +5% + + } + > - + + 折线图 + 柱状图 + 饼图 + 散点图 + + } + > + + + + + + } + /> + + + + + + + + + `${percent}% 优化空间`} + /> + + + + ); };