import { Link, useLocation } from "react-router-dom"; import { Swiper, SwiperSlide } from "swiper/react"; import { Autoplay, EffectFade } from "swiper/modules"; import "swiper/css"; import "swiper/css/effect-fade"; import styles from "./Banner.module.css"; import { useMemo } from "react"; import { useStore } from "@/store"; const FALLBACK_GRADIENT = "linear-gradient(135deg, #1a2a4a 0%, #2d4a7c 100%)"; export type BannerConfig = { title?: string; content?: string; subtitle?: string; largeContent?: string; titleSize?: "large" | "medium" | string; showBreadcrumb?: boolean; backgroundImage?: string | string[]; }; type Props = { title: string; subtitle?: string; desc?: string; content?: string; largedesc?: string; showBreadcrumb?: boolean; titleSize?: "large" | "medium" | string; backgroundImage: string | string[]; }; export default function Banner({ title, subtitle, desc, content, largedesc, showBreadcrumb, titleSize = "large", backgroundImage, }: Props) { const appConfig = useStore((s) => s.appConfig); const header = appConfig?.header; const navItems = header?.navItems ?? []; const location = useLocation(); const images = Array.isArray(backgroundImage) ? backgroundImage : [backgroundImage]; const isCarousel = images.length > 1; const descText = desc ?? content; const breadcrumbItems = useMemo(() => { const segments = location.pathname.split("/").filter((s) => s !== ""); if (segments.length === 0) { return [{ label: "首页", to: "/" }]; } const paths: string[] = []; for (let i = 0; i < segments.length; i++) { paths.push((paths[i - 1] ?? "") + "/" + segments[i]); } const getLabelByPath = (path: string): string => { if (path === "/") return navItems.find((n) => n.index)?.label ?? "首页"; const top = navItems.find((n) => n.path === path); if (top) return top.label; for (const item of navItems) { const child = item.children?.find((c) => c.path === path); if (child) return child.label; } const last = path.split("/").pop() ?? path; return last; }; const items = paths.map((path) => ({ label: getLabelByPath(path), to: path, })); items.unshift({ label: navItems.find((n) => n.index)?.label ?? "首页", to: "/", }); return items; }, [location.pathname, navItems]); const heroContent = (
{descText}
} {largedesc &&{largedesc}
}