告警中心 初始化

This commit is contained in:
mmc
2026-05-07 14:13:26 +08:00
parent e401eef62f
commit 9cf26ce2bd
19 changed files with 1321 additions and 928 deletions

View File

@@ -0,0 +1,183 @@
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<any>(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 <Tag color={color}>{text}</Tag>;
}
},
{ 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 <Badge status={s.status as any} text={s.text} />;
}
},
{
title: '操作',
render: (_: any, record: any) => (
<Button type="link" icon={<EyeOutlined />} onClick={() => showDetail(record)}>
查看详情
</Button>
)
}
];
return (
<div style={{ padding: 24 }}>
<AntdCard title="告警历史">
{/* 统一筛选栏:搜索 + 时间 + 设备 */}
<Space wrap size={16} style={{ marginBottom: 16, width: '100%' }}>
<Search
placeholder="搜索设备/内容/级别"
style={{ width: 260 }}
onSearch={handleSearch}
/>
<Form layout="inline">
<Form.Item label="时间范围">
<Select
value={timeRange}
style={{ width: 160 }}
onChange={(val) => {
setTimeRange(val);
handleFilter();
}}
>
<Option value="today">今日</Option>
<Option value="yesterday">昨日</Option>
<Option value="week">近7天</Option>
<Option value="month">本月</Option>
<Option value="all">全部</Option>
</Select>
</Form.Item>
<Form.Item label="设备类型">
<Select
value={deviceType}
style={{ width: 160 }}
onChange={(val) => {
setDeviceType(val);
handleFilter();
}}
>
<Option value="all">全部设备</Option>
<Option value="传感器">传感器</Option>
<Option value="球机">球机</Option>
<Option value="电池">电池设备</Option>
</Select>
</Form.Item>
</Form>
</Space>
{/* 表格 */}
<Table
rowKey="id"
columns={columns}
dataSource={filteredList}
pagination={{ pageSize: 10 }}
/>
</AntdCard>
{/* 详情弹窗 */}
<Modal
title="告警历史详情"
open={detailVisible}
onCancel={() => setDetailVisible(false)}
footer={null}
width={520}
>
{currentAlarm && (
<Descriptions column={1} bordered>
<Descriptions.Item label="告警时间">{currentAlarm.time}</Descriptions.Item>
<Descriptions.Item label="设备名称">{currentAlarm.deviceName}</Descriptions.Item>
<Descriptions.Item label="告警内容">{currentAlarm.content}</Descriptions.Item>
<Descriptions.Item label="告警级别">
<Tag color={currentAlarm.level === 'warn' ? 'orange' : currentAlarm.level === 'error' ? 'red' : 'blue'}>
{currentAlarm.level === 'warn' ? '警告' : currentAlarm.level === 'error' ? '严重' : '提示'}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="处理状态">
<Badge
status={currentAlarm.status === 'processed' ? 'success' : 'default'}
text={currentAlarm.status === 'processed' ? '已处理' : '已关闭'}
/>
</Descriptions.Item>
</Descriptions>
)}
</Modal>
</div>
);
};
export default AlarmHistory;