From 554beaf6e79707b214fddace4795a87afb1f2c50 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 8 Feb 2020 18:30:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E4=BF=AE=E6=94=B9=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=81=B6=E5=B0=94=E6=9C=AA=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/system/role/index.vue | 12 ++++++------ .../system/controller/SysDeptController.java | 6 +++++- .../system/controller/SysMenuController.java | 7 ++++++- .../project/system/service/ISysMenuService.java | 8 ++++++++ .../system/service/impl/SysMenuServiceImpl.java | 16 ++++++++++++++-- .../resources/mybatis/system/SysMenuMapper.xml | 2 +- 6 files changed, 40 insertions(+), 11 deletions(-) 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},