You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
231 lines
5.4 KiB
231 lines
5.4 KiB
import { LucideIcon, LayoutDashboard, Users, Settings, FolderOpen, TestTube, BarChart3, Gauge, FileText, ClipboardList } from 'lucide-react';
|
|
|
|
// 定义权限类型
|
|
export type Permission =
|
|
| 'dashboard.view'
|
|
| 'users.view'
|
|
| 'users.manage'
|
|
| 'roles.view'
|
|
| 'roles.manage'
|
|
| 'permissions.view'
|
|
| 'permissions.manage'
|
|
| 'settings.view'
|
|
| 'settings.manage'
|
|
// 场景管理权限
|
|
| 'scenarios.view'
|
|
| 'scenarios.manage'
|
|
| 'scenarios.create'
|
|
// 用例管理权限
|
|
| 'testcases.view'
|
|
| 'testcases.manage'
|
|
| 'testcases.create'
|
|
| 'teststeps.view'
|
|
| 'teststeps.manage'
|
|
| 'teststeps.create'
|
|
// 任务管理权限
|
|
| 'tasks.view'
|
|
| 'tasks.manage'
|
|
| 'tasks.create'
|
|
| 'taskreviews.view'
|
|
| 'taskreviews.manage'
|
|
| 'taskreviews.create'
|
|
| 'taskexecutions.view'
|
|
| 'taskexecutions.manage'
|
|
| 'taskexecutions.create'
|
|
// 结果分析权限
|
|
| 'functionalanalysis.view'
|
|
| 'functionalanalysis.manage'
|
|
| 'performanceanalysis.view'
|
|
| 'performanceanalysis.manage'
|
|
| 'issueanalysis.view'
|
|
| 'issueanalysis.manage'
|
|
| 'ueanalysis.view'
|
|
| 'ueanalysis.manage'
|
|
// 仪表管理权限
|
|
| 'devices.view'
|
|
| 'devices.manage'
|
|
| 'protocols.view'
|
|
| 'protocols.manage'
|
|
| 'configs.view'
|
|
| 'configs.manage';
|
|
|
|
export interface MenuItem {
|
|
title: string;
|
|
icon: LucideIcon;
|
|
href: string;
|
|
permission?: Permission;
|
|
children?: {
|
|
title: string;
|
|
href: string;
|
|
permission?: Permission;
|
|
}[];
|
|
}
|
|
|
|
export const menuItems: MenuItem[] = [
|
|
{
|
|
title: '仪表盘',
|
|
icon: LayoutDashboard,
|
|
href: '/dashboard',
|
|
permission: 'dashboard.view',
|
|
},
|
|
{
|
|
title: '场景管理',
|
|
icon: FileText,
|
|
href: '/dashboard/scenarios',
|
|
permission: 'scenarios.view',
|
|
children: [
|
|
{
|
|
title: '场景列表',
|
|
href: '/dashboard/scenarios/list',
|
|
permission: 'scenarios.view',
|
|
},
|
|
{
|
|
title: '创建场景',
|
|
href: '/dashboard/scenarios/create',
|
|
permission: 'scenarios.create',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '用例管理',
|
|
icon: TestTube,
|
|
href: '/dashboard/testcases',
|
|
permission: 'testcases.view',
|
|
children: [
|
|
{
|
|
title: '用例列表',
|
|
href: '/dashboard/testcases/list',
|
|
permission: 'testcases.view',
|
|
},
|
|
{
|
|
title: '创建用例',
|
|
href: '/dashboard/testcases/create',
|
|
permission: 'testcases.create',
|
|
},
|
|
{
|
|
title: '步骤列表',
|
|
href: '/dashboard/testcases/steps',
|
|
permission: 'teststeps.view',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '任务管理',
|
|
icon: ClipboardList,
|
|
href: '/dashboard/tasks',
|
|
permission: 'tasks.view',
|
|
children: [
|
|
{
|
|
title: '任务列表',
|
|
href: '/dashboard/tasks/list',
|
|
permission: 'tasks.view',
|
|
},
|
|
{
|
|
title: '创建任务',
|
|
href: '/dashboard/tasks/create',
|
|
permission: 'tasks.create',
|
|
},
|
|
{
|
|
title: '审核任务',
|
|
href: '/dashboard/tasks/reviews',
|
|
permission: 'taskreviews.view',
|
|
},
|
|
{
|
|
title: '执行任务',
|
|
href: '/dashboard/tasks/executions',
|
|
permission: 'taskexecutions.view',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '结果分析',
|
|
icon: BarChart3,
|
|
href: '/dashboard/analysis',
|
|
permission: 'functionalanalysis.view',
|
|
children: [
|
|
{
|
|
title: '功能分析',
|
|
href: '/dashboard/analysis/functional',
|
|
permission: 'functionalanalysis.view',
|
|
},
|
|
{
|
|
title: '性能分析',
|
|
href: '/dashboard/analysis/performance',
|
|
permission: 'performanceanalysis.view',
|
|
},
|
|
{
|
|
title: '问题分析',
|
|
href: '/dashboard/analysis/issue',
|
|
permission: 'issueanalysis.view',
|
|
},
|
|
{
|
|
title: 'UE分析',
|
|
href: '/dashboard/analysis/ue',
|
|
permission: 'ueanalysis.view',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '仪表管理',
|
|
icon: Gauge,
|
|
href: '/dashboard/instruments',
|
|
permission: 'devices.view',
|
|
children: [
|
|
{
|
|
title: '设备列表',
|
|
href: '/dashboard/instruments/devices',
|
|
permission: 'devices.view',
|
|
},
|
|
{
|
|
title: '协议列表',
|
|
href: '/dashboard/instruments/protocols',
|
|
permission: 'protocols.view',
|
|
},
|
|
{
|
|
title: '配置列表',
|
|
href: '/dashboard/instruments/configs',
|
|
permission: 'configs.view',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '用户管理',
|
|
icon: Users,
|
|
href: '/dashboard/users',
|
|
permission: 'users.view',
|
|
children: [
|
|
{
|
|
title: '用户列表',
|
|
href: '/dashboard/users/list',
|
|
permission: 'users.view',
|
|
},
|
|
{
|
|
title: '角色管理',
|
|
href: '/dashboard/users/roles',
|
|
permission: 'roles.view',
|
|
},
|
|
{
|
|
title: '权限管理',
|
|
href: '/dashboard/users/permissions',
|
|
permission: 'permissions.view',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '系统设置',
|
|
icon: Settings,
|
|
href: '/dashboard/settings',
|
|
permission: 'settings.view',
|
|
},
|
|
];
|
|
|
|
// 导出权限检查工具函数
|
|
export const hasPermission = (userPermissions: Permission[] | undefined | null, requiredPermission?: Permission): boolean => {
|
|
// 如果没有设置权限要求,则默认允许访问
|
|
if (!requiredPermission) return true;
|
|
|
|
// 如果用户权限为空,则拒绝访问
|
|
if (!userPermissions || !Array.isArray(userPermissions)) return false;
|
|
|
|
return userPermissions.includes(requiredPermission);
|
|
};
|