import { useCallback, useEffect, useRef, useState } from 'react' import Collapse from '@/components/Collapse' import { MenuBarMobile } from './MenuBarMobile' import throttle from 'lodash.throttle' import SearchInput from './SearchInput' import DarkModeButton from '@/components/DarkModeButton' import LogoBar from './LogoBar' /** * 顶部导航栏 + 菜单 * @param {} param0 * @returns */ export default function TopNavBar(props) { const { className } = props const [isOpen, changeShow] = useState(false) const collapseRef = useRef(null) let windowTop = 0 // 监听滚动 useEffect(() => { scrollTrigger() window.addEventListener('scroll', scrollTrigger) return () => { window.removeEventListener('scroll', scrollTrigger) } }, []) const throttleMs = 200 const scrollTrigger = useCallback(throttle(() => { const scrollS = window.scrollY const nav = document.querySelector('#nav-bg') // const header = document.querySelector('#top-nav') const header = document.querySelector('#container-inner') const showNav = scrollS <= windowTop || scrollS < 5 || (scrollS <= header.clientHeight)// 非首页无大图时影藏顶部 滚动条置顶时隐藏 if (!showNav) { nav && nav.classList.replace('-top-20', 'top-0') windowTop = scrollS } else { nav && nav.classList.replace('top-0', '-top-20') windowTop = scrollS } }, throttleMs) ) const toggleMenuOpen = () => { changeShow(!isOpen) } return (
{/* 图标Logo */}
{/* 移动端折叠菜单 */}
collapseRef.current?.updateCollapseHeight(param)} />
{/* 导航栏菜单 */}
{/* 搜索框、折叠按钮、仅移动端显示 */}
{isOpen ? : }
{/* 桌面端顶部菜单 */}
{/* {links && links?.map((link, index) => )} */}
) }