feat: 完善权限管理

This commit is contained in:
fit2cloud-chenyw 2021-03-15 17:23:21 +08:00
parent 3a5921377f
commit 0bf906779e
7 changed files with 118 additions and 18 deletions

View File

@ -8,6 +8,7 @@ import io.dataease.controller.sys.request.DeptCreateRequest;
import io.dataease.controller.sys.request.DeptDeleteRequest;
import io.dataease.controller.sys.request.DeptStatusRequest;
import io.dataease.controller.sys.response.DeptNodeResponse;
import io.dataease.controller.sys.response.DeptTreeNode;
import io.dataease.service.sys.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -82,4 +83,9 @@ public class SysDeptController extends ResultHolder {
deptService.updateStatus(request);
}
@PostMapping("/nodesByDeptId/{deptId}")
public List<DeptTreeNode> nodesByDeptId(@PathVariable("deptId") Long deptId){
return deptService.searchTree(deptId);
}
}

View File

@ -0,0 +1,27 @@
package io.dataease.controller.sys.response;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeptTreeNode implements Serializable {
private Long id;
private String label;
private Boolean hasChildren;
private List<DeptTreeNode> children;
public List<DeptTreeNode> toList(){
List<DeptTreeNode> lists = new ArrayList<>();
lists.add(this);
return lists;
}
}

View File

@ -8,10 +8,12 @@ import io.dataease.base.mapper.ext.query.GridExample;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.base.ConditionEntity;
import io.dataease.controller.sys.request.DeptCreateRequest;
import io.dataease.controller.sys.request.DeptDeleteRequest;
import io.dataease.controller.sys.request.DeptStatusRequest;
import io.dataease.controller.sys.request.SimpleTreeNode;
import io.dataease.controller.sys.response.DeptTreeNode;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -139,6 +141,33 @@ public class DeptService {
return sysDepts;
}
public List<DeptTreeNode> searchTree(Long deptId){
List<SysDept> roots = nodesByPid(0L);
if (deptId == DEPT_ROOT_PID) return roots.stream().map(this::format).collect(Collectors.toList());
SysDept sysDept = sysDeptMapper.selectByPrimaryKey(deptId);
if (roots.stream().anyMatch(node -> node.getDeptId() == deptId)) return roots.stream().map(this::format).collect(Collectors.toList());
SysDept current = sysDept;
DeptTreeNode currentNode = format(sysDept);
while (current.getPid() != DEPT_ROOT_PID){
SysDept parent = sysDeptMapper.selectByPrimaryKey(current.getPid()); //pid上有索引 所以效率不会太差
DeptTreeNode parentNode = format(parent);
parentNode.setChildren(currentNode.toList());
current = parent;
currentNode = parentNode;
}
DeptTreeNode targetRootNode = currentNode;
return roots.stream().map(node -> node.getDeptId() == targetRootNode.getId() ? targetRootNode : format(node)).collect(Collectors.toList());
}
private DeptTreeNode format(SysDept sysDept){
DeptTreeNode deptTreeNode = new DeptTreeNode();
deptTreeNode.setId(sysDept.getDeptId());
deptTreeNode.setLabel(sysDept.getName());
deptTreeNode.setHasChildren(sysDept.getSubCount() > 0);
return deptTreeNode;
}
private DeptService proxy(){
return CommonBeanFactory.getBean(DeptService.class);
}

View File

@ -41,4 +41,11 @@ export function editDept(data) {
})
}
export default { addDept, delDept, editDept, getDeptTree, loadTable }
export function treeByDeptId(deptId) {
return request({
url: '/api/dept/nodesByDeptId/' + deptId,
method: 'post'
})
}
export default { addDept, delDept, editDept, getDeptTree, loadTable, treeByDeptId }

View File

