"use client" import {useEffect, useState} from "react" import { Alert, Button, Card, Col, Descriptions, Form, Input, Modal, Row, Select, Space, Table, Tag, Timeline, } from "antd" import {BellOutlined, CheckCircleOutlined, EditOutlined, EyeOutlined} from "@ant-design/icons" import {Line} from "@ant-design/plots" import globalMessage from "@/app/_modules/globalMessage"; const { Option } = Select const { TextArea } = Input // 模拟报警数据 const mockAlarmData = [ { id: "A001", title: "解放路段压力异常报警", type: "压力异常", level: "高", location: "解放路调压站", deviceId: "D001", deviceName: "压力监测器001", value: 0.52, threshold: 0.45, unit: "MPa", status: "未处理", createTime: "2024-01-15 14:30:25", updateTime: "2024-01-15 14:30:25", handler: null, handleTime: null, description: "管网压力超出安全阈值,可能存在安全隐患", solution: null, }, { id: "A002", title: "人民路段流量异常报警", type: "流量异常", level: "中", location: "人民路段", deviceId: "D002", deviceName: "流量监测器002", value: 4200, threshold: 3500, unit: "m³/h", status: "处理中", createTime: "2024-01-15 13:45:10", updateTime: "2024-01-15 14:15:30", handler: "张三", handleTime: "2024-01-15 14:15:30", description: "流量超出正常范围,需要检查管网状态", solution: "正在检查管网连接状态,预计30分钟内完成", }, { id: "A003", title: "建设路段泄漏报警", type: "泄漏检测", level: "高", location: "建设路北段", deviceId: "D004", deviceName: "泄漏检测器004", value: 0.08, threshold: 0.05, unit: "ppm", status: "已处理", createTime: "2024-01-15 12:20:15", updateTime: "2024-01-15 13:45:20", handler: "李四", handleTime: "2024-01-15 12:25:15", description: "检测到燃气泄漏,浓度超标", solution: "已完成管线检修,泄漏点已修复,监测数据恢复正常", }, ] // 模拟报警统计数据 const mockAlarmStats = [ { time: "00:00", count: 2 }, { time: "04:00", count: 1 }, { time: "08:00", count: 3 }, { time: "12:00", count: 5 }, { time: "16:00", count: 2 }, { time: "20:00", count: 1 }, ] export default function AbnormalAlarm() { const [isModalVisible, setIsModalVisible] = useState(false) const [isDetailModalVisible, setIsDetailModalVisible] = useState(false) const [selectedAlarm, setSelectedAlarm] = useState(null) const [form] = Form.useForm() const [alarmData, setAlarmData] = useState(mockAlarmData) // 模拟实时报警更新 useEffect(() => { const interval = setInterval(() => { // 模拟新报警 if (Math.random() < 0.1) { const newAlarm = { id: `A${Date.now()}`, title: "新报警事件", type: "压力异常", level: "中", location: "测试路段", deviceId: "D999", deviceName: "测试设备", value: 0.48, threshold: 0.45, unit: "MPa", status: "未处理", createTime: new Date().toLocaleString(), updateTime: new Date().toLocaleString(), handler: null, handleTime: null, description: "模拟报警事件", solution: null, } setAlarmData((prev) => [newAlarm, ...prev]) globalMessage.warning("收到新报警!") } }, 30000) // 30秒检查一次 return () => clearInterval(interval) }, []) const handleView = (record: any) => { setSelectedAlarm(record) setIsDetailModalVisible(true) } const handleProcess = (record: any) => { setSelectedAlarm(record) form.setFieldsValue({ handler: "当前用户", solution: "", }) setIsModalVisible(true) } const handleModalOk = () => { form.validateFields().then((values) => { const updatedData = alarmData.map((item) => item.id === selectedAlarm?.id ? { ...item, status: "处理中", handler: values.handler, handleTime: new Date().toLocaleString(), updateTime: new Date().toLocaleString(), solution: values.solution, } : item, ) setAlarmData(updatedData) globalMessage.success("报警处理成功") setIsModalVisible(false) form.resetFields() }) } const handleComplete = (id: string) => { const updatedData = alarmData.map((item) => item.id === id ? { ...item, status: "已处理", updateTime: new Date().toLocaleString(), } : item, ) setAlarmData(updatedData) globalMessage.success("报警已标记为完成") } const getStatusColor = (status: string) => { switch (status) { case "未处理": return "red" case "处理中": return "orange" case "已处理": return "green" default: return "default" } } const getLevelColor = (level: string) => { switch (level) { case "高": return "red" case "中": return "orange" case "低": return "blue" default: return "default" } } const columns = [ { title: "报警编号", dataIndex: "id", key: "id", width: 100 }, { title: "报警标题", dataIndex: "title", key: "title", width: 200 }, { title: "报警类型", dataIndex: "type", key: "type", width: 120 }, { title: "报警等级", dataIndex: "level", key: "level", width: 100, render: (level: string) => {level}, }, { title: "位置", dataIndex: "location", key: "location", width: 150 }, { title: "设备名称", dataIndex: "deviceName", key: "deviceName", width: 150 }, { title: "异常值", key: "value", width: 120, render: (_, record: any) => `${record.value} ${record.unit}`, }, { title: "阈值", key: "threshold", width: 120, render: (_, record: any) => `${record.threshold} ${record.unit}`, }, { title: "状态", dataIndex: "status", key: "status", width: 100, render: (status: string) => {status}, }, { title: "创建时间", dataIndex: "createTime", key: "createTime", width: 180 }, { title: "处理人", dataIndex: "handler", key: "handler", width: 100 }, { title: "操作", key: "action", width: 200, fixed: "right", render: (_, record) => ( {record.status === "未处理" && ( )} {record.status === "处理中" && ( )} ), }, ] const lineConfig = { data: mockAlarmStats, xField: "time", yField: "count", color: "#f5222d", point: { size: 5, shape: "diamond", }, area: { style: { fill: "l(270) 0:#ffffff 0.5:#ffccc7 1:#f5222d", fillOpacity: 0.3, }, }, } const unhandledCount = alarmData.filter((item) => item.status === "未处理").length const processingCount = alarmData.filter((item) => item.status === "处理中").length const handledCount = alarmData.filter((item) => item.status === "已处理").length return (
{/* 报警概览 */}
{unhandledCount}
未处理报警
{processingCount}
处理中
{handledCount}
已处理
{alarmData.length}
报警总数
{/* 紧急报警提醒 */} {unhandledCount > 0 && ( } showIcon className="mb-6" /> )} {/* 报警趋势图 */} {/* 筛选控件 */}
{/* 报警列表 */} (record.status === "未处理" && record.level === "高" ? "bg-red-50" : "")} /> {/* 处理模态框 */} setIsModalVisible(false)} width={600} >