import { useEffect, useRef } from 'react'; import { ClipboardList, Clock, CheckCircle, AlertTriangle, TrendingUp, TrendingDown, Database } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { dashboardStats, dbInstances, statusMap, statusColorMap, dbTypeColorMap, tickets } from '@/lib/mock'; import * as echarts from 'echarts'; const stats = [ { title: '今日工单', value: dashboardStats.todayTickets, trend: dashboardStats.todayTicketsTrend, icon: ClipboardList, color: 'text-blue-400', bg: 'bg-blue-400/10' }, { title: '待审批', value: dashboardStats.pendingApproval, trend: dashboardStats.pendingTrend, icon: Clock, color: 'text-orange-400', bg: 'bg-orange-400/10' }, { title: '查询审计', value: dashboardStats.queryAuditCount.toLocaleString(), trend: dashboardStats.queryTrend, icon: CheckCircle, color: 'text-purple-400', bg: 'bg-purple-400/10' }, { title: '慢查询', value: dashboardStats.slowQueries, trend: dashboardStats.slowQueryTrend, icon: AlertTriangle, color: 'text-red-400', bg: 'bg-red-400/10' }, ]; export default function Dashboard() { const chartRef = useRef(null); useEffect(() => { if (!chartRef.current) return; const chart = echarts.init(chartRef.current); const option: any = { backgroundColor: 'transparent', tooltip: { trigger: 'axis' as const, backgroundColor: 'rgba(22, 27, 34, 0.95)', borderColor: '#30363d', textStyle: { color: '#f0f6fc' }, }, legend: { data: ['提交工单', '执行成功', '执行失败'], textStyle: { color: '#8b949e' }, bottom: 0, itemWidth: 14, itemHeight: 8, }, grid: { left: '2%', right: '3%', bottom: '18%', top: '8%', containLabel: true }, xAxis: { type: 'category' as const, data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], axisLine: { lineStyle: { color: '#30363d' } }, axisLabel: { color: '#8b949e', fontSize: 11 }, }, yAxis: { type: 'value' as const, axisLine: { show: false }, splitLine: { lineStyle: { color: '#21262d' } }, axisLabel: { color: '#8b949e', fontSize: 11 }, }, series: [ { name: '提交工单', type: 'line', smooth: true, data: [120, 132, 101, 134, 90, 230, 210], itemStyle: { color: '#58a6ff' }, lineStyle: { width: 2 }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(88, 166, 255, 0.3)' }, { offset: 1, color: 'rgba(88, 166, 255, 0)' }, ]), }, symbol: 'none', }, { name: '执行成功', type: 'line', smooth: true, data: [110, 125, 95, 128, 85, 215, 200], itemStyle: { color: '#3fb950' }, lineStyle: { width: 2 }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(63, 185, 80, 0.3)' }, { offset: 1, color: 'rgba(63, 185, 80, 0)' }, ]), }, symbol: 'none', }, { name: '执行失败', type: 'line', smooth: true, data: [5, 3, 4, 2, 3, 8, 5], itemStyle: { color: '#f85149' }, lineStyle: { width: 2 }, symbol: 'none', }, ], }; chart.setOption(option); const handleResize = () => chart.resize(); window.addEventListener('resize', handleResize); return () => { window.removeEventListener('resize', handleResize); chart.dispose(); }; }, []); const onlineInstances = dbInstances.filter(i => i.status === 'online').length; const warningInstances = dbInstances.filter(i => i.status === 'warning').length; const offlineInstances = dbInstances.filter(i => i.status === 'offline').length; const pendingTickets = tickets.filter(t => t.status === 'pending' || t.status === 'reviewing').slice(0, 4); return (
{/* 统计卡片 */}
{stats.map((s, i) => (
{s.title}
{s.value}
= 0 ? 'text-green-400' : 'text-red-400'}`}> {s.trend >= 0 ? : } {Math.abs(s.trend)}% 较昨日
))}
{/* 图表 + 实例状态 */}
{/* 工单趋势图 */}
工单趋势
{['近7天', '近30天', '近90天'].map((p, i) => ( ))}
{/* 实例状态 */} 实例状态
{onlineInstances}
在线
{warningInstances}
告警
{offlineInstances}
离线
{dbInstances.slice(0, 4).map(inst => (
{inst.name}
{inst.host}:{inst.port}
{inst.status === 'online' ? '在线' : inst.status === 'warning' ? '告警' : '离线'}
))}
{/* 待处理工单 */} 待处理工单
{pendingTickets.map(ticket => ( ))}
工单号 标题 数据库 申请人 状态 创建时间 操作
{ticket.id} {ticket.title} {ticket.dbType.toUpperCase()} {ticket.applicant} {statusMap[ticket.status]} {ticket.createTime}
); }