import { type FormEvent, useState } from 'react' import { useNavigate, Link } from 'react-router-dom' import { useAuth } from '../hooks/useAuth' import Button from '../components/ui/Button' import toast from '../components/ui/Toast' export default function LoginPage() { const { login } = useAuth() const navigate = useNavigate() const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState('') const handleSubmit = async (e: FormEvent) => { e.preventDefault() setError('') setLoading(true) try { await login(username, password) toast.success('登录成功') navigate('/dashboard', { replace: true }) } catch (err: any) { const status = err?.response?.status const detail = err?.response?.data?.detail ?? '登录失败' if (status === 423) { setError('账户已锁定,请 15 分钟后再试') } else if (status === 401) { setError('用户名或密码错误') } else { setError(detail) } } finally { setLoading(false) } } return (
Hive Manage v3
{/* Error */} {error && (还没有账号?{' '} 注册