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
58 changes: 58 additions & 0 deletions web/src/components/admin/about-panel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ExternalLink, Info } from "lucide-react";
import { Separator } from "@/components/ui/separator";

/**
* 后台「关于」分区(nav #19 §A3):零后端改动的静态信息。
*
* 版本号来自构建时注入的 `__APP_VERSION__`(vite.config.ts / vitest.config.ts
* 读取仓库根 package.json 的 version),源码里不手写版本号。
*/
export function AboutPanel() {
const year = new Date().getFullYear();

return (
<div className="flex flex-col gap-5">
<div className="flex items-center gap-2">
<Info className="size-5 text-muted-foreground" aria-hidden="true" />
<h2 className="font-heading text-lg font-semibold">关于</h2>
</div>

<dl className="grid gap-x-6 gap-y-3 text-sm sm:grid-cols-[5.5rem_1fr]">
<dt className="text-muted-foreground">应用</dt>
<dd className="font-medium">Nav</dd>

<dt className="text-muted-foreground">版本</dt>
<dd>
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs">
{__APP_VERSION__}
</code>
</dd>

<dt className="text-muted-foreground">开源仓库</dt>
<dd>
<a
href="https://github.com/WorkerHub/nav"
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1 text-primary underline-offset-4 hover:underline"
>
WorkerHub/nav
<ExternalLink className="size-3.5" aria-hidden="true" />
</a>
</dd>

<dt className="text-muted-foreground">技术栈</dt>
<dd>
React · TypeScript · Vite · Tailwind CSS · shadcn/ui · Cloudflare
Workers
</dd>
</dl>

<Separator />

<p className="text-xs text-muted-foreground">
© {year} Nav · 保留所有权利
</p>
</div>
);
}
17 changes: 15 additions & 2 deletions web/src/components/admin/admin-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ArrowDownUp,
ArrowLeft,
FolderTree,
Info,
Layers,
Link as LinkIcon,
LogOut,
Expand All @@ -11,6 +12,7 @@ import {
Wrench,
} from "lucide-react";
import * as React from "react";
import { AboutPanel } from "@/components/admin/about-panel";
import { CategoryPanel, LinkPanel } from "@/components/admin/crud-panels";
import { ScenePanel } from "@/components/admin/scene-panel";
import { SecurityPanel } from "@/components/admin/security-panel";
Expand Down Expand Up @@ -39,8 +41,8 @@ import type { AdminScene } from "@/lib/types";
* + 玻璃内容卡。分区菜单用 Radix Tabs 单一根:宽屏是左栏竖排,窄屏变内容区顶部的
* 横向滚动菜单条(同一个 TabsList,只换 orientation 与响应式类,不做抽屉)。
*
* 分区内容(分类 / 链接 / 搜索引擎 / 站点设置 / 导入导出 / 安全·两步验证 /
* 系统管理)的容器换成了玻璃卡,面板组件本身的表单与业务逻辑不动。
* 分区内容(分类 / 链接 / 场景管理 / 搜索引擎 / 站点设置 / 导入导出 /
* 安全·两步验证 / 系统管理 / 关于)的容器换成了玻璃卡,面板组件本身的表单与业务逻辑不动。
*
* 后台数据由 store(useNavStore.adminData)承载,本页只负责加载与分发;
* 安全区的数据(2FA 状态、Passkey 凭据)属会话期敏感数据,由 SecurityPanel 自行拉取,
Expand All @@ -57,6 +59,7 @@ const ADMIN_TABS = [
{ value: "io", label: "导入导出", icon: ArrowDownUp },
{ value: "security", label: "安全 / 两步验证", icon: ShieldCheck },
{ value: "system", label: "系统管理", icon: Wrench },
{ value: "about", label: "关于", icon: Info },
] as const;

