(1)tree属性扩展,支持新增节点
(2)特定服务增加一列标记新增节点
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
<%@ attribute name="showParentName" type="java.lang.String" required="false" description="显示父类名称"%>
|
||||
<%@ attribute name="checkedPS" type="java.lang.String" required="false" description="复选框选中时是否关联父子节点,ps关联父子,p关联父,s关联子,都不关联为空"%>
|
||||
<%@ attribute name="unCheckedPS" type="java.lang.String" required="false" description="复选框取消选中时是否关联父子节点,ps关联父子,p关联父,s关联子,都不关联为空"%>
|
||||
<%@ attribute name="enableAddBtn" type="java.lang.Boolean" required="false" description="节点是否可编辑"%>
|
||||
<div class="input-group">
|
||||
<input id="${id}Id" name="${name}" class="${cssClass} singleClass" type="hidden" value="${value}" />
|
||||
<input id="${id}Name" name="${labelName}" ${allowInput?'':'readonly="readonly"'} type="text" value="<spring:message code='${empty value?"":labelValue}'/>" data-msg-required="${dataMsgRequired}" placeholder="${empty value?labelValue:value}"
|
||||
@@ -45,7 +46,7 @@
|
||||
return true;
|
||||
}
|
||||
// 正常打开
|
||||
top.$.jBox.open("iframe:${ctx}/tag/treeselect?url="+encodeURIComponent("${url}")+"&selectIds="+$("#${id}Id").val()+"&module=${module}&checked=${checked}&extId=${extId}&isAll=${isAll}&title=${title}", "<spring:message code='choose'/> <spring:message code='${title}'/>", 320, 420, {
|
||||
top.$.jBox.open("iframe:${ctx}/tag/treeselect?url="+encodeURIComponent("${url}")+"&selectIds="+$("#${id}Id").val()+"&module=${module}&checked=${checked}&extId=${extId}&isAll=${isAll}&title=${title}&enableAddBtn=${enableAddBtn}", "<spring:message code='choose'/> <spring:message code='${title}'/>", 320, 420, {
|
||||
ajaxData:{selectIds: $("#${id}Id").val()},buttons:{"<spring:message code='ok'/>":"ok", "<spring:message code='clear'/>":"clear","<spring:message code='close'/>":true}, submit:function(v, h, f){
|
||||
if (v == "ok"){
|
||||
var tree = h.find("iframe")[0].contentWindow.tree;//h.find("iframe").contents();
|
||||
@@ -57,6 +58,7 @@
|
||||
}
|
||||
//wx提示,c:if标签前加了//注释,c:if标签的判断条件仍会生效
|
||||
for(var i=0; i<nodes.length; i++) {
|
||||
console.log(nodes[i]);
|
||||
//<c:if test="${checked && notAllowSelectParent}">
|
||||
if (nodes[i].isParent && "${checkedPS}"!=''){
|
||||
continue; // 如果为复选框选择,并且父子节点有关联,则过滤掉父节点
|
||||
|
||||
@@ -82,7 +82,7 @@ $(function(){
|
||||
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="social_app"/></label>
|
||||
<div class="col-md-6">
|
||||
<sys:treeselect id="specServiceId" name="specServiceId" value="${_cfg.specServiceId}"
|
||||
labelName="parent.specServiceName" notAllowSelectRoot="true" notAllowSelectParent="true"
|
||||
labelName="parent.specServiceName" notAllowSelectRoot="true" notAllowSelectParent="true" enableAddBtn="true"
|
||||
labelValue="${empty _cfg.specServiceId?spec_service_id:fns:getBySpecServiceId(_cfg.specServiceId).specServiceName}"
|
||||
title="${spec_service_id}" url="/specific/specificServiceCfg/treeData?isLeafShow=false&cfgType=${app}" extId=""
|
||||
cssClass="form-control required"/>
|
||||
|
||||
@@ -78,7 +78,7 @@ $(function(){
|
||||
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="social_app"/></label>
|
||||
<div class="col-md-6">
|
||||
<sys:treeselect id="specServiceId" name="specServiceId" value="${_cfg.specServiceId}"
|
||||
labelName="parent.specServiceName" notAllowSelectRoot="true" notAllowSelectParent="true"
|
||||
labelName="parent.specServiceName" notAllowSelectRoot="true" notAllowSelectParent="true" enableAddBtn="true"
|
||||
labelValue="${empty _cfg.specServiceId?spec_service_id:fns:getBySpecServiceId(_cfg.specServiceId).specServiceName}"
|
||||
title="${spec_service_id}" url="/specific/specificServiceCfg/treeData?isLeafShow=false&cfgType=${app}" extId=""
|
||||
cssClass="form-control required"/>
|
||||
|
||||
@@ -6,12 +6,33 @@
|
||||
<title>数据选择</title>
|
||||
<link href="${pageContext.request.contextPath}/static/global/plugins/jquery-ztree/3.5.12/css/zTreeStyle/zTreeStyle.min.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="${pageContext.request.contextPath}/static/global/plugins/jquery-ztree/3.5.12/js/jquery.ztree.all-3.5.min.js" type="text/javascript"></script>
|
||||
<%--解决ztree add小图标丢失 --%>
|
||||
<style type="text/css">
|
||||
.ztree li span.button.add{margin-right:2px;background-position:-144px 0;vertical-align:top;*vertical-align:middle}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var key, lastValue = "", nodeList = [], type = getQueryString("type", "${url}");
|
||||
var tree, setting = {view:{selectedMulti:false,dblClickExpand:false},check:{enable:"${checked}",chkboxType: { "Y" : "${checkedPS}", "N" : "${unCheckedPS}" },nocheckInherit:true},
|
||||
var tree, setting = {
|
||||
view:{
|
||||
addHoverDom: addHoverDom,
|
||||
removeHoverDom: removeHoverDom,
|
||||
selectedMulti:false,
|
||||
dblClickExpand:false
|
||||
},
|
||||
edit: {
|
||||
enable: true,
|
||||
showRemoveBtn: showRemoveBtn,
|
||||
showRenameBtn: showRenameBtn,
|
||||
removeTitle: "remove",
|
||||
renameTitle: "rename",
|
||||
},
|
||||
check:{enable:"${checked}",chkboxType: { "Y" : "${checkedPS}", "N" : "${unCheckedPS}" },nocheckInherit:true},
|
||||
async:{enable:(type==6),url:"${ctx}/sys/user/treeData",autoParam:["id=officeId"]},
|
||||
data:{simpleData:{enable:true}},callback:{
|
||||
|
||||
data:{simpleData:{enable:true}},
|
||||
callback:{
|
||||
beforeEditName:beforeEditName,
|
||||
beforeRename:beforeRename,
|
||||
beforeRemove:beforeRemove,
|
||||
//beforeClick: function(treeId, treeNode){
|
||||
//if("${checked}" == "true"){
|
||||
//tree.checkNode(treeNode, !node.checked, true, true);
|
||||
@@ -36,7 +57,9 @@
|
||||
},onDblClick: function(){//<c:if test="${!checked}">
|
||||
top.$.jBox.getBox().find("button[value='ok']").trigger("click");
|
||||
//$("input[type='text']", top.mainFrame.document).focus();//</c:if>
|
||||
}
|
||||
},
|
||||
onRename:onRename,
|
||||
onRemove:onRemove
|
||||
}
|
||||
};
|
||||
function expandNodes(nodes) {
|
||||
@@ -61,12 +84,15 @@
|
||||
}else{
|
||||
map.name="<spring:message code='root_node' />";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
tree = $.fn.zTree.init($("#tree"), setting, zNodes);
|
||||
// 默认展开一级节点
|
||||
var nodes = tree.getNodesByParam("level", 0);
|
||||
// 默认展开一二级节点
|
||||
var nodes = tree.getNodesByParam("level", 1);
|
||||
for(var i=0; i<nodes.length; i++) {
|
||||
tree.expandNode(nodes[i], true, false, false);
|
||||
}
|
||||
nodes=tree.getNodesByParam("level", 0);
|
||||
for(var i=0; i<nodes.length; i++) {
|
||||
tree.expandNode(nodes[i], true, false, false);
|
||||
}
|
||||
@@ -195,7 +221,145 @@
|
||||
$("#txt").toggle();
|
||||
$("#key").focus();
|
||||
}
|
||||
|
||||
function beforeEditName(treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj("tree");
|
||||
zTree.selectNode(treeNode);
|
||||
return confirm("<spring:message code='edit' />" + treeNode.name + "?");
|
||||
}
|
||||
function beforeRename(treeId, treeNode, newName) {
|
||||
var zTree = $.fn.zTree.getZTreeObj("tree");
|
||||
if (newName.length == 0) {
|
||||
var tip="<spring:message code='can_not_null' />";
|
||||
alert("<spring:message code='${title}' />"+tip.replace("%s"," "));
|
||||
setTimeout(function(){zTree.editName(treeNode)}, 10);
|
||||
return false;
|
||||
}
|
||||
if(confirm("<spring:message code='save' />" + treeNode.name + "?")){
|
||||
return true;
|
||||
}else{
|
||||
setTimeout(function(){zTree.editName(treeNode)}, 10);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function beforeRemove(treeId, treeNode, newName) {
|
||||
return confirm("<spring:message code='remove' /> " + treeNode.name + "?");
|
||||
}
|
||||
//在重命名节点时,调用后台存储,将返回结果更新
|
||||
function onRename(e, treeId, treeNode) {
|
||||
loading("<spring:message code='loading' />...");
|
||||
$.ajax({
|
||||
type:'post',
|
||||
async:true,
|
||||
cache:false,
|
||||
url:'${ctx}/specific/specificServiceCfg/ajaxSaveOrUpdateApp',
|
||||
data:{
|
||||
"specServiceId":treeNode.id,
|
||||
"specServiceCode":treeNode.serviceCode,
|
||||
"specServiceName":treeNode.name,
|
||||
"cfgType":treeNode.serviceType,
|
||||
"groupId":treeNode.groupId,
|
||||
"businessType":treeNode.pId.replace("businessType",""),
|
||||
"addFlag":treeNode.user
|
||||
},
|
||||
//dataType:"json",
|
||||
//contentType:"application/json; charset=utf-8",
|
||||
success:function(data){
|
||||
treeNode.groupId=data.data;
|
||||
treeNode.specServiceCode=data.specServiceCode;
|
||||
treeNode.user=data.addFlag;
|
||||
var zTree = $.fn.zTree.getZTreeObj("tree");
|
||||
zTree.updateNode(treeNode);
|
||||
closeTip();
|
||||
}
|
||||
});
|
||||
}
|
||||
function onRemove(e, treeId, treeNode) {
|
||||
loading("<spring:message code='loading' />...");
|
||||
if(typeof treeNode=="string"){
|
||||
var zTree = $.fn.zTree.getZTreeObj("tree");
|
||||
zTree.removeNode(treeNode,true);
|
||||
}else{
|
||||
$.ajax({
|
||||
type:'post',
|
||||
async:true,
|
||||
cache:false,
|
||||
url:'${ctx}/specific/specificServiceCfg/ajaxRemoveApp',
|
||||
data:{
|
||||
"specServiceId":treeNode.id
|
||||
},
|
||||
//dataType:"json",
|
||||
//contentType:"application/json; charset=utf-8",
|
||||
success:function(data){
|
||||
if(data){
|
||||
var zTree = $.fn.zTree.getZTreeObj("tree");
|
||||
zTree.removeNode(treeNode,false);
|
||||
}
|
||||
closeTip();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
//用户只能rename自己添加的节点
|
||||
function showRenameBtn(treeId, treeNode) {
|
||||
if(treeNode.isParent){
|
||||
return false;
|
||||
}
|
||||
if("${enableAddBtn}"&&"${enableAddBtn}"=="true"&&treeNode.user&&treeNode.user=="${userId}"){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//用户只能remove自己添加的节点
|
||||
function showRemoveBtn(treeId, treeNode) {
|
||||
if(treeNode.isParent){
|
||||
return false;
|
||||
}
|
||||
if("${enableAddBtn}"&&"${enableAddBtn}"=="true"&&treeNode.user&&treeNode.user=="${userId}"){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//只有在配置了enableAddBtn的界面上才会显示添加按钮
|
||||
function addHoverDom(treeId, treeNode) {
|
||||
//开启节点增加
|
||||
if("${enableAddBtn}"&&"${enableAddBtn}"=="true"){
|
||||
//根节点不需要增加节点
|
||||
if(treeNode.pId==null||(treeNode.businessType&&treeNode.businessType!=-1)){
|
||||
return;
|
||||
}
|
||||
var sObj = $("#" + treeNode.tId + "_span");
|
||||
if (treeNode.editNameFlag || $("#addBtn_"+treeNode.id).length>0) return;
|
||||
var title="<spring:message code='add' /> <spring:message code='${title}' />";
|
||||
var addStr = "<span class='button add' id='addBtn_" + treeNode.id
|
||||
+ "' title='"+title+"' onfocus='this.blur();'></span>";
|
||||
sObj.after(addStr);
|
||||
var btn = $("#addBtn_"+treeNode.id);
|
||||
if (btn){
|
||||
btn.bind("click", function(){
|
||||
//区别人工添加,在ID前加上manual
|
||||
var id="manual"+new Date().getTime();
|
||||
var zTree = $.fn.zTree.getZTreeObj("tree"); //addSelectedNode
|
||||
zTree.addNodes(treeNode, {id:id, pId:treeNode.id, name:"<spring:message code='new' /> <spring:message code='${title}' />",
|
||||
businessType:treeNode.id.replace("businessType",""),user:"${userId}",serviceType:treeNode.serviceType,groupId:"",
|
||||
serviceCode:""});
|
||||
var node = zTree.getNodeByParam("id", id,treeNode);
|
||||
if(node){
|
||||
zTree.updateNode(node);
|
||||
zTree.editName(node);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
function removeHoverDom(treeId, treeNode) {
|
||||
$("#addBtn_"+treeNode.id).unbind().remove();
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user