blob: 25bf6dc7de1e2499565f3eaf1d8974020e250875 [file] [log] [blame]
22301014bc4616f2025-06-03 16:59:44 +08001import { MailOutlined, LockOutlined } from '@ant-design/icons';
2import { Button, Form, Input, message, Row, Col } from 'antd';
3import { NavLink } from 'react-router';
4import { useState, useEffect } from 'react';
5
6function Forget() {
7 const [countdown, setCountdown] = useState(0);
8 const [emailSent,] = useState(false);
9
10 const onFinish = async () => {
11
12 };
13
14 useEffect(() => {
15 let countdownTimer = null;
16
17 if (countdown > 0) {
18 countdownTimer = setTimeout(() => {
19 setCountdown(prev => prev - 1);
20 }, 1000);
21 }
22
23 return () => {
24 if (countdownTimer) {
25 clearTimeout(countdownTimer);
26 }
27 };
28 }, [countdown]);
29
30 const resendCode = () => {
31 if (countdown > 0) return;
32 setCountdown(60);
33 message.info('验证码已重新发送');
34 };
35
36 return (
37 <Form
38 name="forget"
39 initialValues={{ remember: true }}
40 style={{ maxWidth: 360 }}
41 onFinish={onFinish}
42 >
43 <h2>重置密码</h2>
44 <p>请输入您注册时使用的邮箱地址</p>
45
46 <Form.Item
47 name="email"
48 rules={[
49 { required: true, message: '请输入您的邮箱!' },
50 { type: 'email', message: '请输入正确的邮箱格式' }
51 ]}
52 >
53 <Input prefix={<MailOutlined />} placeholder="注册邮箱" />
54 </Form.Item>
55
56 {emailSent && (
57 <>
58 <Form.Item
59 name="code"
60 rules={[{ required: true, message: '请输入验证码!' }]}
61 >
62 <Row gutter={8}>
63 <Col span={16}>
64 <Input placeholder="验证码" />
65 </Col>
66 <Col span={8}>
67 <Button
68 disabled={countdown > 0}
69 onClick={resendCode}
70 style={{ width: '100%' }}
71 >
72 {countdown > 0 ? `${countdown}s后重试` : '重新发送'}
73 </Button>
74 </Col>
75 </Row>
76 </Form.Item>
77
78 <Form.Item
79 name="password"
80 rules={[
81 { required: true, message: '请设置新密码!' },
82 { min: 6, message: '密码长度至少为6位' }
83 ]}
84 >
85 <Input.Password prefix={<LockOutlined />} placeholder="新密码" />
86 </Form.Item>
87
88 <Form.Item
89 name="confirmPassword"
90 dependencies={['password']}
91 rules={[
92 { required: true, message: '请确认新密码!' },
93 ({ getFieldValue }) => ({
94 validator(_, value) {
95 if (!value || getFieldValue('password') === value) {
96 return Promise.resolve();
97 }
98 return Promise.reject(new Error('两次输入的密码不一致!'));
99 },
100 }),
101 ]}
102 >
103 <Input.Password prefix={<LockOutlined />} placeholder="确认新密码" />
104 </Form.Item>
105 </>
106 )}
107
108 <Form.Item>
109 <Button block type="primary" htmlType="submit">
110 {emailSent ? '确认重置' : '获取验证码'}
111 </Button>
112 <NavLink to='/login'>返回登录</NavLink>
113 </Form.Item>
114 </Form>
115 );
116}
117
118export default Forget;