作者 小范

配置数据权限功能完善

... ... @@ -45,3 +45,21 @@ export const updateRolePerm = params => { return axios({
'Content-Type': 'application/json;charset=UTF-8'
}
})};
//获取已有的数据权限
export const roleDataPermGet = params => { return axios({
method: 'POST',
url: `${base}/roleDataPermGet`,
data: params,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})};
//提交数据权限
export const dataPermSet = params => { return axios({
method: 'POST',
url: `${base}/dataPermSet`,
data: params,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})};
... ...
... ... @@ -187,26 +187,18 @@
</div>
</el-tab-pane>
<el-tab-pane label="数据权限" name="second">
<!-- <el-row>-->
<!-- <el-col :span="4" >-->
<!-- <el-button type="primary" @click.native="treeMerges(false)">合并节点</el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="4">-->
<!-- <el-button type="success" @click.native="treeMerges(true)">展开节点</el-button>-->
<!-- </el-col>-->
<!-- </el-row>-->
<el-divider></el-divider>
<el-form :model="permForms" style="width: 95%" ref="permForm">
<el-tree :data="departmentNameList" :props="treeDefaultPropss"
@check="clickDeal"
<el-tree :data="departmentList" :props="treeDefaultPropss"
@check="dataPermTreeClickDeal"
:default-expand-all = "treeExpands"
show-checkbox highlight-current
node-key="dataPermId" ref="trees">
node-key="data_perm_id" ref="trees">
</el-tree>
</el-form>
<div align="center" class="dialog-footer" style="margin-bottom: 20px">
<el-button @click.native="PermFormVisible = false">取消</el-button>
<el-button type="primary" :loading="addLoading">提交</el-button>
<el-button type="primary" @click.native="setDataPerm" :loading="addLoading">提交</el-button>
</div>
</el-tab-pane>
</el-tabs>
... ... @@ -218,12 +210,14 @@
<script>
import util from '../../common/js/util'
import NProgress from 'nprogress'
import { getList, remove, batchRemove, edit, add, updateRolePerm } from '../../api/role_api';
import { getList, remove, batchRemove, edit, add, updateRolePerm ,roleDataPermGet,dataPermSet} from '../../api/role_api';
import { getList as getDepartmentList } from '@/api/user/data_perm_api.js'
// import { getList as getDepartmentList} from '../../api/department';
import { getList as permList } from '../../api/perm_api';
import moment from 'moment'
import {selectList} from "../../api/consigner/vehicle";
import {addTrans} from "../../api/trn";
export default {
name:'Role',
data() {
... ... @@ -260,13 +254,14 @@
},
treeDefaultPropss: {
children: 'children',
label: 'perm_des',
label: 'perm_name',
},
treeExpand: true,
treeExpands: true,
roles: [],
permissons: [],
departmentNameList:[],
departmentList:[],
currentRolePermList: [],
permIds: [],
permIdss: [],
total: 0,
... ... @@ -314,11 +309,8 @@
permissions: []
},
permForms: {
roleId: 1,
description: '',
roleName: '',
roleSign: 1,
departmentNameList: []
roleId: -1,
permissionIds: []
},
}
... ... @@ -394,7 +386,6 @@
});
},
//获取数据权限列表
// getdepartmentNames() {
//
... ... @@ -428,9 +419,8 @@
};
getDepartmentList(para).then(res => {
this.$message.success('获取列表成功')
this.departmentNameList = res.list
console.log(this.departmentNameList);
// this.total = res.total
this.departmentList = res.list
// console.log(this.departmentList);
}).catch(error => {
this.$message.error(error)
})
... ... @@ -497,12 +487,17 @@
// 配置权限管理
setPerm: function (index, row) {
this.PermFormVisible = true;
this.activeName= 'first';
//获取接口权限
this.getPermList();
//获取数据权限信息
this.getRoleDataPerm(row.roleId);
var _this = this;
this.permIds = [];
this.permForm = Object.assign({}, row);
let rolePerms = this.permForm.permissions;
if (util.checkNull(rolePerms)){
this.permForms.roleId = this.permForm.roleId;
if (util.checkNull(rolePerms)){
rolePerms.forEach(function (perm,v_index,v_arr) {
if(util.checkNull(perm)){
_this.permIds[v_index] = perm.permissionId;
... ... @@ -514,26 +509,68 @@
this.$refs.tree.setCheckedKeys(this.permIds);
});
},
//获取已增加数据权限的数据
getRoleDataPerm(roleId) {
const _this = this
roleDataPermGet({roleId:roleId}).then((response) => {
const res = response.data
// console.log(res)
if (res.code !== '200') {
return _this.$message.error('获取已有的数据权限,失败!')
}else {
// 获取列表数据
if (res.data){
_this.currentRolePermList = res.data.dataPermissions;
}else{
_this.currentRolePermList = [];
}
// console.log(this.data_perm_id)
_this.$message.success('获取已有的数据权限,成功!')
}
}).catch(error => {
// 关闭加载
_this.$message.error(error.toString())
})
},
// 配置数据权限
handleClick(tab, row) {
handleClick: function (tab, index,row) {
let _this = this;
this.permForms.permissionIds = [];
if (tab.name === 'second'){
this.getDataList();
var _this = this;
this.permIdss = [];
this.permForms = Object.assign({}, row);
let rolePermss = this.permForms.departmentNameList;
if (util.checkNull(rolePermss)){
rolePermss.forEach(function (perm,v_index,v_arr) {
if(util.checkNull(perm)){
_this.permIdss[v_index] = perm.dataPermId;
}
});
if (this.currentRolePermList && this.currentRolePermList.length>0){
this.currentRolePermList.forEach((v,i) =>{
_this.permForms.permissionIds[i]=v.data_perm_id;
})
}
this.$nextTick(() => {
//反向适配
this.$refs.trees.setCheckedKeys(this.permIdss);
});
}
this.$nextTick(() => {
//反向适配
this.$refs.trees.setCheckedKeys(this.permForms.permissionIds);
});
},
//提交数据权限
setDataPerm(){
let _this = this;
if (this.currentRolePermList && this.currentRolePermList.length>0){
this.currentRolePermList.forEach((v,i) =>{
_this.permForms.permissionIds[i]=v.data_perm_id;
})
}
dataPermSet(this.permForms).then((response) => {
const res = response.data
// 添加失败
if (res.code !== '200') {
// 关闭加载
return this.$message.error(res.msg)
}
// 添加,成功
this.$message.success(res.msg)
// 隐藏对话框
this.PermFormVisible = false;
}).catch(error => {
this.$message.error(error.toString())
})
},
//显示新增界面,每次点开初始化数据
handleAdd: function (index,row) {
... ... @@ -751,10 +788,15 @@
// this.uniteParentSame(currentObj.id,treeStatus)
// }
}
}
},
dataPermTreeClickDeal: function (currentObj, treeStatus) {
this.permForms.permissionIds.push(currentObj.data_perm_id);
},
},
mounted() {
this.getRoles();
this.getDataList();
let _this = this;
document.onkeydown = function (e) {
let key = window.event.keyCode;
... ... @@ -763,8 +805,6 @@
}
};
this.isExpansion=true;
// this.getdepartmentNames();
}
}
... ... @@ -776,6 +816,9 @@
<style lang="scss">
.v-modal{
z-index:-2000;
}
/*//一级节点选择器*!*!*/
.el-tree-node>.el-tree-node__content {
font-weight: 900;
... ...