Layui 树形菜单使用

一:如果你的项目中用到了树形菜单,Layui 也许是一个不错的选择:Layui 官方网站链接。

二:使用简介:

1、前端界面,项目中导入Layui 框架

Layui 树形菜单使用_第1张图片

2、前端界面,使用树形菜单控件,由于是Javaweb项目,这里采用jsp页面,代码如下:

<%--
  Created by IntelliJ IDEA.
  User: zyf
  Date: 2019/3/1
  Time: 18:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>




    
    
    
    
    
    
    





    3、数据加载,后台返回一个树形json丢给前端页面就可以展示树形菜单了,后端代码如下:

        //获取组织架构树
        public ArrayList> getOrganizationTree(String rootDept ){
            ArrayList> organizationArray = new ArrayList<>();
            if (rootDept == null || rootDept.isEmpty()){return organizationArray;}
            DataTable organizationDt = dao.getDataTable(" SELECT * FROM FE_BASE5..SYS_GROUP WHERE SG00 >=  '"+rootDept+"'  AND SG21 = 1 AND SG07 = 1 ORDER BY SG00 " , 1 , Integer.MAX_VALUE);
            if (organizationDt != null && organizationDt.getRow() > 0 ){
                for (int i = 0 ; i organizationMap = new HashMap<>();
                    FieldSet organizationFs = organizationDt.getData(i);
                    organizationMap.put("name",organizationFs.getString("SG01"));
                    organizationMap.put("id",organizationFs.getInt("SG00"));
                    organizationMap.put("spread","true");
                    ArrayList> tempArray = getSubOrganization(organizationFs);
                    if (tempArray != null && tempArray.size()>0){
                        organizationMap.put("children",tempArray);
                    }
                    organizationArray.add(organizationMap);
                }
            }
            return organizationArray;
        }
        //组织架构树迭代方法
        public ArrayList> getSubOrganization( FieldSet organizationFs){
            DataTable subDt = dao.getDataTable(" SELECT * FROM FE_BASE5..SYS_GROUP WHERE SG04 = '"+organizationFs.getString("SG04")+"/"+ organizationFs.getString("SG01") + "' AND SG21 = 1 AND SG08 < 9  ORDER BY SG08" , 1 , Integer.MAX_VALUE);
            ArrayList> tempArray = new ArrayList<>();
            if (subDt != null && subDt.getRow() > 0){
                for (int j = 0 ; j tempMap = new HashMap<>();
                    FieldSet subFs = subDt.getData(j);
                    Integer id = subFs.getInt("SG00");
                    System.out.println("-------SG00-------" + id);
                    tempMap.put("name",subFs.getString("SG01"));
                    tempMap.put("id",subFs.getInt("SG00"));
                    tempMap.put("spread","true");
                    ArrayList> nextOaganizationArray = getSubOrganization(subFs);
                    if (nextOaganizationArray != null){
                        tempMap.put("children",nextOaganizationArray);
                    }
                    tempArray.add(tempMap);
                }
            }
            return tempArray;
        }

    4、树形菜单效果图

    Layui 树形菜单使用_第2张图片

     

    你可能感兴趣的:(Java)