mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 02:28:03 +08:00 
			
		
		
		
	初始化 dept 部门模块
This commit is contained in:
		| @ -26,6 +26,7 @@ export function getDept(deptId) { | ||||
| } | ||||
|  | ||||
| // 查询部门下拉树结构 | ||||
| // TODO 准备删除 | ||||
| export function treeselect() { | ||||
|   return request({ | ||||
|     url: '/system/dept/treeselect', | ||||
| @ -34,6 +35,7 @@ export function treeselect() { | ||||
| } | ||||
|  | ||||
| // 根据角色ID查询部门树结构 | ||||
| // TODO 准备删除 | ||||
| export function roleDeptTreeselect(roleId) { | ||||
|   return request({ | ||||
|     url: '/system/dept/roleDeptTreeselect/' + roleId, | ||||
| @ -41,6 +43,14 @@ export function roleDeptTreeselect(roleId) { | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 获取部门精简信息列表 | ||||
| export function listSimpleDepts() { | ||||
|   return request({ | ||||
|     url: '/system/dept/list-all-simple', | ||||
|     method: 'get' | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 新增部门 | ||||
| export function addDept(data) { | ||||
|   return request({ | ||||
|  | ||||
| @ -24,7 +24,18 @@ export const SysMenuTypeEnum = { | ||||
| /** | ||||
|  * 角色的类型枚举 | ||||
|  */ | ||||
| export const RoleTypeEnum = { | ||||
| export const SysRoleTypeEnum = { | ||||
|   SYSTEM: 1, // 内置角色 | ||||
|   CUSTOM: 2 // 自定义角色 | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * 数据权限的泛微枚举 | ||||
|  */ | ||||
| export const SysDataScopeEnum = { | ||||
|   ALL: 1, // 全部数据权限 | ||||
|   DEPT_CUSTOM: 2, // 指定部门数据权限 | ||||
|   DEPT_ONLY: 3, // 部门数据权限 | ||||
|   DEPT_AND_CHILD: 4, // 部门及以下数据权限 | ||||
|   DEPT_SELF: 5 // 仅本人数据权限 | ||||
| } | ||||
|  | ||||
| @ -9,6 +9,7 @@ export const DICT_TYPE = { | ||||
|   SYS_COMMON_STATUS: 'sys_common_status', | ||||
|   SYS_MENU_TYPE: 'sys_menu_type', | ||||
|   SYS_ROLE_TYPE: 'sys_role_type', | ||||
|   SYS_DATA_SCOPE: 'sys_data_scope', | ||||
| } | ||||
|  | ||||
| /** | ||||
|  | ||||
| @ -163,7 +163,7 @@ | ||||
|     </el-dialog> | ||||
|  | ||||
|     <!-- 分配角色的数据权限对话框 --> | ||||
|     <el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body> | ||||
|     <el-dialog title="分配数据权限" :visible.sync="openDataScope" width="500px" append-to-body> | ||||
|       <el-form :model="form" label-width="80px"> | ||||
|         <el-form-item label="角色名称"> | ||||
|           <el-input v-model="form.name" :disabled="true" /> | ||||
| @ -174,15 +174,15 @@ | ||||
|         <el-form-item label="权限范围"> | ||||
|           <el-select v-model="form.dataScope"> | ||||
|             <el-option | ||||
|               v-for="item in dataScopeOptions" | ||||
|               :key="item.value" | ||||
|               v-for="item in dataScopeDictDatas" | ||||
|               :key="parseInt(item.value)" | ||||
|               :label="item.label" | ||||
|               :value="item.value" | ||||
|               :value="parseInt(item.value)" | ||||
|             ></el-option> | ||||
|           </el-select> | ||||
|         </el-form-item> | ||||
|         <el-form-item label="数据权限" v-show="form.dataScope == 2"> | ||||
|           <el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox> | ||||
|         <el-form-item label="数据权限" v-show="form.dataScope === SysDataScopeEnum.DEPT_CUSTOM"> | ||||
|           <el-checkbox v-model="!form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动(选中父节点,自动选择子节点)</el-checkbox> | ||||
|           <el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox> | ||||
|           <el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox> | ||||
|           <el-tree | ||||
| @ -237,11 +237,20 @@ | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role"; | ||||
| import { listSimpleMenus } from "@/api/system/menu"; | ||||
| import { listRoleMenus, assignRoleMenu } from "@/api/system/permission"; | ||||
| import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept"; | ||||
| import {SysCommonStatusEnum, SysMenuTypeEnum} from "@/utils/constants"; | ||||
| import { | ||||
|   addRole, | ||||
|   changeRoleStatus, | ||||
|   dataScope, | ||||
|   delRole, | ||||
|   exportRole, | ||||
|   getRole, | ||||
|   listRole, | ||||
|   updateRole | ||||
| } from "@/api/system/role"; | ||||
| import {listSimpleMenus} from "@/api/system/menu"; | ||||
| import {assignRoleMenu, listRoleMenus} from "@/api/system/permission"; | ||||
| import {listSimpleDepts, treeselect as deptTreeselect} from "@/api/system/dept"; | ||||
| import {SysCommonStatusEnum, SysDataScopeEnum} from "@/utils/constants"; | ||||
| import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; | ||||
|  | ||||
| export default { | ||||
| @ -264,38 +273,12 @@ export default { | ||||
|       openDataScope: false, | ||||
|       // 是否显示弹出层(菜单权限) | ||||
|       openMenu: false, | ||||
|       // TODO 需要简化下 | ||||
|       menuExpand: false, | ||||
|       menuNodeAll: false, | ||||
|       deptExpand: true, | ||||
|       deptNodeAll: false, | ||||
|       // 日期范围 | ||||
|       dateRange: [], | ||||
|       // 状态数据字典 | ||||
|       statusOptions: [], | ||||
|       // 数据范围选项 | ||||
|       dataScopeOptions: [ | ||||
|         { | ||||
|           value: "1", | ||||
|           label: "全部数据权限" | ||||
|         }, | ||||
|         { | ||||
|           value: "2", | ||||
|           label: "自定数据权限" | ||||
|         }, | ||||
|         { | ||||
|           value: "3", | ||||
|           label: "本部门数据权限" | ||||
|         }, | ||||
|         { | ||||
|           value: "4", | ||||
|           label: "本部门及以下数据权限" | ||||
|         }, | ||||
|         { | ||||
|           value: "5", | ||||
|           label: "仅本人数据权限" | ||||
|         } | ||||
|       ], | ||||
|       // 菜单列表 | ||||
|       menuOptions: [], | ||||
|       // 部门列表 | ||||
| @ -328,10 +311,12 @@ export default { | ||||
|       }, | ||||
|  | ||||
|       // 枚举 | ||||
|       CommonStatusEnum: SysCommonStatusEnum, | ||||
|       SysCommonStatusEnum: SysCommonStatusEnum, | ||||
|       SysDataScopeEnum: SysDataScopeEnum, | ||||
|       // 数据字典 | ||||
|       roleTypeDictDatas: getDictDatas(DICT_TYPE.SYS_ROLE_TYPE), | ||||
|       statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS) | ||||
|       statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS), | ||||
|       dataScopeDictDatas: getDictDatas(DICT_TYPE.SYS_DATA_SCOPE) | ||||
|     }; | ||||
|   }, | ||||
|   created() { | ||||
| @ -349,28 +334,6 @@ export default { | ||||
|         } | ||||
|       ); | ||||
|     }, | ||||
|     /** 查询部门树结构 */ | ||||
|     getDeptTreeselect() { | ||||
|       deptTreeselect().then(response => { | ||||
|         this.deptOptions = response.data; | ||||
|       }); | ||||
|     }, | ||||
|     // 所有部门节点数据 | ||||
|     getDeptAllCheckedKeys() { | ||||
|       // 目前被选中的部门节点 | ||||
|       let checkedKeys = this.$refs.dept.getCheckedKeys(); | ||||
|       // 半选中的部门节点 | ||||
|       let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys(); | ||||
|       checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys); | ||||
|       return checkedKeys; | ||||
|     }, | ||||
|     /** 根据角色ID查询部门树结构 */ | ||||
|     getRoleDeptTreeselect(id) { | ||||
|       return roleDeptTreeselect(id).then(response => { | ||||
|         this.deptOptions = response.depts; | ||||
|         return response; | ||||
|       }); | ||||
|     }, | ||||
|     // 角色状态修改 | ||||
|     handleStatusChange(row) { | ||||
|       // 此时,row 已经变成目标状态了,所以可以直接提交请求和提示 | ||||
| @ -511,16 +474,22 @@ export default { | ||||
|     /** 分配数据权限操作 */ | ||||
|     handleDataScope(row) { | ||||
|       this.reset(); | ||||
|       const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id); | ||||
|       // 处理了 form 的角色 name 和 code 的展示 | ||||
|       this.form.id = row.id; | ||||
|       this.form.name = row.name; | ||||
|       this.form.code = row.code; | ||||
|       // 打开弹窗 | ||||
|       this.openDataScope = true; | ||||
|       // 获得部门列表 | ||||
|       listSimpleDepts().then(response => { | ||||
|         // 处理 menuOptions 参数 | ||||
|         this.deptOptions = []; | ||||
|         this.deptOptions.push(...this.handleTree(response.data, "id")); | ||||
|       }); | ||||
|       // 获得角色拥有的数据权限 | ||||
|       getRole(row.id).then(response => { | ||||
|         this.form = response.data; | ||||
|         this.openDataScope = true; | ||||
|         this.$nextTick(() => { | ||||
|           roleDeptTreeselect.then(res => { | ||||
|             this.$refs.dept.setCheckedKeys(res.checkedKeys); | ||||
|           }); | ||||
|         }); | ||||
|         this.title = "分配数据权限"; | ||||
|         // TODO 搞一搞 | ||||
|         // this.$refs.dept.setCheckedKeys(res.checkedKeys); | ||||
|       }); | ||||
|     }, | ||||
|     /** 提交按钮 */ | ||||
| @ -546,8 +515,13 @@ export default { | ||||
|     /** 提交按钮(数据权限) */ | ||||
|     submitDataScope: function() { | ||||
|       if (this.form.id !== undefined) { | ||||
|         this.form.deptIds = this.getDeptAllCheckedKeys(); | ||||
|         dataScope(this.form).then(response => { | ||||
|         // this.form.deptIds = this.getDeptAllCheckedKeys(); | ||||
|         debugger | ||||
|         dataScope({ | ||||
|           roleId: this.form.id, | ||||
|           deptIds: this.form.dataScope !== SysDataScopeEnum.DEPT_CUSTOM ? [] : | ||||
|               this.$refs.dept.getCheckedKeys(false) | ||||
|         }).then(response => { | ||||
|           this.msgSuccess("修改成功"); | ||||
|           this.openDataScope = false; | ||||
|           this.getList(); | ||||
| @ -556,7 +530,6 @@ export default { | ||||
|     }, | ||||
|     /** 提交按钮(菜单权限) */ | ||||
|     submitMenu: function() { | ||||
|       // TODO 需要改动下 | ||||
|       if (this.form.id !== undefined) { | ||||
|         assignRoleMenu({ | ||||
|           roleId: this.form.id, | ||||
|  | ||||
| @ -1,14 +1,52 @@ | ||||
| package cn.iocoder.dashboard.modules.system.controller.dept; | ||||
|  | ||||
| import cn.iocoder.dashboard.common.enums.CommonStatusEnum; | ||||
| import cn.iocoder.dashboard.common.pojo.CommonResult; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO; | ||||
| import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; | ||||
| import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.Comparator; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.dashboard.common.pojo.CommonResult.success; | ||||
|  | ||||
| @Api(tags = "部门 API") | ||||
| @RestController | ||||
| @RequestMapping("/system/dept") | ||||
| public class SysDeptController { | ||||
|  | ||||
|     @Resource | ||||
|     private SysDeptService sysDeptService; | ||||
|  | ||||
|     @ApiOperation("获取部门列表") | ||||
| //    @PreAuthorize("@ss.hasPermi('system:dept:list')") | ||||
|     @GetMapping("/list") | ||||
|     public CommonResult<List<SysDeptRespVO>> listDepts(SysDeptListReqVO reqVO) { | ||||
|         List<SysDeptDO> list = sysDeptService.listDepts(reqVO); | ||||
|         list.sort(Comparator.comparing(SysDeptDO::getSort)); | ||||
|         return success(SysDeptConvert.INSTANCE.convertList(list)); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项") | ||||
|     @GetMapping("/list-all-simple") | ||||
|     public CommonResult<List<SysDeptSimpleRespVO>> listSimpleDepts() { | ||||
|         // 获得部门列表,只要开启状态的 | ||||
|         SysDeptListReqVO reqVO = new SysDeptListReqVO(); | ||||
|         reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||||
|         List<SysDeptDO> list = sysDeptService.listDepts(reqVO); | ||||
|         // 排序后,返回个诶前端 | ||||
|         list.sort(Comparator.comparing(SysDeptDO::getSort)); | ||||
|         return success(SysDeptConvert.INSTANCE.convertList02(list)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -27,7 +27,7 @@ public class SysRoleBaseVO { | ||||
|     @NotBlank(message = "显示顺序不能为空") | ||||
|     private String sort; | ||||
|  | ||||
|     @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "见 RoleTypeEnum 枚举") | ||||
|     @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "见 SysRoleTypeEnum 枚举") | ||||
|     private Integer type; | ||||
|  | ||||
|     @ApiModelProperty(value = "备注", example = "我是一个角色") | ||||
|  | ||||
| @ -25,7 +25,7 @@ public class SysRoleRespVO extends SysRoleBaseVO { | ||||
|     @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") | ||||
|     private Integer status; | ||||
|  | ||||
|     @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 RoleTypeEnum 枚举类") | ||||
|     @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 SysRoleTypeEnum 枚举类") | ||||
|     private Integer type; | ||||
|  | ||||
|     @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") | ||||
|  | ||||
| @ -14,9 +14,9 @@ public class SysRoleUpdateStatusReqVO { | ||||
|     @NotNull(message = "角色编号不能为空") | ||||
|     private Long id; | ||||
|  | ||||
|     @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") | ||||
|     @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SysCommonStatusEnum 枚举") | ||||
|     @NotNull(message = "状态不能为空") | ||||
| //    @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | ||||
| //    @InEnum(value = SysCommonStatusEnum.class, message = "修改状态必须是 {value}") | ||||
|     private Integer status; | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,20 @@ | ||||
| package cn.iocoder.dashboard.modules.system.convert.dept; | ||||
|  | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| @Mapper | ||||
| public interface SysDeptConvert { | ||||
|  | ||||
|     SysDeptConvert INSTANCE = Mappers.getMapper(SysDeptConvert.class); | ||||
|  | ||||
|     List<SysDeptRespVO> convertList(List<SysDeptDO> list); | ||||
|  | ||||
|     List<SysDeptSimpleRespVO> convertList02(List<SysDeptDO> list); | ||||
|  | ||||
| } | ||||
| @ -1,6 +1,9 @@ | ||||
| package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept; | ||||
|  | ||||
| import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| @ -10,7 +13,12 @@ import java.util.List; | ||||
| public interface SysDeptMapper extends BaseMapper<SysDeptDO> { | ||||
|  | ||||
|     default List<SysDeptDO> selectList() { | ||||
|         return selectList(null); | ||||
|         return selectList(new QueryWrapper<>()); | ||||
|     } | ||||
|  | ||||
|     default List<SysDeptDO> selectList(SysDeptListReqVO reqVO) { | ||||
|         return selectList(new QueryWrapperX<SysDeptDO>().likeIfPresent("name", reqVO.getName()) | ||||
|                 .eqIfPresent("status", reqVO.getStatus())); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| package cn.iocoder.dashboard.modules.system.service.dept; | ||||
|  | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; | ||||
|  | ||||
| import java.util.List; | ||||
| @ -14,8 +15,16 @@ public interface SysDeptService { | ||||
|     /** | ||||
|      * 获得所有部门列表 | ||||
|      * | ||||
|      * @return 菜单列表 | ||||
|      * @return 部门列表 | ||||
|      */ | ||||
|     List<SysDeptDO> listDepts(); | ||||
|  | ||||
|     /** | ||||
|      * 筛选部门列表 | ||||
|      * | ||||
|      * @param reqVO 筛选条件请求 VO | ||||
|      * @return 部门列表 | ||||
|      */ | ||||
|     List<SysDeptDO> listDepts(SysDeptListReqVO reqVO); | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| package cn.iocoder.dashboard.modules.system.service.dept.impl; | ||||
|  | ||||
| import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysDeptMapper; | ||||
| import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; | ||||
| import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; | ||||
| @ -24,4 +25,9 @@ public class SysDeptServiceImpl implements SysDeptService { | ||||
|         return deptMapper.selectList(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<SysDeptDO> listDepts(SysDeptListReqVO reqVO) { | ||||
|         return deptMapper.selectList(reqVO); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV