'use client'; import { usePathname, useRouter } from 'next/navigation'; import { useCallback, useEffect, useRef } from 'react'; import { useTabStore } from '@/stores/tab-store'; /** 多页签条:与路由联动;左右滚动占位(后续可接完整滚动实现)。 */ export function TabStrip() { const router = useRouter(); const pathname = usePathname() ?? ''; const scrollRef = useRef(null); const { tabs, activeId, close, activate } = useTabStore(); useEffect(() => { if (!pathname.startsWith('/dashboard')) { return; } useTabStore.getState().syncFromPath(pathname); }, [pathname]); const onTabClick = useCallback( (id: string, path: string) => { activate(id); router.push(path); }, [activate, router], ); const scrollBy = (delta: number) => { scrollRef.current?.scrollBy({ left: delta, behavior: 'smooth' }); }; return (
{tabs.map((t) => { const isActive = activeId === t.id; return ( ); })}
); }