-
+
-
+
@@ -65,26 +65,6 @@
v-hasPermi="['system:role:add']"
>新增
-
- 修改
-
-
- 删除
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -127,6 +107,13 @@
@click="handleUpdate(scope.row)"
v-hasPermi="['system:role:edit']"
>修改
+ 菜单权限
-
-
+
+
-
-
+
+
-
-
-
-
-
- {{dict.dictLabel}}
-
-
-
- 展开/折叠
- 全选/全不选
- 父子联动
-
+
+
@@ -199,14 +162,14 @@
-
+
-
+
-
-
+
+
@@ -240,6 +203,37 @@
取 消
+
+
+
+
+
+
+
+
+
+
+
+ 展开/折叠
+ 全选/全不选
+ 父子联动
+
+
+
+
+
@@ -247,6 +241,8 @@
import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
+import {SysCommonStatusEnum, SysMenuTypeEnum} from "@/utils/constants";
+import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict";
export default {
name: "Role",
@@ -254,12 +250,6 @@ export default {
return {
// 遮罩层
loading: true,
- // 选中数组
- ids: [],
- // 非单个禁用
- single: true,
- // 非多个禁用
- multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
@@ -272,6 +262,9 @@ export default {
open: false,
// 是否显示弹出层(数据权限)
openDataScope: false,
+ // 是否显示弹出层(菜单权限)
+ openMenu: false,
+ // TODO 需要简化下
menuExpand: false,
menuNodeAll: false,
deptExpand: true,
@@ -309,10 +302,10 @@ export default {
deptOptions: [],
// 查询参数
queryParams: {
- pageNum: 1,
+ pageNo: 1,
pageSize: 10,
- roleName: undefined,
- roleKey: undefined,
+ name: undefined,
+ code: undefined,
status: undefined
},
// 表单参数
@@ -323,23 +316,26 @@ export default {
},
// 表单校验
rules: {
- roleName: [
+ name: [
{ required: true, message: "角色名称不能为空", trigger: "blur" }
],
- roleKey: [
- { required: true, message: "权限字符不能为空", trigger: "blur" }
+ code: [
+ { required: true, message: "角色标识不能为空", trigger: "blur" }
],
- roleSort: [
+ sort: [
{ required: true, message: "角色顺序不能为空", trigger: "blur" }
]
- }
+ },
+
+ // 枚举
+ CommonStatusEnum: SysCommonStatusEnum,
+ // 数据字典
+ roleTypeDictDatas: getDictDatas(DICT_TYPE.SYS_ROLE_TYPE),
+ statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)
};
},
created() {
this.getList();
- this.getDicts("sys_normal_disable").then(response => {
- this.statusOptions = response.data;
- });
},
methods: {
/** 查询角色列表 */
@@ -347,8 +343,8 @@ export default {
this.loading = true;
listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
response => {
- this.roleList = response.rows;
- this.total = response.total;
+ this.roleList = response.data.list;
+ this.total = response.data.total;
this.loading = false;
}
);
@@ -384,34 +380,41 @@ export default {
return checkedKeys;
},
/** 根据角色ID查询菜单树结构 */
- getRoleMenuTreeselect(roleId) {
- return roleMenuTreeselect(roleId).then(response => {
+ getRoleMenuTreeselect(id) {
+ return roleMenuTreeselect(id).then(response => {
this.menuOptions = response.menus;
return response;
});
},
/** 根据角色ID查询部门树结构 */
- getRoleDeptTreeselect(roleId) {
- return roleDeptTreeselect(roleId).then(response => {
+ getRoleDeptTreeselect(id) {
+ return roleDeptTreeselect(id).then(response => {
this.deptOptions = response.depts;
return response;
});
},
// 角色状态修改
handleStatusChange(row) {
- let text = row.status === "0" ? "启用" : "停用";
- this.$confirm('确认要"' + text + '""' + row.roleName + '"角色吗?', "警告", {
+ // 此时,row 已经变成目标状态了,所以可以直接提交请求和提示
+ let text = row.status === SysCommonStatusEnum.ENABLE ? "启用" : "停用";
+ this.$confirm('确认要"' + text + '""' + row.name + '"角色吗?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
- return changeRoleStatus(row.roleId, row.status);
+ return changeRoleStatus(row.id, row.status);
}).then(() => {
this.msgSuccess(text + "成功");
}).catch(function() {
- row.status = row.status === "0" ? "1" : "0";
+ // 异常时,需要将 row.status 状态重置回之前的
+ row.status = row.status === SysCommonStatusEnum.ENABLE ? SysCommonStatusEnum.DISABLE
+ : SysCommonStatusEnum.ENABLE;
});
},
+ // 角色类型字典翻译
+ typeFormat(row, column) {
+ return getDictDataLabel(DICT_TYPE.SYS_ROLE_TYPE, row.type)
+ },
// 取消按钮
cancel() {
this.open = false;
@@ -422,6 +425,11 @@ export default {
this.openDataScope = false;
this.reset();
},
+ // 取消按钮(菜单权限)
+ cancelMenu() {
+ this.openMenu = false;
+ this.reset();
+ },
// 表单重置
reset() {
if (this.$refs.menu != undefined) {
@@ -432,10 +440,10 @@ export default {
this.deptExpand = true,
this.deptNodeAll = false,
this.form = {
- roleId: undefined,
- roleName: undefined,
- roleKey: undefined,
- roleSort: 0,
+ id: undefined,
+ name: undefined,
+ code: undefined,
+ sort: 0,
status: "0",
ids: [],
deptIds: [],
@@ -447,7 +455,7 @@ export default {
},
/** 搜索按钮操作 */
handleQuery() {
- this.queryParams.pageNum = 1;
+ this.queryParams.pageNo = 1;
this.getList();
},
/** 重置按钮操作 */
@@ -456,12 +464,6 @@ export default {
this.resetForm("queryForm");
this.handleQuery();
},
- // 多选框选中数据
- handleSelectionChange(selection) {
- this.ids = selection.map(item => item.roleId)
- this.single = selection.length!=1
- this.multiple = !selection.length
- },
// 树权限(展开/折叠)
handleCheckedTreeExpand(value, type) {
if (type == 'menu') {
@@ -495,31 +497,50 @@ export default {
/** 新增按钮操作 */
handleAdd() {
this.reset();
- this.getMenuTreeselect();
this.open = true;
this.title = "添加角色";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
- const roleId = row.roleId || this.ids
- const roleMenu = this.getRoleMenuTreeselect(roleId);
- getRole(roleId).then(response => {
+ const id = row.id
+ getRole(id).then(response => {
this.form = response.data;
this.open = true;
- this.$nextTick(() => {
- roleMenu.then(res => {
- this.$refs.menu.setCheckedKeys(res.checkedKeys);
- });
- });
this.title = "修改角色";
});
},
+ /** 分配菜单权限操作 */
+ handleMenu(row) {
+ this.reset();
+ const id = row.id
+ // TODO 优化
+ this.getMenuTreeselect();
+ const roleMenu = this.getRoleMenuTreeselect(id);
+ this.$nextTick(() => {
+ roleMenu.then(res => {
+ this.$refs.menu.setCheckedKeys(res.checkedKeys);
+ });
+ });
+ this.openMenu = true;
+
+ // const roleDeptTreeselect = this.getRoleDeptTreeselect(row.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 = "分配数据权限";
+ // });
+ },
/** 分配数据权限操作 */
handleDataScope(row) {
this.reset();
- const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
- getRole(row.roleId).then(response => {
+ const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id);
+ getRole(row.id).then(response => {
this.form = response.data;
this.openDataScope = true;
this.$nextTick(() => {
@@ -534,15 +555,17 @@ export default {
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
- if (this.form.roleId != undefined) {
- this.form.ids = this.getMenuAllCheckedKeys();
+ if (this.form.id !== undefined) {
+ // TODO 芋艿:需要迁移
+ // this.form.ids = this.getMenuAllCheckedKeys();
updateRole(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
- this.form.ids = this.getMenuAllCheckedKeys();
+ // TODO 芋艿:需要迁移
+ // this.form.ids = this.getMenuAllCheckedKeys();
addRole(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
@@ -554,7 +577,19 @@ export default {
},
/** 提交按钮(数据权限) */
submitDataScope: function() {
- if (this.form.roleId != undefined) {
+ if (this.form.id != undefined) {
+ this.form.deptIds = this.getDeptAllCheckedKeys();
+ dataScope(this.form).then(response => {
+ this.msgSuccess("修改成功");
+ this.openDataScope = false;
+ this.getList();
+ });
+ }
+ },
+ /** 提交按钮(菜单权限) */
+ submitMenu: function() {
+ // TODO 需要改动下
+ if (this.form.id != undefined) {
this.form.deptIds = this.getDeptAllCheckedKeys();
dataScope(this.form).then(response => {
this.msgSuccess("修改成功");
@@ -565,13 +600,13 @@ export default {
},
/** 删除按钮操作 */
handleDelete(row) {
- const roleIds = row.roleId || this.ids;
- this.$confirm('是否确认删除角色编号为"' + roleIds + '"的数据项?', "警告", {
+ const ids = row.id || this.ids;
+ this.$confirm('是否确认删除角色编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
- return delRole(roleIds);
+ return delRole(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java
index 748e82ec3..f95ac371b 100644
--- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java
+++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java
@@ -2,16 +2,12 @@ package cn.iocoder.dashboard.modules.system.controller.permission;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.common.pojo.PageResult;
-import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleCreateReqVO;
-import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRolePageReqVO;
-import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleRespVO;
-import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleUpdateReqVO;
+import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.*;
import cn.iocoder.dashboard.modules.system.convert.permission.SysRoleConvert;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -82,14 +78,10 @@ public class SysRoleController {
@ApiOperation("修改角色状态")
@PostMapping("/update-status")
- @ApiImplicitParams(value = {
- @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024"),
- @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
- })
// @PreAuthorize("@ss.hasPermi('system:role:edit')")
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
- public CommonResult