From 18999bd5fec9a6d823613188409ccca32328620a Mon Sep 17 00:00:00 2001 From: Todos Date: Thu, 5 Nov 2026 14:58:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E9=A1=B6=E6=A0=8F=E6=95=B4?= =?UTF-8?q?=E6=9D=A1=E6=AF=9B=E7=8E=BB=E7=92=83=E3=80=81=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E9=94=9A=E7=82=B9=E6=A0=8F=E3=80=81=E7=AB=99?= =?UTF-8?q?=E7=82=B9=E6=A0=87=E9=A2=98=E7=A7=BB=E5=85=A5=E9=A1=B6=E6=A0=8F?= =?UTF-8?q?=20header=20=E6=94=B9=E7=94=A8=20glass-bar=EF=BC=88=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=E7=8E=BB=E7=92=83=20token=EF=BC=9A=E5=8D=8A=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E5=BA=95=20+=20blur=20+=20=E5=BA=95=E8=BE=B9=E5=88=86?= =?UTF-8?q?=E9=9A=94=E7=BA=BF=EF=BC=8C=E5=85=A8=E5=AE=BD=E3=80=81=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=BB=8D=E5=B1=85=E4=B8=AD=EF=BC=89=EF=BC=9B=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=20CategoryAnchorBar=20=E5=8F=8A=E5=85=B6?= =?UTF-8?q?=E6=AD=BB=E4=BB=A3=E7=A0=81=EF=BC=9B=E6=A0=87=E9=A2=98=EF=BC=88?= =?UTF-8?q?=E5=90=AB=20Logo=20=E5=8F=98=E4=BD=93=EF=BC=89=E7=A7=BB?= =?UTF-8?q?=E5=85=A5=E9=A1=B6=E6=A0=8F=E5=B9=B6=E4=BF=9D=E7=95=99=20h1=20?= =?UTF-8?q?=E8=AF=AD=E4=B9=89=EF=BC=8C=20=E6=90=9C=E7=B4=A2=E5=8C=BA?= =?UTF-8?q?=E5=A4=A7=E6=A0=87=E9=A2=98=E5=88=A0=E9=99=A4=E3=80=81=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E9=9A=8F=E4=B9=8B=E4=B8=8A=E7=A7=BB=EF=BC=9B?= =?UTF-8?q?=E8=A1=A5=202=20=E6=9D=A1=E9=A1=B6=E6=A0=8F=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=B9=B6=E5=90=8C=E6=AD=A5=20README=20/=20?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E8=A7=84=E8=8C=83=E6=8F=8F=E8=BF=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checkpoint: 6-odGmwVkA2y8_s5CaACI --- README.md | 2 +- web/design-system/nav/MASTER.md | 7 ++-- web/src/components/link-grid.tsx | 50 ----------------------- web/src/components/public-page.tsx | 44 +++++++++++--------- web/src/index.css | 10 +++++ web/test/public-page.test.tsx | 65 +++++++++++++++++++++++++++++- 6 files changed, 103 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 86e6053..f9425a4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Monorepo: ## 界面预览 -首页:毛玻璃搜索框、分类锚点栏与公开导航网格;登录后多出私有分类,后台可管理分类、链接与站点设置。 +首页:整条毛玻璃顶栏(站点标题)、毛玻璃搜索框与公开导航网格;登录后多出私有分类,后台可管理分类、链接与站点设置。

