diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java index c15c9e6c1..2f9bcb08c 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java @@ -37,6 +37,12 @@ public class SysRole extends BaseEntity @Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限") private String dataScope; + /** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */ + private boolean menuCheckStrictly; + + /** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */ + private boolean deptCheckStrictly; + /** 角色状态(0正常 1停用) */ @Excel(name = "角色状态", readConverterExp = "0=正常,1=停用") private String status; @@ -128,6 +134,26 @@ public class SysRole extends BaseEntity this.dataScope = dataScope; } + public boolean isMenuCheckStrictly() + { + return menuCheckStrictly; + } + + public void setMenuCheckStrictly(boolean menuCheckStrictly) + { + this.menuCheckStrictly = menuCheckStrictly; + } + + public boolean isDeptCheckStrictly() + { + return deptCheckStrictly; + } + + public void setDeptCheckStrictly(boolean deptCheckStrictly) + { + this.deptCheckStrictly = deptCheckStrictly; + } + public String getStatus() { return status; @@ -185,6 +211,8 @@ public class SysRole extends BaseEntity .append("roleKey", getRoleKey()) .append("roleSort", getRoleSort()) .append("dataScope", getDataScope()) + .append("menuCheckStrictly", isMenuCheckStrictly()) + .append("deptCheckStrictly", isDeptCheckStrictly()) .append("status", getStatus()) .append("delFlag", getDelFlag()) .append("createBy", getCreateBy()) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index 7a2433a3e..db7cbf8e6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -25,9 +25,10 @@ public interface SysDeptMapper * 根据角色ID查询部门树信息 * * @param roleId 角色ID + * @param deptCheckStrictly 部门树选择项是否关联显示 * @return 选中部门列表 */ - public List selectDeptListByRoleId(Long roleId); + public List selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); /** * 根据部门ID查询信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java index 62b545b17..d1ef73e22 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java @@ -63,9 +63,10 @@ public interface SysMenuMapper * 根据角色ID查询菜单树信息 * * @param roleId 角色ID + * @param menuCheckStrictly 菜单树选择项是否关联显示 * @return 选中菜单列表 */ - public List selectMenuListByRoleId(Long roleId); + public List selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly); /** * 根据菜单ID查询信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 6197c9371..7f23a5b2c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -4,17 +4,17 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.exception.CustomException; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.system.api.domain.SysDept; +import com.ruoyi.system.api.domain.SysRole; import com.ruoyi.system.domain.vo.TreeSelect; import com.ruoyi.system.mapper.SysDeptMapper; +import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysDeptService; /** @@ -28,6 +28,9 @@ public class SysDeptServiceImpl implements ISysDeptService @Autowired private SysDeptMapper deptMapper; + @Autowired + private SysRoleMapper roleMapper; + /** * 查询部门管理数据 * @@ -95,7 +98,8 @@ public class SysDeptServiceImpl implements ISysDeptService @Override public List selectDeptListByRoleId(Long roleId) { - return deptMapper.selectDeptListByRoleId(roleId); + SysRole role = roleMapper.selectRoleById(roleId); + return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index afe94f12e..ecba62cbd 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -13,12 +13,14 @@ import org.springframework.stereotype.Service; import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.system.api.domain.SysRole; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.domain.SysMenu; import com.ruoyi.system.domain.vo.MetaVo; import com.ruoyi.system.domain.vo.RouterVo; import com.ruoyi.system.domain.vo.TreeSelect; import com.ruoyi.system.mapper.SysMenuMapper; +import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.mapper.SysRoleMenuMapper; import com.ruoyi.system.service.ISysMenuService; @@ -35,6 +37,9 @@ public class SysMenuServiceImpl implements ISysMenuService @Autowired private SysMenuMapper menuMapper; + @Autowired + private SysRoleMapper roleMapper; + @Autowired private SysRoleMenuMapper roleMenuMapper; @@ -124,7 +129,8 @@ public class SysMenuServiceImpl implements ISysMenuService @Override public List selectMenuListByRoleId(Long roleId) { - return menuMapper.selectMenuListByRoleId(roleId); + SysRole role = roleMapper.selectRoleById(roleId); + return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index ffd510127..f8cdf67c4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -44,12 +44,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by d.parent_id, d.order_num - + select d.dept_id from sys_dept d left join sys_role_dept rd on d.dept_id = rd.dept_id where rd.role_id = #{roleId} - and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId}) + + and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId}) + order by d.parent_id, d.order_num diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index 83d161e2b..051eea4b7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -82,12 +82,14 @@ order by m.parent_id, m.order_num - + select m.menu_id from sys_menu m left join sys_role_menu rm on m.menu_id = rm.menu_id where rm.role_id = #{roleId} - and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id = rm.menu_id and rm.role_id = #{roleId}) + + and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id = rm.menu_id and rm.role_id = #{roleId}) + order by m.parent_id, m.order_num diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml index c2b30499d..9d00caa83 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -5,22 +5,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - - - - - - - - + + + + + + + + + + + + + + - select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, + select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly, r.status, r.del_flag, r.create_time, r.remark from sys_role r left join sys_user_role ur on ur.role_id = r.role_id @@ -95,6 +97,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" role_key, role_sort, data_scope, + menu_check_strictly, + dept_check_strictly, status, remark, create_by, @@ -105,6 +109,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{roleKey}, #{roleSort}, #{dataScope}, + #{menuCheckStrictly}, + #{deptCheckStrictly}, #{status}, #{remark}, #{createBy}, @@ -119,6 +125,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" role_key = #{roleKey}, role_sort = #{roleSort}, data_scope = #{dataScope}, + menu_check_strictly = #{menuCheckStrictly}, + dept_check_strictly = #{deptCheckStrictly}, status = #{status}, remark = #{remark}, update_by = #{updateBy}, diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 8757bdeca..937b887d5 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -175,11 +175,16 @@ + 展开/折叠 + 全选/全不选 + 父子联动 @@ -214,12 +219,17 @@ + 展开/折叠 + 全选/全不选 + 父子联动 @@ -262,6 +272,10 @@ export default { open: false, // 是否显示弹出层(数据权限) openDataScope: false, + menuExpand: false, + menuNodeAll: false, + deptExpand: true, + deptNodeAll: false, // 日期范围 dateRange: [], // 状态数据字典 @@ -413,6 +427,10 @@ export default { if (this.$refs.menu != undefined) { this.$refs.menu.setCheckedKeys([]); } + this.menuExpand = false, + this.menuNodeAll = false, + this.deptExpand = true, + this.deptNodeAll = false, this.form = { roleId: undefined, roleName: undefined, @@ -421,6 +439,8 @@ export default { status: "0", menuIds: [], deptIds: [], + menuCheckStrictly: true, + deptCheckStrictly: true, remark: undefined }; this.resetForm("form"); @@ -441,6 +461,36 @@ export default { this.ids = selection.map(item => item.roleId) this.single = selection.length!=1 this.multiple = !selection.length + }, + // 树权限(展开/折叠) + handleCheckedTreeExpand(value, type) { + if (type == 'menu') { + let treeList = this.menuOptions; + for (let i = 0; i < treeList.length; i++) { + this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value; + } + } else if (type == 'dept') { + let treeList = this.deptOptions; + for (let i = 0; i < treeList.length; i++) { + this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value; + } + } + }, + // 树权限(全选/全不选) + handleCheckedTreeNodeAll(value, type) { + if (type == 'menu') { + this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []); + } else if (type == 'dept') { + this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []); + } + }, + // 树权限(父子联动) + handleCheckedTreeConnect(value, type) { + if (type == 'menu') { + this.form.menuCheckStrictly = value ? true: false; + } else if (type == 'dept') { + this.form.deptCheckStrictly = value ? true: false; + } }, /** 新增按钮操作 */ handleAdd() { diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index 7148a4e3f..af148302c 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -209,7 +209,7 @@ - + diff --git a/sql/ry_20200901.sql b/sql/ry_20200921.sql similarity index 96% rename from sql/ry_20200901.sql rename to sql/ry_20200921.sql index a9e323011..16ee42d19 100644 --- a/sql/ry_20200901.sql +++ b/sql/ry_20200921.sql @@ -102,26 +102,28 @@ insert into sys_post values(4, 'user', '普通员工', 4, '0', 'admin', '2018-0 -- ---------------------------- drop table if exists sys_role; create table sys_role ( - role_id bigint(20) not null auto_increment comment '角色ID', - role_name varchar(30) not null comment '角色名称', - role_key varchar(100) not null comment '角色权限字符串', - role_sort int(4) not null comment '显示顺序', - data_scope char(1) default '1' comment '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)', - status char(1) not null comment '角色状态(0正常 1停用)', - del_flag char(1) default '0' comment '删除标志(0代表存在 2代表删除)', - create_by varchar(64) default '' comment '创建者', - create_time datetime comment '创建时间', - update_by varchar(64) default '' comment '更新者', - update_time datetime comment '更新时间', - remark varchar(500) default null comment '备注', + role_id bigint(20) not null auto_increment comment '角色ID', + role_name varchar(30) not null comment '角色名称', + role_key varchar(100) not null comment '角色权限字符串', + role_sort int(4) not null comment '显示顺序', + data_scope char(1) default '1' comment '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)', + menu_check_strictly tinyint(1) default 1 comment '菜单树选择项是否关联显示', + dept_check_strictly tinyint(1) default 1 comment '部门树选择项是否关联显示', + status char(1) not null comment '角色状态(0正常 1停用)', + del_flag char(1) default '0' comment '删除标志(0代表存在 2代表删除)', + create_by varchar(64) default '' comment '创建者', + create_time datetime comment '创建时间', + update_by varchar(64) default '' comment '更新者', + update_time datetime comment '更新时间', + remark varchar(500) default null comment '备注', primary key (role_id) ) engine=innodb auto_increment=100 comment = '角色信息表'; -- ---------------------------- -- 初始化-角色信息表数据 -- ---------------------------- -insert into sys_role values('1', '超级管理员', 'admin', 1, 1, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '超级管理员'); -insert into sys_role values('2', '普通角色', 'common', 2, 2, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '普通角色'); +insert into sys_role values('1', '超级管理员', 'admin', 1, 1, 1, 1, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '超级管理员'); +insert into sys_role values('2', '普通角色', 'common', 2, 2, 1, 1, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '普通角色'); -- ----------------------------