From 2900dce4fd746a07cfd5c5b96302fab1e8db4438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Mon, 14 Oct 2019 23:35:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=9A=84=E5=8A=9F=E8=83=BD=E5=81=9A=E6=88=90?= =?UTF-8?q?=E5=8D=95=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erp_web/pages/user/userRole.html | 52 +++++++++---------- .../jsh/erp/controller/RoleController.java | 12 +---- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/erp_web/pages/user/userRole.html b/erp_web/pages/user/userRole.html index 4913c278..c676a080 100644 --- a/erp_web/pages/user/userRole.html +++ b/erp_web/pages/user/userRole.html @@ -27,46 +27,44 @@ var url_id = getUrlParam('id'); //获取传值id(用户id) var type = "UserRole"; var url;//定义链接地址 - function GetNode(ctype) { + function getNode() { var node = $('#tt').tree('getChecked'); var cnodes = ''; - var pnodes = ''; - var prevNode = ''; //保存上一步所选父节点 for (var i = 0; i < node.length; i++) { - if ($('#tt').tree('isLeaf', node[i].target)) { cnodes += '[' + node[i].id + ']'; - - var pnode = $('#tt').tree('getParent', node[i].target); //获取当前节点的父节点 - if (prevNode != pnode.id) //保证当前父节点与上一次父节点不同 - { - pnodes += '[' + pnode.id + ']'; - prevNode = pnode.id; //保存当前节点 - } } } - //cnodes = cnodes.substring(0, cnodes.length - 1); - pnodes = pnodes.substring(0, pnodes.length - 1); - - if (ctype == 'child') { - return cnodes; - } - else { - return pnodes - } - ; - }; + return cnodes; + } $(function () { - $('#tt').tree({ url: '/role/findUserRole?UBType=' + type + '&UBKeyId=' + url_id, animate: true, - checkbox: true + checkbox: true, + onSelect: function (node) { + var cknodes = $('#tt').tree("getChecked"); + for (var i = 0; i < cknodes.length; i++) { + if (cknodes[i].id != node.id) { + $('#tt').tree("uncheck", cknodes[i].target); + } + } + if (node.checked) { + $('#tt').tree('uncheck', node.target); + } else { + $('#tt').tree('check', node.target); + } + }, + onLoadSuccess: function (node, data) { + $(this).find('span.tree-checkbox').unbind().click(function () { + $('#tt').tree('select', $(this).parent()); + return false; + }); + } }); - $("#btnOK").click( function () { var id = checkUserRole(); @@ -84,7 +82,7 @@ info: JSON.stringify({ type: type, keyid: url_id, - value: GetNode('child') + value: getNode() }) }, dataType: "json", @@ -102,7 +100,6 @@ }); } ); - }); //检查记录是否存在 @@ -132,6 +129,7 @@ }); return flag; } + \ No newline at end of file diff --git a/src/main/java/com/jsh/erp/controller/RoleController.java b/src/main/java/com/jsh/erp/controller/RoleController.java index acef713d..df049631 100644 --- a/src/main/java/com/jsh/erp/controller/RoleController.java +++ b/src/main/java/com/jsh/erp/controller/RoleController.java @@ -41,13 +41,6 @@ public class RoleController { JSONArray arr = new JSONArray(); try { List dataList = roleService.findUserRole(); - //开始拼接json数据 - JSONObject outer = new JSONObject(); - outer.put("id", 1); - outer.put("text", "角色列表"); - outer.put("state", "open"); - //存放数据json数组 - JSONArray dataArray = new JSONArray(); if (null != dataList) { for (Role role : dataList) { JSONObject item = new JSONObject(); @@ -63,12 +56,9 @@ public class RoleController { if (flag == true) { item.put("checked", true); } - //结束 - dataArray.add(item); + arr.add(item); } } - outer.put("children", dataArray); - arr.add(outer); } catch (Exception e) { e.printStackTrace(); }