forked from gitee/vben-java
优化菜单加载
This commit is contained in:
@@ -45,7 +45,7 @@ public class AuthcService {
|
||||
List<String> btnList = findBtnList(zuser);
|
||||
|
||||
//4.设置前台返回数据
|
||||
menuList = buildTree(menuList);
|
||||
menuList = buildByRecursive(menuList);
|
||||
backMap.put("portals", portalList);
|
||||
backMap.put("menus", menuList);
|
||||
backMap.put("btns", btnList);
|
||||
@@ -133,7 +133,7 @@ public class AuthcService {
|
||||
}
|
||||
|
||||
//4.设置前台返回数据
|
||||
menuList = buildTree(menuList);
|
||||
menuList = buildByRecursive(menuList);
|
||||
backMap.put("portals", portalList);
|
||||
backMap.put("menus", menuList);
|
||||
}
|
||||
@@ -212,8 +212,8 @@ public class AuthcService {
|
||||
List<Zmenu> direList = jdbcDao.getTp().query(direSql, (rs, rowNum) -> {
|
||||
Zmenu zmenu = new Zmenu();
|
||||
zmenu.setType("D");
|
||||
zmenu.setPorid(rs.getString("porid"));
|
||||
zmenu.setId(rs.getString("id"));
|
||||
zmenu.setPorid(rs.getString("porid"));
|
||||
zmenu.setPid(rs.getString("pid"));
|
||||
zmenu.setPerm(rs.getString("perm"));
|
||||
zmenu.setName(rs.getString("code"));
|
||||
@@ -258,7 +258,7 @@ public class AuthcService {
|
||||
List<Zmenu> shouldAddlist1 = new ArrayList<>();
|
||||
for (Zmenu zdire : direList) {
|
||||
for (Zmenu zmenu : list) {
|
||||
if (zmenu.getPid().equals(zdire.getId())) {
|
||||
if (zdire.getId().equals(zmenu.getPid())) {
|
||||
shouldAddlist1.add(zdire);
|
||||
break;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public class AuthcService {
|
||||
for (Zmenu zdire : direList) {
|
||||
for (Zmenu zshould : shouldAddlist1) {
|
||||
if (zshould.getPid() != null) {
|
||||
if (zshould.getPid().equals(zdire.getId())) {
|
||||
if (zdire.getId().equals(zshould.getPid())) {
|
||||
shouldAddlist2.add(zdire);
|
||||
break;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public class AuthcService {
|
||||
for (Zmenu zdire : direList) {
|
||||
for (Zmenu zshould : shouldAddlist2) {
|
||||
if (zshould.getPid() != null) {
|
||||
if (zshould.getPid().equals(zdire.getId())) {
|
||||
if (zdire.getId().equals(zshould.getPid())) {
|
||||
shouldAddlist3.add(zdire);
|
||||
break;
|
||||
}
|
||||
@@ -394,29 +394,74 @@ public class AuthcService {
|
||||
}
|
||||
|
||||
|
||||
// //使用递归方法建树
|
||||
// private List<Zmenu> buildTree(List<Zmenu> treeNodes) {
|
||||
// List<Zmenu> trees = new ArrayList<>();
|
||||
// for (Zmenu treeNode : treeNodes) {
|
||||
// if (treeNode.getPid() == null) {
|
||||
// trees.add(recTree(treeNode, treeNodes));
|
||||
// }
|
||||
// }
|
||||
// return trees;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //递归查找子节点
|
||||
// private Zmenu recTree(Zmenu treeNode, List<Zmenu> treeNodes) {
|
||||
// for (Zmenu it : treeNodes) {
|
||||
// if (treeNode.getId().equals(it.getPid())) {
|
||||
// if (treeNode.getChildren() == null) {
|
||||
// treeNode.setChildren(new ArrayList<>());
|
||||
// }
|
||||
// treeNode.getChildren().add(recTree(it, treeNodes));
|
||||
// }
|
||||
// }
|
||||
// return treeNode;
|
||||
// }
|
||||
|
||||
|
||||
//使用递归方法建树
|
||||
private List<Zmenu> buildTree(List<Zmenu> treeNodes) {
|
||||
List<Zmenu> trees = new ArrayList<>();
|
||||
for (Zmenu treeNode : treeNodes) {
|
||||
if (treeNode.getPid() == null) {
|
||||
trees.add(recTree(treeNode, treeNodes));
|
||||
private List<Zmenu> buildByRecursive(List<Zmenu> nodes)
|
||||
{
|
||||
List<Zmenu> list = new ArrayList<>();
|
||||
for (Zmenu node : nodes) {
|
||||
if (node.getPid() == null)
|
||||
{
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = false;
|
||||
for (Zmenu node2 : nodes) {
|
||||
if (node.getPid().equals(node2.getId()))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
list.add(findChildrenByTier(node, nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
return trees;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
//递归查找子节点
|
||||
private Zmenu recTree(Zmenu treeNode, List<Zmenu> treeNodes) {
|
||||
for (Zmenu it : treeNodes) {
|
||||
if (treeNode.getId().equals(it.getPid())) {
|
||||
if (treeNode.getChildren() == null) {
|
||||
treeNode.setChildren(new ArrayList<>());
|
||||
private Zmenu findChildrenByTier(Zmenu node, List<Zmenu> nodes)
|
||||
{
|
||||
for (Zmenu item : nodes) {
|
||||
if (node.getId().equals(item.getPid()))
|
||||
{
|
||||
if (node.getChildren() == null)
|
||||
{
|
||||
node.setChildren(new ArrayList<>());
|
||||
}
|
||||
treeNode.getChildren().add(recTree(it, treeNodes));
|
||||
node.getChildren().add(findChildrenByTier(item, nodes));
|
||||
}
|
||||
}
|
||||
return treeNode;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,12 +11,8 @@ import java.util.List;
|
||||
public class Zmenu implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
private String id;
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
private String pid;
|
||||
|
||||
@JsonIgnore
|
||||
|
||||
@@ -31,7 +31,7 @@ spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
|
||||
#spring.datasource.primary.url=jdbc:mysql://127.0.0.1:3306/dw?characterEncoding=utf-8&useSSL=false
|
||||
#spring.datasource.primary.username=root
|
||||
#spring.datasource.primary.password=123456
|
||||
spring.datasource.primary.url=jdbc:mysql://127.0.0.1:3306/vboot-java?characterEncoding=utf-8&useSSL=false
|
||||
spring.datasource.primary.url=jdbc:mysql://127.0.0.1:3306/vboot-java2?characterEncoding=utf-8&useSSL=false
|
||||
spring.datasource.primary.username=root
|
||||
spring.datasource.primary.password=123456
|
||||
|
||||
|
||||
Reference in New Issue
Block a user