import { useEffect, useState } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { BrainCircuit, Calculator, Network, Boxes, ReceiptText, CalendarClock, Sparkles, LogOut } from 'lucide-react'; import { useTheme } from '@/shared/context/ThemeContext'; import StarBackground from '@/shared/components/StarBackground'; import ThemeToggle from '@/shared/components/ThemeToggle'; import { modules } from '@/modules/registry'; import { getUserInfo, clearSession, type SessionUserInfo } from '@/shared/services/iamAuth'; const ICON_MAP: Record> = { BrainCircuit, Calculator, Network, Boxes, ReceiptText, CalendarClock, Sparkles, }; export default function HomePage() { const navigate = useNavigate(); const { theme } = useTheme(); const isDark = theme === 'dark'; const [searchParams] = useSearchParams(); const [userInfo, setUserInfo] = useState(() => getUserInfo()); // 登录守卫:未登录跳转 /login useEffect(() => { const token = sessionStorage.getItem('userToken'); if (!token) { navigate('/login', { replace: true }); } }, [navigate]); // 首页模块多时需纵向滚动;离开后恢复全局 overflow:hidden(其他模块自管布局) useEffect(() => { document.body.style.overflow = 'auto'; return () => { document.body.style.overflow = ''; }; }, []); // 接收 URL 参数 userToken,写入 sessionStorage useEffect(() => { const userToken = searchParams.get('userToken'); if (userToken) { sessionStorage.setItem('userToken', userToken); } }, [searchParams]); const handleLogout = () => { clearSession(); setUserInfo(null); navigate('/login', { replace: true }); }; return (
{/* 星空背景(dark)/ 浅色渐变(light) */} {isDark ? ( ) : (
)} {/* 顶部导航栏 */}
{/* 左上角 Logo + 标题 + 标语 */}
Digiwin

EIOSpace

企业智能 · 数据驱动 · 产业赋能
{/* 右上角:用户信息 + 主题切换 */}
{userInfo && (
{(userInfo.userName ?? userInfo.userId).charAt(0).toUpperCase()}
{userInfo.userName ?? userInfo.userId}
)}
{/* 内容层 */}
{/* 模块卡片网格 */}
{modules.map((mod, idx) => { const IconComp = ICON_MAP[mod.icon]; const accentColor = isDark ? mod.accentColor : mod.accentColorLight; const gradient = isDark ? mod.gradient : mod.gradientLight; return (
navigate(mod.path)} style={{ borderRadius: 20, overflow: 'hidden', cursor: 'pointer', transition: 'all 0.25s ease', animation: `card-in 0.4s ${0.1 + idx * 0.08}s both`, ...(isDark ? { background: 'rgba(0,20,60,0.55)', border: '1px solid rgba(0,212,255,0.25)', boxShadow: '0 0 20px rgba(0,212,255,0.06), inset 0 1px 0 rgba(255,255,255,0.05)', backdropFilter: 'blur(12px)', } : { background: '#ffffff', border: '1px solid rgba(10,122,255,0.12)', boxShadow: '0 2px 12px rgba(0,0,0,0.06)', }), }} onMouseEnter={(e) => { if (isDark) { e.currentTarget.style.borderColor = `${accentColor}60`; e.currentTarget.style.boxShadow = `0 0 30px ${accentColor}20, inset 0 1px 0 rgba(255,255,255,0.08)`; e.currentTarget.style.transform = 'translateY(-4px)'; } else { e.currentTarget.style.borderColor = `${accentColor}40`; e.currentTarget.style.boxShadow = `0 8px 24px rgba(0,0,0,0.10)`; e.currentTarget.style.transform = 'translateY(-4px)'; } }} onMouseLeave={(e) => { if (isDark) { e.currentTarget.style.borderColor = 'rgba(0,212,255,0.25)'; e.currentTarget.style.boxShadow = '0 0 20px rgba(0,212,255,0.06), inset 0 1px 0 rgba(255,255,255,0.05)'; e.currentTarget.style.transform = 'translateY(0)'; } else { e.currentTarget.style.borderColor = 'rgba(10,122,255,0.12)'; e.currentTarget.style.boxShadow = '0 2px 12px rgba(0,0,0,0.06)'; e.currentTarget.style.transform = 'translateY(0)'; } }} > {/* 卡片顶部渐变条 */}
{/* 扫光动画(dark模式) */} {isDark && (
)} {IconComp && }
{/* 卡片内容 */}

{mod.name}

{mod.description}

{/* 标签 */}
{mod.tags.map(tag => ( {tag} ))}
{/* 进入按钮 */}
); })}
{/* 底部品牌 */}
Powered by Digiwin EIOSpace
); }