角色列表页面权限分配.
This commit is contained in:
@@ -2,6 +2,10 @@ package com.xuxd.kafka.console.beans.dto;
|
|||||||
|
|
||||||
import com.xuxd.kafka.console.beans.dos.SysRoleDO;
|
import com.xuxd.kafka.console.beans.dos.SysRoleDO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: xuxd
|
* @author: xuxd
|
||||||
@@ -16,14 +20,16 @@ public class SysRoleDTO {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String permissionIds;
|
private List<String> permissionIds;
|
||||||
|
|
||||||
public SysRoleDO toDO() {
|
public SysRoleDO toDO() {
|
||||||
SysRoleDO roleDO = new SysRoleDO();
|
SysRoleDO roleDO = new SysRoleDO();
|
||||||
roleDO.setId(this.id);
|
roleDO.setId(this.id);
|
||||||
roleDO.setRoleName(this.roleName);
|
roleDO.setRoleName(this.roleName);
|
||||||
roleDO.setDescription(this.description);
|
roleDO.setDescription(this.description);
|
||||||
roleDO.setPermissionIds(this.permissionIds);
|
if (CollectionUtils.isNotEmpty(permissionIds)) {
|
||||||
|
roleDO.setPermissionIds(StringUtils.join(this.permissionIds, ","));
|
||||||
|
}
|
||||||
return roleDO;
|
return roleDO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ public class UserManageController {
|
|||||||
return userManageService.addUser(userDTO);
|
return userManageService.addUser(userDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ControllerLog("新增角色")
|
@ControllerLog("新增/更新角色")
|
||||||
@PostMapping("/role")
|
@PostMapping("/role")
|
||||||
public Object addRole(@RequestBody SysRoleDTO roleDTO) {
|
public Object addOrUpdateRole(@RequestBody SysRoleDTO roleDTO) {
|
||||||
return userManageService.addRole(roleDTO);
|
return userManageService.addOrUdpateRole(roleDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ControllerLog("新增权限")
|
@ControllerLog("新增权限")
|
||||||
@@ -54,4 +54,9 @@ public class UserManageController {
|
|||||||
public Object selectPermission() {
|
public Object selectPermission() {
|
||||||
return userManageService.selectPermission();
|
return userManageService.selectPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/role")
|
||||||
|
public Object deleteRole(@RequestParam Long id) {
|
||||||
|
return userManageService.deleteRole(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public interface UserManageService {
|
|||||||
*/
|
*/
|
||||||
ResponseData addPermission(SysPermissionDTO permissionDTO);
|
ResponseData addPermission(SysPermissionDTO permissionDTO);
|
||||||
|
|
||||||
ResponseData addRole(SysRoleDTO roleDTO);
|
ResponseData addOrUdpateRole(SysRoleDTO roleDTO);
|
||||||
|
|
||||||
ResponseData addUser(SysUserDTO userDTO);
|
ResponseData addUser(SysUserDTO userDTO);
|
||||||
|
|
||||||
@@ -29,4 +29,6 @@ public interface UserManageService {
|
|||||||
ResponseData updateUser(SysUserDTO userDTO);
|
ResponseData updateUser(SysUserDTO userDTO);
|
||||||
|
|
||||||
ResponseData updateRole(SysRoleDTO roleDTO);
|
ResponseData updateRole(SysRoleDTO roleDTO);
|
||||||
|
|
||||||
|
ResponseData deleteRole(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,13 @@ public class UserManageServiceImpl implements UserManageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseData addRole(SysRoleDTO roleDTO) {
|
public ResponseData addOrUdpateRole(SysRoleDTO roleDTO) {
|
||||||
roleMapper.insert(roleDTO.toDO());
|
SysRoleDO roleDO = roleDTO.toDO();
|
||||||
|
if (roleDO.getId() == null) {
|
||||||
|
roleMapper.insert(roleDO);
|
||||||
|
} else {
|
||||||
|
roleMapper.updateById(roleDO);
|
||||||
|
}
|
||||||
return ResponseData.create().success();
|
return ResponseData.create().success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,4 +137,10 @@ public class UserManageServiceImpl implements UserManageService {
|
|||||||
roleMapper.updateById(roleDTO.toDO());
|
roleMapper.updateById(roleDTO.toDO());
|
||||||
return ResponseData.create().success();
|
return ResponseData.create().success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseData deleteRole(Long id) {
|
||||||
|
roleMapper.deleteById(id);
|
||||||
|
return ResponseData.create().success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -322,4 +322,12 @@ export const UserManageApi = {
|
|||||||
url: "/sys/user/manage/role",
|
url: "/sys/user/manage/role",
|
||||||
method: "get",
|
method: "get",
|
||||||
},
|
},
|
||||||
|
addOrUpdateRole: {
|
||||||
|
url: "/sys/user/manage/role",
|
||||||
|
method: "post",
|
||||||
|
},
|
||||||
|
deleteRole: {
|
||||||
|
url: "/sys/user/manage/role",
|
||||||
|
method: "delete",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
<a-table
|
<a-table
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:data-source="data"
|
:data-source="data"
|
||||||
:row-selection="rowSelection"
|
|
||||||
:expanded-row-keys.sync="expandedRowKeys"
|
:expanded-row-keys.sync="expandedRowKeys"
|
||||||
>
|
>
|
||||||
<div slot="type" slot-scope="text">
|
<div slot="type" slot-scope="text">
|
||||||
@@ -32,13 +31,7 @@ const columns = [
|
|||||||
width: "12%",
|
width: "12%",
|
||||||
slots: { title: "type" },
|
slots: { title: "type" },
|
||||||
scopedSlots: { customRender: "type" },
|
scopedSlots: { customRender: "type" },
|
||||||
},
|
}
|
||||||
{
|
|
||||||
title: "权限标记",
|
|
||||||
dataIndex: "permission",
|
|
||||||
width: "30%",
|
|
||||||
key: "permission",
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
|
|||||||
@@ -20,7 +20,12 @@
|
|||||||
item.roleName
|
item.roleName
|
||||||
}}</a>
|
}}</a>
|
||||||
</a-list-item-meta>
|
</a-list-item-meta>
|
||||||
<a-popconfirm title="确定删除角色?">
|
<a-popconfirm
|
||||||
|
title="确定删除角色?"
|
||||||
|
ok-text="确认"
|
||||||
|
cancel-text="取消"
|
||||||
|
@confirm="deleteRole(item.id)"
|
||||||
|
>
|
||||||
<a :style="{ display: 'flex' }">
|
<a :style="{ display: 'flex' }">
|
||||||
<a-icon type="delete" />
|
<a-icon type="delete" />
|
||||||
</a>
|
</a>
|
||||||
@@ -79,7 +84,7 @@
|
|||||||
<!-- <a-checkbox :checked="menuPermission.checked">-->
|
<!-- <a-checkbox :checked="menuPermission.checked">-->
|
||||||
<!-- 可见</a-checkbox-->
|
<!-- 可见</a-checkbox-->
|
||||||
<!-- >-->
|
<!-- >-->
|
||||||
<a-switch v-model="menuPermission.checked" />
|
<!-- <a-switch v-model="menuPermission.checked" />-->
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
<a-divider type="horizontal" :style="{ margin: '0px' }" />
|
<a-divider type="horizontal" :style="{ margin: '0px' }" />
|
||||||
@@ -100,13 +105,20 @@
|
|||||||
/>
|
/>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="3" :style="{ textAlign: 'right' }">
|
<a-col :span="3" :style="{ textAlign: 'right' }">
|
||||||
<a-checkbox> 全选</a-checkbox>
|
<a-checkbox
|
||||||
|
v-model="checkboxPermission.selectAll"
|
||||||
|
@click="onCheckboxSelectAll(checkboxPermission)"
|
||||||
|
>
|
||||||
|
全选</a-checkbox
|
||||||
|
>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
</div>
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item>
|
<a-form-item>
|
||||||
<a-button type="primary" :loading="loading">保存</a-button>
|
<a-button type="primary" :loading="loading" @click="onSave()"
|
||||||
|
>保存</a-button
|
||||||
|
>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,6 +151,16 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
selected(role) {
|
selected(role) {
|
||||||
this.selectedRole = Object.assign({}, role);
|
this.selectedRole = Object.assign({}, role);
|
||||||
|
this.form.getFieldDecorator("description", {
|
||||||
|
rules: [{ required: true, message: "请填写备注说明!" }],
|
||||||
|
initialValue: this.selectedRole.description,
|
||||||
|
});
|
||||||
|
this.form.getFieldDecorator("roleName", {
|
||||||
|
rules: [{ required: true, message: "请填写角色名称!" }],
|
||||||
|
initialValue: this.selectedRole.roleName,
|
||||||
|
});
|
||||||
|
this.form.setFieldsValue({ roleName: this.selectedRole.roleName });
|
||||||
|
this.form.setFieldsValue({ description: this.selectedRole.description });
|
||||||
const idSet = this.selectedRole.permissionIds
|
const idSet = this.selectedRole.permissionIds
|
||||||
? new Set(this.selectedRole.permissionIds)
|
? new Set(this.selectedRole.permissionIds)
|
||||||
: new Set();
|
: new Set();
|
||||||
@@ -181,14 +203,78 @@ export default {
|
|||||||
.map((bc) => bc.id)
|
.map((bc) => bc.id)
|
||||||
.filter((id) => idSet.has(id));
|
.filter((id) => idSet.has(id));
|
||||||
btn.selected = selected || [];
|
btn.selected = selected || [];
|
||||||
|
btn.selectAll = btn.selected.length == btn.children.length;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.children = arr;
|
menu.children = arr;
|
||||||
menu.checked = idSet.has(menu.id);
|
// menu.checked = idSet.has(menu.id);
|
||||||
}
|
}
|
||||||
this.selectedPermissions.push(menu);
|
this.selectedPermissions.push(menu);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
deleteRole(id) {
|
||||||
|
this.loading = true;
|
||||||
|
request({
|
||||||
|
url: UserManageApi.deleteRole.url + "?id=" + id,
|
||||||
|
method: UserManageApi.deleteRole.method,
|
||||||
|
}).then((res) => {
|
||||||
|
this.loading = false;
|
||||||
|
if (res.code == 0) {
|
||||||
|
this.$message.success(res.msg);
|
||||||
|
this.getRoles();
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: "error",
|
||||||
|
description: res.msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSave() {
|
||||||
|
this.form.validateFields((err, values) => {
|
||||||
|
if (!err) {
|
||||||
|
const params = Object.assign({}, this.selectedRole, values);
|
||||||
|
params.permissionIds = [];
|
||||||
|
this.selectedPermissions.forEach((e) => {
|
||||||
|
if (e.children) {
|
||||||
|
e.children.forEach((child) => {
|
||||||
|
if (child.selected) {
|
||||||
|
params.permissionIds.push(...child.selected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.loading = true;
|
||||||
|
request({
|
||||||
|
url: UserManageApi.addOrUpdateRole.url,
|
||||||
|
method: UserManageApi.addOrUpdateRole.method,
|
||||||
|
data: params,
|
||||||
|
}).then((res) => {
|
||||||
|
this.loading = false;
|
||||||
|
if (res.code == 0) {
|
||||||
|
this.$message.success(res.msg);
|
||||||
|
this.getRoles();
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: "error",
|
||||||
|
description: res.msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onCheckboxSelectAll(record) {
|
||||||
|
if (!record.children) {
|
||||||
|
record.selected = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!record.selectAll) {
|
||||||
|
record.selected = record.children.map((bc) => bc.id);
|
||||||
|
} else {
|
||||||
|
record.selected = [];
|
||||||
|
}
|
||||||
|
},
|
||||||
getRoles() {
|
getRoles() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
request({
|
request({
|
||||||
|
|||||||
Reference in New Issue
Block a user