import React, { useState } from 'react'; import styled from 'styled-components'; import { login } from '../services/api'; const LoginContainer = styled.div` background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); border-radius: 20px; padding: 40px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); width: 100%; max-width: 400px; text-align: center; `; const Title = styled.h1` color: #333; margin-bottom: 30px; font-size: 28px; font-weight: 300; `; const Form = styled.form` display: flex; flex-direction: column; gap: 20px; `; const Input = styled.input` padding: 15px 20px; border: 2px solid #e1e5e9; border-radius: 12px; font-size: 16px; transition: all 0.3s ease; outline: none; &:focus { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); } &::placeholder { color: #a0a0a0; } `; const Button = styled.button` background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; padding: 15px 20px; border-radius: 12px; font-size: 16px; font-weight: 500; cursor: pointer; transition: all 0.3s ease; margin-top: 10px; &:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3); } &:disabled { opacity: 0.6; cursor: not-allowed; transform: none; } `; const ErrorMessage = styled.div` color: #e74c3c; font-size: 14px; margin-top: 10px; padding: 10px; background: rgba(231, 76, 60, 0.1); border-radius: 8px; `; const Hint = styled.div` color: #666; font-size: 14px; margin-top: 20px; padding: 15px; background: rgba(102, 126, 234, 0.1); border-radius: 8px; border-left: 4px solid #667eea; `; function LoginForm({ onLogin }) { const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); setError(''); try { const response = await login(password); onLogin(response.token); } catch (err) { setError(err.response?.data?.error || '登录失败,请重试'); } finally { setLoading(false); } }; return ( 工作待办
setPassword(e.target.value)} required />
{error && {error}} 💡 提示:首次使用需要输入访问密码
); } export default LoginForm;