"use client" import {useMemo, useState} from "react" import Section from "@/components/shared/section" import {Button} from "@/components/ui/button" import {Badge} from "@/components/ui/badge" import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card" import { type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, } from "@/components/ui/chart" import { Bar, BarChart, CartesianGrid, Cell, Line, LineChart, Pie, PieChart, ResponsiveContainer, XAxis, YAxis, } from "recharts" import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table" import {Dialog, DialogContent, DialogHeader, DialogTitle} from "@/components/ui/dialog" import {Separator} from "@/components/ui/separator" import {AlarmClock, ShieldCheck} from 'lucide-react' type Warning = { id: string type: "泄漏" | "水压异常" | "液位过高" | "阀门故障" industry: "燃气" | "供水" | "排水" severity: "高" | "中" | "低" district: string time: string status: "待处置" | "处置中" | "已完成" } function useWarnings() { const now = new Date() const items: Warning[] = Array.from({ length: 12 }).map((_, i) => { const types: Warning["type"][] = ["泄漏", "水压异常", "液位过高", "阀门故障"] const industries: Warning["industry"][] = ["燃气", "供水", "排水"] const severities: Warning["severity"][] = ["高", "中", "低"] const statuses: Warning["status"][] = ["待处置", "处置中", "已完成"] const t = new Date(now.getTime() - i * 36 * 60 * 1000) return { id: `ALM-${1000 + i}`, type: types[i % types.length]!, industry: industries[(i + 1) % industries.length]!, severity: severities[i % severities.length]!, district: ["天河区", "越秀区", "黄埔区", "海珠区"][i % 4]!, time: t.toLocaleString(), status: statuses[i % statuses.length]!, } }) return items } const trendConfig = { alarms: { label: "报警数", color: "hsl(var(--chart-5))" }, } satisfies ChartConfig export default function AlertsDashboard() { const warnings = useWarnings() const [selected, setSelected] = useState(null) const trend = useMemo( () => Array.from({ length: 10 }).map((_, i) => ({ name: `${i + 1}日`, alarms: Math.round(80 + 20 * Math.sin(i / 2) + (i % 3) * 6), })), [], ) const byIndustry = useMemo(() => { const data = [ { name: "燃气", value: 0 }, { name: "供水", value: 0 }, { name: "排水", value: 0 }, ] warnings.forEach((w) => { const idx = data.findIndex((d) => d.name === w.industry) data[idx]!.value++ }) return data }, [warnings]) const efficiency = { correct: 86, avgMinutes: 42 } return (
location.reload()}>模拟刷新} >
预警列表 编号 类型 行业 等级 区域 时间 状态 {warnings.map((w) => ( setSelected(w)}> {w.id} {w.type} {w.industry} {w.severity} {w.district} {w.time} {w.status} ))}
近10日报警趋势 } />
按行业分布 } /> } /> {byIndustry.map((d) => ( ))} 平均处置时效(分钟) ({ name: `${i + 1}周`, minutes: Math.round(50 - i * 2 + (i % 3) * 4), }))} > } />
正确预警比例
{efficiency.correct}%
正确预警

结合人工复核等处置数据,统计系统预警准确度。

平均处置用时
{efficiency.avgMinutes} 分钟

较上周提升 8%

按类型(样例) } /> 成因分布(样例) } /> } />
!open && setSelected(null)} />
) } function WarningDialog({ warning, onOpenChange, }: { warning: Warning | null onOpenChange: (open: boolean) => void }) { return ( 预警详情 {warning ? (
编号: {warning.id}
时间: {warning.time}
类型: {warning.type}
行业: {warning.industry}
等级: {warning.severity}
状态: {warning.status}
区域: {warning.district}
定位(示意)
) : null}
) }