Skip to content

Commit

Permalink
支持一级菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
tangllty committed Dec 28, 2023
1 parent d6e5a20 commit c27d0b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/layout/components/Sidebar/SidebarItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div v-if="!item.meta || !item.meta.hidden">
<el-sub-menu v-if="item.children" :index="resolvePath(item.path)">
<el-sub-menu v-if="item.children && item.type === 'DIRECTORY'" :index="resolvePath(item.path)">
<template #title>
<el-icon>
<svg-icon
Expand All @@ -21,6 +21,20 @@
/>
</el-sub-menu>

<el-menu-item v-else-if="item.root && item.type === 'MENU'" :index="resolvePath(item.path)">
<template #title>
<el-icon>
<svg-icon
v-if="item.meta && item.meta.icon"
:name="item.meta.icon"
/>
</el-icon>
<span>
{{ item.meta.title }}
</span>
</template>
</el-menu-item>

<el-menu-item v-else :index="resolvePath('')">
<template #title>
<el-icon>
Expand Down
10 changes: 9 additions & 1 deletion src/store/modules/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ export const usePermissionStore = defineStore('permission', () => {
const filterAsyncRoutes = (routes: RouteRecordRaw[]): RouteRecordRaw[] => {
return routes.map((route) => {
const tempRoute: any = { ...route }
if (tempRoute.component === 'Layout') {
if (tempRoute.root) {
if (tempRoute.type === 'MENU') {
const children = {
path: tempRoute.path,
meta: tempRoute.meta,
component: tempRoute.component,
}
tempRoute.children = [children]
}
tempRoute.component = Layout
} else {
tempRoute.component = modules[`../../views/${route.component}.vue`] as any
Expand Down

0 comments on commit c27d0b4

Please sign in to comment.