- 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
831 B
TypeScript
27 lines
831 B
TypeScript
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;
|
|
}
|