2026-02-09 11:12:16 +08:00
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
|
import { Outlet, Link, useLocation, useNavigate } from 'react-router-dom'
|
|
|
|
|
import {
|
|
|
|
|
LayoutDashboard,
|
|
|
|
|
Users,
|
|
|
|
|
CreditCard,
|
|
|
|
|
Settings,
|
|
|
|
|
LogOut,
|
|
|
|
|
Wallet,
|
|
|
|
|
BookOpen,
|
2026-02-25 16:26:13 +08:00
|
|
|
GitMerge,
|
2026-02-26 18:03:01 +08:00
|
|
|
Crown,
|
2026-02-28 15:16:23 +08:00
|
|
|
GraduationCap,
|
|
|
|
|
Calendar,
|
2026-03-04 19:06:06 +08:00
|
|
|
User,
|
|
|
|
|
ShieldCheck,
|
|
|
|
|
ChevronDown,
|
|
|
|
|
ChevronUp,
|
2026-03-10 11:04:34 +08:00
|
|
|
Handshake,
|
2026-02-09 11:12:16 +08:00
|
|
|
} from 'lucide-react'
|
|
|
|
|
import { get, post } from '@/api/client'
|
2026-02-10 15:03:31 +08:00
|
|
|
import { clearAdminToken } from '@/api/auth'
|
2026-02-09 11:12:16 +08:00
|
|
|
|
2026-03-06 12:12:13 +08:00
|
|
|
// 主菜单(核心运营 3 项)
|
2026-03-04 19:06:06 +08:00
|
|
|
const primaryMenuItems = [
|
2026-02-09 11:12:16 +08:00
|
|
|
{ icon: LayoutDashboard, label: '数据概览', href: '/dashboard' },
|
|
|
|
|
{ icon: BookOpen, label: '内容管理', href: '/content' },
|
|
|
|
|
{ icon: Users, label: '用户管理', href: '/users' },
|
2026-03-04 19:06:06 +08:00
|
|
|
]
|
2026-03-06 12:12:13 +08:00
|
|
|
// 折叠区「更多」(字典类 + 业务)
|
2026-03-04 19:06:06 +08:00
|
|
|
const moreMenuItems = [
|
2026-03-06 12:12:13 +08:00
|
|
|
{ icon: Crown, label: 'VIP 角色', href: '/vip-roles' },
|
|
|
|
|
{ icon: User, label: '作者详情', href: '/author-settings' },
|
2026-03-04 19:06:06 +08:00
|
|
|
{ icon: ShieldCheck, label: '管理员', href: '/admin-users' },
|
2026-02-28 15:16:23 +08:00
|
|
|
{ icon: GraduationCap, label: '导师管理', href: '/mentors' },
|
|
|
|
|
{ icon: Calendar, label: '导师预约', href: '/mentor-consultations' },
|
2026-03-06 12:12:13 +08:00
|
|
|
{ icon: Wallet, label: '推广中心', href: '/distribution' },
|
2026-03-10 11:04:34 +08:00
|
|
|
{ icon: Handshake, label: '找伙伴', href: '/find-partner' },
|
2026-02-25 16:26:13 +08:00
|
|
|
{ icon: GitMerge, label: '匹配记录', href: '/match-records' },
|
2026-02-09 11:12:16 +08:00
|
|
|
{ icon: CreditCard, label: '推广设置', href: '/referral-settings' },
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
export function AdminLayout() {
|
|
|
|
|
const location = useLocation()
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
|
const [authChecked, setAuthChecked] = useState(false)
|
2026-03-04 19:06:06 +08:00
|
|
|
const [moreExpanded, setMoreExpanded] = useState(false)
|
2026-02-09 11:12:16 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setMounted(true)
|
|
|
|
|
}, [])
|
2026-03-04 19:06:06 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
const inMore = moreMenuItems.some((item) => location.pathname === item.href)
|
|
|
|
|
if (inMore) setMoreExpanded(true)
|
|
|
|
|
}, [location.pathname])
|
2026-02-09 11:12:16 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!mounted) return
|
|
|
|
|
setAuthChecked(false)
|
|
|
|
|
let cancelled = false
|
|
|
|
|
get<{ success?: boolean }>('/api/admin')
|
|
|
|
|
.then((data) => {
|
|
|
|
|
if (cancelled) return
|
|
|
|
|
if (data && (data as { success?: boolean }).success !== false) {
|
|
|
|
|
setAuthChecked(true)
|
|
|
|
|
} else {
|
|
|
|
|
navigate('/login', { replace: true })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
if (!cancelled) navigate('/login', { replace: true })
|
|
|
|
|
})
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true
|
|
|
|
|
}
|
|
|
|
|
}, [mounted, navigate])
|
|
|
|
|
|
|
|
|
|
const handleLogout = async () => {
|
2026-02-10 15:03:31 +08:00
|
|
|
clearAdminToken()
|
|
|
|
|
try {
|
|
|
|
|
await post('/api/admin/logout', {})
|
|
|
|
|
} catch {
|
|
|
|
|
// 忽略登出接口失败,本地已清 token
|
|
|
|
|
}
|
2026-02-09 11:12:16 +08:00
|
|
|
navigate('/login', { replace: true })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mounted || !authChecked) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex min-h-screen bg-[#0a1628]">
|
|
|
|
|
<div className="w-64 bg-[#0f2137] border-r border-gray-700/50" />
|
|
|
|
|
<div className="flex-1 flex items-center justify-center">
|
|
|
|
|
<div className="text-[#38bdac]">加载中...</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex min-h-screen bg-[#0a1628]">
|
|
|
|
|
<div className="w-64 bg-[#0f2137] flex flex-col border-r border-gray-700/50 shadow-xl">
|
|
|
|
|
<div className="p-6 border-b border-gray-700/50">
|
|
|
|
|
<h1 className="text-xl font-bold text-[#38bdac]">管理后台</h1>
|
|
|
|
|
<p className="text-xs text-gray-400 mt-1">Soul创业派对</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-04 19:06:06 +08:00
|
|
|
<nav className="flex-1 p-4 space-y-1 overflow-y-auto">
|
|
|
|
|
{primaryMenuItems.map((item) => {
|
2026-02-09 11:12:16 +08:00
|
|
|
const isActive = location.pathname === item.href
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
key={item.href}
|
|
|
|
|
to={item.href}
|
|
|
|
|
className={`flex items-center gap-3 px-4 py-3 rounded-lg transition-colors ${
|
|
|
|
|
isActive
|
|
|
|
|
? 'bg-[#38bdac]/20 text-[#38bdac] font-medium'
|
|
|
|
|
: 'text-gray-400 hover:bg-gray-700/50 hover:text-white'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
2026-03-04 19:06:06 +08:00
|
|
|
<item.icon className="w-5 h-5 shrink-0" />
|
2026-02-09 11:12:16 +08:00
|
|
|
<span className="text-sm">{item.label}</span>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
|
})}
|
2026-03-04 19:06:06 +08:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setMoreExpanded(!moreExpanded)}
|
|
|
|
|
className="w-full flex items-center justify-between gap-3 px-4 py-3 text-gray-400 hover:bg-gray-700/50 hover:text-white rounded-lg transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<span className="flex items-center gap-3">
|
|
|
|
|
{moreExpanded ? <ChevronUp className="w-5 h-5" /> : <ChevronDown className="w-5 h-5" />}
|
|
|
|
|
<span className="text-sm">更多</span>
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
{moreExpanded && (
|
|
|
|
|
<div className="space-y-1 pl-4">
|
|
|
|
|
{moreMenuItems.map((item) => {
|
|
|
|
|
const isActive = location.pathname === item.href
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
key={item.href}
|
|
|
|
|
to={item.href}
|
|
|
|
|
className={`flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${
|
|
|
|
|
isActive
|
|
|
|
|
? 'bg-[#38bdac]/20 text-[#38bdac] font-medium'
|
|
|
|
|
: 'text-gray-400 hover:bg-gray-700/50 hover:text-white'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<item.icon className="w-5 h-5 shrink-0" />
|
|
|
|
|
<span className="text-sm">{item.label}</span>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="pt-4 mt-4 border-t border-gray-700/50">
|
|
|
|
|
<Link
|
|
|
|
|
to="/settings"
|
|
|
|
|
className={`flex items-center gap-3 px-4 py-3 rounded-lg transition-colors ${
|
|
|
|
|
location.pathname === '/settings'
|
|
|
|
|
? 'bg-[#38bdac]/20 text-[#38bdac] font-medium'
|
|
|
|
|
: 'text-gray-400 hover:bg-gray-700/50 hover:text-white'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<Settings className="w-5 h-5 shrink-0" />
|
|
|
|
|
<span className="text-sm">系统设置</span>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
2026-02-09 11:12:16 +08:00
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
<div className="p-4 border-t border-gray-700/50 space-y-1">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={handleLogout}
|
|
|
|
|
className="w-full flex items-center gap-3 px-4 py-3 text-gray-400 hover:text-white rounded-lg hover:bg-gray-700/50 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<LogOut className="w-5 h-5" />
|
|
|
|
|
<span className="text-sm">退出登录</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-28 10:19:46 +08:00
|
|
|
<div className="flex-1 overflow-auto bg-[#0a1628] min-w-0">
|
|
|
|
|
<div className="w-full min-w-[1024px] min-h-full">
|
|
|
|
|
<Outlet />
|
|
|
|
|
</div>
|
2026-02-09 11:12:16 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|