diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java index 141a28ca4..2721dca56 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java @@ -149,7 +149,7 @@ public class SysDeptController extends BaseController @ResponseBody public List> treeData() { - List> tree = deptService.selectDeptTree(); + List> tree = deptService.selectDeptTree(new SysDept()); return tree; } diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js index d49dddabc..6924adba1 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js @@ -744,6 +744,17 @@ } return true; }, + // 不允许最后层级节点选择 + notAllowLastLevel: function(_tree) { + var nodes = _tree.getSelectedNodes(); + for (var i = 0; i < nodes.length; i++) { + if (nodes[i].level == nodes.length + 1) { + $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")"); + return false; + } + } + return true; + }, // 隐藏/显示搜索栏 toggleSearch: function() { $('#search').slideToggle(200); diff --git a/ruoyi-admin/src/main/resources/templates/system/dept/edit.html b/ruoyi-admin/src/main/resources/templates/system/dept/edit.html index 6dd926d4b..7bb5177e8 100644 --- a/ruoyi-admin/src/main/resources/templates/system/dept/edit.html +++ b/ruoyi-admin/src/main/resources/templates/system/dept/edit.html @@ -123,10 +123,13 @@ } function doSubmit(index, layero){ - var body = layer.getChildFrame('body', index); - $("#treeId").val(body.find('#treeId').val()); - $("#treeName").val(body.find('#treeName').val()); - layer.close(index); + var tree = layero.find("iframe")[0].contentWindow.$._tree; + if ($.tree.notAllowLastLevel(tree)) { + var body = layer.getChildFrame('body', index); + $("#treeId").val(body.find('#treeId').val()); + $("#treeName").val(body.find('#treeName').val()); + layer.close(index); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java index f8f3e3756..b379f7f3a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java @@ -23,9 +23,10 @@ public interface ISysDeptService /** * 查询部门管理树 * + * @param dept 部门信息 * @return 所有部门信息 */ - public List> selectDeptTree(); + public List> selectDeptTree(SysDept dept); /** * 根据角色ID查询菜单 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index a26d130ab..2cfdd30e1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -28,6 +28,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 查询部门管理数据 * + * @param dept 部门信息 * @return 部门信息集合 */ @Override @@ -40,13 +41,15 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 查询部门管理树 * + * @param dept 部门信息 * @return 所有部门信息 */ @Override - public List> selectDeptTree() + @DataScope(tableAlias = "d") + public List> selectDeptTree(SysDept dept) { List> trees = new ArrayList>(); - List deptList = selectDeptList(new SysDept()); + List deptList = deptMapper.selectDeptList(dept); trees = getTrees(deptList, false, null); return trees; }