feat: 重构 AppMenu 组件以使用 PanelMenu,优化菜单项生成逻辑,更新无限加载页面按钮样式,调整 Vite 插件配置
This commit is contained in:
@ -1,17 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import type { MenuProps } from 'primevue/menu';
|
||||
import type { MenuItem } from 'primevue/menuitem';
|
||||
import type { PanelMenuProps } from 'primevue/panelmenu';
|
||||
import type { RouteRecordRaw } from 'vue-router/auto';
|
||||
import { routes } from 'vue-router/auto-routes';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 递归处理路由生成菜单项
|
||||
const generateMenuItems = (routes: RouteRecordRaw[]): MenuProps['model'] => {
|
||||
const generateMenuItems = (routes: RouteRecordRaw[]): PanelMenuProps['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,
|
||||
// url: route.path,
|
||||
command: route.children?.length
|
||||
? undefined
|
||||
: () => {
|
||||
console.debug(`route :>> `, route);
|
||||
router.push(route);
|
||||
},
|
||||
// _route_info_: JSON.parse(JSON.stringify(route)),
|
||||
};
|
||||
|
||||
if (route.children && route.children.length > 0) {
|
||||
@ -21,13 +29,13 @@ const generateMenuItems = (routes: RouteRecordRaw[]): MenuProps['model'] => {
|
||||
});
|
||||
};
|
||||
|
||||
const cmptItems = computed<MenuProps['model']>(() => {
|
||||
const cmptItems = computed(() => {
|
||||
return generateMenuItems(routes);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Menu :model="cmptItems" />
|
||||
<PanelMenu :model="cmptItems" />
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
|
@ -18,7 +18,7 @@ const loadData = async (page: number) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Button label="刷新" @click="list.splice(0, list.length) && $refs.infiniteLoading?.refresh()" />
|
||||
<Button label="刷新" @click="list.splice(0, list.length) && $refs.infiniteLoading?.refresh()" mb-4 />
|
||||
<Card v-for="item in list" :key="item.id" class="mb-[16px]">
|
||||
<template #title>{{ item.name }}</template>
|
||||
<template #content>
|
||||
|
@ -136,11 +136,6 @@ export function Plugins() {
|
||||
'https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700,900',
|
||||
]),
|
||||
|
||||
// https://github.com/webfansplz/vite-plugin-vue-devtools
|
||||
VueDevTools({
|
||||
// launchEditor: env.LAUNCH_EDITOR,
|
||||
}),
|
||||
|
||||
// https://github.com/condorheroblog/vite-plugin-fake-server?tab=readme-ov-file#usage
|
||||
vitePluginFakeServer({
|
||||
include: 'fake',
|
||||
@ -150,6 +145,13 @@ export function Plugins() {
|
||||
);
|
||||
|
||||
const _unused = () => {
|
||||
plugins.push(
|
||||
// https://github.com/webfansplz/vite-plugin-vue-devtools
|
||||
VueDevTools({
|
||||
// launchEditor: env.LAUNCH_EDITOR,
|
||||
}),
|
||||
);
|
||||
|
||||
plugins.push(
|
||||
// https://github.com/unplugin/unplugin-vue-components/issues/664$0
|
||||
// https://github.com/VaJoy/vite-plugin-cdn-import-async$0
|
||||
|
Reference in New Issue
Block a user