首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

ztree二级树菜单(SSI框架上)-hulian平台二版代码

2012-09-01 
ztree二级树菜单(SSI框架下)--hulian平台二版代码这是用jquery ztree做的二级权限树,互联二版代码,原理主

ztree二级树菜单(SSI框架下)--hulian平台二版代码

这是用jquery ztree做的二级权限树,互联二版代码,原理主要:

1.框架基于struts2、spring3、ibatIS2.3

2.主要是TEmployeePriv表的三个字段(PRIV_NUM、MENU_ID_1、PRIV_TYPE):

?? privNum为id(子id),menuId1为pId(父id),

?? privType为权限菜单类型[权限菜单(60),权限集合(61),权限动作(62)]即60一级菜单、61二级菜单、62三级菜单

?

一、action代码

/** * 打开授权 */public String openImpower(){role = service.queryById(roleNum);TRolePriv rp = new TRolePriv();rp.setRoleNum(roleNum);List<TRolePriv> rpList = service.queryRolePriv(rp);//权限中间表ListList<TEmployeePriv> privList = service.queryAllPriv(new TEmployeePriv());//查询所有TEmployeePriv/**合成权限树*/List<PrivJSON> jsonList = new ArrayList<PrivJSON>();for( TEmployeePriv priv : privList ){if("60".equals(priv.getPrivType())){PrivJSON json = new PrivJSON();//一级菜单json.setId(priv.getPrivNum());json.setpId("0");json.setName(priv.getPrivName());json.setOpen(false);//默认不展开jsonList.add(json);}else{PrivJSON json2 = new PrivJSON();json2.setId(priv.getPrivNum());json2.setpId(priv.getMenuId1());json2.setName(priv.getPrivName());json2.setPrivNum(priv.getPrivNum());for(TRolePriv trp : rpList){if(trp.getPrivNum().equals(priv.getPrivNum())){json2.setOpen(false);//默认不展开json2.setChecked(true);}}jsonList.add(json2);}}JSONArray myjsonObj = JSONArray.fromObject(jsonList);//将权限集合,转成JSON数组this.getRequest().setAttribute("myjsonObj",myjsonObj);successPath = "/jsp/phone/priv/role/impowerRole.jsp";return SUCCESS;}

?

二、jsp页面代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>角色授权</title><%@ include file="/cssBasePage.jsp"%><link rel="stylesheet" href="BaseInfo/ztree/demoStyle/demo.css" type="text/css"/>  <link rel="stylesheet" href="BaseInfo/ztree/zTreeStyle/zTreeStyle.css" type="text/css"/>  <script type="text/javascript" src="BaseInfo/ztree/jquery.ztree-2.6.js"></script><script type="text/javascript" src="<%=path%>/jsp/phone/priv/role/impowerRole.js"></script>  <script type="text/javascript">var zTreeObj;var setting = {checkable:true,treeNodeKey:"id",treeNodeParentKey:"pId",isSimpleData:true}; //zTree的参数配置,深入使用请参考 API 文档(参数说明 -- setting 详解)/*var zNodes = [{name:"test1", open:true, nodes:[{name:"test1_1"}, {name:"test1_2"}]},{name:"test2", open:true, nodes:[{name:"test2_1"}, {name:"test2_2"}]}];*/ //zTree的数据属性,深入使用请参考 API 文档(参数说明 -- zTreeNodes 详解)var myjsonObj = ${requestScope.myjsonObj};var zNodes = myjsonObj;                $(document).ready(function(){zTreeObj = $("#treeDemo").zTree(setting, zNodes);});function expandAll(expandSign) {zTreeObj.expandAll(expandSign);}function checkAllTreeNode(checked) {var oldNodes = zTreeObj.getNodes();var oldcheckNum = zTreeObj.getCheckedNodes(checked).length;zTreeObj.checkAllNodes(checked);var newcheckNum = zTreeObj.getCheckedNodes(checked).length;if (newcheckNum != oldcheckNum) zTreeObj.checkAllNodes(checked);}/*测试用树授权*/function testImpower(){var temp ="";var nodes = zTreeObj.getCheckedNodes();for( var i=0; i<nodes.length; i++ ){if(nodes[i].privNum != ''){temp = temp+";"+nodes[i].privNum;}}alert(temp);document.getElementById('privSelect').value=temp;}/*分配运维权限*/function allotYunwei(){checkAllTreeNode(false);var privNum = ["menu_0101","menu_0102"];//数组不能包含一级菜单,包含将会选中整个节点for(var i=0;i<privNum.length;i++){var node = zTreeObj.getNodeByParam("privNum", privNum[i]);node.checked=true;zTreeObj.updateNode(node,true);//zTreeObj.selectNode(node);//选中指定的节点}}  </script> </head>  <body><hp:HpNavigate TValue="工号及权限管理,角色管理,角色授权"></hp:HpNavigate><hp:HpSearch namekey="site.page.update.title"><br/><table>    <tr>    <td colspan="2">&nbsp;</td>    </tr>        <tr>    <td colspan="2">    <div name="form1" id="form1">    <input type="hidden" name="roleNum" value="${role.roleNum}"/>    <input id="privSelect" name="privSelect" type="hidden"/> <!-- 真正提交时的list,后台Action中得到此项,修改权限 -->        <br/>    <table>        <tr>    <td name="alterReason" id="alterReason" TValue="" TCols="75" TTMaxLength="50" /><div id="role.alterReasonDiv" style="display: inline" ></div></td>    </tr>        <tr>    <td Tid="password2" TMaxLength="16" TOnBlur="onBlurValiPass2(this.value,'password2Div')" ></hp:HpInputPass><div id="password2Div" style="display: inline" ></div></td>    </tr>            <tr>    <td></td>    <td TValue="save" id=""></hp:HpButton><hp:HpButton TJsClick="$('.DivShowInfoCss').html('');" TValue="reset" id=""></hp:HpButton><hp:HpButton TJsClick="$.hpDialog.close();" TValue="return" id=""></hp:HpButton>    </td>    <td></td>    </tr>    </table>    </form></hp:HpSearch>    </body></html>

热点排行