菜单&数据权限新增(展开/折叠 全选/全不选 父子联动)
| | |
| | | @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;
|
| | |
| | | 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;
|
| | |
| | | * æ ¹æ®è§è²IDæ¥è¯¢é¨é¨æ ä¿¡æ¯
|
| | | *
|
| | | * @param roleId è§è²ID
|
| | | * @param deptCheckStrictly é¨é¨æ 鿩项æ¯å¦å
³èæ¾ç¤º
|
| | | * @return éä¸é¨é¨å表
|
| | | */
|
| | | public List<Integer> selectDeptListByRoleId(Long roleId);
|
| | | public List<Integer> selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
|
| | |
|
| | | /**
|
| | | * æ ¹æ®é¨é¨IDæ¥è¯¢ä¿¡æ¯
|
| | |
| | |
|
| | | /**
|
| | | * æ ¹æ®è§è²IDæ¥è¯¢èåæ ä¿¡æ¯
|
| | | *
|
| | | * |
| | | * @param roleId è§è²ID
|
| | | * @param menuCheckStrictly èåæ éæ©é¡¹æ¯å¦å
³èæ¾ç¤º
|
| | | * @return éä¸èåå表
|
| | | */
|
| | | public List<Integer> selectMenuListByRoleId(Long roleId);
|
| | | public List<Integer> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly);
|
| | |
|
| | | /**
|
| | | * æ ¹æ®èåIDæ¥è¯¢ä¿¡æ¯
|
| | |
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.TreeSelect;
|
| | | import com.ruoyi.common.core.domain.entity.SysDept;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.system.mapper.SysDeptMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMapper;
|
| | | import com.ruoyi.system.service.ISysDeptService;
|
| | |
|
| | | /**
|
| | |
| | | {
|
| | | @Autowired
|
| | | private SysDeptMapper deptMapper;
|
| | |
|
| | | @Autowired
|
| | | private SysRoleMapper roleMapper;
|
| | |
|
| | | /**
|
| | | * æ¥è¯¢é¨é¨ç®¡çæ°æ®
|
| | |
| | | @Override
|
| | | public List<Integer> selectDeptListByRoleId(Long roleId)
|
| | | {
|
| | | return deptMapper.selectDeptListByRoleId(roleId);
|
| | | SysRole role = roleMapper.selectRoleById(roleId);
|
| | | return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.TreeSelect;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.system.domain.vo.MetaVo;
|
| | | import com.ruoyi.system.domain.vo.RouterVo;
|
| | | import com.ruoyi.system.mapper.SysMenuMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
| | | import com.ruoyi.system.service.ISysMenuService;
|
| | |
|
| | |
| | |
|
| | | @Autowired
|
| | | private SysMenuMapper menuMapper;
|
| | |
|
| | | @Autowired
|
| | | private SysRoleMapper roleMapper;
|
| | |
|
| | | @Autowired
|
| | | private SysRoleMenuMapper roleMenuMapper;
|
| | |
| | | @Override
|
| | | public List<Integer> selectMenuListByRoleId(Long roleId)
|
| | | {
|
| | | return menuMapper.selectMenuListByRoleId(roleId);
|
| | | SysRole role = roleMapper.selectRoleById(roleId);
|
| | | return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | order by d.parent_id, d.order_num
|
| | | </select>
|
| | |
|
| | | <select id="selectDeptListByRoleId" parameterType="Long" resultType="Integer">
|
| | | select d.dept_id, d.parent_id
|
| | | <select id="selectDeptListByRoleId" resultType="Integer">
|
| | | 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})
|
| | | <if test="deptCheckStrictly">
|
| | | 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})
|
| | | </if>
|
| | | order by d.parent_id, d.order_num
|
| | | </select>
|
| | |
|
| | |
| | | order by m.parent_id, m.order_num
|
| | | </select>
|
| | |
|
| | | <select id="selectMenuListByRoleId" parameterType="Long" resultType="Integer">
|
| | | select m.menu_id, m.parent_id
|
| | | <select id="selectMenuListByRoleId" resultType="Integer">
|
| | | 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})
|
| | | <if test="menuCheckStrictly">
|
| | | 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})
|
| | | </if>
|
| | | order by m.parent_id, m.order_num
|
| | | </select>
|
| | |
|
| | |
| | | <mapper namespace="com.ruoyi.system.mapper.SysRoleMapper">
|
| | |
|
| | | <resultMap type="SysRole" id="SysRoleResult">
|
| | | <id property="roleId" column="role_id" />
|
| | | <result property="roleName" column="role_name" />
|
| | | <result property="roleKey" column="role_key" />
|
| | | <result property="roleSort" column="role_sort" />
|
| | | <result property="dataScope" column="data_scope" />
|
| | | <result property="status" column="status" />
|
| | | <result property="delFlag" column="del_flag" />
|
| | | <result property="createBy" column="create_by" />
|
| | | <result property="createTime" column="create_time" />
|
| | | <result property="updateBy" column="update_by" />
|
| | | <result property="updateTime" column="update_time" />
|
| | | <result property="remark" column="remark" />
|
| | | <id property="roleId" column="role_id" />
|
| | | <result property="roleName" column="role_name" />
|
| | | <result property="roleKey" column="role_key" />
|
| | | <result property="roleSort" column="role_sort" />
|
| | | <result property="dataScope" column="data_scope" />
|
| | | <result property="menuCheckStrictly" column="menu_check_strictly" />
|
| | | <result property="deptCheckStrictly" column="dept_check_strictly" />
|
| | | <result property="status" column="status" />
|
| | | <result property="delFlag" column="del_flag" />
|
| | | <result property="createBy" column="create_by" />
|
| | | <result property="createTime" column="create_time" />
|
| | | <result property="updateBy" column="update_by" />
|
| | | <result property="updateTime" column="update_time" />
|
| | | <result property="remark" column="remark" />
|
| | | </resultMap>
|
| | |
|
| | | <sql id="selectRoleVo">
|
| | | 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
|
| | |
| | | <if test="roleKey != null and roleKey != ''">role_key,</if>
|
| | | <if test="roleSort != null and roleSort != ''">role_sort,</if>
|
| | | <if test="dataScope != null and dataScope != ''">data_scope,</if>
|
| | | <if test="menuCheckStrictly != null and menuCheckStrictly != ''">menu_check_strictly,</if>
|
| | | <if test="deptCheckStrictly != null and deptCheckStrictly != ''">dept_check_strictly,</if>
|
| | | <if test="status != null and status != ''">status,</if>
|
| | | <if test="remark != null and remark != ''">remark,</if>
|
| | | <if test="createBy != null and createBy != ''">create_by,</if>
|
| | |
| | | <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
|
| | | <if test="roleSort != null and roleSort != ''">#{roleSort},</if>
|
| | | <if test="dataScope != null and dataScope != ''">#{dataScope},</if>
|
| | | <if test="menuCheckStrictly != null">#{menu_check_strictly},</if>
|
| | | <if test="deptCheckStrictly != null">#{dept_check_strictly},</if>
|
| | | <if test="status != null and status != ''">#{status},</if>
|
| | | <if test="remark != null and remark != ''">#{remark},</if>
|
| | | <if test="createBy != null and createBy != ''">#{createBy},</if>
|
| | |
| | | <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
|
| | | <if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
|
| | | <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
|
| | | <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
|
| | | <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
|
| | | <if test="status != null and status != ''">status = #{status},</if>
|
| | | <if test="remark != null">remark = #{remark},</if>
|
| | | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
| | |
| | | padding: 10px 20px !important;
|
| | | }
|
| | |
|
| | | /* tree border */
|
| | | .tree-border {
|
| | | margin-top: 5px;
|
| | | border: 1px solid #e5e6e7;
|
| | | background: #FFFFFF none;
|
| | | border-radius:4px;
|
| | | }
|
| | |
|
| | | .pagination-container .el-pagination {
|
| | | right: 0;
|
| | | position: absolute;
|
| | |
| | | </el-radio-group>
|
| | | </el-form-item>
|
| | | <el-form-item label="èåæé">
|
| | | <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">å±å¼/æå </el-checkbox>
|
| | | <el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">å
¨é/å
¨ä¸é</el-checkbox>
|
| | | <el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">ç¶åèå¨</el-checkbox>
|
| | | <el-tree
|
| | | class="tree-border"
|
| | | :data="menuOptions"
|
| | | show-checkbox
|
| | | ref="menu"
|
| | | node-key="id"
|
| | | :check-strictly="!form.menuCheckStrictly"
|
| | | empty-text="å è½½ä¸ï¼è¯·ç¨å"
|
| | | :props="defaultProps"
|
| | | ></el-tree>
|
| | |
| | | </el-select>
|
| | | </el-form-item>
|
| | | <el-form-item label="æ°æ®æé" v-show="form.dataScope == 2">
|
| | | <el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">å±å¼/æå </el-checkbox>
|
| | | <el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">å
¨é/å
¨ä¸é</el-checkbox>
|
| | | <el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">ç¶åèå¨</el-checkbox>
|
| | | <el-tree
|
| | | class="tree-border"
|
| | | :data="deptOptions"
|
| | | show-checkbox
|
| | | default-expand-all
|
| | | ref="dept"
|
| | | node-key="id"
|
| | | :check-strictly="!form.deptCheckStrictly"
|
| | | empty-text="å è½½ä¸ï¼è¯·ç¨å"
|
| | | :props="defaultProps"
|
| | | ></el-tree>
|
| | |
| | | open: false,
|
| | | // æ¯å¦æ¾ç¤ºå¼¹åºå±ï¼æ°æ®æéï¼
|
| | | openDataScope: false,
|
| | | menuExpand: false,
|
| | | menuNodeAll: false,
|
| | | deptExpand: true,
|
| | | deptNodeAll: false,
|
| | | // æ¥æèå´
|
| | | dateRange: [],
|
| | | // ç¶ææ°æ®åå
¸
|
| | |
| | | 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,
|
| | |
| | | status: "0",
|
| | | menuIds: [],
|
| | | deptIds: [],
|
| | | menuCheckStrictly: true,
|
| | | remark: undefined
|
| | | };
|
| | | this.resetForm("form");
|
| | |
| | | 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() {
|
| | | this.reset();
|
| | |
| | | </el-col>
|
| | | <el-col :span="12">
|
| | | <el-form-item label="å½å±é¨é¨" prop="deptId">
|
| | | <treeselect v-model="form.deptId" :options="deptOptions" :disable-branch-nodes="true" :show-count="true" placeholder="è¯·éæ©å½å±é¨é¨" />
|
| | | <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="è¯·éæ©å½å±é¨é¨" />
|
| | | </el-form-item>
|
| | | </el-col>
|
| | | </el-row>
|
ÎļþÃû´Ó sql/ry_20200901.sql ÐÞ¸Ä |
| | |
| | | -- ----------------------------
|
| | | 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', 'æ®éè§è²');
|
| | |
|
| | |
|
| | | -- ----------------------------
|