"use client" import {Activity, Cpu, Droplets, Flame, Waves} from 'lucide-react' import MetricCard from "@/components/shared/metric-card" import Section from "@/components/shared/section" import {Button} from "@/components/ui/button" import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card" import { type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, } from "@/components/ui/chart" import { Area, Bar, BarChart, CartesianGrid, Legend, Line, LineChart, Pie, PieChart, RadialBar, RadialBarChart, ResponsiveContainer, XAxis, YAxis, } from "recharts" import {useMemo, useState} from "react" const industries = [ { key: "gas", label: "燃气", icon: }, { key: "water", label: "供水", icon: }, { key: "drain", label: "排水", icon: }, ] as const function useMockOverviewData() { // Deterministic mock numbers const base = { gas: { facilities: 1240, devices: 8420, onlineRate: 96.2, supply: 52.4 }, water: { facilities: 980, devices: 6230, onlineRate: 97.8, supply: 315.6 }, drain: { facilities: 760, devices: 4210, onlineRate: 94.1, supply: 288.3 }, } const totalFacilities = base.gas.facilities + base.water.facilities + base.drain.facilities const totalDevices = base.gas.devices + base.water.devices + base.drain.devices const avgOnline = Math.round(((base.gas.onlineRate + base.water.onlineRate + base.drain.onlineRate) / 3) * 10) / 10 const typeShare = [ { name: "燃气", value: base.gas.facilities, key: "gas" }, { name: "供水", value: base.water.facilities, key: "water" }, { name: "排水", value: base.drain.facilities, key: "drain" }, ] const trend = Array.from({ length: 12 }).map((_, i) => ({ month: `${i + 1}月`, // mock报警/事件趋势 alarms: Math.round(140 + 30 * Math.sin((i / 12) * Math.PI * 2) + (i % 3) * 8), supply: base.water.supply * (0.9 + 0.02 * i), // example: 供水能力趋势 })) return { base, totalFacilities, totalDevices, avgOnline, typeShare, trend } } const shareConfig = { gas: { label: "燃气", color: "hsl(var(--chart-1))" }, water: { label: "供水", color: "hsl(var(--chart-2))" }, drain: { label: "排水", color: "hsl(var(--chart-3))" }, } satisfies ChartConfig const trendConfig = { alarms: { label: "报警数", color: "hsl(var(--chart-4))" }, supply: { label: "供水能力", color: "hsl(var(--chart-2))" }, } satisfies ChartConfig export default function OverviewDashboard() { const { base, totalFacilities, totalDevices, avgOnline, typeShare, trend } = useMockOverviewData() const [loading, setLoading] = useState(false) const onlineRadial = useMemo( () => [{ name: "在线率", online: avgOnline, fill: "hsl(var(--chart-1))" }], [avgOnline], ) return (
{ setLoading(true) setTimeout(() => setLoading(false), 800) }} > {loading ? "刷新中..." : "刷新数据"} } >
} trend={{ delta: 2.4, label: "同比" }} /> } trend={{ delta: 1.2, label: "环比" }} /> } trend={{ delta: 0.6, label: "近7天" }} /> } />
设施类型占比 } /> } /> {typeShare.map((entry) => ( ))}
{industries.map((it) => (
{it.icon} {it.label}
))}
报警趋势与供水能力
平均在线率 } />

目标 ≥ 95%

设施规模变化(样例) ({ name: `${i + 1}期`, facilities: 2200 + (i % 3) * 120 + Math.round(50 * Math.sin(i)), }))} > } />
) } function ComposedTrend({ data }: { data: Array<{ month: string; alarms: number; supply: number }> }) { return ( } /> ) }