import React, { useState, useEffect } from 'react';
import {
Card, Table, Tag, Badge, Space, Button,
Modal, Descriptions, Form, Select, Input, Pagination, message
} from 'antd';
import { EyeOutlined, SearchOutlined } from '@ant-design/icons';
import dayjs from 'dayjs';
// 引入你的告警接口
import {
getAlarmList,
getAlarmDetail
} from '../../api/alarmApi.js';
const { Option } = Select;
const { Search } = Input;
// 级别 + 状态映射(和主页面保持一致)
const levelColor = { 1: '#F53F3F', 2: '#FF7D00', 3: '#F7BA1E', 4: '#165DFF' };
const levelText = { 1: '严重', 2: '重要', 3: '一般', 4: '提示' };
const statusText = { 0: '待处理', 1: '处理中', 2: '已关闭' };
const AlarmHistory = () => {
const [form] = Form.useForm();
// 弹窗
const [detailVisible, setDetailVisible] = useState(false);
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);
}
};
// 获取详情
const showDetail = async (id) => {
try {
const res = await getAlarmDetail(id);
if (res.code === 200) {
setCurrentAlarm(res.data);
setDetailVisible(true);
}
} catch (err) {
message.error('获取详情失败');
}
};
// 搜索
const handleSearch = (values) => {
setQueryParams({ ...values });
setPageNum(1);
};
// 加载
useEffect(() => {
fetchList();
}, [pageNum, pageSize, queryParams]);
// 表格列
const columns = [
{
title: '告警时间',
dataIndex: 'createTime',
width: 190,
sorter: true
},
{
title: '设备名称',
dataIndex: 'deviceName',
ellipsis: true
},
{
title: '告警级别',
width: 100,
render: (r) => (