From ba89f559bcd2b9c481f6c3aa7d66cc383333eeb1 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 30 Jul 2026 07:10:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(PageHead):=20=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=8C=96=E6=8B=86=E5=88=86=EF=BC=8C=E4=B8=BB=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=B2=BE=E7=AE=80=E5=88=B0~100=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/layout/PageHead/index.tsx | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 apps/web/src/components/layout/PageHead/index.tsx diff --git a/apps/web/src/components/layout/PageHead/index.tsx b/apps/web/src/components/layout/PageHead/index.tsx new file mode 100644 index 000000000..a3d604fc0 --- /dev/null +++ b/apps/web/src/components/layout/PageHead/index.tsx @@ -0,0 +1,92 @@ +/** + * PageHead - 页面头部组件(Task 1.4) + * + * 功能: + * - 页面标题展示 + * - 面包屑导航(自动根据路由生成,也支持手动传入) + * - 右侧操作按钮区(slot,由页面自行填充) + * - 响应式:移动端简化布局(隐藏面包屑,缩小标题) + * + * 复用 global.css 中已有的 .xx-page-head 基础样式, + * 补充面包屑、操作区等扩展样式。 + */ +import React from "react" +import { useLocation, useNavigate, Link } from "react-router-dom" +import { RightOutlined, HomeOutlined } from "@ant-design/icons" +import type { PageHeadProps } from "./types" +import { generateBreadcrumb } from "./utils" +import "./PageHead.css" + +const PageHead: React.FC = ({ + title, + description, + breadcrumb, + actions, + hideBreadcrumb = false, +}) => { + const location = useLocation() + const navigate = useNavigate() + + // 使用传入的面包屑或自动生成 + const breadcrumbItems = breadcrumb ?? generateBreadcrumb(location.pathname) + + // 首页不显示面包屑 + const showBreadcrumb = + !hideBreadcrumb && + breadcrumbItems.length > 1 && + location.pathname !== "/app" && + location.pathname !== "/app/dashboard" + + return ( +
+
+ {/* 面包屑导航 */} + {showBreadcrumb && ( + + )} + + {/* 标题 + 描述 */} +
+

{title}

+ {description &&

{description}

} +
+
+ + {/* 右侧操作区 */} + {actions &&
{actions}
} +
+ ) +} + +export default PageHead +export type { BreadcrumbItem, PageHeadProps } from "./types" +