import { useState } from 'react' import { Shield, Lock, AlertCircle, Loader2, LogIn } from 'lucide-react' import { api, setToken } from '@/lib/api' import { setStoredUser } from '@/lib/auth' interface LoginFormProps { onSuccess: () => void } export function LoginForm({ onSuccess }: LoginFormProps) { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') if (!username.trim() || !password.trim()) { setError('请输入用户名和密码') return } setLoading(true) try { const res = await api.login({ username: username.trim(), password }) setToken(res.token) setStoredUser(res.user) onSuccess() } catch (err: any) { setError(err?.message || '登录失败,请稍后重试') } finally { setLoading(false) } } return (

登录账号

请输入用户名和密码进入系统。

setUsername(e.target.value)} className="w-full pl-9 pr-3 py-2.5 rounded-input bg-base border border-border text-sm focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30 transition-all" />
setPassword(e.target.value)} className="w-full pl-9 pr-3 py-2.5 rounded-input bg-base border border-border text-sm focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30 transition-all" />
{error && (
{error}
)}
没有账号?请联系管理员创建
) } // 简单内联 motion 组件,避免引入 framer-motion 依赖 const motion = { div: ({ children, className, ...props }: any) => { return (
{ if (el && props.initial) { el.style.opacity = String(props.initial.opacity ?? 1) el.style.transform = `translateY(${props.initial.y ?? 0}px)` requestAnimationFrame(() => { el.style.transition = `all ${props.transition?.duration ?? 0.3}s ${(props.transition?.ease || [0.16, 1, 0.3, 1]).join(',')}` el.style.opacity = String(props.animate?.opacity ?? 1) el.style.transform = `translateY(${props.animate?.y ?? 0}px)` }) } }} className={className} > {children}
) }, }