Jeecg使用多级菜单

基于jeecg3.6.6代码修改,替换ListtoMenu类,或只替换getACESubMenugetHplusSubMenugetLeafOfHplusTree三个函数

package org.jeecgframework.core.util;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jeecgframework.core.enums.SysACEIconEnum;
import org.jeecgframework.web.system.pojo.base.TSFunction;
import org.jeecgframework.web.system.service.MutiLangServiceI;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * 动态菜单栏生成
 * 
 * @author 张代浩
 *  获取是否有子节点不用查询数据库;
 */
public class ListtoMenu {
   

    @Autowired
    private static MutiLangServiceI mutiLangService;

    /**
     * 拼装easyui菜单JSON方式
     * 
     * @param set
     * @param set1
     * @return
     */
    public static String getMenu(List<TSFunction> set, List<TSFunction> set1) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("{\"menus\":[");
        for (TSFunction node : set) {
            String iconClas = "default";// 权限图标样式
            if (node.getTSIcon() != null) {
                iconClas = ResourceUtil.allTSIcons.get(node.getTSIcon().getId()).getIconClas();
            }
            buffer.append("{\"menuid\":\"" + node.getId() + "\",\"icon\":\""
                    + iconClas + "\"," + "\"menuname\":\""
            + getMutiLang(node.getFunctionName()) + "\",\"menus\":[");
            iterGet(set1, node.getId(), buffer);
            buffer.append("]},");
        }
        buffer.append("]}");

        // 将,\n]替换成\n]

        String tmp = buffer.toString();

