import { useState, useEffect } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { User, Lock, LogIn, AlertCircle, Loader2 } from 'lucide-react'; import StarBackground from '@/shared/components/StarBackground'; import { iamLogin, saveSession } from '@/shared/services/iamAuth'; import { useTheme } from '@/shared/context/ThemeContext'; const inputStyle = (isDark: boolean): React.CSSProperties => ({ width: '100%', boxSizing: 'border-box', padding: '12px 14px 12px 42px', borderRadius: 10, border: `1px solid ${isDark ? 'rgba(0,212,255,0.25)' : 'rgba(0,0,0,0.12)'}`, background: isDark ? 'rgba(0,212,255,0.06)' : '#fff', color: isDark ? '#e8f4ff' : '#1e293b', fontSize: 14, outline: 'none', transition: 'border-color 0.2s, box-shadow 0.2s', }); const iconStyle = (isDark: boolean): React.CSSProperties => ({ position: 'absolute', left: 14, top: '50%', transform: 'translateY(-50%)', color: isDark ? 'rgba(0,212,255,0.6)' : '#94a3b8', }); export default function LoginPage() { const navigate = useNavigate(); const location = useLocation(); const { theme } = useTheme(); const isDark = theme === 'dark'; const [userId, setUserId] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); useEffect(() => { document.body.style.overflow = 'auto'; return () => { document.body.style.overflow = ''; }; }, []); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); if (!userId.trim() || !password) { setError('请输入账号和密码'); return; } setLoading(true); setError(''); try { const result = await iamLogin({ userId: userId.trim(), password }); saveSession(result.token, result.userInfo); // 回跳原页面(RequireAuth 记录的 from),否则去首页 const from = (location.state as { from?: string })?.from ?? '/'; navigate(from, { replace: true }); } catch (ex) { setError(ex instanceof Error ? ex.message : '登录失败,请稍后重试'); } finally { setLoading(false); } }; return (
{isDark ? : (
)}
{/* 品牌区 */}
Digiwin

EIOSpace

企业智能 · 数据驱动 · 产业赋能

{/* 登录表单 */}
setUserId(e.target.value)} placeholder="请输入账号" autoComplete="username" style={inputStyle(isDark)} onFocus={(e) => { e.currentTarget.style.borderColor = '#00d4ff'; }} onBlur={(e) => { e.currentTarget.style.borderColor = isDark ? 'rgba(0,212,255,0.25)' : 'rgba(0,0,0,0.12)'; }} />
setPassword(e.target.value)} placeholder="请输入密码" autoComplete="current-password" style={inputStyle(isDark)} onFocus={(e) => { e.currentTarget.style.borderColor = '#00d4ff'; }} onBlur={(e) => { e.currentTarget.style.borderColor = isDark ? 'rgba(0,212,255,0.25)' : 'rgba(0,0,0,0.12)'; }} />
{error && (
{error}
)}

鼎捷云统一身份认证 · IAM

); }