easyui中权限分配和添加 前后端代码

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<meta charset="utf-8">
<link href="<%=basePath%>css/themes/default/easyui.css" rel="stylesheet" type="text/css"/>
<%-- <link href="<%=basePath%>css/themes/icon.css" rel="stylesheet" type="text/css"/> --%>
<link href="<%=basePath%>css/themes/color.css" rel="stylesheet" type="text/css"/>
<%-- <link href="<%=basePath%>css/themes/mobile.css" rel="stylesheet" type="text/css"/> --%>


<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/easyloader.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.easyui.mobile.js"></script>
<script type="text/javascript" src="<%=basePath%>js/plugins/jquery.parser.js"></script>
<script type="text/javascript" src="<%=basePath%>js/plugins/jquery.pagination.js"></script>
<script type="text/javascript" src="<%=basePath%>js/plugins/jquery.form.js"></script>
<style type="text/css">
#producttable{
width: 90%;
border-collapse:separate; border-spacing:0px 20px;
}
#producttable input{
height:32px;
}
</style>

</head>
<body>
<div style="height: 50%;width:70%;float: left;display:inline-block;margin-top: 35px;">
<table id="allotControltable">

</table>
</div>
<!-- 添加角色 -->
<div id="allotControlAdd">
<form id="allotControlAddform">
<table id="producttable">
<tr>
<td align="right">角色名称: </td>
<td>
<input id="REMARK" name="REMARK"></input>
</td>
<td align="right">类型生效标志:</td>
<td>
<select id="EFFECT_STS" name="EFFECT_STS" >
<option value="1" selected="selected">生效</option>
<option value="2">无效</option>
</select>
</td>
</tr>
</table>
</form>
</div>
<!-- 修改角色 -->
<div id="allotControlUpdate">
<form id="allotControlUpdateform">
<table id="producttable">
<tr>
<td align="right">角色名称: </td>
<td>
<input id="remark1" name="REMARK"></input>
</td>
<td align="right">类型生效标志:</td>
<td>
<select id="effect_STS1" name="EFFECT_STS" >
<option value="1" selected="selected">生效</option>
<option value="2">无效</option>
</select>
</td>
</tr>
<tr>
<td align="right">时间戳: </td>
<td>
<input id="tm_SMP1" name="TM_SMP" readonly="readonly"></input>
</td>

</tr>
</table>
</form>
</div>

<div id="container"
style="width: 12%; height: 800px;display:inline-block; float: left !important;">
<div class="easyui-panel" title="权限列表"
style="width: 100%; height: 99%; float: right !important; overflow-y: scroll; background-color: #fff">
<ul>
<input type="checkbox" id="tree_select" name="tree_select"
onclick="allselect()" />
<a>全选或者取消全选</a>
</ul>
<ul id="dgMenu" class="easyui-tree" style="width: 200px"></ul>
</div>
</div>
<script type="text/javascript">
//全选或者取消全选
function allselect(){
var tree_select = $('#tree_select').is(':checked');
var roots = $('#dgMenu').tree('getRoots');//返回tree的所有根节点数组
console.log(tree_select);
if (tree_select==true) {
for ( var i = 0; i < roots.length; i++) {
var node = $('#dgMenu').tree('find', roots[i].id);//查找节点
$('#dgMenu').tree('check', node.target);//将得到的节点选中
}
} else {
for ( var i = 0; i < roots.length; i++) {
var node = $('#dgMenu').tree('find', roots[i].id);
$('#dgMenu').tree('uncheck', node.target);
}
}
}

$('#dgMenu').tree({
checkbox: 'checked',
cascadeCheck: true,
url: '<%=basePath%>user/getMenu.do',
loadFilter: function(data){
console.log(data);
return data;
},
/* onBeforeLoad:function(node,param){
param.categoryId = "13";
} */
});

$("#allotControltable").datagrid({
//var row = $('#xyData_userListlk').datagrid('getSelected');
onClickRow: function (index, row) {
var categoryId=row.tm_SMP;//用户类别ID
//alert("查询已经有的权限======"+categoryId);
$('#dgMenu').tree({
checkbox: true,
cascadeCheck: true,
url: '<%=basePath%>user/getMenu.do?categoryId='+categoryId,
loadFilter: function(data){
return data;
}
});
}

});


