refactor: 用户拥有的菜单路由权限判断移至后台

This commit is contained in:
Ray.Hao 2024-07-11 08:19:10 +08:00
parent 5df0175e03
commit ed51889870
6 changed files with 30 additions and 27 deletions

View File

@ -22,5 +22,5 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
/** /**
* 获取菜单路由列表 * 获取菜单路由列表
*/ */
List<RouteBO> listRoutes(Set<String> routes); List<RouteBO> listRoutes(Set<String> roles);
} }

View File

@ -1,21 +1,14 @@
package com.youlai.system.model.bo; 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 com.youlai.system.enums.MenuTypeEnum;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* 路由 * 路由
*/ */
@Data @Data
public class RouteBO { public class RouteBO {
/**
*
*/
@TableId(type = IdType.AUTO)
private Long id; private Long id;
/** /**
@ -29,14 +22,19 @@ public class RouteBO {
private String name; private String name;
/** /**
* 菜单类型(1-菜单2-目录3-外链4-按钮权限) * 菜单类型(1-菜单 2-目录 3-外链 4-按钮)
*/ */
private MenuTypeEnum type; private MenuTypeEnum type;
/** /**
* 路由路径(浏览器地址栏路径) * 路由名称Vue Router 中定义的路由名称
*/ */
private String path; private String routeName;
/**
* 路由路径Vue Router 中定义的 URL 路径
*/
private String routePath;
/** /**
* 组件路径(vue页面完整路径省略.vue后缀) * 组件路径(vue页面完整路径省略.vue后缀)
@ -68,11 +66,6 @@ public class RouteBO {
*/ */
private String redirect; private String redirect;
/**
* 拥有路由的权限
*/
private List<String> roles;
/** /**
* 目录只有一个子路由是否始终显示(1: 0:) * 目录只有一个子路由是否始终显示(1: 0:)
*/ */

View File

@ -37,10 +37,15 @@ public class SysMenu{
*/ */
private MenuTypeEnum type; private MenuTypeEnum type;
/**
* 路由名称Vue Router 中定义的路由名称
*/
private String routeName;
/** /**
* 路由路径(浏览器地址栏路径) * 路由路径(浏览器地址栏路径)
*/ */
private String path; private String routePath;
/** /**
* 组件路径(vue页面完整路径省略.vue后缀) * 组件路径(vue页面完整路径省略.vue后缀)

View File

@ -11,6 +11,7 @@ import java.util.List;
@Data @Data
public class MenuVO { public class MenuVO {
@Schema(description = "菜单ID") @Schema(description = "菜单ID")
private Long id; private Long id;
@ -23,8 +24,11 @@ public class MenuVO {
@Schema(description="菜单类型") @Schema(description="菜单类型")
private MenuTypeEnum type; private MenuTypeEnum type;
@Schema(description = "路由名称")
private String routeName;
@Schema(description = "路由路径") @Schema(description = "路由路径")
private String path; private String routePath;
@Schema(description = "组件路径") @Schema(description = "组件路径")
private String component; private String component;

View File

@ -18,6 +18,7 @@ import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
public class RouteVO { public class RouteVO {
@Schema(description = "路由路径", example = "user") @Schema(description = "路由路径", example = "user")
private String path; private String path;
@ -46,9 +47,6 @@ public class RouteVO {
@Schema(description = "是否隐藏(true-是 false-否)", example = "true") @Schema(description = "是否隐藏(true-是 false-否)", example = "true")
private Boolean hidden; private Boolean hidden;
@Schema(description = "拥有路由权限的角色编码", example = "['ADMIN','ROOT']")
private List<String> roles;
@Schema(description = "【菜单】是否开启页面缓存", example = "true") @Schema(description = "【菜单】是否开启页面缓存", example = "true")
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean keepAlive; private Boolean keepAlive;

View File

@ -33,7 +33,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 菜单务实现类 * 菜单务实现类
* *
* @author Ray * @author Ray
* @since 2020/11/06 * @since 2020/11/06
@ -171,19 +171,22 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
*/ */
private RouteVO toRouteVo(RouteBO routeBO) { private RouteVO toRouteVo(RouteBO routeBO) {
RouteVO routeVO = new RouteVO(); 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}) // 根据name路由跳转 this.$router.push({name:xxx})
routeVO.setName(routeName); routeVO.setName(routeName);
// 根据path路由跳转 this.$router.push({path:xxx}) // 根据path路由跳转 this.$router.push({path:xxx})
routeVO.setPath(routeBO.getPath()); routeVO.setPath(routeBO.getRoutePath());
routeVO.setRedirect(routeBO.getRedirect()); routeVO.setRedirect(routeBO.getRedirect());
routeVO.setComponent(routeBO.getComponent()); routeVO.setComponent(routeBO.getComponent());
RouteVO.Meta meta = new RouteVO.Meta(); RouteVO.Meta meta = new RouteVO.Meta();
meta.setTitle(routeBO.getName()); meta.setTitle(routeBO.getName());
meta.setIcon(routeBO.getIcon()); meta.setIcon(routeBO.getIcon());
meta.setRoles(routeBO.getRoles());
meta.setHidden(StatusEnum.DISABLE.getValue().equals(routeBO.getVisible())); meta.setHidden(StatusEnum.DISABLE.getValue().equals(routeBO.getVisible()));
// 菜单是否开启页面缓存 // 菜单是否开启页面缓存
if (MenuTypeEnum.MENU.equals(routeBO.getType()) if (MenuTypeEnum.MENU.equals(routeBO.getType())