151 lines
4.7 KiB
TypeScript
151 lines
4.7 KiB
TypeScript
|
|
import React from 'react';
|
||
|
|
import {
|
||
|
|
Table,
|
||
|
|
Tag,
|
||
|
|
Input,
|
||
|
|
Button,
|
||
|
|
Row,
|
||
|
|
Col,
|
||
|
|
Card,
|
||
|
|
Typography,
|
||
|
|
Space,
|
||
|
|
Statistic
|
||
|
|
} from 'antd';
|
||
|
|
import {
|
||
|
|
BellOutlined,
|
||
|
|
AlertOutlined,
|
||
|
|
InfoCircleOutlined,
|
||
|
|
SearchOutlined,
|
||
|
|
FilterOutlined,
|
||
|
|
CheckCircleOutlined,
|
||
|
|
SyncOutlined
|
||
|
|
} from '@ant-design/icons';
|
||
|
|
import { ALERTS } from '../constants';
|
||
|
|
|
||
|
|
const { Text, Title } = Typography;
|
||
|
|
|
||
|
|
export default function Alerts() {
|
||
|
|
const columns = [
|
||
|
|
{
|
||
|
|
title: '级别',
|
||
|
|
dataIndex: 'type',
|
||
|
|
key: 'type',
|
||
|
|
render: (type: string) => {
|
||
|
|
const config = {
|
||
|
|
critical: { color: 'error', text: '紧急', icon: <AlertOutlined /> },
|
||
|
|
warning: { color: 'warning', text: '警告', icon: <BellOutlined /> },
|
||
|
|
info: { color: 'processing', text: '提示', icon: <InfoCircleOutlined /> },
|
||
|
|
}[type] || { color: 'default', text: '其他', icon: <InfoCircleOutlined /> };
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Tag color={config.color} icon={config.icon} bordered={false} style={{ fontWeight: 'bold' }}>
|
||
|
|
{config.text}
|
||
|
|
</Tag>
|
||
|
|
);
|
||
|
|
},
|
||
|
|
width: 100,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '设备来源',
|
||
|
|
key: 'device',
|
||
|
|
render: (record: any) => (
|
||
|
|
<Space direction="vertical" size={0}>
|
||
|
|
<Text strong style={{ fontSize: 13 }}>{record.deviceName}</Text>
|
||
|
|
<Text type="secondary" style={{ fontSize: 10, fontFamily: 'monospace' }}>{record.deviceId}</Text>
|
||
|
|
</Space>
|
||
|
|
),
|
||
|
|
width: 180,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '内容描述',
|
||
|
|
dataIndex: 'message',
|
||
|
|
key: 'message',
|
||
|
|
render: (text: string) => <Text ellipsis style={{ maxWidth: 300 }}>{text}</Text>,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '发生时间',
|
||
|
|
dataIndex: 'time',
|
||
|
|
key: 'time',
|
||
|
|
render: (time: string) => <Text type="secondary" style={{ fontFamily: 'monospace', fontSize: 11 }}>{time}</Text>,
|
||
|
|
width: 160,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '状态',
|
||
|
|
key: 'status',
|
||
|
|
render: (record: any) => (
|
||
|
|
record.handled ?
|
||
|
|
<Text type="success" italic style={{ fontSize: 11 }}><CheckCircleOutlined /> 已归档</Text> :
|
||
|
|
<Text type="warning" strong style={{ fontSize: 11 }}><SyncOutlined spin /> 待处理</Text>
|
||
|
|
),
|
||
|
|
width: 120,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '操作',
|
||
|
|
key: 'action',
|
||
|
|
align: 'right' as const,
|
||
|
|
render: () => (
|
||
|
|
<Space>
|
||
|
|
<Button type="primary" size="small" style={{ borderRadius: 2 }}>处理</Button>
|
||
|
|
<Button type="default" size="small" style={{ borderRadius: 2 }}>忽略</Button>
|
||
|
|
</Space>
|
||
|
|
),
|
||
|
|
width: 140,
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
const summary = [
|
||
|
|
{ label: '严重故障', count: ALERTS.filter(a => a.type === 'critical').length, color: '#f5222d', icon: <AlertOutlined />, bgColor: '#fff1f0', borderColor: '#ffa39e' },
|
||
|
|
{ label: '异常警告', count: ALERTS.filter(a => a.type === 'warning').length, color: '#faad14', icon: <BellOutlined />, bgColor: '#fffbe6', borderColor: '#ffe58f' },
|
||
|
|
{ label: '状态提示', count: ALERTS.filter(a => a.type === 'info').length, color: '#1890ff', icon: <InfoCircleOutlined />, bgColor: '#e6f7ff', borderColor: '#91d5ff' },
|
||
|
|
];
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="space-y-4">
|
||
|
|
<div className="flex items-center justify-between">
|
||
|
|
<Title level={5} style={{ margin: 0 }}>警报中心: 实时检索</Title>
|
||
|
|
<Space>
|
||
|
|
<Input
|
||
|
|
prefix={<SearchOutlined style={{ color: 'rgba(0,0,0,0.25)' }} />}
|
||
|
|
placeholder="搜索设备ID或警报内容..."
|
||
|
|
style={{ width: 250, borderRadius: 2 }}
|
||
|
|
/>
|
||
|
|
<Button icon={<FilterOutlined />} style={{ borderRadius: 2 }}>
|
||
|
|
高级过滤
|
||
|
|
</Button>
|
||
|
|
</Space>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<Row gutter={16}>
|
||
|
|
{summary.map((item) => (
|
||
|
|
<Col span={8} key={item.label}>
|
||
|
|
<Card
|
||
|
|
size="small"
|
||
|
|
style={{
|
||
|
|
backgroundColor: item.bgColor,
|
||
|
|
borderColor: item.borderColor,
|
||
|
|
borderRadius: 4
|
||
|
|
}}
|
||
|
|
>
|
||
|
|
<Statistic
|
||
|
|
title={<Text strong type="secondary" style={{ fontSize: 10, textTransform: 'uppercase', opacity: 0.7 }}>{item.label}</Text>}
|
||
|
|
value={item.count}
|
||
|
|
valueStyle={{ color: item.color, fontWeight: 900, fontSize: 24 }}
|
||
|
|
prefix={React.cloneElement(item.icon, { style: { opacity: 0.4 } })}
|
||
|
|
/>
|
||
|
|
</Card>
|
||
|
|
</Col>
|
||
|
|
))}
|
||
|
|
</Row>
|
||
|
|
|
||
|
|
<Card styles={{ body: { padding: 0 } }} className="overflow-hidden">
|
||
|
|
<Table
|
||
|
|
size="small"
|
||
|
|
columns={columns}
|
||
|
|
dataSource={ALERTS.map(a => ({ ...a, key: a.id }))}
|
||
|
|
pagination={{ pageSize: 12, size: 'small' }}
|
||
|
|
/>
|
||
|
|
</Card>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|