| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 1 | import React, { useState } from 'react'; |
| Krishya | 1df0589 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 2 | import '../../pages/AuthPage/AuthPage.css'; |
| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 3 | import image from './logo.svg'; // 引入图片 |
| 4 | |
| 5 | const Register = ({ onLoginClick }) => { |
| 6 | const [formData, setFormData] = useState({ |
| 7 | username: '', |
| 8 | password: '', |
| 9 | email: '' |
| 10 | }); |
| 11 | const [verificationCode, setVerificationCode] = useState(''); |
| 12 | |
| 13 | const handleSubmit = async (e) => { |
| 14 | e.preventDefault(); |
| 15 | // 注册逻辑 |
| 16 | }; |
| 17 | |
| 18 | const verifyEmailCode = async () => { |
| 19 | try { |
| 20 | const response = await fetch('http://localhost:8080/user/verify-code', { |
| 21 | method: 'POST', |
| 22 | headers: { |
| 23 | 'Content-Type': 'application/json', |
| 24 | }, |
| 25 | body: JSON.stringify({ |
| 26 | email: formData.email, |
| 27 | code: verificationCode, |
| 28 | }), |
| 29 | }); |
| 30 | |
| 31 | const result = await response.json(); |
| 32 | if (response.ok && result.code === "0") { |
| 33 | console.log('邮箱验证成功:', result.msg); |
| 34 | // 处理成功逻辑 |
| 35 | } else { |
| 36 | console.error('邮箱验证失败:', result.msg); |
| 37 | // 处理失败逻辑 |
| 38 | } |
| 39 | } catch (error) { |
| 40 | console.error('请求错误:', error); |
| 41 | // 处理请求错误 |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | return ( |
| 47 | <div className="auth-container"> |
| 48 | <img |
| 49 | src={image} |
| 50 | alt="描述" |
| 51 | style={{ width: '30%', height: 'auto'}} |
| 52 | /> |
| 53 | <div className="auth-form-section"> |
| 54 | <h3>用户注册</h3> |
| 55 | <form onSubmit={handleSubmit}> |
| 56 | <div className="form-group"> |
| 57 | <label>用户名</label> |
| 58 | <input |
| 59 | type="text" |
| 60 | className="form-input" |
| 61 | placeholder="请输入用户名" |
| 62 | value={formData.username} |
| 63 | onChange={(e) => setFormData({ ...formData, username: e.target.value })} |
| 64 | required |
| 65 | /> |
| 66 | </div> |
| 67 | <div className="form-group"> |
| 68 | <label>密码</label> |
| 69 | <input |
| 70 | type="password" |
| 71 | className="form-input" |
| 72 | placeholder="请输入密码" |
| 73 | value={formData.password} |
| 74 | onChange={(e) => setFormData({ ...formData, password: e.target.value })} |
| 75 | required |
| 76 | /> |
| 77 | </div> |
| 78 | <div className="form-group"> |
| 79 | <label>邮箱</label> |
| 80 | <div style={{ display: 'flex', alignItems: 'center' }}> |
| 81 | <input |
| 82 | type="email" |
| 83 | className="form-input" |
| 84 | placeholder="请输入邮箱" |
| 85 | value={formData.email} |
| 86 | onChange={(e) => setFormData({ ...formData, email: e.target.value })} |
| 87 | required |
| 88 | style={{ flex: 1, marginRight: '10px' }} |
| 89 | /> |
| 90 | <button type="button" onClick={verifyEmailCode} className="verify-button"> |
| 91 | 验证邮箱 |
| 92 | </button> |
| 93 | </div> |
| 94 | </div> |
| 95 | <div className="form-group"> |
| 96 | <label>验证码</label> |
| 97 | <input |
| 98 | type="text" |
| 99 | className="form-input" |
| 100 | placeholder="请输入邮箱验证码" |
| 101 | value={verificationCode} |
| 102 | onChange={(e) => setVerificationCode(e.target.value)} |
| 103 | required |
| 104 | /> |
| 105 | </div> |
| 106 | <button type="submit" className="auth-button"> |
| 107 | 注册 |
| 108 | </button> |
| 109 | <p className="login-link"> |
| 110 | 已有账号? |
| 111 | <button onClick={onLoginClick} className="link-button"> |
| 112 | 点击登录 |
| 113 | </button> |
| 114 | </p> |
| 115 | </form> |
| 116 | </div> |
| 117 | </div> |
| 118 | ); |
| 119 | }; |
| 120 | |
| 121 | export default Register; |