mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
64 lines
1.7 KiB
Vue
64 lines
1.7 KiB
Vue
<script setup lang="ts">
|
|
import type { MenuRecordRaw } from "/@/vben/typings";
|
|
|
|
import { computed } from "vue";
|
|
|
|
import { MenuBadge, MenuItem, SubMenu as SubMenuComp } from "./components";
|
|
// eslint-disable-next-line import/no-self-import
|
|
import SubMenu from "./sub-menu.vue";
|
|
import { FsSlotRender } from "@fast-crud/fast-crud";
|
|
|
|
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"
|
|
:active-icon="menu.activeIcon"
|
|
:badge="menu.badge"
|
|
:badge-type="menu.badgeType"
|
|
:badge-variants="menu.badgeVariants"
|
|
:icon="menu.icon"
|
|
:path="menu.path"
|
|
:click="menu.meta?.click"
|
|
>
|
|
<template v-if="menu.meta?.slot" #default>
|
|
<fs-render :render-func="menu.meta.slot" />
|
|
</template>
|
|
<template v-else #title>
|
|
<span>{{ menu.name }}</span>
|
|
</template>
|
|
</MenuItem>
|
|
<SubMenuComp v-else :key="`${menu.path}_sub`" :active-icon="menu.activeIcon" :icon="menu.icon" :path="menu.path">
|
|
<template #content>
|
|
<MenuBadge :badge="menu.badge" :badge-type="menu.badgeType" :badge-variants="menu.badgeVariants" class="right-6" />
|
|
</template>
|
|
<template #title>
|
|
<span>{{ menu.name }}</span>
|
|
</template>
|
|
<template v-for="childItem in menu.children || []" :key="childItem.path">
|
|
<SubMenu :menu="childItem" />
|
|
</template>
|
|
</SubMenuComp>
|
|
</template>
|