feat: Next.js 后端 + SQLite + 暗门后台 /virtheart + 服务咨询页

后端(node:sqlite 零原生依赖,data/site.db,WAL + busy_timeout 抗并发):
- works / service_items / site_config / inquiries / admin_users / admin_sessions / captcha_challenges
- API:admin 登录登出/密码、作品与服务 CRUD、图片上传、留言箱、
  验证码 challenge/verify、咨询提交(一次性滑块令牌防重放)

后台 /virtheart(仅手动访问,未登录一律 307 → /virtheart/login):
- 服务端布局鉴权 + DB 会话(httpOnly cookie 7 天)+ CSRF 头校验
- 概览 / 作品(上传、网格预设、发布开关)/ 服务 / 留言箱 / 配置(全站文案)
- 设计与主站同语言:暗底点阵、mono、lime 选中,非传统后台模板

公开站:
- 路由组 (site) 隔离站点壳层;首页/服务页文案全部 DB 驱动即时生效
- /services 服务菜单 + 留言表单 + 全屏居中滑块拼图验证码(对齐缺口)
- 提交入 inquiries 并 SMTP(飞书 notify@)邮件通知 chenchun@virtheart.com
- Header 新增「服务」菜单;旧作品清理,空状态自动接管
- 根布局仅承载字体/全局样式,后台无站点壳层

