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 (
验证码识别服务平台