nav 首页:全屏背景图上的毛玻璃搜索框,顶部是「开发」「阅读」分类锚点,下面是两排公开导航图标卡片 diff --git a/web/design-system/nav/MASTER.md b/web/design-system/nav/MASTER.md index 45c20f1..de9d830 100644 --- a/web/design-system/nav/MASTER.md +++ b/web/design-system/nav/MASTER.md @@ -27,14 +27,14 @@ ## 1. Pattern(页面与布局模式) -产品形态:**现代毛玻璃起始页** —— 全屏背景图 + 毛玻璃卡片承载的搜索框、图标网格与分类锚点栏。 +产品形态:**现代毛玻璃起始页** —— 全屏背景图 + 整条毛玻璃顶栏(站点标题/Logo)+ 毛玻璃卡片承载的搜索框与图标网格。 ### 1.1 页面结构(公开页 `/`) 1. **背景层**:全屏背景图(`settings.background_url`),固定不随滚动;上覆一层半透明暗/亮罩(`rgba(15,23,42,0.45)` 或浅色等价)保证前景可读。 -2. **顶部锚点栏**(sticky):分类名横向排列,点击滚动定位到对应分类区块,滚动时高亮当前区块;最右为低调登录入口(未登录)或「后台」+ 退出(已登录)。 +2. **顶栏**(sticky,整条毛玻璃:半透明底 + `backdrop-blur` + 底部分隔线):左侧为站点标题(`settings.logoUrl` 有值时为 Logo 图,否则站点标题文字;`h1` 语义);右侧为低调登录入口(未登录)或「后台」+ 退出(已登录),最右为主题切换。 3. **搜索区**(首屏中央偏上):毛玻璃大搜索框 + 引擎切换(当前引擎图标 + 下拉菜单);`/` 键聚焦、Enter 提交(按 `url_template` 的 `{q}` 替换)。 -4. **导航区**:「我的导航」标题 + 分类分节;每节是图标网格(桌面 7–8 列,平板 5–6 列,手机 4 列)。 +4. **导航区**:分类分节;每节是分类标题 + 图标网格(桌面 7–8 列,平板 5–6 列,手机 4 列)。 5. **私有区**(仅登录后):与公开区同构的分节,视觉上以毛玻璃卡片边缘的 accent 描边/「私有」徽标区分;**未登录时该区块在 DOM 与数据中完全不存在**。 ### 1.2 后台(`/admin`) @@ -118,7 +118,6 @@ - **阴影层级**:`sm 0 1px 2px rgba(0,0,0,.05)` / `md 0 4px 6px rgba(0,0,0,.10)` / `lg 0 10px 15px rgba(0,0,0,.10)` / `xl 0 20px 25px rgba(0,0,0,.15)`。 - **动效(Motion,Dial motion=3/10 微交互档)**: - 入场:搜索框/网格卡片 stagger `opacity 0→1, y 8→0`,150–220ms,ease-out。 - - 锚点滚动:`scrollIntoView({ behavior: 'smooth', block: 'start' })`,sticky 栏下留 `scroll-margin-top`。 - 拖拽:dnd-kit `DndContext` + Motion 布局动画;拖起态加阴影与轻微旋转(≤2°)。 - 引擎切换 / 登录结果:Toast(shadcn/ui Sonner)。 - **一律尊重 `prefers-reduced-motion: reduce`**:跳过非必要动画,直接呈现终态。 diff --git a/web/src/components/link-grid.tsx b/web/src/components/link-grid.tsx index b04b0de..1c11c84 100644 --- a/web/src/components/link-grid.tsx +++ b/web/src/components/link-grid.tsx @@ -1,9 +1,7 @@ -import * as React from "react"; import { FadeIn, GlassCard } from "@/components/glass"; import { SiteIcon } from "@/components/site-icon"; import { safeHost } from "@/lib/icons"; import type { SiteCategory, SiteLink } from "@/lib/types"; -import { cn } from "@/lib/utils"; /** 链接卡片:图标 + 标题 + 域名;桌面 7–8 列 / 手机 4 列 */ function LinkTile({ link, index }: { link: SiteLink; index: number }) { @@ -69,51 +67,3 @@ export function CategorySection({ ); } - -/** 顶部锚点栏:滚动定位 + 当前分类高亮 */ -export function CategoryAnchorBar({ - categories, -}: { - categories: SiteCategory[]; -}) { - const [active, setActive] = React.useState(null); - - React.useEffect(() => { - const observer = new IntersectionObserver( - (entries) => { - const visible = entries - .filter((e) => e.isIntersecting) - .sort( - (a, b) => a.boundingClientRect.top - b.boundingClientRect.top, - )[0]; - if (visible) setActive(visible.target.id); - }, - { rootMargin: "-96px 0px -60% 0px", threshold: 0 }, - ); - categories.forEach((c) => { - const el = document.getElementById(`cat-${c.id}`); - if (el) observer.observe(el); - }); - return () => observer.disconnect(); - }, [categories]); - - return ( -