//添加用户
$('#allotControlAdd').dialog({
title:'添加用户',
width:'50%',
height:'300px',
iconCls:'icon-add',
closed:true,
closable: true,
draggable: false,
modal: true,
buttons:[ {
text : '保存',
iconCls : 'icon-ok',
handler : function() {
$('#allotControlAddform').form('submit',{
onSubmit:function(){
return $(this).form('enableValidation').form('validate');
},
url:'<%=basePath%>user/allotControlAdd.do',
success : function(data) {
data = eval("(" + data + ")");//JSON字符串转对象
$.messager.show({
title:'提示',
msg: data.msg,
showType:'show'
});
$('#allotControlAdd').dialog('close');
$('#allotControltable').datagrid('reload');
},
error: function(){
$.messager.show({
title:'提示',
msg: '添加失败',
showType:'show'
});
}
});
}
}, {
text : '取消',
iconCls : 'icon-cancel',
handler : function() {
$('#allotControlAdd').dialog('close');
}
} ]
});
//修改产品

$('#allotControlUpdate').dialog({
title:'添加用户',
width:'50%',
height:'300px',
iconCls:'icon-add',
closed:true,
closable: true,
draggable: false,
modal: true,
buttons:[ {
text : '保存',
iconCls : 'icon-ok',
handler : function() {
$('#allotControlUpdateform').form('submit',{
onSubmit:function(){
return $(this).form('enableValidation').form('validate');
},
url:'<%=basePath%>user/allotControlUpdate.do',
success : function(data) {
data = eval("(" + data + ")");//JSON字符串转对象
$.messager.show({
title:'提示',
msg: data.msg,
showType:'show'
});
$('#allotControlUpdate').dialog('close');
$('#allotControltable').datagrid('reload');
},
error: function(){
$.messager.show({
title:'提示',
msg: data.msg,
showType:'show'
});
}
});
}
}, {
text : '取消',
iconCls : 'icon-cancel',
handler : function() {
$('#allotControlUpdate').dialog('close');
}
} ]
});
$('#').dialog('close');
$('#allotControlUpdate').dialog('close');
$('#allotControltable').datagrid({
width: 'auto',
height:'auto',
striped: true,
fit: true,
pagination: true,
scrollbarSize: 0,
singleSelect: true,
url: '<%=basePath%>user/findAllotControl.do',
loadMsg: '数据加载中请稍后……',
columns: [[{
field: 'category_ID',
title: '产品编号',
align: 'center',
resizable: false,
width: '10%'
},{
field: 'remark',
title: '角色名称',
align: 'center',
resizable: false,
width: '15%'
}, {
field: 'effect_STS',
title: '类型生效标志',
align: 'center',
resizable: false,
width: '15%'
}, {
field: 'tm_SMP',
title: '时间戳',
align: 'center',
resizable: false,
width: '15%'
}, {
field: 'upd_OPER',
title: '维护操作员',
align: 'center',
resizable: false,
width: '15%'
}, {
field: 'org_NO',
title: '机构编号',
align: 'center',
resizable: false,
width: '15%'
}, {
field: 'del_STATUS',
title: '删除状态',
align: 'center',
resizable: false,
width: '15%'
}
]],
method: 'post',
toolbar: [{
text:'添加',
iconCls: 'icon-edit',
handler: function(){
$('#allotControlAddform').form('clear');
$('#allotControlAdd').dialog('open').dialog('setTitle', '添加产品');
$("#EFFECT_STS").val(Array('1'))
}
},'-',{
text:'修改',
iconCls: 'icon-help',
handler: function(){
var row=$('#allotControltable').datagrid('getSelected');
if(row){

$('#allotControlUpdateform').form('load',row);
$('#remark1').val(row.remark);
$('#tm_SMP1').val(row.tm_SMP);
$('#effect_STS1').val(row.effect_STS);
//alert(row.remark+"--"+row.tm_SMP+"--"+row.effect_STS)

$('#allotControlUpdate').dialog('open').dialog('setTitle', '添加产品');

}else{
$.messager.show({
title:'提示',
msg: '至少选择一条',
showType:'show'
});
}

}
},'-',{
text:'删除',
iconCls: 'icon-help',
handler: function(){
var row=$('#allotControltable').datagrid('getSelected');
if(row){
$.messager.confirm('删除数据', '您确定删除此用户吗?', function(r){
if (r){
$.post('<%=basePath%>user/deleteAllotControltable.do?TM_SMP=' + row.tm_SMP+"&CATEGORY_ID="+ row.tm_SMP,
function (result) {
$.messager.show({
title:'提示',
msg: result.msg,
showType:'show'
});
$('#allotControltable').datagrid('reload');

},'json');
}
});

}else{
$.messager.show({
title:'提示',
msg: '至少选择一条',
showType:'show'
});
}

}
},'-',{
text:'保存权限',
iconCls: 'icon-help',
handler: function(){
var row=$('#allotControltable').datagrid('getSelected');

if(row){
//获取选中的树状结构项
var nodes = $('#dgMenu').tree('getChecked', ['checked','indeterminate']);

console.log('nodes=='+nodes);
var checkNod='';
for(var i=0;i<nodes.length;i++){
if(i==nodes.length-1){
checkNod+=nodes[i].id;
}else{
checkNod+=nodes[i].id+',';
}
}
console.log('checkNod=='+checkNod);
$.messager.confirm('保存权限', '确认保存此权限吗?', function(r){
$.post('<%=basePath%>user/saveMenus.do?checkNod=' + checkNod+"&CATEGORY_ID="+ row.tm_SMP+'&UPD_OPER='+row.upd_OPER,
function(result){
$.messager.show({
title:'提示',
msg: result.msg,
showType:'show'
});
},'json')
})
}else{
$.messager.show({
title:'提示',
msg: '至少选择一条',
showType:'show'
});
}

}
}

]
});

