添加了相关测试文件,引入Tailwindcss
Change-Id: I12054143571bb688590af0357125a0ed26ff2050
diff --git a/src/pages/Register.jsx b/src/pages/Register.jsx
new file mode 100644
index 0000000..65de07e
--- /dev/null
+++ b/src/pages/Register.jsx
@@ -0,0 +1,118 @@
+import React, { useState } from 'react';
+import { useNavigate, Link } from 'react-router-dom';
+import { Form, Input, Button, Card, message, Typography, Divider } from 'antd';
+import { UserOutlined, LockOutlined, MailOutlined } from '@ant-design/icons';
+import axios from 'axios';
+// 删除 import './Register.css';
+
+const { Title, Text } = Typography;
+
+const Register = () => {
+ const [loading, setLoading] = useState(false);
+ const navigate = useNavigate();
+
+ const onFinish = async (values) => {
+ setLoading(true);
+ try {
+ const response = await axios.post('/api/auth/register', {
+ username: values.username,
+ email: values.email,
+ password: values.password
+ });
+
+ if (response.data.code === 200) {
+ message.success('注册成功!');
+ navigate('/login');
+ } else {
+ message.error(response.data.message || '注册失败');
+ }
+ } catch (error) {
+ console.error('注册错误:', error);
+ message.error('注册失败,请检查网络连接');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+ <div className="flex justify-center items-center min-h-screen bg-gray-100">
+ <Card className="w-full max-w-md">
+ <div className="text-center mb-6">
+ <Title level={2} className="mb-3">注册账号</Title>
+ <Text type="secondary">创建您的PT网站账号</Text>
+ </div>
+
+ <Form
+ name="register"
+ onFinish={onFinish}
+ size="large"
+ layout="vertical"
+ >
+ <Form.Item
+ name="username"
+ rules={[
+ { required: true, message: '请输入用户名!' },
+ { min: 3, message: '用户名至少3个字符' },
+ { max: 20, message: '用户名最多20个字符' }
+ ]}
+ >
+ <Input prefix={<UserOutlined />} placeholder="用户名" />
+ </Form.Item>
+
+ <Form.Item
+ name="email"
+ rules={[
+ { required: true, message: '请输入邮箱!' },
+ { type: 'email', message: '请输入有效的邮箱地址!' }
+ ]}
+ >
+ <Input prefix={<MailOutlined />} placeholder="邮箱" />
+ </Form.Item>
+
+ <Form.Item
+ name="password"
+ rules={[
+ { required: true, message: '请输入密码!' },
+ { min: 6, message: '密码至少6个字符' }
+ ]}
+ >
+ <Input.Password prefix={<LockOutlined />} placeholder="密码" />
+ </Form.Item>
+
+ <Form.Item
+ name="confirm"
+ dependencies={['password']}
+ rules={[
+ { required: true, message: '请确认密码!' },
+ ({ getFieldValue }) => ({
+ validator(_, value) {
+ if (!value || getFieldValue('password') === value) {
+ return Promise.resolve();
+ }
+ return Promise.reject(new Error('两次输入的密码不一致!'));
+ },
+ }),
+ ]}
+ >
+ <Input.Password prefix={<LockOutlined />} placeholder="确认密码" />
+ </Form.Item>
+
+ <Form.Item>
+ <Button type="primary" htmlType="submit" className="w-full" loading={loading}>
+ 注册
+ </Button>
+ </Form.Item>
+
+ <Divider plain>或者</Divider>
+
+ <div className="text-center mt-2">
+ <Text type="secondary">已有账号?</Text>
+ <Link to="/login">立即登录</Link>
+ </div>
+ </Form>
+ </Card>
+ </div>
+ );
+};
+
+export default Register;
\ No newline at end of file