From ed518898702ba56bfdd08f393b8450d40983d961 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Thu, 11 Jul 2024 08:19:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=94=A8=E6=88=B7=E6=8B=A5?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E8=8F=9C=E5=8D=95=E8=B7=AF=E7=94=B1=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=88=A4=E6=96=AD=E7=A7=BB=E8=87=B3=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../youlai/system/mapper/SysMenuMapper.java | 2 +- .../com/youlai/system/model/bo/RouteBO.java | 25 +++++++------------ .../youlai/system/model/entity/SysMenu.java | 7 +++++- .../com/youlai/system/model/vo/MenuVO.java | 6 ++++- .../com/youlai/system/model/vo/RouteVO.java | 4 +-- .../service/impl/SysMenuServiceImpl.java | 13 ++++++---- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/mapper/SysMenuMapper.java b/youlai-system/system-boot/src/main/java/com/youlai/system/mapper/SysMenuMapper.java index 7f16f7e8a..9ded2edfd 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/mapper/SysMenuMapper.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/mapper/SysMenuMapper.java @@ -22,5 +22,5 @@ public interface SysMenuMapper extends BaseMapper { /** * 获取菜单路由列表 */ - List listRoutes(Set routes); + List listRoutes(Set roles); } diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/model/bo/RouteBO.java b/youlai-system/system-boot/src/main/java/com/youlai/system/model/bo/RouteBO.java index 54700e4bf..eb99812c4 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/model/bo/RouteBO.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/model/bo/RouteBO.java @@ -1,21 +1,14 @@ package com.youlai.system.model.bo; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import com.youlai.system.enums.MenuTypeEnum; import lombok.Data; -import java.util.List; - /** * 路由 */ @Data public class RouteBO { - /** - * - */ - @TableId(type = IdType.AUTO) + private Long id; /** @@ -29,14 +22,19 @@ public class RouteBO { private String name; /** - * 菜单类型(1-菜单;2-目录;3-外链;4-按钮权限) + * 菜单类型(1-菜单 2-目录 3-外链 4-按钮) */ private MenuTypeEnum type; /** - * 路由路径(浏览器地址栏路径) + * 路由名称(Vue Router 中定义的路由名称) */ - private String path; + private String routeName; + + /** + * 路由路径(Vue Router 中定义的 URL 路径) + */ + private String routePath; /** * 组件路径(vue页面完整路径,省略.vue后缀) @@ -68,11 +66,6 @@ public class RouteBO { */ private String redirect; - /** - * 拥有路由的权限 - */ - private List roles; - /** * 【目录】只有一个子路由是否始终显示(1:是 0:否) */ diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/model/entity/SysMenu.java b/youlai-system/system-boot/src/main/java/com/youlai/system/model/entity/SysMenu.java index d4a879373..925b4df5f 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/model/entity/SysMenu.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/model/entity/SysMenu.java @@ -37,10 +37,15 @@ public class SysMenu{ */ private MenuTypeEnum type; +/** + * 路由名称(Vue Router 中定义的路由名称) + */ + private String routeName; + /** * 路由路径(浏览器地址栏路径) */ - private String path; + private String routePath; /** * 组件路径(vue页面完整路径,省略.vue后缀) diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/MenuVO.java b/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/MenuVO.java index 72ed36c92..909ef2225 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/MenuVO.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/MenuVO.java @@ -11,6 +11,7 @@ import java.util.List; @Data public class MenuVO { + @Schema(description = "菜单ID") private Long id; @@ -23,8 +24,11 @@ public class MenuVO { @Schema(description="菜单类型") private MenuTypeEnum type; + @Schema(description = "路由名称") + private String routeName; + @Schema(description = "路由路径") - private String path; + private String routePath; @Schema(description = "组件路径") private String component; diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/RouteVO.java b/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/RouteVO.java index a0045e9f5..2cd56201e 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/RouteVO.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/model/vo/RouteVO.java @@ -18,6 +18,7 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class RouteVO { + @Schema(description = "路由路径", example = "user") private String path; @@ -46,9 +47,6 @@ public class RouteVO { @Schema(description = "是否隐藏(true-是 false-否)", example = "true") private Boolean hidden; - @Schema(description = "拥有路由权限的角色编码", example = "['ADMIN','ROOT']") - private List roles; - @Schema(description = "【菜单】是否开启页面缓存", example = "true") @JsonInclude(JsonInclude.Include.NON_NULL) private Boolean keepAlive; diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysMenuServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysMenuServiceImpl.java index cf8b98a73..2df80e3aa 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysMenuServiceImpl.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysMenuServiceImpl.java @@ -33,7 +33,7 @@ import java.util.*; import java.util.stream.Collectors; /** - * 菜单业务实现类 + * 菜单服务实现类 * * @author Ray * @since 2020/11/06 @@ -171,19 +171,22 @@ public class SysMenuServiceImpl extends ServiceImpl impl */ private RouteVO toRouteVo(RouteBO routeBO) { RouteVO routeVO = new RouteVO(); - // 路由名称 将path转换为驼峰命名 user => User - String routeName = StringUtils.capitalize(StrUtil.toCamelCase(routeBO.getPath(), '-')); + // 获取路由名称 + String routeName = routeBO.getRouteName(); + if (StrUtil.isBlank(routeName)) { + // 路由 name 需要驼峰,首字母大写 + routeName = StringUtils.capitalize(StrUtil.toCamelCase(routeBO.getRoutePath(), '-')); + } // 根据name路由跳转 this.$router.push({name:xxx}) routeVO.setName(routeName); // 根据path路由跳转 this.$router.push({path:xxx}) - routeVO.setPath(routeBO.getPath()); + routeVO.setPath(routeBO.getRoutePath()); routeVO.setRedirect(routeBO.getRedirect()); routeVO.setComponent(routeBO.getComponent()); RouteVO.Meta meta = new RouteVO.Meta(); meta.setTitle(routeBO.getName()); meta.setIcon(routeBO.getIcon()); - meta.setRoles(routeBO.getRoles()); meta.setHidden(StatusEnum.DISABLE.getValue().equals(routeBO.getVisible())); // 【菜单】是否开启页面缓存 if (MenuTypeEnum.MENU.equals(routeBO.getType())