var p = $('#allotControltable').datagrid('getPager');
$(p).pagination({
pageSize : 10,//每页显示的记录条数,默认为10
pageList : [10, 20, 30],//可以设置每页记录条数的列表
beforePageText : '第',//页数文本框前显示的汉字
afterPageText : '页 共 {pages} 页',
displayMsg : '当前显示 {from} - {to} 条记录 共 {total} 条记录',
});
</script>
</body>
</html>

java代码==============

 

/**
* 查询权限列表
* @param categoryId
* @return
*/
@Override
public List<Map<String, Object>> getMenus(String categoryId) {
List<Map<String, Object>>menuallist= userDao.selectMenuAllList();
List<String> meunSelectedList = null;
if (StringUtils.isNotBlank(categoryId)) {
//查询已有权限
meunSelectedList = userDao.selectMenuSelectedList(categoryId);
}
//获取树状结构
List<Map<String, Object>>listTree=getTreeList(menuallist,meunSelectedList,"id","pre_id","children");
return listTree;
}
public List<Map<String,Object>> getTreeList(List<Map<String, Object>>menuaList,List<String> idlist,String id,String pre_id,String children) {
System.out.println("获取树状结构开始》》》》》》》》》》》》》》》》》》》");
/**
* 给获取数组的每一项添加一个子项
*/
for(int i=0;i<menuaList.size();i++) {//checked
menuaList.get(i).put("checked","");
menuaList.get(i).put(children, new ArrayList<Map<String, Object>>());
}
System.out.println("menuaList=="+menuaList);
List<Map<String,Object>>treeList=new ArrayList<Map<String,Object>>();
for(Map<String,Object>outMap:menuaList) {
for(Map<String,Object>inMap:menuaList) {
String outid=outMap.get(id).toString();
String inPre_id=inMap.get(pre_id).toString();
if(outid.equals(inPre_id)) {
List<Map<String,Object>> listMap=(ArrayList<Map<String,Object>>)outMap.get(children);
listMap.add(inMap);
String inId=inMap.get("id").toString();
//判断查询获取的id和内循环id是否相同 如果相同给checked赋值为true
if(null!=idlist) {
if(isFaseOrTrue(inId,idlist)) {
inMap.put("checked", "true");
}
}
}
}
String outPid=outMap.get(pre_id).toString();
if(StringUtils.isAllBlank(outPid)) {
treeList.add(outMap);
String outId=outMap.get(id).toString();
if(null!=idlist) {
if(isFaseOrTrue(outId,idlist)) {
outMap.put("checked", "true");
}
}
}
}
return treeList;

}
//判断表达式
private Boolean isFaseOrTrue(String id,List<String>list) {
Boolean flag=false;
for(String str:list) {
if(id.equals(str)) {
flag=true;
break;
}
}
return flag;
}

posted @ 2019-12-13 15:39  红尘沙漏  阅读(242)  评论(0编辑  收藏  举报