page.tsx 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. "use client"
  2. import React, {useEffect, useMemo, useState} from "react"
  3. import type {MenuProps, TableColumnsType} from "antd"
  4. import {
  5. Badge,
  6. Button,
  7. Card,
  8. Col,
  9. ConfigProvider,
  10. DatePicker,
  11. Descriptions,
  12. Divider,
  13. Drawer,
  14. Layout,
  15. Menu,
  16. Progress,
  17. Row,
  18. Select,
  19. Space,
  20. Statistic,
  21. Switch,
  22. Table,
  23. Tabs,
  24. Tag,
  25. Timeline,
  26. Tooltip as AntdTooltip
  27. } from "antd"
  28. import {
  29. Activity,
  30. AlertTriangle,
  31. BellRing,
  32. Database,
  33. Droplets,
  34. Factory,
  35. Flame,
  36. Gauge,
  37. Layers3,
  38. Map,
  39. Moon,
  40. Settings2,
  41. ShieldCheck,
  42. Sun,
  43. TrendingUp,
  44. Waves
  45. } from 'lucide-react'
  46. import EChart from "@/components/echarts"
  47. import dayjs from "dayjs"
  48. import {EChartsOption} from "echarts";
  49. const { Header, Sider, Content } = Layout
  50. const { RangePicker } = DatePicker
  51. // Helpers
  52. const primary = "#10b981" // teal, avoid blue
  53. const danger = "#ef4444"
  54. const warn = "#f59e0b"
  55. const ok = "#22c55e"
  56. const muted = "#6b7280"
  57. type Facility = {
  58. id: string
  59. industry: "燃气" | "供水" | "排水"
  60. type: string
  61. count: number
  62. age: number
  63. region: string
  64. }
  65. type Device = {
  66. id: string
  67. type: string
  68. status: "在线" | "离线"
  69. industry: Facility["industry"]
  70. risk: "高" | "中" | "低"
  71. lat: number
  72. lng: number
  73. }
  74. type Alert = {
  75. id: string
  76. level: "I级" | "II级" | "III级" | "IV级"
  77. industry: Facility["industry"]
  78. type: string
  79. time: string
  80. status: "待处置" | "处置中" | "已闭环"
  81. location: string
  82. desc: string
  83. }
  84. function useMockData() {
  85. const [facilities] = useState<Facility[]>(() => {
  86. const regions = ["中心城区", "东区", "西区", "南区", "北区"]
  87. const types = {
  88. 燃气: ["高压管道", "调压站", "门站", "阀门井"],
  89. 供水: ["原水管", "净水厂", "二次供水", "监测点"],
  90. 排水: ["主干管", "泵站", "检查井", "溢流口"],
  91. } as const
  92. let i = 0
  93. return (["燃气", "供水", "排水"] as Facility["industry"][]).flatMap((ind) =>
  94. types[ind].map((t) => ({
  95. id: `f-${i++}`,
  96. industry: ind,
  97. type: t,
  98. count: Math.floor(Math.random() * 900 + 100),
  99. age: Math.floor(Math.random() * 30 + 1),
  100. region: regions[Math.floor(Math.random() * regions.length)],
  101. }))
  102. )
  103. })
  104. const [devices, setDevices] = useState<Device[]>(() => {
  105. const types = ["压力", "流量", "液位", "阀位", "水质", "气体浓度"]
  106. let i = 0
  107. return Array.from({ length: 250 }).map(() => ({
  108. id: `d-${i++}`,
  109. type: types[Math.floor(Math.random() * types.length)],
  110. status: Math.random() > 0.12 ? "在线" : "离线",
  111. industry: (["燃气", "供水", "排水"] as const)[Math.floor(Math.random() * 3)],
  112. risk: Math.random() > 0.8 ? "高" : Math.random() > 0.5 ? "中" : "低",
  113. lat: Math.random(),
  114. lng: Math.random(),
  115. }))
  116. })
  117. // Simulate device status fluctuation
  118. useEffect(() => {
  119. const t = setInterval(() => {
  120. setDevices((prev) =>
  121. prev.map((d) =>
  122. Math.random() > 0.97 ? { ...d, status: d.status === "在线" ? "离线" : "在线" } : d
  123. )
  124. )
  125. }, 4000)
  126. return () => clearInterval(t)
  127. }, [])
  128. const [alerts, setAlerts] = useState<Alert[]>(() => {
  129. const levels: Alert["level"][] = ["I级", "II级", "III级", "IV级"]
  130. const types = ["泄漏", "压力异常", "流量突变", "停电", "液位过低", "浊度异常"]
  131. let i = 0
  132. return Array.from({ length: 30 }).map(() => ({
  133. id: `a-${i++}`,
  134. level: levels[Math.floor(Math.random() * levels.length)],
  135. industry: (["燃气", "供水", "排水"] as const)[Math.floor(Math.random() * 3)],
  136. type: types[Math.floor(Math.random() * types.length)],
  137. time: dayjs().subtract(Math.floor(Math.random() * 200), "minute").format("YYYY-MM-DD HH:mm"),
  138. status: Math.random() > 0.6 ? "已闭环" : Math.random() > 0.3 ? "处置中" : "待处置",
  139. location: ["中心城区", "东区", "西区", "南区", "北区"][Math.floor(Math.random() * 5)],
  140. desc: "自动监测发现异常,已推送至管理单位核实。",
  141. }))
  142. })
  143. // Simulate new alerts
  144. useEffect(() => {
  145. const t = setInterval(() => {
  146. setAlerts((prev) => {
  147. const n: Alert = {
  148. id: `a-${prev.length + 1}`,
  149. level: Math.random() > 0.85 ? "I级" : Math.random() > 0.6 ? "II级" : Math.random() > 0.3 ? "III级" : "IV级",
  150. industry: (["燃气", "供水", "排水"] as const)[Math.floor(Math.random() * 3)],
  151. type: ["泄漏", "压力异常", "流量突变", "停电", "液位过低", "浊度异常"][Math.floor(Math.random() * 6)],
  152. time: dayjs().format("YYYY-MM-DD HH:mm"),
  153. status: "待处置",
  154. location: ["中心城区", "东区", "西区", "南区", "北区"][Math.floor(Math.random() * 5)],
  155. desc: "前端设备上报新预警,请尽快核查。",
  156. }
  157. return [n, ...prev].slice(0, 60)
  158. })
  159. }, 20000)
  160. return () => clearInterval(t)
  161. }, [])
  162. return { facilities, devices, alerts }
  163. }
  164. function LevelTag({ level }: { level: Alert["level"] }) {
  165. const map = {
  166. "I级": { color: danger },
  167. "II级": { color: warn },
  168. "III级": { color: "#f97316" },
  169. "IV级": { color: ok },
  170. } as const
  171. return <Tag color={map[level].color}>{level}</Tag>
  172. }
  173. function StatusBadge({ s }: { s: Alert["status"] }) {
  174. const status = {
  175. 待处置: "error",
  176. 处置中: "processing",
  177. 已闭环: "success",
  178. } as const
  179. return <Badge status={status[s]} text={s} />
  180. }
  181. export default function Page() {
  182. const [collapsed, setCollapsed] = useState(false)
  183. const { facilities, devices, alerts } = useMockData()
  184. const [selectedMenu, setSelectedMenu] = useState("overview")
  185. const [drawerOpen, setDrawerOpen] = useState(false)
  186. const [selectedAlert, setSelectedAlert] = useState<Alert | null>(null)
  187. const [isDark, setIsDark] = useState(true)
  188. const totals = useMemo(() => {
  189. const sum = { 燃气: 0, 供水: 0, 排水: 0 } as Record<Facility["industry"], number>
  190. facilities.forEach((f) => (sum[f.industry] += f.count))
  191. return sum
  192. }, [facilities])
  193. const onlineRate = useMemo(() => {
  194. const total = devices.length
  195. const online = devices.filter((d) => d.status === "在线").length
  196. return Math.round((online / Math.max(total, 1)) * 100)
  197. }, [devices])
  198. const riskDist = useMemo(() => {
  199. const dist = { 高: 0, 中: 0, 低: 0 } as Record<Device["risk"], number>
  200. devices.forEach((d) => (dist[d.risk] += 1))
  201. return dist
  202. }, [devices])
  203. // Menu
  204. const menuItems: MenuProps["items"] = [
  205. { key: "overview", icon: <Layers3 size={18} />, label: "总体概览" },
  206. { key: "asset", icon: <Database size={18} />, label: "基础设施管理" },
  207. { key: "monitor", icon: <Activity size={18} />, label: "运行监测管理" },
  208. { key: "alert", icon: <BellRing size={18} />, label: "预警处置管理" },
  209. { type: "divider" as const },
  210. { key: "settings", icon: <Settings2 size={18} />, label: "设置" },
  211. ]
  212. // Charts Options
  213. const infraPieOption = useMemo(
  214. () => ({
  215. title: { text: "设施类型占比", left: "center", textStyle: { fontSize: 14 } },
  216. tooltip: { trigger: "item" },
  217. legend: { bottom: 0 },
  218. color: [primary, "#f59e0b", "#6366f1", "#ef4444", "#14b8a6", "#a855f7"],
  219. series: [
  220. {
  221. type: "pie",
  222. radius: ["35%", "60%"],
  223. avoidLabelOverlap: false,
  224. itemStyle: { borderRadius: 6, borderColor: "#fff", borderWidth: 2 },
  225. data: ["燃气", "供水", "排水"].map((ind) => ({
  226. name: ind,
  227. value: Object.values(facilities)
  228. .filter((f) => (f as Facility).industry === ind)
  229. .reduce((acc, f) => acc + (f as Facility).count, 0),
  230. })),
  231. },
  232. ],
  233. }),
  234. [facilities]
  235. )
  236. const deviceBarOption = useMemo(
  237. () => {
  238. const types = Array.from(new Set(devices.map((d) => d.type)))
  239. const byType = types.map((t) => devices.filter((d) => d.type === t).length)
  240. return {
  241. title: { text: "监测设备类型规模", left: "center", textStyle: { fontSize: 14 } },
  242. tooltip: { trigger: "axis" },
  243. xAxis: { type: "category", data: types, axisLabel: { rotate: 20 } },
  244. yAxis: { type: "value" },
  245. grid: { left: 40, right: 10, bottom: 50, top: 40 },
  246. color: [primary],
  247. series: [{ type: "bar", data: byType, barWidth: "50%", itemStyle: { borderRadius: [4, 4, 0, 0] } }],
  248. } as const
  249. },
  250. [devices]
  251. )
  252. const alertTrendOption = useMemo(() => {
  253. const days = 14
  254. const labels = Array.from({ length: days }).map((_, i) => dayjs().subtract(days - i - 1, "day").format("MM-DD"))
  255. const series = (["燃气", "供水", "排水"] as const).map((ind, idx) => ({
  256. name: ind,
  257. type: "line",
  258. smooth: true,
  259. data: labels.map(() => Math.floor(Math.random() * (idx === 0 ? 12 : idx === 1 ? 9 : 7)) + (idx === 0 ? 3 : 1)),
  260. }))
  261. return {
  262. title: { text: "预警趋势(近14天)", left: "center", textStyle: { fontSize: 14 } },
  263. tooltip: { trigger: "axis" },
  264. legend: { bottom: 0 },
  265. grid: { left: 40, right: 10, bottom: 40, top: 40 },
  266. xAxis: { type: "category", data: labels },
  267. yAxis: { type: "value" },
  268. color: [primary, "#f59e0b", "#a855f7"],
  269. series,
  270. } as const
  271. }, [])
  272. const onlineGaugeOption = useMemo(
  273. () => ({
  274. title: { text: "设备在线率", left: "center", top: 10, textStyle: { fontSize: 14 } },
  275. series: [
  276. {
  277. type: "gauge",
  278. startAngle: 200,
  279. endAngle: -20,
  280. radius: "90%",
  281. pointer: { show: false },
  282. progress: { show: true, width: 16, itemStyle: { color: onlineRate > 95 ? ok : onlineRate > 85 ? "#84cc16" : warn } },
  283. axisLine: { lineStyle: { width: 16 } },
  284. axisTick: { show: false },
  285. splitLine: { show: false },
  286. axisLabel: { show: false },
  287. detail: { valueAnimation: true, formatter: "{value}%", fontSize: 22, offsetCenter: [0, "10%"] },
  288. data: [{ value: onlineRate }],
  289. },
  290. ],
  291. }),
  292. [onlineRate]
  293. )
  294. const riskBarOption = useMemo(
  295. () => ({
  296. title: { text: "风险等级分布", left: "center", textStyle: { fontSize: 14 } },
  297. tooltip: { trigger: "axis" },
  298. grid: { left: 40, right: 10, top: 40, bottom: 20 },
  299. xAxis: { type: "category", data: ["高", "中", "低"] },
  300. yAxis: { type: "value" },
  301. color: [danger, warn, ok],
  302. series: [{ type: "bar", data: [riskDist["高"], riskDist["中"], riskDist["低"]], barWidth: "50%" }],
  303. }),
  304. [riskDist]
  305. )
  306. const efficiencyPieOption = useMemo(
  307. () => {
  308. const total = alerts.length
  309. const closed = alerts.filter((a) => a.status === "已闭环").length
  310. const correct = Math.floor(closed * (0.85 + Math.random() * 0.1)) // 假定人工复核正确率
  311. const wrong = Math.max(closed - correct, 0)
  312. return {
  313. title: { text: "预警正确性(闭环内)", left: "center", textStyle: { fontSize: 14 } },
  314. tooltip: { trigger: "item", formatter: "{b}: {c} ({d}%)" },
  315. legend: { bottom: 0 },
  316. color: [ok, danger],
  317. series: [
  318. {
  319. type: "pie",
  320. radius: ["35%", "60%"],
  321. data: [
  322. { name: "正确预警", value: correct },
  323. { name: "误报", value: wrong },
  324. ],
  325. },
  326. ],
  327. } as const
  328. },
  329. [alerts]
  330. )
  331. const radarCapacityOption = useMemo(
  332. () => ({
  333. title: { text: "应急保障能力雷达", left: "center", textStyle: { fontSize: 14 } },
  334. tooltip: {},
  335. radar: {
  336. indicator: [
  337. { name: "抢修速度", max: 100 },
  338. { name: "物资充足", max: 100 },
  339. { name: "跨部门联动", max: 100 },
  340. { name: "覆盖广度", max: 100 },
  341. { name: "应急演练", max: 100 },
  342. ],
  343. },
  344. color: [primary],
  345. series: [
  346. {
  347. type: "radar",
  348. data: [{ value: [78, 85, 72, 88, 76], name: "当前" }],
  349. areaStyle: { color: primary + "33" },
  350. },
  351. ],
  352. }),
  353. []
  354. )
  355. // Tables
  356. const facilityColumns: TableColumnsType<Facility> = [
  357. { title: "行业", dataIndex: "industry", key: "industry", width: 90 },
  358. { title: "类型", dataIndex: "type", key: "type" },
  359. { title: "数量", dataIndex: "count", key: "count", width: 100 },
  360. { title: "平均年限", dataIndex: "age", key: "age", width: 120, render: (v) => `${v} 年` },
  361. { title: "分布区域", dataIndex: "region", key: "region", width: 120 },
  362. ]
  363. const alertColumns: TableColumnsType<Alert> = [
  364. { title: "等级", dataIndex: "level", key: "level", width: 90, render: (v) => <LevelTag level={v} /> },
  365. { title: "行业", dataIndex: "industry", key: "industry", width: 90 },
  366. { title: "类型", dataIndex: "type", key: "type", width: 140 },
  367. { title: "时间", dataIndex: "time", key: "time", width: 160 },
  368. { title: "状态", dataIndex: "status", key: "status", width: 120, render: (s) => <StatusBadge s={s} /> },
  369. { title: "位置", dataIndex: "location", key: "location", width: 120 },
  370. {
  371. title: "操作",
  372. key: "action",
  373. render: (_, record) => (
  374. <Space size="small">
  375. <a
  376. onClick={() => {
  377. setSelectedAlert(record)
  378. setDrawerOpen(true)
  379. }}
  380. >
  381. 查看
  382. </a>
  383. <a>派单</a>
  384. <a>联动</a>
  385. </Space>
  386. ),
  387. width: 160,
  388. fixed: "right",
  389. },
  390. ]
  391. const alertLevelColor = (lvl: Alert["level"]) =>
  392. lvl === "I级" ? danger : lvl === "II级" ? warn : lvl === "III级" ? "#f97316" : ok
  393. // Derived numbers
  394. const stats = [
  395. {
  396. title: "燃气总规模",
  397. value: totals["燃气"],
  398. icon: <Flame className="text-white" size={18} />,
  399. bg: "bg-emerald-500",
  400. },
  401. {
  402. title: "供水总规模",
  403. value: totals["供水"],
  404. icon: <Droplets className="text-white" size={18} />,
  405. bg: "bg-teal-500",
  406. },
  407. {
  408. title: "排水总规模",
  409. value: totals["排水"],
  410. icon: <Waves className="text-white" size={18} />,
  411. bg: "bg-cyan-500",
  412. },
  413. {
  414. title: "在线设备",
  415. value: devices.filter((d) => d.status === "在线").length,
  416. icon: <Gauge className="text-white" size={18} />,
  417. bg: "bg-lime-500",
  418. },
  419. ]
  420. // Map markers for device distribution
  421. const markers = devices.slice(0, 120).map((d, i) => ({
  422. id: d.id,
  423. top: `${Math.floor(d.lat * 85) + 5}%`,
  424. left: `${Math.floor(d.lng * 90) + 5}%`,
  425. color: d.risk === "高" ? danger : d.risk === "中" ? warn : ok,
  426. title: `${d.industry}/${d.type}(${d.status})`,
  427. }))
  428. const themeTokens = useMemo(
  429. () => ({
  430. token: {
  431. colorPrimary: primary,
  432. colorInfo: primary,
  433. borderRadius: 8,
  434. fontSize: 13,
  435. },
  436. components: {
  437. Layout: {
  438. headerBg: isDark ? "#0f172a" : "#ffffff",
  439. siderBg: isDark ? "#0b1220" : "#ffffff",
  440. bodyBg: isDark ? "#0b1220" : "#f6f7f9",
  441. },
  442. Menu: {
  443. itemSelectedBg: isDark ? "#0ea5a8" : "#d1fae5",
  444. itemSelectedColor: isDark ? "#fff" : "#0f172a",
  445. itemActiveBg: "#0ea5a822",
  446. },
  447. },
  448. }),
  449. [isDark]
  450. )
  451. return (
  452. <ConfigProvider theme={themeTokens}>
  453. <Layout style={{ minHeight: "100vh" }}>
  454. <Sider collapsible collapsed={collapsed} onCollapse={setCollapsed} width={240} theme={isDark ? "dark" : "light"}>
  455. <div className="flex items-center gap-2 px-4 py-3">
  456. <ShieldCheck className="text-emerald-400" size={22} />
  457. {!collapsed && (
  458. <div className={isDark ? "text-emerald-100 font-medium" : "text-emerald-700 font-medium"}>
  459. 城市生命线驾驶舱
  460. </div>
  461. )}
  462. </div>
  463. <Menu
  464. theme={isDark ? "dark" : "light"}
  465. mode="inline"
  466. selectedKeys={[selectedMenu]}
  467. onClick={(e) => setSelectedMenu(e.key)}
  468. items={menuItems}
  469. />
  470. </Sider>
  471. <Layout>
  472. <Header className="flex items-center justify-between px-4">
  473. <div className={`flex items-center gap-3 ${isDark ? "text-white" : "text-slate-800"}`}>
  474. <Factory size={18} />
  475. <span className="font-medium">综合运行态势</span>
  476. <span className={`text-xs hidden md:inline ${isDark ? "text-slate-300" : "text-slate-500"}`}>
  477. 更新时间 {dayjs().format("YYYY-MM-DD HH:mm:ss")}
  478. </span>
  479. </div>
  480. <div className="flex items-center gap-3">
  481. <Select
  482. size="small"
  483. defaultValue="全市"
  484. options={[
  485. { value: "全市", label: "全市" },
  486. { value: "中心城区", label: "中心城区" },
  487. { value: "东区", label: "东区" },
  488. { value: "西区", label: "西区" },
  489. { value: "南区", label: "南区" },
  490. { value: "北区", label: "北区" },
  491. ]}
  492. style={{ width: 120 }}
  493. />
  494. <RangePicker size="small" />
  495. <Button
  496. size="small"
  497. onClick={() => setIsDark((v) => !v)}
  498. icon={isDark ? <Sun size={14} /> : <Moon size={14} />}
  499. >
  500. {isDark ? "暗色" : "白色"}
  501. </Button>
  502. </div>
  503. </Header>
  504. <Content className="p-4 md:p-6">
  505. {selectedMenu === "overview" && (
  506. <section className="space-y-4">
  507. <Row gutter={[16, 16]}>
  508. {stats.map((s) => (
  509. <Col xs={24} sm={12} md={12} lg={6} key={s.title}>
  510. <Card>
  511. <div className="flex items-center gap-3">
  512. <div className={`w-9 h-9 rounded-md flex items-center justify-center ${s.bg}`}>{s.icon}</div>
  513. <div className="flex-1">
  514. <div className="text-xs text-slate-500">{s.title}</div>
  515. <div className="text-xl font-semibold">{s.value.toLocaleString()}</div>
  516. </div>
  517. <AntdTooltip title="环比增长">
  518. <TrendingUp className="text-emerald-500" size={18} />
  519. </AntdTooltip>
  520. </div>
  521. </Card>
  522. </Col>
  523. ))}
  524. </Row>
  525. <Row gutter={[16, 16]}>
  526. <Col xs={24} md={12} lg={8}>
  527. <Card>
  528. <EChart option={infraPieOption} />
  529. </Card>
  530. </Col>
  531. <Col xs={24} md={12} lg={8}>
  532. <Card>
  533. <EChart option={deviceBarOption as EChartsOption} />
  534. </Card>
  535. </Col>
  536. <Col xs={24} md={24} lg={8}>
  537. <Card>
  538. <EChart option={onlineGaugeOption} />
  539. </Card>
  540. </Col>
  541. </Row>
  542. <Row gutter={[16, 16]}>
  543. <Col xs={24} md={12}>
  544. <Card>
  545. <EChart option={alertTrendOption as EChartsOption} />
  546. </Card>
  547. </Col>
  548. <Col xs={24} md={12}>
  549. <Card>
  550. <EChart option={riskBarOption} />
  551. </Card>
  552. </Col>
  553. </Row>
  554. <Card title="监测分布(示意)" extra={<span className="text-xs text-slate-500">标注颜色代表风险等级</span>}>
  555. <div className="relative w-full h-[380px] rounded-md overflow-hidden bg-slate-100">
  556. <img
  557. src="/images/city-map.png"
  558. alt="城市简化地图"
  559. className="absolute inset-0 w-full h-full object-cover opacity-90"
  560. />
  561. {/* Markers */}
  562. {markers.map((m) => (
  563. <AntdTooltip key={m.id} title={m.title}>
  564. <div
  565. className="absolute w-2.5 h-2.5 rounded-full ring-2 ring-white/70"
  566. style={{ top: m.top, left: m.left, backgroundColor: m.color }}
  567. />
  568. </AntdTooltip>
  569. ))}
  570. {/* Legend */}
  571. <div className="absolute right-3 top-3 bg-white/90 backdrop-blur rounded-md p-2 text-xs shadow">
  572. <div className="font-medium mb-1 flex items-center gap-1">
  573. <Map size={14} /> 覆盖与风险
  574. </div>
  575. <div className="flex items-center gap-3">
  576. <div className="flex items-center gap-1">
  577. <span className="inline-block w-2.5 h-2.5 rounded-full" style={{ background: danger }} /> 高
  578. </div>
  579. <div className="flex items-center gap-1">
  580. <span className="inline-block w-2.5 h-2.5 rounded-full" style={{ background: warn }} /> 中
  581. </div>
  582. <div className="flex items-center gap-1">
  583. <span className="inline-block w-2.5 h-2.5 rounded-full" style={{ background: ok }} /> 低
  584. </div>
  585. </div>
  586. </div>
  587. </div>
  588. </Card>
  589. </section>
  590. )}
  591. {selectedMenu === "asset" && (
  592. <section className="space-y-4">
  593. <Tabs
  594. defaultActiveKey="archive"
  595. items={[
  596. { key: "archive", label: "基础档案" },
  597. { key: "run", label: "运行信息" },
  598. { key: "mgmt", label: "管理信息" },
  599. { key: "emergency", label: "应急保障" },
  600. ]}
  601. />
  602. <Row gutter={[16, 16]}>
  603. <Col xs={24} lg={14}>
  604. <Card title="设施基础档案">
  605. <Table
  606. size="small"
  607. rowKey="id"
  608. columns={facilityColumns}
  609. dataSource={facilities}
  610. pagination={{ pageSize: 8 }}
  611. scroll={{ x: 700 }}
  612. />
  613. </Card>
  614. </Col>
  615. <Col xs={24} lg={10}>
  616. <Card title="行业重点指标">
  617. <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
  618. <div>
  619. <div className="text-xs text-slate-500 mb-1">平均设施年限</div>
  620. <Statistic value={Math.round(facilities.reduce((a, b) => a + b.age, 0) / facilities.length)} suffix="年" />
  621. <Progress percent={Math.min(100, Math.round((facilities.filter((f) => f.age >= 20).length / facilities.length) * 100))} size="small" />
  622. <div className="text-xs text-slate-500 mt-1">20年以上占比</div>
  623. </div>
  624. <div>
  625. <div className="text-xs text-slate-500 mb-1">重点设施数量</div>
  626. <Statistic value={facilities.filter((f) => f.type.includes("主") || f.type.includes("厂")).reduce((a, b) => a + b.count, 0)} />
  627. <div className="text-xs text-slate-500 mt-1">主干/厂站等关键设施总量</div>
  628. </div>
  629. </div>
  630. </Card>
  631. <Card className="mt-4" title="分布热点(示意)">
  632. <EChart
  633. option={{
  634. title: { text: "区域设施数量", left: "center", textStyle: { fontSize: 14 } },
  635. xAxis: { type: "category", data: ["中心城区", "东区", "西区", "南区", "北区"] },
  636. yAxis: { type: "value" },
  637. grid: { left: 40, right: 10, bottom: 20, top: 40 },
  638. color: [primary],
  639. series: [
  640. {
  641. type: "bar",
  642. data: ["中心城区", "东区", "西区", "南区", "北区"].map(
  643. (r) => facilities.filter((f) => f.region === r).reduce((a, b) => a + b.count, 0)
  644. ),
  645. barWidth: "50%",
  646. },
  647. ],
  648. }}
  649. />
  650. </Card>
  651. </Col>
  652. </Row>
  653. <Row gutter={[16, 16]}>
  654. <Col xs={24} md={12}>
  655. <Card title="日常供应能力(示意)">
  656. <EChart
  657. option={{
  658. tooltip: { trigger: "axis" },
  659. legend: { bottom: 0 },
  660. grid: { left: 40, right: 10, top: 20, bottom: 40 },
  661. xAxis: { type: "category", data: Array.from({ length: 24 }).map((_, i) => `${i}:00`) },
  662. yAxis: { type: "value" },
  663. color: [primary, "#f59e0b"],
  664. series: [
  665. { name: "供水(万m³/h)", type: "line", smooth: true, data: Array.from({ length: 24 }).map(() => 50 + Math.random() * 20) },
  666. { name: "燃气(万m³/h)", type: "line", smooth: true, data: Array.from({ length: 24 }).map(() => 30 + Math.random() * 15) },
  667. ],
  668. }}
  669. />
  670. </Card>
  671. </Col>
  672. <Col xs={24} md={12}>
  673. <Card title="管理单位信息">
  674. <Descriptions size="small" column={1} bordered>
  675. <Descriptions.Item label="燃气管理单位">市燃气集团、区属燃气公司等(共 6 家)</Descriptions.Item>
  676. <Descriptions.Item label="供水管理单位">市自来水公司、二供物业等(共 9 家)</Descriptions.Item>
  677. <Descriptions.Item label="排水管理单位">城排中心、各区运营公司(共 7 家)</Descriptions.Item>
  678. <Descriptions.Item label="产权分布">市属 60%,区属 30%,社会 10%</Descriptions.Item>
  679. </Descriptions>
  680. <Divider className="my-3" />
  681. <Timeline
  682. items={[
  683. { color: "green", children: "制度更新:设施巡检标准(本月)" },
  684. { color: "blue", children: "完成年度普查 80%" },
  685. { color: "orange", children: "外包维保单位进场(上周)" },
  686. ]}
  687. />
  688. </Card>
  689. </Col>
  690. </Row>
  691. <Row gutter={[16, 16]}>
  692. <Col xs={24} md={12}>
  693. <Card title="应急资源配置">
  694. <div className="grid grid-cols-2 gap-4">
  695. <Card size="small">
  696. <div className="text-xs text-slate-500">物资仓库</div>
  697. <div className="text-xl font-semibold mt-1">12 处</div>
  698. <Progress percent={78} status="active" size="small" />
  699. <div className="text-xs text-slate-500 mt-1">库存充足度</div>
  700. </Card>
  701. <Card size="small">
  702. <div className="text-xs text-slate-500">抢修队伍</div>
  703. <div className="text-xl font-semibold mt-1">26 支</div>
  704. <Progress percent={86} status="active" size="small" />
  705. <div className="text-xs text-slate-500 mt-1">到岗率</div>
  706. </Card>
  707. <Card size="small">
  708. <div className="text-xs text-slate-500">重点防护目标</div>
  709. <div className="text-xl font-semibold mt-1">143 处</div>
  710. <Progress percent={92} status="active" size="small" />
  711. <div className="text-xs text-slate-500 mt-1">纳入台账比例</div>
  712. </Card>
  713. <Card size="small">
  714. <div className="text-xs text-slate-500">联动单位</div>
  715. <div className="text-xl font-semibold mt-1">19 家</div>
  716. <Progress percent={74} status="active" size="small" />
  717. <div className="text-xs text-slate-500 mt-1">联动成熟度</div>
  718. </Card>
  719. </div>
  720. </Card>
  721. </Col>
  722. <Col xs={24} md={12}>
  723. <Card>
  724. <EChart option={radarCapacityOption} />
  725. </Card>
  726. </Col>
  727. </Row>
  728. </section>
  729. )}
  730. {selectedMenu === "monitor" && (
  731. <section className="space-y-4">
  732. <Tabs
  733. defaultActiveKey="summary"
  734. items={[
  735. { key: "summary", label: "监测概览" },
  736. { key: "distribution", label: "监测分布" },
  737. { key: "running", label: "运行概况" },
  738. ]}
  739. />
  740. <Row gutter={[16, 16]}>
  741. <Col xs={24} md={12} lg={8}>
  742. <Card>
  743. <EChart option={onlineGaugeOption} />
  744. </Card>
  745. </Col>
  746. <Col xs={24} md={12} lg={8}>
  747. <Card>
  748. <EChart option={deviceBarOption as EChartsOption} />
  749. </Card>
  750. </Col>
  751. <Col xs={24} md={24} lg={8}>
  752. <Card>
  753. <EChart option={riskBarOption} />
  754. </Card>
  755. </Col>
  756. </Row>
  757. <Card title="监测分布(按行业与风险)">
  758. <Row gutter={[16, 16]}>
  759. {(["燃气", "供水", "排水"] as const).map((ind) => (
  760. <Col xs={24} md={8} key={ind}>
  761. <Card size="small" title={ind}>
  762. <div className="flex items-center gap-4">
  763. <div className="flex-1">
  764. <div className="text-xs text-slate-500">设备在线</div>
  765. <div className="text-lg font-semibold">
  766. {devices.filter((d) => d.industry === ind && d.status === "在线").length}
  767. </div>
  768. <div className="text-xs text-slate-500">总量 {devices.filter((d) => d.industry === ind).length}</div>
  769. </div>
  770. <div className="flex-1">
  771. <div className="text-xs text-slate-500">高风险</div>
  772. <div className="text-lg font-semibold">{devices.filter((d) => d.industry === ind && d.risk === "高").length}</div>
  773. <Progress percent={Math.round((devices.filter((d) => d.industry === ind && d.risk === "高").length / Math.max(devices.filter((d) => d.industry === ind).length, 1)) * 100)} size="small" />
  774. </div>
  775. </div>
  776. </Card>
  777. </Col>
  778. ))}
  779. </Row>
  780. </Card>
  781. <Card title="运行概况(报警覆盖)">
  782. <EChart
  783. option={{
  784. tooltip: { trigger: "axis" },
  785. legend: { bottom: 0 },
  786. grid: { left: 40, right: 10, top: 20, bottom: 40 },
  787. xAxis: { type: "category", data: Array.from({ length: 12 }).map((_, i) => dayjs().subtract(11 - i, "month").format("YYYY-MM")) },
  788. yAxis: { type: "value" },
  789. color: [primary, "#f59e0b", "#a855f7"],
  790. series: (["燃气", "供水", "排水"] as const).map((ind, idx) => ({
  791. name: ind,
  792. type: "bar",
  793. stack: "sum",
  794. emphasis: { focus: "series" },
  795. data: Array.from({ length: 12 }).map(() => Math.floor(Math.random() * (idx === 0 ? 50 : idx === 1 ? 40 : 30))),
  796. })),
  797. }}
  798. />
  799. </Card>
  800. </section>
  801. )}
  802. {selectedMenu === "alert" && (
  803. <section className="space-y-4">
  804. <Tabs
  805. defaultActiveKey="current"
  806. items={[
  807. { key: "current", label: "当前预警" },
  808. { key: "history", label: "历史分析" },
  809. { key: "efficiency", label: "预警效率" },
  810. { key: "analysis", label: "预警分析" },
  811. ]}
  812. />
  813. <Row gutter={[16, 16]}>
  814. <Col xs={24} lg={16}>
  815. <Card title="总体预警处置情况">
  816. <Table
  817. size="small"
  818. rowKey="id"
  819. columns={alertColumns}
  820. dataSource={alerts}
  821. pagination={{ pageSize: 8 }}
  822. onRow={(record) => ({
  823. onClick: () => {
  824. setSelectedAlert(record)
  825. setDrawerOpen(true)
  826. },
  827. })}
  828. scroll={{ x: 900 }}
  829. />
  830. </Card>
  831. </Col>
  832. <Col xs={24} lg={8}>
  833. <Card title="处置效率">
  834. <div className="grid grid-cols-2 gap-4">
  835. <div>
  836. <div className="text-xs text-slate-500">平均处置时效</div>
  837. <div className="text-xl font-semibold mt-1">{(45 + Math.random() * 30).toFixed(0)} 分钟</div>
  838. <Progress percent={78} status="active" size="small" />
  839. <div className="text-xs text-slate-500 mt-1">较上月 +6%</div>
  840. </div>
  841. <div>
  842. <div className="text-xs text-slate-500">闭环率</div>
  843. <div className="text-xl font-semibold mt-1">
  844. {Math.round((alerts.filter((a) => a.status === "已闭环").length / Math.max(alerts.length, 1)) * 100)}%
  845. </div>
  846. <Progress percent={86} status="active" size="small" />
  847. <div className="text-xs text-slate-500 mt-1">较上周 +2%</div>
  848. </div>
  849. </div>
  850. </Card>
  851. <Card className="mt-4">
  852. <EChart option={efficiencyPieOption as EChartsOption} />
  853. </Card>
  854. </Col>
  855. </Row>
  856. <Row gutter={[16, 16]}>
  857. <Col xs={24} md={12}>
  858. <Card title="各行业预警数量(近6月)">
  859. <EChart
  860. option={{
  861. tooltip: { trigger: "axis" },
  862. legend: { bottom: 0 },
  863. grid: { left: 40, right: 10, top: 20, bottom: 40 },
  864. xAxis: { type: "category", data: Array.from({ length: 6 }).map((_, i) => dayjs().subtract(5 - i, "month").format("YYYY-MM")) },
  865. yAxis: { type: "value" },
  866. color: [primary, "#f59e0b", "#a855f7"],
  867. series: (["燃气", "供水", "排水"] as const).map((ind, idx) => ({
  868. name: ind,
  869. type: "line",
  870. smooth: true,
  871. data: Array.from({ length: 6 }).map(() => Math.floor(Math.random() * (idx === 0 ? 60 : idx === 1 ? 45 : 35)) + 5),
  872. })),
  873. }}
  874. />
  875. </Card>
  876. </Col>
  877. <Col xs={24} md={12}>
  878. <Card title="预警类型与成因分布">
  879. <EChart
  880. option={{
  881. tooltip: { trigger: "axis" },
  882. legend: { bottom: 0 },
  883. grid: { left: 40, right: 10, top: 20, bottom: 40 },
  884. xAxis: {
  885. type: "category",
  886. data: ["泄漏", "压力异常", "流量突变", "停电", "液位过低", "浊度异常"],
  887. axisLabel: { rotate: 20 },
  888. },
  889. yAxis: { type: "value" },
  890. color: [primary, "#f59e0b"],
  891. series: [
  892. { name: "设备原因", type: "bar", data: [30, 22, 18, 12, 9, 7] },
  893. { name: "外部原因", type: "bar", data: [18, 15, 14, 28, 11, 10] },
  894. ],
  895. }}
  896. />
  897. </Card>
  898. </Col>
  899. </Row>
  900. <Drawer
  901. title={
  902. <div className="flex items-center gap-2">
  903. <AlertTriangle size={18} color={selectedAlert ? alertLevelColor(selectedAlert.level) : primary} />
  904. <span>预警详情</span>
  905. </div>
  906. }
  907. placement="right"
  908. width={520}
  909. open={drawerOpen}
  910. onClose={() => setDrawerOpen(false)}
  911. >
  912. {selectedAlert ? (
  913. <div className="space-y-4">
  914. <Descriptions size="small" column={1} bordered>
  915. <Descriptions.Item label="预警编号">{selectedAlert.id}</Descriptions.Item>
  916. <Descriptions.Item label="等级">
  917. <LevelTag level={selectedAlert.level} />
  918. </Descriptions.Item>
  919. <Descriptions.Item label="行业">{selectedAlert.industry}</Descriptions.Item>
  920. <Descriptions.Item label="类型">{selectedAlert.type}</Descriptions.Item>
  921. <Descriptions.Item label="时间">{selectedAlert.time}</Descriptions.Item>
  922. <Descriptions.Item label="位置">{selectedAlert.location}</Descriptions.Item>
  923. <Descriptions.Item label="状态">
  924. <StatusBadge s={selectedAlert.status} />
  925. </Descriptions.Item>
  926. <Descriptions.Item label="描述">{selectedAlert.desc}</Descriptions.Item>
  927. </Descriptions>
  928. <Card size="small" title="事件时序">
  929. <EChart
  930. option={{
  931. grid: { left: 30, right: 10, top: 20, bottom: 20 },
  932. xAxis: { type: "category", data: ["发现", "确认", "处置", "复盘"] },
  933. yAxis: { type: "value" },
  934. color: [primary],
  935. series: [{ type: "line", smooth: true, data: [0, 12, 38, 60] }],
  936. }}
  937. />
  938. </Card>
  939. <Card size="small" title="一张图联动(示意)">
  940. <div className="relative w-full h-[200px] rounded-md overflow-hidden">
  941. <img src="/images/city-map.png" alt="地图联动示意图" className="absolute inset-0 w-full h-full object-cover opacity-90" />
  942. <div className="absolute inset-0">
  943. <div
  944. className="absolute w-3 h-3 rounded-full ring-2 ring-white animate-pulse"
  945. style={{ top: "42%", left: "56%", background: alertLevelColor(selectedAlert.level) }}
  946. title="预警位置"
  947. />
  948. </div>
  949. </div>
  950. </Card>
  951. <Space>
  952. <a className="text-emerald-600">查看工单</a>
  953. <a className="text-emerald-600">下达指令</a>
  954. <a className="text-emerald-600">通知联动</a>
  955. </Space>
  956. </div>
  957. ) : (
  958. <div className="text-slate-500 text-sm">请选择左侧预警查看详情。</div>
  959. )}
  960. </Drawer>
  961. </section>
  962. )}
  963. {selectedMenu === "settings" && (
  964. <section className="space-y-4">
  965. <Card title="预警设置">
  966. <Row gutter={[16, 16]}>
  967. <Col xs={24} md={12}>
  968. <Card size="small" title="阈值设置">
  969. <div className="grid grid-cols-2 gap-4">
  970. <div>
  971. <div className="text-xs text-slate-500 mb-1">压力异常阈值</div>
  972. <Select defaultValue="P≤0.3MPa" options={[{ value: "P≤0.3MPa", label: "P≤0.3MPa" }, { value: "P≤0.2MPa", label: "P≤0.2MPa" }]} />
  973. </div>
  974. <div>
  975. <div className="text-xs text-slate-500 mb-1">流量突变阈值</div>
  976. <Select defaultValue="ΔQ≥20%" options={[{ value: "ΔQ≥20%", label: "ΔQ≥20%" }, { value: "ΔQ≥30%", label: "ΔQ≥30%" }]} />
  977. </div>
  978. <div>
  979. <div className="text-xs text-slate-500 mb-1">水质指标(浊度)</div>
  980. <Select defaultValue="≥5 NTU" options={[{ value: "≥5 NTU", label: "≥5 NTU" }, { value: "≥3 NTU", label: "≥3 NTU" }]} />
  981. </div>
  982. <div>
  983. <div className="text-xs text-slate-500 mb-1">液位过低</div>
  984. <Select defaultValue="≤20%" options={[{ value: "≤20%", label: "≤20%" }, { value: "≤15%", label: "≤15%" }]} />
  985. </div>
  986. </div>
  987. </Card>
  988. </Col>
  989. <Col xs={24} md={12}>
  990. <Card size="small" title="通知策略">
  991. <div className="grid grid-cols-2 gap-4">
  992. <div className="flex items-center justify-between">
  993. <span>高等级预警短信</span>
  994. <Switch defaultChecked />
  995. </div>
  996. <div className="flex items-center justify-between">
  997. <span>邮件抄送管理层</span>
  998. <Switch />
  999. </div>
  1000. <div className="flex items-center justify-between">
  1001. <span>自动派单</span>
  1002. <Switch />
  1003. </div>
  1004. <div className="flex items-center justify-between">
  1005. <span>与值守大屏联动</span>
  1006. <Switch defaultChecked />
  1007. </div>
  1008. </div>
  1009. </Card>
  1010. </Col>
  1011. </Row>
  1012. </Card>
  1013. </section>
  1014. )}
  1015. </Content>
  1016. </Layout>
  1017. </Layout>
  1018. </ConfigProvider>
  1019. )
  1020. }