初始化项目
This commit is contained in:
218
src/pages/Home.tsx
Normal file
218
src/pages/Home.tsx
Normal file
@@ -0,0 +1,218 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Card,
|
||||
Row,
|
||||
Col,
|
||||
Statistic,
|
||||
Table,
|
||||
Tag,
|
||||
Progress,
|
||||
List,
|
||||
Button,
|
||||
Typography,
|
||||
Space,
|
||||
} from 'antd';
|
||||
import {
|
||||
ThunderboltOutlined,
|
||||
DashboardOutlined,
|
||||
DotChartOutlined,
|
||||
RocketOutlined,
|
||||
BellOutlined,
|
||||
CloudUploadOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { DEVICES, ALERTS } from '../constants';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const AntdCard = Card as any;
|
||||
|
||||
export default function Home() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const stats = [
|
||||
{ title: '芯片温度', value: 32.08, icon: <DashboardOutlined />, color: '#ff4d4f', suffix: '℃' },
|
||||
{ title: '设备电流', value: 0, icon: <ThunderboltOutlined />, color: '#1677ff', suffix: 'A' },
|
||||
{ title: '设备电压', value: 0, icon: <DotChartOutlined />, color: '#fa8c16', suffix: 'V' },
|
||||
{ title: '设备数量', value: DEVICES.length, icon: <RocketOutlined />, color: '#52c41a', suffix: '' },
|
||||
{ title: '告警数量', value: ALERTS.filter(a => !a.handled).length, icon: <BellOutlined />, color: '#ff4d4f', suffix: '' },
|
||||
{ title: '上报事件', value: 1, icon: <CloudUploadOutlined />, color: '#52c41a', suffix: '' },
|
||||
];
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: 'Node / 标识',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
render: (text: string, record: any) => (
|
||||
<Space direction="vertical" size={2}>
|
||||
<Text strong style={{ fontSize: 13 }}>{text}</Text>
|
||||
<Text type="secondary" style={{ fontSize: 11, fontFamily: 'monospace' }}>{record.id}</Text>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Status / 状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 110,
|
||||
render: (status: string) => (
|
||||
<Tag
|
||||
color={status === 'online' ? 'success' : status === 'alert' ? 'error' : 'default'}
|
||||
style={{
|
||||
borderRadius: 4,
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
padding: '2px 8px'
|
||||
}}
|
||||
>
|
||||
{status.toUpperCase()}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Batt / 电量',
|
||||
dataIndex: 'battery',
|
||||
key: 'battery',
|
||||
width: 140,
|
||||
render: (percent: number) => (
|
||||
<Progress
|
||||
percent={percent}
|
||||
size="small"
|
||||
status={percent < 20 ? 'exception' : 'active'}
|
||||
strokeColor={percent < 20 ? '#ff4d4f' : '#52c41a'}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Load / 负载',
|
||||
dataIndex: 'cpu',
|
||||
key: 'cpu',
|
||||
width: 100,
|
||||
render: (cpu: number) => (
|
||||
<Text style={{ fontFamily: 'monospace', fontSize: 12 }}>{cpu}%</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Ping / 延迟',
|
||||
key: 'ping',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: () => <Text style={{ fontFamily: 'monospace', fontSize: 12 }}>12ms</Text>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: '16px' }}>
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
{stats.map((stat, idx) => (
|
||||
<Col xs={12} sm={12} md={8} lg={4} xl={4} key={idx}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
bordered={false}
|
||||
hoverable
|
||||
style={{
|
||||
borderRadius: 10,
|
||||
boxShadow: '0 2px 12px rgba(0,0,0,0.06)',
|
||||
transition: 'all 0.3s',
|
||||
}}
|
||||
bodyStyle={{ padding: '16px 14px' }}
|
||||
>
|
||||
<Statistic
|
||||
title={<span style={{ fontSize: 12, color: '#666', fontWeight: 500 }}>{stat.title}</span>}
|
||||
value={stat.value}
|
||||
precision={idx === 0 ? 2 : 0}
|
||||
valueStyle={{
|
||||
color: '#1f2329',
|
||||
fontWeight: 600,
|
||||
fontSize: 22,
|
||||
marginTop: 4,
|
||||
}}
|
||||
prefix={React.cloneElement(stat.icon as React.ReactElement, {
|
||||
style: { color: stat.color, fontSize: 16, marginRight: 6 },
|
||||
})}
|
||||
suffix={<span style={{ fontSize: 13, color: '#888' }}>{stat.suffix}</span>}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 4 }}>
|
||||
{/* 设备表格 */}
|
||||
<Col xs={24} lg={16}>
|
||||
<Card
|
||||
title={<span style={{ fontSize: 14, fontWeight: 600 }}>核心节点实时清单</span>}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 10, boxShadow: '0 2px 12px rgba(0,0,0,0.06)' }}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<Table
|
||||
size="middle"
|
||||
columns={columns}
|
||||
dataSource={DEVICES.map(d => ({ ...d, key: d.id }))}
|
||||
pagination={false}
|
||||
onRow={(record) => ({
|
||||
onClick: () => navigate('/devices'),
|
||||
style: { cursor: 'pointer' },
|
||||
})}
|
||||
rowHoverable
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 告警列表 */}
|
||||
<Col xs={24} lg={8}>
|
||||
<Card
|
||||
title={<span style={{ fontSize: 14, fontWeight: 600 }}>当日重点警报</span>}
|
||||
extra={
|
||||
<Button type="text" danger size="small" style={{ fontWeight: 500 }}>
|
||||
一键清除
|
||||
</Button>
|
||||
}
|
||||
bordered={false}
|
||||
style={{ borderRadius: 10, boxShadow: '0 2px 12px rgba(0,0,0,0.06)' }}
|
||||
bodyStyle={{ padding: 0, height: 460, overflowY: 'auto' }}
|
||||
>
|
||||
<List
|
||||
dataSource={ALERTS.slice(0, 10)}
|
||||
renderItem={(alert) => (
|
||||
<List.Item
|
||||
style={{
|
||||
padding: '12px 16px',
|
||||
borderBottom: '1px solid #f5f5f5',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
hoverable
|
||||
>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
|
||||
<Tag
|
||||
color={alert.type === 'critical' ? 'error' : alert.type === 'warning' ? 'warning' : 'processing'}
|
||||
style={{
|
||||
borderRadius: 4,
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
padding: '0 6px',
|
||||
}}
|
||||
>
|
||||
{alert.type}
|
||||
</Tag>
|
||||
<Text type="secondary" style={{ fontSize: 11 }}>
|
||||
{alert.time.split(' ')[1]}
|
||||
</Text>
|
||||
</div>
|
||||
<Text style={{ fontSize: 13, fontWeight: 500, lineHeight: 1.4 }}>
|
||||
{alert.message}
|
||||
</Text>
|
||||
<Text type="secondary" style={{ fontSize: 11, marginTop: 4, display: 'block' }}>
|
||||
设备:{alert.deviceName}
|
||||
</Text>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user