@ -24,7 +24,7 @@
@search="search"
>
<template #buttons>
<fu-table-button icon="el-icon-circle-plus-outline" :label="$t('organization.create')" @click="create" />
<fu-table-button v-permission="['dept:add']" icon="el-icon-circle-plus-outline" :label="$t('organization.create')" @click="create" />
</template>
<el-table
ref="table"
@ -129,7 +129,7 @@ import Treeselect from '@riophae/vue-treeselect'
import { formatCondition } from '@/utils/index'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { LOAD_CHILDREN_OPTIONS, LOAD_ROOT_OPTIONS } from '@riophae/vue-treeselect'
import { checkPermission } from '@/utils/permission'
import { getDeptTree, addDept, editDept, delDept, loadTable } from '@/api/system/dept'
export default {
@ -173,9 +173,11 @@ export default {
columns: [],
buttons: [
{
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit,
show: checkPermission(['dept:edit'])
}, {
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this._handleDelete
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this._handleDelete,
show: checkPermission(['dept:del'])
}
],
searchConfig: {

View File

@ -7,8 +7,8 @@
:search-config="searchConfig"
@search="initTableData"
>
<template #buttons>
<fu-table-button icon="el-icon-circle-plus-outline" :label="$t('menu.create')" @click="create" />
<template v-permission="['menu:add']" #buttons>
<fu-table-button v-permission="['menu:add']" icon="el-icon-circle-plus-outline" :label="$t('menu.create')" @click="create" />
</template>
<el-table
@ -124,7 +124,7 @@ import IconSelect from '@/components/IconSelect'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { LOAD_CHILDREN_OPTIONS, LOAD_ROOT_OPTIONS } from '@riophae/vue-treeselect'
import { checkPermission } from '@/utils/permission'
import { addMenu, editMenu, delMenu, getMenusTree } from '@/api/system/menu'
export default {
@ -137,7 +137,7 @@ export default {
data() {
return {
menus: [],
topMunu: { id: 0, label: '顶级目', children: null },
topMunu: { id: 0, label: '顶级', children: null },
formType: 'add',
dialogVisible: false,
condition: {},
@ -165,9 +165,11 @@ export default {
columns: [],
buttons: [
{
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit,
show: checkPermission(['menu:edit'])
}, {
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this._handleDelete
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this._handleDelete,
show: checkPermission(['menu:del'])
}
],
searchConfig: {

View File

@ -11,7 +11,7 @@
@search="search"
>
<template #buttons>
<fu-table-button icon="el-icon-circle-plus-outline" :label="$t('user.create')" @click="create" />
<fu-table-button v-permission="['user:add']" icon="el-icon-circle-plus-outline" :label="$t('user.create')" @click="create" />
</template>
<el-table-column type="selection" fix />
@ -157,7 +157,7 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { userLists, addUser, editUser, delUser, editPassword, editStatus } from '@/api/system/user'
import { allRoles } from '@/api/system/role'
import { getDeptTree } from '@/api/system/dept'
import { getDeptTree, treeByDeptId } from '@/api/system/dept'
export default {
@ -168,9 +168,11 @@ export default {
columns: [],
buttons: [
{
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit,
show: checkPermission(['user:edit'])
}, {
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this.del
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this.del,
show: checkPermission(['user:del'])
}, {
label: this.$t('member.edit_password'), icon: 'el-icon-s-tools', type: 'danger', click: this.editPassword,
show: checkPermission(['user:editPwd'])
@ -306,14 +308,20 @@ export default {
},
create() {
this.depts = null
this.formType = 'add'
this.form = Object.assign({}, this.defaultForm)
this.dialogVisible = true
},
edit(row) {
this.depts = null
this.formType = 'modify'
this.dialogVisible = true
this.form = Object.assign({}, row)
if (this.form.deptId === 0) {
this.form.deptId = null
}
this.initDeptTree()
},
editPassword(row) {
this.editPasswordVisible = true
@ -364,6 +372,7 @@ export default {
})
},
handleClose() {
this.depts = null
this.formType = 'add'
this.form = {}
this.editPasswordVisible = false
@ -376,12 +385,30 @@ export default {
this.$success(this.$t('commons.modify_success'))
})
},
initDeptTree() {
treeByDeptId(this.form.deptId || 0).then(res => {
const results = res.data.map(node => {
if (node.hasChildren && !node.children) {
node.children = null
}
return node
})
this.depts = results
})
},
//
loadDepts({ action, parentNode, callback }) {
if (action === LOAD_ROOT_OPTIONS) {
if (action === LOAD_ROOT_OPTIONS && !this.form.deptId) {
const _self = this
!this.depts && getDeptTree('0').then(res => {
_self.depts = res.data.map(node => _self.normalizer(node))
treeByDeptId(0).then(res => {
const results = res.data.map(node => {
if (node.hasChildren && !node.children) {
node.children = null
}
return node
})
_self.depts = results
callback()
})
}