'use client'; import { Clover, Film, Github, Home, MessageCircleHeart, MountainSnow, Search, Star, Swords, Tv, VenetianMask, } from 'lucide-react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useSite } from './SiteProvider'; interface MobileBottomNavProps { /** * 主动指定当前激活的路径。当未提供时,自动使用 usePathname() 获取的路径。 */ activePath?: string; } const MobileBottomNav = ({ activePath }: MobileBottomNavProps) => { const pathname = usePathname(); // 当前激活路径:优先使用传入的 activePath,否则回退到浏览器地址 const currentActive = activePath ?? pathname; const navItems = [ { icon: Home, label: '首页', href: '/' }, { icon: Search, label: '搜索', href: '/search' }, { icon: Film, label: '电影', href: '/douban?type=movie&tag=热门&title=热门电影', }, { icon: Tv, label: '剧集', href: '/douban?type=tv&tag=热门&title=热门剧集', }, { icon: Star, label: '高分', href: '/douban?type=movie&tag=top250&title=豆瓣 Top250', }, { icon: Clover, label: '综艺', href: '/douban?type=tv&tag=综艺&title=综艺', }, { icon: Swords, label: '美剧', href: '/douban?type=tv&tag=美剧' }, { icon: MessageCircleHeart, label: '韩剧', href: '/douban?type=tv&tag=韩剧', }, { icon: MountainSnow, label: '日剧', href: '/douban?type=tv&tag=日剧' }, { icon: VenetianMask, label: '日漫', href: '/douban?type=tv&tag=日本动画' }, ]; const { siteName } = useSite(); if (siteName !== 'MoonTV') { navItems.push({ icon: Github, label: 'MoonTV', href: 'https://github.com/senshinya/MoonTV', }); } const isActive = (href: string) => { const typeMatch = href.match(/type=([^&]+)/)?.[1]; const tagMatch = href.match(/tag=([^&]+)/)?.[1]; // 解码URL以进行正确的比较 const decodedActive = decodeURIComponent(currentActive); const decodedItemHref = decodeURIComponent(href); return ( decodedActive === decodedItemHref || (decodedActive.startsWith('/douban') && decodedActive.includes(`type=${typeMatch}`) && decodedActive.includes(`tag=${tagMatch}`)) ); }; return ( ); }; export default MobileBottomNav;