|
|
|
@ -2,57 +2,49 @@ import { ElSubMenu, ElMenuItem } from 'element-plus'
|
|
|
|
import { hasOneShowingChild } from '../helper'
|
|
|
|
import { hasOneShowingChild } from '../helper'
|
|
|
|
import { isUrl } from '@/utils/is'
|
|
|
|
import { isUrl } from '@/utils/is'
|
|
|
|
import { useRenderMenuTitle } from './useRenderMenuTitle'
|
|
|
|
import { useRenderMenuTitle } from './useRenderMenuTitle'
|
|
|
|
import { useDesign } from '@/hooks/web/useDesign'
|
|
|
|
|
|
|
|
import { pathResolve } from '@/utils/routerHelper'
|
|
|
|
import { pathResolve } from '@/utils/routerHelper'
|
|
|
|
|
|
|
|
|
|
|
|
const { renderMenuTitle } = useRenderMenuTitle()
|
|
|
|
const { renderMenuTitle } = useRenderMenuTitle()
|
|
|
|
|
|
|
|
|
|
|
|
export const useRenderMenuItem = (
|
|
|
|
export const useRenderMenuItem = () =>
|
|
|
|
// allRouters: AppRouteRecordRaw[] = [],
|
|
|
|
// allRouters: AppRouteRecordRaw[] = [],
|
|
|
|
menuMode: 'vertical' | 'horizontal'
|
|
|
|
{
|
|
|
|
) => {
|
|
|
|
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
|
|
|
|
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
|
|
|
|
return routers
|
|
|
|
return routers
|
|
|
|
.filter((v) => !v.meta?.hidden)
|
|
|
|
.filter((v) => !v.meta?.hidden)
|
|
|
|
.map((v) => {
|
|
|
|
.map((v) => {
|
|
|
|
const meta = v.meta ?? {}
|
|
|
|
const meta = v.meta ?? {}
|
|
|
|
const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v)
|
|
|
|
const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v)
|
|
|
|
const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
|
|
|
|
const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
oneShowingChild &&
|
|
|
|
oneShowingChild &&
|
|
|
|
(!onlyOneChild?.children || onlyOneChild?.noShowingChildren) &&
|
|
|
|
(!onlyOneChild?.children || onlyOneChild?.noShowingChildren) &&
|
|
|
|
!meta?.alwaysShow
|
|
|
|
!meta?.alwaysShow
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<ElMenuItem index={onlyOneChild ? pathResolve(fullPath, onlyOneChild.path) : fullPath}>
|
|
|
|
<ElMenuItem
|
|
|
|
{{
|
|
|
|
index={onlyOneChild ? pathResolve(fullPath, onlyOneChild.path) : fullPath}
|
|
|
|
default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta)
|
|
|
|
>
|
|
|
|
}}
|
|
|
|
{{
|
|
|
|
</ElMenuItem>
|
|
|
|
default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta)
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
} else {
|
|
|
|
</ElMenuItem>
|
|
|
|
const { getPrefixCls } = useDesign()
|
|
|
|
)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<ElSubMenu index={fullPath}>
|
|
|
|
|
|
|
|
{{
|
|
|
|
|
|
|
|
title: () => renderMenuTitle(meta),
|
|
|
|
|
|
|
|
default: () => renderMenuItem(v.children!, fullPath)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
</ElSubMenu>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const preFixCls = getPrefixCls('menu-popper')
|
|
|
|
return {
|
|
|
|
return (
|
|
|
|
renderMenuItem
|
|
|
|
<ElSubMenu
|
|
|
|
}
|
|
|
|
index={fullPath}
|
|
|
|
|
|
|
|
popperClass={
|
|
|
|
|
|
|
|
menuMode === 'vertical' ? `${preFixCls}--vertical` : `${preFixCls}--horizontal`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
{{
|
|
|
|
|
|
|
|
title: () => renderMenuTitle(meta),
|
|
|
|
|
|
|
|
default: () => renderMenuItem(v.children!, fullPath)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
</ElSubMenu>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
renderMenuItem
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|