初始化 dept 部门模块

This commit is contained in:
YunaiV 2021-01-09 22:00:22 +08:00
parent 6edd4d7eae
commit 04feb57ed8
12 changed files with 157 additions and 81 deletions

View File

@ -26,6 +26,7 @@ export function getDept(deptId) {
} }
// 查询部门下拉树结构 // 查询部门下拉树结构
// TODO 准备删除
export function treeselect() { export function treeselect() {
return request({ return request({
url: '/system/dept/treeselect', url: '/system/dept/treeselect',
@ -34,6 +35,7 @@ export function treeselect() {
} }
// 根据角色ID查询部门树结构 // 根据角色ID查询部门树结构
// TODO 准备删除
export function roleDeptTreeselect(roleId) { export function roleDeptTreeselect(roleId) {
return request({ return request({
url: '/system/dept/roleDeptTreeselect/' + roleId, 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) { export function addDept(data) {
return request({ return request({
@ -65,4 +75,4 @@ export function delDept(deptId) {
url: '/system/dept/' + deptId, url: '/system/dept/' + deptId,
method: 'delete' method: 'delete'
}) })
} }

View File

@ -24,7 +24,18 @@ export const SysMenuTypeEnum = {
/** /**
* 角色的类型枚举 * 角色的类型枚举
*/ */
export const RoleTypeEnum = { export const SysRoleTypeEnum = {
SYSTEM: 1, // 内置角色 SYSTEM: 1, // 内置角色
CUSTOM: 2 // 自定义角色 CUSTOM: 2 // 自定义角色
} }
/**
* 数据权限的泛微枚举
*/
export const SysDataScopeEnum = {
ALL: 1, // 全部数据权限
DEPT_CUSTOM: 2, // 指定部门数据权限
DEPT_ONLY: 3, // 部门数据权限
DEPT_AND_CHILD: 4, // 部门及以下数据权限
DEPT_SELF: 5 // 仅本人数据权限
}

View File

@ -9,6 +9,7 @@ export const DICT_TYPE = {
SYS_COMMON_STATUS: 'sys_common_status', SYS_COMMON_STATUS: 'sys_common_status',
SYS_MENU_TYPE: 'sys_menu_type', SYS_MENU_TYPE: 'sys_menu_type',
SYS_ROLE_TYPE: 'sys_role_type', SYS_ROLE_TYPE: 'sys_role_type',
SYS_DATA_SCOPE: 'sys_data_scope',
} }
/** /**

View File

@ -163,7 +163,7 @@
</el-dialog> </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 :model="form" label-width="80px">
<el-form-item label="角色名称"> <el-form-item label="角色名称">
<el-input v-model="form.name" :disabled="true" /> <el-input v-model="form.name" :disabled="true" />
@ -174,15 +174,15 @@
<el-form-item label="权限范围"> <el-form-item label="权限范围">
<el-select v-model="form.dataScope"> <el-select v-model="form.dataScope">
<el-option <el-option
v-for="item in dataScopeOptions" v-for="item in dataScopeDictDatas"
:key="item.value" :key="parseInt(item.value)"
:label="item.label" :label="item.label"
:value="item.value" :value="parseInt(item.value)"
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="数据权限" v-show="form.dataScope == 2"> <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="!form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动(选中父节点自动选择子节点)</el-checkbox>
<el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($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-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
<el-tree <el-tree
@ -237,11 +237,20 @@
</template> </template>
<script> <script>
import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role"; import {
import { listSimpleMenus } from "@/api/system/menu"; addRole,
import { listRoleMenus, assignRoleMenu } from "@/api/system/permission"; changeRoleStatus,
import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept"; dataScope,
import {SysCommonStatusEnum, SysMenuTypeEnum} from "@/utils/constants"; 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"; import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict";
export default { export default {
@ -264,38 +273,12 @@ export default {
openDataScope: false, openDataScope: false,
// //
openMenu: false, openMenu: false,
// TODO
menuExpand: false, menuExpand: false,
menuNodeAll: false, menuNodeAll: false,
deptExpand: true, deptExpand: true,
deptNodeAll: false, deptNodeAll: false,
// //
dateRange: [], dateRange: [],
//
statusOptions: [],
//
dataScopeOptions: [
{
value: "1",
label: "全部数据权限"
},
{
value: "2",
label: "自定数据权限"
},
{
value: "3",
label: "本部门数据权限"
},
{
value: "4",
label: "本部门及以下数据权限"
},
{
value: "5",
label: "仅本人数据权限"
}
],
// //
menuOptions: [], menuOptions: [],
// //
@ -328,10 +311,12 @@ export default {
}, },
// //
CommonStatusEnum: SysCommonStatusEnum, SysCommonStatusEnum: SysCommonStatusEnum,
SysDataScopeEnum: SysDataScopeEnum,
// //
roleTypeDictDatas: getDictDatas(DICT_TYPE.SYS_ROLE_TYPE), 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() { 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) { handleStatusChange(row) {
// row // row
@ -511,16 +474,22 @@ export default {
/** 分配数据权限操作 */ /** 分配数据权限操作 */
handleDataScope(row) { handleDataScope(row) {
this.reset(); 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 => { getRole(row.id).then(response => {
this.form = response.data; // TODO
this.openDataScope = true; // this.$refs.dept.setCheckedKeys(res.checkedKeys);
this.$nextTick(() => {
roleDeptTreeselect.then(res => {
this.$refs.dept.setCheckedKeys(res.checkedKeys);
});
});
this.title = "分配数据权限";
}); });
}, },
/** 提交按钮 */ /** 提交按钮 */
@ -546,8 +515,13 @@ export default {
/** 提交按钮(数据权限) */ /** 提交按钮(数据权限) */
submitDataScope: function() { submitDataScope: function() {
if (this.form.id !== undefined) { if (this.form.id !== undefined) {
this.form.deptIds = this.getDeptAllCheckedKeys(); // this.form.deptIds = this.getDeptAllCheckedKeys();
dataScope(this.form).then(response => { debugger
dataScope({
roleId: this.form.id,
deptIds: this.form.dataScope !== SysDataScopeEnum.DEPT_CUSTOM ? [] :
this.$refs.dept.getCheckedKeys(false)
}).then(response => {
this.msgSuccess("修改成功"); this.msgSuccess("修改成功");
this.openDataScope = false; this.openDataScope = false;
this.getList(); this.getList();
@ -556,7 +530,6 @@ export default {
}, },
/** 提交按钮(菜单权限) */ /** 提交按钮(菜单权限) */
submitMenu: function() { submitMenu: function() {
// TODO
if (this.form.id !== undefined) { if (this.form.id !== undefined) {
assignRoleMenu({ assignRoleMenu({
roleId: this.form.id, roleId: this.form.id,

View File

@ -1,14 +1,52 @@
package cn.iocoder.dashboard.modules.system.controller.dept; 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.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; 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") @Api(tags = "部门 API")
@RestController @RestController
@RequestMapping("/system/dept") @RequestMapping("/system/dept")
public class SysDeptController { 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));
}
} }

View File

@ -27,7 +27,7 @@ public class SysRoleBaseVO {
@NotBlank(message = "显示顺序不能为空") @NotBlank(message = "显示顺序不能为空")
private String sort; private String sort;
@ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "RoleTypeEnum 枚举") @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "SysRoleTypeEnum 枚举")
private Integer type; private Integer type;
@ApiModelProperty(value = "备注", example = "我是一个角色") @ApiModelProperty(value = "备注", example = "我是一个角色")

View File

@ -25,7 +25,7 @@ public class SysRoleRespVO extends SysRoleBaseVO {
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
private Integer status; private Integer status;
@ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 RoleTypeEnum 枚举类") @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 SysRoleTypeEnum 枚举类")
private Integer type; private Integer type;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")

View File

@ -14,9 +14,9 @@ public class SysRoleUpdateStatusReqVO {
@NotNull(message = "角色编号不能为空") @NotNull(message = "角色编号不能为空")
private Long id; private Long id;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "CommonStatusEnum 枚举") @ApiModelProperty(value = "状态", required = true, example = "1", notes = "SysCommonStatusEnum 枚举")
@NotNull(message = "状态不能为空") @NotNull(message = "状态不能为空")
// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") // @InEnum(value = SysCommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status; private Integer status;
} }

View File

@ -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);
}

View File

@ -1,6 +1,9 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept; 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 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 com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -10,7 +13,12 @@ import java.util.List;
public interface SysDeptMapper extends BaseMapper<SysDeptDO> { public interface SysDeptMapper extends BaseMapper<SysDeptDO> {
default List<SysDeptDO> selectList() { 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()));
} }
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.dashboard.modules.system.service.dept; 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 cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
import java.util.List; import java.util.List;
@ -14,8 +15,16 @@ public interface SysDeptService {
/** /**
* 获得所有部门列表 * 获得所有部门列表
* *
* @return 菜单列表 * @return 部门列表
*/ */
List<SysDeptDO> listDepts(); List<SysDeptDO> listDepts();
/**
* 筛选部门列表
*
* @param reqVO 筛选条件请求 VO
* @return 部门列表
*/
List<SysDeptDO> listDepts(SysDeptListReqVO reqVO);
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.dashboard.modules.system.service.dept.impl; 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.dao.dept.SysDeptMapper;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
@ -24,4 +25,9 @@ public class SysDeptServiceImpl implements SysDeptService {
return deptMapper.selectList(); return deptMapper.selectList();
} }
@Override
public List<SysDeptDO> listDepts(SysDeptListReqVO reqVO) {
return deptMapper.selectList(reqVO);
}
} }