From 3faff98dc8ea78c24f5a4e8439a12e0181b966a8 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 1 Jul 2026 15:52:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(layout):=20=E5=90=8E=E5=8F=B0=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8F=E4=B8=8E=E6=AD=A3=E6=96=87=E5=AE=BD=E5=BA=A6?= =?UTF-8?q?=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Header 的导航宽度写死 max-w-3xl(前台阅读宽度),后台直接复用导致 导航栏(768px)比正文(max-w-5xl=1024px)窄 256px,左边缘错位。 给 Header 加 max_width prop(默认 max-w-3xl 保持前台行为不变),后台 两处调用点传 max-w-5xl,与 admin_layout 的 main 同宽对齐。 --- src/components/admin_layout.rs | 4 ++-- src/components/header.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/admin_layout.rs b/src/components/admin_layout.rs index 9b7dfcb..cc18d02 100644 --- a/src/components/admin_layout.rs +++ b/src/components/admin_layout.rs @@ -118,7 +118,7 @@ pub fn AdminLayout() -> Element { (true, Some(_)) => { rsx! { div { class: "{root_class}", - Header { nav_items: admin_nav_items, right_content } + Header { nav_items: admin_nav_items, right_content, max_width: "max-w-5xl" } main { class: "{main_class}", Outlet:: {} } Footer {} } @@ -137,7 +137,7 @@ pub fn AdminLayout() -> Element { // 使用与真实布局完全相同的结构包裹内容骨架,避免 checked 变化时的布局闪烁 rsx! { div { class: "{root_class}", - Header { nav_items: admin_nav_items, right_content } + Header { nav_items: admin_nav_items, right_content, max_width: "max-w-5xl" } main { class: "{main_class}", div { class: if show_skeleton() { "" } else { "opacity-0" }, { diff --git a/src/components/header.rs b/src/components/header.rs index 4065d34..dfc6863 100644 --- a/src/components/header.rs +++ b/src/components/header.rs @@ -29,14 +29,20 @@ pub struct NavItemConfig { /// Props: /// - `nav_items`:导航项列表 /// - `right_content`:右侧自定义内容(如主题切换、登出按钮) +/// - `max_width`:内部导航的宽度类,需与正文 `max-w-*` 一致以保证左右边缘对齐。 +/// 默认 `max-w-3xl`(前台阅读宽度);后台传 `max-w-5xl` 与之同宽。 #[component] -pub fn Header(nav_items: Vec, right_content: Element) -> Element { +pub fn Header( + nav_items: Vec, + right_content: Element, + #[props(default = "max-w-3xl")] max_width: &'static str, +) -> Element { let mut mobile_open = use_signal(|| false); let menu_id = use_memo(|| "mobile-nav-menu".to_string()); rsx! { header { class: "sticky top-0 z-40 w-full border-b border-paper-border bg-paper-theme/80 backdrop-blur-sm", - nav { class: "max-w-3xl mx-auto px-6 h-[60px] flex items-center justify-between", + nav { class: "{max_width} mx-auto px-6 h-[60px] flex items-center justify-between", Link { class: "text-2xl font-bold font-serif text-paper-primary hover:text-paper-accent transition-colors duration-200", to: Route::Home {},