feat: 重构 AppMenu 组件以动态生成菜单项,更新路由和样式,添加返回按钮
This commit is contained in:
@ -1,7 +1,33 @@
|
||||
<script setup lang="ts"></script>
|
||||
<script setup lang="ts">
|
||||
import type { MenuProps } from 'primevue/menu';
|
||||
import type { MenuItem } from 'primevue/menuitem';
|
||||
import type { RouteRecordRaw } from 'vue-router/auto';
|
||||
import { routes } from 'vue-router/auto-routes';
|
||||
|
||||
// 递归处理路由生成菜单项
|
||||
const generateMenuItems = (routes: RouteRecordRaw[]): MenuProps['model'] => {
|
||||
return routes.map((route, index) => {
|
||||
const menuItem: MenuItem = {
|
||||
label: `${index + 1}. ${(route.name as string) || route.path}`,
|
||||
icon: (route.meta?.icon as string) || 'pi pi-fw pi-home',
|
||||
url: route.path,
|
||||
_route: route,
|
||||
};
|
||||
|
||||
if (route.children && route.children.length > 0) {
|
||||
menuItem.items = generateMenuItems(route.children);
|
||||
}
|
||||
return menuItem;
|
||||
});
|
||||
};
|
||||
|
||||
const cmptItems = computed<MenuProps['model']>(() => {
|
||||
return generateMenuItems(routes);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="border border-gray-300 rounded-lg min-h-full" flex items-center justify-center>AppMenu.vue</div>
|
||||
<Menu :model="cmptItems" />
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
|
Reference in New Issue
Block a user