948 lines
30 KiB
TypeScript
948 lines
30 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
|
||
} from '@ant-design/icons';
|
||
import dayjs from 'dayjs';
|
||
import { exportTable } 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';
|
||
|
||
const { RangePicker } = DatePicker;
|
||
const { Text } = Typography;
|
||
const { Option } = Select;
|
||
|
||
// ====================== 你提供的枚举 ======================
|
||
|
||
// 颜色映射(从枚举自动生成)
|
||
const levelColor = Object.keys(alarmLevelConfig).reduce((map, key) => {
|
||
map[key] = alarmLevelConfig[key].color;
|
||
return map;
|
||
}, {});
|
||
|
||
const levelText = Object.keys(alarmLevelConfig).reduce((map, key) => {
|
||
map[key] = alarmLevelConfig[key].description;
|
||
return map;
|
||
}, {});
|
||
|
||
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 [editModalVisible, setEditModalVisible] = useState(false);
|
||
const [editForm] = Form.useForm();
|
||
|
||
|
||
// 查询条件
|
||
const [queryParams, setQueryParams] = useState({
|
||
deviceId: '',
|
||
alarmLevel: '',
|
||
handleStatus: '',
|
||
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 });
|
||
if (res.code === 0) {
|
||
setAlarmList(res.rows || []);
|
||
setTotal(res.total || 0);
|
||
}
|
||
} catch (err) {
|
||
messageApi.error('加载失败');
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
};
|
||
|
||
// ====================== 获取统计(带上查询条件) ======================
|
||
const fetchStat = async () => {
|
||
try {
|
||
// 把查询条件一起传给统计接口
|
||
const res = await getAlarmStatistics(queryParams);
|
||
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({
|
||
id: currentAlarm.id,
|
||
handleStatus: values.handleStatus,
|
||
handleRemark: values.handleRemark || '已处理'
|
||
});
|
||
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]);
|
||
useEffect(() => {
|
||
fetchTodayAndYesterdayStat();
|
||
fetchStat();
|
||
|
||
}, []);
|
||
|
||
// ====================== 表格列 ======================
|
||
const columns = [
|
||
{
|
||
title: '告警编号',
|
||
dataIndex: 'alarmNo',
|
||
width: 180,
|
||
render: (text) => <Text style={{ color: '#165DFF', fontWeight: 500 }}>{text}</Text>
|
||
},
|
||
{
|
||
title: '告警标题',
|
||
dataIndex: 'alarmTitle',
|
||
ellipsis: true,
|
||
width: 180
|
||
},
|
||
{
|
||
title: '告警内容',
|
||
dataIndex: 'alarmContent',
|
||
ellipsis: true
|
||
},
|
||
{
|
||
title: '设备名称',
|
||
dataIndex: 'deviceName',
|
||
width: 160
|
||
},
|
||
{
|
||
title: '告警类型',
|
||
dataIndex: 'alarmType',
|
||
width: 120,
|
||
render: (t) => alarmTypeMap[t] || '-'
|
||
},
|
||
{
|
||
title: '告警级别',
|
||
dataIndex: 'alarmLevel',
|
||
width: 100,
|
||
render: (l) => (
|
||
<Tag color={levelColor[l]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>
|
||
{levelText[l]}
|
||
</Tag>
|
||
)
|
||
},
|
||
{
|
||
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] || '-';
|
||
// 1:待处理 2:处理中 3:已关闭 4:已忽略
|
||
switch (s) {
|
||
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}>{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 (!alarmList.length) return [];
|
||
const groupMap = {};
|
||
|
||
alarmList.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] = {};
|
||
groupMap[day][level] = (groupMap[day][level] || 0) + 1;
|
||
});
|
||
|
||
// 规整成图表一维数组
|
||
return Object.entries(groupMap).map(([date, obj]) => ({
|
||
date,
|
||
severe: obj['1'] || 0, // 严重
|
||
important: obj['2'] || 0, // 重要
|
||
normal: obj['3'] || 0, // 一般
|
||
tip: obj['4'] || 0 // 提示
|
||
}));
|
||
};
|
||
|
||
const pieData = [
|
||
{
|
||
name: '严重',
|
||
value: statData.levelStats?.[1] || 0,
|
||
color: '#FF4D4F',
|
||
},
|
||
{
|
||
name: '重要',
|
||
value: statData.levelStats?.[2] || 0,
|
||
color: '#FA8C16',
|
||
},
|
||
{
|
||
name: '一般',
|
||
value: statData.levelStats?.[3] || 0,
|
||
color: '#FADB14',
|
||
},
|
||
{
|
||
name: '提示',
|
||
value: statData.levelStats?.[4] || 0,
|
||
color: '#1890FF',
|
||
},
|
||
].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`,
|
||
});
|
||
if (todayRes.code === 200) {
|
||
setTodayData(todayRes.data || {});
|
||
}
|
||
|
||
// 请求昨日
|
||
const yesterdayRes = await getAlarmStatistics({
|
||
startTime: `${yesterday} 00:00:00`,
|
||
endTime: `${yesterday} 23:59:59`,
|
||
});
|
||
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 handleaddOrder = async () => {
|
||
if (!currentAlarm) {
|
||
messageApi.warning('无告警信息,无法生成工单');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
// 组装接口需要的所有参数(你给的格式)
|
||
const params = {
|
||
id: '',
|
||
orderNo: '',
|
||
orderTitle: currentAlarm.alarmTitle || '告警生成工单',
|
||
sourceType: 7, // 来源 7=告警
|
||
orderType: 5, // 类型 5=运维
|
||
priorityLevel: currentAlarm.alarmLevel === 1 ? 1 : 2, // 严重=高,其他=中
|
||
deviceId: currentAlarm.deviceId || '',
|
||
deviceName: currentAlarm.deviceName || '',
|
||
deviceType: '', // 没有就传空
|
||
siteId: '',
|
||
siteName: '',
|
||
orgId: '',
|
||
assigneeId: '',
|
||
assigneeName: '',
|
||
collaboratorIds: '',
|
||
collaboratorNames: '',
|
||
planStartTime: '',
|
||
planEndTime: '',
|
||
deadlineTime: '',
|
||
actualStartTime: '',
|
||
actualEndTime: '',
|
||
orderStatus: 1, // 1-待处理
|
||
alarmId: currentAlarm.id || '', // 关联告警ID
|
||
alarmNo: currentAlarm.alarmNo || '', // 关联告警编号
|
||
taskDescription: currentAlarm.alarmContent || '', // 任务描述=告警内容
|
||
aiSuggestion: currentAlarm.rootCause || '', // AI建议
|
||
requiredEquipment: '',
|
||
estimatedImpact: '',
|
||
handleResult: '',
|
||
handleRemark: ''
|
||
};
|
||
|
||
// 调用新增接口
|
||
const res = await addWorkOrder(params);
|
||
if (res.code === 0 || res.code === 200) {
|
||
messageApi.success('工单生成成功');
|
||
} 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?.[1] || 0,
|
||
trend: (() => {
|
||
const now = todayData.levelStats?.[1] ?? 0;
|
||
const last = yesterdayData.levelStats?.[1] ?? 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?.[1] ?? 0;
|
||
const last = yesterdayData.levelStats?.[1] ?? 0;
|
||
if (last === 0) return '#86909C';
|
||
const rateNum = ((now - last) / last) * 100;
|
||
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
|
||
})(),
|
||
subText: `昨日 ${yesterdayData.levelStats?.[1] || 0}`,
|
||
icon: <ExclamationCircleOutlined />,
|
||
color: '#FF4D4F',
|
||
bg: '#FFF1F0'
|
||
},
|
||
{
|
||
title: '处理中',
|
||
value: todayData.processing || 0,
|
||
trend: (() => {
|
||
const now = todayData.processing ?? 0;
|
||
const last = yesterdayData.processing ?? 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.processing ?? 0;
|
||
const last = yesterdayData.processing ?? 0;
|
||
if (last === 0) return '#86909C';
|
||
const rateNum = ((now - last) / last) * 100;
|
||
return rateNum > 0 ? '#FF4D4F' : rateNum < 0 ? '#00B42A' : '#86909C';
|
||
})(),
|
||
subText: `昨日 ${yesterdayData.processing || 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={[24, 16]} align="middle">
|
||
<Col>
|
||
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>告警级别</div>
|
||
<Select
|
||
style={{ width: 120 }}
|
||
value={queryParams.alarmLevel}
|
||
onChange={v => setQueryParams({ ...queryParams, alarmLevel: v })}
|
||
options={[
|
||
{ value: '', label: '全部' },
|
||
{ value: 1, label: '严重' },
|
||
{ value: 2, label: '重要' },
|
||
{ value: 3, label: '一般' },
|
||
{ value: 4, label: '提示' },
|
||
]}
|
||
/>
|
||
</Col>
|
||
<Col>
|
||
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>处理状态</div>
|
||
<Select
|
||
style={{ width: 120 }}
|
||
value={queryParams.handleStatus}
|
||
onChange={v => setQueryParams({ ...queryParams, handleStatus: v })}
|
||
options={[
|
||
{ value: '', label: '全部' },
|
||
{ value: 1, label: '待处理' },
|
||
{ value: 2, label: '处理中' },
|
||
{ value: 3, label: '已关闭' },
|
||
{ value: 4, 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: 160 }}
|
||
/>
|
||
</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')
|
||
});
|
||
}
|
||
}}
|
||
/>
|
||
</Col>
|
||
<Col style={{ alignSelf: 'flex-end' }}>
|
||
<Space>
|
||
<Button style={{ borderRadius: 8 }} onClick={() => {
|
||
setQueryParams({ deviceId: '', alarmLevel: '', handleStatus: '', startTime: '', endTime: '' });
|
||
fetchList();
|
||
fetchStat();
|
||
}}>重置</Button>
|
||
<Button type="primary" style={{ borderRadius: 8, background: '#165DFF' }} onClick={() => {
|
||
fetchList(); // 刷新列表
|
||
fetchStat(); // 刷新统计
|
||
}}>
|
||
<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: 'severe',
|
||
name: '严重',
|
||
color: '#FF4D4F',
|
||
strokeWidth: 2,
|
||
},
|
||
{
|
||
key: 'important',
|
||
name: '重要',
|
||
color: '#FA8C16',
|
||
strokeWidth: 2,
|
||
},
|
||
{
|
||
key: 'normal',
|
||
name: '一般',
|
||
color: '#FADB14',
|
||
strokeWidth: 2,
|
||
},
|
||
{
|
||
key: 'tip',
|
||
name: '提示',
|
||
color: '#1890FF',
|
||
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.processing || 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={420}
|
||
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>
|
||
<Tag color={levelColor[currentAlarm.alarmLevel]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>
|
||
{levelText[currentAlarm.alarmLevel]}
|
||
</Tag>
|
||
</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.Item label="负责人">{currentAlarm.handleUserName || '-'}</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.rootCause || '-'}</div>
|
||
</Card>
|
||
|
||
{/* 推荐处理措施 */}
|
||
<Card size="small" title="推荐处理措施" style={{ marginBottom: 16 }}>
|
||
<div style={{ color: '#333' }}>{currentAlarm.handleSuggestion || '-'}</div>
|
||
<div className="flex justify-between">
|
||
<div>
|
||
|
||
</div>
|
||
<Button type="primary" onClick={handleaddOrder}>生成工单</Button>
|
||
|
||
</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>
|
||
<Option value={3}>已关闭</Option>
|
||
<Option value={4}>已忽略</Option>
|
||
</Select>
|
||
</Form.Item>
|
||
<Form.Item label="处理备注" name="handleRemark">
|
||
<Input.TextArea rows={2} placeholder="请输入处理备注" />
|
||
</Form.Item>
|
||
</Card>
|
||
|
||
{/* 通知与订阅 */}
|
||
<Card size="small" title="通知与订阅" style={{ marginBottom: 16 }}>
|
||
<Row gutter={[8, 8]}>
|
||
<Col span={8}>
|
||
<Space>
|
||
<svg t="1778634297838" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9839" width="16" height="16"><path d="M761.984 1009.28H253.696C138.368 1009.28 44.8 915.712 44.8 800.384V292.096C44.8 176.768 138.368 83.2 253.696 83.2h508.288c115.328 0 208.896 93.568 208.896 208.896v508.288c0 115.328-93.568 208.896-208.896 208.896z" fill="#00E560" p-id="9840"></path><path d="M507.776 265.856c-72.576 0-139.776 20.352-193.536 54.528-54.272 34.432-94.592 83.2-113.408 139.264-7.552 22.528-11.648 46.464-11.648 71.04 0 92.16 56.448 172.928 142.208 220.544 7.68 4.224 11.648 13.44 8.32 21.632-6.4 15.616-14.592 30.592-24.32 44.672-3.072 4.352 0.768 10.368 6.016 8.96 29.44-7.808 56.96-19.072 81.92-33.28 9.088-5.248 19.456-6.912 29.696-4.864 23.936 4.736 49.024 7.296 74.88 7.296 176 0 318.592-118.656 318.592-264.832 0-146.304-142.72-264.96-318.72-264.96z" fill="#FFFFFF" p-id="9841"></path></svg>
|
||
<span>短信</span>
|
||
<Switch checked={currentAlarm.notifySms === 1} />
|
||
</Space>
|
||
</Col>
|
||
<Col span={8}>
|
||
<Space>
|
||
<svg t="1778634173765" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8764" width="16" height="16"><path d="M512.003 79C272.855 79 79 272.855 79 512.003 79 751.145 272.855 945 512.003 945 751.145 945 945 751.145 945 512.003 945 272.855 751.145 79 512.003 79z m200.075 375.014c-0.867 3.764-3.117 9.347-6.234 16.012h0.087l-0.347 0.648c-18.183 38.86-65.631 115.108-65.631 115.108l-0.215-0.52-13.856 24.147h66.8L565.063 779l29.002-115.368h-52.598l18.27-76.29c-14.76 3.55-32.253 8.436-52.945 15.1 0 0-27.967 16.36-80.607-31.5 0 0-35.501-31.29-14.891-39.078 8.744-3.33 42.466-7.573 69.004-11.122 35.93-4.845 57.965-7.441 57.965-7.441s-110.607 1.643-136.841-2.468c-26.237-4.11-59.525-47.905-66.626-86.377 0 0-10.953-21.117 23.595-11.122 34.547 10 177.535 38.95 177.535 38.95s-185.933-56.992-198.36-70.929c-12.381-13.846-36.406-75.902-33.289-113.981 0 0 1.343-9.521 11.127-6.926 0 0 137.49 62.75 231.475 97.152 94.028 34.403 175.76 51.885 165.2 96.414z" fill="#3AA2EB" p-id="8765"></path></svg>
|
||
{/*<NotificationOutlined />*/}
|
||
<span>钉钉</span>
|
||
<Switch checked={currentAlarm.notifyTelegram === 1} />
|
||
</Space>
|
||
</Col>
|
||
<Col span={8}>
|
||
<Space>
|
||
<svg t="1778634149974" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7716" width="16" height="16"><path d="M512 512m-448 0a448 448 0 1 0 896 0 448 448 0 1 0-896 0Z" fill="#608BE9" p-id="7717"></path><path d="M192 302m32 0l576 0q32 0 32 32l0 356q0 32-32 32l-576 0q-32 0-32-32l0-356q0-32 32-32Z" fill="#EAEDF5" p-id="7718"></path><path d="M224 722h576c17.673 0 32-14.327 32-32v-58C660.96 493.333 554.294 424 512 424c-42.294 0-148.96 69.333-320 208v58c0 17.673 14.327 32 32 32z" fill="#CCDAF7" p-id="7719"></path><path d="M224 302h576c17.673 0 32 14.327 32 32v58C651.35 517.333 544.683 580 512 580c-32.683 0-139.35-62.667-320-188v-58c0-17.673 14.327-32 32-32z" fill="#FFFFFF" p-id="7720"></path></svg>
|
||
{/*<NotificationOutlined />*/}
|
||
<span>邮件</span>
|
||
<Switch checked={currentAlarm.notifyEmail === 1} />
|
||
</Space>
|
||
</Col>
|
||
</Row>
|
||
</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>
|
||
<Option value={1}>严重</Option>
|
||
<Option value={2}>重要</Option>
|
||
<Option value={3}>一般</Option>
|
||
<Option value={4}>提示</Option>
|
||
</Select>
|
||
</Form.Item>
|
||
|
||
<Form.Item
|
||
label="告警类型"
|
||
name="alarmType"
|
||
rules={[{ required: true, message: '请选择告警类型' }]}
|
||
>
|
||
<Select>
|
||
<Option value={1}>设备故障</Option>
|
||
<Option value={2}>数据异常</Option>
|
||
<Option value={3}>通信中断</Option>
|
||
<Option value={4}>性能告警</Option>
|
||
<Option value={5}>安全告警</Option>
|
||
<Option value={6}>环境告警</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>
|
||
|
||
</div>
|
||
);
|
||
}
|