diff --git a/.gitignore b/.gitignore
index dce0379..4473910 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,4 +43,6 @@ next-env.d.ts
haoqi_clone
.workbuddy/
-outputs/
\ No newline at end of file
+outputs/
+# SQLite 数据(后台内容库,部署时需持久化)
+/data
diff --git a/app/(site)/layout.tsx b/app/(site)/layout.tsx
new file mode 100644
index 0000000..bb95ef8
--- /dev/null
+++ b/app/(site)/layout.tsx
@@ -0,0 +1,55 @@
+import SmoothScroller from "@/components/dom/SmoothScroller";
+import Header from "@/components/dom/Header";
+import BackgroundGrid from "@/components/dom/BackgroundGrid";
+import CustomScrollbar from "@/components/dom/CustomScrollbar";
+import LoadingOverlay from "@/components/dom/LoadingOverlay";
+import { HeroScene } from "@/components/canvas/HeroScene";
+import { PasscodeAccessProvider } from "@/components/dom/PasscodeAccess";
+import { FullscreenTransitionProvider } from "@/lib/routeTransition";
+import RouteTransitionOverlay from "@/components/dom/RouteTransitionOverlay";
+import { getPasscodeAccessServer } from "@/lib/passcodeServer";
+import { getSiteConfig } from "@/lib/siteConfig";
+import type { Metadata } from "next";
+
+/**
+ * (site) 布局 — 公开站点的完整壳层:WebGL 画布、网格、平滑滚动、
+ * Header、路由过渡。/virtheart 后台不套用此壳层(纯净布局)。
+ * 站点文案从 site_config 读出后以 props 下发(Header 品牌/版权、
+ * 自我介绍槽位等),后台改完即时生效。
+ */
+export async function generateMetadata(): Promise {
+ const config = getSiteConfig();
+ return {
+ title: config.site_title,
+ description: config.site_description,
+ };
+}
+
+export default async function SiteLayout({
+ children,
+}: Readonly<{
+ children: React.ReactNode;
+}>) {
+ const [initialAccess, config] = await Promise.all([
+ getPasscodeAccessServer(),
+ Promise.resolve(getSiteConfig()),
+ ]);
+ return (
+
+
+ {/* Original stacking (1:1): the WebGL canvas host is a plain `fixed`
+ z-auto element first in the body; the grid overlay (z-20) comes
+ AFTER it in DOM order so it paints above the canvas, exactly like
+ the original's main > canvas + z-20 grid sibling. */}
+
+
+
+
+ {children}
+
+
+
+
+
+ );
+}
diff --git a/app/page.tsx b/app/(site)/page.tsx
similarity index 58%
rename from app/page.tsx
rename to app/(site)/page.tsx
index 7b965a7..fae7f5a 100644
--- a/app/page.tsx
+++ b/app/(site)/page.tsx
@@ -4,14 +4,28 @@ import FooterSection from "@/components/dom/FooterSection";
import WorkSection from "@/components/dom/WorkSection";
import HyperSpaceSection from "@/components/dom/HyperSpaceSection";
import PasscodeRevealText from "@/components/dom/PasscodeRevealText";
+import { getSiteConfig, listWorks } from "@/lib/siteConfig";
+import type { WorkItem } from "@/lib/workItems";
/**
- * Page content matching the original DOM (haoqi_body.html):
- * - banner section (h-dvh) with meta row + big title, all scramble-revealed
- * - signature/about section (kept simple)
+ * 首页 — 结构复刻原站(haoqi_body.html),文案全部来自 site_config
+ *(/virtheart 后台「配置」可改,保存即生效);作品来自 works 表。
*/
-
-export default function Home() {
+export default async function Home() {
+ const config = getSiteConfig();
+ const items: WorkItem[] = listWorks(true)
+ .filter((w) => w.name && (w.image_url || w.href))
+ .map((w) => ({
+ name: w.name,
+ imageUrl: w.image_url,
+ hoverImageUrl: w.hover_image_url,
+ href: w.href || `/work/${w.slug}`,
+ year: w.year,
+ type: w.type,
+ gridClass: w.grid_class || "col-span-12 lg:col-span-6 xl:col-span-4",
+ codingProject: w.coding_project === 1,
+ passcodeProtected: w.passcode_protected === 1,
+ }));
return (
// NOTE: the original scrolls INSIDE (its Lenis wraps the main
// container), which is what lets its position:sticky children pin. Our
@@ -26,25 +40,30 @@ export default function Home() {
>
-
-
-
+
+
+
@@ -59,10 +78,7 @@ export default function Home() {
'var(--font-tiktok), "MiSans", sans-serif',
}}
>
-
- 全栈开发者,融合产品设计与工程能力,负责从产品构思、界面设计到前后端、跨端客户端的完整应用交付,现阶段深耕
- AI 应用开发。
-
+ {config.about_p1}
-
- 我相信工程塑造可靠的产品,设计赋予它们灵魂;
+
+ {config.about_p2}
- 我的作品
+ {config.about_p2_link_label}
- 里记录了这些探索的痕迹。
+ {config.about_p2.endsWith(";") || config.about_p2.endsWith(",")
+ ? "里记录了这些探索的痕迹。"
+ : ""}
{/* Selected Work grid (id="selected-work", WebGL image layers) */}
-
+
{/* Hyper-space scroll section (id="hyper-space"): the WebGL
hyperspace arrow (cursor.glb stripes) tracks this section's
@@ -94,7 +122,7 @@ export default function Home() {
{/* Contact / Footer Section (#contact, data-section="footer") */}
-
+
);
diff --git a/app/(site)/services/ServicesClient.tsx b/app/(site)/services/ServicesClient.tsx
new file mode 100644
index 0000000..9ca79f1
--- /dev/null
+++ b/app/(site)/services/ServicesClient.tsx
@@ -0,0 +1,299 @@
+"use client";
+
+/**
+ * 服务页(client)— 与主站同一设计语言:
+ * 大字 scramble 标题、编号服务菜单(NO.01…)、选择后展开留言表单,
+ * 提交触发全屏居中滑块验证码,通过后 POST /api/inquiry(后端入库 +
+ * 邮件通知 chenchun@virtheart.com)。
+ */
+import { useCallback, useMemo, useState } from "react";
+import ScrambleReveal from "@/components/dom/ScrambleReveal";
+import SliderCaptcha from "@/components/dom/SliderCaptcha";
+import { useRouteTransitionController } from "@/lib/routeTransition";
+import { CONTACT_EMAIL } from "@/lib/socials";
+
+export type ServiceOption = {
+ slug: string;
+ title: string;
+ description: string;
+ priceNote: string;
+};
+
+const inputCls =
+ "w-full border border-line bg-b1 px-3 py-2.5 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1 placeholder:text-l3";
+const labelCls = "mb-1.5 block font-mono-2 text-xs uppercase tracking-widest text-l2";
+const dotted =
+ "relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1";
+
+export default function ServicesClient({
+ headline,
+ submitNote,
+ services,
+}: {
+ headline: string;
+ submitNote: string;
+ services: ServiceOption[];
+}) {
+ const { startNavigation } = useRouteTransitionController();
+ const headlineLines = useMemo(
+ () => (headline || "可提供的服务|选择你需要的服务,留言告诉我").split("|"),
+ [headline]
+ );
+ const [selected, setSelected] = useState(null);
+ const [name, setName] = useState("");
+ const [contact, setContact] = useState("");
+ const [message, setMessage] = useState("");
+ const [captchaOpen, setCaptchaOpen] = useState(false);
+ const [submitting, setSubmitting] = useState(false);
+ const [error, setError] = useState(null);
+ const [doneId, setDoneId] = useState(null);
+
+ const canSubmit = selected && name.trim() && contact.trim() && message.trim();
+
+ const startSubmit = useCallback(() => {
+ if (!canSubmit || submitting) return;
+ setError(null);
+ setCaptchaOpen(true);
+ }, [canSubmit, submitting]);
+
+ const onCaptchaVerified = useCallback(
+ async (submitToken: string) => {
+ if (!selected) return;
+ setSubmitting(true);
+ setError(null);
+ try {
+ const res = await fetch("/api/inquiry", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ submitToken,
+ name: name.trim(),
+ contact: contact.trim(),
+ serviceSlug: selected.slug,
+ serviceTitle: selected.title,
+ message: message.trim(),
+ }),
+ });
+ const data = (await res.json()) as { id?: number; error?: string };
+ if (!res.ok) {
+ setError(data.error ?? "提交失败,请重试");
+ setCaptchaOpen(false);
+ return;
+ }
+ setDoneId(data.id ?? 0);
+ setCaptchaOpen(false);
+ } catch {
+ setError("网络错误,请重试");
+ setCaptchaOpen(false);
+ } finally {
+ setSubmitting(false);
+ }
+ },
+ [selected, name, contact, message]
+ );
+
+ if (doneId !== null) {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+ }
+
+ return (
+
+
+
+ {headlineLines.map((line, i) => (
+ 0 ? "block text-right lg:text-right" : "block"}>
+ 0}
+ scrambleColors={false}
+ />
+
+ ))}
+
+
+
+
+
+
+
+ {/* 服务菜单 */}
+
+ {services.length === 0 ? (
+
+ 服务清单整理中——有需要可直接写邮件给我。
+
+ ) : (
+
+ {services.map((s, i) => {
+ const active = selected?.slug === s.slug;
+ return (
+ -
+
+ {active && s.description && (
+
+ {s.description}
+
+ )}
+
+ );
+ })}
+
+ )}
+
+
+ {/* 留言表单 */}
+
+
+ {selected ? `咨询:${selected.title}` : "留言"}
+
+
+
+
+ {error && (
+
+ {error}
+
+ )}
+
+
+
+
+ !submitting && setCaptchaOpen(false)}
+ onVerified={onCaptchaVerified}
+ />
+
+ );
+}
diff --git a/app/(site)/services/page.tsx b/app/(site)/services/page.tsx
new file mode 100644
index 0000000..afd204e
--- /dev/null
+++ b/app/(site)/services/page.tsx
@@ -0,0 +1,28 @@
+import type { Metadata } from "next";
+import ServicesClient from "./ServicesClient";
+import { getSiteConfig, listServices } from "@/lib/siteConfig";
+
+export const metadata: Metadata = {
+ title: "服务 · 北极新一",
+ description: "可提供的服务 — 选择你需要的服务,留言告诉我",
+};
+
+export const dynamic = "force-dynamic";
+
+/** /services — 服务列表(server 读 DB)+ 咨询表单(滑块验证码)。 */
+export default function ServicesPage() {
+ const config = getSiteConfig();
+ const services = listServices(true).map((s) => ({
+ slug: s.slug,
+ title: s.title,
+ description: s.description,
+ priceNote: s.price_note,
+ }));
+ return (
+
+ );
+}
diff --git a/app/unlock/[scope]/page.tsx b/app/(site)/unlock/[scope]/page.tsx
similarity index 100%
rename from app/unlock/[scope]/page.tsx
rename to app/(site)/unlock/[scope]/page.tsx
diff --git a/app/work/[slug]/layout.tsx b/app/(site)/work/[slug]/layout.tsx
similarity index 100%
rename from app/work/[slug]/layout.tsx
rename to app/(site)/work/[slug]/layout.tsx
diff --git a/app/work/[slug]/page.tsx b/app/(site)/work/[slug]/page.tsx
similarity index 100%
rename from app/work/[slug]/page.tsx
rename to app/(site)/work/[slug]/page.tsx
diff --git a/app/api/admin/config/route.ts b/app/api/admin/config/route.ts
new file mode 100644
index 0000000..67b1e2f
--- /dev/null
+++ b/app/api/admin/config/route.ts
@@ -0,0 +1,32 @@
+/** /api/admin/config — 站点配置读写。 */
+import { NextResponse } from "next/server";
+import { getSession, verifyCsrf } from "@/lib/auth";
+import { CONFIG_KEYS, getSiteConfig, setSiteConfig, type SiteConfig } from "@/lib/siteConfig";
+
+export const runtime = "nodejs";
+
+export async function GET() {
+ if (!(await getSession())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ return NextResponse.json({ config: getSiteConfig() });
+}
+
+export async function PUT(req: Request) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ let body: Partial;
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const patch: Partial> = {};
+ for (const key of CONFIG_KEYS) {
+ const v = (body as Record)[key];
+ if (typeof v === "string") patch[key] = v;
+ }
+ setSiteConfig(patch);
+ return NextResponse.json({ ok: true, config: getSiteConfig() });
+}
diff --git a/app/api/admin/inquiries/route.ts b/app/api/admin/inquiries/route.ts
new file mode 100644
index 0000000..e38fba2
--- /dev/null
+++ b/app/api/admin/inquiries/route.ts
@@ -0,0 +1,53 @@
+/** /api/admin/inquiries — 留言箱:列表 / 状态更新 / 删除。 */
+import { NextResponse } from "next/server";
+import { getSession, verifyCsrf } from "@/lib/auth";
+import {
+ deleteInquiry,
+ listInquiries,
+ updateInquiryStatus,
+ type InquiryRow,
+} from "@/lib/siteConfig";
+
+export const runtime = "nodejs";
+
+export async function GET() {
+ if (!(await getSession())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ return NextResponse.json({ inquiries: listInquiries(200) });
+}
+
+export async function PATCH(req: Request) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ let body: { id?: number; status?: InquiryRow["status"] };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const valid: InquiryRow["status"][] = ["new", "read", "replied", "archived"];
+ if (
+ !Number.isInteger(body.id) ||
+ !body.status ||
+ !valid.includes(body.status)
+ ) {
+ return NextResponse.json({ error: "参数错误" }, { status: 400 });
+ }
+ updateInquiryStatus(body.id as number, body.status);
+ return NextResponse.json({ ok: true });
+}
+
+export async function DELETE(req: Request) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ const { searchParams } = new URL(req.url);
+ const id = Number(searchParams.get("id"));
+ if (!Number.isInteger(id)) {
+ return NextResponse.json({ error: "无效 ID" }, { status: 400 });
+ }
+ deleteInquiry(id);
+ return NextResponse.json({ ok: true });
+}
diff --git a/app/api/admin/login/route.ts b/app/api/admin/login/route.ts
new file mode 100644
index 0000000..26cd7ff
--- /dev/null
+++ b/app/api/admin/login/route.ts
@@ -0,0 +1,40 @@
+/**
+ * /api/admin/login — 后台登录。
+ * POST { username, password } → 设置 httpOnly 会话 cookie。
+ */
+import { NextResponse } from "next/server";
+import { createSession, SESSION_COOKIE } from "@/lib/auth";
+import { verifyAdminPassword } from "@/lib/auth";
+
+export const runtime = "nodejs";
+
+export async function POST(req: Request) {
+ let body: { username?: string; password?: string };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const username = String(body.username ?? "").trim();
+ const password = String(body.password ?? "");
+ if (!username || !password) {
+ return NextResponse.json({ error: "请输入用户名和密码" }, { status: 400 });
+ }
+
+ const userId = verifyAdminPassword(username, password);
+ if (userId === null) {
+ // 统一错误信息,不区分用户名/密码错误(防枚举)
+ return NextResponse.json({ error: "用户名或密码不正确" }, { status: 401 });
+ }
+
+ const { token, csrf } = createSession(userId);
+ const res = NextResponse.json({ ok: true, csrf });
+ res.cookies.set(SESSION_COOKIE, token, {
+ httpOnly: true,
+ sameSite: "lax",
+ secure: process.env.NODE_ENV === "production",
+ path: "/",
+ maxAge: 60 * 60 * 24 * 7,
+ });
+ return res;
+}
diff --git a/app/api/admin/logout/route.ts b/app/api/admin/logout/route.ts
new file mode 100644
index 0000000..6d99beb
--- /dev/null
+++ b/app/api/admin/logout/route.ts
@@ -0,0 +1,13 @@
+/** /api/admin/logout — 清除会话。 */
+import { NextResponse } from "next/server";
+import { destroySession, getSession, SESSION_COOKIE } from "@/lib/auth";
+
+export const runtime = "nodejs";
+
+export async function POST() {
+ const session = await getSession();
+ if (session) destroySession(session.token);
+ const res = NextResponse.json({ ok: true });
+ res.cookies.set(SESSION_COOKIE, "", { path: "/", maxAge: 0 });
+ return res;
+}
diff --git a/app/api/admin/password/route.ts b/app/api/admin/password/route.ts
new file mode 100644
index 0000000..2d3ba82
--- /dev/null
+++ b/app/api/admin/password/route.ts
@@ -0,0 +1,24 @@
+/** /api/admin/password — 修改后台密码。 */
+import { NextResponse } from "next/server";
+import { changeAdminPassword, getSession, verifyCsrf } from "@/lib/auth";
+
+export const runtime = "nodejs";
+
+export async function PUT(req: Request) {
+ const session = await getSession();
+ if (!session || !(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ let body: { password?: string };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const password = String(body.password ?? "");
+ if (password.length < 8) {
+ return NextResponse.json({ error: "密码至少 8 位" }, { status: 400 });
+ }
+ await changeAdminPassword(session.user_id, password);
+ return NextResponse.json({ ok: true });
+}
diff --git a/app/api/admin/services/[id]/route.ts b/app/api/admin/services/[id]/route.ts
new file mode 100644
index 0000000..e974e48
--- /dev/null
+++ b/app/api/admin/services/[id]/route.ts
@@ -0,0 +1,22 @@
+/** /api/admin/services/[id] — 删除服务。 */
+import { NextResponse } from "next/server";
+import { verifyCsrf } from "@/lib/auth";
+import { deleteService } from "@/lib/siteConfig";
+
+export const runtime = "nodejs";
+
+export async function DELETE(
+ _req: Request,
+ { params }: { params: Promise<{ id: string }> }
+) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ const { id } = await params;
+ const numId = Number(id);
+ if (!Number.isInteger(numId)) {
+ return NextResponse.json({ error: "无效 ID" }, { status: 400 });
+ }
+ deleteService(numId);
+ return NextResponse.json({ ok: true });
+}
diff --git a/app/api/admin/services/route.ts b/app/api/admin/services/route.ts
new file mode 100644
index 0000000..57782fd
--- /dev/null
+++ b/app/api/admin/services/route.ts
@@ -0,0 +1,45 @@
+/** /api/admin/services — 服务项目管理。 */
+import { NextResponse } from "next/server";
+import { getSession, verifyCsrf } from "@/lib/auth";
+import { listServices, upsertService } from "@/lib/siteConfig";
+
+export const runtime = "nodejs";
+
+export async function GET() {
+ if (!(await getSession())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ return NextResponse.json({ services: listServices(false) });
+}
+
+export async function POST(req: Request) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ let body: {
+ id?: number;
+ title?: string;
+ description?: string;
+ price_note?: string;
+ sort_order?: number;
+ enabled?: number;
+ };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const title = String(body.title ?? "").trim();
+ if (!title) {
+ return NextResponse.json({ error: "服务名称必填" }, { status: 400 });
+ }
+ const row = upsertService({
+ id: body.id,
+ title,
+ description: body.description,
+ price_note: body.price_note,
+ sort_order: body.sort_order,
+ enabled: body.enabled,
+ });
+ return NextResponse.json({ ok: true, service: row });
+}
diff --git a/app/api/admin/upload/route.ts b/app/api/admin/upload/route.ts
new file mode 100644
index 0000000..18cba00
--- /dev/null
+++ b/app/api/admin/upload/route.ts
@@ -0,0 +1,56 @@
+/**
+ * /api/admin/upload — 图片上传(作品封面 / 服务配图)。
+ * multipart/form-data: file → 保存到 public/work/,返回可访问路径。
+ * 文件类型白名单 png/jpg/webp,大小 ≤ 8MB。
+ */
+import { NextResponse } from "next/server";
+import crypto from "node:crypto";
+import fs from "node:fs/promises";
+import path from "node:path";
+import { verifyCsrf } from "@/lib/auth";
+
+export const runtime = "nodejs";
+
+const ALLOWED: Record = {
+ "image/png": "png",
+ "image/jpeg": "jpg",
+ "image/webp": "webp",
+};
+const MAX_SIZE = 8 * 1024 * 1024;
+
+export async function POST(req: Request) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ let form: FormData;
+ try {
+ form = await req.formData();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const file = form.get("file");
+ if (!(file instanceof File)) {
+ return NextResponse.json({ error: "缺少文件" }, { status: 400 });
+ }
+ const ext = ALLOWED[file.type];
+ if (!ext) {
+ return NextResponse.json(
+ { error: "仅支持 PNG / JPG / WebP" },
+ { status: 400 }
+ );
+ }
+ if (file.size > MAX_SIZE) {
+ return NextResponse.json({ error: "文件不能超过 8MB" }, { status: 400 });
+ }
+
+ const dir = path.join(process.cwd(), "public", "work");
+ await fs.mkdir(dir, { recursive: true });
+ const name = `${Date.now().toString(36)}-${crypto
+ .randomBytes(4)
+ .toString("hex")}.${ext}`;
+ await fs.writeFile(
+ path.join(dir, name),
+ Buffer.from(await file.arrayBuffer())
+ );
+ return NextResponse.json({ ok: true, url: `/work/${name}` });
+}
diff --git a/app/api/admin/works/[id]/route.ts b/app/api/admin/works/[id]/route.ts
new file mode 100644
index 0000000..15ff8a4
--- /dev/null
+++ b/app/api/admin/works/[id]/route.ts
@@ -0,0 +1,22 @@
+/** /api/admin/works/[id] — 删除作品。 */
+import { NextResponse } from "next/server";
+import { verifyCsrf } from "@/lib/auth";
+import { deleteWork } from "@/lib/siteConfig";
+
+export const runtime = "nodejs";
+
+export async function DELETE(
+ _req: Request,
+ { params }: { params: Promise<{ id: string }> }
+) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ const { id } = await params;
+ const numId = Number(id);
+ if (!Number.isInteger(numId)) {
+ return NextResponse.json({ error: "无效 ID" }, { status: 400 });
+ }
+ deleteWork(numId);
+ return NextResponse.json({ ok: true });
+}
diff --git a/app/api/admin/works/route.ts b/app/api/admin/works/route.ts
new file mode 100644
index 0000000..c4311a3
--- /dev/null
+++ b/app/api/admin/works/route.ts
@@ -0,0 +1,31 @@
+/** /api/admin/works — 作品列表 + 新增/更新(upsert by slug)。 */
+import { NextResponse } from "next/server";
+import { getSession, verifyCsrf } from "@/lib/auth";
+import { listWorks, upsertWork, type WorkRow } from "@/lib/siteConfig";
+
+export const runtime = "nodejs";
+
+export async function GET() {
+ if (!(await getSession())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ return NextResponse.json({ works: listWorks(false) });
+}
+
+export async function POST(req: Request) {
+ if (!(await verifyCsrf())) {
+ return NextResponse.json({ error: "未登录" }, { status: 401 });
+ }
+ let body: Partial & { name?: string };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const name = String(body.name ?? "").trim();
+ if (!name) {
+ return NextResponse.json({ error: "作品名称必填" }, { status: 400 });
+ }
+ const row = upsertWork({ ...body, name });
+ return NextResponse.json({ ok: true, work: row });
+}
diff --git a/app/api/captcha/new/route.ts b/app/api/captcha/new/route.ts
new file mode 100644
index 0000000..1511d3f
--- /dev/null
+++ b/app/api/captcha/new/route.ts
@@ -0,0 +1,10 @@
+/** /api/captcha/new — 生成滑块挑战(公开)。 */
+import { NextResponse } from "next/server";
+import { createCaptchaChallenge } from "@/lib/captcha";
+
+export const runtime = "nodejs";
+
+export async function POST() {
+ const challenge = createCaptchaChallenge();
+ return NextResponse.json(challenge);
+}
diff --git a/app/api/captcha/verify/route.ts b/app/api/captcha/verify/route.ts
new file mode 100644
index 0000000..f179c74
--- /dev/null
+++ b/app/api/captcha/verify/route.ts
@@ -0,0 +1,24 @@
+/** /api/captcha/verify — 校验滑块位置,通过则签发一次性提交令牌。 */
+import { NextResponse } from "next/server";
+import { verifyCaptcha } from "@/lib/captcha";
+
+export const runtime = "nodejs";
+
+export async function POST(req: Request) {
+ let body: { token?: string; x?: number };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+ const token = String(body.token ?? "");
+ const x = Number(body.x);
+ if (!token || !Number.isFinite(x)) {
+ return NextResponse.json({ error: "参数错误" }, { status: 400 });
+ }
+ const result = verifyCaptcha(token, Math.round(x));
+ if (!result.ok) {
+ return NextResponse.json({ error: result.error }, { status: 400 });
+ }
+ return NextResponse.json({ ok: true, submitToken: result.submitToken });
+}
diff --git a/app/api/inquiry/route.ts b/app/api/inquiry/route.ts
new file mode 100644
index 0000000..dc56e08
--- /dev/null
+++ b/app/api/inquiry/route.ts
@@ -0,0 +1,84 @@
+/**
+ * /api/inquiry — 服务咨询提交(公开)。
+ * 必须携带滑块验证通过后签发的一次性 submitToken。
+ * 入库后异步发通知邮件到 chenchun@virtheart.com(失败不影响入库,
+ * 状态记录在 inquiries.email_sent / email_error,后台留言箱可见)。
+ */
+import { NextResponse } from "next/server";
+import { consumeSubmitToken } from "@/lib/captcha";
+import { createInquiry, markInquiryEmail } from "@/lib/siteConfig";
+import { sendInquiryNotification } from "@/lib/mailer";
+
+export const runtime = "nodejs";
+
+const NAME_MAX = 40;
+const CONTACT_MAX = 80;
+const MESSAGE_MAX = 2000;
+
+export async function POST(req: Request) {
+ let body: {
+ submitToken?: string;
+ name?: string;
+ contact?: string;
+ serviceSlug?: string;
+ serviceTitle?: string;
+ message?: string;
+ };
+ try {
+ body = await req.json();
+ } catch {
+ return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
+ }
+
+ const name = String(body.name ?? "").trim();
+ const contact = String(body.contact ?? "").trim();
+ const message = String(body.message ?? "").trim();
+ const serviceSlug = String(body.serviceSlug ?? "").slice(0, 80);
+ const serviceTitle = String(body.serviceTitle ?? "").slice(0, 120);
+
+ if (!name || !contact || !message) {
+ return NextResponse.json(
+ { error: "姓名、联系方式和留言内容都不能为空" },
+ { status: 400 }
+ );
+ }
+ if (name.length > NAME_MAX || contact.length > CONTACT_MAX || message.length > MESSAGE_MAX) {
+ return NextResponse.json({ error: "内容超出长度限制" }, { status: 400 });
+ }
+
+ // 滑块一次性令牌校验(消费即作废,防重放)
+ const submitToken = String(body.submitToken ?? "");
+ if (!submitToken || !consumeSubmitToken(submitToken)) {
+ return NextResponse.json(
+ { error: "验证已失效,请重新完成滑块验证" },
+ { status: 403 }
+ );
+ }
+
+ const inquiry = createInquiry({
+ name,
+ contact,
+ service_slug: serviceSlug,
+ service_title: serviceTitle,
+ message,
+ });
+
+ // 邮件通知:失败不阻塞提交
+ try {
+ await sendInquiryNotification({
+ id: inquiry.id,
+ name: inquiry.name,
+ contact: inquiry.contact,
+ service_title: inquiry.service_title,
+ message: inquiry.message,
+ created_at: inquiry.created_at,
+ });
+ markInquiryEmail(inquiry.id, true);
+ } catch (err) {
+ const msg = err instanceof Error ? err.message : String(err);
+ markInquiryEmail(inquiry.id, false, msg.slice(0, 300));
+ console.error("[inquiry] 邮件通知失败:", msg);
+ }
+
+ return NextResponse.json({ ok: true, id: inquiry.id });
+}
diff --git a/app/globals.css b/app/globals.css
index 9af7ca3..2ca15a0 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -140,6 +140,26 @@ html::-webkit-scrollbar, body::-webkit-scrollbar {
animation: caret-blink 1s step-end infinite;
}
+/* 滑块验证码 — 校验失败抖动。 */
+@keyframes vh-shake {
+ 0%,
+ 100% {
+ transform: translateX(0);
+ }
+ 20% {
+ transform: translateX(-6px);
+ }
+ 40% {
+ transform: translateX(6px);
+ }
+ 60% {
+ transform: translateX(-4px);
+ }
+ 80% {
+ transform: translateX(4px);
+ }
+}
+
@keyframes hsstFadeIn {
0% {
opacity: 0;
diff --git a/app/layout.tsx b/app/layout.tsx
index 52e0c9d..d8c1e4a 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -1,16 +1,6 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
-import SmoothScroller from "@/components/dom/SmoothScroller";
-import Header from "@/components/dom/Header";
-import BackgroundGrid from "@/components/dom/BackgroundGrid";
-import CustomScrollbar from "@/components/dom/CustomScrollbar";
-import LoadingOverlay from "@/components/dom/LoadingOverlay";
-import { HeroScene } from "@/components/canvas/HeroScene";
-import { PasscodeAccessProvider } from "@/components/dom/PasscodeAccess";
-import { FullscreenTransitionProvider } from "@/lib/routeTransition";
-import RouteTransitionOverlay from "@/components/dom/RouteTransitionOverlay";
-import { getPasscodeAccessServer } from "@/lib/passcodeServer";
const tiktokSans = localFont({
src: "./fonts/TikTokSans.ttf",
@@ -34,18 +24,21 @@ const departureMono = localFont({
// 以 引入 —— 见下方 ;不进 next/font 管线(整包 5MB/字重)。
export const metadata: Metadata = {
- // Detail pages override the title via generateMetadata in
- // app/work/[slug]/layout.tsx (original: per-page title).
+ // 站点标题/描述可在 /virtheart 后台「配置」中修改(site_config 表)。
title: "北极新一©2026",
description: "设计与工程 / 数字产品与 AI 应用 © 2026",
};
-export default async function RootLayout({
+/**
+ * 根布局 — 仅承载 html/body/字体/全局样式。
+ * 站点壳层(画布、Header、滚动)在 app/(site)/layout.tsx;
+ * 后台 /virtheart 使用独立布局,不加载站点壳层。
+ */
+export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
- const initialAccess = await getPasscodeAccessServer();
return (
-
-
-
- {/* Original stacking (1:1): the WebGL canvas host is a plain `fixed`
- z-auto element first in the body; the grid overlay (z-20) comes
- AFTER it in DOM order so it paints above the canvas, exactly like
- the original's main > canvas + z-20 grid sibling. */}
-
-
-
-
- {children}
-
-
-
-
-
-
+ {children}
);
}
diff --git a/app/virtheart/(protected)/AdminShell.tsx b/app/virtheart/(protected)/AdminShell.tsx
new file mode 100644
index 0000000..3eb90b5
--- /dev/null
+++ b/app/virtheart/(protected)/AdminShell.tsx
@@ -0,0 +1,111 @@
+"use client";
+
+/**
+ * AdminShell — 后台框架:顶栏(品牌 + 导航 + 退出)+ 内容区。
+ * 设计与主站一致:点阵底、mono 标签、无圆角卡片堆砌。
+ */
+import Link from "next/link";
+import { usePathname, useRouter } from "next/navigation";
+import { useCallback } from "react";
+
+const NAV = [
+ { href: "/virtheart/dashboard", label: "概览" },
+ { href: "/virtheart/works", label: "作品" },
+ { href: "/virtheart/services", label: "服务" },
+ { href: "/virtheart/inquiries", label: "留言箱" },
+ { href: "/virtheart/settings", label: "配置" },
+];
+
+export default function AdminShell({
+ csrf,
+ children,
+}: {
+ csrf: string;
+ children: React.ReactNode;
+}) {
+ const pathname = usePathname();
+ const router = useRouter();
+
+ const logout = useCallback(async () => {
+ await fetch("/api/admin/logout", { method: "POST" });
+ router.replace("/virtheart/login");
+ }, [router]);
+
+ return (
+
+
+
+ );
+}
+
+import { createContext, useContext } from "react";
+
+const AdminCsrfContext = createContext("");
+
+/** 后台 mutation 统一带上 CSRF 头。 */
+export function useAdminFetch() {
+ const csrf = useContext(AdminCsrfContext);
+ return useCallback(
+ (input: string, init?: RequestInit) => {
+ const headers = new Headers(init?.headers);
+ headers.set(CSRF_HEADER_NAME, csrf);
+ return fetch(input, { ...init, headers });
+ },
+ [csrf]
+ );
+}
+
+export const CSRF_HEADER_NAME = "x-vh-csrf";
diff --git a/app/virtheart/(protected)/dashboard/page.tsx b/app/virtheart/(protected)/dashboard/page.tsx
new file mode 100644
index 0000000..3a4819c
--- /dev/null
+++ b/app/virtheart/(protected)/dashboard/page.tsx
@@ -0,0 +1,75 @@
+/** /virtheart/dashboard — 概览:统计 + 最近留言。 */
+import Link from "next/link";
+import { listInquiries, listServices, listWorks } from "@/lib/siteConfig";
+
+export const dynamic = "force-dynamic";
+
+function StatCard({ label, value, href }: { label: string; value: number | string; href: string }) {
+ return (
+
+
+ {label}
+
+ {value}
+
+ );
+}
+
+export default function DashboardPage() {
+ const works = listWorks(false);
+ const services = listServices(false);
+ const inquiries = listInquiries(200);
+ const newCount = inquiries.filter((i) => i.status === "new").length;
+ const latest = inquiries.slice(0, 5);
+
+ return (
+
+
+
+
+
+ w.published).length} href="/virtheart/works" />
+
+
+
+
+
+
+
最近留言
+
+ 全部 →
+
+
+ {latest.length === 0 ? (
+
+ 暂无留言——有人通过服务页联系你时会出现在这里。
+
+ ) : (
+
+ {latest.map((i) => (
+ -
+ #{i.id}
+ {i.name}
+ {i.service_title || "未选择服务"}
+ {i.status === "new" && (
+ NEW
+ )}
+
+ {i.created_at}
+
+
+ ))}
+
+ )}
+
+
+ );
+}
diff --git a/app/virtheart/(protected)/inquiries/page.tsx b/app/virtheart/(protected)/inquiries/page.tsx
new file mode 100644
index 0000000..018408e
--- /dev/null
+++ b/app/virtheart/(protected)/inquiries/page.tsx
@@ -0,0 +1,138 @@
+"use client";
+
+/** /virtheart/inquiries — 留言箱:查看 / 标记状态 / 删除。 */
+import { useCallback, useEffect, useState } from "react";
+import { useAdminFetch } from "../AdminShell";
+import type { InquiryRow } from "@/lib/siteConfig";
+
+const STATUS_LABELS: Record = {
+ new: "新",
+ read: "已读",
+ replied: "已回复",
+ archived: "归档",
+};
+
+const NEXT_STATUS: Record = {
+ new: "read",
+ read: "replied",
+ replied: "archived",
+ archived: "new",
+};
+
+export default function InquiriesAdminPage() {
+ const adminFetch = useAdminFetch();
+ const [items, setItems] = useState([]);
+ const [loading, setLoading] = useState(true);
+
+ // 数据加载(async 内 setState,避免 effect 同步路径触发级联渲染)。
+ useEffect(() => {
+ let cancelled = false;
+ void (async () => {
+ const res = await adminFetch("/api/admin/inquiries");
+ const data = (await res.json()) as { inquiries?: InquiryRow[] };
+ if (cancelled) return;
+ setItems(data.inquiries ?? []);
+ setLoading(false);
+ })();
+ return () => {
+ cancelled = true;
+ };
+ }, [adminFetch]);
+
+ // mutation 后刷新列表(不回置 loading 骨架)。
+ const load = useCallback(async () => {
+ const res = await adminFetch("/api/admin/inquiries");
+ const data = (await res.json()) as { inquiries?: InquiryRow[] };
+ setItems(data.inquiries ?? []);
+ }, [adminFetch]);
+
+ const setStatus = useCallback(
+ async (id: number, status: InquiryRow["status"]) => {
+ await adminFetch("/api/admin/inquiries", {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ id, status }),
+ });
+ void load();
+ },
+ [adminFetch, load]
+ );
+
+ const remove = useCallback(
+ async (id: number) => {
+ if (!window.confirm(`确定删除留言 #${id}?`)) return;
+ await adminFetch(`/api/admin/inquiries?id=${id}`, { method: "DELETE" });
+ void load();
+ },
+ [adminFetch, load]
+ );
+
+ return (
+
+
+
留言箱
+
+ 服务页提交的咨询都会记录在这里,并同步邮件通知到联系邮箱
+
+
+
+ {loading ? (
+
加载中…
+ ) : items.length === 0 ? (
+
+ 暂无留言。
+
+ ) : (
+
+ {items.map((i) => (
+ -
+
+
#{i.id}
+
{i.name}
+
+ {i.contact}
+
+
+ {i.service_title || "未选择服务"}
+
+ {i.status === "new" && (
+
+ NEW
+
+ )}
+
+ {i.created_at}
+
+
+
+ {i.message}
+
+
+
+
+
+ {i.email_sent ? "邮件已通知" : i.email_error ? `邮件失败:${i.email_error}` : ""}
+
+
+
+ ))}
+
+ )}
+
+ );
+}
diff --git a/app/virtheart/(protected)/layout.tsx b/app/virtheart/(protected)/layout.tsx
new file mode 100644
index 0000000..8e19a74
--- /dev/null
+++ b/app/virtheart/(protected)/layout.tsx
@@ -0,0 +1,25 @@
+import { redirect } from "next/navigation";
+import { getSession, isAdmin } from "@/lib/auth";
+import type { Metadata } from "next";
+import AdminShell from "./AdminShell";
+
+export const metadata: Metadata = {
+ title: "控制台",
+ robots: { index: false, follow: false },
+};
+
+export const dynamic = "force-dynamic";
+
+/**
+ * /virtheart/(protected) 布局 — 服务端鉴权:未登录一律跳 /virtheart/login。
+ * 会话中的 csrf_token 传给 AdminShell,mutation 请求头统一回传。
+ */
+export default async function ProtectedLayout({
+ children,
+}: Readonly<{ children: React.ReactNode }>) {
+ if (!(await isAdmin())) {
+ redirect("/virtheart/login");
+ }
+ const session = await getSession();
+ return {children};
+}
diff --git a/app/virtheart/(protected)/services/page.tsx b/app/virtheart/(protected)/services/page.tsx
new file mode 100644
index 0000000..ca4ff4d
--- /dev/null
+++ b/app/virtheart/(protected)/services/page.tsx
@@ -0,0 +1,233 @@
+"use client";
+
+/** /virtheart/services — 服务项目管理(增删改 + 启用开关)。 */
+import { useCallback, useEffect, useState } from "react";
+import { useAdminFetch } from "../AdminShell";
+import type { ServiceRow } from "@/lib/siteConfig";
+
+const inputCls =
+ "w-full border border-line bg-b1 px-3 py-2 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1";
+
+type Draft = {
+ id?: number;
+ title: string;
+ description: string;
+ price_note: string;
+ sort_order: number;
+ enabled: number;
+};
+
+const EMPTY: Draft = { title: "", description: "", price_note: "", sort_order: 0, enabled: 1 };
+
+export default function ServicesAdminPage() {
+ const adminFetch = useAdminFetch();
+ const [services, setServices] = useState([]);
+ const [draft, setDraft] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ // 数据加载(async 内 setState,避免 effect 同步路径触发级联渲染)。
+ useEffect(() => {
+ let cancelled = false;
+ void (async () => {
+ const res = await adminFetch("/api/admin/services");
+ const data = (await res.json()) as { services?: ServiceRow[] };
+ if (cancelled) return;
+ setServices(data.services ?? []);
+ setLoading(false);
+ })();
+ return () => {
+ cancelled = true;
+ };
+ }, [adminFetch]);
+
+ // mutation 后刷新列表(不回置 loading 骨架)。
+ const load = useCallback(async () => {
+ const res = await adminFetch("/api/admin/services");
+ const data = (await res.json()) as { services?: ServiceRow[] };
+ setServices(data.services ?? []);
+ }, [adminFetch]);
+
+ const save = useCallback(async () => {
+ if (!draft) return;
+ setError(null);
+ const res = await adminFetch("/api/admin/services", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify(draft),
+ });
+ const data = (await res.json()) as { error?: string };
+ if (!res.ok) {
+ setError(data.error ?? "保存失败");
+ return;
+ }
+ setDraft(null);
+ void load();
+ }, [draft, adminFetch, load]);
+
+ const remove = useCallback(
+ async (id: number) => {
+ if (!window.confirm(`确定删除服务 #${id}?`)) return;
+ await adminFetch(`/api/admin/services/${id}`, { method: "DELETE" });
+ void load();
+ },
+ [adminFetch, load]
+ );
+
+ return (
+
+
+
+
服务
+
+ /services 页面展示已启用的服务条目
+
+
+
+
+
+ {error && (
+
{error}
+ )}
+
+ {loading ? (
+
加载中…
+ ) : services.length === 0 ? (
+
+ 暂无服务——服务页将只显示联系引导。
+
+ ) : (
+
+ {services.map((s) => (
+ -
+
+
+ {s.title}
+ {!s.enabled && (
+
+ 已停用
+
+ )}
+
+
+ {s.description}
+
+
+
+
+
+
+
+ ))}
+
+ )}
+
+ {draft && (
+
+
+
+ {draft.id ? "编辑服务" : "新增服务"}
+
+
+
+
+ setDraft({ ...draft, title: e.target.value })}
+ autoFocus
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )}
+
+ );
+}
diff --git a/app/virtheart/(protected)/settings/page.tsx b/app/virtheart/(protected)/settings/page.tsx
new file mode 100644
index 0000000..18397fd
--- /dev/null
+++ b/app/virtheart/(protected)/settings/page.tsx
@@ -0,0 +1,239 @@
+"use client";
+
+/**
+ * /virtheart/settings — 站点配置编辑(分组字段 + 修改密码)。
+ * 改动保存到 site_config 表,前台页面即时读取生效。
+ */
+import { useCallback, useEffect, useState } from "react";
+import { useAdminFetch } from "../AdminShell";
+import type { SiteConfig } from "@/lib/siteConfig";
+
+const inputCls =
+ "w-full border border-line bg-b1 px-3 py-2 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1";
+const labelCls = "mb-1 block font-mono-2 text-xs text-l2";
+
+const FIELD_LABELS: Record = {
+ site_title: "浏览器标题",
+ site_description: "站点描述(SEO)",
+ brand_name: "Header 品牌名",
+ copyright_name: "页脚版权名",
+ hero_line1: "首屏标签 · 第一段",
+ hero_line2: "首屏标签 · 第二段",
+ hero_tagline: "首屏标语",
+ hero_big_1: "首屏大字 · 行一",
+ hero_big_2: "首屏大字 · 行二",
+ hero_big_3: "首屏大字 · 行三",
+ intro_prefix: "自我介绍 · 前半句",
+ intro_suffix: "自我介绍 · 后半句",
+ intro_brand: "自我介绍 · 品牌位(口令解锁前显示 ■■■)",
+ about_p1: "关于 · 第一段",
+ about_p2: "关于 · 第二段(链接前)",
+ about_p2_link_label: "关于 · 链接文字",
+ about_p2_link_href: "关于 · 链接地址",
+ footer_headline: "页脚大字(用 | 分行)",
+ contact_email: "联系邮箱",
+ work_empty_headline: "作品区空状态 · 大字(用 | 分行)",
+ work_empty_note: "作品区空状态 · 说明",
+ work_empty_cta_prefix: "作品区空状态 · CTA 前缀",
+ work_empty_cta_suffix: "作品区空状态 · CTA 中缀",
+ work_empty_cta_action: "作品区空状态 · CTA 动作文字",
+ services_hero: "服务页大字(用 | 分行)",
+ services_submit_note: "服务页 · 提交说明",
+};
+
+const MULTILINE: (keyof SiteConfig)[] = [
+ "about_p1",
+ "about_p2",
+ "intro_prefix",
+ "intro_suffix",
+ "work_empty_note",
+ "services_submit_note",
+];
+
+const GROUP_TITLES: Record = {
+ basic: "基础",
+ hero: "首屏",
+ about: "关于",
+ footer: "页脚",
+ empty: "作品区空状态",
+ services: "服务页",
+};
+
+const GROUPS: { id: string; keys: (keyof SiteConfig)[] }[] = [
+ { id: "basic", keys: ["site_title", "site_description", "brand_name", "copyright_name"] },
+ {
+ id: "hero",
+ keys: [
+ "hero_line1",
+ "hero_line2",
+ "hero_tagline",
+ "hero_big_1",
+ "hero_big_2",
+ "hero_big_3",
+ "intro_prefix",
+ "intro_suffix",
+ "intro_brand",
+ ],
+ },
+ { id: "about", keys: ["about_p1", "about_p2", "about_p2_link_label", "about_p2_link_href"] },
+ { id: "footer", keys: ["footer_headline", "contact_email"] },
+ {
+ id: "empty",
+ keys: [
+ "work_empty_headline",
+ "work_empty_note",
+ "work_empty_cta_prefix",
+ "work_empty_cta_suffix",
+ "work_empty_cta_action",
+ ],
+ },
+ { id: "services", keys: ["services_hero", "services_submit_note"] },
+];
+
+export default function SettingsAdminPage() {
+ const adminFetch = useAdminFetch();
+ const [config, setConfig] = useState(null);
+ const [saving, setSaving] = useState(false);
+ const [saved, setSaved] = useState(false);
+ const [error, setError] = useState(null);
+
+ const [newPassword, setNewPassword] = useState("");
+ const [pwMsg, setPwMsg] = useState(null);
+
+ useEffect(() => {
+ void (async () => {
+ const res = await adminFetch("/api/admin/config");
+ const data = (await res.json()) as { config?: SiteConfig };
+ setConfig(data.config ?? null);
+ })();
+ }, [adminFetch]);
+
+ const save = useCallback(async () => {
+ if (!config) return;
+ setSaving(true);
+ setError(null);
+ setSaved(false);
+ const res = await adminFetch("/api/admin/config", {
+ method: "PUT",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify(config),
+ });
+ setSaving(false);
+ if (!res.ok) {
+ const data = (await res.json()) as { error?: string };
+ setError(data.error ?? "保存失败");
+ return;
+ }
+ setSaved(true);
+ window.setTimeout(() => setSaved(false), 2000);
+ }, [config, adminFetch]);
+
+ const changePassword = useCallback(async () => {
+ setPwMsg(null);
+ if (newPassword.length < 8) {
+ setPwMsg("密码至少 8 位");
+ return;
+ }
+ const res = await adminFetch("/api/admin/password", {
+ method: "PUT",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ password: newPassword }),
+ });
+ const data = (await res.json()) as { error?: string };
+ if (!res.ok) {
+ setPwMsg(data.error ?? "修改失败");
+ return;
+ }
+ setPwMsg("密码已更新,下次登录生效");
+ setNewPassword("");
+ }, [newPassword, adminFetch]);
+
+ if (!config) {
+ return 加载中…
;
+ }
+
+ return (
+
+
+
+
配置
+
+ 站点文案与信息,保存后前台即时生效
+
+
+
+ {saved && (
+ 已保存 ✓
+ )}
+
+
+
+
+ {error && (
+
{error}
+ )}
+
+ {GROUPS.map((group) => (
+
+
+ {GROUP_TITLES[group.id]}
+
+
+ {group.keys.map((key) => (
+
+
+ {MULTILINE.includes(key) ? (
+
+ ))}
+
+
+ ))}
+
+
+ 修改密码
+
+
+
+ setNewPassword(e.target.value)}
+ />
+
+
+ {pwMsg &&
{pwMsg}}
+
+
+
+ );
+}
diff --git a/app/virtheart/(protected)/works/page.tsx b/app/virtheart/(protected)/works/page.tsx
new file mode 100644
index 0000000..a87ea33
--- /dev/null
+++ b/app/virtheart/(protected)/works/page.tsx
@@ -0,0 +1,401 @@
+"use client";
+
+/**
+ * /virtheart/works — 作品管理:列表 + 新增/编辑。
+ * 单页内联编辑(终端风),字段与 lib/siteConfig 的 works 表对应。
+ */
+import { useCallback, useEffect, useState } from "react";
+import { useAdminFetch } from "../AdminShell";
+import type { WorkRow } from "@/lib/siteConfig";
+
+const GRID_PRESETS = [
+ { label: "大卡(8列居中)", value: "col-span-12 lg:col-span-8 lg:col-start-3" },
+ { label: "中卡(6列)", value: "col-span-12 lg:col-span-6 xl:col-span-4" },
+ { label: "宽左(5列)", value: "col-span-12 lg:col-start-1 lg:col-span-6 xl:col-span-5" },
+ { label: "宽右(5列)", value: "col-span-12 lg:col-span-6 xl:col-span-5 lg:col-start-7 xl:col-start-7" },
+ { label: "小卡(3列)", value: "col-span-6 lg:col-span-4 xl:col-span-3" },
+ { label: "小卡右(3列)", value: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-10 xl:col-span-3" },
+];
+
+const TYPE_OPTIONS = [
+ { label: "文章", value: "post" },
+ { label: "工具", value: "tools" },
+ { label: "活动", value: "event" },
+];
+
+type Draft = {
+ id?: number;
+ slug?: string;
+ name: string;
+ year: string;
+ type: string;
+ href: string;
+ image_url: string;
+ hover_image_url: string;
+ grid_class: string;
+ coding_project: number;
+ sort_order: number;
+ published: number;
+};
+
+const EMPTY_DRAFT: Draft = {
+ name: "",
+ year: new Date().getFullYear().toString(),
+ type: "post",
+ href: "",
+ image_url: "",
+ hover_image_url: "",
+ grid_class: GRID_PRESETS[1].value,
+ coding_project: 0,
+ sort_order: 0,
+ published: 1,
+};
+
+const inputCls =
+ "w-full border border-line bg-b1 px-3 py-2 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1";
+const labelCls = "mb-1 block font-mono-2 text-xs text-l2";
+
+export default function WorksAdminPage() {
+ const adminFetch = useAdminFetch();
+ const [works, setWorks] = useState([]);
+ const [draft, setDraft] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [saving, setSaving] = useState(false);
+ const [error, setError] = useState(null);
+ const [uploading, setUploading] = useState(false);
+
+ // 数据加载(async 内 setState,避免 effect 同步路径触发级联渲染)。
+ useEffect(() => {
+ let cancelled = false;
+ void (async () => {
+ const res = await adminFetch("/api/admin/works");
+ const data = (await res.json()) as { works?: WorkRow[] };
+ if (cancelled) return;
+ setWorks(data.works ?? []);
+ setLoading(false);
+ })();
+ return () => {
+ cancelled = true;
+ };
+ }, [adminFetch]);
+
+ // mutation 后刷新列表(不回置 loading 骨架)。
+ const load = useCallback(async () => {
+ const res = await adminFetch("/api/admin/works");
+ const data = (await res.json()) as { works?: WorkRow[] };
+ setWorks(data.works ?? []);
+ }, [adminFetch]);
+
+ const save = useCallback(async () => {
+ if (!draft) return;
+ setSaving(true);
+ setError(null);
+ const res = await adminFetch("/api/admin/works", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify(draft),
+ });
+ const data = (await res.json()) as { error?: string };
+ setSaving(false);
+ if (!res.ok) {
+ setError(data.error ?? "保存失败");
+ return;
+ }
+ setDraft(null);
+ void load();
+ }, [draft, adminFetch, load]);
+
+ const remove = useCallback(
+ async (id: number) => {
+ if (!window.confirm(`确定删除作品 #${id}?`)) return;
+ await adminFetch(`/api/admin/works/${id}`, { method: "DELETE" });
+ void load();
+ },
+ [adminFetch, load]
+ );
+
+ const upload = useCallback(
+ async (file: File, field: "image_url" | "hover_image_url") => {
+ setUploading(true);
+ setError(null);
+ const form = new FormData();
+ form.append("file", file);
+ const res = await adminFetch("/api/admin/upload", {
+ method: "POST",
+ body: form,
+ });
+ const data = (await res.json()) as { url?: string; error?: string };
+ setUploading(false);
+ if (!res.ok || !data.url) {
+ setError(data.error ?? "上传失败");
+ return;
+ }
+ setDraft((d) => (d ? { ...d, [field]: data.url as string } : d));
+ },
+ [adminFetch]
+ );
+
+ return (
+
+
+
+
作品
+
+ 首页「精选作品」网格按排序展示已发布条目
+
+
+
+
+
+ {error && (
+
{error}
+ )}
+
+ {loading ? (
+
加载中…
+ ) : works.length === 0 && !draft ? (
+
+
+ 暂无作品——首页作品区当前展示「制作中」占位。
+
+
+ 添加第一个作品后,占位自动消失。
+
+
+ ) : (
+ works.length > 0 && (
+
+ {works.map((w) => (
+ -
+ {w.image_url && (
+ // eslint-disable-next-line @next/next/no-img-element -- 后台缩略图
+
+ )}
+
+
+ {w.name}
+ {!w.published && (
+
+ 未发布
+
+ )}
+
+
+ {w.year} · {w.slug} · 排序 {w.sort_order}
+
+
+
+
+
+
+
+ ))}
+
+ )
+ )}
+
+ {draft && (
+
+
+
+ {draft.id ? `编辑作品 #${draft.id}` : "新增作品"}
+
+
+
+
+
+
+
+
+
+ )}
+
+ );
+}
diff --git a/app/virtheart/layout.tsx b/app/virtheart/layout.tsx
new file mode 100644
index 0000000..06e38c8
--- /dev/null
+++ b/app/virtheart/layout.tsx
@@ -0,0 +1,12 @@
+import type { Metadata } from "next";
+
+export const metadata: Metadata = {
+ title: "登录",
+ robots: { index: false, follow: false },
+};
+
+export default function VirtheartLayout({
+ children,
+}: Readonly<{ children: React.ReactNode }>) {
+ return children;
+}
diff --git a/app/virtheart/login/page.tsx b/app/virtheart/login/page.tsx
new file mode 100644
index 0000000..eca67ec
--- /dev/null
+++ b/app/virtheart/login/page.tsx
@@ -0,0 +1,109 @@
+"use client";
+
+/**
+ * /virtheart/login — 后台登录页。
+ * 设计语言与主站对齐:暗底、等宽字体、点阵网格、scramble 式聚焦;
+ * 不用传统后台模板。登录成功 → /virtheart/dashboard。
+ */
+import { useCallback, useState } from "react";
+import { useRouter } from "next/navigation";
+
+export default function VirtheartLoginPage() {
+ const router = useRouter();
+ const [username, setUsername] = useState("");
+ const [password, setPassword] = useState("");
+ const [error, setError] = useState(null);
+ const [busy, setBusy] = useState(false);
+
+ const submit = useCallback(
+ async (e: React.FormEvent) => {
+ e.preventDefault();
+ if (busy) return;
+ setBusy(true);
+ setError(null);
+ try {
+ const res = await fetch("/api/admin/login", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ username, password }),
+ });
+ const data = (await res.json()) as { error?: string };
+ if (!res.ok) {
+ setError(data.error ?? "登录失败");
+ return;
+ }
+ router.replace("/virtheart/dashboard");
+ } catch {
+ setError("网络错误,请重试");
+ } finally {
+ setBusy(false);
+ }
+ },
+ [busy, username, password, router]
+ );
+
+ return (
+
+
+
+ );
+}
diff --git a/app/virtheart/page.tsx b/app/virtheart/page.tsx
new file mode 100644
index 0000000..59ab77f
--- /dev/null
+++ b/app/virtheart/page.tsx
@@ -0,0 +1,16 @@
+import { redirect } from "next/navigation";
+import { isAdmin } from "@/lib/auth";
+
+/**
+ * /virtheart — 后台暗门入口。
+ * 未登录 → /virtheart/login;已登录 → /virtheart/dashboard。
+ * 该路径不进站点地图、不进导航,仅手动访问。
+ */
+export const dynamic = "force-dynamic";
+
+export default async function VirtheartEntry() {
+ if (await isAdmin()) {
+ redirect("/virtheart/dashboard");
+ }
+ redirect("/virtheart/login");
+}
diff --git a/components/dom/FooterSection.tsx b/components/dom/FooterSection.tsx
index 6521ca6..bf760cd 100644
--- a/components/dom/FooterSection.tsx
+++ b/components/dom/FooterSection.tsx
@@ -18,7 +18,7 @@ import { CONTACT_EMAIL } from "@/lib/socials";
* - 微信:无链接,点击弹出二维码浮层(移动端无 hover 也能查看)。
*/
-// CONTACT_EMAIL 来自 @/lib/socials(与空作品区 CTA 共享)。
+// CONTACT_EMAIL 作为默认值 fallback;页面级会传入 site_config 的 contact_email。
const dottedLink =
"block before:absolute relative before:inset-0 p-2 lg:hover:before:border-l1 before:border-2 before:border-transparent active:before:border-l1 before:border-dotted uppercase before:content-[''] before:transition-colors before:duration-200 cursor-pointer pointer-events-auto before:pointer-events-none";
@@ -85,7 +85,11 @@ function QrPreview({ social }: { social: Social }) {
);
}
-export default function FooterSection() {
+export default function FooterSection({
+ contactEmail = CONTACT_EMAIL,
+}: {
+ contactEmail?: string;
+}) {
const [activeQr, setActiveQr] = useState(null);
const closeQr = useCallback(() => setActiveQr(null), []);
@@ -138,9 +142,9 @@ export default function FooterSection() {
-
+
diff --git a/components/dom/Header.tsx b/components/dom/Header.tsx
index 36bbfd4..7fb24b3 100644
--- a/components/dom/Header.tsx
+++ b/components/dom/Header.tsx
@@ -5,6 +5,7 @@ import ScrambleReveal from "@/components/dom/ScrambleReveal";
import { useShellMedia, type ThemeSetting } from "@/lib/shellMedia";
import { useBgm } from "@/lib/useBgm";
import { scrollEnv } from "@/lib/scrollEnv";
+import { useRouteTransitionController } from "@/lib/routeTransition";
import {
useArrowFullscreenPastThreshold,
ARROW_FULLSCREEN_DOM_COLOR_TRANSITION,
@@ -49,9 +50,16 @@ function useBrowserName(): string {
return name;
}
-export default function Header() {
+export default function Header({
+ brandName = "北极新一",
+ copyrightName = "北极新一",
+}: {
+ brandName?: string;
+ copyrightName?: string;
+}) {
const { theme, setTheme, soundEnabled, setSoundEnabled } = useShellMedia();
useBgm(soundEnabled);
+ const { startNavigation } = useRouteTransitionController();
// Arrow-fullscreen state: past the 0.5 reveal threshold the whole header
// (and the hyper-space section) turn white over the black stripe base
// (original X = useArrowFullscreenPastThreshold()).
@@ -199,7 +207,7 @@ export default function Header() {
style={{ fontVariationSettings: '"wght" 700, "wdth" 120' }}
href="/"
>
-
+
+