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"
|
2024-07-28 06:29:05 +00:00
|
|
|
|
:active-icon="menu.activeIcon"
|
2024-05-19 13:20:42 +00:00
|
|
|
|
: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`"
|
2024-07-28 06:29:05 +00:00
|
|
|
|
:active-icon="menu.activeIcon"
|
2024-05-19 13:20:42 +00:00
|
|
|
|
: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"
|
2024-07-18 17:26:13 +00:00
|
|
|
|
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>
|