Compare commits
10
Commits
7e30631c68
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bbd6947da | ||
|
|
2457d5ec69 | ||
|
|
1abadd04b8 | ||
|
|
3f05bd16e1 | ||
|
|
24a2311e20 | ||
|
|
77e1208c31 | ||
|
|
6c8077477a | ||
|
|
f6ce630587 | ||
|
|
73d2465ef2 | ||
|
|
b5fe5e13ab |
@@ -1,7 +1,9 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getBlogBySlug } from "@/services/blog.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { BlogPageDetail } from "@/types/wagtail";
|
||||
|
||||
interface BlogDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
@@ -17,7 +19,11 @@ export async function generateMetadata({
|
||||
|
||||
export default async function BlogDetailPage({ params }: BlogDetailPageProps) {
|
||||
const { slug } = await params;
|
||||
const post = await getBlogBySlug(slug).catch(() => null);
|
||||
const post = await getPreviewOrFallback<BlogPageDetail>(
|
||||
"blog.blogpage",
|
||||
"body,intro,published_at",
|
||||
() => getBlogBySlug(slug).catch(() => null),
|
||||
);
|
||||
|
||||
if (!post) {
|
||||
notFound();
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getCaseStudyBySlug } from "@/services/case.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { CaseStudyPageDetail } from "@/types/wagtail";
|
||||
|
||||
interface CaseStudyDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: CaseStudyDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const item = await getCaseStudyBySlug(slug).catch(() => null);
|
||||
return { title: item?.title ?? "案例未找到" };
|
||||
}
|
||||
|
||||
export default async function CaseStudyDetailPage({
|
||||
params,
|
||||
}: CaseStudyDetailPageProps) {
|
||||
const { slug } = await params;
|
||||
const item = await getPreviewOrFallback<CaseStudyPageDetail>(
|
||||
"cases.casestudypage",
|
||||
"body,client_name,industry,published_at,summary",
|
||||
() => getCaseStudyBySlug(slug).catch(() => null),
|
||||
);
|
||||
|
||||
if (!item) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<h1 className="mb-2 text-4xl font-bold text-slate-900">{item.title}</h1>
|
||||
<p className="mb-12 text-sm text-slate-500">
|
||||
{item.client_name}
|
||||
{item.industry ? ` · ${item.industry}` : ""}
|
||||
</p>
|
||||
<BlockRenderer blocks={item.body} />
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getCaseStudyList } from "@/services/case.service";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "客户案例",
|
||||
};
|
||||
|
||||
export default async function CaseStudyListPage() {
|
||||
const caseStudies = await getCaseStudyList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">客户案例</h1>
|
||||
<ul className="space-y-6">
|
||||
{caseStudies.map((item) => (
|
||||
<li key={item.id} className="border-b border-slate-100 pb-6">
|
||||
<Link
|
||||
href={`/cases/${item.meta.slug}`}
|
||||
className="text-2xl font-semibold text-slate-900 hover:text-primary"
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
<p className="mt-1 text-sm text-slate-500">
|
||||
{item.client_name}
|
||||
{item.industry ? ` · ${item.industry}` : ""}
|
||||
</p>
|
||||
{item.summary && (
|
||||
<p className="mt-2 text-slate-600">{item.summary}</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
{caseStudies.length === 0 && (
|
||||
<p className="text-slate-500">暂无案例,或后端服务未连接。</p>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+17
-1
@@ -1,7 +1,9 @@
|
||||
import type { Metadata } from "next";
|
||||
import { draftMode } from "next/headers";
|
||||
import "./globals.css";
|
||||
import Header from "@/components/layout/Header";
|
||||
import Footer from "@/components/layout/Footer";
|
||||
import CookieConsent from "@/components/layout/CookieConsent";
|
||||
import ReactQueryProvider from "@/providers/react-query-provider";
|
||||
|
||||
// 面向中国大陆用户,避免依赖 next/font/google(构建期需访问 Google 服务器)。
|
||||
@@ -15,14 +17,28 @@ export const metadata: Metadata = {
|
||||
description: "企业级 Headless CMS 驱动的现代化官网",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: LayoutProps<"/">) {
|
||||
export default async function RootLayout({ children }: LayoutProps<"/">) {
|
||||
const { isEnabled: isPreview } = await draftMode();
|
||||
|
||||
return (
|
||||
<html lang="zh-hans" className="h-full antialiased">
|
||||
<body className="min-h-full flex flex-col font-sans">
|
||||
<ReactQueryProvider>
|
||||
{isPreview && (
|
||||
<div className="flex items-center justify-center gap-4 bg-amber-400 px-4 py-2 text-sm font-medium text-amber-950">
|
||||
<span>预览模式:当前显示的是未发布的草稿内容</span>
|
||||
<a
|
||||
href="/preview/disable"
|
||||
className="underline underline-offset-2"
|
||||
>
|
||||
退出预览
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
<Header />
|
||||
<main className="flex-1">{children}</main>
|
||||
<Footer />
|
||||
<CookieConsent />
|
||||
</ReactQueryProvider>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+7
-1
@@ -1,13 +1,19 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getHomePage } from "@/services/page.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { HomePageDetail } from "@/types/wagtail";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "首页",
|
||||
};
|
||||
|
||||
export default async function Home() {
|
||||
const homePage = await getHomePage().catch(() => null);
|
||||
const homePage = await getPreviewOrFallback<HomePageDetail>(
|
||||
"home.homepage",
|
||||
"body,seo_title_override,seo_description_override",
|
||||
() => getHomePage().catch(() => null),
|
||||
);
|
||||
|
||||
if (!homePage) {
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { draftMode, cookies } from "next/headers";
|
||||
import {
|
||||
PREVIEW_CONTENT_TYPE_COOKIE,
|
||||
PREVIEW_TOKEN_COOKIE,
|
||||
} from "@/services/preview.service";
|
||||
|
||||
/** 退出预览模式:关闭 Draft Mode 并清除预览专用 cookie,重定向回首页。 */
|
||||
export async function GET(request: NextRequest) {
|
||||
const draft = await draftMode();
|
||||
draft.disable();
|
||||
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.delete(PREVIEW_CONTENT_TYPE_COOKIE);
|
||||
cookieStore.delete(PREVIEW_TOKEN_COOKIE);
|
||||
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { draftMode, cookies } from "next/headers";
|
||||
import {
|
||||
fetchPreviewPage,
|
||||
resolvePreviewPath,
|
||||
PREVIEW_CONTENT_TYPE_COOKIE,
|
||||
PREVIEW_TOKEN_COOKIE,
|
||||
} from "@/services/preview.service";
|
||||
import type { WagtailPageSummary } from "@/types/wagtail";
|
||||
|
||||
/**
|
||||
* Wagtail 编辑器点击"预览"后会重定向到此路由(详见 wagtailcms/settings/base.py
|
||||
* 中 WAGTAIL_HEADLESS_PREVIEW.CLIENT_URLS)。校验 token 有效后开启 Next.js
|
||||
* Draft Mode 并重定向到对应内容的前端路由,由页面组件通过 getPreviewOrFallback
|
||||
* 拉取草稿数据渲染。
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
const contentType = request.nextUrl.searchParams.get("content_type");
|
||||
const token = request.nextUrl.searchParams.get("token");
|
||||
|
||||
if (!contentType || !token) {
|
||||
return NextResponse.json(
|
||||
{ error: "缺少 content_type 或 token 参数" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
// 先校验 token 是否有效并取回 slug,未开启 Draft Mode,避免暴露无效预览。
|
||||
const page = await fetchPreviewPage<WagtailPageSummary>(contentType, token);
|
||||
const path = page ? resolvePreviewPath(contentType, page) : null;
|
||||
|
||||
if (!page || !path) {
|
||||
return NextResponse.json(
|
||||
{ error: "预览链接无效或已过期" },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
|
||||
const draft = await draftMode();
|
||||
draft.enable();
|
||||
|
||||
const isProduction = process.env.NODE_ENV === "production";
|
||||
const cookieStore = await cookies();
|
||||
const cookieOptions = {
|
||||
httpOnly: true,
|
||||
sameSite: "lax" as const,
|
||||
secure: isProduction,
|
||||
path: "/",
|
||||
};
|
||||
cookieStore.set(PREVIEW_CONTENT_TYPE_COOKIE, contentType, cookieOptions);
|
||||
cookieStore.set(PREVIEW_TOKEN_COOKIE, token, cookieOptions);
|
||||
|
||||
return NextResponse.redirect(new URL(path, request.url));
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
||||
|
||||
export default function DeleteConfirmForm() {
|
||||
const searchParams = useSearchParams();
|
||||
const token = searchParams.get("token");
|
||||
const [status, setStatus] = useState<
|
||||
"idle" | "submitting" | "done" | "error"
|
||||
>("idle");
|
||||
const [message, setMessage] = useState("");
|
||||
|
||||
async function handleConfirm() {
|
||||
if (!token) return;
|
||||
setStatus("submitting");
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${API_BASE_URL}/api/v1/custom/leads/deletion-requests/confirm/`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token }),
|
||||
},
|
||||
);
|
||||
const json = await res.json();
|
||||
if (!res.ok) {
|
||||
setMessage(json?.error?.message ?? "确认失败,请重新申请删除。");
|
||||
setStatus("error");
|
||||
return;
|
||||
}
|
||||
setMessage(json?.message ?? "已成功删除您的个人信息。");
|
||||
setStatus("done");
|
||||
} catch {
|
||||
setMessage("网络错误,请稍后重试。");
|
||||
setStatus("error");
|
||||
}
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
return (
|
||||
<p className="text-slate-700">
|
||||
链接无效,请从确认邮件中重新打开该链接,或前往{" "}
|
||||
<a
|
||||
href="/privacy-policy/delete-request"
|
||||
className="text-primary underline"
|
||||
>
|
||||
申请删除个人信息
|
||||
</a>{" "}
|
||||
重新发起申请。
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
if (status === "done") {
|
||||
return <p className="text-slate-700">{message}</p>;
|
||||
}
|
||||
|
||||
if (status === "error") {
|
||||
return <p className="text-red-600">{message}</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-bold text-slate-900">确认删除个人信息</h1>
|
||||
<p className="text-slate-700">
|
||||
点击下方按钮将永久删除您通过表单提交给我们的个人信息,此操作不可撤销。
|
||||
</p>
|
||||
<button
|
||||
onClick={handleConfirm}
|
||||
disabled={status === "submitting"}
|
||||
className="rounded-full bg-red-600 px-6 py-2 font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
{status === "submitting" ? "处理中..." : "确认删除"}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Suspense } from "react";
|
||||
import type { Metadata } from "next";
|
||||
import DeleteConfirmForm from "./DeleteConfirmForm";
|
||||
|
||||
export const metadata: Metadata = { title: "确认删除个人信息" };
|
||||
|
||||
export default function DeleteConfirmPage() {
|
||||
return (
|
||||
<div className="mx-auto max-w-xl px-6 py-24">
|
||||
<Suspense fallback={<p className="text-slate-500">加载中...</p>}>
|
||||
<DeleteConfirmForm />
|
||||
</Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
||||
|
||||
export default function DeleteRequestPage() {
|
||||
const [contact, setContact] = useState("");
|
||||
const [status, setStatus] = useState<
|
||||
"idle" | "submitting" | "done" | "error"
|
||||
>("idle");
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setStatus("submitting");
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${API_BASE_URL}/api/v1/custom/leads/deletion-requests/`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ contact }),
|
||||
},
|
||||
);
|
||||
if (!res.ok) throw new Error("request failed");
|
||||
setStatus("done");
|
||||
} catch {
|
||||
setStatus("error");
|
||||
}
|
||||
}
|
||||
|
||||
if (status === "done") {
|
||||
return (
|
||||
<div className="mx-auto max-w-xl px-6 py-24 text-center text-slate-700">
|
||||
如果我们持有与该邮箱关联的信息,确认邮件将发送至该邮箱,请查收并点击链接完成删除确认。
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-xl px-6 py-24">
|
||||
<h1 className="mb-4 text-2xl font-bold text-slate-900">
|
||||
申请删除个人信息
|
||||
</h1>
|
||||
<p className="mb-6 text-slate-700">
|
||||
依据《中华人民共和国个人信息保护法》(PIPL),您可以申请删除我们通过表单收集的您的个人信息。
|
||||
请输入您提交表单时使用的邮箱,我们将向该邮箱发送确认邮件,点击邮件中的链接即可完成删除。
|
||||
</p>
|
||||
<form onSubmit={handleSubmit} className="flex gap-2">
|
||||
<input
|
||||
type="email"
|
||||
required
|
||||
value={contact}
|
||||
onChange={(e) => setContact(e.target.value)}
|
||||
placeholder="请输入邮箱"
|
||||
className="flex-1 rounded-lg border border-slate-200 px-4 py-2"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={status === "submitting"}
|
||||
className="rounded-full bg-primary px-6 py-2 font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
{status === "submitting" ? "提交中..." : "提交申请"}
|
||||
</button>
|
||||
</form>
|
||||
{status === "error" && (
|
||||
<p className="mt-4 text-red-600">提交失败,请稍后重试。</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getSimpleContentPageBySlug } from "@/services/legal.service";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const page = await getSimpleContentPageBySlug("privacy-policy").catch(() => null);
|
||||
return { title: page?.title ?? "隐私政策" };
|
||||
}
|
||||
|
||||
export default async function PrivacyPolicyPage() {
|
||||
const page = await getSimpleContentPageBySlug("privacy-policy").catch(() => null);
|
||||
|
||||
if (!page) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<h1 className="mb-8 text-4xl font-bold text-slate-900">{page.title}</h1>
|
||||
{/* page.body 为 Wagtail RichTextField 渲染出的 HTML,内容仅由后台编辑人员维护,非用户输入,可信任直接渲染 */}
|
||||
<div
|
||||
className="space-y-4 text-slate-700 [&_h2]:mt-8 [&_h2]:text-2xl [&_h2]:font-semibold [&_h2]:text-slate-900 [&_ul]:list-disc [&_ul]:pl-6 [&_li]:mt-1"
|
||||
dangerouslySetInnerHTML={{ __html: page.body }}
|
||||
/>
|
||||
<p className="mt-8 text-slate-700">
|
||||
如需删除我们持有的您的个人信息,请
|
||||
<a
|
||||
href="/privacy-policy/delete-request"
|
||||
className="text-primary underline"
|
||||
>
|
||||
点击此处申请删除
|
||||
</a>
|
||||
。
|
||||
</p>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getProductBySlug } from "@/services/product.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { ProductPageDetail } from "@/types/wagtail";
|
||||
|
||||
interface ProductDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: ProductDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const product = await getProductBySlug(slug).catch(() => null);
|
||||
return { title: product?.title ?? "产品未找到" };
|
||||
}
|
||||
|
||||
export default async function ProductDetailPage({
|
||||
params,
|
||||
}: ProductDetailPageProps) {
|
||||
const { slug } = await params;
|
||||
const product = await getPreviewOrFallback<ProductPageDetail>(
|
||||
"products.productpage",
|
||||
"body,summary",
|
||||
() => getProductBySlug(slug).catch(() => null),
|
||||
);
|
||||
|
||||
if (!product) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<h1 className="mb-4 text-4xl font-bold text-slate-900">
|
||||
{product.title}
|
||||
</h1>
|
||||
{product.summary && (
|
||||
<p className="mb-12 text-lg text-slate-600">{product.summary}</p>
|
||||
)}
|
||||
<BlockRenderer blocks={product.body} />
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getProductList } from "@/services/product.service";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "产品",
|
||||
};
|
||||
|
||||
export default async function ProductListPage() {
|
||||
const products = await getProductList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">产品</h1>
|
||||
<ul className="space-y-6">
|
||||
{products.map((product) => (
|
||||
<li key={product.id} className="border-b border-slate-100 pb-6">
|
||||
<Link
|
||||
href={`/products/${product.meta.slug}`}
|
||||
className="text-2xl font-semibold text-slate-900 hover:text-primary"
|
||||
>
|
||||
{product.title}
|
||||
</Link>
|
||||
{product.summary && (
|
||||
<p className="mt-2 text-slate-600">{product.summary}</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
{products.length === 0 && (
|
||||
<p className="text-slate-500">暂无产品,或后端服务未连接。</p>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getSolutionBySlug } from "@/services/solution.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { SolutionPageDetail } from "@/types/wagtail";
|
||||
|
||||
interface SolutionDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: SolutionDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const solution = await getSolutionBySlug(slug).catch(() => null);
|
||||
return { title: solution?.title ?? "解决方案未找到" };
|
||||
}
|
||||
|
||||
export default async function SolutionDetailPage({
|
||||
params,
|
||||
}: SolutionDetailPageProps) {
|
||||
const { slug } = await params;
|
||||
const solution = await getPreviewOrFallback<SolutionPageDetail>(
|
||||
"solutions.solutionpage",
|
||||
"body,industry,summary",
|
||||
() => getSolutionBySlug(slug).catch(() => null),
|
||||
);
|
||||
|
||||
if (!solution) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<h1 className="mb-2 text-4xl font-bold text-slate-900">
|
||||
{solution.title}
|
||||
</h1>
|
||||
{solution.industry && (
|
||||
<p className="mb-12 text-sm text-slate-500">{solution.industry}</p>
|
||||
)}
|
||||
<BlockRenderer blocks={solution.body} />
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getSolutionList } from "@/services/solution.service";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "解决方案",
|
||||
};
|
||||
|
||||
export default async function SolutionListPage() {
|
||||
const solutions = await getSolutionList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">解决方案</h1>
|
||||
<ul className="space-y-6">
|
||||
{solutions.map((solution) => (
|
||||
<li key={solution.id} className="border-b border-slate-100 pb-6">
|
||||
<Link
|
||||
href={`/solutions/${solution.meta.slug}`}
|
||||
className="text-2xl font-semibold text-slate-900 hover:text-primary"
|
||||
>
|
||||
{solution.title}
|
||||
</Link>
|
||||
{solution.industry && (
|
||||
<p className="mt-1 text-sm text-slate-500">{solution.industry}</p>
|
||||
)}
|
||||
{solution.summary && (
|
||||
<p className="mt-2 text-slate-600">{solution.summary}</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
{solutions.length === 0 && (
|
||||
<p className="text-slate-500">暂无解决方案,或后端服务未连接。</p>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -5,13 +5,21 @@ import FeatureGrid from "./feature-grid/FeatureGrid";
|
||||
import FAQ from "./faq/FAQ";
|
||||
import CTA from "./cta/CTA";
|
||||
import LogoCloud from "./logo-cloud/LogoCloud";
|
||||
import CaseStudyCard from "./case-study/CaseStudyCard";
|
||||
import LeadForm from "./form/LeadForm";
|
||||
import ProductCardGrid from "./product-card/ProductCardGrid";
|
||||
import Pricing from "./pricing/Pricing";
|
||||
import Timeline from "./timeline/Timeline";
|
||||
import Team from "./team/Team";
|
||||
import TechStack from "./tech-stack/TechStack";
|
||||
import Video from "./video/Video";
|
||||
import type { StreamFieldBlock } from "@/types/wagtail";
|
||||
|
||||
/**
|
||||
* StreamField type → 组件映射表。
|
||||
* StreamField 类型 → 组件映射表。
|
||||
* 必须与后端 apps/core/blocks.py 的 COMMON_BLOCKS 保持一致,
|
||||
* 否则新增/重命名 Block 时前后端会出现字段不对齐问题
|
||||
* (详见 documents/设计方案分析与完善版.md §2.6)。
|
||||
* (详见 documents/设计方案分析与完善版.md §2.6)。
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const components: Record<string, ComponentType<{ value: any }>> = {
|
||||
@@ -21,6 +29,14 @@ const components: Record<string, ComponentType<{ value: any }>> = {
|
||||
faq: FAQ,
|
||||
cta: CTA,
|
||||
logo_cloud: LogoCloud,
|
||||
case_study: CaseStudyCard,
|
||||
form: LeadForm,
|
||||
product_card: ProductCardGrid,
|
||||
pricing: Pricing,
|
||||
timeline: Timeline,
|
||||
team: Team,
|
||||
tech_stack: TechStack,
|
||||
video: Video,
|
||||
};
|
||||
|
||||
export function BlockRenderer({ blocks }: { blocks: StreamFieldBlock[] }) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import Link from "next/link";
|
||||
import type { CaseStudyBlockValue } from "@/types/wagtail";
|
||||
|
||||
export default function CaseStudyCard({ value }: { value: CaseStudyBlockValue }) {
|
||||
if (!value.case_page) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-3xl px-6 py-8">
|
||||
<Link
|
||||
href={value.case_page.meta.html_url ?? "#"}
|
||||
className="block rounded-3xl border border-slate-100 p-8 shadow-sm transition hover:shadow-md"
|
||||
>
|
||||
<h3 className="text-xl font-semibold text-slate-900">
|
||||
{value.case_page.title}
|
||||
</h3>
|
||||
{value.summary && (
|
||||
<p className="mt-2 text-slate-600">{value.summary}</p>
|
||||
)}
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import type { FormBlockValue } from "@/types/wagtail";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
||||
|
||||
export default function LeadForm({ value }: { value: FormBlockValue }) {
|
||||
const [values, setValues] = useState<Record<string, string>>({});
|
||||
const [website, setWebsite] = useState(""); // 蜂蜜陷阱字段,正常用户不可见,只有机器人会填写
|
||||
const [status, setStatus] = useState<"idle" | "submitting" | "done" | "error">(
|
||||
"idle",
|
||||
);
|
||||
|
||||
const form = value.form;
|
||||
if (!form) {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setStatus("submitting");
|
||||
try {
|
||||
const res = await fetch(`${API_BASE_URL}/api/v1/custom/leads/`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
form_id: form!.id,
|
||||
data: values,
|
||||
source_url: typeof window !== "undefined" ? window.location.href : "",
|
||||
website,
|
||||
}),
|
||||
});
|
||||
if (!res.ok) throw new Error("submit failed");
|
||||
setStatus("done");
|
||||
} catch {
|
||||
setStatus("error");
|
||||
}
|
||||
}
|
||||
|
||||
if (status === "done") {
|
||||
return (
|
||||
<div className="mx-auto max-w-xl px-6 py-12 text-center text-slate-700">
|
||||
{form.success_message}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="mx-auto max-w-xl space-y-4 px-6 py-12"
|
||||
>
|
||||
<h3 className="text-2xl font-semibold text-slate-900">{form.name}</h3>
|
||||
{form.fields.map((field) => (
|
||||
<div key={field.field_key}>
|
||||
<label className="mb-1 block text-sm font-medium text-slate-700">
|
||||
{field.label}
|
||||
{field.required && <span className="text-red-500">*</span>}
|
||||
</label>
|
||||
{field.field_type === "textarea" ? (
|
||||
<textarea
|
||||
required={field.required}
|
||||
className="w-full rounded-lg border border-slate-200 px-4 py-2"
|
||||
rows={4}
|
||||
onChange={(e) =>
|
||||
setValues((v) => ({ ...v, [field.field_key]: e.target.value }))
|
||||
}
|
||||
/>
|
||||
) : field.field_type === "select" ? (
|
||||
<select
|
||||
required={field.required}
|
||||
className="w-full rounded-lg border border-slate-200 px-4 py-2"
|
||||
onChange={(e) =>
|
||||
setValues((v) => ({ ...v, [field.field_key]: e.target.value }))
|
||||
}
|
||||
>
|
||||
<option value="">请选择</option>
|
||||
{field.choices.map((choice) => (
|
||||
<option key={choice} value={choice}>
|
||||
{choice}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<input
|
||||
type={field.field_type}
|
||||
required={field.required}
|
||||
className="w-full rounded-lg border border-slate-200 px-4 py-2"
|
||||
onChange={(e) =>
|
||||
setValues((v) => ({ ...v, [field.field_key]: e.target.value }))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{/* 蜂蜜陷阱字段:离屏幕定位而非 display:none,避免部分机器人检测到隐藏属性后跳过;无需 tabIndex/aria-hidden 以外的额外依赖 */}
|
||||
<input
|
||||
type="text"
|
||||
name="website"
|
||||
value={website}
|
||||
onChange={(e) => setWebsite(e.target.value)}
|
||||
autoComplete="off"
|
||||
tabIndex={-1}
|
||||
aria-hidden="true"
|
||||
className="absolute left-[-9999px] top-auto h-px w-px overflow-hidden"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={status === "submitting"}
|
||||
className="w-full rounded-full bg-primary px-6 py-3 font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
{status === "submitting" ? "提交中..." : form.submit_button_text}
|
||||
</button>
|
||||
{status === "error" && (
|
||||
<p className="text-sm text-red-500">提交失败,请稍后重试。</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import Link from "next/link";
|
||||
import type { PricingBlockValue } from "@/types/wagtail";
|
||||
|
||||
export default function Pricing({ value }: { value: PricingBlockValue }) {
|
||||
return (
|
||||
<section className="bg-slate-50 py-24">
|
||||
<div className="mx-auto max-w-7xl px-6">
|
||||
{value.heading && (
|
||||
<h2 className="mb-16 text-center text-4xl font-bold text-slate-900">
|
||||
{value.heading}
|
||||
</h2>
|
||||
)}
|
||||
<div className="grid gap-8 lg:grid-cols-3">
|
||||
{value.plans?.map((plan, index) => (
|
||||
<div
|
||||
key={`${plan.name}-${index}`}
|
||||
className={`flex flex-col rounded-3xl border p-8 shadow-sm ${
|
||||
plan.highlighted
|
||||
? "border-primary bg-white ring-2 ring-primary"
|
||||
: "border-slate-100 bg-white"
|
||||
}`}
|
||||
>
|
||||
<h3 className="mb-2 text-xl font-semibold text-slate-900">
|
||||
{plan.name}
|
||||
</h3>
|
||||
<div className="mb-6 text-3xl font-bold text-primary">{plan.price}</div>
|
||||
<ul className="mb-8 flex-1 space-y-3">
|
||||
{plan.features?.map((feature, featureIndex) => (
|
||||
<li
|
||||
key={`${feature}-${featureIndex}`}
|
||||
className="text-sm text-slate-600"
|
||||
>
|
||||
{feature}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{plan.button && (
|
||||
<Link
|
||||
href={plan.button.link}
|
||||
className="rounded-2xl bg-primary px-6 py-3 text-center text-white"
|
||||
>
|
||||
{plan.button.text}
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import type { ProductCardBlockValue } from "@/types/wagtail";
|
||||
|
||||
export default function ProductCardGrid({ value }: { value: ProductCardBlockValue }) {
|
||||
return (
|
||||
<section className="py-24">
|
||||
<div className="mx-auto max-w-7xl px-6">
|
||||
{value.heading && (
|
||||
<h2 className="mb-16 text-4xl font-bold text-slate-900">{value.heading}</h2>
|
||||
)}
|
||||
<div className="grid gap-8 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{value.items?.map((item, index) => {
|
||||
const card = (
|
||||
<div className="h-full rounded-3xl border border-slate-100 p-6 shadow-sm transition hover:shadow-md">
|
||||
{item.image && (
|
||||
<Image
|
||||
src={item.image.url}
|
||||
alt={item.image.title}
|
||||
width={400}
|
||||
height={240}
|
||||
className="mb-6 h-40 w-full rounded-2xl object-cover"
|
||||
/>
|
||||
)}
|
||||
<h3 className="mb-2 text-xl font-semibold text-slate-900">
|
||||
{item.title}
|
||||
</h3>
|
||||
{item.description && (
|
||||
<p className="text-slate-600">{item.description}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
const key = `${item.title}-${index}`;
|
||||
return item.link ? (
|
||||
<Link key={key} href={item.link} className="block h-full">
|
||||
{card}
|
||||
</Link>
|
||||
) : (
|
||||
<div key={key}>{card}</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import Image from "next/image";
|
||||
import type { TeamBlockValue } from "@/types/wagtail";
|
||||
|
||||
export default function Team({ value }: { value: TeamBlockValue }) {
|
||||
return (
|
||||
<section className="py-24">
|
||||
<div className="mx-auto max-w-7xl px-6">
|
||||
{value.heading && (
|
||||
<h2 className="mb-16 text-4xl font-bold text-slate-900">{value.heading}</h2>
|
||||
)}
|
||||
<div className="grid gap-8 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{value.members?.map((member) => (
|
||||
<div key={member.id} className="text-center">
|
||||
{member.photo ? (
|
||||
<Image
|
||||
src={member.photo.url}
|
||||
alt={member.photo.title}
|
||||
width={200}
|
||||
height={200}
|
||||
className="mx-auto mb-4 h-40 w-40 rounded-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="mx-auto mb-4 h-40 w-40 rounded-full bg-slate-100" />
|
||||
)}
|
||||
<div className="text-lg font-semibold text-slate-900">
|
||||
{member.name}
|
||||
</div>
|
||||
{member.role && (
|
||||
<div className="mb-2 text-sm text-primary">{member.role}</div>
|
||||
)}
|
||||
{member.bio && (
|
||||
<p className="text-sm text-slate-600">{member.bio}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { TechStackBlockValue } from "@/types/wagtail";
|
||||
|
||||
export default function TechStack({ value }: { value: TechStackBlockValue }) {
|
||||
return (
|
||||
<section className="bg-slate-50 py-24">
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
{value.heading && (
|
||||
<h2 className="mb-16 text-center text-4xl font-bold text-slate-900">
|
||||
{value.heading}
|
||||
</h2>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-6 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{value.items?.map((item, index) => (
|
||||
<div
|
||||
key={`${item.label}-${index}`}
|
||||
className="flex flex-col items-center gap-3 rounded-2xl bg-white p-6 text-center shadow-sm"
|
||||
>
|
||||
{item.icon && <span className="text-3xl">{item.icon}</span>}
|
||||
<span className="text-sm font-medium text-slate-700">
|
||||
{item.label}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { TimelineBlockValue } from "@/types/wagtail";
|
||||
|
||||
export default function Timeline({ value }: { value: TimelineBlockValue }) {
|
||||
return (
|
||||
<section className="py-24">
|
||||
<div className="mx-auto max-w-4xl px-6">
|
||||
{value.heading && (
|
||||
<h2 className="mb-16 text-4xl font-bold text-slate-900">{value.heading}</h2>
|
||||
)}
|
||||
<ol className="relative space-y-10 border-l border-slate-200 pl-8">
|
||||
{value.items?.map((item, index) => (
|
||||
<li key={`${item.year}-${index}`} className="relative">
|
||||
<span className="absolute -left-[2.35rem] top-1 h-3 w-3 rounded-full bg-primary" />
|
||||
<div className="mb-1 text-lg font-semibold text-primary">
|
||||
{item.year}
|
||||
</div>
|
||||
<p className="text-slate-600">{item.event}</p>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { VideoBlockValue } from "@/types/wagtail";
|
||||
|
||||
const DIRECT_VIDEO_EXTENSIONS = [".mp4", ".webm", ".ogg"];
|
||||
|
||||
export default function Video({ value }: { value: VideoBlockValue }) {
|
||||
if (!value.video_url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isDirectFile = DIRECT_VIDEO_EXTENSIONS.some((ext) =>
|
||||
value.video_url.toLowerCase().includes(ext)
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="py-24">
|
||||
<div className="mx-auto max-w-5xl px-6">
|
||||
{value.heading && (
|
||||
<h2 className="mb-8 text-center text-4xl font-bold text-slate-900">
|
||||
{value.heading}
|
||||
</h2>
|
||||
)}
|
||||
<div className="overflow-hidden rounded-3xl bg-black shadow-lg">
|
||||
{isDirectFile ? (
|
||||
<video
|
||||
src={value.video_url}
|
||||
poster={value.poster?.url}
|
||||
controls
|
||||
className="aspect-video w-full"
|
||||
/>
|
||||
) : (
|
||||
<iframe
|
||||
src={value.video_url}
|
||||
allow="autoplay; fullscreen"
|
||||
allowFullScreen
|
||||
className="aspect-video w-full"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
|
||||
const CONSENT_STORAGE_KEY = "cookie-consent";
|
||||
|
||||
export default function CookieConsent() {
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// 仅在浏览器已明确同意/拒绝前展示,避免每次访问重复弹出。
|
||||
// localStorage 只能在客户端读取,此处属于“挂载后同步一次性客户端状态”的合理用法。
|
||||
const consent = window.localStorage.getItem(CONSENT_STORAGE_KEY);
|
||||
if (!consent) {
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect -- 首次挂载后读取 localStorage 决定是否展示横幅,属预期用法
|
||||
setVisible(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
function handleChoice(choice: "accepted" | "rejected") {
|
||||
window.localStorage.setItem(CONSENT_STORAGE_KEY, choice);
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="dialog"
|
||||
aria-live="polite"
|
||||
aria-label="Cookie 使用提示"
|
||||
className="fixed inset-x-0 bottom-0 z-[100] border-t border-slate-800 bg-slate-950 px-6 py-4 text-sm text-slate-300"
|
||||
>
|
||||
<div className="mx-auto flex max-w-7xl flex-col items-center justify-between gap-3 sm:flex-row">
|
||||
<p>
|
||||
本网站使用 Cookie 以提升您的浏览体验。继续访问即表示您同意我们按照{" "}
|
||||
<Link
|
||||
href="/privacy-policy"
|
||||
className="underline underline-offset-2 hover:text-white"
|
||||
>
|
||||
隐私政策
|
||||
</Link>{" "}
|
||||
使用 Cookie。您也可以选择拒绝非必要 Cookie。
|
||||
</p>
|
||||
<div className="flex shrink-0 gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleChoice("rejected")}
|
||||
className="rounded-md border border-slate-600 px-4 py-2 text-slate-300 hover:bg-slate-800"
|
||||
>
|
||||
拒绝
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleChoice("accepted")}
|
||||
className="rounded-md bg-primary px-4 py-2 font-medium text-white hover:opacity-90"
|
||||
>
|
||||
接受
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,24 +1,41 @@
|
||||
export default function Footer() {
|
||||
import { getSiteSettings } from "@/services/site-settings.service";
|
||||
|
||||
// 合规要求:中国大陆网站需展示 ICP 备案号并链接至工信部备案查询。
|
||||
// 详见 documents/设计方案分析与完善版.md §2.15。
|
||||
const FALLBACK_ICP_NUMBER = "冀ICP备2025130506号-1";
|
||||
const FALLBACK_ICP_URL = "https://beian.miit.gov.cn/";
|
||||
|
||||
export default async function Footer() {
|
||||
// 优先使用后台配置的站点设置(apps.core.SiteSettings),
|
||||
// 接口不可用时回退到硬编码的备案信息,保证构建/渲染始终可用。
|
||||
const siteSettings = await getSiteSettings();
|
||||
const icpNumber = siteSettings?.icp_number || FALLBACK_ICP_NUMBER;
|
||||
const icpUrl = siteSettings?.icp_url || FALLBACK_ICP_URL;
|
||||
|
||||
return (
|
||||
<footer className="mt-auto border-t border-slate-100 bg-slate-950 py-10 text-slate-400">
|
||||
<div className="mx-auto max-w-7xl px-6 text-center text-sm">
|
||||
<p>© {new Date().getFullYear()} 企业官网. All rights reserved.</p>
|
||||
{/*
|
||||
合规要求:中国大陆网站需展示 ICP 备案号并链接至工信部备案查询。
|
||||
详见 documents/设计方案分析与完善版.md §2.15。
|
||||
实际备案号需在完成 ICP 备案后替换。
|
||||
*/}
|
||||
<p>
|
||||
© {new Date().getFullYear()}{" "}
|
||||
{siteSettings?.company_name || "企业官网"}. All rights reserved.
|
||||
</p>
|
||||
<p className="mt-2">
|
||||
<a href="/privacy-policy" className="hover:text-white">
|
||||
隐私政策
|
||||
</a>
|
||||
</p>
|
||||
<p className="mt-2">
|
||||
<a
|
||||
href="https://beian.miit.gov.cn/"
|
||||
href={icpUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="hover:text-white"
|
||||
>
|
||||
沪ICP备XXXXXXXX号-1
|
||||
{icpNumber}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
import Link from "next/link";
|
||||
import { getNavigationMenu } from "@/services/navigation.service";
|
||||
|
||||
const navItems = [
|
||||
const fallbackNavItems = [
|
||||
{ title: "首页", href: "/" },
|
||||
{ title: "产品", href: "/products" },
|
||||
{ title: "解决方案", href: "/solutions" },
|
||||
{ title: "案例", href: "/cases" },
|
||||
{ title: "博客", href: "/blog" },
|
||||
];
|
||||
|
||||
export default function Header() {
|
||||
export default async function Header() {
|
||||
// 优先使用后台配置的主导航(apps.core.NavigationMenu,name="main"),
|
||||
// 未配置或接口不可用时回退到静态导航项,保证构建/渲染始终可用。
|
||||
const menu = await getNavigationMenu("main");
|
||||
const navItems = menu?.items.length
|
||||
? menu.items.map((item) => ({
|
||||
title: item.label,
|
||||
href: item.url,
|
||||
newTab: item.open_in_new_tab,
|
||||
}))
|
||||
: fallbackNavItems.map((item) => ({ ...item, newTab: false }));
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-50 border-b border-slate-100 bg-white/80 backdrop-blur">
|
||||
<div className="mx-auto flex h-16 max-w-7xl items-center justify-between px-6">
|
||||
@@ -14,7 +29,13 @@ export default function Header() {
|
||||
</Link>
|
||||
<nav className="flex gap-8">
|
||||
{navItems.map((item) => (
|
||||
<Link key={item.href} href={item.href} className="text-slate-700">
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className="text-slate-700"
|
||||
target={item.newTab ? "_blank" : undefined}
|
||||
rel={item.newTab ? "noreferrer" : undefined}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
))}
|
||||
@@ -23,3 +44,4 @@ export default function Header() {
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type {
|
||||
CaseStudyPageDetail,
|
||||
CaseStudyPageSummary,
|
||||
WagtailListResponse,
|
||||
} from "@/types/wagtail";
|
||||
|
||||
/** 获取客户案例列表(按发布时间倒序)。 */
|
||||
export async function getCaseStudyList(): Promise<CaseStudyPageSummary[]> {
|
||||
const res = await fetchAPI<WagtailListResponse<CaseStudyPageSummary>>(
|
||||
"/api/v2/pages/?type=cases.CaseStudyPage&fields=client_name,industry,published_at,summary&order=-published_at",
|
||||
{ tags: ["case-study-list"] },
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
|
||||
/** 根据 slug 获取客户案例详情。 */
|
||||
export async function getCaseStudyBySlug(
|
||||
slug: string,
|
||||
): Promise<CaseStudyPageDetail | null> {
|
||||
const res = await fetchAPI<WagtailListResponse<CaseStudyPageDetail>>(
|
||||
`/api/v2/pages/?type=cases.CaseStudyPage&slug=${encodeURIComponent(slug)}&fields=body,client_name,industry,published_at,summary&limit=1`,
|
||||
{ tags: [`case-study:${slug}`] },
|
||||
);
|
||||
return res.items[0] ?? null;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { SimpleContentPageDetail, WagtailListResponse } from "@/types/wagtail";
|
||||
|
||||
/**
|
||||
* 根据 slug 获取通用富文本内容页(apps.core.SimpleContentPage),
|
||||
* 用于隐私政策、服务条款等法务/说明类页面。
|
||||
*/
|
||||
export async function getSimpleContentPageBySlug(
|
||||
slug: string,
|
||||
): Promise<SimpleContentPageDetail | null> {
|
||||
const res = await fetchAPI<WagtailListResponse<SimpleContentPageDetail>>(
|
||||
`/api/v2/pages/?type=core.SimpleContentPage&slug=${encodeURIComponent(slug)}&fields=body&limit=1`,
|
||||
{ tags: [`legal-page:${slug}`] },
|
||||
);
|
||||
return res.items[0] ?? null;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { NavigationMenuValue } from "@/types/wagtail";
|
||||
|
||||
/**
|
||||
* 根据 name(如 main / footer)获取导航菜单(apps.core.NavigationMenu Snippet)。
|
||||
* 未在后台配置对应菜单时返回 null,调用方应回退到静态导航项。
|
||||
*/
|
||||
export async function getNavigationMenu(
|
||||
name: string,
|
||||
): Promise<NavigationMenuValue | null> {
|
||||
try {
|
||||
return await fetchAPI<NavigationMenuValue>(
|
||||
`/api/v1/custom/core/navigation/?name=${encodeURIComponent(name)}`,
|
||||
{ tags: [`navigation:${name}`] },
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { PartnerValue } from "@/types/wagtail";
|
||||
|
||||
/** 获取合作伙伴/客户 Logo 列表(apps.core.Partner Snippet)。 */
|
||||
export async function getPartners(): Promise<PartnerValue[]> {
|
||||
const res = await fetchAPI<{ items: PartnerValue[] }>(
|
||||
"/api/v1/custom/core/partners/",
|
||||
{ tags: ["partners"] },
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { draftMode, cookies } from "next/headers";
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { WagtailPageSummary } from "@/types/wagtail";
|
||||
|
||||
/**
|
||||
* Wagtail 预览模式(wagtail_headless_preview + Next.js Draft Mode)。
|
||||
* 详见 documents/设计方案分析与完善版.md §2.16,后端实现见 apps/api/urls.py
|
||||
* 的 PagePreviewAPIViewSet(挂载在 /api/v2/page_preview/)。
|
||||
*/
|
||||
|
||||
export const PREVIEW_CONTENT_TYPE_COOKIE = "wagtail_preview_content_type";
|
||||
export const PREVIEW_TOKEN_COOKIE = "wagtail_preview_token";
|
||||
|
||||
/** content_type(`app_label.model`,小写)→ 对应前端路由的解析函数 */
|
||||
const PREVIEW_PATH_RESOLVERS: Record<
|
||||
string,
|
||||
(page: WagtailPageSummary) => string
|
||||
> = {
|
||||
"home.homepage": () => "/",
|
||||
"blog.blogpage": (page) => `/blog/${page.meta.slug}`,
|
||||
"products.productpage": (page) => `/products/${page.meta.slug}`,
|
||||
"cases.casestudypage": (page) => `/cases/${page.meta.slug}`,
|
||||
"solutions.solutionpage": (page) => `/solutions/${page.meta.slug}`,
|
||||
};
|
||||
|
||||
/** 根据 content_type 解析预览内容应跳转到的前端路径,未知类型返回 null。 */
|
||||
export function resolvePreviewPath(
|
||||
contentType: string,
|
||||
page: WagtailPageSummary,
|
||||
): string | null {
|
||||
const resolver = PREVIEW_PATH_RESOLVERS[contentType];
|
||||
return resolver ? resolver(page) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取草稿页面数据。`fields` 省略时仅返回 Wagtail API 默认字段(含 meta.slug/meta.type),
|
||||
* 用于 /preview 路由校验 token 是否有效。
|
||||
*/
|
||||
export async function fetchPreviewPage<T extends WagtailPageSummary>(
|
||||
contentType: string,
|
||||
token: string,
|
||||
fields?: string,
|
||||
): Promise<T | null> {
|
||||
const query = new URLSearchParams({ content_type: contentType, token });
|
||||
if (fields) {
|
||||
query.set("fields", fields);
|
||||
}
|
||||
try {
|
||||
return await fetchAPI<T>(`/api/v2/page_preview/?${query.toString()}`, {
|
||||
revalidate: 0,
|
||||
});
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在页面组件中调用:若 Draft Mode 已开启且 cookie 中记录的 content_type
|
||||
* 与当前页面类型一致,返回草稿数据;否则回退到 `fallback()`(正常已发布内容)。
|
||||
*/
|
||||
export async function getPreviewOrFallback<T extends WagtailPageSummary>(
|
||||
expectedContentType: string,
|
||||
fields: string,
|
||||
fallback: () => Promise<T | null>,
|
||||
): Promise<T | null> {
|
||||
const { isEnabled } = await draftMode();
|
||||
if (!isEnabled) {
|
||||
return fallback();
|
||||
}
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const contentType = cookieStore.get(PREVIEW_CONTENT_TYPE_COOKIE)?.value;
|
||||
const token = cookieStore.get(PREVIEW_TOKEN_COOKIE)?.value;
|
||||
|
||||
if (contentType !== expectedContentType || !token) {
|
||||
return fallback();
|
||||
}
|
||||
|
||||
const preview = await fetchPreviewPage<T>(expectedContentType, token, fields);
|
||||
return preview ?? fallback();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type {
|
||||
ProductPageDetail,
|
||||
ProductPageSummary,
|
||||
WagtailListResponse,
|
||||
} from "@/types/wagtail";
|
||||
|
||||
/** 获取产品列表。 */
|
||||
export async function getProductList(): Promise<ProductPageSummary[]> {
|
||||
const res = await fetchAPI<WagtailListResponse<ProductPageSummary>>(
|
||||
"/api/v2/pages/?type=products.ProductPage&fields=summary",
|
||||
{ tags: ["product-list"] },
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
|
||||
/** 根据 slug 获取产品详情。 */
|
||||
export async function getProductBySlug(
|
||||
slug: string,
|
||||
): Promise<ProductPageDetail | null> {
|
||||
const res = await fetchAPI<WagtailListResponse<ProductPageDetail>>(
|
||||
`/api/v2/pages/?type=products.ProductPage&slug=${encodeURIComponent(slug)}&fields=body,summary&limit=1`,
|
||||
{ tags: [`product:${slug}`] },
|
||||
);
|
||||
return res.items[0] ?? null;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { SiteSettingsValue } from "@/types/wagtail";
|
||||
|
||||
/** 获取站点全局配置(apps.core.SiteSettings,wagtail.contrib.settings)。 */
|
||||
export async function getSiteSettings(): Promise<SiteSettingsValue | null> {
|
||||
try {
|
||||
return await fetchAPI<SiteSettingsValue>(
|
||||
"/api/v1/custom/core/site-settings/",
|
||||
{ tags: ["site-settings"] },
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type {
|
||||
SolutionPageDetail,
|
||||
SolutionPageSummary,
|
||||
WagtailListResponse,
|
||||
} from "@/types/wagtail";
|
||||
|
||||
/** 获取解决方案列表。 */
|
||||
export async function getSolutionList(): Promise<SolutionPageSummary[]> {
|
||||
const res = await fetchAPI<WagtailListResponse<SolutionPageSummary>>(
|
||||
"/api/v2/pages/?type=solutions.SolutionPage&fields=industry,summary",
|
||||
{ tags: ["solution-list"] },
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
|
||||
/** 根据 slug 获取解决方案详情。 */
|
||||
export async function getSolutionBySlug(
|
||||
slug: string,
|
||||
): Promise<SolutionPageDetail | null> {
|
||||
const res = await fetchAPI<WagtailListResponse<SolutionPageDetail>>(
|
||||
`/api/v2/pages/?type=solutions.SolutionPage&slug=${encodeURIComponent(slug)}&fields=body,industry,summary&limit=1`,
|
||||
{ tags: [`solution:${slug}`] },
|
||||
);
|
||||
return res.items[0] ?? null;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { TeamMemberValue } from "@/types/wagtail";
|
||||
|
||||
/** 获取团队成员列表(apps.core.TeamMember Snippet)。 */
|
||||
export async function getTeamMembers(): Promise<TeamMemberValue[]> {
|
||||
const res = await fetchAPI<{ items: TeamMemberValue[] }>(
|
||||
"/api/v1/custom/core/team/",
|
||||
{ tags: ["team"] },
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { fetchAPI } from "./api-client";
|
||||
import type { TestimonialValue } from "@/types/wagtail";
|
||||
|
||||
/** 获取客户证言列表(apps.core.Testimonial Snippet)。 */
|
||||
export async function getTestimonials(): Promise<TestimonialValue[]> {
|
||||
const res = await fetchAPI<{ items: TestimonialValue[] }>(
|
||||
"/api/v1/custom/core/testimonials/",
|
||||
{ tags: ["testimonials"] },
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
@@ -75,6 +75,98 @@ export interface LogoCloudBlockValue {
|
||||
logos: { url: string; title: string }[];
|
||||
}
|
||||
|
||||
export interface CaseStudyBlockValue {
|
||||
case_page: WagtailPageSummary | null;
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
/** 与后端 apps/forms/models.py FIELD_TYPE_CHOICES 保持一致 */
|
||||
export type FormFieldType = "text" | "textarea" | "email" | "tel" | "select";
|
||||
|
||||
export interface FormFieldDef {
|
||||
label: string;
|
||||
field_key: string;
|
||||
field_type: FormFieldType;
|
||||
required: boolean;
|
||||
choices: string[];
|
||||
}
|
||||
|
||||
export interface FormDefinitionValue {
|
||||
id: number;
|
||||
name: string;
|
||||
submit_button_text: string;
|
||||
success_message: string;
|
||||
fields: FormFieldDef[];
|
||||
}
|
||||
|
||||
export interface FormBlockValue {
|
||||
form: FormDefinitionValue | null;
|
||||
}
|
||||
|
||||
export interface ProductCardItemValue {
|
||||
title: string;
|
||||
description?: string;
|
||||
image?: { url: string; title: string } | null;
|
||||
link?: string;
|
||||
}
|
||||
|
||||
export interface ProductCardBlockValue {
|
||||
heading?: string;
|
||||
items: ProductCardItemValue[];
|
||||
}
|
||||
|
||||
export interface PricingPlanValue {
|
||||
name: string;
|
||||
price: string;
|
||||
features: string[];
|
||||
highlighted?: boolean;
|
||||
button?: CTAButtonValue | null;
|
||||
}
|
||||
|
||||
export interface PricingBlockValue {
|
||||
heading?: string;
|
||||
plans: PricingPlanValue[];
|
||||
}
|
||||
|
||||
export interface TimelineItemValue {
|
||||
year: string;
|
||||
event: string;
|
||||
}
|
||||
|
||||
export interface TimelineBlockValue {
|
||||
heading?: string;
|
||||
items: TimelineItemValue[];
|
||||
}
|
||||
|
||||
export interface TeamMemberBlockValue {
|
||||
id: number;
|
||||
name: string;
|
||||
role: string;
|
||||
bio: string;
|
||||
photo: { url: string; title: string } | null;
|
||||
}
|
||||
|
||||
export interface TeamBlockValue {
|
||||
heading?: string;
|
||||
members: TeamMemberBlockValue[];
|
||||
}
|
||||
|
||||
export interface TechStackItemValue {
|
||||
icon?: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface TechStackBlockValue {
|
||||
heading?: string;
|
||||
items: TechStackItemValue[];
|
||||
}
|
||||
|
||||
export interface VideoBlockValue {
|
||||
heading?: string;
|
||||
video_url: string;
|
||||
poster?: { url: string; title: string } | null;
|
||||
}
|
||||
|
||||
export type StreamFieldBlock =
|
||||
| { id: string; type: "hero"; value: HeroBlockValue }
|
||||
| { id: string; type: "stats"; value: StatsBlockValue }
|
||||
@@ -82,6 +174,14 @@ export type StreamFieldBlock =
|
||||
| { id: string; type: "faq"; value: FAQBlockValue }
|
||||
| { id: string; type: "cta"; value: CTABlockValue }
|
||||
| { id: string; type: "logo_cloud"; value: LogoCloudBlockValue }
|
||||
| { id: string; type: "case_study"; value: CaseStudyBlockValue }
|
||||
| { id: string; type: "form"; value: FormBlockValue }
|
||||
| { id: string; type: "product_card"; value: ProductCardBlockValue }
|
||||
| { id: string; type: "pricing"; value: PricingBlockValue }
|
||||
| { id: string; type: "timeline"; value: TimelineBlockValue }
|
||||
| { id: string; type: "team"; value: TeamBlockValue }
|
||||
| { id: string; type: "tech_stack"; value: TechStackBlockValue }
|
||||
| { id: string; type: "video"; value: VideoBlockValue }
|
||||
| { id: string; type: "richtext"; value: string };
|
||||
|
||||
export interface HomePageDetail extends WagtailPageSummary {
|
||||
@@ -98,3 +198,85 @@ export interface BlogPageSummary extends WagtailPageSummary {
|
||||
export interface BlogPageDetail extends BlogPageSummary {
|
||||
body: StreamFieldBlock[];
|
||||
}
|
||||
|
||||
export interface ProductPageSummary extends WagtailPageSummary {
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
export interface ProductPageDetail extends ProductPageSummary {
|
||||
body: StreamFieldBlock[];
|
||||
}
|
||||
|
||||
export interface CaseStudyPageSummary extends WagtailPageSummary {
|
||||
client_name: string;
|
||||
industry?: string;
|
||||
published_at?: string;
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
export interface CaseStudyPageDetail extends CaseStudyPageSummary {
|
||||
body: StreamFieldBlock[];
|
||||
}
|
||||
|
||||
export interface SolutionPageSummary extends WagtailPageSummary {
|
||||
industry?: string;
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
export interface SolutionPageDetail extends SolutionPageSummary {
|
||||
body: StreamFieldBlock[];
|
||||
}
|
||||
|
||||
export interface SimpleContentPageDetail extends WagtailPageSummary {
|
||||
body: string; // richtext HTML
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局 Snippet 类型(apps/core/models.py)。
|
||||
* 通过 /api/v1/custom/core/... 只读接口获取,非 Wagtail Page API。
|
||||
*/
|
||||
export interface TeamMemberValue {
|
||||
id: number;
|
||||
name: string;
|
||||
role: string;
|
||||
bio: string;
|
||||
photo: { url: string; title: string } | null;
|
||||
}
|
||||
|
||||
export interface TestimonialValue {
|
||||
id: number;
|
||||
quote: string;
|
||||
author_name: string;
|
||||
author_title: string;
|
||||
author_photo: { url: string; title: string } | null;
|
||||
}
|
||||
|
||||
export interface PartnerValue {
|
||||
id: number;
|
||||
name: string;
|
||||
website_url: string;
|
||||
logo: { url: string; title: string } | null;
|
||||
}
|
||||
|
||||
export interface NavigationMenuItemValue {
|
||||
label: string;
|
||||
url: string;
|
||||
open_in_new_tab: boolean;
|
||||
}
|
||||
|
||||
export interface NavigationMenuValue {
|
||||
name: string;
|
||||
items: NavigationMenuItemValue[];
|
||||
}
|
||||
|
||||
export interface SiteSettingsValue {
|
||||
company_name: string;
|
||||
contact_phone: string;
|
||||
contact_email: string;
|
||||
address: string;
|
||||
icp_number: string;
|
||||
icp_url: string;
|
||||
wechat_account: string;
|
||||
weibo_url: string;
|
||||
wechat_qrcode: { url: string; title: string } | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user