zhou zhou
4 小时以前 fec285d150b377d004e47f0973d298b92fe4c711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 }