<template>
|
<div class="menuSettings_box">
|
<div class="menuSettings_tree">
|
<div class="content_left_box subpage_Div content-border">
|
<My-bread :list="[
|
`${$t('operatManage.operatManage')}`,
|
`${$t('operatManage.RoleResAuthorization')}`,
|
]"></My-bread>
|
<el-divider />
|
<div style="height: 90%; overflow-y: auto">
|
<el-tree
|
:data="depList"
|
:props="defaultProps"
|
:show-checkbox="false"
|
:check-on-click-node="true"
|
:check-strictly="true"
|
node-key="id"
|
@check="treeCheck"
|
ref="treeForm"
|
:default-expanded-keys="[1]"
|
>
|
</el-tree>
|
</div>
|
</div>
|
<div class="content_box subpage_Div content-border">
|
<div style="
|
font-size: 14px;
|
color: #216fe6;
|
line-height: 1;
|
cursor: text;
|
position: relative;
|
top: 10px;
|
margin-left: 10px;
|
">
|
{{ $t('operatManage.UserRoleAuthorizationObj.RoleTable') }}
|
</div>
|
<el-divider />
|
<el-table
|
:data="tableData"
|
style="width: 100%"
|
border
|
@row-click="singleElection"
|
highlight-current-row
|
height="calc(100% - 80px)"
|
>
|
<el-table-column
|
align="center"
|
width="55"
|
row-key="id"
|
>
|
<template slot-scope="scope">
|
<el-radio
|
class="radio"
|
v-model="templateSelection"
|
:label="scope.row.id"
|
> </el-radio>
|
</template>
|
</el-table-column>
|
<el-table-column
|
align="center"
|
type="index"
|
:label="$t('dataManage.styleObj.index')"
|
/>
|
<el-table-column
|
prop="name"
|
:label="$t('operatManage.UserRoleAuthorizationObj.name')"
|
>
|
</el-table-column>
|
</el-table>
|
<div
|
style="text-align: center; margin-top: 10px"
|
class="pagination_box"
|
>
|
<el-pagination
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
:current-page="listData.pageIndex"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="userlistData.pageSize"
|
layout="prev, pager, next"
|
:total="count"
|
>
|
</el-pagination>
|
</div>
|
</div>
|
<div class="content_box subpage_Div content-border">
|
<div style="
|
font-size: 14px;
|
color: #216fe6;
|
line-height: 1;
|
cursor: text;
|
position: relative;
|
top: 0px;
|
margin-left: 10px;
|
display: flex;
|
align-items: center;
|
">
|
<span>
|
{{ $t('operatManage.UserRoleAuthorizationObj.ResTable') }}</span>
|
<div
|
class="btn"
|
style="margin-left: auto"
|
>
|
<el-button
|
v-if="menuStatus.insert"
|
type="success"
|
icon="el-icon-circle-plus-outline"
|
size="small"
|
:disabled="roleid == null ? true : false"
|
@click="adduser"
|
>{{
|
$t('operatManage.UserRoleAuthorizationObj.Added')
|
}}</el-button>
|
<el-button
|
v-if="menuStatus.delete"
|
type="danger"
|
icon="el-icon-delete"
|
size="small"
|
@click="deletesUser"
|
:disabled="roleid == null ? true : false"
|
>{{
|
$t('operatManage.UserRoleAuthorizationObj.delete')
|
}}</el-button>
|
</div>
|
</div>
|
<el-divider class="divider" />
|
<el-tree
|
:data="Layertree"
|
show-checkbox
|
node-key="layerid"
|
ref="layerFrom"
|
:props="defaultLayerrops"
|
accordion
|
:default-expanded-keys="[1]"
|
>
|
</el-tree>
|
</div>
|
</div>
|
|
<el-dialog
|
:title="$t('operatManage.UserRoleAuthorizationObj.Added')"
|
:visible.sync="dialogTableVisible"
|
>
|
<el-table
|
:data="gridData"
|
height="40vh"
|
@selection-change="addhandleSelectionChange"
|
>
|
<el-table-column
|
type="selection"
|
width="55"
|
> </el-table-column>
|
<el-table-column
|
align="center"
|
type="index"
|
:label="$t('dataManage.styleObj.index')"
|
/>
|
<el-table-column
|
prop="name"
|
:label="$t('operatManage.UserRoleAuthorizationObj.name')"
|
>
|
</el-table-column>
|
<el-table-column
|
prop="server"
|
:label="$t('operatManage.UserRoleAuthorizationObj.server')"
|
>
|
</el-table-column>
|
</el-table>
|
<div
|
style="margin-top: 20px; text-align: center"
|
class="pagination_box"
|
>
|
<el-pagination
|
@size-change="addhandleSizeChange"
|
@current-change="addhandleCurrentChange"
|
:current-page="addlistData.pageIndex"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="addlistData.pageSize"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="addcount"
|
>
|
</el-pagination>
|
</div>
|
<div
|
slot="footer"
|
class="dialog-footer"
|
>
|
<el-button
|
size="small"
|
@click="dialogTableVisible = false"
|
>{{
|
$t('dataManage.dictionaryManageObj.cancel')
|
}}</el-button>
|
<el-button
|
size="small"
|
type="primary"
|
@click="addConfirm"
|
>{{ $t('dataManage.dictionaryManageObj.confirm') }}</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import MyBread from '../../components/MyBread.vue';
|
import {
|
queryDepTree,
|
select_Role_ByPageAndCount,
|
|
roleResInserts,
|
|
roleLayer_selectResByRole,
|
roleLayer_inserts,
|
roleLayer_deletes
|
} from '../../api/api';
|
export default {
|
//import引入的组件需要注入到对象中才能使用
|
components: {
|
MyBread,
|
},
|
|
data() {
|
return {
|
menuStatus: {
|
delete: false,
|
insert: false,
|
update: false,
|
},
|
addcount: 0,
|
gridData: [],
|
addlistData: {
|
pageIndex: 1,
|
pageSize: 10,
|
},
|
dialogTableVisible: false,
|
usertableData: [],
|
userlistData: {
|
pageIndex: 1,
|
pageSize: 10,
|
},
|
usercount: 0,
|
tableData: [],
|
// 当前选择的行的id
|
templateSelection: '',
|
// 当前选择的行的数据
|
checkList: [],
|
defaultLayerrops: {
|
children: "children",
|
label: "cnName",
|
},
|
defaultProps: {
|
children: 'children',
|
label: 'name',
|
},
|
oriData: [], //原始树数据
|
depList: [], //el树数据
|
backUpData: {},
|
formLabelWidth: '170px',
|
listData: {
|
pageIndex: 1,
|
pageSize: 10,
|
},
|
count: 0,
|
usermultipleSelection: [],
|
debid: null,
|
roleid: null,
|
addmultipleSelection: [],
|
layerData: [],
|
layeroption: [],
|
Layertree: []
|
|
};
|
},
|
methods: {
|
addConfirm() {
|
this.$confirm('确定是否新增', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then(async () => {
|
let arr = [];
|
this.addmultipleSelection.forEach((e) => {
|
arr.push({ resid: e.id, roleid: this.roleid });
|
});
|
const data = await roleResInserts(arr);
|
if (data.code !== 200) {
|
return this.$message.error('新增失败');
|
}
|
|
this.$message({
|
type: 'success',
|
message: '新增成功!',
|
});
|
this.dialogTableVisible = false;
|
this.getuserList();
|
})
|
.catch(() => { });
|
},
|
async adduser() {
|
var val = this.$refs.layerFrom.getCheckedNodes(false, true); // 利用这个方法就可以获取到子节点+父节点)
|
|
var std = [];
|
for (var i in val) {
|
if (val[i].id == 0) {
|
val[i].roleid = this.roleid
|
std.push(val[i])
|
}
|
}
|
if (std.length == 0) {
|
return
|
}
|
|
const data = await roleLayer_inserts(std);
|
|
if (data.code != 200) {
|
this.$message.error('授权失败');
|
} else {
|
this.$message({
|
type: 'success',
|
message: '授权成功!',
|
});
|
}
|
this.getuserList();
|
// this.dialogTableVisible = true;
|
// this.getadduserList();
|
},
|
//用户删除
|
async deletesUser() {
|
var val = this.$refs.layerFrom.getCheckedNodes(false, true); // 利用这个方法就可以获取到子节点+父节点)
|
var std = [];
|
for (var i in val) {
|
if (val[i].id > 0) {
|
std.push(val[i].id)
|
}
|
}
|
var res = this.layeroption;
|
var arr = [];
|
for (var i in res) {
|
if (res[i].id > 0 && std.indexOf(res[i].id) == -1) {
|
arr.push(res[i].id)
|
}
|
}
|
if (arr.length == 0) {
|
return
|
}
|
const data = await roleLayer_deletes({ ids: arr.toString() });
|
if (data.code != 200) {
|
this.$message.error('授权失败');
|
} else {
|
this.$message({
|
type: 'success',
|
message: '授权成功!',
|
});
|
}
|
this.getuserList()
|
// let arr = [];
|
// this.usermultipleSelection.forEach((e) => {
|
// arr.push(e.id);
|
// });
|
// this.$confirm('此操作将永久删除该权限, 是否继续?', '提示', {
|
// confirmButtonText: '确定',
|
// cancelButtonText: '取消',
|
// type: 'warning'
|
// }).then(async () => {
|
// const data = await roleResDeletes({ ids: arr.toString() });
|
// if (data.code == 200) {
|
// this.InsertFormdialog = false;
|
// this.$message({
|
// message: '删除成功!',
|
// type: 'success',
|
// });
|
// this.getuserList();
|
// } else {
|
// this.$message({
|
// message: '删除失败!',
|
// type: 'warning',
|
// });
|
// }
|
// }).catch(() => {
|
// this.$message({
|
// type: 'info',
|
// message: '已取消删除'
|
// });
|
// });
|
|
},
|
//用户表多选
|
handleSelectionChange(val) {
|
this.usermultipleSelection = val;
|
},
|
//新增用户表多选
|
addhandleSelectionChange(val) {
|
this.addmultipleSelection = val;
|
},
|
// 新增用户表分页
|
addhandleSizeChange(val) {
|
this.addlistData.pageSize = val;
|
this.getadduserList();
|
},
|
// 新增用户表分页
|
addhandleCurrentChange(val) {
|
this.addlistData.pageIndex = val;
|
this.getadduserList();
|
},
|
// 用户表分页
|
userhandleSizeChange(val) {
|
this.userlistData.pageSize = val;
|
this.getuserList();
|
},
|
// 用户表分页
|
userhandleCurrentChange(val) {
|
this.userlistData.pageIndex = val;
|
this.getuserList();
|
},
|
// 角色表分页
|
handleSizeChange(val) {
|
this.listData.pageSize = val;
|
this.getRole();
|
},
|
// 角色表分页
|
handleCurrentChange(val) {
|
this.listData.pageIndex = val;
|
this.getRole();
|
},
|
//获取资源列表
|
async getlayerTree() {
|
// this.layerData = []
|
// const data = await res_selectAll();
|
// if (data.code != 200) {
|
// return this.$message.error("图层列表查询失败");
|
// }
|
// var val = this.setTreeData(data.result);
|
// val.sort(function (a, b) {
|
// return a.sort - b.sort
|
// })
|
// this.layerData = val
|
},
|
setTreeData(source) {
|
let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
|
return cloneData.filter((father) => {
|
// 循环所有项
|
let branchArr = cloneData.filter((child) => father.layerid == child.pid); // 对比ID,分别上下级菜单,并返回数据
|
branchArr.length > 0 ? (father.children = branchArr) : ""; // 给父级添加一个children属性,并赋值
|
// 属于同一对象问题,例如:令 a=b、c=1 ,然后再令 b.c=c , 那么 a.c=b.c=c=1 ;同理,后续令 c.d=2 ,那么 a.c.d 也是=2;
|
// 由此循环多次后,就能形成相应的树形数据结构
|
return father.pid == 0; // 返回一级菜单
|
});
|
},
|
// 角色单选
|
singleElection(row) {
|
this.templateSelection = row.id;
|
this.checkList = this.tableData.filter((item) => item.id === row.id);
|
this.userlistData.roleid = row.id;
|
this.roleid = row.id;
|
this.getuserList();
|
},
|
// 部门请求
|
async getMenuTree() {
|
//获取目录树最大ID,新建节点使用
|
const data = await queryDepTree();
|
|
if (data.code !== 200) {
|
return this.$message.error('请求单位报错');
|
}
|
this.depList = this.treeData(data.result);
|
},
|
treeData(source) {
|
let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
|
return cloneData.filter((father) => {
|
// 循环所有项
|
let branchArr = cloneData.filter((child) => father.id == child.pid); // 对比ID,分别上下级菜单,并返回数据
|
branchArr.length > 0 ? (father.children = branchArr) : ''; // 给父级添加一个children属性,并赋值
|
return father.pid == 0; // 返回一级菜单
|
});
|
},
|
// 部门树单选
|
treeCheck(node, list) {
|
//node 该节点所对应的对象、list 树目前的选中状态对象
|
//选中事件在选中后执行,当lis中有两个选中时,使用setCheckedKeys方法,选中一个节点
|
|
if (list.checkedNodes.length > 0) {
|
this.listData.depid = node.id;
|
this.debid = node.id;
|
this.getRole();
|
if (list.checkedKeys.length == 2) {
|
//单选实现
|
this.$refs.treeForm.setCheckedKeys([node.id]);
|
}
|
} else {
|
this.debid = null;
|
this.roleid = null;
|
this.tableData = [];
|
this.usertableData = [];
|
}
|
},
|
async getadduserList() {
|
// this.addlistData.roleid = this.roleid;
|
|
// // this.addlistData.debid = this.debid;
|
// const data = await resSelectCountForRole(this.addlistData);
|
// if (data.code !== 200) {
|
// return this.$message.error('新增资源列表请求错误');
|
// }
|
|
// this.gridData = data.result;
|
// this.addcount = data.count;
|
|
|
},
|
// 用户表请求
|
async getuserList() {
|
this.Layertree = [];
|
this.layeroption = [];
|
|
const data = await roleLayer_selectResByRole({ roleid: this.userlistData.roleid });
|
if (data.code !== 200) {
|
return this.$message.error('根据ID查询资源失败');
|
}
|
var std = [];
|
this.layeroption = data.result;
|
for (var i in data.result) {
|
if (data.result[i].id > 0 && data.result[i].isLayer != 0) {
|
std.push(data.result[i].layerid)
|
}
|
}
|
var val = this.setTreeData(data.result);
|
|
|
this.Layertree = val
|
this.$refs.layerFrom.setCheckedKeys(std);
|
},
|
// 角色表请求
|
async getRole() {
|
const data = await select_Role_ByPageAndCount(this.listData);
|
if (data.code !== 200) {
|
return this.$message.error('用户角色请求错误');
|
}
|
this.tableData = data.result;
|
this.count = data.count;
|
if (data.result == null) {
|
this.usertableData = [];
|
this.usercount = 0;
|
}
|
},
|
showPermsMenu(res) {
|
switch (res.tag) {
|
case '/delete':
|
this.menuStatus.delete = true;
|
break;
|
case '/insert':
|
this.menuStatus.insert = true;
|
break;
|
case '/update':
|
this.menuStatus.update = true;
|
break;
|
}
|
},
|
},
|
created() {
|
var val = this.$store.state.currentPerms;
|
var permsEntity = this.$store.state.permsEntity;
|
for (var i = 0; i < permsEntity.length; i++) {
|
if (permsEntity[i].perms == val) {
|
this.showPermsMenu(permsEntity[i]);
|
}
|
}
|
this.getMenuTree();
|
// this.getlayerTree();
|
},
|
};
|
</script>
|
<style lang="less" scoped>
|
//@import url(); 引入公共css类
|
.menuSettings_box {
|
height: calc(100% - 20px);
|
//height: 98%;
|
width: 98%;
|
padding: 10px 1%;
|
|
.menuSettings_tree {
|
width: 100%;
|
height: 100%;
|
display: flex;
|
justify-content: space-around;
|
.content_left_box {
|
padding: 10px;
|
width: 20%;
|
height: calc(100% - 20px);
|
border-radius: 5px;
|
}
|
.content_box {
|
padding: 10px;
|
width: 36%;
|
height: calc(100% - 20px);
|
border-radius: 5px;
|
}
|
.divider {
|
margin-top: 8px;
|
}
|
}
|
}
|
.el-table,
|
.el-table /deep/ .el-table__expanded-cell {
|
background-color: transparent !important;
|
}
|
.el-table /deep/ th,
|
.el-table /deep/ tr {
|
background-color: transparent !important;
|
}
|
</style>
|