66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { LOCALES } from "@/i18n/routing";
|
||
import { getLines } from "@/lib/lines";
|
||
import { constructMetadata } from "@/lib/metadata";
|
||
import { Line } from "@/types/line";
|
||
import { Metadata } from "next";
|
||
import { getTranslations } from "next-intl/server";
|
||
|
||
// 强制静态生成
|
||
export const dynamic = "force-static";
|
||
|
||
// 明确 Params 类型(静态生成的参数)
|
||
type Params = { locale: string };
|
||
|
||
type MetadataProps = {
|
||
params: Params;
|
||
};
|
||
|
||
// 生成页面元数据(确保服务端/客户端翻译一致)
|
||
export async function generateMetadata({
|
||
params,
|
||
}: MetadataProps): Promise<Metadata> {
|
||
const { locale } = params;
|
||
const t = await getTranslations({ locale, namespace: "Workshop" });
|
||
|
||
return constructMetadata({
|
||
page: "Workshop",
|
||
title: t("pageTitle", { defaultValue: "车间展示" }), // 使用 next-intl 官方的 defaultValue
|
||
description: t("pageDesc", { defaultValue: "公司产品线展示" }),
|
||
locale: locale,
|
||
path: `/line`,
|
||
canonicalUrl: `/line`,
|
||
});
|
||
}
|
||
|
||
// 生成静态路由参数(多语言)
|
||
export async function generateStaticParams() {
|
||
return LOCALES.map((locale) => ({
|
||
locale,
|
||
}));
|
||
}
|
||
|
||
// 空数据组件(纯静态,无动态属性)
|
||
function EmptyState() {
|
||
return <div className="py-10 text-center text-gray-500">暂无产品线数据</div>;
|
||
}
|
||
|
||
// 单个车间卡片组件(Client Component 标记,避免 Hydration 冲突)
|
||
// 'use client'; // 仅当需要添加交互时启用,当前纯展示可不用
|
||
|
||
function ProductCard({ product }: { product: Line }) {
|
||
|
||
}
|
||
|
||
// 页面主组件(Server Component)
|
||
export default async function Page({
|
||
params,
|
||
}: {
|
||
params: Params;
|
||
}) {
|
||
const { locale } = await params;
|
||
// 获取翻译(确保服务端/客户端一致)
|
||
const t = await getTranslations({ locale, namespace: "Workshop" });
|
||
|
||
// 获取产品线数据(顶层 await,Server Component 原生支持)
|
||
const products: Line[] = await getLines(locale);
|
||
} |