feat: SideNav 按 role 过滤菜单,/users 仅 zhipianren,/editor-desk 仅 zhipianren+zebian

This commit is contained in:
simonkoson
2026-05-21 19:47:21 +08:00
parent 3942f01def
commit 4eca31f8eb
+25 -10
View File
@@ -8,19 +8,34 @@ import {
UserOutlined, UserOutlined,
TeamOutlined, TeamOutlined,
} from '@ant-design/icons' } from '@ant-design/icons'
import useAuthStore from '../../stores/authStore'
const menuItems = [
{ key: '/dashboard', icon: <DashboardOutlined />, label: '仪表盘' },
{ key: '/tps', icon: <FileTextOutlined />, label: 'TPS 选题策划' },
{ key: '/knowledge', icon: <BookOutlined />, label: '知识库' },
{ key: '/doco', icon: <SyncOutlined />, label: '文稿对齐' },
{ key: '/editor-home', icon: <UserOutlined />, label: '个人首页' },
{ key: '/users', icon: <TeamOutlined />, label: '用户管理' },
]
function SideNav() { function SideNav() {
const navigate = useNavigate() const navigate = useNavigate()
const location = useLocation() const location = useLocation()
const { user } = useAuthStore()
const allMenuItems = [
{ key: '/dashboard', icon: <DashboardOutlined />, label: '仪表盘' },
{ key: '/editor-desk', icon: <FileTextOutlined />, label: '责编录入' },
{ key: '/tps', icon: <FileTextOutlined />, label: 'TPS 选题策划' },
{ key: '/knowledge', icon: <BookOutlined />, label: '知识库' },
{ key: '/doco', icon: <SyncOutlined />, label: '文稿对齐' },
{ key: '/editor-home', icon: <UserOutlined />, label: '个人首页' },
{ key: '/users', icon: <TeamOutlined />, label: '用户管理' },
]
// 按角色过滤菜单项
const visibleItems = allMenuItems.filter(item => {
// /dashboard 三角色都可见
if (item.key === '/dashboard') return true
// /users 仅 zhipianren
if (item.key === '/users') return user?.role === 'zhipianren'
// /editor-desk 仅 zhipianren + zebian
if (item.key === '/editor-desk') return user?.role === 'zhipianren' || user?.role === 'zebian'
// 其余三角色都可见(保留后期 Phase 入口)
return true
})
return ( return (
<div className="side-nav"> <div className="side-nav">
@@ -31,7 +46,7 @@ function SideNav() {
<Menu <Menu
mode="inline" mode="inline"
selectedKeys={[location.pathname]} selectedKeys={[location.pathname]}
items={menuItems} items={visibleItems}
onClick={({ key }) => navigate(key)} onClick={({ key }) => navigate(key)}
className="side-nav-menu" className="side-nav-menu"
/> />