import Collapse from '@/components/Collapse' import Link from 'next/link' import { useRouter } from 'next/router' import { useState } from 'react' /** * 折叠菜单 * @param {*} param0 * @returns */ export const MenuItemCollapse = ({ link }) => { const [show, changeShow] = useState(false) const hasSubMenu = link?.subMenus?.length > 0 const router = useRouter() const [isOpen, changeIsOpen] = useState(false) const toggleShow = () => { changeShow(!show) } const toggleOpenSubMenu = () => { changeIsOpen(!isOpen) } if (!link || !link.show) { return null } const selected = router.pathname === link.href || router.asPath === link.href return ( <>
{!hasSubMenu && (
{link.icon && ( )}
{link.name}
{link.slot} )} {hasSubMenu && (
{link?.name}
)}
{/* 折叠子菜单 */} {hasSubMenu && ( {link.subMenus.map((sLink, index) => { return (
{sLink.title}
) })}
)} ) }