import React, { useState } from 'react'; import { Card, Table, Tag, Badge, Space, Button, Modal, Descriptions, Form, Select, Input } from 'antd'; import { EyeOutlined } from '@ant-design/icons'; const AntdCard = Card as any; const { Option } = Select; const { Search } = Input; // 模拟历史数据 const mockHistory = [ { id: 1, deviceName: '1#环境传感器', level: 'warn', content: '温度超过阈值 62℃', time: '2026-05-07 08:10:22', status: 'processed' }, { id: 2, deviceName: '2#阵列区球机', level: 'error', content: '视频信号丢失', time: '2026-05-06 15:30:11', status: 'closed' }, { id: 3, deviceName: '3#电池供电设备', level: 'info', content: '电量低于20%', time: '2026-05-05 10:20:15', status: 'processed' }, { id: 4, deviceName: '1#阵列区球机', level: 'error', content: '存储设备故障', time: '2026-05-04 23:10:00', status: 'closed' }, ]; const AlarmHistory = () => { // 详情弹窗 const [detailVisible, setDetailVisible] = useState(false); const [currentAlarm, setCurrentAlarm] = useState(null); // 搜索筛选 const [list, setList] = useState(mockHistory); const [filteredList, setFilteredList] = useState(mockHistory); const [timeRange, setTimeRange] = useState('today'); const [deviceType, setDeviceType] = useState('all'); // 打开详情 const showDetail = (record: any) => { setCurrentAlarm(record); setDetailVisible(true); }; // 统一筛选逻辑 const handleFilter = (searchValue = '') => { let res = list.filter(item => { // 时间筛选 const timeMatch = timeRange === 'all' || true; // 后端可替换 // 设备筛选 const deviceMatch = deviceType === 'all' || item.deviceName.includes(deviceType); // 搜索筛选 const searchMatch = !searchValue || item.deviceName.includes(searchValue) || item.content.includes(searchValue) || item.level.includes(searchValue); return timeMatch && deviceMatch && searchMatch; }); setFilteredList(res); }; // 搜索 const handleSearch = (value: string) => { handleFilter(value); }; // 表格列 const columns = [ { title: '告警时间', dataIndex: 'time', width: 180 }, { title: '设备名称', dataIndex: 'deviceName' }, { title: '告警级别', render: (row: any) => { const color = row.level === 'warn' ? 'orange' : row.level === 'error' ? 'red' : 'blue'; const text = row.level === 'warn' ? '警告' : row.level === 'error' ? '严重' : '提示'; return {text}; } }, { title: '告警内容', dataIndex: 'content' }, { title: '处理状态', render: (row: any) => { const statusMap = { processed: { status: 'success', text: '已处理' }, closed: { status: 'default', text: '已关闭' }, }; const s = statusMap[row.status] || { status: 'default', text: '未知' }; return ; } }, { title: '操作', render: (_: any, record: any) => ( ) } ]; return (
{/* 统一筛选栏:搜索 + 时间 + 设备 */}
{/* 表格 */} {/* 详情弹窗 */} setDetailVisible(false)} footer={null} width={520} > {currentAlarm && ( {currentAlarm.time} {currentAlarm.deviceName} {currentAlarm.content} {currentAlarm.level === 'warn' ? '警告' : currentAlarm.level === 'error' ? '严重' : '提示'} )} ); }; export default AlarmHistory;