有菜单树的接口逻辑
This commit is contained in:
@@ -42,82 +42,38 @@ public class FunctionsController {
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
try {
|
||||
String fc = hasFunctions; //当前用户所拥有的功能列表,格式如:[1][2][5]
|
||||
//当前用户所拥有的功能列表,格式如:[1][2][5]
|
||||
String fc = hasFunctions;
|
||||
List<Functions> dataList = functionsService.getRoleFunctions(pNumber);
|
||||
if (null != dataList) {
|
||||
for (Functions functions : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", functions.getId());
|
||||
List<Functions> dataList1 = functionsService.getRoleFunctions(functions.getNumber());
|
||||
JSONArray dataArray1 = new JSONArray();
|
||||
if (dataList1.size() != 0) {
|
||||
item.put("text", functions.getName()); //是目录就没链接
|
||||
item.put("icon", functions.getIcon());
|
||||
for (Functions functions1 : dataList1) {
|
||||
item.put("state", "open"); //如果不为空,节点展开
|
||||
JSONObject item1 = new JSONObject();
|
||||
List<Functions> dataList2 = functionsService.getRoleFunctions(functions1.getNumber());
|
||||
if (fc.indexOf("[" + functions1.getId().toString() + "]") != -1 || dataList2.size() != 0) {
|
||||
item1.put("id", functions1.getId());
|
||||
JSONArray dataArray2 = new JSONArray();
|
||||
if (dataList2.size() != 0) {
|
||||
item1.put("text", functions1.getName());//是目录就没链接
|
||||
item1.put("icon", functions1.getIcon());
|
||||
for (Functions functions2 : dataList2) {
|
||||
item1.put("state", "closed"); //如果不为空,节点不展开
|
||||
JSONObject item2 = new JSONObject();
|
||||
List<Functions> dataList3 = functionsService.getRoleFunctions(functions2.getNumber());
|
||||
if (fc.indexOf("[" + functions2.getId().toString() + "]") != -1 || dataList3.size() != 0) {
|
||||
item2.put("id", functions2.getId());
|
||||
JSONArray dataArray3 = new JSONArray();
|
||||
if (dataList3.size() != 0) {
|
||||
item2.put("text", functions2.getName());//是目录就没链接
|
||||
item2.put("icon", functions2.getIcon());
|
||||
for (Functions functions3 : dataList3) {
|
||||
item2.put("state", "closed"); //如果不为空,节点不展开
|
||||
JSONObject item3 = new JSONObject();
|
||||
item3.put("id", functions3.getId());
|
||||
item3.put("text", functions3.getName());
|
||||
item3.put("icon", functions3.getIcon());
|
||||
//
|
||||
dataArray3.add(item3);
|
||||
item2.put("children", dataArray3);
|
||||
}
|
||||
} else {
|
||||
//不是目录,有链接
|
||||
item2.put("text", functions2.getName());
|
||||
item2.put("icon", functions2.getIcon());
|
||||
item2.put("url", functions2.getUrl());
|
||||
dataArray2.add(item2);
|
||||
item1.put("children", dataArray2);
|
||||
}
|
||||
} else {
|
||||
//不是目录,有链接
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不是目录,有链接
|
||||
item1.put("text", functions1.getName());
|
||||
item1.put("icon", functions1.getIcon());
|
||||
item1.put("url", functions1.getUrl());
|
||||
dataArray1.add(item1);
|
||||
item.put("children", dataArray1);
|
||||
}
|
||||
} else {
|
||||
//不是目录,有链接
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不是目录,有链接
|
||||
item.put("text", functions.getName());
|
||||
item.put("icon", functions.getIcon());
|
||||
item.put("url", functions.getUrl());
|
||||
}
|
||||
if (dataList.size() != 0) {
|
||||
dataArray = getMenuByFunction(dataList, fc);
|
||||
}
|
||||
} catch (DataAccessException e) {
|
||||
logger.error(">>>>>>>>>>>>>>>>>>>查找异常", e);
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
public JSONArray getMenuByFunction(List<Functions> dataList, String fc) throws Exception {
|
||||
JSONArray dataArray = new JSONArray();
|
||||
for (Functions functions : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
List<Functions> newList = functionsService.getRoleFunctions(functions.getNumber());
|
||||
item.put("id", functions.getId());
|
||||
item.put("text", functions.getName());
|
||||
item.put("icon", functions.getIcon());
|
||||
if (newList.size()>0) {
|
||||
JSONArray childrenArr = getMenuByFunction(newList, fc);
|
||||
if(childrenArr.size()>0) {
|
||||
item.put("children", childrenArr);
|
||||
dataArray.add(item);
|
||||
}
|
||||
} else {
|
||||
item.put("url", functions.getUrl());
|
||||
if (fc.indexOf("[" + functions.getId().toString() + "]") != -1) {
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
} catch (DataAccessException e) {
|
||||
logger.error(">>>>>>>>>>>>>>>>>>>查找应用异常", e);
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user