diff --git a/src/components/alerts/AlarmHistory.tsx b/src/components/alerts/AlarmHistory.tsx
index a4b121a..8ab52ab 100644
--- a/src/components/alerts/AlarmHistory.tsx
+++ b/src/components/alerts/AlarmHistory.tsx
@@ -1,33 +1,34 @@
import React, { useState, useEffect } from 'react';
import {
- Card, Table, Tag, Badge, Space, Button,
- Modal, Descriptions, Form, Select, Input, Pagination, message
+ Card, Table, Tag, Space, Button,
+ Drawer, Descriptions, Form, Select, Pagination, message
} from 'antd';
-import { EyeOutlined, SearchOutlined } from '@ant-design/icons';
+import { EyeOutlined, NotificationOutlined } 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 statusColor = { 0: '#F7BA1E', 1: '#165DFF', 2: '#00B42A' };
const AlarmHistory = () => {
const [form] = Form.useForm();
- // 弹窗
- const [detailVisible, setDetailVisible] = useState(false);
+ // 抽屉
+ const [drawerVisible, setDrawerVisible] = useState(false);
const [currentAlarm, setCurrentAlarm] = useState(null);
+ const [detailLoading, setDetailLoading] = useState(false);
- // 列表 + 分页
+ // 列表
const [loading, setLoading] = useState(false);
const [alarmList, setAlarmList] = useState([]);
const [total, setTotal] = useState(0);
@@ -36,69 +37,64 @@ const AlarmHistory = () => {
// 查询条件
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) {
+ const res = await getAlarmList({ pageNum, pageSize, ...queryParams });
+ if (res.code === 0) {
setAlarmList(res.rows || []);
setTotal(res.total || 0);
}
} catch (err) {
- message.error('加载历史记录失败');
+ message.error('加载失败');
} finally {
setLoading(false);
}
};
- // 获取详情
+ // 查看详情(打开抽屉)
const showDetail = async (id) => {
+ setDetailLoading(true);
try {
const res = await getAlarmDetail(id);
if (res.code === 200) {
setCurrentAlarm(res.data);
- setDetailVisible(true);
+ setDrawerVisible(true);
+ } else {
+ message.error('获取详情失败');
}
} catch (err) {
- message.error('获取详情失败');
+ message.error('请求异常');
+ } finally {
+ setDetailLoading(false);
}
};
// 搜索
const handleSearch = (values) => {
- setQueryParams({ ...values });
+ setQueryParams(values);
setPageNum(1);
};
- // 加载
useEffect(() => {
fetchList();
}, [pageNum, pageSize, queryParams]);
// 表格列
const columns = [
+ { title: '告警编号', dataIndex: 'alarmNo', width: 180 },
{
title: '告警时间',
- dataIndex: 'createTime',
+ dataIndex: 'alarmTime',
width: 190,
- sorter: true
- },
- {
- title: '设备名称',
- dataIndex: 'deviceName',
- ellipsis: true
+ render: (t) => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
+ { title: '设备名称', dataIndex: 'deviceName', ellipsis: true },
{
title: '告警级别',
width: 100,
@@ -108,24 +104,22 @@ const AlarmHistory = () => {
)
},
- {
- title: '告警内容',
- dataIndex: 'content',
- ellipsis: true
- },
+ { title: '告警标题', dataIndex: 'alarmTitle', ellipsis: true, width: 180 },
+ { title: '告警内容', dataIndex: 'alarmContent', ellipsis: true },
{
title: '处理状态',
- width: 100,
+ width: 110,
render: (r) => (
-
+
+
+ {statusText[r.handleStatus]}
+
)
},
{
title: '操作',
width: 120,
+ fixed: 'right',
render: (_, r) => (
} onClick={() => showDetail(r.id)}>
查看详情
@@ -135,21 +129,14 @@ const AlarmHistory = () => {
];
return (
-
-
历史告警记录}
- >
- {/* 筛选栏 */}
+
+
- {/* 表格 */}
{
scroll={{ x: 'max-content' }}
/>
- {/* 分页 */}
{
- setPageNum(p);
- setPageSize(s);
- }}
+ onChange={(p, s) => { setPageNum(p); setPageSize(s); }}
showSizeChanger
showQuickJumper
showTotal={(total) => `共 ${total} 条`}
@@ -202,39 +184,75 @@ const AlarmHistory = () => {
- {/* 详情弹窗 */}
- setDetailVisible(false)}
- footer={null}
- width={580}
+ {/* 右侧详情抽屉 —— 新版设计稿样式 */}
+ setDrawerVisible(false)}
+ width={650}
destroyOnClose
>
+
+ {currentAlarm?.alarmNo || '-'}
+ {currentAlarm?.alarmTitle || '-'}
+ {currentAlarm?.alarmContent || '-'}
+ {currentAlarm?.deviceId || '-'}
+ {currentAlarm?.deviceName || '-'}
+
+ {currentAlarm?.alarmTime ? dayjs(currentAlarm.alarmTime).format('YYYY-MM-DD HH:mm:ss') : '-'}
+
+
+
+ {levelText[currentAlarm?.alarmLevel]}
+
+
+
+
+ {statusText[currentAlarm?.handleStatus]}
+
+
+ {currentAlarm?.handleUserName || '-'}
+
+ {currentAlarm?.handleTime ? dayjs(currentAlarm.handleTime).format('YYYY-MM-DD HH:mm:ss') : '-'}
+
+ {currentAlarm?.handleRemark || '-'}
+ {currentAlarm?.rootCause || '-'}
+
+ {/* 新增:推荐处理措施 */}
+
+ {currentAlarm?.handleSuggestion || '-'}
+
+
+
+ {/* 通知订阅模块 */}
{currentAlarm && (
-
- {currentAlarm.id}
- {currentAlarm.createTime}
- {currentAlarm.deviceId}
- {currentAlarm.deviceName || '-'}
- {currentAlarm.content}
-
-
- {levelText[currentAlarm.alarmLevel]}
-
-
-
-
-
- {currentAlarm.handleRemark && (
- {currentAlarm.handleRemark}
- )}
-
+
+
+
+
+ 短信
+
+ {currentAlarm.notifySms === 1 ? '已开启' : '已关闭'}
+
+
+
+
+ 钉钉
+
+ {currentAlarm.notifyTelegram === 1 ? '已开启' : '已关闭'}
+
+
+
+
+ 邮件:
+
+ {currentAlarm.notifyEmail === 1 ? '已开启' : '已关闭'}
+
+
+
+
)}
-
+
);
};
diff --git a/src/components/alerts/AlarmOverview.tsx b/src/components/alerts/AlarmOverview.tsx
index e67fa74..bb74e78 100644
--- a/src/components/alerts/AlarmOverview.tsx
+++ b/src/components/alerts/AlarmOverview.tsx
@@ -1,12 +1,11 @@
import React, { useState, useEffect } from 'react';
import {
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
- Typography, Modal, Form, message, Pagination, Spin, Empty, Divider, Switch
+ Typography, message, Pagination, Spin, Drawer, Descriptions, Switch
} from 'antd';
import {
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined,
- SearchOutlined, ReloadOutlined, CloseOutlined, InfoCircleOutlined,
- FileTextOutlined, LineChartOutlined, PieChartOutlined, BarChartOutlined,
+ SearchOutlined, ReloadOutlined, FileTextOutlined, NotificationOutlined
} from '@ant-design/icons';
import { Line, Pie, Bar } from '@ant-design/charts';
import dayjs from 'dayjs';
@@ -21,7 +20,7 @@ import {
} from '../../api/alarmApi.js';
const { RangePicker } = DatePicker;
-const { Text, Title } = Typography;
+const { Text } = Typography;
// 级别 + 状态颜色
const levelColor = { 1: '#F53F3F', 2: '#FF7D00', 3: '#F7BA1E', 4: '#165DFF' };
@@ -31,7 +30,6 @@ const statusColor = { 0: '#F7BA1E', 1: '#165DFF', 2: '#00B42A' };
const statusText = { 0: '待处理', 1: '处理中', 2: '已关闭' };
export default function AlarmCenterPage() {
- const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const [detailLoading, setDetailLoading] = useState(false);
@@ -50,11 +48,11 @@ export default function AlarmCenterPage() {
endTime: '',
});
- // 详情
- const [detailVisible, setDetailVisible] = useState(false);
+ // 抽屉
+ const [drawerVisible, setDrawerVisible] = useState(false);
const [currentAlarm, setCurrentAlarm] = useState(null);
- // 统计(精准匹配后端接口)
+ // 统计
const [statData, setStatData] = useState({
total: 0,
levelStats: {},
@@ -68,7 +66,7 @@ export default function AlarmCenterPage() {
setLoading(true);
try {
const res = await getAlarmList({ pageNum, pageSize, ...queryParams });
- if (res.code === 200) {
+ if (res.code === 0) {
setAlarmList(res.rows || []);
setTotal(res.total || 0);
}
@@ -94,9 +92,9 @@ export default function AlarmCenterPage() {
setDetailLoading(true);
try {
const res = await getAlarmDetail(id);
- if (res.code === 200) {
+ if (res.code === 0 || res.code === 200) {
setCurrentAlarm(res.data);
- setDetailVisible(true);
+ setDrawerVisible(true);
}
} catch (err) {
message.error('加载详情失败');
@@ -110,7 +108,7 @@ export default function AlarmCenterPage() {
try {
await handleAlarm({ id: currentAlarm.id, handleStatus: 2, handleRemark: '已处理' });
message.success('处理成功');
- setDetailVisible(false);
+ setDrawerVisible(false);
fetchList();
fetchStat();
} catch (err) {
@@ -141,12 +139,26 @@ export default function AlarmCenterPage() {
const columns = [
{
title: '告警编号',
- dataIndex: 'id',
- width: 140,
- render: (text) => AL{text}
+ dataIndex: 'alarmNo',
+ width: 180,
+ render: (text) => {text}
+ },
+ {
+ title: '告警标题',
+ dataIndex: 'alarmTitle',
+ ellipsis: true,
+ width: 180
+ },
+ {
+ title: '告警内容',
+ dataIndex: 'alarmContent',
+ ellipsis: true
+ },
+ {
+ title: '设备名称',
+ dataIndex: 'deviceName',
+ width: 160
},
- { title: '告警内容', dataIndex: 'content', ellipsis: true },
- { title: '来源设备', dataIndex: 'deviceId', width: 160 },
{
title: '告警级别',
dataIndex: 'alarmLevel',
@@ -157,11 +169,16 @@ export default function AlarmCenterPage() {
)
},
- { title: '发生时间', dataIndex: 'createTime', width: 160 },
+ {
+ title: '告警时间',
+ dataIndex: 'alarmTime',
+ width: 180,
+ render: (t) => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
+ },
{
title: '处理状态',
dataIndex: 'handleStatus',
- width: 100,
+ width: 110,
render: (s) => (
@@ -171,14 +188,15 @@ export default function AlarmCenterPage() {
},
{
title: '操作',
- width: 80,
+ width: 100,
+ fixed: 'right',
render: (_, record) => (
)
}
];
- // 图表数据(自动使用接口统计)
+ // 图表数据
const pieConfig = {
data: [
{ type: '严重', value: statData.levelStats?.[1] || 0 },
@@ -193,285 +211,337 @@ export default function AlarmCenterPage() {
return (
-
- {/* 左侧 */}
-
- {/* 查询栏 */}
-
-
-
-
-
- 告警级别
-
- {/* 统计卡片 —— 完全匹配后端接口 */}
-
-
-
-
-
-
-
-
-
-
- 告警总数
-
- {statData.total || 0}
-
-
-
-
-
+ {/* 底部按钮 */}
+
+ >
+ )}
+
+
-
-
-
-
-
-
-
-
-
- 严重告警
-
- {statData.levelStats?.[1] || 0}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 待处理
-
- {statData.pending || 0}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 处理中
-
- {statData.processing || 0}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 已关闭
-
- {statData.closed || 0}
-
-
-
-
-
-
-
- {/* 表格 */}
-
-
-
-
-
-
-
-
setPageNum(p)}
- showSizeChanger={false} showQuickJumper size="small"
- />
-
-
-
-
-
- {/* 三个图表 */}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {/* 右侧详情 */}
- {detailVisible && currentAlarm && (
-
-
-
setDetailVisible(false)} />} style={{ borderRadius: 8 }}>
-
-
-
-
-
-
-
- {currentAlarm.content}
-
- {levelText[currentAlarm.alarmLevel]}
-
-
-
告警编号:AL{currentAlarm.id}
-
-
-
-
- 设备ID
{currentAlarm.deviceId}
- 状态
{statusText[currentAlarm.handleStatus]}
- 发生时间
{currentAlarm.createTime}
-
-
-
-
-
-
- )}
-
);
}
diff --git a/src/components/alerts/AlarmStatistics.tsx b/src/components/alerts/AlarmStatistics.tsx
index 6439146..e414524 100644
--- a/src/components/alerts/AlarmStatistics.tsx
+++ b/src/components/alerts/AlarmStatistics.tsx
@@ -1,125 +1,165 @@
-import React, { useEffect, useRef } from 'react';
+import React, { useEffect, useRef, useState } from 'react';
import { Card, Row, Col, Space } from 'antd';
-import { AreaChartOutlined } from '@ant-design/icons';
+import {
+ BellOutlined,
+ ExclamationCircleOutlined,
+ ClockCircleOutlined,
+ CheckCircleOutlined
+} from '@ant-design/icons';
import * as echarts from 'echarts';
-const AntdCard = Card as any;
+// 接口引入
+import { getAlarmStatistics } from '../../api/alarmApi.js';
const AlarmStatistics = () => {
- // 图表 ref
const barChartRef = useRef(null);
const pieChartRef = useRef(null);
+ const [statData, setStatData] = useState({
+ total: 0,
+ levelStats: {},
+ pending: 0,
+ processing: 0,
+ closed: 0,
+ });
+
+ // 获取统计(修复:接口 code = 0 才是成功)
+ const fetchStat = async () => {
+ try {
+ const res = await getAlarmStatistics();
+ if (res.code === 200) {
+ setStatData(res.data || {});
+ }
+ } catch (err) { }
+ };
+
// 柱状图
useEffect(() => {
if (!barChartRef.current) return;
- const barChart = echarts.init(barChartRef.current);
- barChart.setOption({
- title: { text: '近7天告警趋势' },
- xAxis: {
- type: 'category',
- data: ['1日', '2日', '3日', '4日', '5日', '6日', '7日']
- },
+ const chart = echarts.init(barChartRef.current);
+
+ const option = {
+ title: { text: '近7天告警趋势', textStyle: { fontSize: 14 } },
+ xAxis: { type: 'category', data: ['1日', '2日', '3日', '4日', '5日', '6日', '7日'] },
yAxis: { type: 'value' },
- series: [
- {
- data: [5, 8, 12, 9, 15, 7, 12],
- type: 'bar',
- itemStyle: { color: '#1677ff' }
- }
- ]
- });
-
- const resizeFn = () => barChart.resize();
- window.addEventListener('resize', resizeFn);
-
- return () => {
- barChart.dispose();
- window.removeEventListener('resize', resizeFn);
+ series: [{
+ data: [5, 8, 12, 9, 15, 7, statData.total || 2],
+ type: 'bar',
+ itemStyle: { color: '#165DFF', borderRadius: 4 }
+ }]
};
- }, []);
+
+ chart.setOption(option);
+ const resize = () => chart.resize();
+ window.addEventListener('resize', resize);
+ return () => {
+ chart.dispose();
+ window.removeEventListener('resize', resize);
+ };
+ }, [statData]);
// 饼图
useEffect(() => {
if (!pieChartRef.current) return;
- const pieChart = echarts.init(pieChartRef.current);
- pieChart.setOption({
+ const chart = echarts.init(pieChartRef.current);
+
+ const pieData = [
+ { value: statData.levelStats?.[1] || 0, name: '严重告警' },
+ { value: statData.levelStats?.[2] || 0, name: '重要告警' },
+ { value: statData.levelStats?.[3] || 0, name: '一般告警' },
+ { value: statData.levelStats?.[4] || 0, name: '提示告警' },
+ ].filter(i => i.value > 0);
+
+ const option = {
title: { text: '告警级别分布' },
tooltip: { trigger: 'item' },
- series: [
- {
- type: 'pie',
- radius: '50%',
- data: [
- { value: 15, name: '严重告警' },
- { value: 30, name: '警告告警' },
- { value: 25, name: '提示告警' }
- ]
- }
- ]
- });
-
- const resizeFn = () => pieChart.resize();
- window.addEventListener('resize', resizeFn);
-
- return () => {
- pieChart.dispose();
- window.removeEventListener('resize', resizeFn);
+ legend: { bottom: 0 },
+ series: [{
+ type: 'pie',
+ radius: ['40%', '70%'],
+ data: pieData.length ? pieData : [{ value: 1, name: '暂无数据' }],
+ color: ['#F53F3F', '#FF7D00', '#F7BA1E', '#165DFF'],
+ }]
};
+
+ chart.setOption(option);
+ const resize = () => chart.resize();
+ window.addEventListener('resize', resize);
+ return () => {
+ chart.dispose();
+ window.removeEventListener('resize', resize);
+ };
+ }, [statData]);
+
+ useEffect(() => {
+ fetchStat();
}, []);
return (
-
- {/* 顶部统计卡片 保留你原来的图标样式 */}
-
-
-
-
-
-
+
+
+
+
+
+
+
-
今日告警
-
12
+
告警总数
+
{statData.total || 0}
-
-
-
-
+
+
+
+
+
-
本周告警
-
45
+
严重告警
+
{statData.levelStats?.[1] || 0}
-
-
-
-
+
+
+
+
+
-
本月告警
-
128
+
待处理
+
{statData.pending || 0}
+
+
+
+
+
+
+
+
+
+
+
已关闭
+
{statData.closed || 0}
-
+
- {/* 两个图表 左右各一半 并排显示 不空洞 */}
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+