'use client'; import { useState, useLayoutEffect, useRef } from 'react'; import { StaticLink } from '@/components/ui/static-link'; import { usePathname, useSearchParams } from 'next/navigation'; import { Home, Briefcase, Package, FileText, User } from 'lucide-react'; import { motion } from 'framer-motion'; import { cn } from '@/lib/utils'; const tabs = [ { id: 'home', label: '首页', href: '/', icon: Home }, { id: 'services', label: '服务', href: '/#services', icon: Briefcase }, { id: 'products', label: '产品', href: '/#products', icon: Package }, { id: 'news', label: '新闻', href: '/#news', icon: FileText }, { id: 'contact', label: '联系', href: '/contact', icon: User }, ]; export function MobileTabBar() { const pathname = usePathname(); const searchParams = useSearchParams(); const [hash, setHash] = useState(''); const isInitializedRef = useRef(false); useLayoutEffect(() => { if (!isInitializedRef.current) { isInitializedRef.current = true; setHash(window.location.hash.slice(1)); } const handleHashChange = () => { setHash(window.location.hash.slice(1)); }; window.addEventListener('hashchange', handleHashChange); return () => window.removeEventListener('hashchange', handleHashChange); }, []); const isActive = (_href: string, id: string) => { if (id === 'contact') { return pathname === '/contact'; } if (pathname === '/') { const section = searchParams.get('section'); const currentSection = section || hash; if (id === 'home') { return !currentSection || currentSection === 'home'; } return currentSection === id; } return false; }; return ( ); }