From ab0851d43992f3e33a4299317fb82276fa050ea7 Mon Sep 17 00:00:00 2001 From: hxr <1490493387@qq.com> Date: Sun, 22 Oct 2023 00:05:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=AE=E5=BD=95=E5=9C=A8=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AD=90=E8=B7=AF=E7=94=B1=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E6=98=AF=E5=90=A6=E5=A7=8B=E7=BB=88=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: fcbd963b9c74b7bdf09c59420bd62ad2bf2592bd --- src/api/menu/types.ts | 9 ++ src/layout/components/Sidebar/SidebarItem.vue | 67 +++++----- src/router/index.ts | 1 + src/views/system/menu/index.vue | 118 +++++++++++------- 4 files changed, 119 insertions(+), 76 deletions(-) diff --git a/src/api/menu/types.ts b/src/api/menu/types.ts index 2ba6c21d..38101e8a 100644 --- a/src/api/menu/types.ts +++ b/src/api/menu/types.ts @@ -112,4 +112,13 @@ export interface MenuForm { * 权限标识 */ perm?: string; + /** + * 【菜单】是否开启页面缓存 + */ + keepAlive?: number; + + /** + * 【目录】只有一个子路由是否始终显示 + */ + alwaysShow?: number; } diff --git a/src/layout/components/Sidebar/SidebarItem.vue b/src/layout/components/Sidebar/SidebarItem.vue index 32a853f1..980dee69 100644 --- a/src/layout/components/Sidebar/SidebarItem.vue +++ b/src/layout/components/Sidebar/SidebarItem.vue @@ -3,12 +3,11 @@ import path from "path-browserify"; import { isExternal } from "@/utils/index"; import AppLink from "./Link.vue"; -import { translateRouteTitleI18n } from "@/utils/i18n"; -import SvgIcon from "@/components/SvgIcon/index.vue"; +import Item from "./Item.vue"; const props = defineProps({ /** - * 路由(eg:level_3_1) + * 路由(eg:user) */ item: { type: Object, @@ -16,12 +15,16 @@ const props = defineProps({ }, /** - * 父层级完整路由路径(eg:/level/level_3/level_3_1) + * 父层级完整路由路径(eg:/system) */ basePath: { type: String, required: true, }, + isNest: { + type: Boolean, + default: false, + }, }); const onlyOneChild = ref(); // 临时变量,唯一子路由 @@ -36,32 +39,33 @@ const onlyOneChild = ref(); // 临时变量,唯一子路由 * @param parent 当前路由 */ function hasOneShowingChild(children = [], parent: any) { - // 需要显示的子路由数组 + // 子路由集合 const showingChildren = children.filter((item: any) => { if (item.meta?.hidden) { - return false; // 过滤不显示的子路由 + // 过滤不显示的子路由 + return false; } else { - onlyOneChild.value = item; // 唯一子路由赋值(多个子路由情况 onlyOneChild 变量是用不上的) + // 临时变量(多个子路由 onlyOneChild 变量是用不上的) + onlyOneChild.value = item; return true; } }); - // 1:如果只有一个子路由, 返回 true + // 如果只有一个子路由, 返回 true if (showingChildren.length === 1) { return true; } - // 2:如果无子路由, 复制当前路由信息作为其子路由,满足只拥有一个子路由的条件,所以返回 true + // 如果没有子路由,显示父级路由 if (showingChildren.length === 0) { onlyOneChild.value = { ...parent, path: "", noShowingChildren: true }; - return true; } return false; } /** - * 解析路径 + * 解析路由路径(相对路径 → 绝对路径) * * @param routePath 路由路径 */ @@ -73,53 +77,48 @@ function resolvePath(routePath: string) { return props.basePath; } - // 完整路径 = 父级路径(/level/level_3) + 路由路径 - const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径 + // 完整路径(/system/user) = 父级路径(/system) + 路由路径(user) + const fullPath = path.resolve(props.basePath, routePath); return fullPath; }