Files
wagtailcms-frontend/components/layout/Header.tsx
T
Zhengen 24a2311e20 feat: 接入后端全局Snippet(导航菜单/站点设置),补充团队/证言/合作伙伴 service 层
- Header 改为异步 Server Component,接入 NavigationMenu(name=main),
  接口不可用或未配置时回退静态导航项
- Footer 改为异步 Server Component,接入 SiteSettings,
  公司名/ICP备案号/备案链接优先取后台配置,缺省回退硬编码值
- types/wagtail.ts 新增 TeamMember/Testimonial/Partner/NavigationMenu/SiteSettings 类型
- 新增 services: team/testimonial/partner/navigation/site-settings.service.ts
- lint、build 均已验证通过
2026-08-07 13:06:45 +08:00

48 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Link from "next/link";
import { getNavigationMenu } from "@/services/navigation.service";
const fallbackNavItems = [
{ title: "首页", href: "/" },
{ title: "产品", href: "/products" },
{ title: "解决方案", href: "/solutions" },
{ title: "案例", href: "/cases" },
{ title: "博客", href: "/blog" },
];
export default async function Header() {
// 优先使用后台配置的主导航(apps.core.NavigationMenuname="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">
<Link href="/" className="text-xl font-bold text-primary">
企业官网
</Link>
<nav className="flex gap-8">
{navItems.map((item) => (
<Link
key={item.href}
href={item.href}
className="text-slate-700"
target={item.newTab ? "_blank" : undefined}
rel={item.newTab ? "noreferrer" : undefined}
>
{item.title}
</Link>
))}
</nav>
</div>
</header>
);
}