部分样式调整
This commit is contained in:
@@ -2,7 +2,7 @@ import { ChevronRight, LayoutGrid } from "lucide-react";
|
||||
import type { AuthUser, AuthWorkspace } from "../../context/AuthContext";
|
||||
|
||||
type TopbarProps = {
|
||||
activePage: string;
|
||||
pageTitle: string;
|
||||
apiOnline: boolean;
|
||||
user: AuthUser | null;
|
||||
currentWorkspace: AuthWorkspace;
|
||||
@@ -14,7 +14,7 @@ type TopbarProps = {
|
||||
};
|
||||
|
||||
export function Topbar({
|
||||
activePage,
|
||||
pageTitle,
|
||||
apiOnline,
|
||||
user,
|
||||
currentWorkspace,
|
||||
@@ -24,13 +24,6 @@ export function Topbar({
|
||||
onSetCurrentWorkspace,
|
||||
onLogout,
|
||||
}: TopbarProps) {
|
||||
const pageTitles: Record<string, string> = {
|
||||
home: "工作台",
|
||||
scripts: "构建脚本",
|
||||
schedules: "调度配置",
|
||||
system: "系统管理",
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="relative z-[2] flex h-[70px] min-h-[70px] items-center justify-between border-b border-[#dfe6ee] bg-white px-[22px]">
|
||||
<div className="flex items-center gap-[9px]">
|
||||
@@ -45,7 +38,7 @@ export function Topbar({
|
||||
开发工作区
|
||||
</span>
|
||||
<h1 className="m-0 mt-px text-[18px] leading-[1.1] text-[#14243a]">
|
||||
{pageTitles[activePage] || "工作台"}
|
||||
{pageTitle}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -21,6 +21,42 @@ export type NavigationItem = {
|
||||
children?: NavigationItem[];
|
||||
};
|
||||
|
||||
export function pathForPage(page: ActivePage): string {
|
||||
if (page === "home") return "/workbench";
|
||||
return `/${page}`;
|
||||
}
|
||||
|
||||
function normalizePath(pathname: string): string {
|
||||
const trimmed = pathname.replace(/\/+$/, "");
|
||||
return trimmed || "/";
|
||||
}
|
||||
|
||||
/** 根据当前 pathname 解析顶栏标题:二级菜单显示子项名称,一级菜单显示自身名称。 */
|
||||
export function pageTitleFromPath(pathname: string): string {
|
||||
const path = normalizePath(pathname);
|
||||
|
||||
for (const item of navigation) {
|
||||
if (item.children) {
|
||||
for (const child of item.children) {
|
||||
const childPath =
|
||||
child.activePath ?? `${pathForPage(child.page)}/${child.sub}`;
|
||||
if (path === childPath) {
|
||||
return child.label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const item of navigation) {
|
||||
const itemPath = item.activePath ?? pathForPage(item.page);
|
||||
if (path === itemPath) {
|
||||
return item.label;
|
||||
}
|
||||
}
|
||||
|
||||
return "工作台";
|
||||
}
|
||||
|
||||
export const navigation: NavigationItem[] = [
|
||||
{ label: "工作台", icon: Home, page: "home", permission: "dashboard:view" },
|
||||
{ label: "构建脚本", icon: Code, page: "scripts", permission: "script:view" },
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router";
|
||||
|
||||
import { PanelLeft, ChevronRight } from "lucide-react";
|
||||
import { navigation } from "./platform.navigation";
|
||||
import { ChevronRight, Menu } from "lucide-react";
|
||||
import {
|
||||
navigation,
|
||||
pathForPage,
|
||||
pageTitleFromPath,
|
||||
} from "./platform.navigation";
|
||||
import type { ActivePage, NavigationItem, SubPage } from "./platform.navigation";
|
||||
import { Collapsible } from "@base-ui/react/collapsible";
|
||||
|
||||
@@ -21,9 +25,10 @@ import {
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubItem,
|
||||
SidebarMenuSubButton,
|
||||
SidebarTrigger,
|
||||
SidebarInset,
|
||||
useSidebar,
|
||||
} from "~/components/ui/sidebar";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { useApi, useAuth, usePermission } from "~/context/AuthContext";
|
||||
import { useEditSessionLifecycle } from "~/features/platform/hooks/useEditSessionLifecycle";
|
||||
import {
|
||||
@@ -46,11 +51,6 @@ function pageFromPath(pathname: string): ActivePage {
|
||||
return "home";
|
||||
}
|
||||
|
||||
function pathForPage(page: ActivePage): string {
|
||||
if (page === "home") return "/workbench";
|
||||
return `/${page}`;
|
||||
}
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [
|
||||
{ title: "模型实验开发平台" },
|
||||
@@ -132,6 +132,26 @@ function NavRow({
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarCollapseButton() {
|
||||
const { toggleSidebar, state } = useSidebar();
|
||||
const collapsed = state === "collapsed";
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleSidebar}
|
||||
className={cn(
|
||||
"flex w-full cursor-pointer items-center gap-2.5 border-t border-sidebar-border py-3.5 text-sm text-sidebar-foreground/75 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
collapsed ? "justify-center px-0" : "px-[17px]",
|
||||
)}
|
||||
aria-label={collapsed ? "展开菜单" : "收起菜单"}
|
||||
>
|
||||
<Menu className="size-4 shrink-0" />
|
||||
{!collapsed && <span>收起菜单</span>}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default function PlatformLayout() {
|
||||
const { currentWorkspace } = useAuth();
|
||||
if (!currentWorkspace) {
|
||||
@@ -151,6 +171,7 @@ function AuthenticatedLayout() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const activePage = pageFromPath(location.pathname);
|
||||
const pageTitle = pageTitleFromPath(location.pathname);
|
||||
const auth = useAuth();
|
||||
const {
|
||||
user,
|
||||
@@ -246,16 +267,14 @@ function AuthenticatedLayout() {
|
||||
))}
|
||||
</SidebarMenu>
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<SidebarTrigger>
|
||||
<PanelLeft /> {!sidebarCollapsed && <span>收起菜单</span>}
|
||||
</SidebarTrigger>
|
||||
<SidebarFooter className="p-0">
|
||||
<SidebarCollapseButton />
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
|
||||
<SidebarInset className="h-screen min-w-0">
|
||||
<Topbar
|
||||
activePage={activePage}
|
||||
pageTitle={pageTitle}
|
||||
apiOnline={apiOnline}
|
||||
user={user}
|
||||
currentWorkspace={currentWorkspace!}
|
||||
|
||||
Reference in New Issue
Block a user