refactor: Extract dashboard title into separate component

This commit is contained in:
wood chen 2025-02-22 01:04:56 +08:00
parent 4a98942064
commit 3bbf87d875
2 changed files with 30 additions and 23 deletions

View File

@ -1,33 +1,12 @@
"use client";
import { usePathname } from "next/navigation";
import { DashboardTitle } from "@/components/layout/dashboard-title";
import { Header } from "./header";
export function DashboardHeader() {
const pathname = usePathname();
const getTitle = () => {
if (pathname === "/dashboard") return "控制台";
if (pathname === "/dashboard/clients") return "应用管理";
if (pathname.includes("/dashboard/clients/")) return "应用详情";
if (pathname === "/dashboard/settings") return "账号设置";
if (pathname === "/admin/users") return "用户列表";
if (pathname === "/admin/logs") return "系统日志";
if (pathname === "/admin") return "管理后台";
if (pathname === "/admin/clients") return "应用管理";
if (pathname === "/admin/authorizations") return "授权管理";
return "";
};
return (
<div className="flex flex-col">
<Header />
<div className="border-b">
<div className="mx-auto flex h-16 max-w-7xl items-center px-4 sm:px-6 lg:px-8">
<h1 className="text-2xl font-bold">{getTitle()}</h1>
</div>
</div>
<DashboardTitle />
</div>
);
}

View File

@ -0,0 +1,28 @@
"use client";
import { usePathname } from "next/navigation";
export function DashboardTitle() {
const pathname = usePathname();
const getTitle = () => {
if (pathname === "/dashboard") return "控制台";
if (pathname === "/dashboard/clients") return "应用管理";
if (pathname.includes("/dashboard/clients/")) return "应用详情";
if (pathname === "/dashboard/settings") return "账号设置";
if (pathname === "/admin/users") return "用户列表";
if (pathname === "/admin/logs") return "系统日志";
if (pathname === "/admin") return "管理后台";
if (pathname === "/admin/clients") return "应用管理";
if (pathname === "/admin/authorizations") return "授权管理";
return "";
};
return (
<div className="border-b">
<div className="mx-auto flex h-16 max-w-7xl items-center px-4 sm:px-6 lg:px-8">
<h1 className="text-2xl font-bold">{getTitle()}</h1>
</div>
</div>
);
}