- types: Product/CaseStudy page types, CaseStudyBlockValue, FormBlockValue - services: product.service.ts, case.service.ts - app/products, app/cases: list + detail pages - blocks: CaseStudyCard, LeadForm (submits to /api/v1/custom/leads/) - Header nav: add 产品/案例 links
27 lines
978 B
TypeScript
27 lines
978 B
TypeScript
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;
|
|
}
|