Skip to content

Commit ff0566b

Browse files
committed
2024-02-06 fix: 修复Menu组件缩略菜单弹窗内样式不统一问题
1 parent db10683 commit ff0566b

File tree

2 files changed

+47
-51
lines changed

2 files changed

+47
-51
lines changed
Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,50 @@
11
import { ElSubMenu, ElMenuItem } from 'element-plus'
2-
import type { RouteMeta } from 'vue-router'
32
import { hasOneShowingChild } from '../helper'
43
import { isUrl } from '@/utils/is'
54
import { useRenderMenuTitle } from './useRenderMenuTitle'
6-
import { useDesign } from '@/hooks/web/useDesign'
75
import { pathResolve } from '@/utils/routerHelper'
86

9-
export const useRenderMenuItem = (
10-
// allRouters: AppRouteRecordRaw[] = [],
11-
menuMode: 'vertical' | 'horizontal'
12-
) => {
13-
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
14-
return routers.map((v) => {
15-
const meta = (v.meta ?? {}) as RouteMeta
16-
if (!meta.hidden) {
17-
const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v)
18-
const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
19-
20-
const { renderMenuTitle } = useRenderMenuTitle()
7+
const { renderMenuTitle } = useRenderMenuTitle()
218

22-
if (
23-
oneShowingChild &&
24-
(!onlyOneChild?.children || onlyOneChild?.noShowingChildren) &&
25-
!meta?.alwaysShow
26-
) {
27-
return (
28-
<ElMenuItem index={onlyOneChild ? pathResolve(fullPath, onlyOneChild.path) : fullPath}>
29-
{{
30-
default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta)
31-
}}
32-
</ElMenuItem>
33-
)
34-
} else {
35-
const { getPrefixCls } = useDesign()
9+
export const useRenderMenuItem = () =>
10+
// allRouters: AppRouteRecordRaw[] = [],
11+
{
12+
const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => {
13+
return routers
14+
.filter((v) => !v.meta?.hidden)
15+
.map((v) => {
16+
const meta = v.meta ?? {}
17+
const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v)
18+
const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath<AppRouteRecordRaw>(allRouters, v.path).join('/')
3619

37-
const preFixCls = getPrefixCls('menu-popper')
38-
return (
39-
<ElSubMenu
40-
index={fullPath}
41-
popperClass={
42-
menuMode === 'vertical' ? `${preFixCls}--vertical` : `${preFixCls}--horizontal`
43-
}
44-
>
45-
{{
46-
title: () => renderMenuTitle(meta),
47-
default: () => renderMenuItem(v.children!, fullPath)
48-
}}
49-
</ElSubMenu>
50-
)
51-
}
52-
}
53-
})
54-
}
20+
if (
21+
oneShowingChild &&
22+
(!onlyOneChild?.children || onlyOneChild?.noShowingChildren) &&
23+
!meta?.alwaysShow
24+
) {
25+
return (
26+
<ElMenuItem
27+
index={onlyOneChild ? pathResolve(fullPath, onlyOneChild.path) : fullPath}
28+
>
29+
{{
30+
default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta)
31+
}}
32+
</ElMenuItem>
33+
)
34+
} else {
35+
return (
36+
<ElSubMenu index={fullPath}>
37+
{{
38+
title: () => renderMenuTitle(meta),
39+
default: () => renderMenuItem(v.children!, fullPath)
40+
}}
41+
</ElSubMenu>
42+
)
43+
}
44+
})
45+
}
5546

56-
return {
57-
renderMenuItem
47+
return {
48+
renderMenuItem
49+
}
5850
}
59-
}

src/layout/components/Menu/src/components/useRenderMenuTitle.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { RouteMeta } from 'vue-router'
22
import { Icon } from '@/components/Icon'
3+
import { useI18n } from '@/hooks/web/useI18n'
34

45
export const useRenderMenuTitle = () => {
56
const renderMenuTitle = (meta: RouteMeta) => {
@@ -9,10 +10,14 @@ export const useRenderMenuTitle = () => {
910
return icon ? (
1011
<>
1112
<Icon icon={meta.icon}></Icon>
12-
<span class="v-menu__title">{t(title as string)}</span>
13+
<span class="v-menu__title overflow-hidden overflow-ellipsis whitespace-nowrap">
14+
{t(title as string)}
15+
</span>
1316
</>
1417
) : (
15-
<span class="v-menu__title">{t(title as string)}</span>
18+
<span class="v-menu__title overflow-hidden overflow-ellipsis whitespace-nowrap">
19+
{t(title as string)}
20+
</span>
1621
)
1722
}
1823

0 commit comments

Comments
 (0)