feat:菜单
This commit is contained in:
@@ -1,12 +1,5 @@
|
|||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
|
|
||||||
const navigation = [
|
|
||||||
{ label: "工作台", icon: "home" as const, page: "home" as const },
|
|
||||||
{ label: "构建脚本", icon: "script" as const, page: "scripts" as const },
|
|
||||||
{ label: "调度配置", icon: "schedule" as const, page: "schedules" as const },
|
|
||||||
{ label: "系统管理", icon: "settings" as const, page: "system" as const },
|
|
||||||
];
|
|
||||||
|
|
||||||
type ActivePage = "home" | "scripts" | "schedules" | "system";
|
type ActivePage = "home" | "scripts" | "schedules" | "system";
|
||||||
|
|
||||||
type SidebarProps = {
|
type SidebarProps = {
|
||||||
@@ -17,6 +10,13 @@ type SidebarProps = {
|
|||||||
onEndEditing?: () => void;
|
onEndEditing?: () => void;
|
||||||
onSelectScript?: (scriptId: null) => void;
|
onSelectScript?: (scriptId: null) => void;
|
||||||
editSessionRef?: React.RefObject<unknown | null>;
|
editSessionRef?: React.RefObject<unknown | null>;
|
||||||
|
isSystemAdmin?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NavigationItem = {
|
||||||
|
label: string;
|
||||||
|
icon: "home" | "script" | "schedule" | "settings";
|
||||||
|
page: ActivePage;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Sidebar({
|
export function Sidebar({
|
||||||
@@ -27,6 +27,7 @@ export function Sidebar({
|
|||||||
onEndEditing,
|
onEndEditing,
|
||||||
onSelectScript,
|
onSelectScript,
|
||||||
editSessionRef,
|
editSessionRef,
|
||||||
|
isSystemAdmin = false,
|
||||||
}: SidebarProps) {
|
}: SidebarProps) {
|
||||||
const handleNavigationClick = (page: ActivePage) => {
|
const handleNavigationClick = (page: ActivePage) => {
|
||||||
if (page !== "scripts") {
|
if (page !== "scripts") {
|
||||||
@@ -39,6 +40,18 @@ export function Sidebar({
|
|||||||
onNavigate(page);
|
onNavigate(page);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 根据管理员权限构建菜单项
|
||||||
|
const navigation: NavigationItem[] = [
|
||||||
|
{ label: "工作台", icon: "home", page: "home" },
|
||||||
|
{ label: "构建脚本", icon: "script", page: "scripts" },
|
||||||
|
{ label: "调度配置", icon: "schedule", page: "schedules" },
|
||||||
|
];
|
||||||
|
|
||||||
|
// 系统管理员才显示"系统管理"菜单
|
||||||
|
if (isSystemAdmin) {
|
||||||
|
navigation.push({ label: "系统管理", icon: "settings", page: "system" });
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className={`sidebar${collapsed ? " is-collapsed" : ""}`}>
|
<aside className={`sidebar${collapsed ? " is-collapsed" : ""}`}>
|
||||||
<div className="brand">
|
<div className="brand">
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ function AuthenticatedLayout() {
|
|||||||
onEndEditing={() => void endEditing(true)}
|
onEndEditing={() => void endEditing(true)}
|
||||||
onSelectScript={selectScript}
|
onSelectScript={selectScript}
|
||||||
editSessionRef={editSessionHandle}
|
editSessionRef={editSessionHandle}
|
||||||
|
isSystemAdmin={user?.is_system_admin ?? false}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<main className="main-area">
|
<main className="main-area">
|
||||||
|
|||||||
Reference in New Issue
Block a user