Skip to content

Commit d5dc4e3

Browse files
committed
fix: 修复Menu组件缩略菜单弹窗内样式不统一问题
1 parent 5440766 commit d5dc4e3

File tree

2 files changed

+44
-47
lines changed

2 files changed

+44
-47
lines changed

src/components/Menu/src/Menu.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@ export default defineComponent({
8989
backgroundColor="var(--left-menu-bg-color)"
9090
textColor="var(--left-menu-text-color)"
9191
activeTextColor="var(--left-menu-text-active-color)"
92+
popperClass={
93+
unref(menuMode) === 'vertical'
94+
? `${prefixCls}-popper--vertical`
95+
: `${prefixCls}-popper--horizontal`
96+
}
9297
onSelect={menuSelect}
9398
>
9499
{{
95100
default: () => {
96-
const { renderMenuItem } = useRenderMenuItem(unref(menuMode))
101+
const { renderMenuItem } = useRenderMenuItem()
97102
return renderMenuItem(unref(routers))
98103
}
99104
}}

src/components/Menu/src/components/useRenderMenuItem.tsx

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,49 @@ import { ElSubMenu, ElMenuItem } from 'element-plus'
22
import { hasOneShowingChild } from '../helper'
33
import { isUrl } from '@/utils/is'
44
import { useRenderMenuTitle } from './useRenderMenuTitle'
5-
import { useDesign } from '@/hooks/web/useDesign'
65
import { pathResolve } from '@/utils/routerHelper'
76

87
const { renderMenuTitle } = useRenderMenuTitle()
98

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

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()
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+
}
3646

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-
})
47+
return {
48+
renderMenuItem
49+
}
5350
}
54-
55-
return {
56-
renderMenuItem
57-
}
58-
}

0 commit comments

Comments
 (0)