2026-05-12 17:31:34 +08:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2026-05-07 14:13:26 +08:00
|
|
|
import {
|
|
|
|
|
Card, Table, Tag, Badge, Space, Button,
|
2026-05-12 17:31:34 +08:00
|
|
|
Modal, Descriptions, Form, Select, Input, Pagination, message
|
2026-05-07 14:13:26 +08:00
|
|
|
} from 'antd';
|
2026-05-12 17:31:34 +08:00
|
|
|
import { EyeOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
|
|
|
|
// 引入你的告警接口
|
|
|
|
|
import {
|
|
|
|
|
getAlarmList,
|
|
|
|
|
getAlarmDetail
|
|
|
|
|
} from '../../api/alarmApi.js';
|
2026-05-07 14:13:26 +08:00
|
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
const { Search } = Input;
|
|
|
|
|
|
2026-05-12 17:31:34 +08:00
|
|
|
// 级别 + 状态映射(和主页面保持一致)
|
|
|
|
|
const levelColor = { 1: '#F53F3F', 2: '#FF7D00', 3: '#F7BA1E', 4: '#165DFF' };
|
|
|
|
|
const levelText = { 1: '严重', 2: '重要', 3: '一般', 4: '提示' };
|
|
|
|
|
const statusText = { 0: '待处理', 1: '处理中', 2: '已关闭' };
|
2026-05-07 14:13:26 +08:00
|
|
|
|
|
|
|
|
const AlarmHistory = () => {
|
2026-05-12 17:31:34 +08:00
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
// 弹窗
|
2026-05-07 14:13:26 +08:00
|
|
|
const [detailVisible, setDetailVisible] = useState(false);
|
2026-05-12 17:31:34 +08:00
|
|
|
const [currentAlarm, setCurrentAlarm] = useState(null);
|
|
|
|
|
|
|
|
|
|
// 列表 + 分页
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [alarmList, setAlarmList] = useState([]);
|
|
|
|
|
const [total, setTotal] = useState(0);
|
|
|
|
|
const [pageNum, setPageNum] = useState(1);
|
|
|
|
|
const [pageSize, setPageSize] = useState(10);
|
|
|
|
|
|
|
|
|
|
// 查询条件
|
|
|
|
|
const [queryParams, setQueryParams] = useState({
|
|
|
|
|
deviceName: '',
|
|
|
|
|
alarmLevel: '',
|
|
|
|
|
handleStatus: '',
|
|
|
|
|
timeRange: 'all'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取告警历史列表
|
|
|
|
|
const fetchList = async () => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
|
|
|
|
const res = await getAlarmList({
|
|
|
|
|
pageNum,
|
|
|
|
|
pageSize,
|
|
|
|
|
...queryParams
|
|
|
|
|
});
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
setAlarmList(res.rows || []);
|
|
|
|
|
setTotal(res.total || 0);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
message.error('加载历史记录失败');
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
2026-05-07 14:13:26 +08:00
|
|
|
};
|
|
|
|
|
|
2026-05-12 17:31:34 +08:00
|
|
|
// 获取详情
|
|
|
|
|
const showDetail = async (id) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await getAlarmDetail(id);
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
setCurrentAlarm(res.data);
|
|
|
|
|
setDetailVisible(true);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
message.error('获取详情失败');
|
|
|
|
|
}
|
2026-05-07 14:13:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 搜索
|
2026-05-12 17:31:34 +08:00
|
|
|
const handleSearch = (values) => {
|
|
|
|
|
setQueryParams({ ...values });
|
|
|
|
|
setPageNum(1);
|
2026-05-07 14:13:26 +08:00
|
|
|
};
|
|
|
|
|
|
2026-05-12 17:31:34 +08:00
|
|
|
// 加载
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchList();
|
|
|
|
|
}, [pageNum, pageSize, queryParams]);
|
|
|
|
|
|
2026-05-07 14:13:26 +08:00
|
|
|
// 表格列
|
|
|
|
|
const columns = [
|
2026-05-12 17:31:34 +08:00
|
|
|
{
|
|
|
|
|
title: '告警时间',
|
|
|
|
|
dataIndex: 'createTime',
|
|
|
|
|
width: 190,
|
|
|
|
|
sorter: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '设备名称',
|
|
|
|
|
dataIndex: 'deviceName',
|
|
|
|
|
ellipsis: true
|
|
|
|
|
},
|
2026-05-07 14:13:26 +08:00
|
|
|
{
|
|
|
|
|
title: '告警级别',
|
2026-05-12 17:31:34 +08:00
|
|
|
width: 100,
|
|
|
|
|
render: (r) => (
|
|
|
|
|
<Tag color={levelColor[r.alarmLevel]} style={{ border: 'none', color: '#fff' }}>
|
|
|
|
|
{levelText[r.alarmLevel]}
|
|
|
|
|
</Tag>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '告警内容',
|
|
|
|
|
dataIndex: 'content',
|
|
|
|
|
ellipsis: true
|
2026-05-07 14:13:26 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '处理状态',
|
2026-05-12 17:31:34 +08:00
|
|
|
width: 100,
|
|
|
|
|
render: (r) => (
|
|
|
|
|
<Badge
|
|
|
|
|
status={r.handleStatus === 2 ? 'success' : r.handleStatus === 1 ? 'processing' : 'warning'}
|
|
|
|
|
text={statusText[r.handleStatus]}
|
|
|
|
|
/>
|
|
|
|
|
)
|
2026-05-07 14:13:26 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '操作',
|
2026-05-12 17:31:34 +08:00
|
|
|
width: 120,
|
|
|
|
|
render: (_, r) => (
|
|
|
|
|
<Button type="link" icon={<EyeOutlined />} onClick={() => showDetail(r.id)}>
|
2026-05-07 14:13:26 +08:00
|
|
|
查看详情
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={{ padding: 24 }}>
|
2026-05-12 17:31:34 +08:00
|
|
|
<Card
|
|
|
|
|
title="告警历史"
|
|
|
|
|
style={{ borderRadius: 8 }}
|
|
|
|
|
extra={<span style={{ color: '#888' }}>历史告警记录</span>}
|
|
|
|
|
>
|
|
|
|
|
{/* 筛选栏 */}
|
|
|
|
|
<Form
|
|
|
|
|
form={form}
|
|
|
|
|
layout="inline"
|
|
|
|
|
onFinish={handleSearch}
|
|
|
|
|
style={{ marginBottom: 16, flexWrap: 'wrap', gap: 16 }}
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item name="alarmLevel" label="告警级别">
|
|
|
|
|
<Select placeholder="全部" style={{ width: 130 }} allowClear>
|
|
|
|
|
<Option value={1}>严重</Option>
|
|
|
|
|
<Option value={2}>重要</Option>
|
|
|
|
|
<Option value={3}>一般</Option>
|
|
|
|
|
<Option value={4}>提示</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item name="handleStatus" label="处理状态">
|
|
|
|
|
<Select placeholder="全部" style={{ width: 130 }} allowClear>
|
|
|
|
|
<Option value={0}>待处理</Option>
|
|
|
|
|
<Option value={1}>处理中</Option>
|
|
|
|
|
<Option value={2}>已关闭</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Space>
|
|
|
|
|
<Button type="primary" htmlType="submit">查询</Button>
|
|
|
|
|
<Button htmlType="reset">重置</Button>
|
|
|
|
|
</Space>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
2026-05-07 14:13:26 +08:00
|
|
|
|
|
|
|
|
{/* 表格 */}
|
|
|
|
|
<Table
|
|
|
|
|
rowKey="id"
|
|
|
|
|
columns={columns}
|
2026-05-12 17:31:34 +08:00
|
|
|
dataSource={alarmList}
|
|
|
|
|
loading={loading}
|
|
|
|
|
pagination={false}
|
|
|
|
|
scroll={{ x: 'max-content' }}
|
2026-05-07 14:13:26 +08:00
|
|
|
/>
|
2026-05-12 17:31:34 +08:00
|
|
|
|
|
|
|
|
{/* 分页 */}
|
|
|
|
|
<div style={{ textAlign: 'center', marginTop: 16 }}>
|
|
|
|
|
<Pagination
|
|
|
|
|
current={pageNum}
|
|
|
|
|
pageSize={pageSize}
|
|
|
|
|
total={total}
|
|
|
|
|
onChange={(p, s) => {
|
|
|
|
|
setPageNum(p);
|
|
|
|
|
setPageSize(s);
|
|
|
|
|
}}
|
|
|
|
|
showSizeChanger
|
|
|
|
|
showQuickJumper
|
|
|
|
|
showTotal={(total) => `共 ${total} 条`}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
2026-05-07 14:13:26 +08:00
|
|
|
|
|
|
|
|
{/* 详情弹窗 */}
|
|
|
|
|
<Modal
|
|
|
|
|
title="告警历史详情"
|
|
|
|
|
open={detailVisible}
|
|
|
|
|
onCancel={() => setDetailVisible(false)}
|
|
|
|
|
footer={null}
|
2026-05-12 17:31:34 +08:00
|
|
|
width={580}
|
|
|
|
|
destroyOnClose
|
2026-05-07 14:13:26 +08:00
|
|
|
>
|
|
|
|
|
{currentAlarm && (
|
2026-05-12 17:31:34 +08:00
|
|
|
<Descriptions column={1} bordered size="small">
|
|
|
|
|
<Descriptions.Item label="告警ID">{currentAlarm.id}</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="告警时间">{currentAlarm.createTime}</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="设备ID">{currentAlarm.deviceId}</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="设备名称">{currentAlarm.deviceName || '-'}</Descriptions.Item>
|
2026-05-07 14:13:26 +08:00
|
|
|
<Descriptions.Item label="告警内容">{currentAlarm.content}</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="告警级别">
|
2026-05-12 17:31:34 +08:00
|
|
|
<Tag color={levelColor[currentAlarm.alarmLevel]} style={{ border: 'none', color: '#fff' }}>
|
|
|
|
|
{levelText[currentAlarm.alarmLevel]}
|
2026-05-07 14:13:26 +08:00
|
|
|
</Tag>
|
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="处理状态">
|
|
|
|
|
<Badge
|
2026-05-12 17:31:34 +08:00
|
|
|
status={currentAlarm.handleStatus === 2 ? 'success' : currentAlarm.handleStatus === 1 ? 'processing' : 'warning'}
|
|
|
|
|
text={statusText[currentAlarm.handleStatus]}
|
2026-05-07 14:13:26 +08:00
|
|
|
/>
|
|
|
|
|
</Descriptions.Item>
|
2026-05-12 17:31:34 +08:00
|
|
|
{currentAlarm.handleRemark && (
|
|
|
|
|
<Descriptions.Item label="处理备注">{currentAlarm.handleRemark}</Descriptions.Item>
|
|
|
|
|
)}
|
2026-05-07 14:13:26 +08:00
|
|
|
</Descriptions>
|
|
|
|
|
)}
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AlarmHistory;
|