提交 acd03eba 编写于 作者: laizhilong's avatar laizhilong

角色权限关系自定义视图

上级 9af176a3
.sys-role-permissioncustom-view{
.sys-permissionmpickup-view{
position: relative;
.tree-right-menu {
.ivu-divider-horizontal {
width: calc(100% - 32px);
min-width: calc(100% - 32px);
margin: 0 auto;
}
.ivu-dropdown-item {
position: relative; position: relative;
padding-left: 32px;
> i {
position: absolute;
left: 16px;
top: 10px;
}
.ivu-icon-ios-arrow-forward {
left: initial;
right: 4px;
}
}
.ivu-dropdown {
.ivu-select-dropdown {
margin: 0;
}
}
}
.text{
font-weight: 700;color: #303133;font-size: 15px;margin-left:10px;margin-top:20px;
}
.col{
display: inline-block;
width: 400px;
}
.search{
width:200px;margin-left:20px;margin-top:30px;margin-bottom:20px;
}
.save{
margin-top:30px;margin-bottom:20px;margin-left:40px;
}
.roll{
height:calc(100vh - 445px) ;overflow:hidden;overflow-x: hidden;overflow-y: auto;
}
.tre{
margin-left:20px;
}
}
.pickup-view {
>.translate-contant {
flex-grow: 1;
display: flex;
justify-content: flex-end;
height: calc(100% - 64px);
.translate-buttons {
width: 80px;
display: flex;
align-items: center;
text-align: center;
button {
margin-bottom: 5px;
}
}
.left, .right {
width: 300px;
}
.right {
border: 1px solid #e9e9e9;
.mpicker-select {
font-family: helvetica, sans-serif;
font-size: 16px;
text-align: justify;
word-spacing: -3.8pt;
line-height: 1.6;
font-weight: bold;
word-spacing: 10px;
//height: 100%;
overflow: auto;
}
.mpicker-select > div {
padding: 3px 10px;
font-size: 14px;
color: rgba(0, 0, 0, 0.85);
font-weight: initial;
cursor: pointer;
min-height: 28px;
border: 1px solid #e9e9e9;
margin: 4px 4px;
transition: all .3s;
}
.mpicker-select > div:hover {
background: #ecf6fd;
}
.mpicker-select > .select{
color: #108ee9;
background: #ecf6fd;
}
}
.center{
width: calc(100% - 380px);
.pickupviewpanel {
width: 100%;
//height: 100%;
}
}
}
>.footer {
height: 64px;
}
} }
// this is less
<template>
<div class="view-container dempickupview sys-permissionmpickup-view">
<card class='view-card view-no-caption view-no-toolbar' :dis-hover="true" :padding="0" :bordered="false">
<div class="content-container pickup-view">
<div class="translate-contant">
<!--应用菜单-->
<div class="center" :style="{width : '33%',border:'0px solid red' }">
<context-menu-container class='design-tree-container'>
<div>
<div class="text">应用菜单</div>
<div class="roll">
<el-tree
class="tre"
:data="this.CDdata"
ref="CDtree"
show-checkbox
node-key="id"
:default-expand-all="false"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
<!--数据能力-->
<div class="center" :style="{width : '33%',border:'0px solid red' }">
<context-menu-container class='design-tree-container'>
<div>
<div class="text">数据能力</div>
<div class="roll">
<el-tree
class="tre"
:data="this.QXdata"
ref="QXtree"
show-checkbox
node-key="id"
:default-expand-all="false"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
<!--统一资源-->
<div class="center" :style="{width : '33%',border:'0px solid red' }">
<context-menu-container class='design-tree-container'>
<div>
<div class="text">统一资源</div>
<div class="roll">
<el-tree
class="tre"
:data="this.ZYdata"
ref="ZYtree"
show-checkbox
node-key="id"
:default-expand-all="false"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
</div>
<div>
<!--操作按钮-->
<card :dis-hover="true" :bordered="false" class="footer">
<row :style="{ textAlign: 'right',border:'0px solid red' }">
<i-button type="primary" :disabled="this.selectData.length > 0 ? false : true"
@click="onClickOk">{{this.containerModel.view_okbtn.text}}
</i-button>
</row>
</card>
</div>
</div>
</card>
</div>
</template>
<script lang='tsx'> <script lang='tsx'>
import { Component } from 'vue-property-decorator'; import {Component, Vue} from 'vue-property-decorator';
import SYS_ROLE_PERMISSIONCustomViewBase from './sys-role-permissioncustom-view-base.vue'; import view_pickupviewpanel
from '@widgets/sys-permission/mpickup-viewpickupviewpanel-pickupviewpanel/mpickup-viewpickupviewpanel-pickupviewpanel.vue';
import ContextMenuContainer from "@components/context-menu-container/context-menu-container.vue";
@Component({ @Component({
components: { components: {
ContextMenuContainer,
view_pickupviewpanel,
}, },
beforeRouteEnter: (to: any, from: any, next: any) => { beforeRouteEnter: (to: any, from: any, next: any) => {
next((vm: any) => { next((vm: any) => {
vm.$store.commit('addCurPageViewtag', { fullPath: to.fullPath, viewtag: vm.viewtag }); vm.$store.commit('addCurPageViewtag', {fullPath: to.fullPath, viewtag: vm.viewtag});
}); });
}, },
}) })
export default class SYS_ROLE_PERMISSIONCustomView extends SYS_ROLE_PERMISSIONCustomViewBase { export default class SYS_ROLE_PERMISSIONCustomView extends Vue {
/*应用菜单数据*/
protected CDdata: any = [];
/*数据能力数据*/
protected QXdata: any = [];
/*统一资源数据*/
protected ZYdata: any = [];
/*默认选中节点*/
protected defaultCheckedNodes: any = [];
/**
* 树显示说明:子树为节点对象的children,节点标签为节点对象的label
*/
protected defaultProps: any = {
children: 'children',
label: 'label'
}
/**
* 选中数据
*/
protected selectData: any = {};
/**
* 初始选中的数据
*/
protected ininselectData: any = {};
/**
* 视图选中数据
*/
public viewSelections: any[] = [];
/**
* 父数据
*/
protected parentData: any = {};
/**
* 父数据主键
*/
protected srfparentkey: any;
/**
* vue 创建
*/
public created() {
const _this: any = this;
// 获取父数据
if (_this.$attrs && _this.$attrs.viewdata) {
_this.parentData = JSON.parse(_this.$attrs.viewdata);
}
if (_this.parentData && _this.parentData.sys_role) {
// console.log("父主键:" + _this.parentData.sys_role);
_this.srfparentkey = _this.parentData.sys_role;
}
}
/**
* vue 挂载
*/
public mounted() {
this.initTree();
}
/**
* 初始化树
*/
private initTree() {
const _this = this;
// get全部菜单和数据能力和统一资源的请求路径
const url = `sys_permissions/getallMenuAndPermissionAndUnires?roleid=` + _this.srfparentkey;
this.$http.get(url).then((response: any) => {
if (!response || response.status !== 200) {
this.$Notice.error({title: '错误', desc: response.message});
return;
} else {
// 给树赋值,数据结构在后台已经按照eltree格式化
_this.CDdata = response.data[0];
_this.QXdata = response.data[1];
_this.ZYdata = response.data[2];
_this.defaultCheckedNodes = response.data[3];
// 设置默认选中节点,即当前角色所有权限
this.$nextTick(()=>{
const CDtree: any = this.$refs.CDtree;
const QXtree: any = this.$refs.QXtree;
const ZYtree: any = this.$refs.ZYtree;
CDtree.setCheckedNodes(_this.defaultCheckedNodes);
QXtree.setCheckedNodes(_this.defaultCheckedNodes);
ZYtree.setCheckedNodes(_this.defaultCheckedNodes);
// 保存初始选中的节点数据,便于后续保存时比较
const arr = CDtree.getCheckedNodes().concat(QXtree.getCheckedNodes()).concat(ZYtree.getCheckedNodes());
this.ininselectData = arr;
});
}
}).catch((e) => {
console.log(e);
});
}
} /**
* 处理选中节点
*/
protected handleCheckChange() {
// console.log("SYS_PERMISSIONMPickupView执行了handleCheckChange")
// 获取当前三棵树
const CDtree: any = this.$refs.CDtree;
const QXtree: any = this.$refs.QXtree;
const ZYtree: any = this.$refs.ZYtree;
// 获取选中状态的节点
const arr = CDtree.getCheckedNodes().concat(QXtree.getCheckedNodes()).concat(ZYtree.getCheckedNodes());
this.selectData = arr;
// console.log("选中的node:" + JSON.stringify(this.selectData));
}
/**
* 容器模型
*/
public containerModel: any = {
view_okbtn: {name: 'okbtn', type: 'button', text: '确定', disabled: true},
};
/**
* 确定
*/
public onClickOk(): void {
// 处理选中的数据
if (this.selectData && this.selectData.length > 0) {
// 判断选中的数据和初始数据
if (JSON.stringify(this.selectData) == JSON.stringify(this.ininselectData)) {
this.$emit('close', null);
return;
}
// 先删除当前角色的所有角色权限关系
let url = `sys_permissions/deleteRolePermissionByRoleid`;
let param = {roleid: this.srfparentkey};
this.$http.post(url,param).then((response: any) => {
if (!response || response.status !== 200) {
this.$Notice.error({title: '错误', desc: response.message});
return;
} else {
// 再重新添加新选中的权限
this.selectData.forEach((item: any) => {
let _itemTemp: any = JSON.parse(JSON.stringify(item));
let _item: any = {};
if (_itemTemp.sys_permissionId) {// 应用菜单
_item.srfdataaccaction = _itemTemp.sys_permissionId;
_item.srfkey = _itemTemp.sys_permissionId;
_item.sys_permission = _itemTemp.sys_permissionId;
_item.sys_permissionid = _itemTemp.sys_permissionId;
_item.srfmajortext = _itemTemp.label;
_item.sys_permissionname = _itemTemp.label;
Object.assign(_item, {_select: false})
this.viewSelections.push(_item);
} else {
if (!_itemTemp.children) {// 数据能力或者统一资源
_item.srfdataaccaction = _itemTemp.id;
_item.srfkey = _itemTemp.id;
_item.sys_permission = _itemTemp.id;
_item.sys_permissionid = _itemTemp.id;
_item.srfmajortext = _itemTemp.label;
_item.sys_permissionname = _itemTemp.label;
Object.assign(_item, {_select: false})
this.viewSelections.push(_item);
}
}
});
// 交给viewdataschange进行后续保存进库操作
// this.$emit('viewdataschange', this.viewSelections);
// this.$emit('close', null);
// 保存选中的权限信息
url = 'sys_permissions/saveRolePermissionByRoleid';
Object.assign(param,{roleid:this.srfparentkey, checkedNodes: this.viewSelections});
this.$http.post(url,param).then((response: any) => {
if (!(!response || response.status !== 200)) {
this.$Notice.success({title: '', desc: '操作成功!'});
} else {
this.$Notice.error({title: '错误', desc: response.message});
return;
}
}).catch((e) => {
console.log(e);
});
}
}).catch((e) => {
console.log(e);
});
} else {
this.$Notice.error({title: '错误', desc: '未选中数据!'});
}
}
}
</script> </script>
<style lang='less'>
@import './sys-role-permissioncustom-view';
</style>
\ No newline at end of file
package cn.ibizlab.core.extensions.service; package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.domain.SYS_ROLE_PERMISSION;
import cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService; import cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService;
import cn.ibizlab.core.uaa.service.ISYS_PSAPPMENUITEMService; import cn.ibizlab.core.uaa.service.ISYS_PSAPPMENUITEMService;
import cn.ibizlab.core.uaa.service.ISYS_ROLE_PERMISSIONService; import cn.ibizlab.core.uaa.service.ISYS_ROLE_PERMISSIONService;
...@@ -647,5 +648,22 @@ public class UAACoreService { ...@@ -647,5 +648,22 @@ public class UAACoreService {
isys_role_permissionService.removeByRoleid(roleid); isys_role_permissionService.removeByRoleid(roleid);
} }
/**
* 根据角色id保存选中的权限信息
* @param roleid
* @param checkedNodes
*/
public void saveRolePermissionByRoleid(String roleid, JSONArray checkedNodes) {
for (int i = 0; i < checkedNodes.size(); i++) {
JSONObject obj = checkedNodes.getJSONObject(i);
SYS_ROLE_PERMISSION rolePermission = new SYS_ROLE_PERMISSION();
rolePermission.setRoleid(roleid);
rolePermission.setPermissionid(obj.getString("sys_permissionid"));
isys_role_permissionService.save(rolePermission);
}
}
} }
...@@ -56,4 +56,28 @@ public class UAACoreResource { ...@@ -56,4 +56,28 @@ public class UAACoreResource {
return ResponseEntity.ok(resObj); return ResponseEntity.ok(resObj);
} }
/**
* 保存选中的权限信息
* @param param
* @return
*/
@PostMapping(value = "/sys_permissions/saveRolePermissionByRoleid")
public ResponseEntity<JSONObject> saveRolePermissionByRoleid(@RequestBody JSONObject param) {
JSONObject resObj = new JSONObject();
// 角色id
String roleid = param.getString("roleid");
if (StringUtils.isEmpty(roleid))
new BadRequestAlertException("操作失败,未获取到当前角色标识!","","");
// 选中的权限信息
JSONArray checkedNodes = param.getJSONArray("checkedNodes");
if (checkedNodes.size() > 0) {
// save操作
uaaCoreService.saveRolePermissionByRoleid(roleid, checkedNodes);
} else {
new BadRequestAlertException("操作失败,未获取到选中数据!","","");
}
return ResponseEntity.ok(resObj);
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册