import React, { useState } from 'react'; import styled from 'styled-components'; import { useNavigate } from 'react-router-dom'; const Container = styled.div` max-width: 400px; margin: 50px auto; padding: 30px; background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); `; const Title = styled.h2` text-align: center; margin-bottom: 30px; color: #333; `; const Form = styled.form` display: flex; flex-direction: column; gap: 15px; `; const InputGroup = styled.div` display: flex; flex-direction: column; gap: 5px; `; const Label = styled.label` font-weight: 500; color: #555; `; const Input = styled.input` padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; &:focus { outline: none; border-color: #667eea; } `; const Button = styled.button` padding: 12px; background: #667eea; color: white; border: none; border-radius: 4px; font-size: 16px; font-weight: 500; cursor: pointer; transition: background 0.2s; &:hover { background: #5568d3; } `; const Link = styled.a` text-align: center; color: #667eea; text-decoration: none; font-size: 14px; &:hover { text-decoration: underline; } `; const RegisterPage = () => { const navigate = useNavigate(); const [username, setUsername] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); setError(''); if (password !== confirmPassword) { setError('两次输入的密码不一致'); return; } // TODO: 调用注册 API console.log('Register:', { username, email, password }); navigate('/login'); }; return ( 注册
{error && (
{error}
)} setUsername(e.target.value)} placeholder="请输入用户名" required /> setEmail(e.target.value)} placeholder="请输入邮箱" required /> setPassword(e.target.value)} placeholder="请输入密码" required /> setConfirmPassword(e.target.value)} placeholder="请再次输入密码" required />
已有账号?立即登录
); }; export default RegisterPage;