Files
web-Iot/src/components/alerts/AlarmOverview.tsx

1073 lines
31 KiB
TypeScript
Raw Normal View History

import React, { useState, useEffect } from 'react';
2026-05-07 17:09:19 +08:00
import {
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
2026-05-18 09:35:44 +08:00
Typography, message, Pagination, Spin, Drawer, Descriptions, Switch, Form, Modal
2026-05-07 17:09:19 +08:00
} from 'antd';
import {
2026-05-11 14:59:36 +08:00
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined,
2026-05-18 14:28:42 +08:00
SearchOutlined, ReloadOutlined, FileTextOutlined, NotificationOutlined,
EyeOutlined,
2026-07-13 16:25:44 +08:00
EditOutlined,
ExclamationOutlined
2026-05-07 17:09:19 +08:00
} from '@ant-design/icons';
import dayjs from 'dayjs';
2026-07-24 19:35:56 +08:00
import { alarmHandleResultOptions, errorLevelOptions, exportTable, levelColorMap } from "../../lib/utils.js"
// 接口引入
import {
getAlarmList,
getAlarmDetail,
getAlarmStatistics,
handleAlarm,
2026-05-18 09:35:44 +08:00
exportAlarm,
updateAlarm
} from '../../api/alarmApi.js';
2026-05-14 15:15:50 +08:00
import { UniversalBarChart, UniversalLineChart, UniversalPieChart } from '../recharts.jsx';
2026-05-15 15:39:28 +08:00
import { addWorkOrder } from '@/api/workOrder.js';
2026-05-18 09:35:44 +08:00
import { alarmLevelConfig, alarmTypeMap, handleStatusMap } from '../../constants.js';
2026-07-13 16:25:44 +08:00
import { useSelector } from 'react-redux';
import { RootState } from '@/src/store/index.js';
2026-05-07 14:13:26 +08:00
2026-05-07 17:09:19 +08:00
const { RangePicker } = DatePicker;
2026-05-13 09:06:50 +08:00
const { Text } = Typography;
2026-05-13 11:12:17 +08:00
const { Option } = Select;
2026-07-13 16:25:44 +08:00
// 快速根据 value 获取 label
const getLevelLabel = (val) => {
const item = errorLevelOptions.find(opt => opt.value === val);
return item?.label || '未知';
};
/**
* 通用告警级别标签组件
* @param level 接口返回字符串 INFO / WARNING / ERROR
* @param size small表格 | large详情弹窗
*/
const AlarmLevelTag = ({ level, size = 'small' }) => {
const color = levelColorMap[level] || '#86909C';
const text = getLevelLabel(level);
// 详情大标签
if (size === 'large') {
return (
<Tag
color={color}
style={{
border: 'none',
color: '#fff',
padding: '4px 10px',
fontSize: 14,
borderRadius: 4,
display: 'inline-flex',
alignItems: 'center',
gap: 6
}}
>
{text}
</Tag>
);
}
// 表格小标签
return (
<Tag
color={color}
style={{
border: 'none',
color: '#fff',
padding: '2px 6px',
fontSize: 12,
borderRadius: 2,
display: 'inline-flex',
alignItems: 'center',
gap: 4
}}
>
{text}
</Tag>
);
};
export default function AlarmCenterPage() {
2026-05-13 11:12:17 +08:00
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const [detailLoading, setDetailLoading] = useState(false);
2026-05-07 17:09:19 +08:00
// 列表
const [alarmList, setAlarmList] = useState([]);
const [total, setTotal] = useState(0);
const [pageNum, setPageNum] = useState(1);
const [pageSize] = useState(10);
2026-05-15 15:39:28 +08:00
const [messageApi, contextHolder] = message.useMessage();
2026-05-18 10:17:05 +08:00
const [todayData, setTodayData] = useState({});
const [yesterdayData, setYesterdayData] = useState({});
2026-08-04 16:33:52 +08:00
const { stationId, currentStation } = useSelector((state: RootState) => state.station);
2026-07-13 16:25:44 +08:00
const { userInfo } = useSelector((state: RootState) => state.user);
2026-05-15 15:39:28 +08:00
2026-05-18 09:35:44 +08:00
const [editModalVisible, setEditModalVisible] = useState(false);
const [editForm] = Form.useForm();
// ========== 新增:工单弹窗状态 & 表单 ==========
const [createOrderModalVisible, setCreateOrderModalVisible] = useState(false);
const [orderForm] = Form.useForm();
2026-07-24 19:35:56 +08:00
// 图表使用:满足筛选条件的【全部告警明细】,不受分页限制
const [allAlarmForChart, setAllAlarmForChart] = useState([]);
2026-05-07 17:09:19 +08:00
// 查询条件
const [queryParams, setQueryParams] = useState({
2026-07-24 19:35:56 +08:00
siteId: stationId,
deviceId: '',
alarmLevel: '',
2026-07-20 13:56:10 +08:00
alarmType: '',
2026-07-24 19:35:56 +08:00
handleStatus: 1,
startTime: '',
endTime: '',
});
2026-05-09 16:44:39 +08:00
2026-05-13 09:06:50 +08:00
// 抽屉
const [drawerVisible, setDrawerVisible] = useState(false);
const [currentAlarm, setCurrentAlarm] = useState(null);
2026-05-13 09:06:50 +08:00
// 统计
const [statData, setStatData] = useState({
total: 0,
levelStats: {},
pending: 0,
processing: 0,
closed: 0,
});
// ====================== 获取列表 ======================
const fetchList = async () => {
setLoading(true);
try {
2026-07-13 16:25:44 +08:00
const res = await getAlarmList({ pageNum, pageSize, ...queryParams, siteId: stationId });
if (res.code === 200) {
setAlarmList(res.rows || []);
setTotal(res.total || 0);
}
} catch (err) {
2026-05-15 15:39:28 +08:00
messageApi.error('加载失败');
} finally {
setLoading(false);
}
};
2026-07-24 19:35:56 +08:00
// 获取【全部满足筛选条件告警明细】,专门给趋势图使用,不分页
const fetchChartAllAlarm = async () => {
try {
// pageSize 给超大值,拉取当前筛选条件下所有告警
const res = await getAlarmList({
pageNum: 1,
pageSize: 99999,
...queryParams,
siteId: stationId,
handleStatus: queryParams.handleStatus
});
if (res.code === 200) {
setAllAlarmForChart(res.rows || []);
}
} catch (err) {
console.error('加载图表告警数据失败', err);
}
};
2026-05-18 09:58:36 +08:00
// ====================== 获取统计(带上查询条件) ======================
const fetchStat = async () => {
try {
2026-05-18 09:58:36 +08:00
// 把查询条件一起传给统计接口
2026-07-24 19:35:56 +08:00
const res = await getAlarmStatistics({ ...queryParams, handleStatus: "", siteId: stationId });
if (res.code === 200) {
setStatData(res.data || {});
}
} catch (err) { }
};
// ====================== 查看详情 ======================
const showDetail = async (id) => {
setDetailLoading(true);
try {
const res = await getAlarmDetail(id);
2026-05-13 09:06:50 +08:00
if (res.code === 0 || res.code === 200) {
setCurrentAlarm(res.data);
2026-05-13 11:12:17 +08:00
// 表单赋值
form.setFieldsValue({
handleStatus: res.data.handleStatus,
handleRemark: '已处理'
});
2026-05-13 09:06:50 +08:00
setDrawerVisible(true);
}
} catch (err) {
2026-05-15 15:39:28 +08:00
messageApi.error('加载详情失败');
} finally {
setDetailLoading(false);
}
};
// ====================== 处理告警 ======================
2026-05-13 11:12:17 +08:00
const doHandle = async (values) => {
try {
2026-05-13 11:12:17 +08:00
await handleAlarm({
2026-07-20 13:56:10 +08:00
alarmId: currentAlarm.id,
2026-05-13 11:12:17 +08:00
handleStatus: values.handleStatus,
2026-07-24 19:35:56 +08:00
handleResult: values.handleResult,
handleRemark: values.handleRemark || '已处理',
rootCause: values.rootCause || '无'
2026-05-13 11:12:17 +08:00
});
2026-05-15 15:39:28 +08:00
messageApi.success('处理成功');
2026-05-13 09:06:50 +08:00
setDrawerVisible(false);
fetchList();
fetchStat();
} catch (err) {
2026-05-15 15:39:28 +08:00
messageApi.error('处理失败');
}
};
2026-05-07 17:09:19 +08:00
// ====================== 导出 ======================
const doExport = () => {
2026-05-13 11:12:17 +08:00
//exportTable(columns, alarmList, "告警记录")
exportAlarm(queryParams).then(res => {
const blob = new Blob([res], { type: 'application/vnd.ms-excel' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `告警记录_${dayjs().format('YYYYMMDDHHmmss')}.xlsx`;
a.click();
URL.revokeObjectURL(url);
});
};
2026-05-18 09:35:44 +08:00
// 打开修改告警弹窗
const openEditModal = (record) => {
editForm.setFieldsValue({
id: record.id,
alarmTitle: record.alarmTitle,
alarmContent: record.alarmContent,
alarmLevel: record.alarmLevel,
alarmType: record.alarmType,
});
setEditModalVisible(true);
};
// 提交修改告警
const handleUpdateAlarm = async (values) => {
try {
await updateAlarm(values);
messageApi.success('修改成功');
setEditModalVisible(false);
fetchList(); // 刷新列表
fetchStat(); // 刷新统计
} catch (err) {
messageApi.error('修改失败');
console.error(err);
}
};
// 加载
useEffect(() => {
fetchList();
2026-05-18 10:17:05 +08:00
2026-07-13 16:25:44 +08:00
}, [pageNum, stationId]);
2026-05-18 10:17:05 +08:00
useEffect(() => {
fetchTodayAndYesterdayStat();
fetchStat();
2026-07-24 19:35:56 +08:00
fetchChartAllAlarm();
2026-05-18 10:17:05 +08:00
2026-07-24 19:35:56 +08:00
}, [stationId]);
// ====================== 表格列 ======================
2026-05-07 17:09:19 +08:00
const columns = [
2026-05-11 14:59:36 +08:00
{
title: '告警编号',
2026-05-13 09:06:50 +08:00
dataIndex: 'alarmNo',
render: (text) => <Text style={{ color: '#165DFF', fontWeight: 500 }}>{text}</Text>
},
{
title: '告警标题',
dataIndex: 'alarmTitle',
ellipsis: true,
width: 180
},
{
title: '告警内容',
dataIndex: 'alarmContent',
ellipsis: true
},
2026-07-27 17:08:10 +08:00
{
title: '上报值',
dataIndex: 'time_values',
ellipsis: true
},
2026-05-13 09:06:50 +08:00
{
title: '设备名称',
dataIndex: 'deviceName',
2026-07-13 16:25:44 +08:00
width: 280
2026-05-11 14:59:36 +08:00
},
2026-05-13 09:28:34 +08:00
{
title: '告警类型',
dataIndex: 'alarmType',
width: 120,
render: (t) => alarmTypeMap[t] || '-'
},
2026-05-11 14:59:36 +08:00
{
title: '告警级别',
dataIndex: 'alarmLevel',
2026-05-11 14:59:36 +08:00
width: 100,
2026-07-13 16:25:44 +08:00
render: (l) => <AlarmLevelTag level={l} size="small" />
2026-05-11 14:59:36 +08:00
},
2026-05-13 09:06:50 +08:00
{
title: '告警时间',
dataIndex: 'alarmTime',
width: 180,
render: (t) => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
},
2026-05-11 14:59:36 +08:00
{
title: '处理状态',
dataIndex: 'handleStatus',
2026-05-13 09:06:50 +08:00
width: 110,
2026-05-13 09:28:34 +08:00
render: (s) => {
let color = 'default';
const text = handleStatusMap[s] || '-';
switch (s) {
case 1: color = 'orange'; break; // 待处理
2026-07-24 19:35:56 +08:00
case 2: color = 'green'; break; // 已关闭
2026-05-13 09:28:34 +08:00
default: break;
}
return <Tag color={color}>{text}</Tag>;
}
2026-05-11 14:59:36 +08:00
},
2026-05-07 17:09:19 +08:00
{
2026-05-11 14:59:36 +08:00
title: '操作',
2026-05-13 09:06:50 +08:00
width: 100,
fixed: 'right',
2026-05-07 17:09:19 +08:00
render: (_, record) => (
2026-05-18 09:35:44 +08:00
<Space>
2026-05-18 14:28:42 +08:00
<Button
type="link"
icon={<EyeOutlined />}
onClick={() => showDetail(record.id)}
>
查看
</Button>
<Button
type="link"
icon={<EditOutlined />}
onClick={() => openEditModal(record)}
>
修改
</Button>
2026-05-18 09:35:44 +08:00
</Space>
2026-05-07 17:09:19 +08:00
)
}
];
2026-05-18 09:53:17 +08:00
// 按日期+告警级别分组统计趋势数据
2026-07-24 19:35:56 +08:00
// 按日期+告警级别分组统计趋势数据(使用全量告警,不受分页影响)
2026-05-18 09:53:17 +08:00
const getAlarmTrendData = () => {
2026-07-24 19:35:56 +08:00
if (!allAlarmForChart.length) return [];
2026-05-18 09:53:17 +08:00
const groupMap = {};
2026-07-24 19:35:56 +08:00
allAlarmForChart.forEach(item => {
2026-05-18 09:53:17 +08:00
if (!item.alarmTime || !item.alarmLevel) return;
const day = dayjs(item.alarmTime).format('MM-DD');
const level = String(item.alarmLevel);
2026-07-20 13:56:10 +08:00
if (!groupMap[day]) groupMap[day] = { ERROR: 0, WARNING: 0, INFO: 0 };
2026-05-18 09:53:17 +08:00
groupMap[day][level] = (groupMap[day][level] || 0) + 1;
});
return Object.entries(groupMap).map(([date, obj]) => ({
date,
2026-07-20 13:56:10 +08:00
ERROR: obj.ERROR || 0,
WARNING: obj.WARNING || 0,
INFO: obj.INFO || 0,
2026-05-18 09:53:17 +08:00
}));
};
2026-05-07 14:13:26 +08:00
2026-07-24 19:35:56 +08:00
2026-05-14 15:15:50 +08:00
const pieData = [
{
2026-07-14 17:32:31 +08:00
name: '错误',
value: statData.levelStats?.["ERROR"] || 0,
2026-05-14 15:15:50 +08:00
color: '#FF4D4F',
},
{
2026-07-14 17:32:31 +08:00
name: '警告',
value: statData.levelStats?.['WARNING'] || 0,
2026-05-14 15:15:50 +08:00
color: '#FA8C16',
},
{
2026-07-14 17:32:31 +08:00
name: '信息',
value: statData.levelStats?.['INFO'] || 0,
2026-05-14 15:15:50 +08:00
color: '#FADB14',
},
2026-07-14 17:32:31 +08:00
2026-05-14 15:15:50 +08:00
].filter(i => i.value > 0);
2026-05-18 10:17:05 +08:00
const fetchTodayAndYesterdayStat = async () => {
const today = dayjs().format('YYYY-MM-DD');
const yesterday = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
// 请求今日
const todayRes = await getAlarmStatistics({
startTime: `${today} 00:00:00`,
endTime: `${today} 23:59:59`,
2026-07-24 19:35:56 +08:00
siteId: stationId,
2026-05-18 10:17:05 +08:00
});
if (todayRes.code === 200) {
setTodayData(todayRes.data || {});
}
// 请求昨日
const yesterdayRes = await getAlarmStatistics({
startTime: `${yesterday} 00:00:00`,
endTime: `${yesterday} 23:59:59`,
2026-07-24 19:35:56 +08:00
siteId: stationId,
2026-05-18 10:17:05 +08:00
});
if (yesterdayRes.code === 200) {
const yData = yesterdayRes.data || {};
setYesterdayData({
total: yData.total || 0,
critical: yData.levelStats?.[1] || 0,
processing: yData.processing || 0,
closed: yData.closed || 0,
});
}
};
2026-07-20 13:56:10 +08:00
// 联系负责人
const handleContactUser = () => {
// 自行实现:弹窗联系人列表、拨打电话、跳转聊天、弹窗信息等
console.log('联系负责人', currentAlarm);
};
// 派发工单
const handleDispatchOrder = () => {
// 自行实现:选择处理人、分配工单接口、弹窗派发表单
console.log('派发工单', currentAlarm);
};
// ========== 修改:点击生成工单只打开弹窗,不直接请求接口 ==========
const handleaddOrder = () => {
2026-05-15 15:39:28 +08:00
if (!currentAlarm) {
messageApi.warning('无告警信息,无法生成工单');
return;
}
// 预填充表单
orderForm.setFieldsValue({
orderTitle: currentAlarm.alarmTitle || '告警生成工单',
planStartTime: null
});
setCreateOrderModalVisible(true);
};
2026-05-15 15:39:28 +08:00
// ========== 新增:弹窗提交工单函数 ==========
const submitCreateOrder = async (values) => {
2026-05-15 15:39:28 +08:00
try {
const params = {
id: '',
orderNo: '',
orderTitle: values.orderTitle,
2026-05-15 15:39:28 +08:00
sourceType: 7, // 来源 7=告警
orderType: 5, // 类型 5=运维
priorityLevel: currentAlarm.alarmLevel === 'ERROR' ? 1 : 2, // 修复:等级是字符串,不是数字1
2026-05-15 15:39:28 +08:00
deviceId: currentAlarm.deviceId || '',
deviceName: currentAlarm.deviceName || '',
deviceType: currentAlarm.deviceType,
2026-07-13 16:25:44 +08:00
siteId: stationId,
2026-08-04 16:33:52 +08:00
orgId: currentStation?.orgId || '',
2026-05-15 15:39:28 +08:00
assigneeId: '',
assigneeName: '',
collaboratorIds: '',
collaboratorNames: '',
planStartTime: values.planStartTime ? dayjs(values.planStartTime).format('YYYY-MM-DD HH:mm:ss') : '',
2026-05-15 15:39:28 +08:00
planEndTime: '',
deadlineTime: '',
actualStartTime: '',
actualEndTime: '',
orderStatus: 1, // 1-待处理
alarmId: currentAlarm.id || '',
alarmNo: currentAlarm.alarmNo || '',
taskDescription: values.taskDescription,
aiSuggestion: currentAlarm.rootCause || '',
2026-05-15 15:39:28 +08:00
requiredEquipment: '',
estimatedImpact: '',
handleResult: '',
handleRemark: ''
};
2026-05-09 16:44:39 +08:00
2026-05-15 15:39:28 +08:00
const res = await addWorkOrder(params);
if (res.code === 0 || res.code === 200) {
messageApi.success('工单生成成功');
setCreateOrderModalVisible(false);
orderForm.resetFields();
2026-05-15 15:39:28 +08:00
} else {
messageApi.error(res.msg || '工单生成失败');
}
} catch (error) {
messageApi.error('接口调用失败');
console.error(error);
}
};
2026-05-07 14:13:26 +08:00
return (
2026-05-15 15:39:28 +08:00
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0' }}>
{contextHolder}
2026-05-13 09:06:50 +08:00
{/* 统计卡片 */}
2026-05-14 17:23:12 +08:00
<Row gutter={[8, 8]} style={{ marginBottom: 8, flexWrap: 'wrap' }}>
2026-05-14 10:47:56 +08:00
{[
{
title: '今日告警总数',
2026-05-18 10:17:05 +08:00
value: todayData.total || 0,
trend: (() => {
const now = todayData.total ?? 0;
const last = yesterdayData.total ?? 0;
2026-05-18 12:55:41 +08:00
if (last === 0) return '较昨日 无变化';
2026-05-18 10:17:05 +08:00
const rateNum = ((now - last) / last) * 100;
const rateStr = rateNum.toFixed(1);
return rateNum > 0 ? `较昨日 +${rateStr}% ↑` : rateNum < 0 ? `较昨日 ${rateStr}% ↓` : '较昨日 0%';
})(),
trendColor: (() => {
const now = todayData.total ?? 0;
const last = yesterdayData.total ?? 0;
if (last === 0) return '#86909C';
const rateNum = ((now - last) / last) * 100;
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
})(),
subText: `昨日 ${yesterdayData.total || 0}`,
2026-05-14 10:47:56 +08:00
icon: <BellOutlined />,
color: '#FF4D4F',
bg: '#FFF1F0'
},
{
2026-07-24 19:35:56 +08:00
title: '今日严重告警',
value: todayData.levelStats?.["ERROR"] || 0,
2026-05-18 10:17:05 +08:00
trend: (() => {
2026-07-14 17:32:31 +08:00
const now = todayData.levelStats?.["ERROR"] ?? 0;
const last = yesterdayData.levelStats?.["ERROR"] ?? 0;
2026-05-18 12:55:41 +08:00
if (last === 0) return '较昨日 无变化';
2026-05-18 10:17:05 +08:00
const rateNum = ((now - last) / last) * 100;
const rateStr = rateNum.toFixed(1);
return rateNum > 0 ? `较昨日 +${rateStr}% ↑` : rateNum < 0 ? `较昨日 ${rateStr}% ↓` : '较昨日 0%';
})(),
trendColor: (() => {
2026-07-14 17:32:31 +08:00
const now = todayData.levelStats?.["ERROR"] ?? 0;
const last = yesterdayData.levelStats?.["ERROR"] ?? 0;
2026-05-18 10:17:05 +08:00
if (last === 0) return '#86909C';
const rateNum = ((now - last) / last) * 100;
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
})(),
2026-07-14 17:32:31 +08:00
subText: `昨日 ${yesterdayData.levelStats?.["ERROR"] || 0}`,
2026-05-14 10:47:56 +08:00
icon: <ExclamationCircleOutlined />,
color: '#FF4D4F',
bg: '#FFF1F0'
},
{
2026-07-24 19:35:56 +08:00
title: '今日待处理',
value: todayData.pending || 0,
2026-05-18 10:17:05 +08:00
trend: (() => {
2026-07-24 19:35:56 +08:00
const now = todayData.pending ?? 0;
const last = yesterdayData.pending ?? 0;
2026-05-18 12:55:41 +08:00
if (last === 0) return '较昨日 无变化';
2026-05-18 10:17:05 +08:00
const rateNum = ((now - last) / last) * 100;
const rateStr = rateNum.toFixed(1);
return rateNum > 0 ? `较昨日 +${rateStr}% ↑` : rateNum < 0 ? `较昨日 ${rateStr}% ↓` : '较昨日 0%';
})(),
trendColor: (() => {
2026-07-24 19:35:56 +08:00
const now = todayData.pending ?? 0;
const last = yesterdayData.pending ?? 0;
2026-05-18 10:17:05 +08:00
if (last === 0) return '#86909C';
const rateNum = ((now - last) / last) * 100;
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
})(),
2026-07-24 19:35:56 +08:00
subText: `昨日 ${yesterdayData.pending || 0}`,
2026-05-14 10:47:56 +08:00
icon: <ClockCircleOutlined />,
color: '#FA8C16',
bg: '#FFF7E8'
},
{
2026-07-24 19:35:56 +08:00
title: '今日已关闭',
2026-05-18 10:17:05 +08:00
value: todayData.closed || 0,
trend: (() => {
const now = todayData.closed ?? 0;
const last = yesterdayData.closed ?? 0;
2026-05-18 12:55:41 +08:00
if (last === 0) return '较昨日 无变化';
2026-05-18 10:17:05 +08:00
const rateNum = ((now - last) / last) * 100;
const rateStr = rateNum.toFixed(1);
return rateNum > 0 ? `较昨日 +${rateStr}% ↑` : rateNum < 0 ? `较昨日 ${rateStr}% ↓` : '较昨日 0%';
})(),
trendColor: (() => {
const now = todayData.closed ?? 0;
const last = yesterdayData.closed ?? 0;
if (last === 0) return '#86909C';
const rateNum = ((now - last) / last) * 100;
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
})(),
subText: `昨日 ${yesterdayData.closed || 0}`,
2026-05-14 10:47:56 +08:00
icon: <CheckCircleOutlined />,
color: '#00B42A',
bg: '#E8FFEA'
},
].map((item, idx) => (
2026-05-18 10:25:18 +08:00
<Col key={idx} style={{ minWidth: '200px', flex: '1 1 auto', maxWidth: "400px" }}>
2026-05-14 10:47:56 +08:00
<Card
bordered={false}
bodyStyle={{ padding: '16px 20px' }}
style={{ borderRadius: 8, height: 120 }}
>
<Row align="middle" gutter={16} style={{ height: '100%' }}>
<Col>
<div style={{
width: 48,
height: 48,
background: item.bg,
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
}}>
{React.cloneElement(item.icon, { style: { fontSize: 24, color: item.color } })}
</div>
</Col>
<Col style={{ flex: 1, overflow: 'hidden' }}>
<div style={{ fontSize: 14, color: '#4E5969', marginBottom: 4 }}>{item.title}</div>
<div style={{ fontSize: 28, fontWeight: 700, color: item.color, lineHeight: '36px' }}>
{item.value}
</div>
<div style={{ fontSize: 12, marginTop: 4 }}>
<span style={{ color: '#86909C' }}>{item.trend.split(' ')[0]}</span>
<span style={{ color: item.trendColor, fontWeight: 600, marginLeft: 4 }}>
{item.trend.split(' ').slice(1).join(' ')}
</span>
</div>
<div style={{ fontSize: 12, color: '#86909C', marginTop: 2 }}>
{item.subText}
</div>
</Col>
</Row>
</Card>
</Col>
))}
2026-05-13 09:06:50 +08:00
</Row>
2026-05-18 09:53:17 +08:00
<Row gutter={8} style={{ marginBottom: 8 }}>
<Col span={24}>
<Card bordered={false} bodyStyle={{ padding: '16px 24px' }} style={{ borderRadius: 8 }}>
2026-07-14 17:32:31 +08:00
<Row gutter={[8, 8]} align="middle">
2026-05-18 09:53:17 +08:00
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>告警级别</div>
<Select
style={{ width: 120 }}
value={queryParams.alarmLevel}
2026-07-14 17:32:31 +08:00
allowClear onChange={v => setQueryParams({ ...queryParams, alarmLevel: v })}
options={errorLevelOptions}
2026-05-18 09:53:17 +08:00
/>
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>处理状态</div>
<Select
style={{ width: 120 }}
value={queryParams.handleStatus}
2026-07-14 17:32:31 +08:00
allowClear
2026-05-18 09:53:17 +08:00
onChange={v => setQueryParams({ ...queryParams, handleStatus: v })}
options={[
{ value: 1, label: '待处理' },
2026-07-24 19:35:56 +08:00
{ value: 2, label: '已关闭' },
2026-05-18 09:53:17 +08:00
]}
/>
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>设备ID</div>
<Input
placeholder="设备ID"
value={queryParams.deviceId}
onChange={e => setQueryParams({ ...queryParams, deviceId: e.target.value })}
2026-07-14 17:32:31 +08:00
style={{ width: 280 }}
allowClear
onBlur={(e) => {
const trimVal = e.target.value.trim(); // 只清除首尾空格
setQueryParams({ ...queryParams, deviceId: trimVal });
}}
2026-05-18 09:53:17 +08:00
/>
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>时间范围</div>
<RangePicker
showTime
style={{ width: 320 }}
onChange={arr => {
if (arr) {
setQueryParams({
...queryParams,
startTime: arr[0].format('YYYY-MM-DD HH:mm:ss'),
endTime: arr[1].format('YYYY-MM-DD HH:mm:ss')
});
2026-07-14 17:32:31 +08:00
} else {
// 点击清空按钮 / 无选择,清空时间参数
setQueryParams({
...queryParams,
startTime: '',
endTime: ''
});
2026-05-18 09:53:17 +08:00
}
}}
/>
</Col>
<Col style={{ alignSelf: 'flex-end' }}>
<Space>
<Button style={{ borderRadius: 8 }} onClick={() => {
2026-07-24 19:35:56 +08:00
setQueryParams({ ...queryParams, deviceId: '', alarmLevel: '', handleStatus: 1, startTime: '', endTime: '' });
2026-05-18 09:53:17 +08:00
fetchList();
2026-05-18 09:58:36 +08:00
fetchStat();
2026-07-24 19:35:56 +08:00
fetchChartAllAlarm(); // 新增:刷新图表全量告警
2026-05-18 09:53:17 +08:00
}}>重置</Button>
2026-05-18 09:58:36 +08:00
<Button type="primary" style={{ borderRadius: 8, background: '#165DFF' }} onClick={() => {
fetchList(); // 刷新列表
fetchStat(); // 刷新统计
2026-07-24 19:35:56 +08:00
fetchChartAllAlarm(); // 新增:刷新图表全量告警
2026-05-18 09:58:36 +08:00
}}>
2026-05-18 09:53:17 +08:00
<SearchOutlined />查询
</Button>
<Button style={{ borderRadius: 8 }} onClick={doExport}>
<FileTextOutlined />导出
</Button>
</Space>
</Col>
</Row>
</Card>
</Col>
</Row>
2026-05-13 09:06:50 +08:00
{/* 表格 */}
2026-05-14 17:23:12 +08:00
<Row gutter={16} style={{ marginBottom: 8 }}>
2026-05-13 09:06:50 +08:00
<Col flex="auto" style={{ minWidth: 0 }}>
<Card bordered={false} bodyStyle={{ padding: '16px 24px' }} style={{ borderRadius: 8 }}>
<Spin spinning={loading}>
<Table
rowKey="id"
columns={columns}
dataSource={alarmList}
pagination={false}
size="middle"
scroll={{ x: 'max-content' }}
/>
</Spin>
<div style={{ display: 'flex', justifyContent: 'center', marginTop: 16 }}>
<Pagination
current={pageNum}
pageSize={10}
total={total}
onChange={(p) => setPageNum(p)}
showSizeChanger={false} showQuickJumper size="small"
/>
</div>
</Card>
</Col>
</Row>
{/* 三个图表 */}
<Row gutter={16}>
<Col span={8}>
<Card bordered={false} title="告警趋势" style={{ borderRadius: 8 }}>
2026-05-14 15:15:50 +08:00
<UniversalLineChart
2026-05-18 09:53:17 +08:00
data={getAlarmTrendData()}
2026-05-14 15:15:50 +08:00
xKey="date"
2026-05-13 09:06:50 +08:00
height={220}
2026-05-14 15:15:50 +08:00
smooth
dot
backgroundColor="transparent"
series={[
{
2026-07-14 17:32:31 +08:00
key: 'ERROR',
name: '错误',
2026-05-14 15:15:50 +08:00
color: '#FF4D4F',
2026-05-18 09:53:17 +08:00
strokeWidth: 2,
2026-05-14 15:15:50 +08:00
},
{
2026-07-14 17:32:31 +08:00
key: 'WARNING',
name: '警告',
2026-05-14 15:15:50 +08:00
color: '#FA8C16',
strokeWidth: 2,
},
2026-05-18 09:53:17 +08:00
{
2026-07-14 17:32:31 +08:00
key: 'INFO',
name: '信息',
2026-05-18 09:53:17 +08:00
color: '#FADB14',
strokeWidth: 2,
},
2026-07-14 17:32:31 +08:00
2026-05-14 15:15:50 +08:00
]}
2026-05-13 09:06:50 +08:00
/>
</Card>
</Col>
<Col span={8}>
<Card bordered={false} title="告警分类占比" style={{ borderRadius: 8 }}>
2026-05-14 15:15:50 +08:00
<UniversalPieChart
data={pieData}
height={220}
innerRadius={45}
outerRadius={80}
backgroundColor="transparent"
/>
</Card>
2026-05-13 09:06:50 +08:00
</Col>
<Col span={8}>
<Card bordered={false} title="告警状态统计" style={{ borderRadius: 8 }}>
2026-05-14 15:15:50 +08:00
<UniversalBarChart
2026-05-13 09:06:50 +08:00
data={[
2026-05-14 15:15:50 +08:00
{
name: '待处理',
pending: statData.pending || 0,
},
2026-07-24 19:35:56 +08:00
2026-05-14 15:15:50 +08:00
{
name: '已关闭',
pending: statData.closed || 0,
},
2026-05-13 09:06:50 +08:00
]}
2026-05-14 15:15:50 +08:00
xKey="name"
2026-05-13 09:06:50 +08:00
height={220}
2026-05-14 15:15:50 +08:00
backgroundColor="transparent"
barSize={36}
radius={[6, 6, 0, 0]}
series={[
{
key: 'pending',
name: '数量',
color: '#165DFF',
},
]}
2026-05-13 09:06:50 +08:00
/>
</Card>
</Col>
</Row>
2026-05-13 09:28:34 +08:00
{/* 告警详情抽屉 */}
2026-05-13 09:06:50 +08:00
<Drawer
title="告警详情"
open={drawerVisible}
onClose={() => setDrawerVisible(false)}
2026-07-13 16:25:44 +08:00
width={480}
2026-05-13 09:06:50 +08:00
destroyOnClose
>
2026-07-20 13:56:10 +08:00
2026-05-13 09:06:50 +08:00
<Spin spinning={detailLoading}>
2026-07-20 13:56:10 +08:00
2026-05-13 09:06:50 +08:00
{currentAlarm && (
2026-05-13 11:12:17 +08:00
<Form form={form} onFinish={doHandle} layout="vertical">
<>
{/* 告警头部 */}
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 16 }}>
<div style={{ width: 40, height: 40, background: '#FFF1F0', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center', marginRight: 12 }}>
<ExclamationCircleOutlined style={{ fontSize: 20, color: '#FF4D4F' }} />
</div>
<div style={{ flex: 1 }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<span style={{ fontSize: 16, fontWeight: 700 }}>{currentAlarm.alarmTitle}</span>
2026-07-13 16:25:44 +08:00
2026-05-13 11:12:17 +08:00
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>告警编号:{currentAlarm.alarmNo}</div>
2026-05-13 09:06:50 +08:00
</div>
</div>
2026-05-13 11:12:17 +08:00
{/* 告警基础信息 */}
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
<Descriptions.Item label="来源设备">{currentAlarm.deviceName || '-'}</Descriptions.Item>
<Descriptions.Item label="告警类型">{alarmTypeMap[currentAlarm.alarmType] || '-'}</Descriptions.Item>
<Descriptions.Item label="发生时间">{dayjs(currentAlarm.alarmTime).format('YYYY-MM-DD HH:mm:ss')}</Descriptions.Item>
<Descriptions.Item label="处理状态">
{(() => {
let color = 'default';
const status = currentAlarm.handleStatus;
// 1:待处理 2:处理中 3:已关闭 4:已忽略
switch (status) {
case 1: color = 'orange'; break;
case 2: color = 'blue'; break;
case 3: color = 'green'; break;
case 4: color = 'default'; break;
default: break;
}
return <Tag color={color}>{handleStatusMap[status] || '-'}</Tag>;
})()}
</Descriptions.Item>
</Descriptions>
{/* 告警描述 */}
<Card size="small" title="告警描述" style={{ marginBottom: 16 }}>
<div style={{ color: '#333' }}>{currentAlarm.alarmContent || '-'}</div>
</Card>
{/* 根因分析 */}
{/* 推荐处理措施 */}
<Card size="small" title="推荐处理措施" style={{ marginBottom: 16 }}>
<div style={{ color: '#333' }}>{currentAlarm.handleSuggestion || '-'}</div>
2026-05-15 15:39:28 +08:00
<div className="flex justify-between">
<div>
</div>
2026-07-20 13:56:10 +08:00
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 12 }}>
<Button type="default" onClick={handleContactUser}>联系负责人</Button>
<Button type="primary" onClick={handleaddOrder}>
生成工单
</Button>
</div>
2026-05-15 15:39:28 +08:00
</div>
2026-05-13 11:12:17 +08:00
</Card>
2026-07-20 13:56:10 +08:00
{/* 处理操作 */}
<Card size="small" title="处理操作" style={{ marginBottom: 16 }}>
<Form.Item label="处理状态" name="handleStatus" rules={[{ required: true, message: '请选择处理状态' }]}>
<Select>
<Option value={1}>待处理</Option>
2026-07-24 19:35:56 +08:00
<Option value={2}>已关闭</Option>
2026-07-20 13:56:10 +08:00
</Select>
</Form.Item>
2026-07-24 19:35:56 +08:00
<Form.Item label="处理结果" name="handleResult" rules={[{ required: true, message: '请选择确认处理结果' }]}>
<Select
placeholder="请选择确认处理结果"
options={alarmHandleResultOptions}
/>
</Form.Item>
<Form.Item label="根因分析" name="rootCause">
<Input.TextArea rows={2} placeholder="请输入处理备注" />
</Form.Item>
2026-07-20 13:56:10 +08:00
<Form.Item label="处理备注" name="handleRemark">
<Input.TextArea rows={2} placeholder="请输入处理备注" />
</Form.Item>
2026-07-20 13:56:10 +08:00
</Card>
{/* 底部按钮 */}
<Button type="primary" block htmlType="submit">确认处理</Button>
2026-05-13 11:12:17 +08:00
</>
</Form>
2026-05-13 09:06:50 +08:00
)}
</Spin>
</Drawer>
2026-05-18 09:35:44 +08:00
{/* ====================== 修改告警弹窗 ====================== */}
<Modal
title="修改告警"
open={editModalVisible}
onCancel={() => setEditModalVisible(false)}
footer={null}
width={520}
destroyOnClose
>
<Form
form={editForm}
layout="vertical"
onFinish={handleUpdateAlarm}
>
<Form.Item name="id" hidden>
<Input />
</Form.Item>
<Form.Item
label="告警标题"
name="alarmTitle"
rules={[{ required: true, message: '请输入告警标题' }]}
>
<Input placeholder="请输入告警标题" />
</Form.Item>
<Form.Item
label="告警级别"
name="alarmLevel"
rules={[{ required: true, message: '请选择告警级别' }]}
>
2026-07-13 16:25:44 +08:00
<Select options={errorLevelOptions}>
2026-05-18 09:35:44 +08:00
</Select>
</Form.Item>
<Form.Item
label="告警类型"
name="alarmType"
rules={[{ required: true, message: '请选择告警类型' }]}
>
<Select>
2026-07-20 13:56:10 +08:00
<Option value="UAV_FAULT">无人机故障</Option>
<Option value="MOWER_FAULT">割草机故障</Option>
<Option value="OTHER_DEVICE_FAULT">其他设备故障</Option>
<Option value="SERVER_FAILURE">服务器故障</Option>
<Option value="SYSTEM_ERROR">系统错误</Option>
2026-05-18 09:35:44 +08:00
</Select>
</Form.Item>
<Form.Item
label="告警内容"
name="alarmContent"
rules={[{ required: true, message: '请输入告警内容' }]}
>
<Input.TextArea rows={4} placeholder="请输入告警内容" />
</Form.Item>
<Form.Item style={{ textAlign: 'right', marginBottom: 0 }}>
<Button onClick={() => setEditModalVisible(false)}>取消</Button>
<Button type="primary" htmlType="submit" style={{ marginLeft: 8 }}>
确认修改
</Button>
</Form.Item>
</Form>
</Modal>
2026-05-11 14:59:36 +08:00
{/* ========== 新增:生成工单弹窗 ========== */}
<Modal
title="新建工单"
open={createOrderModalVisible}
onCancel={() => {
setCreateOrderModalVisible(false);
orderForm.resetFields();
}}
width={500}
maskClosable={false}
footer={null}
>
<Form
form={orderForm}
layout="vertical"
onFinish={submitCreateOrder}
>
<Form.Item
label="工单标题"
name="orderTitle"
rules={[{ required: true, message: '请输入工单标题' }]}
>
<Input placeholder="请输入工单标题" />
</Form.Item>
<Form.Item
label="计划开始时间"
name="planStartTime"
rules={[{ required: true, message: '请选择计划开始时间' }]}
>
<DatePicker
showTime
style={{ width: '100%' }}
placeholder="请选择计划开始时间"
/>
</Form.Item>
<Form.Item style={{ textAlign: 'right', marginBottom: 0 }}>
<Button onClick={() => setCreateOrderModalVisible(false)}>取消</Button>
<Button type="primary" htmlType="submit" style={{ marginLeft: 8 }}>
确认生成工单
</Button>
</Form.Item>
</Form>
</Modal>
2026-05-09 16:44:39 +08:00
</div>
2026-05-07 14:13:26 +08:00
);
2026-05-07 17:09:19 +08:00
}