import React, { useState, useEffect } from 'react'; import { Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag, Typography, message, Pagination, Spin, Drawer, Descriptions, Switch } from 'antd'; import { BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined, SearchOutlined, ReloadOutlined, FileTextOutlined, NotificationOutlined } from '@ant-design/icons'; import { Line, Pie, Bar } from '@ant-design/charts'; import dayjs from 'dayjs'; // 接口引入 import { getAlarmList, getAlarmDetail, getAlarmStatistics, handleAlarm, exportAlarm } from '../../api/alarmApi.js'; const { RangePicker } = DatePicker; const { Text } = Typography; // 级别 + 状态颜色 const levelColor = { 1: '#F53F3F', 2: '#FF7D00', 3: '#F7BA1E', 4: '#165DFF' }; const levelText = { 1: '严重', 2: '重要', 3: '一般', 4: '提示' }; const statusColor = { 0: '#F7BA1E', 1: '#165DFF', 2: '#00B42A' }; const statusText = { 0: '待处理', 1: '处理中', 2: '已关闭' }; export default function AlarmCenterPage() { const [loading, setLoading] = useState(false); const [detailLoading, setDetailLoading] = useState(false); // 列表 const [alarmList, setAlarmList] = useState([]); const [total, setTotal] = useState(0); const [pageNum, setPageNum] = useState(1); const [pageSize] = useState(10); // 查询条件 const [queryParams, setQueryParams] = useState({ deviceId: '', alarmLevel: '', handleStatus: '', beginTime: '', endTime: '', }); // 抽屉 const [drawerVisible, setDrawerVisible] = useState(false); const [currentAlarm, setCurrentAlarm] = useState(null); // 统计 const [statData, setStatData] = useState({ total: 0, levelStats: {}, pending: 0, processing: 0, closed: 0, }); // ====================== 获取列表 ====================== const fetchList = async () => { setLoading(true); try { const res = await getAlarmList({ pageNum, pageSize, ...queryParams }); if (res.code === 0) { setAlarmList(res.rows || []); setTotal(res.total || 0); } } catch (err) { message.error('加载失败'); } finally { setLoading(false); } }; // ====================== 获取统计 ====================== const fetchStat = async () => { try { const res = await getAlarmStatistics(); if (res.code === 200) { setStatData(res.data || {}); } } catch (err) { } }; // ====================== 查看详情 ====================== const showDetail = async (id) => { setDetailLoading(true); try { const res = await getAlarmDetail(id); if (res.code === 0 || res.code === 200) { setCurrentAlarm(res.data); setDrawerVisible(true); } } catch (err) { message.error('加载详情失败'); } finally { setDetailLoading(false); } }; // ====================== 处理告警 ====================== const doHandle = async () => { try { await handleAlarm({ id: currentAlarm.id, handleStatus: 2, handleRemark: '已处理' }); message.success('处理成功'); setDrawerVisible(false); fetchList(); fetchStat(); } catch (err) { message.error('处理失败'); } }; // ====================== 导出 ====================== const doExport = () => { exportAlarm(queryParams).then(res => { const blob = new Blob([res], { type: 'application/vnd.ms-excel' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `告警记录_${dayjs().format('YYYYMMDDHHmmss')}.xlsx`; a.click(); URL.revokeObjectURL(url); }); }; // 加载 useEffect(() => { fetchList(); fetchStat(); }, [pageNum]); // ====================== 表格列 ====================== const columns = [ { title: '告警编号', dataIndex: 'alarmNo', width: 180, render: (text) => {text} }, { title: '告警标题', dataIndex: 'alarmTitle', ellipsis: true, width: 180 }, { title: '告警内容', dataIndex: 'alarmContent', ellipsis: true }, { title: '设备名称', dataIndex: 'deviceName', width: 160 }, { title: '告警级别', dataIndex: 'alarmLevel', width: 100, render: (l) => ( {levelText[l]} ) }, { title: '告警时间', dataIndex: 'alarmTime', width: 180, render: (t) => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-' }, { title: '处理状态', dataIndex: 'handleStatus', width: 110, render: (s) => ( {statusText[s]} ) }, { title: '操作', width: 100, fixed: 'right', render: (_, record) => ( ) } ]; // 图表数据 const pieConfig = { data: [ { type: '严重', value: statData.levelStats?.[1] || 0 }, { type: '重要', value: statData.levelStats?.[2] || 0 }, { type: '一般', value: statData.levelStats?.[3] || 0 }, { type: '提示', value: statData.levelStats?.[4] || 0 }, ].filter(i => i.value > 0), angleField: 'value', colorField: 'type', color: ['#F53F3F', '#FF7D00', '#F7BA1E', '#165DFF'], radius: 0.8, innerRadius: 0.6, label: false }; return (
{/* 查询栏 */}
告警级别
setQueryParams({ ...queryParams, handleStatus: v })} options={[ { value: '', label: '全部' }, { value: 0, label: '待处理' }, { value: 1, label: '处理中' }, { value: 2, label: '已关闭' }, ]} />
设备ID
setQueryParams({ ...queryParams, deviceId: e.target.value })} style={{ width: 160 }} />
时间范围
{ if (arr) { setQueryParams({ ...queryParams, beginTime: arr[0].format('YYYY-MM-DD HH:mm:ss'), endTime: arr[1].format('YYYY-MM-DD HH:mm:ss') }); } }} />
{/* 统计卡片 */}
告警总数
{statData.total || 0}
严重告警
{statData.levelStats?.[1] || 0}
待处理
{statData.pending || 0}
处理中
{statData.processing || 0}
已关闭
{statData.closed || 0}
{/* 表格 */}
setPageNum(p)} showSizeChanger={false} showQuickJumper size="small" />
{/* 三个图表 */} {/* 告警详情抽屉 —— 按设计稿完整实现 */} setDrawerVisible(false)} width={420} destroyOnClose > {currentAlarm && ( <> {/* 告警头部 */}
{currentAlarm.alarmTitle} {levelText[currentAlarm.alarmLevel]}
告警编号:{currentAlarm.alarmNo}
{/* 告警基础信息 */} {currentAlarm.deviceName || '-'} {currentAlarm.deviceType || '-'} {dayjs(currentAlarm.alarmTime).format('YYYY-MM-DD HH:mm:ss')} {statusText[currentAlarm.handleStatus]} {currentAlarm.handleUserName || '-'} {/* 告警描述 */}
{currentAlarm.alarmContent || '-'}
{/* 根因分析 */}
{currentAlarm.rootCause || '-'}
{/* 推荐处理措施 */}
{currentAlarm.handleSuggestion || '-'}
{/* 通知与订阅 */}
短信 {/**/} 钉钉 {/**/} 邮件 {/* 底部按钮 */} )} ); }