2024-02-06 fix: 修复Menu组件缩略菜单弹窗内样式不统一问题
This commit is contained in:
parent
db106834a7
commit
ff0566bb7f
@ -1,59 +1,50 @@
|
|||||||
import { ElSubMenu, ElMenuItem } from 'element-plus'
|
import { ElSubMenu, ElMenuItem } from 'element-plus'
|
||||||
import type { RouteMeta } from 'vue-router'
|
|
||||||
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'
|
||||||
|
|
||||||
export const useRenderMenuItem = (
|
const { renderMenuTitle } = useRenderMenuTitle()
|
||||||
|
|
||||||
|
export const useRenderMenuItem = () =>
|
||||||
// allRouters: AppRouteRecordRaw[] = [],
|
// allRouters: AppRouteRecordRaw[] = [],
|
||||||
menuMode: 'vertical' | 'horizontal'
|
{
|
||||||
) => {
|
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
|
||||||
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
|
return routers
|
||||||
return routers.map((v) => {
|
.filter((v) => !v.meta?.hidden)
|
||||||
const meta = (v.meta ?? {}) as RouteMeta
|
.map((v) => {
|
||||||
if (!meta.hidden) {
|
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('/')
|
||||||
|
|
||||||
const { renderMenuTitle } = useRenderMenuTitle()
|
if (
|
||||||
|
oneShowingChild &&
|
||||||
|
(!onlyOneChild?.children || onlyOneChild?.noShowingChildren) &&
|
||||||
|
!meta?.alwaysShow
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<ElMenuItem
|
||||||
|
index={onlyOneChild ? pathResolve(fullPath, onlyOneChild.path) : fullPath}
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta)
|
||||||
|
}}
|
||||||
|
</ElMenuItem>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<ElSubMenu index={fullPath}>
|
||||||
|
{{
|
||||||
|
title: () => renderMenuTitle(meta),
|
||||||
|
default: () => renderMenuItem(v.children!, fullPath)
|
||||||
|
}}
|
||||||
|
</ElSubMenu>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
return {
|
||||||
oneShowingChild &&
|
renderMenuItem
|
||||||
(!onlyOneChild?.children || onlyOneChild?.noShowingChildren) &&
|
}
|
||||||
!meta?.alwaysShow
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<ElMenuItem index={onlyOneChild ? pathResolve(fullPath, onlyOneChild.path) : fullPath}>
|
|
||||||
{{
|
|
||||||
default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta)
|
|
||||||
}}
|
|
||||||
</ElMenuItem>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
const { getPrefixCls } = useDesign()
|
|
||||||
|
|
||||||
const preFixCls = getPrefixCls('menu-popper')
|
|
||||||
return (
|
|
||||||
<ElSubMenu
|
|
||||||
index={fullPath}
|
|
||||||
popperClass={
|
|
||||||
menuMode === 'vertical' ? `${preFixCls}--vertical` : `${preFixCls}--horizontal`
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{{
|
|
||||||
title: () => renderMenuTitle(meta),
|
|
||||||
default: () => renderMenuItem(v.children!, fullPath)
|
|
||||||
}}
|
|
||||||
</ElSubMenu>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
renderMenuItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { RouteMeta } from 'vue-router'
|
import type { RouteMeta } from 'vue-router'
|
||||||
import { Icon } from '@/components/Icon'
|
import { Icon } from '@/components/Icon'
|
||||||
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
|
||||||
export const useRenderMenuTitle = () => {
|
export const useRenderMenuTitle = () => {
|
||||||
const renderMenuTitle = (meta: RouteMeta) => {
|
const renderMenuTitle = (meta: RouteMeta) => {
|
||||||
@ -9,10 +10,14 @@ export const useRenderMenuTitle = () => {
|
|||||||
return icon ? (
|
return icon ? (
|
||||||
<>
|
<>
|
||||||
<Icon icon={meta.icon}></Icon>
|
<Icon icon={meta.icon}></Icon>
|
||||||
<span class="v-menu__title">{t(title as string)}</span>
|
<span class="v-menu__title overflow-hidden overflow-ellipsis whitespace-nowrap">
|
||||||
|
{t(title as string)}
|
||||||
|
</span>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<span class="v-menu__title">{t(title as string)}</span>
|
<span class="v-menu__title overflow-hidden overflow-ellipsis whitespace-nowrap">
|
||||||
|
{t(title as string)}
|
||||||
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user