告警中心 初始化
This commit is contained in:
@@ -1,323 +1,90 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Layout, Menu, Typography } from 'antd';
|
||||
import {
|
||||
Table,
|
||||
Tag,
|
||||
Input,
|
||||
Button,
|
||||
Row,
|
||||
Col,
|
||||
Card,
|
||||
Typography,
|
||||
Space,
|
||||
Statistic,
|
||||
Select,
|
||||
DatePicker,
|
||||
List,
|
||||
Layout,
|
||||
} from 'antd';
|
||||
import {
|
||||
BellOutlined,
|
||||
AlertOutlined,
|
||||
SyncOutlined,
|
||||
CheckCircleOutlined,
|
||||
ClockCircleOutlined,
|
||||
RiseOutlined,
|
||||
FallOutlined,
|
||||
CloseOutlined,
|
||||
AlertOutlined, ClockCircleOutlined, FileTextOutlined, BarChartOutlined,
|
||||
SettingOutlined, BellOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { getMenuList } from '../api/mune';
|
||||
import AlarmOverview from '../components/alerts/AlarmOverview';
|
||||
import AlarmRealtime from '../components/alerts/AlarmRealtime';
|
||||
import AlarmHistory from '../components/alerts/AlarmHistory';
|
||||
import AlarmStatistics from '../components/alerts/AlarmStatistics';
|
||||
import AlarmRules from '../components/alerts/AlarmRules';
|
||||
import AlarmSubscription from '../components/alerts/AlarmSubscription';
|
||||
|
||||
|
||||
|
||||
const { Header, Content } = Layout;
|
||||
const { Text } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
const AntdCard = Card as any;
|
||||
|
||||
// 模拟数据
|
||||
const alertList = [
|
||||
{
|
||||
id: 'AL20250525001',
|
||||
content: '逆变器停机',
|
||||
device: '逆变器 12 (组串式)',
|
||||
level: '严重',
|
||||
time: '2025-05-25 09:18:32',
|
||||
duration: '2小时18分',
|
||||
status: '处理中',
|
||||
handler: '张运维',
|
||||
},
|
||||
{
|
||||
id: 'AL20250525002',
|
||||
content: '发电量下降 > 15%',
|
||||
device: '汇流箱 05',
|
||||
level: '重要',
|
||||
time: '2025-05-25 08:46:11',
|
||||
duration: '3小时50分',
|
||||
status: '处理中',
|
||||
handler: '李工程师',
|
||||
},
|
||||
{
|
||||
id: 'AL20250525003',
|
||||
content: '逆变器温度过高',
|
||||
device: '逆变器 07 (组串式)',
|
||||
level: '重要',
|
||||
time: '2025-05-25 07:32:45',
|
||||
duration: '4小时24分',
|
||||
status: '待处理',
|
||||
handler: '-',
|
||||
},
|
||||
];
|
||||
export default function AlarmCenterPage() {
|
||||
const [activeTab, setActiveTab] = useState('overview');
|
||||
const [rawMenuList, setRawMenuList] = useState([]);
|
||||
const [showTabs, setShowTabs] = useState([]);
|
||||
|
||||
const stats = [
|
||||
{
|
||||
title: '今日告警总数',
|
||||
value: 36,
|
||||
change: '+28.6%',
|
||||
up: true,
|
||||
extra: '昨日 28',
|
||||
icon: <BellOutlined style={{ color: '#ff4d4f' }} />,
|
||||
},
|
||||
{
|
||||
title: '严重告警',
|
||||
value: 8,
|
||||
change: '+33.3%',
|
||||
up: true,
|
||||
extra: '昨日 6',
|
||||
icon: <AlertOutlined style={{ color: '#ff4d4f' }} />,
|
||||
},
|
||||
{
|
||||
title: '处理中',
|
||||
value: 12,
|
||||
change: '+20.0%',
|
||||
up: true,
|
||||
extra: '昨日 10',
|
||||
icon: <SyncOutlined style={{ color: '#fa8c16' }} />,
|
||||
},
|
||||
{
|
||||
title: '已关闭',
|
||||
value: 16,
|
||||
change: '+45.5%',
|
||||
up: true,
|
||||
extra: '昨日 11',
|
||||
icon: <CheckCircleOutlined style={{ color: '#52c41a' }} />,
|
||||
},
|
||||
{
|
||||
title: '平均响应时长',
|
||||
value: '18分32秒',
|
||||
change: '-12.6%',
|
||||
up: false,
|
||||
extra: '昨日 21分12秒',
|
||||
icon: <ClockCircleOutlined style={{ color: '#1890ff' }} />,
|
||||
},
|
||||
];
|
||||
// 获取菜单(和系统设置一模一样)
|
||||
const getMenuListApi = () => {
|
||||
const params = { pageNum: 1, pageSize: 99999 };
|
||||
return getMenuList(params);
|
||||
};
|
||||
|
||||
export default function Alerts() {
|
||||
// 控制右侧详情面板
|
||||
const [showDetail, setShowDetail] = useState(false);
|
||||
const [selectedAlert, setSelectedAlert] = useState<any>(null);
|
||||
// 动态生成 tab
|
||||
useEffect(() => {
|
||||
getMenuListApi().then(res => {
|
||||
if (res.code === 200) {
|
||||
const data = res.rows || [];
|
||||
// 告警中心 parentId 你自己改成你数据库里的 ID
|
||||
const alarmChild = data.filter(m => m.parentId == 3388);
|
||||
|
||||
const columns = [
|
||||
{ title: '告警编号', dataIndex: 'id', key: 'id', width: 120 },
|
||||
{ title: '告警内容', dataIndex: 'content', key: 'content' },
|
||||
{ title: '来源设备', dataIndex: 'device', key: 'device', width: 160 },
|
||||
{
|
||||
title: '告警级别',
|
||||
dataIndex: 'level',
|
||||
key: 'level',
|
||||
width: 80,
|
||||
render: (level: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
严重: 'red',
|
||||
重要: 'orange',
|
||||
一般: 'gold',
|
||||
提示: 'blue',
|
||||
};
|
||||
return <Tag color={colorMap[level]}>{level}</Tag>;
|
||||
},
|
||||
},
|
||||
{ title: '发生时间', dataIndex: 'time', key: 'time', width: 160 },
|
||||
{ title: '持续时长', dataIndex: 'duration', key: 'duration', width: 110 },
|
||||
{
|
||||
title: '处理状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
render: (status: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
处理中: 'blue',
|
||||
待处理: 'orange',
|
||||
已关闭: 'green',
|
||||
};
|
||||
return <Tag color={colorMap[status]}>{status}</Tag>;
|
||||
},
|
||||
},
|
||||
{ title: '负责人', dataIndex: 'handler', key: 'handler', width: 90 },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 80,
|
||||
render: (_, record) => (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => {
|
||||
setSelectedAlert(record);
|
||||
setShowDetail(true);
|
||||
}}
|
||||
>
|
||||
查看
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
alarmChild.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0));
|
||||
|
||||
const tabs = alarmChild.map(item => {
|
||||
if (item.path === '/alerts/all') return { key: 'overview', label: '告警总览', icon: <AlertOutlined /> };
|
||||
if (item.path === '/alerts/time') return { key: 'realtime', label: '实时告警', icon: <ClockCircleOutlined /> };
|
||||
if (item.path === '/alerts/history') return { key: 'history', label: '告警历史', icon: <FileTextOutlined /> };
|
||||
if (item.path === '/alerts/counts') return { key: 'statistics', label: '告警统计', icon: <BarChartOutlined /> };
|
||||
if (item.path === '/alerts/rules') return { key: 'rules', label: '告警规则', icon: <SettingOutlined /> };
|
||||
if (item.path === '/alerts/subscribe') return { key: 'subscription', label: '告警订阅', icon: <BellOutlined /> };
|
||||
return null;
|
||||
}).filter(Boolean);
|
||||
|
||||
setShowTabs(tabs);
|
||||
if (tabs.length > 0) setActiveTab(tabs[0].key);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
// 渲染对应组件
|
||||
const renderTabContent = () => {
|
||||
switch (activeTab) {
|
||||
case 'overview': return <AlarmOverview />;
|
||||
case 'realtime': return <AlarmRealtime />;
|
||||
case 'history': return <AlarmHistory />;
|
||||
case 'statistics': return <AlarmStatistics />;
|
||||
case 'rules': return <AlarmRules />;
|
||||
case 'subscription': return <AlarmSubscription />;
|
||||
default: return <div style={{ padding: 20 }}><Text>请选择菜单</Text></div>;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ background: '#f4f7f9', minHeight: '100%' }}>
|
||||
<Layout style={{ background: 'transparent' }}>
|
||||
{/* 左侧主内容区:宽度动态变化 */}
|
||||
<Layout.Content
|
||||
style={{
|
||||
padding: '16px',
|
||||
transition: 'width 0.3s ease',
|
||||
width: showDetail ? 'calc(100% - 460px)' : '100%',
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>告警中心</div>
|
||||
<Layout style={{ minHeight: '100vh', background: '#fff', overflow: 'hidden' }}>
|
||||
<Header style={{ background: '#fff', padding: 0, borderBottom: '1px solid #f0f0f0', position: 'sticky', top: 0, zIndex: 10 }}>
|
||||
<Menu
|
||||
mode="horizontal"
|
||||
selectedKeys={[activeTab]}
|
||||
onClick={({ key }) => setActiveTab(key)}
|
||||
items={showTabs}
|
||||
style={{ border: 0, height: 64, lineHeight: '64px' }}
|
||||
/>
|
||||
</Header>
|
||||
|
||||
{/* 筛选栏 */}
|
||||
<AntdCard size="small" style={{ borderRadius: 8, marginBottom: 16 }}>
|
||||
<Row gutter={[16, 16]} align="middle">
|
||||
<Col span={4}><Select placeholder="告警级别" style={{ width: '100%' }} /></Col>
|
||||
<Col span={4}><Select placeholder="告警类型" style={{ width: '100%' }} /></Col>
|
||||
<Col span={4}><Select placeholder="设备类型" style={{ width: '100%' }} /></Col>
|
||||
<Col span={6}><RangePicker style={{ width: '100%' }} /></Col>
|
||||
<Col span={6}><Select placeholder="处理状态" style={{ width: '100%' }} /></Col>
|
||||
<Col span={24} style={{ display: 'flex', gap: 8, marginTop: 8 }}>
|
||||
<Input placeholder="搜索" style={{ width: 220 }} />
|
||||
<Button>重置</Button>
|
||||
<Button type="primary">查询</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||
{stats.map((stat, idx) => (
|
||||
<Col xs={24} sm={12} md={8} lg={4} key={idx}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8 }}>
|
||||
<Statistic
|
||||
title={<span style={{ fontSize: 13 }}>{stat.title}</span>}
|
||||
value={stat.value}
|
||||
valueStyle={{ fontSize: 20, fontWeight: 600 }}
|
||||
prefix={stat.icon}
|
||||
/>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>{stat.extra}</Text>
|
||||
<Text style={{ color: stat.up ? '#ff4d4f' : '#52c41a', fontSize: 12 }}>
|
||||
{stat.change} {stat.up ? <RiseOutlined /> : <FallOutlined />}
|
||||
</Text>
|
||||
</div>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
{/* 告警列表 */}
|
||||
<AntdCard
|
||||
size="small"
|
||||
title={
|
||||
<div style={{ fontSize: 14, fontWeight: 600 }}>
|
||||
<span style={{ color: '#165DFF' }}>告警列表</span>
|
||||
<span style={{ color: '#333' }}>(共36条)</span>
|
||||
</div>
|
||||
}
|
||||
style={{ borderRadius: 8 }}
|
||||
>
|
||||
<Table
|
||||
size="small"
|
||||
columns={columns}
|
||||
dataSource={alertList}
|
||||
pagination={{ pageSize: 10 }}
|
||||
rowKey="id"
|
||||
onRow={(record) => ({
|
||||
onClick: () => {
|
||||
setSelectedAlert(record);
|
||||
setShowDetail(true);
|
||||
},
|
||||
})}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Layout.Content>
|
||||
|
||||
{/* 右侧详情面板:推挤式,非覆盖 */}
|
||||
{showDetail && (
|
||||
<Layout.Sider
|
||||
width={460}
|
||||
style={{
|
||||
background: '#fff',
|
||||
padding: '16px',
|
||||
height: 'calc(100vh - 50px)',
|
||||
overflow: 'auto',
|
||||
boxShadow: '-2px 0 8px rgba(0,0,0,0.08)',
|
||||
}}
|
||||
>
|
||||
{selectedAlert && (
|
||||
<div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 16 }}>告警详情</Text>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<CloseOutlined />}
|
||||
onClick={() => setShowDetail(false)}
|
||||
style={{ fontSize: 16 }}
|
||||
/> </div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
|
||||
<BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} />
|
||||
<Text strong style={{ fontSize: 16 }}>{selectedAlert.content}</Text>
|
||||
<Tag color="red">{selectedAlert.level}</Tag>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: '#666', lineHeight: 1.8 }}>
|
||||
<div>告警编号:{selectedAlert.id}</div>
|
||||
<div>来源设备:{selectedAlert.device}</div>
|
||||
<div>发生时间:{selectedAlert.time}</div>
|
||||
<div>持续时长:{selectedAlert.duration}</div>
|
||||
<div>处理状态:{selectedAlert.status}</div>
|
||||
<div>负责人:{selectedAlert.handler}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 13, marginBottom: 8, display: 'block' }}>根因分析建议</Text>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={[
|
||||
'逆变器内部保护触发(IGBT/继电器故障)',
|
||||
'交流侧电压异常或并网不稳定',
|
||||
'散热风扇故障导致过温保护',
|
||||
]}
|
||||
renderItem={(item) => <List.Item style={{ padding: '4px 0' }}>{item}</List.Item>}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 13, marginBottom: 8, display: 'block' }}>推荐处理措施</Text>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={[
|
||||
'现场检查逆变器告警记录及指示灯状态',
|
||||
'检查散热风扇运行及通风条件',
|
||||
'检查交流侧电压及并网条件',
|
||||
]}
|
||||
renderItem={(item) => <List.Item style={{ padding: '4px 0' }}>{item}</List.Item>}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button type="primary" block style={{ marginTop: 16 }}>
|
||||
标记为已解决
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</Layout.Sider>
|
||||
)}
|
||||
</Layout>
|
||||
</div>
|
||||
<Content style={{
|
||||
maxHeight: 'calc(100vh - 64px)', overflowY: 'auto', background: '#f5f7fa',
|
||||
scrollbarWidth: 'none', msOverflowStyle: 'none',
|
||||
}}>
|
||||
{renderTabContent()}
|
||||
</Content>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user