1073 lines
31 KiB
TypeScript
1073 lines
31 KiB
TypeScript
import React, { useState, useEffect } from 'react';
|
||
import {
|
||
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
|
||
Typography, message, Pagination, Spin, Drawer, Descriptions, Switch, Form, Modal
|
||
} from 'antd';
|
||
import {
|
||
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined,
|
||
SearchOutlined, ReloadOutlined, FileTextOutlined, NotificationOutlined,
|
||
EyeOutlined,
|
||
EditOutlined,
|
||
ExclamationOutlined
|
||
} from '@ant-design/icons';
|
||
import dayjs from 'dayjs';
|
||
import { alarmHandleResultOptions, errorLevelOptions, exportTable, levelColorMap } from "../../lib/utils.js"
|
||
|
||
// 接口引入
|
||
import {
|
||
getAlarmList,
|
||
getAlarmDetail,
|
||
getAlarmStatistics,
|
||
handleAlarm,
|
||
exportAlarm,
|
||
updateAlarm
|
||
} from '../../api/alarmApi.js';
|
||
import { UniversalBarChart, UniversalLineChart, UniversalPieChart } from '../recharts.jsx';
|
||
import { addWorkOrder } from '@/api/workOrder.js';
|
||
import { alarmLevelConfig, alarmTypeMap, handleStatusMap } from '../../constants.js';
|
||
import { useSelector } from 'react-redux';
|
||
import { RootState } from '@/src/store/index.js';
|
||
|
||
const { RangePicker } = DatePicker;
|
||
const { Text } = Typography;
|
||
const { Option } = Select;
|
||
|
||
|
||
|
||
|
||
// 快速根据 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() {
|
||
const [form] = Form.useForm();
|
||
const [loading, setLoading] = useState(false);
|
||
const [detailLoading, setDetailLoading] = useState(false);
|
||
|
||
// 列表
|
||
const [alarmList, setAlarmList] = useState([]);
|
||
const [total, setTotal] = useState(0);
|
||
const [pageNum, setPageNum] = useState(1);
|
||
const [pageSize] = useState(10);
|
||
const [messageApi, contextHolder] = message.useMessage();
|
||
const [todayData, setTodayData] = useState({});
|
||
const [yesterdayData, setYesterdayData] = useState({});
|
||
const { stationId, currentStation } = useSelector((state: RootState) => state.station);
|
||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||
|
||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||
const [editForm] = Form.useForm();
|
||
|
||
// ========== 新增:工单弹窗状态 & 表单 ==========
|
||
const [createOrderModalVisible, setCreateOrderModalVisible] = useState(false);
|
||
const [orderForm] = Form.useForm();
|
||
// 图表使用:满足筛选条件的【全部告警明细】,不受分页限制
|
||
const [allAlarmForChart, setAllAlarmForChart] = useState([]);
|
||
|
||
|
||
// 查询条件
|
||
const [queryParams, setQueryParams] = useState({
|
||
siteId: stationId,
|
||
deviceId: '',
|
||
alarmLevel: '',
|
||
alarmType: '',
|
||
handleStatus: 1,
|
||
startTime: '',
|
||
endTime: '',
|
||
});
|
||
|
||
// 抽屉
|
||
const [drawerVisible, setDrawerVisible] = useState(false);
|
||
const [currentAlarm, setCurrentAlarm] = useState(null);
|
||
|
||
// 统计
|
||
const [statData, setStatData] = useState({
|
||
total: 0,
|
||
levelStats: {},
|
||
pending: 0,
|
||
processing: 0,
|
||
closed: 0,
|
||
});
|
||
|
||
|
||
|
||
// ====================== 获取列表 ======================
|
||
const fetchList = async () => {
|
||
setLoading(true);
|
||
try {
|
||
const res = await getAlarmList({ pageNum, pageSize, ...queryParams, siteId: stationId });
|
||
if (res.code === 200) {
|
||
setAlarmList(res.rows || []);
|
||
setTotal(res.total || 0);
|
||
}
|
||
|
||
} catch (err) {
|
||
messageApi.error('加载失败');
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
};
|
||
// 获取【全部满足筛选条件告警明细】,专门给趋势图使用,不分页
|
||
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);
|
||
}
|
||
};
|
||
|
||
// ====================== 获取统计(带上查询条件) ======================
|
||
const fetchStat = async () => {
|
||
try {
|
||
// 把查询条件一起传给统计接口
|
||
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);
|
||
if (res.code === 0 || res.code === 200) {
|
||
setCurrentAlarm(res.data);
|
||
// 表单赋值
|
||
form.setFieldsValue({
|
||
handleStatus: res.data.handleStatus,
|
||
handleRemark: '已处理'
|
||
});
|
||
setDrawerVisible(true);
|
||
}
|
||
} catch (err) {
|
||
messageApi.error('加载详情失败');
|
||
} finally {
|
||
setDetailLoading(false);
|
||
}
|
||
};
|
||
|
||
// ====================== 处理告警 ======================
|
||
const doHandle = async (values) => {
|
||
try {
|
||
await handleAlarm({
|
||
alarmId: currentAlarm.id,
|
||
handleStatus: values.handleStatus,
|
||
handleResult: values.handleResult,
|
||
handleRemark: values.handleRemark || '已处理',
|
||
rootCause: values.rootCause || '无'
|
||
});
|
||
messageApi.success('处理成功');
|
||
setDrawerVisible(false);
|
||
fetchList();
|
||
fetchStat();
|
||
} catch (err) {
|
||
messageApi.error('处理失败');
|
||
}
|
||
};
|
||
|
||
// ====================== 导出 ======================
|
||
const doExport = () => {
|
||
//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);
|
||
});
|
||
};
|
||
// 打开修改告警弹窗
|
||
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();
|
||
|
||
}, [pageNum, stationId]);
|
||
useEffect(() => {
|
||
fetchTodayAndYesterdayStat();
|
||
fetchStat();
|
||
fetchChartAllAlarm();
|
||
|
||
}, [stationId]);
|
||
|
||
// ====================== 表格列 ======================
|
||
const columns = [
|
||
{
|
||
title: '告警编号',
|
||
dataIndex: 'alarmNo',
|
||
render: (text) => <Text style={{ color: '#165DFF', fontWeight: 500 }}>{text}</Text>
|
||
},
|
||
{
|
||
title: '告警标题',
|
||
dataIndex: 'alarmTitle',
|
||
ellipsis: true,
|
||
width: 180
|
||
},
|
||
{
|
||
title: '告警内容',
|
||
dataIndex: 'alarmContent',
|
||
ellipsis: true
|
||
},
|
||
{
|
||
title: '上报值',
|
||
dataIndex: 'time_values',
|
||
ellipsis: true
|
||
},
|
||
{
|
||
title: '设备名称',
|
||
dataIndex: 'deviceName',
|
||
width: 280
|
||
},
|
||
{
|
||
title: '告警类型',
|
||
dataIndex: 'alarmType',
|
||
width: 120,
|
||
render: (t) => alarmTypeMap[t] || '-'
|
||
},
|
||
{
|
||
title: '告警级别',
|
||
dataIndex: 'alarmLevel',
|
||
width: 100,
|
||
render: (l) => <AlarmLevelTag level={l} size="small" />
|
||
|
||
},
|
||
{
|
||
title: '告警时间',
|
||
dataIndex: 'alarmTime',
|
||
width: 180,
|
||
render: (t) => t ? dayjs(t).format('YYYY-MM-DD HH:mm:ss') : '-'
|
||
},
|
||
{
|
||
title: '处理状态',
|
||
dataIndex: 'handleStatus',
|
||
width: 110,
|
||
render: (s) => {
|
||
let color = 'default';
|
||
const text = handleStatusMap[s] || '-';
|
||
switch (s) {
|
||
case 1: color = 'orange'; break; // 待处理
|
||
case 2: color = 'green'; break; // 已关闭
|
||
default: break;
|
||
}
|
||
return <Tag color={color}>{text}</Tag>;
|
||
}
|
||
},
|
||
{
|
||
title: '操作',
|
||
width: 100,
|
||
fixed: 'right',
|
||
render: (_, record) => (
|
||
<Space>
|
||
<Button
|
||
type="link"
|
||
icon={<EyeOutlined />}
|
||
onClick={() => showDetail(record.id)}
|
||
>
|
||
查看
|
||
</Button>
|
||
|
||
<Button
|
||
type="link"
|
||
icon={<EditOutlined />}
|
||
onClick={() => openEditModal(record)}
|
||
>
|
||
修改
|
||
</Button>
|
||
</Space>
|
||
|
||
)
|
||
}
|
||
];
|
||
// 按日期+告警级别分组统计趋势数据
|
||
// 按日期+告警级别分组统计趋势数据(使用全量告警,不受分页影响)
|
||
const getAlarmTrendData = () => {
|
||
if (!allAlarmForChart.length) return [];
|
||
const groupMap = {};
|
||
|
||
allAlarmForChart.forEach(item => {
|
||
if (!item.alarmTime || !item.alarmLevel) return;
|
||
const day = dayjs(item.alarmTime).format('MM-DD');
|
||
const level = String(item.alarmLevel);
|
||
|
||
if (!groupMap[day]) groupMap[day] = { ERROR: 0, WARNING: 0, INFO: 0 };
|
||
groupMap[day][level] = (groupMap[day][level] || 0) + 1;
|
||
});
|
||
|
||
return Object.entries(groupMap).map(([date, obj]) => ({
|
||
date,
|
||
ERROR: obj.ERROR || 0,
|
||
WARNING: obj.WARNING || 0,
|
||
INFO: obj.INFO || 0,
|
||
}));
|
||
};
|
||
|
||
|
||
const pieData = [
|
||
{
|
||
name: '错误',
|
||
value: statData.levelStats?.["ERROR"] || 0,
|
||
color: '#FF4D4F',
|
||
},
|
||
{
|
||
name: '警告',
|
||
value: statData.levelStats?.['WARNING'] || 0,
|
||
color: '#FA8C16',
|
||
},
|
||
{
|
||
name: '信息',
|
||
value: statData.levelStats?.['INFO'] || 0,
|
||
color: '#FADB14',
|
||
},
|
||
|
||
].filter(i => i.value > 0);
|
||
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`,
|
||
siteId: stationId,
|
||
});
|
||
if (todayRes.code === 200) {
|
||
setTodayData(todayRes.data || {});
|
||
}
|
||
|
||
// 请求昨日
|
||
const yesterdayRes = await getAlarmStatistics({
|
||
startTime: `${yesterday} 00:00:00`,
|
||
endTime: `${yesterday} 23:59:59`,
|
||
siteId: stationId,
|
||
|
||
});
|
||
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,
|
||
});
|
||
}
|
||
};
|
||
|
||
// 联系负责人
|
||
const handleContactUser = () => {
|
||
// 自行实现:弹窗联系人列表、拨打电话、跳转聊天、弹窗信息等
|
||
console.log('联系负责人', currentAlarm);
|
||
};
|
||
|
||
// 派发工单
|
||
const handleDispatchOrder = () => {
|
||
// 自行实现:选择处理人、分配工单接口、弹窗派发表单
|
||
console.log('派发工单', currentAlarm);
|
||
};
|
||
|
||
// ========== 修改:点击生成工单只打开弹窗,不直接请求接口 ==========
|
||
const handleaddOrder = () => {
|
||
if (!currentAlarm) {
|
||
messageApi.warning('无告警信息,无法生成工单');
|
||
return;
|
||
}
|
||
// 预填充表单
|
||
orderForm.setFieldsValue({
|
||
orderTitle: currentAlarm.alarmTitle || '告警生成工单',
|
||
planStartTime: null
|
||
});
|
||
setCreateOrderModalVisible(true);
|
||
};
|
||
|
||
// ========== 新增:弹窗提交工单函数 ==========
|
||
const submitCreateOrder = async (values) => {
|
||
try {
|
||
const params = {
|
||
id: '',
|
||
orderNo: '',
|
||
orderTitle: values.orderTitle,
|
||
sourceType: 7, // 来源 7=告警
|
||
orderType: 5, // 类型 5=运维
|
||
priorityLevel: currentAlarm.alarmLevel === 'ERROR' ? 1 : 2, // 修复:等级是字符串,不是数字1
|
||
deviceId: currentAlarm.deviceId || '',
|
||
deviceName: currentAlarm.deviceName || '',
|
||
deviceType: currentAlarm.deviceType,
|
||
siteId: stationId,
|
||
orgId: currentStation?.orgId || '',
|
||
assigneeId: '',
|
||
assigneeName: '',
|
||
collaboratorIds: '',
|
||
collaboratorNames: '',
|
||
planStartTime: values.planStartTime ? dayjs(values.planStartTime).format('YYYY-MM-DD HH:mm:ss') : '',
|
||
planEndTime: '',
|
||
deadlineTime: '',
|
||
actualStartTime: '',
|
||
actualEndTime: '',
|
||
orderStatus: 1, // 1-待处理
|
||
alarmId: currentAlarm.id || '',
|
||
alarmNo: currentAlarm.alarmNo || '',
|
||
taskDescription: values.taskDescription,
|
||
aiSuggestion: currentAlarm.rootCause || '',
|
||
requiredEquipment: '',
|
||
estimatedImpact: '',
|
||
handleResult: '',
|
||
handleRemark: ''
|
||
};
|
||
|
||
const res = await addWorkOrder(params);
|
||
if (res.code === 0 || res.code === 200) {
|
||
messageApi.success('工单生成成功');
|
||
setCreateOrderModalVisible(false);
|
||
orderForm.resetFields();
|
||
} else {
|
||
messageApi.error(res.msg || '工单生成失败');
|
||
}
|
||
} catch (error) {
|
||
messageApi.error('接口调用失败');
|
||
console.error(error);
|
||
}
|
||
};
|
||
|
||
return (
|
||
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0' }}>
|
||
{contextHolder}
|
||
{/* 统计卡片 */}
|
||
<Row gutter={[8, 8]} style={{ marginBottom: 8, flexWrap: 'wrap' }}>
|
||
{[
|
||
{
|
||
title: '今日告警总数',
|
||
value: todayData.total || 0,
|
||
trend: (() => {
|
||
const now = todayData.total ?? 0;
|
||
const last = yesterdayData.total ?? 0;
|
||
if (last === 0) return '较昨日 无变化';
|
||
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}`,
|
||
icon: <BellOutlined />,
|
||
color: '#FF4D4F',
|
||
bg: '#FFF1F0'
|
||
},
|
||
{
|
||
title: '今日严重告警',
|
||
value: todayData.levelStats?.["ERROR"] || 0,
|
||
trend: (() => {
|
||
const now = todayData.levelStats?.["ERROR"] ?? 0;
|
||
const last = yesterdayData.levelStats?.["ERROR"] ?? 0;
|
||
if (last === 0) return '较昨日 无变化';
|
||
const rateNum = ((now - last) / last) * 100;
|
||
const rateStr = rateNum.toFixed(1);
|
||
return rateNum > 0 ? `较昨日 +${rateStr}% ↑` : rateNum < 0 ? `较昨日 ${rateStr}% ↓` : '较昨日 0%';
|
||
})(),
|
||
trendColor: (() => {
|
||
const now = todayData.levelStats?.["ERROR"] ?? 0;
|
||
const last = yesterdayData.levelStats?.["ERROR"] ?? 0;
|
||
if (last === 0) return '#86909C';
|
||
const rateNum = ((now - last) / last) * 100;
|
||
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
|
||
})(),
|
||
subText: `昨日 ${yesterdayData.levelStats?.["ERROR"] || 0}`,
|
||
icon: <ExclamationCircleOutlined />,
|
||
color: '#FF4D4F',
|
||
bg: '#FFF1F0'
|
||
},
|
||
{
|
||
title: '今日待处理',
|
||
value: todayData.pending || 0,
|
||
trend: (() => {
|
||
const now = todayData.pending ?? 0;
|
||
const last = yesterdayData.pending ?? 0;
|
||
if (last === 0) return '较昨日 无变化';
|
||
const rateNum = ((now - last) / last) * 100;
|
||
const rateStr = rateNum.toFixed(1);
|
||
return rateNum > 0 ? `较昨日 +${rateStr}% ↑` : rateNum < 0 ? `较昨日 ${rateStr}% ↓` : '较昨日 0%';
|
||
})(),
|
||
trendColor: (() => {
|
||
const now = todayData.pending ?? 0;
|
||
const last = yesterdayData.pending ?? 0;
|
||
if (last === 0) return '#86909C';
|
||
const rateNum = ((now - last) / last) * 100;
|
||
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
|
||
})(),
|
||
subText: `昨日 ${yesterdayData.pending || 0}`,
|
||
icon: <ClockCircleOutlined />,
|
||
color: '#FA8C16',
|
||
bg: '#FFF7E8'
|
||
},
|
||
{
|
||
title: '今日已关闭',
|
||
value: todayData.closed || 0,
|
||
trend: (() => {
|
||
const now = todayData.closed ?? 0;
|
||
const last = yesterdayData.closed ?? 0;
|
||
if (last === 0) return '较昨日 无变化';
|
||
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}`,
|
||
icon: <CheckCircleOutlined />,
|
||
color: '#00B42A',
|
||
bg: '#E8FFEA'
|
||
},
|
||
].map((item, idx) => (
|
||
<Col key={idx} style={{ minWidth: '200px', flex: '1 1 auto', maxWidth: "400px" }}>
|
||
<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>
|
||
))}
|
||
</Row>
|
||
<Row gutter={8} style={{ marginBottom: 8 }}>
|
||
<Col span={24}>
|
||
<Card bordered={false} bodyStyle={{ padding: '16px 24px' }} style={{ borderRadius: 8 }}>
|
||
<Row gutter={[8, 8]} align="middle">
|
||
<Col>
|
||
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>告警级别</div>
|
||
<Select
|
||
style={{ width: 120 }}
|
||
value={queryParams.alarmLevel}
|
||
allowClear onChange={v => setQueryParams({ ...queryParams, alarmLevel: v })}
|
||
options={errorLevelOptions}
|
||
/>
|
||
</Col>
|
||
<Col>
|
||
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>处理状态</div>
|
||
<Select
|
||
style={{ width: 120 }}
|
||
value={queryParams.handleStatus}
|
||
allowClear
|
||
onChange={v => setQueryParams({ ...queryParams, handleStatus: v })}
|
||
options={[
|
||
{ value: 1, label: '待处理' },
|
||
{ value: 2, label: '已关闭' },
|
||
]}
|
||
/>
|
||
</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 })}
|
||
style={{ width: 280 }}
|
||
allowClear
|
||
onBlur={(e) => {
|
||
const trimVal = e.target.value.trim(); // 只清除首尾空格
|
||
setQueryParams({ ...queryParams, deviceId: trimVal });
|
||
}}
|
||
/>
|
||
</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')
|
||
});
|
||
} else {
|
||
// 点击清空按钮 / 无选择,清空时间参数
|
||
setQueryParams({
|
||
...queryParams,
|
||
startTime: '',
|
||
endTime: ''
|
||
});
|
||
}
|
||
}}
|
||
/>
|
||
</Col>
|
||
<Col style={{ alignSelf: 'flex-end' }}>
|
||
<Space>
|
||
<Button style={{ borderRadius: 8 }} onClick={() => {
|
||
setQueryParams({ ...queryParams, deviceId: '', alarmLevel: '', handleStatus: 1, startTime: '', endTime: '' });
|
||
fetchList();
|
||
fetchStat();
|
||
fetchChartAllAlarm(); // 新增:刷新图表全量告警
|
||
}}>重置</Button>
|
||
<Button type="primary" style={{ borderRadius: 8, background: '#165DFF' }} onClick={() => {
|
||
fetchList(); // 刷新列表
|
||
fetchStat(); // 刷新统计
|
||
fetchChartAllAlarm(); // 新增:刷新图表全量告警
|
||
}}>
|
||
<SearchOutlined />查询
|
||
</Button>
|
||
<Button style={{ borderRadius: 8 }} onClick={doExport}>
|
||
<FileTextOutlined />导出
|
||
</Button>
|
||
</Space>
|
||
</Col>
|
||
</Row>
|
||
</Card>
|
||
</Col>
|
||
</Row>
|
||
|
||
{/* 表格 */}
|
||
<Row gutter={16} style={{ marginBottom: 8 }}>
|
||
<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 }}>
|
||
<UniversalLineChart
|
||
data={getAlarmTrendData()}
|
||
xKey="date"
|
||
height={220}
|
||
smooth
|
||
dot
|
||
backgroundColor="transparent"
|
||
series={[
|
||
{
|
||
key: 'ERROR',
|
||
name: '错误',
|
||
color: '#FF4D4F',
|
||
strokeWidth: 2,
|
||
},
|
||
{
|
||
key: 'WARNING',
|
||
name: '警告',
|
||
color: '#FA8C16',
|
||
strokeWidth: 2,
|
||
},
|
||
{
|
||
key: 'INFO',
|
||
name: '信息',
|
||
color: '#FADB14',
|
||
strokeWidth: 2,
|
||
},
|
||
|
||
]}
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
<Col span={8}>
|
||
<Card bordered={false} title="告警分类占比" style={{ borderRadius: 8 }}>
|
||
<UniversalPieChart
|
||
data={pieData}
|
||
height={220}
|
||
innerRadius={45}
|
||
outerRadius={80}
|
||
backgroundColor="transparent"
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
<Col span={8}>
|
||
<Card bordered={false} title="告警状态统计" style={{ borderRadius: 8 }}>
|
||
<UniversalBarChart
|
||
data={[
|
||
{
|
||
name: '待处理',
|
||
pending: statData.pending || 0,
|
||
},
|
||
|
||
{
|
||
name: '已关闭',
|
||
pending: statData.closed || 0,
|
||
},
|
||
]}
|
||
xKey="name"
|
||
height={220}
|
||
backgroundColor="transparent"
|
||
barSize={36}
|
||
radius={[6, 6, 0, 0]}
|
||
series={[
|
||
{
|
||
key: 'pending',
|
||
name: '数量',
|
||
color: '#165DFF',
|
||
},
|
||
]}
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
</Row>
|
||
|
||
{/* 告警详情抽屉 */}
|
||
<Drawer
|
||
title="告警详情"
|
||
open={drawerVisible}
|
||
onClose={() => setDrawerVisible(false)}
|
||
width={480}
|
||
destroyOnClose
|
||
>
|
||
|
||
<Spin spinning={detailLoading}>
|
||
|
||
{currentAlarm && (
|
||
<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>
|
||
|
||
</div>
|
||
<div style={{ fontSize: 12, color: '#86909C' }}>告警编号:{currentAlarm.alarmNo}</div>
|
||
</div>
|
||
</div>
|
||
|
||
{/* 告警基础信息 */}
|
||
<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>
|
||
<div className="flex justify-between">
|
||
<div>
|
||
|
||
</div>
|
||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 12 }}>
|
||
<Button type="default" onClick={handleContactUser}>联系负责人</Button>
|
||
<Button type="primary" onClick={handleaddOrder}>
|
||
生成工单
|
||
</Button>
|
||
</div>
|
||
|
||
</div>
|
||
</Card>
|
||
|
||
{/* 处理操作 */}
|
||
<Card size="small" title="处理操作" style={{ marginBottom: 16 }}>
|
||
<Form.Item label="处理状态" name="handleStatus" rules={[{ required: true, message: '请选择处理状态' }]}>
|
||
<Select>
|
||
<Option value={1}>待处理</Option>
|
||
|
||
<Option value={2}>已关闭</Option>
|
||
</Select>
|
||
</Form.Item>
|
||
<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>
|
||
<Form.Item label="处理备注" name="handleRemark">
|
||
<Input.TextArea rows={2} placeholder="请输入处理备注" />
|
||
</Form.Item>
|
||
|
||
|
||
|
||
</Card>
|
||
|
||
{/* 底部按钮 */}
|
||
<Button type="primary" block htmlType="submit">确认处理</Button>
|
||
|
||
</>
|
||
</Form>
|
||
)}
|
||
</Spin>
|
||
</Drawer>
|
||
|
||
{/* ====================== 修改告警弹窗 ====================== */}
|
||
<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: '请选择告警级别' }]}
|
||
>
|
||
<Select options={errorLevelOptions}>
|
||
|
||
</Select>
|
||
</Form.Item>
|
||
|
||
<Form.Item
|
||
label="告警类型"
|
||
name="alarmType"
|
||
rules={[{ required: true, message: '请选择告警类型' }]}
|
||
>
|
||
<Select>
|
||
<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>
|
||
</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>
|
||
|
||
{/* ========== 新增:生成工单弹窗 ========== */}
|
||
<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>
|
||
|
||
</div>
|
||
);
|
||
}
|