告警中心 初始化

This commit is contained in:
mmc
2026-05-07 14:13:26 +08:00
parent e401eef62f
commit 9cf26ce2bd
19 changed files with 1321 additions and 928 deletions

View File

@@ -0,0 +1,129 @@
import React, { useEffect, useRef } from 'react';
import { Card, Row, Col, Space } from 'antd';
import { AreaChartOutlined } from '@ant-design/icons';
import * as echarts from 'echarts';
const AntdCard = Card as any;
const AlarmStatistics = () => {
// 图表 ref
const barChartRef = useRef(null);
const pieChartRef = useRef(null);
// 柱状图
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日']
},
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);
};
}, []);
// 饼图
useEffect(() => {
if (!pieChartRef.current) return;
const pieChart = echarts.init(pieChartRef.current);
pieChart.setOption({
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);
};
}, []);
return (
<div style={{ padding: 24 }}>
{/* 顶部统计卡片 保留你原来的图标样式 */}
<AntdCard title="告警概览" style={{ marginBottom: 24 }}>
<Row gutter={16}>
<Col span={8}>
<Space>
<div style={{ background: '#e6f4ff', padding: 8, borderRadius: 8 }}>
<AreaChartOutlined style={{ color: '#1677ff', fontSize: 20 }} />
</div>
<div>
<div style={{ color: '#666' }}>今日告警</div>
<div style={{ fontWeight: 600, fontSize: 18 }}>12</div>
</div>
</Space>
</Col>
<Col span={8}>
<Space>
<div style={{ background: '#fff7e6', padding: 8, borderRadius: 8 }}>
<AreaChartOutlined style={{ color: '#fa8c16', fontSize: 20 }} />
</div>
<div>
<div style={{ color: '#666' }}>本周告警</div>
<div style={{ fontWeight: 600, fontSize: 18 }}>45</div>
</div>
</Space>
</Col>
<Col span={8}>
<Space>
<div style={{ background: '#f6ffed', padding: 8, borderRadius: 8 }}>
<AreaChartOutlined style={{ color: '#52c41a', fontSize: 20 }} />
</div>
<div>
<div style={{ color: '#666' }}>本月告警</div>
<div style={{ fontWeight: 600, fontSize: 18 }}>128</div>
</div>
</Space>
</Col>
</Row>
</AntdCard>
{/* 两个图表 左右各一半 并排显示 不空洞 */}
<Row gutter={16}>
<Col span={12}>
<AntdCard title="告警趋势统计">
<div ref={barChartRef} style={{ width: '100%', height: 350 }} />
</AntdCard>
</Col>
<Col span={12}>
<AntdCard title="告警分类统计">
<div ref={pieChartRef} style={{ width: '100%', height: 350 }} />
</AntdCard>
</Col>
</Row>
</div>
);
};
export default AlarmStatistics;