import React, { useState, useEffect } from 'react'; import { version as appVersion } from '../../package.json'; import { Form, Input, Button, message, Typography, Alert, } from 'antd'; import { UserOutlined, LockOutlined, MailOutlined, PhoneOutlined, SafetyCertificateOutlined, CloudServerOutlined, ArrowLeftOutlined, DashboardOutlined, SecurityScanOutlined, ApiOutlined, } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../hooks/useAuth'; import './Login.css'; const { Title, Text } = Typography; const Login = () => { const [loading, setLoading] = useState(false); const [isFirstUser, setIsFirstUser] = useState(false); const [registerMode, setRegisterMode] = useState(false); const { login, register, checkAdmin } = useAuth(); const navigate = useNavigate(); useEffect(() => { checkIsFirstUser(); }, []); const checkIsFirstUser = async () => { try { const response = await checkAdmin(); if (response.success) { setIsFirstUser(!response.data.hasAdmin); } } catch (error) { console.error('检查管理员状态失败:', error); } }; const onFinishLogin = async (values) => { setLoading(true); try { const result = await login(values.username, values.password); if (result.success) { message.success('登录成功'); navigate('/dashboard'); } else { message.error(result.message); } } catch (error) { message.error('登录失败,请稍后重试'); } finally { setLoading(false); } }; const onFinishRegister = async (values) => { setLoading(true); try { const result = await register({ username: values.username, password: values.password, email: values.email, phone: values.phone, realName: values.realName, }); if (result.success) { message.success(result.isFirstUser ? '管理员账号创建成功' : '注册成功,请等待管理员审核'); if (result.isFirstUser) { setIsFirstUser(false); navigate('/dashboard'); } else { setRegisterMode(false); } } else { message.error(result.message); } } catch (error) { message.error('注册失败,请稍后重试'); } finally { setLoading(false); } }; const features = [ { icon: , title: '实时监控', desc: '3D可视化机房全景', color: '#14b8a6' }, { icon: , title: '安全可靠', desc: '多重权限防护', color: '#3b82f6' }, { icon: , title: '极速响应', desc: '毫秒级数据采集', color: '#8b5cf6' }, ]; const stats = [ { value: '99.9%', label: '可用性', icon: '↑' }, { value: '24/7', label: '监控', icon: '●' }, { value: '<100ms', label: '响应', icon: '⚡' }, ]; const RackVisual = () => (
机房概览 3 在线
{[1, 2, 3].map((rack) => (
{rack.toString().padStart(2, '0')}
{[1, 2, 3, 4, 5].map((slot) => (
))}
))}
); return (

云睿 资产管理系统

智能数据中心基础设施管理平台

{stats.map((stat, index) => (
{stat.value} {stat.label}
))}
{features.map((feature, index) => (
{feature.icon}
{feature.title} {feature.desc}
))}
🛡️ 企业级安全认证 v{appVersion}
{isFirstUser ? '初始化系统' : '欢迎回来'} {isFirstUser ? '创建管理员账号以开始使用系统' : '请登录您的账号继续访问'}
{isFirstUser && ( )} {registerMode && !isFirstUser && ( )}
{registerMode && ( <> } /> } /> } /> } /> )} {!registerMode && ( } placeholder={isFirstUser ? '请设置管理员账号' : '请输入用户名'} className="login-input" /> )} } placeholder={isFirstUser ? '请设置管理员密码' : '请输入密码'} className="login-input" /> {(registerMode || isFirstUser) && ( ({ validator(_, value) { if (!value || getFieldValue('password') === value) { return Promise.resolve(); } return Promise.reject(new Error('两次输入的密码不一致')); }, }), ]} > } placeholder="请确认密码" className="login-input" /> )} {!isFirstUser && !registerMode && (
提示:默认管理员账号通常为 admin
)}
{!isFirstUser && !registerMode && (
)}
YunRui Asset Management v{appVersion}
); }; export default Login;