2024-05-19 21:20:42 +08:00
|
|
|
<script lang="ts" setup>
|
2024-07-23 00:03:59 +08:00
|
|
|
import type { MenuRecordRaw } from '@vben/types';
|
2025-01-01 11:39:49 +08:00
|
|
|
|
2024-05-19 21:20:42 +08:00
|
|
|
import type { NormalMenuProps } from '@vben-core/menu-ui';
|
|
|
|
|
2024-06-09 15:39:11 +08:00
|
|
|
import { onBeforeMount } from 'vue';
|
2024-05-19 21:20:42 +08:00
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
2024-07-23 00:03:59 +08:00
|
|
|
import { findMenuByPath } from '@vben/utils';
|
2025-01-01 11:39:49 +08:00
|
|
|
|
2024-06-08 19:49:06 +08:00
|
|
|
import { NormalMenu } from '@vben-core/menu-ui';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
|
|
interface Props extends NormalMenuProps {}
|
|
|
|
|
2024-06-09 15:39:11 +08:00
|
|
|
const props = defineProps<Props>();
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
defaultSelect: [MenuRecordRaw, MenuRecordRaw?];
|
|
|
|
enter: [MenuRecordRaw];
|
|
|
|
select: [MenuRecordRaw];
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
2024-06-09 15:39:11 +08:00
|
|
|
const menu = findMenuByPath(props.menus || [], route.path);
|
2024-05-19 21:20:42 +08:00
|
|
|
if (menu) {
|
2024-06-09 15:39:11 +08:00
|
|
|
const rootMenu = (props.menus || []).find(
|
2024-05-19 21:20:42 +08:00
|
|
|
(item) => item.path === menu.parents?.[0],
|
|
|
|
);
|
|
|
|
emit('defaultSelect', menu, rootMenu);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<NormalMenu
|
2024-06-09 13:31:43 +08:00
|
|
|
:active-path="activePath"
|
2024-05-19 21:20:42 +08:00
|
|
|
:collapse="collapse"
|
|
|
|
:menus="menus"
|
2024-06-09 13:31:43 +08:00
|
|
|
:rounded="rounded"
|
2024-05-19 21:20:42 +08:00
|
|
|
:theme="theme"
|
|
|
|
@enter="(menu) => emit('enter', menu)"
|
2024-07-18 21:59:18 +08:00
|
|
|
@select="(menu) => emit('select', menu)"
|
2024-05-19 21:20:42 +08:00
|
|
|
/>
|
|
|
|
</template>
|