Files
aurak/web/components/LoginPage.tsx
T
Developer ffe365201a fix(ui): 统一设计语言——颜色、字号、间距、控件样式
UI 修正清单:
┌────────────────────────────────────────────────────────────┐
│ 问题                     │ 修复                          │
├──────────────────────────┼────────────────────────────────┤
│ 登录页 blue → 不一致     │ 统一改为 indigo 系             │
│ text-[10px] 标签难读     │ → text-xs (设置页所有标签)     │
│ text-[9px] 徽章太小      │ → text-xs (角色/租户/权限)    │
│ text-[14px] 输入框不统一  │ → text-sm (编辑弹窗)          │
│ py-3 vs py-3.5 不一致    │ → py-3 统一 (所有输入框)      │
│ 表格头 py-4 过大         │ → py-3                        │
│ 编辑弹窗 max-w-md 太窄   │ → max-w-lg (更宽松)           │
│ 操作列 opacity-0 隐藏     │ → opacity-60 始终可见         │
│ 原生 checkbox 不匹配      │ → 自定义圆角 checkbox + Check  │
│ 登录页 rounded-lg         │ → rounded-xl 统一             │
│ 登录按钮缺阴影            │ → 加 shadow-lg                │
└────────────────────────────────────────────────────────────┘

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 10:28:49 +08:00

97 lines
3.2 KiB
TypeScript

import React, { useState } from 'react';
import { useLanguage } from '../contexts/LanguageContext';
import { ShieldCheck, ArrowRight } from 'lucide-react';
import { authService } from '../services/authService';
interface LoginPageProps {
onLoginSuccess: (token: string) => void;
}
const LoginPage: React.FC<LoginPageProps> = ({ onLoginSuccess }) => {
const { t } = useLanguage();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
if (!username.trim() || !password.trim()) {
setError(t('loginError'));
return;
}
setError('');
try {
const response = await authService.login(username, password);
onLoginSuccess(response.access_token);
} catch (err) {
setError(err.message || 'Login failed.');
}
};
return (
<div className="min-h-screen bg-slate-50 flex flex-col items-center justify-center p-4">
<div className="max-w-md w-full bg-white rounded-2xl shadow-xl p-8 border border-slate-100">
<div className="flex justify-center mb-6">
<div className="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-600">
<ShieldCheck className="w-8 h-8" />
</div>
</div>
<h1 className="text-2xl font-bold text-slate-900 text-center mb-2">
{t('loginTitle')}
</h1>
<p className="text-slate-500 text-center mb-8">
{t('loginDesc')}
</p>
<form onSubmit={handleLogin} className="space-y-4">
<div>
<input
type="text"
value={username}
onChange={(e) => {
setUsername(e.target.value);
setError('');
}}
className="w-full px-4 py-3 rounded-xl border border-slate-300 focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 outline-none transition-all"
placeholder={t('usernamePlaceholder') || 'Username'}
/>
</div>
<div>
<input
type="password"
value={password}
onChange={(e) => {
setPassword(e.target.value);
setError('');
}}
className="w-full px-4 py-3 rounded-xl border border-slate-300 focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 outline-none transition-all"
placeholder={t('passwordPlaceholder') || 'Password'}
/>
{error && <p className="text-red-500 text-sm mt-1 ml-1">{error}</p>}
</div>
<button
type="submit"
className="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-semibold py-3 rounded-xl flex items-center justify-center gap-2 transition-transform active:scale-95 shadow-lg shadow-indigo-200"
>
{t('loginButton')}
<ArrowRight className="w-4 h-4" />
</button>
</form>
<div className="mt-8 text-center">
<p className="text-xs text-slate-400">
Authorized Personnel Only
</p>
</div>
</div>
</div>
);
};
export default LoginPage;