diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 497fed646..49152bbaa 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -369,15 +369,15 @@ export default { /** 根据角色ID查询菜单树结构 */ getRoleMenuTreeselect(roleId) { roleMenuTreeselect(roleId).then(response => { - this.getMenuTreeselect(); - this.$refs.menu.setCheckedKeys(response.data); + this.menuOptions = response.menus; + this.$refs.menu.setCheckedKeys(response.checkedKeys); }); }, /** 根据角色ID查询部门树结构 */ getRoleDeptTreeselect(roleId) { roleDeptTreeselect(roleId).then(response => { - this.getDeptTreeselect(); - this.$refs.dept.setCheckedKeys(response.data); + this.deptOptions = response.depts; + this.$refs.dept.setCheckedKeys(response.checkedKeys); }); }, // 角色状态修改 @@ -407,8 +407,8 @@ export default { }, // 表单重置 reset() { - if (this.$refs.tree != undefined) { - this.$refs.tree.setCheckedKeys([]); + if (this.$refs.menu != undefined) { + this.$refs.menu.setCheckedKeys([]); } this.form = { roleId: undefined, diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java index e344a397d..314af5d96 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java @@ -70,7 +70,11 @@ public class SysDeptController extends BaseController @GetMapping(value = "/roleDeptTreeselect/{roleId}") public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) { - return AjaxResult.success(deptService.selectDeptListByRoleId(roleId)); + List depts = deptService.selectDeptList(new SysDept()); + AjaxResult ajax = AjaxResult.success(); + ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); + ajax.put("depts", deptService.buildDeptTreeSelect(depts)); + return ajax; } /** diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java index 1e6ce5ef3..0cb277edd 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java @@ -80,7 +80,12 @@ public class SysMenuController extends BaseController @GetMapping(value = "/roleMenuTreeselect/{roleId}") public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) { - return AjaxResult.success(menuService.selectMenuListByRoleId(roleId)); + LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + List menus = menuService.selectMenuList(loginUser.getUser().getUserId()); + AjaxResult ajax = AjaxResult.success(); + ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); + ajax.put("menus", menuService.buildMenuTreeSelect(menus)); + return ajax; } /** diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java index cb4d7b723..95f49aea1 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java @@ -13,6 +13,14 @@ import com.ruoyi.project.system.domain.vo.RouterVo; */ public interface ISysMenuService { + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + public List selectMenuList(Long userId); + /** * 根据用户查询系统菜单列表 * diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java index b8d860322..cfb85d027 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java @@ -38,6 +38,18 @@ public class SysMenuServiceImpl implements ISysMenuService @Autowired private SysRoleMenuMapper roleMenuMapper; + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + @Override + public List selectMenuList(Long userId) + { + return selectMenuList(new SysMenu(), userId); + } + /** * 查询系统菜单列表 * @@ -83,9 +95,9 @@ public class SysMenuServiceImpl implements ISysMenuService } /** - * 根据用户名称查询菜单 + * 根据用户ID查询菜单 * - * @param username 用户名称 + * @param userId 用户名称 * @return 菜单列表 */ @Override diff --git a/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml b/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml index 98aee20f0..2ed824f29 100644 --- a/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml +++ b/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml @@ -117,7 +117,7 @@ update sys_menu menu_name = #{menuName}, - parent_id = #{parentId}, + parent_id = #{parentId}, order_num = #{orderNum}, path = #{path}, component = #{component},