JSP代码部分 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="<%=request.getContextPath() %>/js/jqueryTree/css/demo.css" type="text/css"> <link rel="stylesheet" href="<%=request.getContextPath() %>/js/jqueryTree/css/zTreeStyle/zTreeStyle.css" type="text/css"> <script type="text/javascript" src="<%=request.getContextPath() %>/js/jqueryTree/js/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="<%=request.getContextPath() %>/js/jqueryTree/js/jquery.ztree.core-3.5.js"></script> <script type="text/javascript" src="<%=request.getContextPath() %>/js/jqueryTree/js/jquery.ztree.excheck-3.5.js"></script> <script type="text/javascript" src="<%=request.getContextPath() %>/js/jqueryTree/js/jquery.ztree.exedit-3.5.js"></script> <style type="text/css"> .ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle} #layout { text-align:left;} #layout { display:block; height:100%; position:relative;} h4.contentTitle{color:#00579b;border-color:#A3C0E8;background:#E2F0FF url(../../../../images/grid/header-bg.gif) repeat-x left -1px;} h4.contentTitle{font-weight:normal; display:block; font-size:13px; padding:0px 5px;border-style:solid; border-width:0px 0px 0px 0px; line-height:22px;vertical-align:middle; white-space:nowrap;} body{font-size:12px;background:#EAEEF5;} </style> </head> <body> <div id="layout" style="width:100%;"> <div id=‘background1‘ class=‘background‘></div> <h4 class="contentTitle" align="left"><img src="<%=request.getContextPath() %>/images/default/nav.gif" /> 当前位置:综合管理 > 技术资料 > 技术资料维护</h4> </div> <div class="content_wrap" style="float: left;"> <div class="zTreeDemoBackground left"><ul id="treeDemo" class="ztree"></ul></div> <iframe id="iframFileMng" name="location" frameborder="0" style="float: left; border: 1px solid #666; width: 75%; height: 460px; margin-left: 10px" src="bgImg.jsp"></iframe> </div> <div id="divRight" style="width: 650px; margin-top: 100px"> <input type=‘hidden‘ id=‘nodePid‘ name=‘nodePid‘ /> </body> <script type="text/javascript"> var searchUrl = "<%=request.getContextPath()%>/sysMaintenance/technicalInfomation/TechnicalInfomationMngAction/technicalInfomationTree.ajax"; var setting = { view: { addHoverDom: addHoverDom,//用于当鼠标移动到节点上时,显示用户自定义控件 removeHoverDom: removeHoverDom,//用于当鼠标移出节点时,隐藏用户自定义控件 dblClickExpand: true,//双击节点是否自动展开父节点的标识 showLine: true,//设置是否显示节点之间的连线 selectedMulti: false//设置是否允许同时选中多个节点 }, edit: { enable: true,//设置是否可编辑 editNameSelectAll: true, // 节点编辑名称 input 初次显示时,设置 txt 内容是否为全选状态。 showRemoveBtn: showRemoveBtn, //设置是否显示删除按钮 showRenameBtn: showRenameBtn //设置是否显示重命名按钮 }, data: { keep: { parent: true,//如果设置为 true,则所有 isParent = true 的节点,即使该节点的子节点被全部删除或移走,依旧保持父节点状态。 leaf: true//如果设置为 true,则所有 isParent = false 的节点,都无法添加子节点。 }, simpleData: { enable: true//如果设置为true,则zNodes格式必须为json格式,且是有父子关系的json格式 } }, callback: { beforeRemove: beforeRemove,//删除之前调用函数 beforeRename: beforeRename,//重命名之前调用函数 beforeMouseDown: true,//当鼠标按下之前 beforeDrag: false,//禁止拖拽操作 onClick: selectNodeFun,//当鼠标按下时,选中当前节点 onRemove: onRemove,//当删除节点后 onRename: onRename//当重命名节点名称后 } }; function onRemove(e, treeId, treeNode) { showLog("[ "+getTime()+" onRemove ] " + treeNode.name); } function onRename(e, treeId, treeNode) { showLog("[ "+getTime()+" onRename ] " + treeNode.name); } function selectNodeFun(event, treeId, treeNode) { var iframe = document.getElementById("iframFileMng"); iframe.src = treeNode.url != null ? treeNode.url : ""; showAddNodeFun(treeNode);//显示添加子节点按钮 showRemoveBtn(treeId, treeNode);//显示删除按钮 showRenameBtn(treeId, treeNode);//显示重命名按钮 showRightInfo(treeNode); // 显示左侧目录信息 }; function getTime() { var now= new Date(), h=now.getHours(), m=now.getMinutes(), s=now.getSeconds(), ms=now.getMilliseconds(); return (h+":"+m+":"+s+ " " +ms); } function showRightInfo(treeNode) { $("#nodeId").val(treeNode.id); // 节点ID $("#hideNodeId").val(treeNode.id); // 节点ID(隐藏域) $("#nodeName").val(treeNode.name); // 节点名称 $("#num").val(treeNode.num); // 文件编号(排序用) $("#nodePid").val(treeNode.pId); } function showRemoveBtn(treeId, treeNode) { var isShow = treeNode.id == 1000000000 ? false : true if(isShow) { return true; } return false; } function showRenameBtn(treeId, treeNode) { var isShow = true; if(isShow) { return true; } return false; } function showAddNodeFun(treeNode) { var sObj = $("#" + treeNode.tId + "_span"); if (treeNode.editNameFlag || $("#addBtn_"+treeNode.id).length>0) return; var addStr = "<span class=‘button add‘ id=‘addBtn_" + treeNode.id + "‘ title=‘add node‘ onfocus=‘this.blur();‘></span>"; sObj.after(addStr); var btn = $("#addBtn_"+treeNode.id); if (btn) btn.bind("click", function(){ addNodeFun(treeNode); }); } function addNodeFun(treeNode) { treeNode.isParent = true; // 改变节点级别(改为父级节点) treeNode.iconOpen = ‘../../../../images/folderopen-blue.gif‘; $.ajax({ type : "post", context: null, url : "<%=request.getContextPath()%>/sysMaintenance/technicalInfomation/TechnicalInfomationMngAction/technicalInfomationAdd.ajax", data : {"pId" : treeNode.id}, success : function(msg) { var val = ""; if(navigator.userAgent.indexOf("MSIE 9.0")>0||navigator.userAgent.indexOf("MSIE 8.0")>0){ val = "["+msg.text.substring(6,msg.text.length)+"]";//IE8下 }else{ val = "["+msg.childNodes[0].lastChild.lastChild.data+"]";//除IE8以外 } val = eval(‘(‘ + val + ‘)‘); var treeObj = $.fn.zTree.getZTreeObj("treeDemo"); treeObj.addNodes( treeNode, { id:val[0].newNodeId, pId:val[0].parentNodeId, name:val[0].newNodeName, url:val[0].url, target:val[0].target, iconClose:val[0].iconClose, icon:val[0].icon, isParent:val[0].isParent } ); setTimeout("selectNewNode(" + val[0].newNodeId + ")", 1); } }); } function selectNewNode(newNodeId) { var treeObj = $.fn.zTree.getZTreeObj("treeDemo"); var node = treeObj.getNodeByParam(‘id‘, newNodeId); treeObj.selectNode(node); $("#nodeId").val(‘‘); $("#nodeName").val(‘‘); $("#num").val(‘‘); } function beforeRename(treeId, treeNode, newName) { className = (className === "dark" ? "":"dark"); showLog("[ "+getTime()+" beforeRename ] " + treeNode.name); if (newName.length == 0) { ; var zTree = $.fn.zTree.getZTreeObj("treeDemo"); setTimeout(function(){zTree.editName(treeNode);}, 10); return false; } editNodeFun(treeNode.id, newName); return true; } function showLog(str) { if (!log) log = $("#log"); log.append("<li class=‘"+className+"‘>"+str+"</li>"); if(log.children("li").length > 8) { log.get(0).removeChild(log.children("li")[0]); } } function beforeRemove(treeId, treeNode) { var bool = false; className = (className === "dark" ? "":"dark"); showLog("[ "+getTime()+" beforeRemove ] " + treeNode.name); var result = confirm("确认禁用节点 < " + treeNode.name + " > 吗?"); if(result) { bool = countPidNum(treeNode.id); } else { bool = false; } return bool; } function countPidNum(id) { var bool = false; $.ajax({ type : "post", url : "<%=request.getContextPath()%>/sysMaintenance/technicalInfomation/TechnicalInfomationMngAction/countPidNum.ajax", data : {"id" : id}, async : false, success : function(msg) { if (msg.lastChild.lastChild.lastChild.nodeValue=="true") { bool = disableNodeFun(id, true); } else { bool = disableNodeFun(id, false); } } }); return bool; } function disableNodeFun(id, isChildNode) { var bool = false; if(isChildNode) { if(confirm(‘该节点下存在其他子节点, 是否禁用?‘)) { $.ajax({ type : "post", url : "<%=request.getContextPath()%>/sysMaintenance/technicalInfomation/TechnicalInfomationMngAction/technicalInfomationDisable.ajax", data : {"id" : id, "isChildNode" : isChildNode}, async : false, success : function(msg) { if (msg.lastChild.lastChild.lastChild.nodeValue=="true") { bool = true; } else { bool = false; } } }); } } else { $.ajax({ type : "post", url : "<%=request.getContextPath()%>/sysMaintenance/technicalInfomation/TechnicalInfomationMngAction/technicalInfomationDisable.ajax", data : {"id" : id, "isChildNode" : isChildNode}, async : false, success : function(msg) { if (msg.lastChild.lastChild.lastChild.nodeValue=="true") { bool = true; } else { bool = false; } } }); } return bool; } function editNodeFun(id, newName) { $.ajax({ type : "post", url : "<%=request.getContextPath()%>/sysMaintenance/technicalInfomation/TechnicalInfomationMngAction/technicalInfomationEdit.ajax", data : {"id" : id, "newName" : newName}, success : function(msg) { } }); } function addHoverDom(treeId, treeNode) { var sObj = $("#" + treeNode.tId + "_span"); if (treeNode.editNameFlag || $("#addBtn_"+treeNode.id).length>0) return; var addStr = "<span class=‘button add‘ id=‘addBtn_" + treeNode.id + "‘ title=‘add node‘ onfocus=‘this.blur();‘></span>"; sObj.after(addStr); var btn = $("#addBtn_"+treeNode.id); if (btn) btn.bind("click", function(){ addNodeFun(treeNode); }); }; function removeHoverDom(treeId, treeNode) { $("#addBtn_"+treeNode.id).unbind().remove(); }; function showRemoveBtn(treeId, treeNode) { var isShow = treeNode.id == 1000000000 ? false : true; if(isShow) { return true; } return false; } function showRenameBtn(treeId, treeNode) { var isShow = true; if(isShow) { return true; } return false; } var zNodes;//tree data var log, className = "dark"; $(document).ready(function(){ $.ajax({ url: searchUrl, context: null,type : "post", success: initTree}); }); function initTree(res){ //IE8和IE9回调取值方式与IE10和IE11取值方式不同。 if(navigator.userAgent.indexOf("MSIE 9.0")>0||navigator.userAgent.indexOf("MSIE 8.0")>0){ zNodes = "["+res.text.substring(4,res.text.length-1)+"]";//IE8下 }else{ zNodes = "["+res.childNodes[0].childNodes[1].childNodes[0].data+"]";//除IE8以外 } //String转换为json格式 zNodes = eval(‘(‘ + zNodes + ‘)‘); //加载树 $.fn.zTree.init($("#treeDemo"), setting, zNodes); } </script> </html> 后台部分 package com.org.dms.action.sysMaintenance.technicalInfomation; import java.sql.SQLException; import java.util.HashMap; import org.apache.log4j.Logger; import com.org.dms.common.DicConstant; import com.org.dms.dao.sysMaintenance.technicalInfomation.TechnicalInfomationMngDAO; import com.org.dms.dao.sysMaintenance.technicalInfomation.TechnicalInfomationQueryDAO; import com.org.frameImpl.vo.TmTechnicalTreeVO; import com.org.framework.Globals; import com.org.framework.common.BaseResultSet; import com.org.framework.common.PageManager; import com.org.framework.common.QuerySet; import com.org.framework.common.User; import com.org.framework.util.Pub; import com.org.framework.util.RequestUtil; import com.org.mvc.context.ActionContext; public class TechnicalInfomationMngAction { private Logger log = Logger.getLogger(this.getClass()); private ActionContext atx = ActionContext.getContext(); User user = (User) atx.getSession().get(Globals.USER_KEY); private TechnicalInfomationQueryDAO dao1 = TechnicalInfomationQueryDAO.getInstance(atx); private TechnicalInfomationMngDAO dao2 = TechnicalInfomationMngDAO.getInstance(atx); public void technicalInfomationTree() { QuerySet treeList; try { treeList = dao1.technicalInfomationTree(); String tree = ""; if(treeList!=null && treeList.getRowCount()>0){ for (int i = 0; i < treeList.getRowCount(); i++) { String id = treeList.getString(i + 1, "NODE_ID"); String parentNodeId = treeList.getString(i + 1, "PARENT_NODE_ID"); String nodeName = treeList.getString(i + 1, "NODE_NAME"); String nodeNo = treeList.getString(i + 1, "NODE_NO") == null?"99":treeList.getString(i + 1, "NODE_NO"); if(Long.parseLong(parentNodeId) == 0) { tree += "{"id":"" + id + "","pId":"" + parentNodeId + "", "name":"" + nodeName + "", "num":"" + nodeNo + "","url":"bgImg.jsp", "target":"location", "iconOpen":"../../../../images/folderopen-blue.gif", "iconClose":"../../../../images/folder-blue.gif"," + " open:true},"; } else { tree += "{"id":"" + id + "", "pId":"" + parentNodeId + "", "name":"" + nodeName + "", "num":"" + nodeNo + "", "url":"technicalManagerMain.jsp?nodeId=" + id + "", "target":"location", "iconOpen":"../../../../images/folderopen-blue.gif", "iconClose":"../../../../images/folder-blue.gif", "icon":"../../../../images/folder-blue.gif",isParent:false,open:false},"; } } } atx.setOutMsg("tree", tree); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log.error(user,e); } } public void technicalInfomationAdd() { try { String parentNodeId = Pub.val(atx.getRequest(), "pId"); // 目录ID TmTechnicalTreeVO technicalTree = new TmTechnicalTreeVO(); technicalTree.setNodeId(dao1.selectSeq()); technicalTree.setNodeName("新建文件夹"); technicalTree.setParentNodeId(parentNodeId); technicalTree.setNodeStatus(DicConstant.YXBS_01); technicalTree.setNodeType("10000001"); technicalTree.setCreateBy(user.getAccount()); technicalTree.setCreateTime(Pub.getCurrentDate()); dao1.insertTmTechnicalTree(technicalTree); String node = "{"parentNodeId":"" + parentNodeId + "","newNodeId":"" + technicalTree.getNodeId() + "", "newNodeName":"" + technicalTree.getNodeName() + "", "url":"technicalManagerMain.jsp?nodeId=" + technicalTree.getNodeId() + "", "target":"location", "icon":"../../../../images/folder-blue.gif", "iconClose":"../../../../images/folder-blue.gif"," + " isParent:false},"; atx.setOutMsg("result",node); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log.error(user,e); } } public void technicalInfomationEdit() throws SQLException { try{ // 从前台获取需要编辑的信息ID String nodeId = Pub.val(atx.getRequest(), "id"); String nodeName = Pub.val(atx.getRequest(), "newName"); TmTechnicalTreeVO setTechnicalTree = new TmTechnicalTreeVO(); setTechnicalTree.setNodeId(nodeId); setTechnicalTree.setNodeName(nodeName); setTechnicalTree.setUpdateBy(user.getAccount()); setTechnicalTree.setUpdateTime(Pub.getCurrentDate()); dao1.updateTmTechnicalTree(setTechnicalTree); atx.setOutMsg("isEdit", "true"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log.error(user,e); } } public void countPidNum() { try{ // 从前台获取需要禁用的信息ID String nodeId = Pub.val(atx.getRequest(), "id"); QuerySet ps = dao2.countPidNum(nodeId); int result = Integer.parseInt(ps.getString(1,"c")); if(result > 0) { atx.setOutMsg(""isExist"", "true"); } else { atx.setOutMsg(""isExist"", "false"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log.error(user,e); } } public void technicalInfomationDisable() { try{ // 从前台获取需要禁用的信息ID String nodeId = Pub.val(atx.getRequest(), "id"); String isChildNode = Pub.val(atx.getRequest(), "isChildNode"); // isChildNode为true代表有子节点,将对其下子节点一起禁用 if(isChildNode.equals("true")) { dao2.technicalInfomationDisable(nodeId); atx.setOutMsg(""isDisable"", "true"); } else { TmTechnicalTreeVO setTechnicalTree = new TmTechnicalTreeVO(); setTechnicalTree.setNodeId(nodeId); setTechnicalTree.setNodeStatus(DicConstant.YXBS_02); setTechnicalTree.setUpdateBy(user.getAccount()); setTechnicalTree.setUpdateTime(Pub.getCurrentDate()); dao1.updateTmTechnicalTree(setTechnicalTree); atx.setOutMsg(""isDisable"", "true"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log.error(user,e); } } public void technicalInfomationFileMng() { try { PageManager page = new PageManager(); HashMap<String, String> hm = RequestUtil.getValues(atx.getRequest()); BaseResultSet ps = dao1.technicalFileMng(page,hm); atx.setOutData("bs", ps); } catch (Exception e) { e.printStackTrace(); log.error(user,e); atx.setException(e); } } public void technicalInfomationDelTree() { QuerySet treeList; try { treeList = dao1.technicalInfomationTree(); String tree = ""; if(treeList!=null && treeList.getRowCount()>0){ for (int i = 0; i < treeList.getRowCount(); i++) { String id = treeList.getString(i + 1, "NODE_ID"); String parentNodeId = treeList.getString(i + 1, "PARENT_NODE_ID"); String nodeName = treeList.getString(i + 1, "NODE_NAME"); String nodeNo = treeList.getString(i + 1, "NODE_NO") == null?"99":treeList.getString(i + 1, "NODE_NO"); if(Long.parseLong(parentNodeId) == 0) { tree += "{"id":"" + id + "","pId":"" + parentNodeId + "", "name":"" + nodeName + "", "num":"" + nodeNo + "","url":"bgImg.jsp", "target":"location", "iconOpen":"../../../../images/folderopen-blue.gif", "iconClose":"../../../../images/folder-blue.gif"," + " open:true},"; } else { tree += "{"id":"" + id + "", "pId":"" + parentNodeId + "", "name":"" + nodeName + "", "num":"" + nodeNo + "", "url":"technicalManagerDelMain.jsp?nodeId=" + id + "", "target":"location", "iconOpen":"../../../../images/folderopen-blue.gif", "iconClose":"../../../../images/folder-blue.gif", "icon":"../../../../images/folder-blue.gif",isParent:false,open:false},"; } } } atx.setOutMsg("tree", tree); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log.error(user,e); } } }
时间: 2024-10-21 15:41:15