import { router } from '@/router'
|
import { isNavigableMenuItem } from './route'
|
const openExternalLink = (link) => {
|
window.open(link, '_blank')
|
}
|
const handleMenuJump = (item, jumpToFirst = false) => {
|
const { link, isIframe } = item.meta
|
if (link && !isIframe) {
|
return openExternalLink(link)
|
}
|
if (!jumpToFirst || !item.children?.length) {
|
return router.push(item.path)
|
}
|
const findFirstLeafMenu = (items) => {
|
for (const child of items) {
|
if (isNavigableMenuItem(child)) {
|
return child.children?.length ? findFirstLeafMenu(child.children) || child : child
|
}
|
}
|
return void 0
|
}
|
const firstChild = findFirstLeafMenu(item.children)
|
if (!firstChild) {
|
return router.push(item.path)
|
}
|
if (firstChild.meta?.link) {
|
return openExternalLink(firstChild.meta.link)
|
}
|
router.push(firstChild.path)
|
}
|
export { handleMenuJump, openExternalLink }
|