部分样式调整
This commit is contained in:
@@ -2,7 +2,7 @@ import { ChevronRight, LayoutGrid } from "lucide-react";
|
|||||||
import type { AuthUser, AuthWorkspace } from "../../context/AuthContext";
|
import type { AuthUser, AuthWorkspace } from "../../context/AuthContext";
|
||||||
|
|
||||||
type TopbarProps = {
|
type TopbarProps = {
|
||||||
activePage: string;
|
pageTitle: string;
|
||||||
apiOnline: boolean;
|
apiOnline: boolean;
|
||||||
user: AuthUser | null;
|
user: AuthUser | null;
|
||||||
currentWorkspace: AuthWorkspace;
|
currentWorkspace: AuthWorkspace;
|
||||||
@@ -14,7 +14,7 @@ type TopbarProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function Topbar({
|
export function Topbar({
|
||||||
activePage,
|
pageTitle,
|
||||||
apiOnline,
|
apiOnline,
|
||||||
user,
|
user,
|
||||||
currentWorkspace,
|
currentWorkspace,
|
||||||
@@ -24,13 +24,6 @@ export function Topbar({
|
|||||||
onSetCurrentWorkspace,
|
onSetCurrentWorkspace,
|
||||||
onLogout,
|
onLogout,
|
||||||
}: TopbarProps) {
|
}: TopbarProps) {
|
||||||
const pageTitles: Record<string, string> = {
|
|
||||||
home: "工作台",
|
|
||||||
scripts: "构建脚本",
|
|
||||||
schedules: "调度配置",
|
|
||||||
system: "系统管理",
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="relative z-[2] flex h-[70px] min-h-[70px] items-center justify-between border-b border-[#dfe6ee] bg-white px-[22px]">
|
<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]">
|
<div className="flex items-center gap-[9px]">
|
||||||
@@ -45,7 +38,7 @@ export function Topbar({
|
|||||||
开发工作区
|
开发工作区
|
||||||
</span>
|
</span>
|
||||||
<h1 className="m-0 mt-px text-[18px] leading-[1.1] text-[#14243a]">
|
<h1 className="m-0 mt-px text-[18px] leading-[1.1] text-[#14243a]">
|
||||||
{pageTitles[activePage] || "工作台"}
|
{pageTitle}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,6 +21,42 @@ export type NavigationItem = {
|
|||||||
children?: 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[] = [
|
export const navigation: NavigationItem[] = [
|
||||||
{ label: "工作台", icon: Home, page: "home", permission: "dashboard:view" },
|
{ label: "工作台", icon: Home, page: "home", permission: "dashboard:view" },
|
||||||
{ label: "构建脚本", icon: Code, page: "scripts", permission: "script:view" },
|
{ label: "构建脚本", icon: Code, page: "scripts", permission: "script:view" },
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Outlet, useLocation, useNavigate } from "react-router";
|
import { Outlet, useLocation, useNavigate } from "react-router";
|
||||||
|
|
||||||
import { PanelLeft, ChevronRight } from "lucide-react";
|
import { ChevronRight, Menu } from "lucide-react";
|
||||||
import { navigation } from "./platform.navigation";
|
import {
|
||||||
|
navigation,
|
||||||
|
pathForPage,
|
||||||
|
pageTitleFromPath,
|
||||||
|
} from "./platform.navigation";
|
||||||
import type { ActivePage, NavigationItem, SubPage } from "./platform.navigation";
|
import type { ActivePage, NavigationItem, SubPage } from "./platform.navigation";
|
||||||
import { Collapsible } from "@base-ui/react/collapsible";
|
import { Collapsible } from "@base-ui/react/collapsible";
|
||||||
|
|
||||||
@@ -21,9 +25,10 @@ import {
|
|||||||
SidebarMenuSub,
|
SidebarMenuSub,
|
||||||
SidebarMenuSubItem,
|
SidebarMenuSubItem,
|
||||||
SidebarMenuSubButton,
|
SidebarMenuSubButton,
|
||||||
SidebarTrigger,
|
|
||||||
SidebarInset,
|
SidebarInset,
|
||||||
|
useSidebar,
|
||||||
} from "~/components/ui/sidebar";
|
} from "~/components/ui/sidebar";
|
||||||
|
import { cn } from "~/lib/utils";
|
||||||
import { useApi, useAuth, usePermission } from "~/context/AuthContext";
|
import { useApi, useAuth, usePermission } from "~/context/AuthContext";
|
||||||
import { useEditSessionLifecycle } from "~/features/platform/hooks/useEditSessionLifecycle";
|
import { useEditSessionLifecycle } from "~/features/platform/hooks/useEditSessionLifecycle";
|
||||||
import {
|
import {
|
||||||
@@ -46,11 +51,6 @@ function pageFromPath(pathname: string): ActivePage {
|
|||||||
return "home";
|
return "home";
|
||||||
}
|
}
|
||||||
|
|
||||||
function pathForPage(page: ActivePage): string {
|
|
||||||
if (page === "home") return "/workbench";
|
|
||||||
return `/${page}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function meta({}: Route.MetaArgs) {
|
export function meta({}: Route.MetaArgs) {
|
||||||
return [
|
return [
|
||||||
{ title: "模型实验开发平台" },
|
{ 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() {
|
export default function PlatformLayout() {
|
||||||
const { currentWorkspace } = useAuth();
|
const { currentWorkspace } = useAuth();
|
||||||
if (!currentWorkspace) {
|
if (!currentWorkspace) {
|
||||||
@@ -151,6 +171,7 @@ function AuthenticatedLayout() {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const activePage = pageFromPath(location.pathname);
|
const activePage = pageFromPath(location.pathname);
|
||||||
|
const pageTitle = pageTitleFromPath(location.pathname);
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
const {
|
const {
|
||||||
user,
|
user,
|
||||||
@@ -246,16 +267,14 @@ function AuthenticatedLayout() {
|
|||||||
))}
|
))}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
<SidebarFooter>
|
<SidebarFooter className="p-0">
|
||||||
<SidebarTrigger>
|
<SidebarCollapseButton />
|
||||||
<PanelLeft /> {!sidebarCollapsed && <span>收起菜单</span>}
|
|
||||||
</SidebarTrigger>
|
|
||||||
</SidebarFooter>
|
</SidebarFooter>
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
|
|
||||||
<SidebarInset className="h-screen min-w-0">
|
<SidebarInset className="h-screen min-w-0">
|
||||||
<Topbar
|
<Topbar
|
||||||
activePage={activePage}
|
pageTitle={pageTitle}
|
||||||
apiOnline={apiOnline}
|
apiOnline={apiOnline}
|
||||||
user={user}
|
user={user}
|
||||||
currentWorkspace={currentWorkspace!}
|
currentWorkspace={currentWorkspace!}
|
||||||
|
|||||||
Reference in New Issue
Block a user