import React, { useState, useEffect } from 'react'; import { Card, Row, Col, Statistic, Spin, message } from 'antd'; import { DatabaseOutlined, CloudServerOutlined, WarningOutlined, PoweroffOutlined } from '@ant-design/icons'; import axios from 'axios'; function Dashboard() { const [stats, setStats] = useState({ totalDevices: 0, totalRacks: 0, totalRooms: 0, faultDevices: 0 }); const [loading, setLoading] = useState(true); useEffect(() => { // 获取统计数据 const fetchStats = async () => { try { setLoading(true); // 获取所有设备 const devicesRes = await axios.get('/api/devices'); // 设备API返回的是包含devices数组的对象 const devices = devicesRes.data.devices || devicesRes.data; const totalDevices = devices.length; const faultDevices = devices.filter(device => device.status === 'fault').length; // 获取所有机柜 const racksRes = await axios.get('/api/racks'); const racks = racksRes.data; const totalRacks = racks.length; // 获取所有机房 const roomsRes = await axios.get('/api/rooms'); const rooms = roomsRes.data; const totalRooms = rooms.length; setStats({ totalDevices, totalRacks, totalRooms, faultDevices }); } catch (error) { message.error('获取统计数据失败'); console.error('获取统计数据失败:', error); } finally { setLoading(false); } }; fetchStats(); }, []); return (

仪表盘

} loading={loading} /> } loading={loading} /> } loading={loading} /> } valueStyle={{ color: '#cf1322' }} loading={loading} />

欢迎使用IDC设备管理系统!

本系统用于管理IDC机房中的设备、机柜和机房信息,提供设备状态监控、资源分配等功能。

); } export default Dashboard;