SidebarItem.vue
1.47 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<div v-if="!(menu as any).meta?.hidden">
<!-- 有子菜单的情况 -->
<el-sub-menu
v-if="hasChildren"
:index="resolvePath"
:popper-append-to-body="false"
>
<template #title>
<el-icon v-if="menu.icon">
<component :is="menu.icon" />
</el-icon>
<span>{{ menu.menuName }}</span>
</template>
<sidebar-item
v-for="child in menu.children"
:key="child.menuId"
:menu="child"
:base-path="resolvePath"
/>
</el-sub-menu>
<!-- 没有子菜单的情况 -->
<el-menu-item
v-else
:index="resolvePath"
>
<el-icon v-if="menu.icon">
<component :is="menu.icon" />
</el-icon>
<template #title>
<span>{{ menu.menuName }}</span>
</template>
</el-menu-item>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import type { Menu } from '@/types'
interface Props {
menu: Menu
basePath: string
}
const props = defineProps<Props>()
// 是否有子菜单
const hasChildren = computed(() => {
return props.menu.children && props.menu.children.length > 0
})
// 解析路径
const resolvePath = computed(() => {
if (props.menu.path.startsWith('/')) {
return props.menu.path
}
return `${props.basePath}/${props.menu.path}`
})
</script>
<style lang="scss" scoped>
.el-menu-item,
.el-sub-menu__title {
.el-icon {
margin-right: 8px;
font-size: 16px;
}
}
</style>