        tmp = tmp.replaceAll(",\n]", "\n]");
        tmp = tmp.replaceAll(",]}", "]}");
        return tmp;

    }

    static int count = 0;

    /**
     * @param args
     */

    static void iterGet(List<TSFunction> set1, String pid, StringBuffer buffer) {

        for (TSFunction node : set1) {

            // 查找所有父节点为pid的所有对象,然后拼接为json格式的数据
            count++;
            if (node.getTSFunction().getId().equals(pid))

            {
                buffer.append("{\"menuid\":\"" + node.getId()
                        + " \",\"icon\":\"" + ResourceUtil.allTSIcons.get(node.getTSIcon().getId()).getIconClas()
                        + "\"," + "\"menuname\":\"" + getMutiLang(node.getFunctionName())
                        + "\",\"url\":\"" + node.getFunctionUrl() + "\"");
                if (count == set1.size()) {
                    buffer.append("}\n");
                }
                buffer.append("},\n");

            }
        }

    }

    /**
     * 拼装Bootstarp菜单
     * 
     * @param pFunctions
     * @param functions
     * @return
     */
    public static String getBootMenu(List<TSFunction> pFunctions,
            List<TSFunction> functions) {
        StringBuffer menuString = new StringBuffer();
        menuString.append("<ul>");
        for (TSFunction pFunction : pFunctions) {
            menuString.append("<li><a href=\"#\"><span class=\"icon16 icomoon-icon-stats-up\"></span><b>"
            + getMutiLang(pFunction.getFunctionName()) + "</b></a>");
        /*
            int submenusize = pFunction.getSubFunctionSize();
            if (submenusize == 0) {
                menuString.append("</li>");
            }
            if (submenusize > 0) {
                menuString.append("<ul class=\"sub\">");
            }
            for (TSFunction function : functions) {

                if (function.getTSFunction().getId().equals(pFunction.getId())) {
                    menuString
                            .append("<li><a href=\""
                                    + function.getFunctionUrl()
                                    + "\" target=\"contentiframe\"><span class=\"icon16 icomoon-icon-file\"></span>"
                                    + getMutiLang(function.getFunctionName()) + "</a></li>");
                }
            }
            if (submenusize > 0) {
                menuString.append("</ul></li>");
            }*/
            boolean hasSubfun=pFunction.hasSubFunction(functions);
            if(!hasSubfun){
                menuString.append("</li>");
            }else{
                menuString.append("<ul class=\"sub\">");
            }
            for (TSFunction function : functions) {
                if (function.getTSFunction().getId().equals(pFunction.getId())) {
                    menuString.append("<li><a href=\""
                                    + function.getFunctionUrl()
                                    + "\" target=\"contentiframe\"><span class=\"icon16 icomoon-icon-file\"></span>"
                                    + getMutiLang(function.getFunctionName()) + "</a></li>");
                }
            }
            if (hasSubfun) {
                menuString.append("</ul></li>");
            }
        }
        menuString.append("</ul>");
        return menuString.toString();

    }

    /**
     * 拼装EASYUI菜单
     * 
     * @param pFunctions
     * @param functions
     * @return
     */
    public static String getEasyuiMenu(List<TSFunction> pFunctions,
            List<TSFunction> functions) {
        StringBuffer menuString = new StringBuffer();
        for (TSFunction pFunction : pFunctions) {
            menuString.append("<div  title=\"" + getMutiLang(pFunction.getFunctionName())
                    + "\" iconCls=\"" + ResourceUtil.allTSIcons.get(pFunction.getTSIcon().getId()).getIconClas()
                    + "\">");
            /*int submenusize = pFunction.getSubFunctionSize();
            if (submenusize == 0) {
                menuString.append("</div>");
            }
            if (submenusize > 0) {
                menuString.append("<ul>");
            }
            for (TSFunction function : functions) {

                if (function.getTSFunction().getId().equals(pFunction.getId())) {
                    String icon = "folder";
                    if (function.getTSIcon() != null) {
                        icon = ResourceUtil.allTSIcons.get(function.getTSIcon().getId()).getIconClas();
                    }
                    menuString.append("<li><div onclick=\"addTab(\'"
                            + getMutiLang(function.getFunctionName()) + "\',\'"
                            + function.getFunctionUrl() + "&clickFunctionId="
                            + function.getId() + "\',\'" + icon
                            + "\')\"  title=\"" + getMutiLang(function.getFunctionName())
                            + "\" url=\"" + function.getFunctionUrl()
                            + "\" iconCls=\"" + icon + "\"> <a class=\""
                            + getMutiLang(function.getFunctionName())
                            + "\" href=\"#\" > <span class=\"icon " + icon
                            + "\" >&nbsp;</span> <span class=\"nav\" >"
                            + getMutiLang(function.getFunctionName())
                            + "</span></a></div></li>");
                }
            }
            if (submenusize > 0) {
                menuString.append("</ul></div>");
            }*/

            boolean hasSubfun =pFunction.hasSubFunction(functions);
            if(!hasSubfun){
                menuString.append("</div>");
            }else{
                menuString.append("<ul>");
            }
            for (TSFunction function : functions) {
                if (function.getTSFunction().getId().equals(pFunction.getId())) {
                    String icon = "folder";
                    if (function.getTSIcon() != null) {
                        icon = ResourceUtil.allTSIcons.get(function.getTSIcon().getId()).getIconClas();
                    }
                    menuString.append("<li><div onclick=\"addTab(\'"
                            + getMutiLang(function.getFunctionName()) + "\',\'"
                            + function.getFunctionUrl() + "&clickFunctionId="
                            + function.getId() + "\',\'" + icon
                            + "\')\"  title=\"" + getMutiLang(function.getFunctionName())
                            + "\" url=\"" + function.getFunctionUrl()
                            + "\" iconCls=\"" + icon + "\"> <a class=\""
                            + getMutiLang(function.getFunctionName())
                            + "\" href=\"#\" > <span class=\"icon " + icon
                            + "\" >&nbsp;</span> <span class=\"nav\" >"
                            + getMutiLang(function.getFunctionName())
                            + "</span></a></div></li>");
                }
            }
            if (hasSubfun) {
                menuString.append("</ul></div>");
            }
        }
        return menuString.toString();

    }

    /**
     * 拼装EASYUI 多级 菜单
     * 
     * @param pFunctions
     * @param functions
     * @return
     */
    public static String getEasyuiMultistageMenu(
            Map<Integer, List<TSFunction>> map) {
        StringBuffer menuString = new StringBuffer();
        List<TSFunction> list = map.get(0);
        for (TSFunction function : list) {
            menuString.append("<div   title=\"" + getMutiLang(function.getFunctionName())
                    + "\" iconCls=\"" + ResourceUtil.allTSIcons.get(function.getTSIcon().getId()).getIconClas()
                    + "\">");
            /*int submenusize = function.getSubFunctionSize();
            if (submenusize == 0) {
                menuString.append("</div>");
            }
            if (submenusize > 0) {
                menuString.append("<ul>");
            }
            menuString.append(getChild(function,1,map));
            if (submenusize > 0) {
                menuString.append("</ul></div>");
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值