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

根据角色id绘制选中树节点,确定操作时保存新选中节点

上级 8074c40b
......@@ -15,7 +15,7 @@
ref="CDtree"
show-checkbox
node-key="id"
:default-expanded-keys="this.CDdataexpandedKeys"
:default-expand-all="false"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
......@@ -37,7 +37,7 @@
ref="QXtree"
show-checkbox
node-key="id"
:default-expanded-keys="this.QXdataexpandedKeys"
:default-expand-all="false"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
......@@ -59,7 +59,7 @@
ref="ZYtree"
show-checkbox
node-key="id"
:default-expanded-keys="this.ZYdataexpandedKeys"
:default-expand-all="false"
highlight-current
:props="this.defaultProps"
@check-change="handleCheckChange"
......@@ -109,16 +109,12 @@
/*应用菜单数据*/
protected CDdata: any = [];
/*应用菜单数据默认展开节点*/
protected CDdataexpandedKeys: any = [];
/*数据能力数据*/
protected QXdata: any = [];
/*数据能力数据默认展开节点*/
protected QXdataexpandedKeys: any = [];
/*统一资源数据*/
protected ZYdata: any = [];
/*统一资源数据默认展开节点*/
protected ZYdataexpandedKeys: any = [];
/*默认选中节点*/
protected defaultCheckedNodes: any = [];
/**
* 树显示说明:子树为节点对象的children,节点标签为节点对象的label
......@@ -131,6 +127,10 @@
* 选中数据
*/
protected selectData: any = {};
/**
* 初始选中的数据
*/
protected ininselectData: any = {};
/**
* 视图选中数据
......@@ -156,8 +156,8 @@
_this.parentData = JSON.parse(_this.$attrs.viewdata);
}
if (_this.parentData && _this.parentData.srfparentkey) {
// console.log("父主键:" + _this.parentData.srfparentkey);
_this.srfparentkey = _this.parentData.srfparentkey;
// console.log("父主键:" + _this.srfparentkey);
}
}
......@@ -174,7 +174,7 @@
private initTree() {
const _this = this;
// get全部菜单和数据能力和统一资源的请求路径
const url = `sys_permissions/getallMenuAndPermissionAndUnires`;
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});
......@@ -184,28 +184,23 @@
_this.CDdata = response.data[0];
_this.QXdata = response.data[1];
_this.ZYdata = response.data[2];
// 树视图默认展开一级节点
if (_this.CDdata && _this.CDdata.length > 0) {
_this.CDdata.forEach((item: any, index: any) => {
if (item[index]) {
_this.CDdataexpandedKeys.push(item[index].id);
}
})
}
if (_this.QXdata && _this.QXdata.length > 0) {
_this.QXdata.forEach((item: any, index: any) => {
if (item[index]) {
_this.QXdataexpandedKeys.push(item[index].id);
}
})
}
if (_this.ZYdata && _this.ZYdata.length > 0) {
_this.ZYdata.forEach((item: any, index: any) => {
if (item[index]) {
_this.ZYdataexpandedKeys.push(item[index].id);
}
})
}
_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);
......@@ -217,7 +212,7 @@
*/
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;
......@@ -241,6 +236,20 @@
public onClickOk(): void {
// 处理选中的数据
if (this.selectData && this.selectData.length > 0) {
// 判断选中的数据和初始数据
if (JSON.stringify(this.selectData) == JSON.stringify(this.ininselectData)) {
this.$emit('close', null);
return;
}
// 先删除当前角色的所有角色权限关系
const url = `sys_permissions/deleteRolePermissionByRoleid`;
const 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 = {};
......@@ -266,12 +275,19 @@
}
}
});
}
// 交给viewdataschange进行后续保存进库操作
this.$emit('viewdataschange', this.viewSelections);
this.$emit('close', null);
}
}).catch((e) => {
console.log(e);
});
} else {
this.$emit('close', null);
}
}
/**
* 取消
......
......@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService;
import cn.ibizlab.core.uaa.service.ISYS_PSAPPMENUITEMService;
import cn.ibizlab.core.uaa.service.ISYS_ROLE_PERMISSIONService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
......@@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.validation.constraints.NotBlank;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -22,7 +24,8 @@ public class UAACoreService {
private ISYS_PERMISSIONService isys_permissionService;
@Autowired
private ISYS_PSAPPMENUITEMService isys_psappmenuitemService;
@Autowired
private ISYS_ROLE_PERMISSIONService isys_role_permissionService;
/**
* 获取应用菜单
*
......@@ -606,4 +609,43 @@ public class UAACoreService {
return array;
}
/**
* 根据角色id查询所有权限
* @return
* @param roleid
*/
public JSONArray getallPermissionByRoleid(@NotBlank(message = "roleid不允许为空") String roleid) {
JSONArray rolepermission = new JSONArray();
StringBuilder sql = new StringBuilder();
sql.append("select t.SYS_PERMISSIONID as permissionid,t.SYS_PERMISSIONNAME as permissionname,t1.PERMISSIONTYPE as permissiontype from ibzrole_permission t inner join ibzpermission t1 on t.SYS_PERMISSIONID=t1.SYS_PERMISSIONID where t1.enable='1' and t.sys_roleid='"+ roleid +"'");
List<JSONObject> select = isys_permissionService.select(sql.toString(),null);
for (JSONObject obj : select) {
String permissionid = obj.getString("permissionid");
String permissionname = obj.getString("permissionname");
String permissiontype = obj.getString("permissiontype");
JSONObject childNodeObj = new JSONObject();
// 应用菜单需要对权限id进行处理
if ("APPMENU".equals(permissiontype)){
String appmenu_permissionid = permissionid.substring(permissionid.lastIndexOf("-")+1, permissionid.length());
childNodeObj.put("id", appmenu_permissionid);
}else{
childNodeObj.put("id", permissionid);
}
childNodeObj.put("label", permissionname);
rolepermission.add(childNodeObj);
}
return rolepermission;
}
/**
* 根据角色id删除角色权限关系
* @param roleid
*/
public void clearRolePermissionByRoleid(String roleid) {
isys_role_permissionService.removeByRoleid(roleid);
}
}
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.extensions.service.UAACoreService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotBlank;
@RestController
......@@ -20,7 +25,7 @@ public class UAACoreResource {
* @return
*/
@GetMapping(value = "/sys_permissions/getallMenuAndPermissionAndUnires")
public ResponseEntity<JSONArray> getAllPermission() {
public ResponseEntity<JSONArray> getallMenuAndPermissionAndUnires(@Validated @NotBlank(message = "roleid不允许为空")@RequestParam("roleid") String roleid) {
JSONArray treeNode = new JSONArray();
// 获取应用菜单
treeNode.add(uaaCoreService.getAppMenu());
......@@ -28,8 +33,27 @@ public class UAACoreResource {
treeNode.add(uaaCoreService.getDEOppriv());
// 获取统一资源
treeNode.add(uaaCoreService.getUnires());
// 获取当前角色所有权限
treeNode.add(uaaCoreService.getallPermissionByRoleid(roleid));
return ResponseEntity.ok().body(treeNode);
}
/**
* 删除当前角色的所有角色权限关系
* @param param
* @return
*/
@PostMapping(value = "/sys_permissions/deleteRolePermissionByRoleid")
public ResponseEntity<JSONObject> deleteRolePermissionByRoleid(@RequestBody JSONObject param) {
JSONObject resObj = new JSONObject();
String roleid = param.getString("roleid");
if (StringUtils.isEmpty(roleid))
new BadRequestAlertException("操作失败,未获取到当前角色标识!","","");
uaaCoreService.clearRolePermissionByRoleid(roleid);
return ResponseEntity.ok(resObj);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册