- ); -} diff --git a/web/src/components/public-page.tsx b/web/src/components/public-page.tsx index 76ca403..24466bf 100644 --- a/web/src/components/public-page.tsx +++ b/web/src/components/public-page.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { LogIn, LogOut, Settings } from "lucide-react"; import { FadeIn } from "@/components/glass"; -import { CategoryAnchorBar, CategorySection } from "@/components/link-grid"; +import { CategorySection } from "@/components/link-grid"; import { LoginDialog } from "@/components/login-dialog"; import { SearchBar } from "@/components/search-bar"; import { ThemeToggle } from "@/components/theme-toggle"; @@ -9,7 +9,8 @@ import { Button } from "@/components/ui/button"; import { useAuthenticated, useNavStore } from "@/lib/nav-store"; /** - * 公开页(/):背景图 + 毛玻璃搜索框 + 锚点栏 + 「我的导航」图标网格 + 登录后的私有区。 + * 公开页(/):背景图 + 整条毛玻璃顶栏(站点标题/Logo + 登录态操作)+ 毛玻璃搜索框 + * + 「我的导航」图标网格 + 登录后的私有区。 * * 安全口径:未登录时私有区完全不渲染 —— privateData 未加载时组件树里没有私有区块, * 数据请求也只发 /api/public(未登录不请求 /api/private)。 @@ -92,11 +93,27 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) { }} /> - {/* 顶部锚点栏 */} -
- - -
+ {/* 顶栏:整条毛玻璃,左侧站点标题/Logo,右侧后台、退出与主题切换 */} +
+ + {/* + 站点标题放在顶栏(h1 语义):logoUrl 有值显示适配栏高的 Logo 图,否则显示站点标题文字。 + 文字沿用顶栏 text-foreground 口径(与右侧按钮一致):浅色档玻璃底近白、深色档近黑,两档对比度都成立。 + */} +

+ {settings?.logoUrl ? ( + {settings.siteTitle + ) : ( + + {settings?.siteTitle ?? "我的导航"} + + )} +

+
{/* 顶栏按钮统一用前景色:浅色档的玻璃芯片是近白底,白字对比度只有 2.4:1。 新增顶栏按钮请沿用 text-foreground(深色档它就是近白,两档都成立)。 @@ -144,19 +161,8 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
- {/* 搜索区:有 Logo 时头部换成 Logo 图,无则维持标题文字 */} + {/* 搜索区:站点标题已移入顶栏,这里只剩搜索框 */} -

- {settings?.logoUrl ? ( - {settings.siteTitle - ) : ( - (settings?.siteTitle ?? "我的导航") - )} -

{siteData && ( ({ toast: { success: vi.fn(), error: vi.fn() }, @@ -55,6 +55,69 @@ describe("PublicPage 头部:有 Logo 显示 Logo,无 Logo 显示标题文字 }); }); +describe("PublicPage 顶栏:整条毛玻璃 + 标题入栏 + 分类锚点栏已移除", () => { + /** 两个分类各带链接:旧锚点栏在分类多时会横向溢出,现已整块移除。 */ + const categories: SiteCategory[] = [ + { + id: "cat-dev", + name: "开发", + icon: null, + sortOrder: 0, + links: [ + { + id: "link-1", + categoryId: "cat-dev", + title: "GitHub", + url: "https://github.com/", + iconUrl: null, + description: null, + sortOrder: 0, + }, + ], + }, + { id: "cat-read", name: "阅读", icon: null, sortOrder: 1, links: [] }, + ]; + + beforeEach(() => { + useNavStore.setState({ + publicData: { categories, searchEngines: [], settings: baseSettings }, + privateData: null, + authStatus: "anonymous", + loginPromptOpen: false, + loadPublic: async () => {}, + loadPrivate: async () => {}, + }); + }); + + it("站点标题在顶栏(h1)内,顶栏整条毛玻璃", () => { + render(); + + const header = document.querySelector("header"); + expect(header).not.toBeNull(); + // 整条毛玻璃:glass-bar 提供半透明底 + backdrop-blur + 底部分隔线(web/src/index.css) + expect(header).toHaveClass("glass-bar", "sticky", "top-0"); + + const heading = screen.getByRole("heading", { level: 1 }); + expect(header?.contains(heading)).toBe(true); + expect(heading).toHaveTextContent("我的导航"); + }); + + it("不再渲染分类锚点栏,正文分类区块与链接照旧", () => { + render(); + + expect( + screen.queryByRole("navigation", { name: "分类锚点" }), + ).not.toBeInTheDocument(); + expect( + screen.getByRole("heading", { level: 2, name: "开发" }), + ).toBeInTheDocument(); + expect(screen.getByRole("link", { name: /GitHub/ })).toHaveAttribute( + "href", + "https://github.com/", + ); + }); +}); + describe("PublicPage:搜索跳转方式跟随站点设置 searchNewTab", () => { const engines: SearchEngine[] = [ {