Files
wagtailcms-frontend/components/layout/Header.tsx
T

56 lines
2.0 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";
import { getSiteSettings } from "@/services/site-settings.service";
import MobileNavigation from "./MobileNavigation";
const fallbackNavItems = [
{ title: "首页", href: "/" },
{ title: "产品", href: "/products" },
{ title: "解决方案", href: "/solutions" },
{ title: "案例", href: "/cases" },
{ title: "博客", href: "/blog" },
];
export default async function Header() {
// 优先使用后台配置的主导航(apps.core.NavigationMenu,name="main"),
// 未配置或接口不可用时回退到静态导航项,保证构建/渲染始终可用。
const [menu, siteSettings] = await Promise.all([getNavigationMenu("main"), getSiteSettings()]);
const companyName = siteSettings?.company_name || "企业官网";
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="/"
aria-label={`${companyName}首页`}
className="min-w-0 max-w-[50%] truncate text-xl font-bold text-slate-900"
>
<span>{companyName}</span>
</Link>
<nav aria-label="主导航" className="hidden flex-wrap items-center justify-end gap-4 xl:flex">
{navItems.map((item) => (
<Link
key={item.href}
href={item.href}
className="whitespace-nowrap text-slate-700"
target={item.newTab ? "_blank" : undefined}
rel={item.newTab ? "noreferrer" : undefined}
>
{item.title}
</Link>
))}
</nav>
<MobileNavigation items={navItems} />
</div>
</header>
);
}