Files
web-Iot/src/components/alerts/AlarmOverview.tsx
2026-05-07 20:25:14 +08:00

384 lines
14 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState } from 'react';
import {
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
Statistic, Typography
} from 'antd';
import {
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined
} from '@ant-design/icons';
import { Line, Pie, Bar } from '@ant-design/charts';
const { RangePicker } = DatePicker;
const { Text } = Typography;
// 级别 + 状态颜色
const levelColor = {
严重: 'red',
重要: 'orange',
一般: 'gold',
提示: 'blue'
};
const statusColor = {
处理中: 'processing',
待处理: 'warning',
已关闭: 'success'
};
// 模拟数据
const mockAlerts = [
{ id: 'DEVICE_OFFLINE_CAM-02', content: '设备离线', device: 'CAM-02', level: '提示', time: '2026-04-28 17:22:04', duration: '1小时23分', status: '待处理', handler: '-' },
{ id: 'INV_TEMP_HIGH_INV-A02', content: '逆变器温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 17:21:54', duration: '1小时23分', status: '待处理', handler: '-' },
{ id: 'AL-20260428-001', content: 'INV-A02 温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 10:54:45', duration: '36分钟', status: '待处理', handler: '-' },
{ id: 'AL-20260428-002', content: 'CMB-A01 组串电流异常', device: 'CMB-A01', level: '一般', time: '2026-04-28 10:32:45', duration: '52分钟', status: '处理中', handler: '张运维' },
{ id: 'AL-20260428-003', content: 'CAM-02 视频离线', device: 'CAM-02', level: '提示', time: '2026-04-28 09:32:45', duration: '0分钟', status: '待处理', handler: '-' },
];
export default function AlarmCenterPage() {
const [selectedAlert, setSelectedAlert] = useState<any>(mockAlerts[0]);
const [detailVisible, setDetailVisible] = useState(true);
const columns = [
{ title: '告警编号', dataIndex: 'id', width: 180 },
{ title: '告警内容', dataIndex: 'content', ellipsis: true },
{ title: '来源设备', dataIndex: 'device', width: 120 },
{ title: '告警级别', dataIndex: 'level', width: 100, render: l => <Tag color={levelColor[l]}>{l}</Tag> },
{ title: '发生时间', dataIndex: 'time', width: 160 },
{ title: '持续时长', dataIndex: 'duration', width: 100 },
{ title: '处理状态', dataIndex: 'status', width: 100, render: s => <Tag color={statusColor[s]}>{s}</Tag> },
{ title: '负责人', dataIndex: 'handler', width: 100 },
{
title: '操作', width: 120,
render: (_, record) => (
<Space>
<Button type="link" onClick={() => { setSelectedAlert(record); setDetailVisible(true); }}>查看</Button>
<Button type="link">更多</Button>
</Space>
)
}
];
// 告警趋势图配置
const trendConfig = {
data: [
{ date: '05-19', 严重: 12, 重要: 5, 一般: 3, 提示: 2 },
{ date: '05-20', 严重: 30, 重要: 16, 一般: 9, 提示: 6 },
{ date: '05-21', 严重: 23, 重要: 11, 一般: 7, 提示: 5 },
{ date: '05-22', 严重: 25, 重要: 17, 一般: 10, 提示: 4 },
{ date: '05-23', 严重: 19, 重要: 9, 一般: 13, 提示: 7 },
{ date: '05-24', 严重: 24, 重要: 18, 一般: 16, 提示: 8 },
{ date: '05-25', 严重: 36, 重要: 29, 一般: 22, 提示: 13 }
],
xField: 'date',
yField: ['严重', '重要', '一般', '提示'],
color: ['#ff4d4f', '#faad14', '#52c41a', '#1890ff'],
smooth: true,
legend: { position: 'top-left' },
label: { style: { fill: '#aaa' } }
};
// 告警分类占比配置
const pieConfig = {
data: [
{ type: '严重', value: 8, percent: 22.2 },
{ type: '重要', value: 12, percent: 33.3 },
{ type: '一般', value: 11, percent: 30.6 },
{ type: '提示', value: 5, percent: 13.9 }
],
angleField: 'value',
colorField: 'type',
color: ['#ff4d4f', '#faad14', '#52c41a', '#1890ff'],
radius: 0.8,
innerRadius: 0.6,
label: {
type: 'outer',
content: '{name}\n{percentage:.1%} ({value})'
},
annotations: [
{
type: 'text',
style: {
text: '36\n总告警',
x: '50%',
y: '50%',
textAlign: 'center',
fontSize: 20,
fontWeight: 'bold'
}
}
]
};
// 告警来源设备分布
const barConfig = {
data: [
{ device: '逆变器', count: 14, percent: 38.9 },
{ device: '汇流箱', count: 8, percent: 22.2 },
{ device: '组串', count: 6, percent: 16.7 },
{ device: '气象站', count: 3, percent: 8.3 },
{ device: '电表', count: 3, percent: 8.3 },
{ device: '其他', count: 2, percent: 5.6 }
],
xField: 'count',
yField: 'device',
colorField: 'device',
color: ['#1890ff', '#40a9ff', '#69c0ff', '#91d5ff', '#bae7ff', '#e6f7ff'],
barWidthRatio: 0.6,
label: {
position: 'right',
style: { fill: '#666' },
content: (item) => `${item.count}(${item.percent}%)`
}
};
return (
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0 24px 24px' }}>
{/* ===================== 统一宽度容器 ===================== */}
<div style={{ display: 'flex', gap: 16, marginTop: 16, width: '100%' }}>
{/* ===================== 左侧:所有模块宽度完全一致 ===================== */}
<div style={{ flex: 1, minWidth: 0 }}>
{/* 统一容器:保证 筛选 + 统计 宽度完全一样 */}
<div style={{ width: "100%" }}>
{/* 筛选卡片 */}
<Card style={{ borderRadius: 8, border: 'none', marginBottom: 16 }} bodyStyle={{ padding: '16px' }}>
<Row gutter={16} align="middle">
<Col><Select placeholder="告警级别" style={{ width: 120 }} /></Col>
<Col><Select placeholder="告警类型" style={{ width: 120 }} /></Col>
<Col><Select placeholder="设备类型" style={{ width: 120 }} /></Col>
<Col><RangePicker placeholder={['开始', '结束']} style={{ width: 240 }} /></Col>
<Col><Select placeholder="处理状态" style={{ width: 120 }} /></Col>
<Col flex="auto"><Input placeholder="搜索告警编号/内容/设备" style={{ width: '100%' }} /></Col>
<Col><Space><Button>重置</Button><Button type="primary">查询</Button></Space></Col>
</Row>
</Card>
{/* 统计卡片 - 现在和筛选卡片一样宽 */}
<div
style={{
display: "flex",
gap: "16px",
marginBottom: 16,
width: "100%"
}}
>
<div style={{ flex: 1 }}>
<Card bordered={false} style={{ borderRadius: 8, padding: '12px' }} bodyStyle={{ padding: '12px 0 0 0' }}>
<Statistic
title="今日告警总数"
value={5}
prefix={<BellOutlined style={{ color: '#ff4d4f' }} />}
valueStyle={{ fontSize: 28, fontWeight: 700, color: '#ff4d4f' }}
/>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>昨日 28</div>
</Card>
</div>
<div style={{ flex: 1 }}>
<Card bordered={false} style={{ borderRadius: 8, padding: '12px' }} bodyStyle={{ padding: '8px 0 0 0' }}>
<Statistic
title="严重告警"
value={0}
prefix={<ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />}
valueStyle={{ fontSize: 28, fontWeight: 700, color: '#ff4d4f' }}
/>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>重要 2</div>
</Card>
</div>
<div style={{ flex: 1 }}>
<Card bordered={false} style={{ borderRadius: 8, padding: '12px' }} bodyStyle={{ padding: '8px 0 0 0' }}>
<Statistic
title="处理中"
value={1}
prefix={<ClockCircleOutlined style={{ color: '#faad14' }} />}
valueStyle={{ fontSize: 28, fontWeight: 700, color: '#faad14' }}
/>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>待处理 4</div>
</Card>
</div>
<div style={{ flex: 1 }}>
<Card bordered={false} style={{ borderRadius: 8, padding: '12px' }} bodyStyle={{ padding: '8px 0 0 0' }}>
<Statistic
title="已关闭"
value={0}
prefix={<CheckCircleOutlined style={{ color: '#52c41a' }} />}
valueStyle={{ fontSize: 28, fontWeight: 700, color: '#52c41a' }}
/>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>闭环完成</div>
</Card>
</div>
<div style={{ flex: 1 }}>
<Card bordered={false} style={{ borderRadius: 8, padding: '12px' }} bodyStyle={{ padding: '8px 0 0 0' }}>
<Statistic
title="平均响应"
value="49分钟"
prefix={<ClockCircleOutlined style={{ color: '#1890ff' }} />}
valueStyle={{ fontSize: 28, fontWeight: 700, color: '#1890ff' }}
/>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>时间估算</div>
</Card>
</div>
</div>
</div>
{/* 告警列表(宽度 = 筛选卡片 完全一致) */}
{/* 告警列表 + 右侧详情(不换行、表格自适应、可横向滚动) */}
<div style={{
display: 'flex',
gap: 16,
width: '100%',
flexWrap: 'nowrap', /* 强制不换行 */
alignItems: 'stretch', /* 高度对齐 */
marginBottom: 16
}}>
{/* 左侧告警列表:自适应宽度 + 横向滚动 */}
<div style={{
flex: 1,
minWidth: 0, /* 关键:允许表格缩小 */
}}>
<Card
bordered={false}
style={{
borderRadius: 8,
marginBottom: 16,
height: '100%',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<div>
<Typography.Text strong style={{ fontSize: 16 }}>告警列表(共8条)</Typography.Text><br />
<Text type="secondary" style={{ fontSize: 12 }}>点击告警查看详情</Text>
</div>
</div>
<Table
rowKey="id"
columns={columns}
dataSource={mockAlerts}
pagination={{ pageSize: 8 }}
scroll={{ x: 'max-content' }} /* 表格超出自动横向滚动 */
style={{ width: '100%' }}
/>
</Card>
</div>
{/* 右侧详情:固定 360px,不挤压、不换行 */}
{detailVisible && selectedAlert && (
<div style={{
width: 360,
flexShrink: 0, /* 关键:不被挤压 */
display: 'flex',
flexDirection: 'column',
}}>
<Card
title="告警详情"
bordered={false}
style={{
borderRadius: 8,
height: '100%',
display: 'flex',
flexDirection: 'column',
overflow: 'hidden'
}}
bodyStyle={{
padding: '16px',
display: 'flex',
flexDirection: 'column',
flex: 1,
overflow: 'hidden'
}}
>
{/* 可滚动内容区域 */}
<div style={{ flex: 1, overflow: 'auto', paddingRight: 8 }}>
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<ExclamationCircleOutlined style={{ color: '#ff4d4f', marginRight: 8 }} />
<span style={{ fontSize: 16, fontWeight: 500 }}>{selectedAlert.content}</span>
</div>
<Tag color={levelColor[selectedAlert.level]}>{selectedAlert.level}</Tag>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>{selectedAlert.id}</div>
</div>
<div style={{ background: '#fafafa', borderRadius: 8, padding: 16, marginBottom: 16 }}>
<Row gutter={[16, 16]}>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>来源设备</div><div>{selectedAlert.device}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>发生时间</div><div>{selectedAlert.time}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>持续时长</div><div>{selectedAlert.duration}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>处理状态</div><div>{selectedAlert.status}</div></Col>
</Row>
</div>
<div style={{ marginBottom: 16 }}>
<div style={{ fontWeight: 500, marginBottom: 8 }}>根因分析建议</div>
<div style={{ fontSize: 12, color: '#666', lineHeight: 1.7 }}>
设备离线/网络异常<br />
电源或通讯模块故障<br />
现场信号弱或采集器异常
</div>
</div>
</div>
{/* 固定底部操作按钮 */}
<div style={{ marginTop: 12, paddingTop: 12, borderTop: '1px solid #f0f0f0' }}>
<Space direction="vertical" style={{ width: '100%' }}>
<Button type="primary" block>确认告警</Button>
<Button block>标记处理中</Button>
<Button block danger>关闭告警</Button>
</Space>
</div>
</Card>
</div>
)}
</div>
{/* 三个图表卡片:告警趋势 + 分类占比 + 设备分布 */}
<Row gutter={16}>
<Col span={8}>
<Card
bordered={false}
style={{ borderRadius: 8 }}
title="告警趋势"
extra={<Button type="link">更多 </Button>}
>
<Line {...trendConfig} height={180} />
</Card>
</Col>
<Col span={8}>
<Card
bordered={false}
style={{ borderRadius: 8 }}
title="告警分类占比"
extra={<Button type="link">更多 </Button>}
>
<Pie {...pieConfig} height={180} />
</Card>
</Col>
<Col span={8}>
<Card
bordered={false}
style={{ borderRadius: 8 }}
title="告警来源设备分布"
extra={<Button type="link">更多</Button>}
>
<Bar {...barConfig} height={180} />
</Card>
</Col>
</Row>
</div>
{/* ===================== 右侧详情面板:高度拉伸至视口 ===================== */}
</div>
</div >
);
}