admin-vben/packages/@core/ui-kit/menu-ui/src/sub-menu.vue

68 lines
1.5 KiB
Vue
Raw Normal View History

2024-05-19 13:20:42 +00:00
<script setup lang="ts">
import type { MenuRecordRaw } from '@vben-core/typings';
import { computed } from 'vue';
2024-06-08 11:49:06 +00:00
import { VbenMenuBadge } from '@vben-core/shadcn-ui';
2024-05-19 13:20:42 +00:00
import { MenuItem, SubMenu as SubMenuComp } from './components';
// eslint-disable-next-line import/no-self-import
import SubMenu from './sub-menu.vue';
interface Props {
/**
* 菜单项
*/
menu: MenuRecordRaw;
}
defineOptions({
name: 'SubMenuUi',
});
const props = withDefaults(defineProps<Props>(), {});
/**
* 判断是否有子节点动态渲染 menu-item/sub-menu-item
*/
const hasChildren = computed(() => {
const { menu } = props;
return (
Reflect.has(menu, 'children') && !!menu.children && menu.children.length > 0
);
});
</script>
<template>
<MenuItem
v-if="!hasChildren"
:key="menu.path"
:badge="menu.badge"
:badge-type="menu.badgeType"
:badge-variants="menu.badgeVariants"
2024-06-09 05:31:43 +00:00
:icon="menu.icon"
:path="menu.path"
2024-05-19 13:20:42 +00:00
>
<template #title>{{ menu.name }}</template>
</MenuItem>
<SubMenuComp
v-else
:key="`${menu.path}_sub`"
:icon="menu.icon"
2024-06-09 05:31:43 +00:00
:path="menu.path"
2024-05-19 13:20:42 +00:00
>
<template #content>
<VbenMenuBadge
:badge="menu.badge"
:badge-type="menu.badgeType"
:badge-variants="menu.badgeVariants"
class="right-6"
2024-05-19 13:20:42 +00:00
/>
</template>
<template #title>{{ menu.name }}</template>
<template v-for="childItem in menu.children || []" :key="childItem.path">
<SubMenu :menu="childItem" />
</template>
</SubMenuComp>
</template>