feat: 重构 AppMenu 组件以使用 PanelMenu,优化菜单项生成逻辑,更新无限加载页面按钮样式,调整 Vite 插件配置
Some checks failed
/ playwright (push) Failing after 2m51s
/ depcheck (push) Successful in 1m40s
/ build-and-deploy-to-vercel (push) Successful in 1m34s

This commit is contained in:
严浩
2024-12-26 00:20:33 +08:00
parent 49e18facda
commit 1856bd4fc8
3 changed files with 22 additions and 12 deletions

View File

@ -1,17 +1,25 @@
<script setup lang="ts"> <script setup lang="ts">
import type { MenuProps } from 'primevue/menu';
import type { MenuItem } from 'primevue/menuitem'; import type { MenuItem } from 'primevue/menuitem';
import type { PanelMenuProps } from 'primevue/panelmenu';
import type { RouteRecordRaw } from 'vue-router/auto'; import type { RouteRecordRaw } from 'vue-router/auto';
import { routes } from 'vue-router/auto-routes'; 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) => { return routes.map((route, index) => {
const menuItem: MenuItem = { const menuItem: MenuItem = {
label: `${index + 1}. ${(route.name as string) || route.path}`, label: `${index + 1}. ${(route.name as string) || route.path}`,
icon: (route.meta?.icon as string) || 'pi pi-fw pi-home', icon: (route.meta?.icon as string) || 'pi pi-fw pi-home',
url: route.path, // url: route.path,
_route: route, 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) { 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); return generateMenuItems(routes);
}); });
</script> </script>
<template> <template>
<Menu :model="cmptItems" /> <PanelMenu :model="cmptItems" />
</template> </template>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View File

@ -18,7 +18,7 @@ const loadData = async (page: number) => {
</script> </script>
<template> <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]"> <Card v-for="item in list" :key="item.id" class="mb-[16px]">
<template #title>{{ item.name }}</template> <template #title>{{ item.name }}</template>
<template #content> <template #content>

View File

@ -136,11 +136,6 @@ export function Plugins() {
'https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700,900', '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 // https://github.com/condorheroblog/vite-plugin-fake-server?tab=readme-ov-file#usage
vitePluginFakeServer({ vitePluginFakeServer({
include: 'fake', include: 'fake',
@ -150,6 +145,13 @@ export function Plugins() {
); );
const _unused = () => { const _unused = () => {
plugins.push(
// https://github.com/webfansplz/vite-plugin-vue-devtools
VueDevTools({
// launchEditor: env.LAUNCH_EDITOR,
}),
);
plugins.push( plugins.push(
// https://github.com/unplugin/unplugin-vue-components/issues/664$0 // https://github.com/unplugin/unplugin-vue-components/issues/664$0
// https://github.com/VaJoy/vite-plugin-cdn-import-async$0 // https://github.com/VaJoy/vite-plugin-cdn-import-async$0