From 82ded2973740b356723640f483b90a53a228d2b9 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Thu, 7 May 2020 14:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=87=AA=E5=8A=A8=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/templates/tree/tree-user.html | 92 +++++++++---------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html b/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html index b1157e9..ae3300e 100644 --- a/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html +++ b/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html @@ -71,38 +71,45 @@ } // 初始化数据 var initTimeout = null; - var isInited = false; - function initCheckData(zTree) { - if(isInited) { - return; + var isInit = false; + function initSelectNode(zTree) { + var nodes = zTree.transformToArray(zTree.getNodes()); + for(var i = 0, node = nodes[i]; node = nodes[i++];) { + for(var j = 0; item = selectDepartmentUserArray[j++]; ) { + if(node.id == ('u_'+ item.userId) && node.pId == item.departmentId) { + zTree.checkNode(node, true, true); + break; + } + } } + // selectUser(zTree.getCheckedNodes(true)); + } + function initCheckData(zTree) { if(selectedUsers) { if(selectedUsers.length == 0) { return; } - var loadLayerIndex; - top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), { - selectedUsers: selectedUsers - }, null, function(code, data) { - var nodes = zTree.transformToArray(zTree.getNodes()); - for(var i = 0, node = nodes[i]; node = nodes[i++];) { - for(var j = 0, item = data[j]; item = data[j++]; ) { - if(node.id == ('u_'+ item.userId) && node.pId == item.departmentId) { - zTree.checkNode(node, true, true); - break; - } + if(!isInit) { + var loadLayerIndex; + top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), { + selectedUsers: selectedUsers + }, null, function(code, data) { + for(var i = 0, item; item = data[i++];) { + initSelectDepartmentUserArray(item.userId, item.userName, ('【'+ item.departmentName +'】'+ item.userName), item.departmentId); } - } - selectUser(zTree.getCheckedNodes(true)); - }, function(code, data) { - top.dialog.msg(data.msg); - }, function() { - loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3}); - }, function() { - top.dialog.close(loadLayerIndex); - }); + initSelectNode(zTree); + }, function(code, data) { + top.dialog.msg(data.msg); + }, function() { + loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3}); + }, function() { + top.dialog.close(loadLayerIndex); + }); + isInit = true; + } else { + initSelectNode(zTree); + } } - isInited = true; } // 初始化树 function initThree() { @@ -112,7 +119,7 @@ }, async: { enable: true, - autoLoad: false, + autoLoad: true, type: 'get', url: top.restAjax.path('api/department/listztreedepartmentwithuser', []), autoParam:['id'], @@ -131,18 +138,7 @@ return false; }, onAsyncSuccess: function(event, treeId, treeNode) { - if(initTimeout != null) { - clearTimeout(initTimeout) - } - var subNodes = zTree.getNodesByParam('pId', treeNode.id, null); - for(var i = 0, item = subNodes[i]; item = subNodes[i++];) { - if(item.id.indexOf('u_') < 0) { - zTree.expandNode(item, true, false, false); - } - } - initTimeout = setTimeout(function() { - initCheckData(zTree); - }, 500); + initCheckData(zTree); } }, view: { @@ -150,24 +146,26 @@ } }; var zTree = $.fn.zTree.init($('#leftTree'), setting); - zTree.addNodes(null, {id: '0', pId: '-1', name: '根节点', url: 'javascript:void(0);', icon: 'assets/images/tree/tree-department.png', isParent: 'true'}); - common.refreshTree('leftTree'); } initFrame(); initThree(); // 选择人员 + function initSelectDepartmentUserArray(id, name, title, departmentId) { + console.log(title); + selectDepartmentUserArray.push({ + userId: id, + userName: name, + userTitle: title, + departmentId: departmentId, + }); + $('#selectUsers').append(''+ title +' '); + } function selectUser(checkedNodes) { selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length); $('#selectUsers').empty(); for(var i = 0, item = checkedNodes[i]; item = checkedNodes[i++];) { if(item.title && item.title != '') { - selectDepartmentUserArray.push({ - userId: item.id.substring(2, item.id.length), - userName: item.name, - userTitle: item.title, - departmentId: item.pId, - }); - $('#selectUsers').append(''+ item.title +' '); + initSelectDepartmentUserArray(item.id.substring(2, item.id.length), item.name, item.title, item.pId); } } top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;