/** 与 Tailwind `lg` 断点保持一致:左栏竖排 ↔ 顶部横排菜单条的分界。 */
Expand Down Expand Up @@ -137,6 +140,9 @@ export function AdminPage({ onBack }: { onBack: () => void }) {
const sceneCategories = activeScene
? filterByScene(categories, activeScene)
: categories;
// 当前场景的可见性:分类列表据此提示「场景私有,对外不可见」(两层取与)
const activeSceneVisibility =
scenes.find((scene) => scene.id === activeScene)?.visibility ?? "public";

return (
<div className="relative min-h-screen">
Expand Down Expand Up @@ -235,6 +241,7 @@ export function AdminPage({ onBack }: { onBack: () => void }) {
<CategoryPanel
categories={sceneCategories}
sceneId={activeScene}
sceneVisibility={activeSceneVisibility}
onChanged={() => void loadAdmin()}
/>
</div>
Expand Down Expand Up @@ -304,6 +311,12 @@ export function AdminPage({ onBack }: { onBack: () => void }) {
<SystemPanel />
</PanelCard>
</TabsContent>

<TabsContent value="about">
<PanelCard>
<AboutPanel />
</PanelCard>
</TabsContent>
</div>
</Tabs>
) : (
Expand Down
17 changes: 16 additions & 1 deletion web/src/components/admin/crud-panels.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from "react";
import { EyeOff } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -42,16 +43,24 @@ import {
import { useNavStore } from "@/lib/nav-store";
import type { AdminCategory, AdminLink, Visibility } from "@/lib/types";

/** 分类 CRUD + dnd-kit 拖拽排序(分类列表由调用方按当前场景过滤后传入) */
/**
* 分类 CRUD + dnd-kit 拖拽排序(分类列表由调用方按当前场景过滤后传入)。
*
* 两层取与(场景公开 AND 分类公开):所在场景为私有时,行内额外给一条有效状态
* 提示「场景私有,对外不可见」—— 分类自身的公开/私有徽标仍按自身标记展示。
*/
export function CategoryPanel({
categories,
sceneId,
sceneVisibility = "public",
onChanged,
}: {
/** 当前场景的分类(已按 sceneId 过滤;无场景概念时为全量) */
categories: AdminCategory[];
/** 新建分类的归属场景;null/未传 = 无场景概念(旧后端),不提交该字段 */
sceneId?: string | null;
/** 当前场景的可见性:private 时行内提示「对外不可见」;未传按公开 */
sceneVisibility?: Visibility;
onChanged: () => void;
}) {
const [editing, setEditing] = React.useState<AdminCategory | null>(null);
Expand Down Expand Up @@ -160,6 +169,12 @@ export function CategoryPanel({
<Badge variant={c.visibility === "private" ? "default" : "secondary"}>
{c.visibility === "private" ? "私有" : "公开"}
</Badge>
{sceneVisibility === "private" && (
<Badge variant="outline" className="gap-1">
<EyeOff aria-hidden="true" />
场景私有,对外不可见
</Badge>
)}
</span>
),
}));
Expand Down
32 changes: 30 additions & 2 deletions web/src/components/admin/scene-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import {
AssetThumb,
AssetUploadField,
Expand All @@ -28,7 +29,7 @@ import {
} from "@/lib/api";
import { useNavStore } from "@/lib/nav-store";
import { defaultScene } from "@/lib/scene-preference";
import type { AdminScene } from "@/lib/types";
import type { AdminScene, Visibility } from "@/lib/types";

/**
* 场景管理(后台「场景管理」分区,冻结契约 #16 §七)。
Expand All @@ -40,6 +41,9 @@ import type { AdminScene } from "@/lib/types";
* - 删除非默认场景不会丢数据:后端单事务把它的分类(链接随分类走)移入默认场景;
* 确认文案里写明移入哪个场景(取默认场景当前名称);
* - 场景 `sortOrder` 是全局顺序(决定前台/后台胶囊的段序),用 store 的乐观排序。
* - 可见性(nav #19 §B4):与分类表单同一 pattern 的「私有场景」Switch,列表行
* 带公开/私有徽标;默认场景必须公开(契约禁止 default → private),表单里直接
* 禁用该开关并说明原因,不把一个必然 400 的请求发出去。
*/
export function ScenePanel({
scenes,
Expand All @@ -52,13 +56,15 @@ export function ScenePanel({
const [creating, setCreating] = React.useState(false);
const [name, setName] = React.useState("");
const [icon, setIcon] = React.useState("");
const [visibility, setVisibility] = React.useState<Visibility>("public");
const draft = useAssetDraftCleanup();

const fallbackScene = defaultScene(scenes);

const openCreate = () => {
setName("");
setIcon("");
setVisibility("public");
setCreating(true);
setEditing(null);
};
Expand All @@ -68,6 +74,7 @@ export function ScenePanel({
if (!scene) return;
setName(scene.name);
setIcon(scene.icon ?? "");
setVisibility(scene.visibility === "private" ? "private" : "public");
setEditing(scene);
setCreating(false);
};
Expand All @@ -85,7 +92,7 @@ export function ScenePanel({
return;
}
const previousIcon = editing?.icon ?? null;
const payload = { name: nextName, icon: icon || null };
const payload = { name: nextName, icon: icon || null, visibility };
try {
if (editing) {
await adminUpdateScene(editing.id, payload);
Expand Down Expand Up @@ -140,6 +147,11 @@ export function ScenePanel({
meta: (
<span className="flex items-center gap-2">
<AssetThumb src={scene.icon} alt="" />
<Badge
variant={scene.visibility === "private" ? "default" : "secondary"}
>
{scene.visibility === "private" ? "私有" : "公开"}
</Badge>
{scene.isDefault && <Badge variant="secondary">默认</Badge>}
</span>
),
Expand Down Expand Up @@ -192,6 +204,22 @@ export function ScenePanel({
onChange={setIcon}
onUploaded={draft.track}
/>
<div className="flex items-center justify-between gap-4">
<div className="grid gap-1">
<Label htmlFor="scene-vis">私有场景</Label>
{editing?.isDefault && (
<p className="text-xs text-muted-foreground">
默认场景必须公开,不能设为私有。
</p>
)}
</div>
<Switch
id="scene-vis"
checked={visibility === "private"}
disabled={editing?.isDefault ?? false}
onCheckedChange={(v) => setVisibility(v ? "private" : "public")}
/>
</div>
</div>
<DialogFooter>
<Button onClick={() => void save()}>保存</Button>
Expand Down
60 changes: 32 additions & 28 deletions web/src/components/public-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import { Button } from "@/components/ui/button";
import { WallpaperBackground } from "@/components/wallpaper-background";
import { useAuthenticated, useNavStore } from "@/lib/nav-store";
import {
ALL_SCENES,
filterByScene,
resolvePublicScene,
sortCategoriesByScene,
useScenePreferenceStore,
} from "@/lib/scene-preference";

/**
* 公开页(/):背景图 + 整条毛玻璃顶栏(站点标题/Logo + 登录态操作)+ 毛玻璃搜索框
* + 「我的导航」图标网格 + 登录后的私有区。
* 公开页(/):背景图 + 整条毛玻璃顶栏(站点标题/Logo + 场景胶囊 + 登录态操作)
* + 毛玻璃搜索框 + 「我的导航」图标网格 + 登录后的私有区。
*
* 场景(与分类正交):搜索区与导航区之间是场景切换胶囊(只有 1 个场景时不渲染),
* 选中值来自本机偏好 `nav.scene`;切换只过滤前端已拿到的全量数据,不发请求。
* 场景(与分类正交):胶囊在顶栏内部居中(标题在左、操作在右),窄屏在栏内横向
* 滚动、不另起一行;选中值来自本机偏好 `nav.scene`,切换只过滤前端已拿到的数据、
* 不发请求。胶囊只列当前视角的 `scenes`(未登录只有公开场景、登录全量),
* 组件内不做可见性判断 —— 两层取与由数据层完成。
*
* 安全口径:未登录时私有区完全不渲染 —— privateData 未加载时组件树里没有私有区块,
* 数据请求也只发 /api/public(未登录不请求 /api/private)。
Expand Down Expand Up @@ -60,16 +60,15 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
const siteData = (authenticated && privateData) || publicData;
const settings = siteData?.settings;
const categories = siteData?.categories ?? [];
// 旧后端 / 浏览器旧缓存没有 scenes:按「无场景概念」平铺展示,不渲染胶囊
// 当前视角的场景全集:未登录只有公开场景、登录全量(数据层过滤,组件不再判断)。
// 旧后端 / 浏览器旧缓存没有 scenes:按「无场景概念」平铺展示,不渲染胶囊。
const scenes = siteData?.scenes ?? [];
// 偏好命中可用场景就用它,否则回落默认场景;没有场景时 null(不做场景过滤)。
// 本机偏好若指向私有场景,未登录时它不在 scenes 里 → 自然落回公开的默认场景。
const activeScene = resolvePublicScene(scenePreference, scenes);
const filteredCategories = filterByScene(categories, activeScene);
// 「全部」视图按(场景 sortOrder,分类 sortOrder)本地排序:分类的 sort_order 是
// 场景内序号,直接混排会 A0/B0/A1/B1 交错;只排序、不加场景分段标题(仍是现状平铺)。
const visibleCategories =
activeScene === ALL_SCENES
? sortCategoriesByScene(filteredCategories, scenes)
: filteredCategories;
const visibleCategories = activeScene
? filterByScene(categories, activeScene)
: categories;
// 只有 1 个场景(仅「通用」)时与现状一致:不显示胶囊
const showSceneSwitcher = scenes.length > 1;

Expand All @@ -84,9 +83,9 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
{/* 背景层(与后台共用同一份实现):全屏背景图 + 阅读性罩层 */}
<WallpaperBackground settings={settings} />

{/* 顶栏:整条毛玻璃,左侧站点标题/Logo,右侧后台、退出与主题切换 */}
{/* 顶栏:整条毛玻璃,左侧站点标题/Logo,中间场景胶囊,右侧后台、退出与主题切换 */}
<header className="glass-bar sticky top-0 z-20">
<FadeIn className="mx-auto flex h-14 max-w-7xl items-center gap-3 px-4 sm:px-8">
<FadeIn className="mx-auto flex h-14 max-w-7xl items-center gap-2 px-4 sm:gap-3 sm:px-8">
{/*
站点标题放在顶栏(h1 语义):logoUrl 有值显示适配栏高的 Logo 图,否则显示站点标题文字。
文字沿用顶栏 text-foreground 口径(与右侧按钮一致):浅色档玻璃底近白、深色档近黑,两档对比度都成立。
Expand All @@ -104,6 +103,22 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
</span>
)}
</h1>
{/*
场景胶囊在顶栏内部居中:占中间剩余空间,左右两组不因此位移。
窄屏不换行、在栏内横向滚动(flex-nowrap + overflow-x-auto),
标题继续按原布局在左,登录/后台/主题按钮在右。
*/}
{showSceneSwitcher && activeScene && (
<div className="flex min-w-0 flex-1 justify-center">
<SceneSwitcher
scenes={scenes}
value={activeScene}
onValueChange={setScenePreference}
className="no-scrollbar max-w-full flex-nowrap overflow-x-auto"
ariaLabel="切换场景"
/>
</div>
)}
<div className="ml-auto flex shrink-0 items-center gap-2">
{/*
顶栏按钮统一用前景色:浅色档的玻璃芯片是近白底,白字对比度只有 2.4:1。
Expand Down Expand Up @@ -162,19 +177,8 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
)}
</FadeIn>

{/* 导航区:场景胶囊(可选)+ 分类区块;胶囊在搜索区与导航区之间 */}
{/* 导航区:分类区块;场景胶囊在顶栏,不占用页面区 */}
<div className="flex flex-col gap-10">
{showSceneSwitcher && (
<FadeIn>
<SceneSwitcher
scenes={scenes}
value={activeScene}
onValueChange={setScenePreference}
includeAll
ariaLabel="切换场景"
/>
</FadeIn>
)}
{visibleCategories.map((category, i) => (
<FadeIn key={category.id} delay={Math.min(i * 0.05, 0.3)}>
<CategorySection
Expand Down
Loading
Loading