zhou zhou
15 小时以前 40905cbd04c2e332cd4bc2b9e0c5b3e1da9cccfa
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { PHASE_1_COMPONENTS } from '../../router/adapters/backendMenuAdapter.js'
 
const RELEASED_COMPONENT_PATHS = new Set(Object.values(PHASE_1_COMPONENTS))
 
function isIframe(url) {
  return url.startsWith('/outside/iframe/')
}
 
const isNavigableMenuItem = (menuItem) => {
  if (!menuItem.path || !menuItem.path.trim()) {
    return false
  }
  if (!menuItem.meta?.isHide) {
    return true
  }
  return menuItem.meta?.isFullPage === true
}
const normalizePath = (path) => {
  return path.startsWith('/') ? path : `/${path}`
}
 
const hasReleasedComponent = (menuItem) => {
  if (!menuItem || typeof menuItem !== 'object') {
    return false
  }
  const componentPath = typeof menuItem.component === 'string' ? menuItem.component.trim() : ''
  return RELEASED_COMPONENT_PATHS.has(componentPath)
}
 
const getFirstMenuPath = (menuList) => {
  if (!Array.isArray(menuList) || menuList.length === 0) {
    return ''
  }
  for (const menuItem of menuList) {
    if (!isNavigableMenuItem(menuItem)) {
      continue
    }
    if (menuItem.children?.length) {
      const childPath = getFirstMenuPath(menuItem.children)
      if (childPath) {
        return childPath
      }
    }
    if (hasReleasedComponent(menuItem)) {
      return normalizePath(menuItem.path)
    }
  }
  return ''
}
export { getFirstMenuPath, isIframe, isNavigableMenuItem }