mirror of https://gitee.com/y_project/RuoYi.git
Ztree树结构优化
parent
161c0f1a67
commit
1d01d20b49
|
@ -1,7 +1,6 @@
|
||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -11,15 +10,16 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.base.AjaxResult;
|
import com.ruoyi.common.base.AjaxResult;
|
||||||
|
import com.ruoyi.common.base.Ztree;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.util.ShiroUtils;
|
import com.ruoyi.framework.util.ShiroUtils;
|
||||||
|
import com.ruoyi.framework.web.base.BaseController;
|
||||||
import com.ruoyi.system.domain.SysDept;
|
import com.ruoyi.system.domain.SysDept;
|
||||||
import com.ruoyi.system.domain.SysRole;
|
import com.ruoyi.system.domain.SysRole;
|
||||||
import com.ruoyi.system.service.ISysDeptService;
|
import com.ruoyi.system.service.ISysDeptService;
|
||||||
import com.ruoyi.framework.web.base.BaseController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门信息
|
* 部门信息
|
||||||
|
@ -147,10 +147,10 @@ public class SysDeptController extends BaseController
|
||||||
*/
|
*/
|
||||||
@GetMapping("/treeData")
|
@GetMapping("/treeData")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Map<String, Object>> treeData()
|
public List<Ztree> treeData()
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> tree = deptService.selectDeptTree(new SysDept());
|
List<Ztree> ztrees = deptService.selectDeptTree(new SysDept());
|
||||||
return tree;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,9 +158,9 @@ public class SysDeptController extends BaseController
|
||||||
*/
|
*/
|
||||||
@GetMapping("/roleDeptTreeData")
|
@GetMapping("/roleDeptTreeData")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Map<String, Object>> deptTreeData(SysRole role)
|
public List<Ztree> deptTreeData(SysRole role)
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> tree = deptService.roleDeptTreeData(role);
|
List<Ztree> ztrees = deptService.roleDeptTreeData(role);
|
||||||
return tree;
|
return ztrees;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -13,12 +12,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.base.AjaxResult;
|
import com.ruoyi.common.base.AjaxResult;
|
||||||
|
import com.ruoyi.common.base.Ztree;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import com.ruoyi.framework.util.ShiroUtils;
|
import com.ruoyi.framework.util.ShiroUtils;
|
||||||
|
import com.ruoyi.framework.web.base.BaseController;
|
||||||
import com.ruoyi.system.domain.SysMenu;
|
import com.ruoyi.system.domain.SysMenu;
|
||||||
import com.ruoyi.system.domain.SysRole;
|
import com.ruoyi.system.domain.SysRole;
|
||||||
import com.ruoyi.system.service.ISysMenuService;
|
import com.ruoyi.system.service.ISysMenuService;
|
||||||
import com.ruoyi.framework.web.base.BaseController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单信息
|
* 菜单信息
|
||||||
|
@ -154,10 +154,10 @@ public class SysMenuController extends BaseController
|
||||||
*/
|
*/
|
||||||
@GetMapping("/roleMenuTreeData")
|
@GetMapping("/roleMenuTreeData")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Map<String, Object>> roleMenuTreeData(SysRole role)
|
public List<Ztree> roleMenuTreeData(SysRole role)
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> tree = menuService.roleMenuTreeData(role);
|
List<Ztree> ztrees = menuService.roleMenuTreeData(role);
|
||||||
return tree;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,10 +165,10 @@ public class SysMenuController extends BaseController
|
||||||
*/
|
*/
|
||||||
@GetMapping("/menuTreeData")
|
@GetMapping("/menuTreeData")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Map<String, Object>> menuTreeData(SysRole role)
|
public List<Ztree> menuTreeData(SysRole role)
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> tree = menuService.menuTreeData();
|
List<Ztree> ztrees = menuService.menuTreeData();
|
||||||
return tree;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -842,48 +842,50 @@
|
||||||
_lastValue: {},
|
_lastValue: {},
|
||||||
// 初始化树结构
|
// 初始化树结构
|
||||||
init: function(options) {
|
init: function(options) {
|
||||||
|
var defaults = {
|
||||||
|
id: "tree", // 属性ID
|
||||||
|
expandLevel: 0, // 展开等级节点
|
||||||
|
view: {
|
||||||
|
selectedMulti: false, // 设置是否允许同时选中多个节点
|
||||||
|
nameIsHTML: true // 设置 name 属性是否支持 HTML 脚本
|
||||||
|
},
|
||||||
|
check: {
|
||||||
|
enable: false, // 置 zTree 的节点上是否显示 checkbox / radio
|
||||||
|
nocheckInherit: true, // 设置子节点是否自动继承
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
key: {
|
||||||
|
title: "title" // 节点数据保存节点提示信息的属性名称
|
||||||
|
},
|
||||||
|
simpleData: {
|
||||||
|
enable: true // true / false 分别表示 使用 / 不使用 简单数据模式
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var options = $.extend(defaults, options);
|
||||||
$.tree._option = options;
|
$.tree._option = options;
|
||||||
// 属性ID
|
|
||||||
var _id = $.common.isEmpty(options.id) ? "tree" : options.id;
|
|
||||||
// 展开等级节点
|
|
||||||
var _expandLevel = $.common.isEmpty(options.expandLevel) ? 0 : options.expandLevel;
|
|
||||||
// 树结构初始化加载
|
// 树结构初始化加载
|
||||||
var setting = {
|
var setting = {
|
||||||
|
callback: {
|
||||||
|
onClick: options.onClick, // 用于捕获节点被点击的事件回调函数
|
||||||
|
onCheck: options.onCheck, // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数
|
||||||
|
onDblClick: options.onDblClick // 用于捕获鼠标双击之后的事件回调函数
|
||||||
|
},
|
||||||
check: options.check,
|
check: options.check,
|
||||||
view: { selectedMulti: false, nameIsHTML: true },
|
view: options.view,
|
||||||
data: { key: { title: "title" }, simpleData: { enable: true } },
|
data: options.data
|
||||||
callback: { onClick: options.onClick }
|
|
||||||
};
|
};
|
||||||
$.get(options.url, function(data) {
|
$.get(options.url, function(data) {
|
||||||
var treeName = $("#treeName").val();
|
|
||||||
var treeId = $("#treeId").val();
|
var treeId = $("#treeId").val();
|
||||||
tree = $.fn.zTree.init($("#" + _id), setting, data);
|
tree = $.fn.zTree.init($("#" + options.id), setting, data);
|
||||||
$._tree = tree;
|
$._tree = tree;
|
||||||
// 展开第一级节点
|
var nodes = tree.getNodesByParam("level", options.expandLevel - 1);
|
||||||
var nodes = tree.getNodesByParam("level", 0);
|
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
if(_expandLevel > 0) {
|
|
||||||
tree.expandNode(nodes[i], true, false, false);
|
tree.expandNode(nodes[i], true, false, false);
|
||||||
}
|
}
|
||||||
$.tree.selectByIdName(treeId, treeName, nodes[i]);
|
var node = tree.getNodesByParam("id", treeId, null)[0];
|
||||||
}
|
$.tree.selectByIdName(treeId, node);
|
||||||
// 展开第二级节点
|
});
|
||||||
nodes = tree.getNodesByParam("level", 1);
|
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
|
||||||
if(_expandLevel > 1) {
|
|
||||||
tree.expandNode(nodes[i], true, false, false);
|
|
||||||
}
|
|
||||||
$.tree.selectByIdName(treeId, treeName, nodes[i]);
|
|
||||||
}
|
|
||||||
// 展开第三级节点
|
|
||||||
nodes = tree.getNodesByParam("level", 2);
|
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
|
||||||
if(_expandLevel > 2) {
|
|
||||||
tree.expandNode(nodes[i], true, false, false);
|
|
||||||
}
|
|
||||||
$.tree.selectByIdName(treeId, treeName, nodes[i]);
|
|
||||||
}
|
|
||||||
}, null, null, "正在加载,请稍后...");
|
|
||||||
},
|
},
|
||||||
// 搜索节点
|
// 搜索节点
|
||||||
searchNode: function() {
|
searchNode: function() {
|
||||||
|
@ -905,12 +907,10 @@
|
||||||
$.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
|
$.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
|
||||||
},
|
},
|
||||||
// 根据Id和Name选中指定节点
|
// 根据Id和Name选中指定节点
|
||||||
selectByIdName: function(treeId, treeName, node) {
|
selectByIdName: function(treeId, node) {
|
||||||
if ($.common.isNotEmpty(treeName) && $.common.isNotEmpty(treeId)) {
|
if ($.common.isNotEmpty(treeId) && treeId == node.id) {
|
||||||
if (treeId == node.id && treeName == node.name) {
|
|
||||||
$._tree.selectNode(node, true);
|
$._tree.selectNode(node, true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// 显示所有节点
|
// 显示所有节点
|
||||||
showAllNode: function(nodes) {
|
showAllNode: function(nodes) {
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
var options = {
|
var options = {
|
||||||
id: "menuTrees",
|
id: "menuTrees",
|
||||||
url: url,
|
url: url,
|
||||||
check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "ps", "N": "ps" } },
|
check: { enable: true },
|
||||||
expandLevel: 0
|
expandLevel: 0
|
||||||
};
|
};
|
||||||
$.tree.init(options);
|
$.tree.init(options);
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
var options = {
|
var options = {
|
||||||
id: "menuTrees",
|
id: "menuTrees",
|
||||||
url: url,
|
url: url,
|
||||||
check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "ps", "N": "ps" } },
|
check: { enable: true },
|
||||||
expandLevel: 0
|
expandLevel: 0
|
||||||
};
|
};
|
||||||
$.tree.init(options);
|
$.tree.init(options);
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.ruoyi.common.base;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ztree树结构实体类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class Ztree implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 节点ID */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 节点父ID */
|
||||||
|
private Long pId;
|
||||||
|
|
||||||
|
/** 节点名称 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 节点标题 */
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/** 是否勾选 */
|
||||||
|
private boolean checked = false;
|
||||||
|
|
||||||
|
/** 是否展开 */
|
||||||
|
private boolean open = false;
|
||||||
|
|
||||||
|
/** 是否能勾选 */
|
||||||
|
private boolean nocheck = false;
|
||||||
|
|
||||||
|
public Long getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getpId()
|
||||||
|
{
|
||||||
|
return pId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setpId(Long pId)
|
||||||
|
{
|
||||||
|
this.pId = pId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title)
|
||||||
|
{
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChecked()
|
||||||
|
{
|
||||||
|
return checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChecked(boolean checked)
|
||||||
|
{
|
||||||
|
this.checked = checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOpen()
|
||||||
|
{
|
||||||
|
return open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpen(boolean open)
|
||||||
|
{
|
||||||
|
this.open = open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNocheck()
|
||||||
|
{
|
||||||
|
return nocheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNocheck(boolean nocheck)
|
||||||
|
{
|
||||||
|
this.nocheck = nocheck;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.ruoyi.system.service;
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import com.ruoyi.common.base.Ztree;
|
||||||
import com.ruoyi.system.domain.SysDept;
|
import com.ruoyi.system.domain.SysDept;
|
||||||
import com.ruoyi.system.domain.SysRole;
|
import com.ruoyi.system.domain.SysRole;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public interface ISysDeptService
|
||||||
* @param dept 部门信息
|
* @param dept 部门信息
|
||||||
* @return 所有部门信息
|
* @return 所有部门信息
|
||||||
*/
|
*/
|
||||||
public List<Map<String, Object>> selectDeptTree(SysDept dept);
|
public List<Ztree> selectDeptTree(SysDept dept);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询菜单
|
* 根据角色ID查询菜单
|
||||||
|
@ -34,7 +34,7 @@ public interface ISysDeptService
|
||||||
* @param role 角色对象
|
* @param role 角色对象
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
public List<Map<String, Object>> roleDeptTreeData(SysRole role);
|
public List<Ztree> roleDeptTreeData(SysRole role);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门人数
|
* 查询部门人数
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.ruoyi.system.service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import com.ruoyi.common.base.Ztree;
|
||||||
import com.ruoyi.system.domain.SysMenu;
|
import com.ruoyi.system.domain.SysMenu;
|
||||||
import com.ruoyi.system.domain.SysRole;
|
import com.ruoyi.system.domain.SysRole;
|
||||||
import com.ruoyi.system.domain.SysUser;
|
import com.ruoyi.system.domain.SysUser;
|
||||||
|
@ -51,14 +52,14 @@ public interface ISysMenuService
|
||||||
* @param role 角色对象
|
* @param role 角色对象
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
public List<Map<String, Object>> roleMenuTreeData(SysRole role);
|
public List<Ztree> roleMenuTreeData(SysRole role);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有菜单信息
|
* 查询所有菜单信息
|
||||||
*
|
*
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
public List<Map<String, Object>> menuTreeData();
|
public List<Ztree> menuTreeData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询系统所有权限
|
* 查询系统所有权限
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.common.annotation.DataScope;
|
import com.ruoyi.common.annotation.DataScope;
|
||||||
|
import com.ruoyi.common.base.Ztree;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.exception.BusinessException;
|
import com.ruoyi.common.exception.BusinessException;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
@ -47,12 +46,11 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@DataScope(tableAlias = "d")
|
@DataScope(tableAlias = "d")
|
||||||
public List<Map<String, Object>> selectDeptTree(SysDept dept)
|
public List<Ztree> selectDeptTree(SysDept dept)
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
|
||||||
List<SysDept> deptList = deptMapper.selectDeptList(dept);
|
List<SysDept> deptList = deptMapper.selectDeptList(dept);
|
||||||
trees = getTrees(deptList, false, null);
|
List<Ztree> ztrees = initZtree(deptList);
|
||||||
return trees;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,56 +60,63 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
* @return 部门列表(数据权限)
|
* @return 部门列表(数据权限)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> roleDeptTreeData(SysRole role)
|
public List<Ztree> roleDeptTreeData(SysRole role)
|
||||||
{
|
{
|
||||||
Long roleId = role.getRoleId();
|
Long roleId = role.getRoleId();
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
||||||
List<SysDept> deptList = selectDeptList(new SysDept());
|
List<SysDept> deptList = selectDeptList(new SysDept());
|
||||||
if (StringUtils.isNotNull(roleId))
|
if (StringUtils.isNotNull(roleId))
|
||||||
{
|
{
|
||||||
List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId);
|
List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId);
|
||||||
trees = getTrees(deptList, true, roleDeptList);
|
ztrees = initZtree(deptList, roleDeptList);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trees = getTrees(deptList, false, null);
|
ztrees = initZtree(deptList);
|
||||||
}
|
}
|
||||||
return trees;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象转部门树
|
* 对象转部门树
|
||||||
*
|
*
|
||||||
* @param deptList 部门列表
|
* @param deptList 部门列表
|
||||||
* @param isCheck 是否需要选中
|
* @return 树结构列表
|
||||||
* @param roleDeptList 角色已存在菜单列表
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public List<Map<String, Object>> getTrees(List<SysDept> deptList, boolean isCheck, List<String> roleDeptList)
|
public List<Ztree> initZtree(List<SysDept> deptList)
|
||||||
|
{
|
||||||
|
return initZtree(deptList, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转部门树
|
||||||
|
*
|
||||||
|
* @param deptList 部门列表
|
||||||
|
* @param roleDeptList 角色已存在菜单列表
|
||||||
|
* @return 树结构列表
|
||||||
|
*/
|
||||||
|
public List<Ztree> initZtree(List<SysDept> deptList, List<String> roleDeptList)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
||||||
|
boolean isCheck = StringUtils.isNotNull(roleDeptList);
|
||||||
for (SysDept dept : deptList)
|
for (SysDept dept : deptList)
|
||||||
{
|
{
|
||||||
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
|
||||||
{
|
{
|
||||||
Map<String, Object> deptMap = new HashMap<String, Object>();
|
Ztree ztree = new Ztree();
|
||||||
deptMap.put("id", dept.getDeptId());
|
ztree.setId(dept.getDeptId());
|
||||||
deptMap.put("pId", dept.getParentId());
|
ztree.setpId(dept.getParentId());
|
||||||
deptMap.put("name", dept.getDeptName());
|
ztree.setName(dept.getDeptName());
|
||||||
deptMap.put("title", dept.getDeptName());
|
ztree.setTitle(dept.getDeptName());
|
||||||
if (isCheck)
|
if (isCheck)
|
||||||
{
|
{
|
||||||
deptMap.put("checked", roleDeptList.contains(dept.getDeptId() + dept.getDeptName()));
|
ztree.setChecked(roleDeptList.contains(dept.getDeptId() + dept.getDeptName()));
|
||||||
}
|
}
|
||||||
else
|
ztrees.add(ztree);
|
||||||
{
|
|
||||||
deptMap.put("checked", false);
|
|
||||||
}
|
|
||||||
trees.add(deptMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return trees;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,16 +3,15 @@ package com.ruoyi.system.service.impl;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.ruoyi.common.base.Ztree;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.system.domain.SysMenu;
|
import com.ruoyi.system.domain.SysMenu;
|
||||||
|
@ -110,21 +109,21 @@ public class SysMenuServiceImpl implements ISysMenuService
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> roleMenuTreeData(SysRole role)
|
public List<Ztree> roleMenuTreeData(SysRole role)
|
||||||
{
|
{
|
||||||
Long roleId = role.getRoleId();
|
Long roleId = role.getRoleId();
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
||||||
List<SysMenu> menuList = menuMapper.selectMenuAll();
|
List<SysMenu> menuList = menuMapper.selectMenuAll();
|
||||||
if (StringUtils.isNotNull(roleId))
|
if (StringUtils.isNotNull(roleId))
|
||||||
{
|
{
|
||||||
List<String> roleMenuList = menuMapper.selectMenuTree(roleId);
|
List<String> roleMenuList = menuMapper.selectMenuTree(roleId);
|
||||||
trees = getTrees(menuList, true, roleMenuList, true);
|
ztrees = initZtree(menuList, roleMenuList, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trees = getTrees(menuList, false, null, true);
|
ztrees = initZtree(menuList, null, true);
|
||||||
}
|
}
|
||||||
return trees;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,12 +132,11 @@ public class SysMenuServiceImpl implements ISysMenuService
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> menuTreeData()
|
public List<Ztree> menuTreeData()
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
|
||||||
List<SysMenu> menuList = menuMapper.selectMenuAll();
|
List<SysMenu> menuList = menuMapper.selectMenuAll();
|
||||||
trees = getTrees(menuList, false, null, false);
|
List<Ztree> ztrees = initZtree(menuList);
|
||||||
return trees;
|
return ztrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,33 +163,39 @@ public class SysMenuServiceImpl implements ISysMenuService
|
||||||
* 对象转菜单树
|
* 对象转菜单树
|
||||||
*
|
*
|
||||||
* @param menuList 菜单列表
|
* @param menuList 菜单列表
|
||||||
* @param isCheck 是否需要选中
|
* @return 树结构列表
|
||||||
|
*/
|
||||||
|
public List<Ztree> initZtree(List<SysMenu> menuList)
|
||||||
|
{
|
||||||
|
return initZtree(menuList, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转菜单树
|
||||||
|
*
|
||||||
|
* @param menuList 菜单列表
|
||||||
* @param roleMenuList 角色已存在菜单列表
|
* @param roleMenuList 角色已存在菜单列表
|
||||||
* @param permsFlag 是否需要显示权限标识
|
* @param permsFlag 是否需要显示权限标识
|
||||||
* @return
|
* @return 树结构列表
|
||||||
*/
|
*/
|
||||||
public List<Map<String, Object>> getTrees(List<SysMenu> menuList, boolean isCheck, List<String> roleMenuList,
|
public List<Ztree> initZtree(List<SysMenu> menuList, List<String> roleMenuList, boolean permsFlag)
|
||||||
boolean permsFlag)
|
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
||||||
|
boolean isCheck = StringUtils.isNotNull(roleMenuList);
|
||||||
for (SysMenu menu : menuList)
|
for (SysMenu menu : menuList)
|
||||||
{
|
{
|
||||||
Map<String, Object> deptMap = new HashMap<String, Object>();
|
Ztree ztree = new Ztree();
|
||||||
deptMap.put("id", menu.getMenuId());
|
ztree.setId(menu.getMenuId());
|
||||||
deptMap.put("pId", menu.getParentId());
|
ztree.setpId(menu.getParentId());
|
||||||
deptMap.put("name", transMenuName(menu, roleMenuList, permsFlag));
|
ztree.setName(transMenuName(menu, roleMenuList, permsFlag));
|
||||||
deptMap.put("title", menu.getMenuName());
|
ztree.setTitle(menu.getMenuName());
|
||||||
if (isCheck)
|
if (isCheck)
|
||||||
{
|
{
|
||||||
deptMap.put("checked", roleMenuList.contains(menu.getMenuId() + menu.getPerms()));
|
ztree.setChecked(roleMenuList.contains(menu.getMenuId() + menu.getPerms()));
|
||||||
}
|
}
|
||||||
else
|
ztrees.add(ztree);
|
||||||
{
|
|
||||||
deptMap.put("checked", false);
|
|
||||||
}
|
}
|
||||||
trees.add(deptMap);
|
return ztrees;
|
||||||
}
|
|
||||||
return trees;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String transMenuName(SysMenu menu, List<String> roleMenuList, boolean permsFlag)
|
public String transMenuName(SysMenu menu, List<String> roleMenuList, boolean permsFlag)
|
||||||
|
|
Loading…
Reference in New Issue