<template>
|
<div class="menuSettings_box">
|
<!-- 角色,单位 -->
|
<div class="menuSettings_tree">
|
<div class="content_box subpage_Div content-border">
|
<My-bread :list="[
|
`${$t('operatManage.operatManage')}`,
|
`${$t('operatManage.RoleMenuAuthorization')}`,
|
]"></My-bread>
|
<el-divider />
|
<el-form
|
ref="form"
|
:model="selFrom"
|
>
|
<el-form-item :label="$t('userManage.roleMenuAuth.name')">
|
<el-select
|
:popper-append-to-body="false"
|
ref="multiSelect"
|
style="width: 300px;"
|
v-model="selFrom.name"
|
size="small"
|
:placeholder="$t('userManage.roleMenuAuth.nameHolder')"
|
@change="chooseCustom('multiSelect')"
|
>
|
<el-option
|
:value="selectTree"
|
style=" backgrond: transparent; height: 100%;"
|
disabled
|
>
|
<el-tree
|
:data="depList"
|
:props="defaultProps"
|
:check-on-click-node="true"
|
:check-strictly="true"
|
node-key="id"
|
ref="treeForm"
|
@node-click="addAdminHandleNodeClick"
|
:default-expanded-keys="[1]"
|
>
|
</el-tree>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
<el-table
|
:data="tableData"
|
style="width: 100%"
|
border
|
@row-click="singleElection"
|
highlight-current-row
|
height="calc(100% - 135px)"
|
>
|
<el-table-column
|
align="center"
|
width="55"
|
>
|
<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>
|
<div class="content_box subpage_Div content-border">
|
<div style="
|
font-size: 14px;
|
color: #216fe6;
|
line-height: 1;
|
cursor: text;
|
position: relative;
|
top: 5px;
|
margin-left: 10px;
|
display: flex;
|
align-items: center;
|
">
|
<span>
|
{{ $t('operatManage.UserRoleAuthorizationObj.menuTable') }}</span>
|
</div>
|
<el-divider />
|
|
<el-tree
|
:data="menuList"
|
:props="defaultMenuProps"
|
:show-checkbox="false"
|
:check-on-click-node="true"
|
:check-strictly="true"
|
node-key="id"
|
@check="menuTreeCheck"
|
ref="treeForm"
|
:default-expanded-keys="[1]"
|
>
|
</el-tree>
|
|
</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.PermissionTable')
|
}}</span>
|
<div
|
class="btn"
|
style="margin-left: auto"
|
>
|
<el-button
|
v-if="menuStatus.insert"
|
type="success"
|
icon="el-icon-circle-plus-outline"
|
size="small"
|
@click="adduser"
|
:disabled="menuid == null ? true : false"
|
>{{
|
$t('operatManage.UserRoleAuthorizationObj.Added')
|
}}</el-button>
|
<el-button
|
v-if="menuStatus.delete"
|
type="danger"
|
icon="el-icon-delete"
|
size="small"
|
@click="deletesUser"
|
:disabled="menuid == null ? true : false"
|
>{{
|
$t('operatManage.UserRoleAuthorizationObj.delete')
|
}}</el-button>
|
</div>
|
</div>
|
<el-divider class="divider" />
|
<el-table
|
:data="menuTableData"
|
border
|
style="width: 100%"
|
height="calc(100% - 85px)"
|
@selection-change="handleSelectionChange"
|
>
|
<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>
|
|
<div
|
style="margin-top: 10px; text-align: center"
|
class="pagination_box"
|
>
|
<el-pagination
|
@size-change="authhandleSizeChange"
|
@current-change="authhandleCurrentChange"
|
:current-page="rolMenuListData.pageIndex"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="rolMenuListData.pageSize"
|
layout="prev, pager, next"
|
:total="roleMenuCount"
|
>
|
</el-pagination>
|
</div>
|
</div>
|
|
</div>
|
|
<el-dialog
|
:title="$t('operatManage.UserRoleAuthorizationObj.Added')"
|
:visible.sync="dialogTableVisible"
|
:before-close="handleClose"
|
>
|
<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>
|
<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="handleClose"
|
>{{
|
$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,
|
selectMenuRecursives,
|
roleMenuAuthelectByPageForRole,
|
menuAuthSelectByPageForRole,
|
roleMenuAuthInserts,
|
roleMenuAuthDeletes,
|
} from '../../api/api';
|
export default {
|
//import引入的组件需要注入到对象中才能使用
|
components: {
|
MyBread,
|
},
|
|
data() {
|
return {
|
dialogTableVisible: false,
|
selFrom: { name: '' },
|
selectTree: '',
|
depList: [], //el树数据
|
defaultProps: {
|
children: 'children',
|
label: 'name',
|
}, //树绑定对象
|
defaultMenuProps: {
|
children: 'children',
|
label: 'cnName',
|
}, //菜单表绑定权限
|
depid: null, //单位ID
|
roleDepListData: {
|
pageIndex: 1,
|
pageSize: 10,
|
},
|
rolMenuListData: {
|
pageIndex: 1,
|
pageSize: 10,
|
},
|
addlistData: { pageIndex: 1, pageSize: 10 },
|
addcount: 0,
|
roleDepCount: 0,
|
roleMenuCount: 0,
|
roleDepCheckList: [],
|
|
tableData: [], //角色列表
|
templateSelection: '',
|
menuList: [],
|
roleid: null,
|
menuid: null,
|
menuTableData: [],
|
gridData: [],
|
addmultipleSelection: [],
|
usermultipleSelection: [],
|
menuStatus: {
|
delete: false,
|
insert: false,
|
update: false,
|
},
|
};
|
},
|
methods: {
|
async getDepTree() {
|
//获取目录树最大ID,新建节点使用
|
const data = await queryDepTree();
|
if (data.code !== 200) {
|
return this.$message.error('请求单位报错');
|
}
|
this.depList = this.treeData(data.result);
|
},
|
async getMenuTree() {
|
const data = await selectMenuRecursives({ name: menuStartName });
|
if (data.code !== 200) {
|
return this.$message.error('请求单位报错');
|
}
|
|
this.menuList = 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; // 返回一级菜单
|
});
|
},
|
//树选中节点
|
addAdminHandleNodeClick(e) {
|
this.roleDepCheckList = [];
|
this.templateSelection = '';
|
this.depid = e.id;
|
this.selFrom.name = e.name;
|
this.selectTree = e.name;
|
this.chooseCustom('multiSelect');
|
this.getRoleDep();
|
this.getMenuTree();
|
},
|
menuTreeCheck(node, list) {
|
if (list.checkedNodes.length > 0) {
|
if (this.roleid == null) return;
|
this.rolMenuListData.menuid = node.id;
|
this.menuid = node.id;
|
this.rolMenuListData.roleid = this.roleid;
|
this.getRoleMenu();
|
if (list.checkedKeys.length == 2) {
|
//单选实现
|
this.$refs.treeForm.setCheckedKeys([node.id]);
|
}
|
} else {
|
this.menuid = null;
|
}
|
},
|
async getRoleMenu() {
|
const data = await roleMenuAuthelectByPageForRole(this.rolMenuListData);
|
if (data.code !== 200) {
|
return this.$message.error('角色菜单请求错误');
|
}
|
this.menuTableData = data.result;
|
this.roleMenuCount = data.count;
|
},
|
async getRoleDep() {
|
this.roleDepListData.depid = this.depid;
|
const data = await select_Role_ByPageAndCount(this.roleDepListData);
|
if (data.code !== 200) {
|
return this.$message.error('用户角色请求错误');
|
}
|
this.tableData = data.result;
|
this.roleDepCount = data.count;
|
},
|
async getadduserList() {
|
this.addlistData.roleid = this.roleid;
|
this.addlistData.menuid = this.menuid;
|
const data = await menuAuthSelectByPageForRole(this.addlistData);
|
if (data.code !== 200) {
|
return this.$message.error('菜单权限列表请求错误');
|
}
|
this.gridData = data.result;
|
this.addcount = data.count;
|
},
|
singleElection(row) {
|
this.getMenuTree();
|
this.menuTableData = [];
|
this.roleMenuCount = 0;
|
this.templateSelection = row.id;
|
this.roleid = row.id;
|
|
this.roleDepCheckList = this.tableData.filter(
|
(item) => item.id === row.id
|
);
|
},
|
//下拉框选中后自动关闭
|
chooseCustom(refName) {
|
// this.$refs[refName] && this.$refs[refName].blur();
|
this.createTimer(this.autoCloseSelect, refName);
|
},
|
createTimer(callback, refName) {
|
const timer = setTimeout(() => {
|
callback(refName);
|
}, 50);
|
this.$once('hook:beforeDestroy', () => {
|
clearInterval(timer);
|
});
|
},
|
autoCloseSelect(refName) {
|
this.$refs[refName] && this.$refs[refName].blur();
|
},
|
dephandleSizeChange() {
|
this.roleDepListData.pageSize = val;
|
this.getDepTree();
|
},
|
dephandleCurrentChange() {
|
this.roleDepListData.pageIndex = val;
|
this.getDepTree();
|
},
|
authhandleSizeChange() {
|
this.roleDepListData.pageSize = val;
|
this.getRoleMenu();
|
},
|
authhandleCurrentChange() {
|
this.roleDepListData.pageIndex = val;
|
this.getRoleMenu();
|
},
|
// 新增用户表分页
|
addhandleSizeChange(val) {
|
this.addlistData.pageSize = val;
|
this.getadduserList();
|
},
|
// 新增用户表分页
|
addhandleCurrentChange(val) {
|
this.addlistData.pageIndex = val;
|
this.getadduserList();
|
},
|
addhandleSelectionChange(val) {
|
this.addmultipleSelection = val;
|
},
|
handleSelectionChange(val) {
|
this.usermultipleSelection = val;
|
},
|
adduser() {
|
this.dialogTableVisible = true;
|
this.getadduserList();
|
},
|
async deletesUser() {
|
let arr = [];
|
this.usermultipleSelection.forEach((e) => {
|
arr.push(e.id);
|
});
|
this.$confirm('此操作将永久删除该权限, 是否继续?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(async () => {
|
const data = await roleMenuAuthDeletes({ ids: arr.toString() });
|
if (data.code == 200) {
|
this.InsertFormdialog = false;
|
this.$message({
|
message: '删除成功!',
|
type: 'success',
|
});
|
this.getRoleMenu();
|
} else {
|
this.$message({
|
message: '删除失败!',
|
type: 'warning',
|
});
|
}
|
}).catch(() => {
|
this.$message({
|
type: 'info',
|
message: '已取消删除'
|
});
|
});
|
// const data = await roleMenuAuthDeletes({ ids: arr.toString() });
|
// if (data.code !== 200) {
|
// return this.$message.error('删除失败');
|
// }
|
// this.$message({
|
// message: '删除成功',
|
// type: 'success',
|
// });
|
// this.getRoleMenu();
|
},
|
addConfirm() {
|
this.$confirm('确定是否新增', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then(async () => {
|
let arr = [];
|
this.addmultipleSelection.forEach((e) => {
|
arr.push({ menuAuthId: e.id, roleid: this.roleid });
|
});
|
const data = await roleMenuAuthInserts(arr);
|
if (data.code !== 200) {
|
return this.$message.error('新增失败');
|
}
|
|
this.$message({
|
type: 'success',
|
message: '新增成功!',
|
});
|
this.dialogTableVisible = false;
|
this.getRoleMenu();
|
})
|
.catch(() => { });
|
},
|
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;
|
}
|
},
|
handleClose() {
|
this.$confirm("关闭后无法保存,是否关闭?")
|
.then((_) => {
|
this.dialogTableVisible = false
|
})
|
.catch((_) => { });
|
},
|
},
|
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.getDepTree();
|
this.getMenuTree();
|
},
|
};
|
</script>
|
<style lang="less" scoped>
|
//@import url(); 引入公共css类
|
.menuSettings_box {
|
//height: 98%;
|
|
height: calc(100% - 20px);
|
width: 98%;
|
padding: 10px 0.5%;
|
|
.menuSettings_tree {
|
display: flex;
|
justify-content: space-around;
|
width: 100%;
|
height: 100%;
|
.content_box {
|
padding: 10px;
|
width: 30%;
|
height: calc(100% - 20px);
|
//height: 94%;
|
overflow-y: auto;
|
overflow-x: hidden;
|
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>
|