| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 1 | // import React, { useState } from 'react'; |
| 2 | // import '../../pages/AuthPage/AuthPage.css'; |
| 3 | // import image from './logo.svg'; // 引入图片 |
| 4 | // const Login = ({ onRegisterClick }) => { |
| 5 | // const [formData, setFormData] = useState({ |
| 6 | // username: '', |
| 7 | // password: '' |
| 8 | // }); |
| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 9 | |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 10 | // const handleChange = (e) => { |
| 11 | // const { name, value } = e.target; |
| 12 | // setFormData(prev => ({ ...prev, [name]: value })); |
| 13 | // }; |
| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 14 | |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 15 | // const handleSubmit = async (e) => { |
| 16 | // e.preventDefault(); |
| 17 | // try { |
| 18 | // const response = await fetch('http://localhost:8080/user/login', { |
| 19 | // method: 'POST', |
| 20 | // headers: { |
| 21 | // 'Content-Type': 'application/json', |
| 22 | // }, |
| 23 | // body: JSON.stringify(formData), |
| 24 | // }); |
| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 25 | |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 26 | // const result = await response.json(); |
| 27 | // if (response.ok && result.code === "0") { |
| 28 | // console.log('登录成功:', result); |
| 29 | // // 处理成功逻辑 |
| 30 | // } else { |
| 31 | // console.error('登录失败:', result); |
| 32 | // // 处理失败逻辑 |
| 33 | // } |
| 34 | // } catch (error) { |
| 35 | // console.error('请求错误:', error); |
| 36 | // // 处理请求错误 |
| 37 | // } |
| 38 | // }; |
| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 39 | |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 40 | // return ( |
| 41 | // <div className="auth-container"> |
| 42 | // <img |
| 43 | // src={image} |
| 44 | // alt="描述" |
| 45 | // style={{ width: '30%', height: 'auto'}} |
| 46 | // /> |
| 47 | // <div className="auth-form-section"> |
| 48 | // {/* <h3>欢迎来到EchoTorent !</h3> */} |
| 49 | // <h3>用户登录</h3> |
| 50 | // <form onSubmit={handleSubmit}> |
| 51 | // <div className="form-group"> |
| 52 | // <label>用户名</label> |
| 53 | // <input |
| 54 | // type="text" |
| 55 | // name="username" |
| 56 | // placeholder="请输入用户名" |
| 57 | // value={formData.username} |
| 58 | // onChange={handleChange} |
| 59 | // className="form-input" |
| 60 | // /> |
| 61 | // </div> |
| 62 | // <div className="form-group"> |
| 63 | // <label>密码</label> |
| 64 | // <input |
| 65 | // type="password" |
| 66 | // name="password" |
| 67 | // placeholder="请输入密码" |
| 68 | // value={formData.password} |
| 69 | // onChange={handleChange} |
| 70 | // className="form-input" |
| 71 | // /> |
| 72 | // <button |
| 73 | // type="button" |
| 74 | // className="link-button forgot-password" |
| 75 | // onClick={() => console.log('跳转到忘记密码页面')} |
| 76 | // > |
| 77 | // 忘记密码? |
| 78 | // </button> |
| 79 | // </div> |
| 80 | // <button type="submit" className="auth-button"> |
| 81 | // 登录 |
| 82 | // </button> |
| 83 | // <p className="register-link"> |
| 84 | // 没有账号? |
| 85 | // <button onClick={onRegisterClick} className="link-button"> |
| 86 | // 点击注册 |
| 87 | // </button> |
| 88 | // </p> |
| 89 | // </form> |
| 90 | // </div> |
| 91 | // </div> |
| 92 | // ); |
| 93 | // }; |
| Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 94 | |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 95 | // export default Login; |
| 96 | |
| 97 | |
| 98 | // import React, { useState } from 'react'; |
| 99 | // import '../../pages/AuthPage/AuthPage.css'; |
| 100 | // import image from './logo.svg'; |
| 101 | |
| Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame^] | 102 | // |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 103 | |
| 104 | // const Login = ({ onRegisterClick }) => { |
| 105 | // const [formData, setFormData] = useState({ |
| 106 | // username: '', |
| 107 | // password: '' |
| 108 | // }); |
| 109 | // const [error, setError] = useState(''); |
| 110 | // const [isSubmitting, setIsSubmitting] = useState(false); |
| 111 | |
| 112 | // const handleSubmit = async (e) => { |
| 113 | // e.preventDefault(); |
| 114 | // setIsSubmitting(true); |
| 115 | // setError(''); |
| 116 | |
| 117 | // try { |
| Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame^] | 118 | // const response = await fetch(`/user/login`, { |
| Krishya | 57cc17b | 2025-05-26 16:43:34 +0800 | [diff] [blame] | 119 | // method: 'POST', |
| 120 | // headers: { |
| 121 | // 'Content-Type': 'application/json', |
| 122 | // }, |
| 123 | // body: JSON.stringify(formData), |
| 124 | // }); |
| 125 | |
| 126 | // const result = await response.json(); |
| 127 | |
| 128 | // if (!response.ok) { |
| 129 | // throw new Error(result.message || '登录失败'); |
| 130 | // } |
| 131 | |
| 132 | // console.log('登录成功:', result); |
| 133 | // // 这里可以添加登录成功后的跳转逻辑 |
| 134 | // alert('登录成功!'); |
| 135 | // } catch (error) { |
| 136 | // console.error('登录错误:', error); |
| 137 | // setError(error.message || '登录过程中出现错误'); |
| 138 | // } finally { |
| 139 | // setIsSubmitting(false); |
| 140 | // } |
| 141 | // }; |
| 142 | |
| 143 | // const handleChange = (e) => { |
| 144 | // const { name, value } = e.target; |
| 145 | // setFormData(prev => ({ ...prev, [name]: value })); |
| 146 | // }; |
| 147 | |
| 148 | // return ( |
| 149 | // <div className="auth-container"> |
| 150 | // <img |
| 151 | // src={image} |
| 152 | // alt="网站Logo" |
| 153 | // style={{ width: '30%', height: 'auto' }} |
| 154 | // /> |
| 155 | // <div className="auth-form-section"> |
| 156 | // <h3>用户登录</h3> |
| 157 | // {error && <div className="error-message">{error}</div>} |
| 158 | // <form onSubmit={handleSubmit}> |
| 159 | // <div className="form-group"> |
| 160 | // <label>用户名</label> |
| 161 | // <input |
| 162 | // type="text" |
| 163 | // name="username" |
| 164 | // placeholder="请输入用户名" |
| 165 | // value={formData.username} |
| 166 | // onChange={handleChange} |
| 167 | // className="form-input" |
| 168 | // required |
| 169 | // /> |
| 170 | // </div> |
| 171 | // <div className="form-group"> |
| 172 | // <label>密码</label> |
| 173 | // <input |
| 174 | // type="password" |
| 175 | // name="password" |
| 176 | // placeholder="请输入密码" |
| 177 | // value={formData.password} |
| 178 | // onChange={handleChange} |
| 179 | // className="form-input" |
| 180 | // required |
| 181 | // /> |
| 182 | // <button |
| 183 | // type="button" |
| 184 | // className="link-button forgot-password" |
| 185 | // onClick={() => console.log('跳转到忘记密码页面')} |
| 186 | // > |
| 187 | // 忘记密码? |
| 188 | // </button> |
| 189 | // </div> |
| 190 | // <button |
| 191 | // type="submit" |
| 192 | // className="auth-button" |
| 193 | // disabled={isSubmitting} |
| 194 | // > |
| 195 | // {isSubmitting ? '登录中...' : '登录'} |
| 196 | // </button> |
| 197 | // <p className="register-link"> |
| 198 | // 没有账号?{' '} |
| 199 | // <button |
| 200 | // type="button" |
| 201 | // onClick={onRegisterClick} |
| 202 | // className="link-button" |
| 203 | // > |
| 204 | // 点击注册 |
| 205 | // </button> |
| 206 | // </p> |
| 207 | // </form> |
| 208 | // </div> |
| 209 | // </div> |
| 210 | // ); |
| 211 | // }; |
| 212 | |
| 213 | // export default Login; |