Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions web/src/components/admin/settings-panels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ import {
parseBookmarksHtml,
parseImportJson,
} from "@/lib/bookmarks";
import {
LINK_STYLE_LABELS,
LINK_STYLE_OPTIONS,
resolveLinkStyle,
} from "@/lib/link-style";
import { useNavStore } from "@/lib/nav-store";
import type {
AdminCategory,
AdminLink,
LinkStyle,
SearchEngine,
SiteSettings,
} from "@/lib/types";
Expand Down Expand Up @@ -257,6 +263,8 @@ export function SettingsPanel({
wallpaperSource: settings.wallpaperSource ?? "bing",
// 旧数据 / 旧 mock 可能没有该字段:契约默认开
searchNewTab: settings.searchNewTab ?? true,
// 后端该键未落地 / 旧缓存时同样缺字段:契约缺省 classic(读侧统一兜底)
linkStyle: resolveLinkStyle(settings),
});

const save = async () => {
Expand Down Expand Up @@ -307,6 +315,33 @@ export function SettingsPanel({
每日壁纸」时忽略背景图地址。
</p>
</div>
<div className="grid gap-2">
<Label htmlFor="set-link-style">链接样式</Label>
{/*
链接呈现形态(冻结契约 #23):全站统一、访客不可切,保存后公共页刷新即生效。
控件沿用上方「壁纸来源」的 Select 范式,不另造单选组。
*/}
<Select
value={form.linkStyle}
onValueChange={(v) =>
setForm({ ...form, linkStyle: v as LinkStyle })
}
>
<SelectTrigger id="set-link-style" aria-label="选择链接样式">
<SelectValue />
</SelectTrigger>
<SelectContent>
{LINK_STYLE_OPTIONS.map((style) => (
<SelectItem key={style} value={style}>
{LINK_STYLE_LABELS[style]}
</SelectItem>
))}
</SelectContent>
</Select>
<p className="text-sm text-muted-foreground">
全站统一,访客不可切换;保存后公共页刷新即生效。
</p>
</div>
<AssetUploadField
id="set-bg"
label="背景图"
Expand Down
107 changes: 99 additions & 8 deletions web/src/components/link-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
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 type { LinkStyle, SiteCategory, SiteLink } from "@/lib/types";

/** 链接卡片:图标 + 标题 + 域名;桌面 7–8 列 / 手机 4 列 */
/**
* 链接网格(站点设置 `linkStyle` 决定呈现形态,全站统一、访客不可切)。
*
* 三档形状由 `resolveLinkStyle`(lib/link-style.ts)解析,缺省 classic:
* - classic:图标上、名称下、域名小字,列数沿现状(桌面 7–8 列 / 手机 4 列);
* - compact:小图标左、名称右(单行省略),透明无卡片底、不显示域名,桌面 5 列;
* - wide:玻璃底宽卡,图标左、右侧名称 + 域名两行,桌面 3 列 / 窄屏 1–2 列。
*
* 每一条都包一层 `FadeIn`(错峰入场,与改动前一致);外链属性
* `target="_blank" rel="noopener noreferrer"` 三档一致。
*/

/** 每档的网格列数(只有列数与间距不同,条目形状见下方各自的组件)。 */
const GRID_CLASS: Record<LinkStyle, string> = {
classic:
"grid grid-cols-4 gap-3 sm:grid-cols-5 md:grid-cols-6 lg:grid-cols-7 xl:grid-cols-8",
compact:
"grid grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5",
wide: "grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",
};

/** 经典:图标上、名称下、域名小字(改动前的原样) */
function LinkTile({ link, index }: { link: SiteLink; index: number }) {
return (
<FadeIn delay={Math.min(index * 0.02, 0.3)}>
Expand All @@ -30,26 +51,96 @@ function LinkTile({ link, index }: { link: SiteLink; index: number }) {
);
}

export function LinkGrid({ links }: { links: SiteLink[] }) {
/** 紧凑:小图标左、名称右;无卡片底、不显示域名 */
function CompactLinkTile({ link, index }: { link: SiteLink; index: number }) {
return (
<FadeIn delay={Math.min(index * 0.02, 0.3)}>
<a
href={link.url}
target="_blank"
rel="noopener noreferrer"
title={link.title}
className="flex h-full items-center gap-2 rounded-xl px-2 py-2 text-white/90 transition-colors hover:bg-white/10 hover:text-white"
>
<SiteIcon
title={link.title}
url={link.url}
iconUrl={link.iconUrl}
size={20}
/>
<span className="min-w-0 flex-1 truncate text-sm">{link.title}</span>
</a>
</FadeIn>
);
}

/** 宽卡片:玻璃底,图标左,右侧名称 + 域名两行 */
function WideLinkTile({ link, index }: { link: SiteLink; index: number }) {
return (
<FadeIn delay={Math.min(index * 0.02, 0.3)}>
<a
href={link.url}
target="_blank"
rel="noopener noreferrer"
className="glass glass-hover flex h-full items-center gap-3 rounded-2xl px-4 py-3"
>
<SiteIcon
title={link.title}
url={link.url}
iconUrl={link.iconUrl}
size={36}
/>
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-medium text-foreground/90">
{link.title}
</span>
<span className="block truncate text-xs text-muted-foreground">
{safeHost(link.url)}
</span>
</span>
</a>
</FadeIn>
);
}

export function LinkGrid({
links,
linkStyle = "classic",
}: {
links: SiteLink[];
linkStyle?: LinkStyle;
}) {
const Tile =
linkStyle === "compact"
? CompactLinkTile
: linkStyle === "wide"
? WideLinkTile
: LinkTile;

return (
<div className="grid grid-cols-4 gap-3 sm:grid-cols-5 md:grid-cols-6 lg:grid-cols-7 xl:grid-cols-8">
<div className={GRID_CLASS[linkStyle]}>
{links.map((link, i) => (
<LinkTile key={link.id} link={link} index={i} />
<Tile key={link.id} link={link} index={i} />
))}
</div>
);
}

/** 分类区块(锚点目标);private 时带 accent 描边与「私有」徽标 */
/**
* 分类区块(锚点目标);private 时带 accent 描边与「私有」徽标。
* `scroll-mt-6`:顶栏删除后锚点偏移随之调小,跳转后分类标题贴顶可见、不被裁切。
*/
export function CategorySection({
category,
privateZone = false,
linkStyle = "classic",
}: {
category: SiteCategory;
privateZone?: boolean;
linkStyle?: LinkStyle;
}) {
return (
<section id={`cat-${category.id}`} className="scroll-mt-24">
<section id={`cat-${category.id}`} className="scroll-mt-6">
<div className="mb-3 flex items-center gap-2">
<h2 className="font-heading text-xl font-semibold text-white drop-shadow">
{category.name}
Expand All @@ -63,7 +154,7 @@ export function CategorySection({
</GlassCard>
)}
</div>
<LinkGrid links={category.links} />
<LinkGrid links={category.links} linkStyle={linkStyle} />
</section>
);
}
96 changes: 96 additions & 0 deletions web/src/components/public-dock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { LogIn, LogOut, Settings } from "lucide-react";
import { SceneSwitcher } from "@/components/scene-switcher";
import { ThemeToggle } from "@/components/theme-toggle";
import { Button } from "@/components/ui/button";
import type { AuthStatus } from "@/lib/nav-store";
import type { Scene } from "@/lib/types";

/**
* 公共页右下角固定坞(顶栏移除后的场景与操作入口):
*
* - 上部:场景胶囊组(数据源由调用方给:未登录只有公开场景、登录全量;
* 组件内不做可见性判断)。场景多时在**组内**纵向滚动,不把坞撑高。
* - 下部:按钮组纵向排列 —— 主题三态切换,然后是登录态三态的操作:
* 探活未回(pending)时不渲染任何登录态按钮(不闪「登录」),
* 已登录是「后台」+「退出」,未登录是「登录」(仍由公共页弹 LoginDialog)。
*
* 布局:`fixed` 贴右下、层级高于页面内容;外层不吃点击(`pointer-events-none`),
* 只有两块面板各自 `pointer-events-auto` —— 坞占的那片透明区域不会挡住下面的链接。
* 宽度固定 `w-28`,窄屏(390px 级)贴右下角也不会溢出视口。
*/
export function PublicDock({
scenes,
activeScene,
onSceneChange,
authStatus,
onOpenAdmin,
onLogin,
onLogout,
}: {
scenes: readonly Scene[];
/** 当前生效的场景 id;没有场景概念时为 null */
activeScene: string | null;
onSceneChange: (sceneId: string) => void;
authStatus: AuthStatus;
onOpenAdmin: () => void;
onLogin: () => void;
onLogout: () => void;
}) {
// 只有一个场景(仅「通用」)时不显示胶囊:与场景维度上线前的公共页一致
const showScenes = scenes.length > 1 && activeScene !== null;

return (
<aside
aria-label="场景与快捷操作"
className="pointer-events-none fixed inset-x-0 bottom-4 z-30 flex flex-col items-end gap-2 px-4"
>
{showScenes && (
<SceneSwitcher
scenes={scenes}
value={activeScene}
onValueChange={onSceneChange}
ariaLabel="切换场景"
className="no-scrollbar pointer-events-auto max-h-32 w-28 flex-col flex-nowrap overflow-y-auto"
itemClassName="w-full min-w-0 justify-start"
/>
)}
<div className="pointer-events-auto flex w-28 flex-col gap-1">
{/* 主题是访客本机偏好,不受登录态影响:pending 期间照常可点 */}
<ThemeToggle showLabel className="w-full justify-start" />
{authStatus === "pending" ? null : authStatus === "authenticated" ? (
<>
<Button
variant="ghost"
size="sm"
className="glass w-full justify-start gap-1.5 text-foreground hover:text-foreground"
onClick={onOpenAdmin}
>
<Settings className="size-4" aria-hidden="true" />
后台
</Button>
<Button
variant="ghost"
size="sm"
className="glass w-full justify-start gap-1.5 text-foreground hover:text-foreground"
onClick={onLogout}
>
<LogOut className="size-4" aria-hidden="true" />
退出
</Button>
</>
) : (
// 低调登录入口:仍走 LoginDialog(弹窗由公共页持有)
<Button
variant="ghost"
size="sm"
className="glass w-full justify-start gap-1.5 text-foreground hover:text-foreground"
onClick={onLogin}
>
<LogIn className="size-4" aria-hidden="true" />
登录
</Button>
)}
</div>
</aside>
);
}
Loading
Loading