基于jeecg3.6.6代码修改,替换ListtoMenu类,或只替换getACESubMenu
、getHplusSubMenu
和getLeafOfHplusTree
三个函数
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
+ "\" > </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
+ "\" > </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>");