139 lines
4.1 KiB
TypeScript
139 lines
4.1 KiB
TypeScript
import React, { useState } from 'react';
|
|
import {
|
|
Card, Table, Tag, Badge, Space, Button,
|
|
Modal, Descriptions, Input, Select
|
|
} from 'antd';
|
|
import { EyeOutlined } from '@ant-design/icons';
|
|
|
|
const AntdCard = Card as any;
|
|
const { Search } = Input;
|
|
const { Option } = Select;
|
|
|
|
// 模拟数据
|
|
const mockAlarms = [
|
|
{ id: 1, deviceName: '1#环境传感器', level: 'warn', content: '温度超过阈值 62℃', time: '2026-05-07 10:24:00', status: 'unprocessed' },
|
|
{ id: 2, deviceName: '2#阵列区球机', level: 'error', content: '视频信号丢失', time: '2026-05-07 10:20:00', status: 'processing' },
|
|
{ id: 3, deviceName: '3#电池供电设备', level: 'info', content: '电量低于20%', time: '2026-05-07 09:50:00', status: 'processed' },
|
|
];
|
|
|
|
const AlarmRealtime = () => {
|
|
// 弹窗控制
|
|
const [detailVisible, setDetailVisible] = useState(false);
|
|
const [currentAlarm, setCurrentAlarm] = useState<any>(null);
|
|
|
|
// 搜索 + 筛选
|
|
const [list, setList] = useState(mockAlarms);
|
|
const [filteredList, setFilteredList] = useState(mockAlarms);
|
|
|
|
// 打开详情
|
|
const showDetail = (record: any) => {
|
|
setCurrentAlarm(record);
|
|
setDetailVisible(true);
|
|
};
|
|
|
|
// 搜索筛选
|
|
const handleSearch = (value: string) => {
|
|
const res = list.filter(item =>
|
|
item.deviceName.includes(value) ||
|
|
item.content.includes(value) ||
|
|
item.level.includes(value)
|
|
);
|
|
setFilteredList(res);
|
|
};
|
|
|
|
// 表格列
|
|
const columns = [
|
|
{ title: '时间', dataIndex: 'time', width: 180 },
|
|
{ title: '设备', dataIndex: 'deviceName' },
|
|
{
|
|
title: '级别',
|
|
render: (l: any) => {
|
|
const color = l.level === 'warn' ? 'orange' : l.level === 'error' ? 'red' : 'blue';
|
|
const text = l.level === 'warn' ? '警告' : l.level === 'error' ? '严重' : '提示';
|
|
return <Tag color={color}>{text}</Tag>;
|
|
}
|
|
},
|
|
{ title: '内容', dataIndex: 'content' },
|
|
{
|
|
title: '状态',
|
|
render: (r: any) => {
|
|
const statusMap = {
|
|
unprocessed: { status: 'error', text: '未处理' },
|
|
processing: { status: 'warning', text: '处理中' },
|
|
processed: { status: 'success', text: '已处理' },
|
|
closed: { status: 'default', text: '已关闭' },
|
|
};
|
|
const s = statusMap[r.status] || statusMap.unprocessed;
|
|
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="实时告警"
|
|
extra={
|
|
<Search
|
|
placeholder="搜索设备名称/告警内容"
|
|
style={{ width: 260 }}
|
|
onSearch={handleSearch}
|
|
/>
|
|
}
|
|
>
|
|
{/* 表格 */}
|
|
<Table
|
|
rowKey="id"
|
|
columns={columns}
|
|
dataSource={filteredList}
|
|
pagination={{ pageSize: 10 }}
|
|
/>
|
|
</AntdCard>
|
|
|
|
{/* 告警详情弹窗 */}
|
|
<Modal
|
|
title="告警详情"
|
|
open={detailVisible}
|
|
onCancel={() => setDetailVisible(false)}
|
|
footer={null}
|
|
width={500}
|
|
>
|
|
{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 === 'unprocessed' ? 'error' :
|
|
currentAlarm.status === 'processing' ? 'warning' : 'success'
|
|
}
|
|
text={
|
|
currentAlarm.status === 'unprocessed' ? '未处理' :
|
|
currentAlarm.status === 'processing' ? '处理中' : '已处理'
|
|
}
|
|
/>
|
|
</Descriptions.Item>
|
|
</Descriptions>
|
|
)}
|
|
</Modal>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AlarmRealtime;
|