feat: 重构 AppMenu 组件以动态生成菜单项,更新路由和样式,添加返回按钮
Some checks failed
/ build-and-deploy-to-vercel (push) Successful in 1m33s
/ playwright (push) Failing after 2m43s
/ depcheck (push) Successful in 1m35s

This commit is contained in:
严浩
2024-12-25 19:19:21 +08:00
parent 78fe5b0c37
commit eed0f4f3f4
7 changed files with 51 additions and 6 deletions

View File

@ -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>