JSP页面
function getChecked() {
var array = new Array();
var nodes = $('#tt').tree('getChecked');
var nodeParent = $('#tt').tree('getChecked', 'indeterminate');
var s = '';
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
array.push(node.id);
}
for (var i = 0; i < nodeParent.length; i++) {
var nod = nodeParent[i];
array.push(nod.id);
}
var ids = array.join(",");
return ids;
}
//修改回显权限树
@ResponseBody@RequestMapping(value="/updatetree.json",method=RequestMethod.GET)
public List<NodelTree> updatetree(Integer id,HttpServletResponse resp) throws Exception{
List<Functionmenu> functList =functionmenuService.getAllfunctionmenu();
Integer[] rfs = jurisdictionService.getfunctionmenuByFuntId(id);
for(Functionmenu fun : functList){
boolean contains = false;
for(Integer funid : rfs){
if(funid==fun.getFunid() && fun.getParentfunid()!=null && fun.getParentfunid()!=0){
contains=true;
break;
}
}
fun.setChecked(contains);
}
nodes = new ArrayList<NodelTree>();
for(Functionmenu fun :functList){
NodelTree nodetree = new NodelTree();
if( fun.getParentfunid()==null || fun.getParentfunid()==0){
nodetree.setChecked(fun.getChecked());
nodetree.setId(fun.getFunid());
nodetree.setText(fun.getFunname());
nodes.add(nodetree);
}
}
setMenu(functList,nodes,rfs);
/*ObjectMapper mapper = new ObjectMapper();
String json=mapper.writeValueAsString(node);
System.out.println(json);
resp.getWriter().write(json);*/
return nodes;
}
private void setMenu(List<Functionmenu> allMenu,List<NodelTree> parentNodes,Integer[] rfs){
//根据用户角色ID查询所有的菜单
for(NodelTree node :parentNodes){
for(Functionmenu fun :allMenu){
if(fun.getParentfunid()==node.getId()){
NodelTree child = new NodelTree();
child.setId(fun.getFunid());
child.setText(fun.getFunname());
node.getChildren().add(child);
child.setChecked(fun.getChecked());
}
}
setMenu(allMenu,node.getChildren(),rfs);
if(node.getChildren().size()>0){
int checkedCount = 0;
for(NodelTree node2 : node.getChildren()){
if(node2.isChecked()){
checkedCount++;
}
}
if(checkedCount>0 && checkedCount == node.getChildren().size()){
node.setChecked(true);
}else{
node.setChecked(false);
}
}
}
}
//1.所有需要进行控制的按钮列表
//2.当前用户拥有的按钮列表
@ResponseBody
@RequestMapping(value="/control.do",method=RequestMethod.GET)
public List<Functionmenu> control(String href,Model model,HttpSession session){
List<Functionmenu> functList =functionmenuService.getAllfunctionmenu();
Emp emp = (Emp) session.getAttribute("USER");
List<Functionmenu> funs=functionmenuService.getFunctionmenuByRoleid(emp.getRoleid());
// Integer[] funs = jurisdictionService.getfunctionmenuByFuntId(emp.getRoleid());
return funs;
}
<tr>
<td width="100px"><span class="font01 pr5">*</span>权限信息:</td>
<td class="white-tr">
<%-- <c:forEach items="${rfs}" var="r">
<input id="hid" type="hidden" name="ids" value="${r}"/>
</c:forEach> --%>
<div data-options="region:'center',split:true" title="权限树" style="padding: 5px">
<ul id="tt" class="easyui-tree" data-options="url:'<%= request.getContextPath()%>/jurisdiction/updatetree.json',method:'get',animate:true,checkbox:true"></ul>
</div>
</td>
</tr>