parent
c9372b0a5c
commit
3bf173d744
|
@ -1,40 +0,0 @@
|
||||||
package com.ruoyi.web.controller.system;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.ruoyi.common.constant.Constants;
|
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
|
||||||
import com.ruoyi.common.core.domain.entity.SysMenu;
|
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
||||||
import com.ruoyi.common.core.domain.model.LoginBody;
|
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
|
||||||
import com.ruoyi.framework.web.service.SysLoginService;
|
|
||||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
|
||||||
import com.ruoyi.framework.web.service.TokenService;
|
|
||||||
import com.ruoyi.system.service.ISysMenuService;
|
|
||||||
|
|
||||||
|
|
||||||
public class SysLoginController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取路由信息
|
|
||||||
*
|
|
||||||
* @return 路由信息
|
|
||||||
*/
|
|
||||||
@GetMapping("getRouters")
|
|
||||||
public AjaxResult getRouters()
|
|
||||||
{
|
|
||||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
||||||
// 用户信息
|
|
||||||
SysUser user = loginUser.getUser();
|
|
||||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getUserId());
|
|
||||||
return AjaxResult.success(menuService.buildMenus(menus));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -33,8 +34,7 @@ import com.ruoyi.system.service.ISysMenuService;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/menu")
|
@RequestMapping("/system/menu")
|
||||||
public class SysMenuController extends BaseController
|
public class SysMenuController extends BaseController {
|
||||||
{
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysMenuService menuService;
|
private ISysMenuService menuService;
|
||||||
|
|
||||||
|
@ -46,8 +46,7 @@ public class SysMenuController extends BaseController
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:menu:list')")
|
@PreAuthorize("@ss.hasPermi('system:menu:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public AjaxResult list(SysMenu menu)
|
public AjaxResult list(SysMenu menu) {
|
||||||
{
|
|
||||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||||
Long userId = loginUser.getUser().getUserId();
|
Long userId = loginUser.getUser().getUserId();
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
||||||
|
@ -59,8 +58,7 @@ public class SysMenuController extends BaseController
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('system:menu:query')")
|
@PreAuthorize("@ss.hasPermi('system:menu:query')")
|
||||||
@GetMapping(value = "/{menuId}")
|
@GetMapping(value = "/{menuId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long menuId)
|
public AjaxResult getInfo(@PathVariable Long menuId) {
|
||||||
{
|
|
||||||
return AjaxResult.success(menuService.selectMenuById(menuId));
|
return AjaxResult.success(menuService.selectMenuById(menuId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +66,7 @@ public class SysMenuController extends BaseController
|
||||||
* 获取菜单下拉树列表
|
* 获取菜单下拉树列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public AjaxResult treeselect(SysMenu menu)
|
public AjaxResult treeselect(SysMenu menu) {
|
||||||
{
|
|
||||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||||
Long userId = loginUser.getUser().getUserId();
|
Long userId = loginUser.getUser().getUserId();
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
||||||
|
@ -80,8 +77,7 @@ public class SysMenuController extends BaseController
|
||||||
* 加载对应角色菜单列表树
|
* 加载对应角色菜单列表树
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||||
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId)
|
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
||||||
{
|
|
||||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||||
List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
|
List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
@ -96,15 +92,11 @@ public class SysMenuController extends BaseController
|
||||||
@PreAuthorize("@ss.hasPermi('system:menu:add')")
|
@PreAuthorize("@ss.hasPermi('system:menu:add')")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysMenu menu)
|
public AjaxResult add(@Validated @RequestBody SysMenu menu) {
|
||||||
{
|
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
|
||||||
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
|
|
||||||
{
|
|
||||||
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
||||||
}
|
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
|
||||||
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
|
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) {
|
||||||
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
|
|
||||||
{
|
|
||||||
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
||||||
}
|
}
|
||||||
menu.setCreateBy(SecurityUtils.getUsername());
|
menu.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
@ -117,19 +109,13 @@ public class SysMenuController extends BaseController
|
||||||
@PreAuthorize("@ss.hasPermi('system:menu:edit')")
|
@PreAuthorize("@ss.hasPermi('system:menu:edit')")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody SysMenu menu)
|
public AjaxResult edit(@Validated @RequestBody SysMenu menu) {
|
||||||
{
|
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
|
||||||
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
|
|
||||||
{
|
|
||||||
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
||||||
}
|
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
|
||||||
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
|
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) {
|
||||||
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
|
|
||||||
{
|
|
||||||
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
||||||
}
|
} else if (menu.getMenuId().equals(menu.getParentId())) {
|
||||||
else if (menu.getMenuId().equals(menu.getParentId()))
|
|
||||||
{
|
|
||||||
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
||||||
}
|
}
|
||||||
menu.setUpdateBy(SecurityUtils.getUsername());
|
menu.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
@ -142,14 +128,11 @@ public class SysMenuController extends BaseController
|
||||||
@PreAuthorize("@ss.hasPermi('system:menu:remove')")
|
@PreAuthorize("@ss.hasPermi('system:menu:remove')")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{menuId}")
|
@DeleteMapping("/{menuId}")
|
||||||
public AjaxResult remove(@PathVariable("menuId") Long menuId)
|
public AjaxResult remove(@PathVariable("menuId") Long menuId) {
|
||||||
{
|
if (menuService.hasChildByMenuId(menuId)) {
|
||||||
if (menuService.hasChildByMenuId(menuId))
|
|
||||||
{
|
|
||||||
return AjaxResult.error("存在子菜单,不允许删除");
|
return AjaxResult.error("存在子菜单,不允许删除");
|
||||||
}
|
}
|
||||||
if (menuService.checkMenuExistRole(menuId))
|
if (menuService.checkMenuExistRole(menuId)) {
|
||||||
{
|
|
||||||
return AjaxResult.error("菜单已分配,不允许删除");
|
return AjaxResult.error("菜单已分配,不允许删除");
|
||||||
}
|
}
|
||||||
return toAjax(menuService.deleteMenuById(menuId));
|
return toAjax(menuService.deleteMenuById(menuId));
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function login(username, password, code, uuid) {
|
||||||
// 获取用户详细信息
|
// 获取用户详细信息
|
||||||
export function getInfo() {
|
export function getInfo() {
|
||||||
return request({
|
return request({
|
||||||
url: '/get-info',
|
url: '/get-permission-info',
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import request from '@/utils/request'
|
||||||
// 获取路由
|
// 获取路由
|
||||||
export const getRouters = () => {
|
export const getRouters = () => {
|
||||||
return request({
|
return request({
|
||||||
url: '/get-routers',
|
url: '/list-menus',
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,18 +43,27 @@ const permission = {
|
||||||
// 遍历后台传来的路由字符串,转换为组件对象
|
// 遍历后台传来的路由字符串,转换为组件对象
|
||||||
function filterAsyncRouter(asyncRouterMap, isRewrite = false) {
|
function filterAsyncRouter(asyncRouterMap, isRewrite = false) {
|
||||||
return asyncRouterMap.filter(route => {
|
return asyncRouterMap.filter(route => {
|
||||||
if (isRewrite && route.children) {
|
// 将 ruoyi 后端原有耦合前端的逻辑,迁移到此处
|
||||||
route.children = filterChildren(route.children)
|
// 处理 meta 属性
|
||||||
|
route.meta = {
|
||||||
|
title: route.menuName,
|
||||||
|
icon: route.icon
|
||||||
}
|
}
|
||||||
if (route.component) {
|
// 处理 component 属性
|
||||||
// Layout ParentView 组件特殊处理
|
if (route.children) { // 父节点
|
||||||
if (route.component === 'Layout') {
|
// debugger
|
||||||
|
if (route.parentId === 0) {
|
||||||
route.component = Layout
|
route.component = Layout
|
||||||
} else if (route.component === 'ParentView') {
|
|
||||||
route.component = ParentView
|
|
||||||
} else {
|
} else {
|
||||||
|
route.component = ParentView
|
||||||
|
}
|
||||||
|
} else { // 根节点
|
||||||
route.component = loadView(route.component)
|
route.component = loadView(route.component)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filterChildren
|
||||||
|
if (isRewrite && route.children) {
|
||||||
|
route.children = filterChildren(route.children)
|
||||||
}
|
}
|
||||||
if (route.children != null && route.children && route.children.length) {
|
if (route.children != null && route.children && route.children.length) {
|
||||||
route.children = filterAsyncRouter(route.children, route, isRewrite)
|
route.children = filterAsyncRouter(route.children, route, isRewrite)
|
||||||
|
|
|
@ -9,12 +9,12 @@ Content-Type: application/json
|
||||||
"code": "1024"
|
"code": "1024"
|
||||||
}
|
}
|
||||||
|
|
||||||
### 请求 /get-info 接口 => 成功
|
### 请求 /get-permission-info 接口 => 成功
|
||||||
GET {{baseUrl}}/get-info
|
GET {{baseUrl}}/get-permission-info
|
||||||
Authorization: Bearer {{token}}
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
### 请求 /get-routers 接口 => 成功
|
### 请求 /list-menus 接口 => 成功
|
||||||
GET {{baseUrl}}/get-routers
|
GET {{baseUrl}}/list-menus
|
||||||
Authorization: Bearer {{token}}
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
### 请求 /druid/xxx 接口 => 失败 TODO 临时测试
|
### 请求 /druid/xxx 接口 => 失败 TODO 临时测试
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cn.iocoder.dashboard.modules.system.controller.auth;
|
package cn.iocoder.dashboard.modules.system.controller.auth;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetInfoRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetRouterRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.service.auth.SysAuthService;
|
import cn.iocoder.dashboard.modules.system.service.auth.SysAuthService;
|
||||||
|
@ -35,17 +35,17 @@ public class SysAuthController {
|
||||||
return success(SysAuthLoginRespVO.builder().token(token).build());
|
return success(SysAuthLoginRespVO.builder().token(token).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取登陆用户的信息")
|
@ApiOperation("获取登陆用户的权限信息")
|
||||||
@GetMapping("/get-info")
|
@GetMapping("/get-permission-info")
|
||||||
public CommonResult<SysAuthGetInfoRespVO> getInfo() {
|
public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() {
|
||||||
SysAuthGetInfoRespVO respVO = authService.getInfo(getLoginUserId(), getLoginUserRoleIds());
|
SysAuthPermissionInfoRespVO respVO = authService.getPermissionInfo(getLoginUserId(), getLoginUserRoleIds());
|
||||||
return success(respVO);
|
return success(respVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获得菜单 Vue 路由")
|
@ApiOperation("获得登陆用户的菜单列表")
|
||||||
@GetMapping("get-routers")
|
@GetMapping("list-menus")
|
||||||
public CommonResult<List<SysAuthGetRouterRespVO>> getRouters() {
|
public CommonResult<List<SysAuthMenuRespVO>> listMenus() {
|
||||||
List<SysAuthGetRouterRespVO> respVOList = authService.getRouters(getLoginUserId(), getLoginUserRoleIds());
|
List<SysAuthMenuRespVO> respVOList = authService.listMenus(getLoginUserId(), getLoginUserRoleIds());
|
||||||
return success(respVOList);
|
return success(respVOList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
package cn.iocoder.dashboard.modules.system.controller.auth.vo;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 路由配置信息
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public class SysAuthGetRouterRespVO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 菜单编号
|
|
||||||
*/
|
|
||||||
private Long menuId;
|
|
||||||
/**
|
|
||||||
* 父菜单编号
|
|
||||||
*/
|
|
||||||
private Long parentId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 路由名字
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 路由地址
|
|
||||||
*/
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否隐藏路由,当设置 true 的时候该路由不会再侧边栏出现
|
|
||||||
*/
|
|
||||||
private boolean hidden;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重定向地址,当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
|
|
||||||
*/
|
|
||||||
private String redirect;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 组件地址
|
|
||||||
*/
|
|
||||||
private String component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
|
|
||||||
*/
|
|
||||||
private Boolean alwaysShow;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 其他元素
|
|
||||||
*/
|
|
||||||
private MetaVO meta;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 子路由
|
|
||||||
*/
|
|
||||||
private List<SysAuthGetRouterRespVO> children;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public static class MetaVO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置该路由在侧边栏和面包屑中展示的名字
|
|
||||||
*/
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置该路由的图标,对应路径src/assets/icons/svg
|
|
||||||
*/
|
|
||||||
private String icon;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置为true,则不会被 <keep-alive>缓存
|
|
||||||
*/
|
|
||||||
private boolean noCache;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package cn.iocoder.dashboard.modules.system.controller.auth.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel("登陆用户的菜单信息 Response VO")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SysAuthMenuRespVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单编号
|
||||||
|
*/
|
||||||
|
private Long menuId;
|
||||||
|
/**
|
||||||
|
* 父菜单编号
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单名称
|
||||||
|
*/
|
||||||
|
private String menuName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由地址
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
/**
|
||||||
|
* 组件地址
|
||||||
|
*/
|
||||||
|
private String component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子路由
|
||||||
|
*/
|
||||||
|
private List<SysAuthMenuRespVO> children;
|
||||||
|
|
||||||
|
}
|
|
@ -9,20 +9,20 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ApiModel("获得用户信息 Resp VO")
|
@ApiModel(value = "登陆用户的权限信息 Response VO", description = "额外包括用户信息和角色列表")
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
public class SysAuthGetInfoRespVO {
|
public class SysAuthPermissionInfoRespVO {
|
||||||
|
|
||||||
@ApiModelProperty(value = "用户信息", required = true)
|
@ApiModelProperty(value = "用户信息", required = true)
|
||||||
private UserVO user;
|
private UserVO user;
|
||||||
|
|
||||||
@ApiModelProperty(value = "角色权限数组", required = true)
|
@ApiModelProperty(value = "角色标识数组", required = true)
|
||||||
private Set<String> roles;
|
private Set<String> roles;
|
||||||
|
|
||||||
@ApiModelProperty(value = "菜单权限数组", required = true)
|
@ApiModelProperty(value = "操作权限数组", required = true)
|
||||||
private Set<String> permissions;
|
private Set<String> permissions;
|
||||||
|
|
||||||
@ApiModel("用户信息 VO")
|
@ApiModel("用户信息 VO")
|
|
@ -1,17 +1,12 @@
|
||||||
package cn.iocoder.dashboard.modules.system.convert.auth;
|
package cn.iocoder.dashboard.modules.system.convert.auth;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
|
||||||
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetInfoRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetRouterRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
|
||||||
import cn.iocoder.dashboard.modules.system.enums.permission.MenuIdEnum;
|
|
||||||
import cn.iocoder.dashboard.modules.system.enums.permission.MenuTypeEnum;
|
|
||||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||||
import jodd.util.StringUtil;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
@ -21,107 +16,19 @@ import java.util.List;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysAuthConvert {
|
public interface SysAuthConvert {
|
||||||
|
|
||||||
/** Layout组件标识 */
|
|
||||||
public final static String LAYOUT = "Layout";
|
|
||||||
|
|
||||||
/** ParentView组件标识 */
|
|
||||||
public final static String PARENT_VIEW = "ParentView";
|
|
||||||
|
|
||||||
SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class);
|
SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class);
|
||||||
|
|
||||||
@Mapping(source = "updateTime", target = "updateTime", ignore = true) // 字段相同,但是含义不同,忽略
|
@Mapping(source = "updateTime", target = "updateTime", ignore = true) // 字段相同,但是含义不同,忽略
|
||||||
LoginUser convert(SysUserDO bean);
|
LoginUser convert(SysUserDO bean);
|
||||||
|
|
||||||
default SysAuthGetInfoRespVO convert(SysUserDO user, List<SysRoleDO> roleList, List<SysMenuDO> menuList) {
|
default SysAuthPermissionInfoRespVO convert(SysUserDO user, List<SysRoleDO> roleList, List<SysMenuDO> menuList) {
|
||||||
return SysAuthGetInfoRespVO.builder()
|
return SysAuthPermissionInfoRespVO.builder()
|
||||||
.user(SysAuthGetInfoRespVO.UserVO.builder().nickname(user.getNickname()).avatar(user.getAvatar()).build())
|
.user(SysAuthPermissionInfoRespVO.UserVO.builder().nickname(user.getNickname()).avatar(user.getAvatar()).build())
|
||||||
.roles(CollectionUtils.convertSet(roleList, SysRoleDO::getRoleKey))
|
.roles(CollectionUtils.convertSet(roleList, SysRoleDO::getRoleKey))
|
||||||
.permissions(CollectionUtils.convertSet(menuList, SysMenuDO::getPerms))
|
.permissions(CollectionUtils.convertSet(menuList, SysMenuDO::getPermission))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
default SysAuthGetRouterRespVO convertTreeNode(SysMenuDO menu) {
|
SysAuthMenuRespVO convertTreeNode(SysMenuDO menu);
|
||||||
SysAuthGetRouterRespVO.SysAuthGetRouterRespVOBuilder respVOBuilder = SysAuthGetRouterRespVO.builder();
|
|
||||||
respVOBuilder.menuId(menu.getMenuId()).parentId(menu.getParentId())
|
|
||||||
.hidden("1".equals(menu.getVisible())) // TODO 芋艿:需要处理
|
|
||||||
.name(getRouteName(menu)).path(menu.getPath()).component(getComponent(menu))
|
|
||||||
.meta(SysAuthGetRouterRespVO.MetaVO.builder().title(menu.getMenuName()).icon(menu.getIcon())
|
|
||||||
.noCache("1".equals(menu.getIsCache())).build())
|
|
||||||
;
|
|
||||||
return respVOBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO 芋艿:需要预处理。存储的时候
|
|
||||||
default String getRouteName(SysMenuDO menu) {
|
|
||||||
String routerName = StringUtil.capitalize(menu.getPath()); // TODO 芋艿:看看怎么去除掉
|
|
||||||
// 非外链并且是一级目录(类型为目录)
|
|
||||||
if (isMenuFrame(menu)) {
|
|
||||||
routerName = StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
return routerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为菜单内部跳转
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 是否
|
|
||||||
*/
|
|
||||||
// TODO 芋艿:思考下是不是可以重构下
|
|
||||||
default boolean isMenuFrame(SysMenuDO menu) {
|
|
||||||
return MenuIdEnum.ROOT.getId().equals(menu.getParentId())
|
|
||||||
&& MenuTypeEnum.MENU.getType().equals(menu.getMenuType())
|
|
||||||
&& CommonStatusEnum.ENABLE.getStatus().equals(menu.getIsFrame()); // TODO 芋艿:思考是不是用这个好
|
|
||||||
}
|
|
||||||
|
|
||||||
// /** // TODO 芋艿:后面重构下
|
|
||||||
// * 获取路由地址
|
|
||||||
// *
|
|
||||||
// * @param menu 菜单信息
|
|
||||||
// * @return 路由地址
|
|
||||||
// */
|
|
||||||
// default String getRouterPath(SysMenuDO menu) {
|
|
||||||
// String routerPath = menu.getPath();
|
|
||||||
// // 非外链并且是一级目录(类型为目录)
|
|
||||||
// if (MenuIdEnum.ROOT.getId().equals(menu.getParentId())
|
|
||||||
// && MenuTypeEnum.MENU.getType().equals(menu.getMenuType())
|
|
||||||
// && CommonStatusEnum.DISABLE.getStatus().equals(menu.getIsFrame())) {
|
|
||||||
// routerPath = "/" + menu.getPath();
|
|
||||||
// }
|
|
||||||
// // 非外链并且是一级目录(类型为菜单)
|
|
||||||
// else if (isMenuFrame(menu)) {
|
|
||||||
// routerPath = "/";
|
|
||||||
// }
|
|
||||||
// return routerPath;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取组件信息
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 组件信息
|
|
||||||
*/
|
|
||||||
default String getComponent(SysMenuDO menu) {
|
|
||||||
String component = LAYOUT;
|
|
||||||
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
|
|
||||||
component = menu.getComponent();
|
|
||||||
} else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
|
|
||||||
component = PARENT_VIEW;
|
|
||||||
}
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为parent_view组件
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
default boolean isParentView(SysMenuDO menu) {
|
|
||||||
return !MenuIdEnum.ROOT.getId().equals(menu.getParentId())
|
|
||||||
&& MenuTypeEnum.DIR.getType().equals(menu.getMenuType());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,27 +55,12 @@ public class SysMenuDO extends BaseDO {
|
||||||
@Size(max = 200, message = "组件路径不能超过255个字符")
|
@Size(max = 200, message = "组件路径不能超过255个字符")
|
||||||
private String component;
|
private String component;
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为外链(0是 1否)
|
|
||||||
*/
|
|
||||||
private String isFrame;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否缓存(0缓存 1不缓存)
|
|
||||||
*/
|
|
||||||
private String isCache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型(M目录 C菜单 F按钮)
|
* 类型(M目录 C菜单 F按钮)
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "菜单类型不能为空")
|
@NotBlank(message = "菜单类型不能为空")
|
||||||
private String menuType;
|
private String menuType;
|
||||||
|
|
||||||
/**
|
|
||||||
* 显示状态(0显示 1隐藏)
|
|
||||||
*/
|
|
||||||
private String visible;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单状态(0显示 1隐藏)
|
* 菜单状态(0显示 1隐藏)
|
||||||
*/
|
*/
|
||||||
|
@ -85,7 +70,7 @@ public class SysMenuDO extends BaseDO {
|
||||||
* 权限字符串
|
* 权限字符串
|
||||||
*/
|
*/
|
||||||
@Size(max = 100, message = "权限标识长度不能超过100个字符")
|
@Size(max = 100, message = "权限标识长度不能超过100个字符")
|
||||||
private String perms;
|
private String permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单图标
|
* 菜单图标
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cn.iocoder.dashboard.modules.system.service.auth;
|
package cn.iocoder.dashboard.modules.system.service.auth;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.framework.security.core.service.SecurityFrameworkService;
|
import cn.iocoder.dashboard.framework.security.core.service.SecurityFrameworkService;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetInfoRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetRouterRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -28,7 +28,7 @@ public interface SysAuthService extends SecurityFrameworkService {
|
||||||
* @param roleIds 用户拥有的角色编号数组
|
* @param roleIds 用户拥有的角色编号数组
|
||||||
* @return 用户的信息,包括角色权限和菜单权限
|
* @return 用户的信息,包括角色权限和菜单权限
|
||||||
*/
|
*/
|
||||||
SysAuthGetInfoRespVO getInfo(Long userId, Set<Long> roleIds);
|
SysAuthPermissionInfoRespVO getPermissionInfo(Long userId, Set<Long> roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得用户的菜单 Vue 路由
|
* 获得用户的菜单 Vue 路由
|
||||||
|
@ -40,6 +40,6 @@ public interface SysAuthService extends SecurityFrameworkService {
|
||||||
* @param roleIds 用户拥有的角色编号数组
|
* @param roleIds 用户拥有的角色编号数组
|
||||||
* @return 菜单 Vue 路由
|
* @return 菜单 Vue 路由
|
||||||
*/
|
*/
|
||||||
List<SysAuthGetRouterRespVO> getRouters(Long userId, Set<Long> roleIds);
|
List<SysAuthMenuRespVO> listMenus(Long userId, Set<Long> roleIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.dashboard.framework.security.config.SecurityProperties;
|
import cn.iocoder.dashboard.framework.security.config.SecurityProperties;
|
||||||
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetInfoRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthGetRouterRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert;
|
import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
|
||||||
|
@ -225,7 +225,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysAuthGetInfoRespVO getInfo(Long userId, Set<Long> roleIds) {
|
public SysAuthPermissionInfoRespVO getPermissionInfo(Long userId, Set<Long> roleIds) {
|
||||||
// 获得用户信息
|
// 获得用户信息
|
||||||
SysUserDO user = userService.getUser(userId);
|
SysUserDO user = userService.getUser(userId);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
@ -242,7 +242,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysAuthGetRouterRespVO> getRouters(Long userId, Set<Long> roleIds) {
|
public List<SysAuthMenuRespVO> listMenus(Long userId, Set<Long> roleIds) {
|
||||||
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(roleIds,
|
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(roleIds,
|
||||||
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()),
|
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()),
|
||||||
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus()));
|
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus()));
|
||||||
|
@ -250,17 +250,17 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||||
return buildRouterTree(menuList);
|
return buildRouterTree(menuList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<SysAuthGetRouterRespVO> buildRouterTree(List<SysMenuDO> menuList) {
|
private static List<SysAuthMenuRespVO> buildRouterTree(List<SysMenuDO> menuList) {
|
||||||
// 排序,保证菜单的有序性
|
// 排序,保证菜单的有序性
|
||||||
menuList.sort(Comparator.comparing(SysMenuDO::getOrderNum));
|
menuList.sort(Comparator.comparing(SysMenuDO::getOrderNum));
|
||||||
// 构建菜单树
|
// 构建菜单树
|
||||||
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
|
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
|
||||||
Map<Long, SysAuthGetRouterRespVO> treeNodeMap = new LinkedHashMap<>();
|
Map<Long, SysAuthMenuRespVO> treeNodeMap = new LinkedHashMap<>();
|
||||||
menuList.forEach(menu -> treeNodeMap.put(menu.getMenuId(), SysAuthConvert.INSTANCE.convertTreeNode(menu)));
|
menuList.forEach(menu -> treeNodeMap.put(menu.getMenuId(), SysAuthConvert.INSTANCE.convertTreeNode(menu)));
|
||||||
// 处理父子关系
|
// 处理父子关系
|
||||||
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(MenuIdEnum.ROOT.getId())).forEach((childNode) -> {
|
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(MenuIdEnum.ROOT.getId())).forEach((childNode) -> {
|
||||||
// 获得父节点
|
// 获得父节点
|
||||||
SysAuthGetRouterRespVO parentNode = treeNodeMap.get(childNode.getParentId());
|
SysAuthMenuRespVO parentNode = treeNodeMap.get(childNode.getParentId());
|
||||||
if (parentNode == null) {
|
if (parentNode == null) {
|
||||||
log.error("[buildRouterTree][resource({}) 找不到父资源({})]", childNode.getMenuId(), childNode.getParentId());
|
log.error("[buildRouterTree][resource({}) 找不到父资源({})]", childNode.getMenuId(), childNode.getParentId());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||||
private volatile Map<Long, SysMenuDO> menuCache;
|
private volatile Map<Long, SysMenuDO> menuCache;
|
||||||
/**
|
/**
|
||||||
* 权限与菜单缓存
|
* 权限与菜单缓存
|
||||||
* key:权限 {@link SysMenuDO#getPerms()}
|
* key:权限 {@link SysMenuDO#getPermission()}
|
||||||
* value:SysMenuDO 数组,因为一个权限可能对应多个 SysMenuDO 对象
|
* value:SysMenuDO 数组,因为一个权限可能对应多个 SysMenuDO 对象
|
||||||
*
|
*
|
||||||
* 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向
|
* 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向
|
||||||
|
@ -55,7 +55,7 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||||
ImmutableMultimap.Builder<String, SysMenuDO> permMenuCacheBuilder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, SysMenuDO> permMenuCacheBuilder = ImmutableMultimap.builder();
|
||||||
menuList.forEach(menuDO -> {
|
menuList.forEach(menuDO -> {
|
||||||
menuCacheBuilder.put(menuDO.getMenuId(), menuDO);
|
menuCacheBuilder.put(menuDO.getMenuId(), menuDO);
|
||||||
permMenuCacheBuilder.put(menuDO.getPerms(), menuDO);
|
permMenuCacheBuilder.put(menuDO.getPermission(), menuDO);
|
||||||
});
|
});
|
||||||
menuCache = menuCacheBuilder.build();
|
menuCache = menuCacheBuilder.build();
|
||||||
permMenuCache = permMenuCacheBuilder.build();
|
permMenuCache = permMenuCacheBuilder.build();
|
||||||
|
|
Loading…
Reference in New Issue