验证:登录/CSRF/发布隔离/滑块容错/令牌单次消费/SMTP 真发全部通过;
lint 与基线一致(119 errors 均为存量)。
This commit is contained in:
2026-09-02 18:34:18 +08:00
parent 1a12c70462
commit d666cedfc6
46 changed files with 3527 additions and 211 deletions
+299
View File
@@ -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<ServiceOption | null>(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<string | null>(null);
const [doneId, setDoneId] = useState<number | null>(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 (
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px]">
<div className="pt-[14vh] flex flex-col gap-4">
<h1
className="font-bold text-[7.2svw] lg:text-[4.6svw] leading-none text-l1"
style={{ fontVariationSettings: '"wdth" 120' }}
>
<ScrambleReveal text="已收到" startDelayMs={200} scrambleColors={false} />
</h1>
<p className="font-mono-2 text-sm lg:text-base text-l2">
<ScrambleReveal
text={`留言编号 #${doneId} —— 我会尽快通过你留下的联系方式回复。`}
startDelayMs={400}
letterDelayMs={10}
/>
</p>
<div className="mt-4 flex gap-6 font-mono text-sm">
<button
type="button"
onClick={() => startNavigation("/")}
className={`${dotted} p-2 uppercase cursor-pointer text-l1`}
>
<ScrambleReveal text="← 返回首页" startDelayMs={300} scrambleColors={false} />
</button>
<button
type="button"
onClick={() => {
setDoneId(null);
setName("");
setContact("");
setMessage("");
setSelected(null);
}}
className={`${dotted} p-2 uppercase cursor-pointer text-l2`}
>
<ScrambleReveal text="再提交一条" startDelayMs={300} scrambleColors={false} />
</button>
</div>
</div>
</article>
);
}
return (
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px]">
<header className="pt-[10vh]">
<h1
className="font-bold text-[7.2svw] lg:text-[4.6svw] leading-none text-l1"
style={{ fontVariationSettings: '"wdth" 120' }}
>
{headlineLines.map((line, i) => (
<span key={i} className={i > 0 ? "block text-right lg:text-right" : "block"}>
<ScrambleReveal
text={line}
startDelayMs={200 + i * 220}
reverse={i > 0}
scrambleColors={false}
/>
</span>
))}
</h1>
<div className="mt-2 border-line border-b" />
<p className="pt-3 font-mono-2 text-xs text-l3">
<ScrambleReveal
text={`服务咨询 · 邮件直达 ${CONTACT_EMAIL}`}
startDelayMs={500}
letterDelayMs={10}
/>
</p>
</header>
{/* 服务菜单 */}
<section className="mt-12" aria-label="服务列表">
{services.length === 0 ? (
<p className="font-mono-2 text-sm text-l2 border border-dashed border-line p-8 text-center">
服务清单整理中——有需要可直接写邮件给我。
</p>
) : (
<ul className="flex flex-col divide-y divide-line border-y border-line">
{services.map((s, i) => {
const active = selected?.slug === s.slug;
return (
<li key={s.slug}>
<button
type="button"
onClick={() => setSelected(active ? null : s)}
aria-pressed={active}
className={`${dotted} w-full text-left cursor-pointer px-2 py-5 flex items-baseline gap-4 transition-colors ${
active ? "bg-[rgba(var(--label-d),0.04)]" : ""
}`}
>
<span className="font-mono-2 text-xs text-l3 tabular-nums shrink-0">
NO.{String(i + 1).padStart(2, "0")}
</span>
<span
className={`font-semibold text-lg lg:text-xl ${
active ? "text-l1" : "text-l2"
}`}
style={{ fontFamily: 'var(--font-tiktok), "MiSans", sans-serif' }}
>
{s.title}
</span>
{s.priceNote && (
<span className="ml-auto font-mono-2 text-xs text-l3 shrink-0">
{s.priceNote}
</span>
)}
<span
aria-hidden="true"
className={`font-mono text-sm shrink-0 transition-transform ${
active ? "rotate-45 text-l1" : "text-l3"
}`}
>
+
</span>
</button>
{active && s.description && (
<p className="px-2 pb-5 pl-12 font-mono-2 text-sm leading-relaxed text-l2 whitespace-pre-wrap">
{s.description}
</p>
)}
</li>
);
})}
</ul>
)}
</section>
{/* 留言表单 */}
<section className="mt-12 flex flex-col gap-5" aria-label="咨询表单">
<p className="font-mono-2 text-xs text-l3 uppercase tracking-widest">
{selected ? `咨询:${selected.title}` : "留言"}
</p>
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2">
<div>
<label className={labelCls} htmlFor="svc-name">
怎么称呼你 *
</label>
<input
id="svc-name"
className={inputCls}
value={name}
onChange={(e) => setName(e.target.value)}
maxLength={40}
placeholder="姓名 / 昵称"
/>
</div>
<div>
<label className={labelCls} htmlFor="svc-contact">
联系方式 *
</label>
<input
id="svc-contact"
className={inputCls}
value={contact}
onChange={(e) => setContact(e.target.value)}
maxLength={80}
placeholder="邮箱 / 微信 / 手机号"
/>
</div>
</div>
<div>
<label className={labelCls} htmlFor="svc-message">
具体需求 *
</label>
<textarea
id="svc-message"
className={`${inputCls} min-h-32`}
value={message}
onChange={(e) => setMessage(e.target.value)}
maxLength={2000}
placeholder={
selected
? `关于「${selected.title}」,简单描述一下你的场景、周期和预算范围…`
: "简单描述一下你的场景、周期和预算范围…"
}
/>
<p className="mt-1.5 font-mono-2 text-xs text-l3">{submitNote}</p>
</div>
{error && (
<p className="border-l-2 border-selection pl-2 text-sm text-l1" role="alert">
{error}
</p>
)}
<button
type="button"
onClick={startSubmit}
disabled={!canSubmit || submitting}
className="w-full border border-l1 bg-l1 py-3.5 font-mono text-sm uppercase tracking-widest text-b1 transition-opacity hover:opacity-85 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer"
>
{submitting ? "提交中…" : "提交(需完成滑块验证)"}
</button>
</section>
<SliderCaptcha
open={captchaOpen}
onClose={() => !submitting && setCaptchaOpen(false)}
onVerified={onCaptchaVerified}
/>
</article>
);
}
+28
View File
@@ -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 (
<ServicesClient
headline={config.services_hero}
submitNote={config.services_submit_note}
services={services}
/>
);
}