import { useState } from 'react' import { Link } from 'react-router-dom' export default function RegisterPage() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [error, setError] = useState('') const [success, setSuccess] = useState('') const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') setSuccess('') if (password !== confirmPassword) { setError('两次密码不一致') return } setLoading(true) try { const res = await fetch('/api/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) }) const data = await res.json() if (res.ok) { setSuccess('注册成功,请登录') setTimeout(() => { window.location.href = '/login' }, 1500) } else { setError(data.error || '注册失败') } } catch { setError('网络错误,请重试') } finally { setLoading(false) } } return (
AC

AntiCaptcha

验证码识别服务平台

注册

setUsername(e.target.value)} placeholder="请输入用户名" required />
setPassword(e.target.value)} placeholder="请输入密码" required />
setConfirmPassword(e.target.value)} placeholder="请再次输入密码" required />
{error &&
{error}
} {success &&
{success}
}
已有账号?{' '} 立即登录
) }