有菜单树的接口逻辑

This commit is contained in:
季圣华
2020-04-10 00:17:35 +08:00
parent f1611c3376
commit 9710a32567
2 changed files with 75 additions and 94 deletions

View File

@@ -1,25 +1,50 @@
{{#menu}} {{#menu}}
{{#if children}} {{#if children}}
<li class="treeview"> <li class="treeview">
<a href="javascript:" data-href="blank" class="addTabPage" title="{{text}}" data-code="{{id}}"> <a href="javascript:" data-href="blank" class="addTabPage" title="{{text}}" data-code="{{id}}">
<i class="fa fa-fw {{icon}}"></i> <i class="fa fa-fw {{icon}}"></i>
<span>{{text}}</span> <span>{{text}}</span>
<span class="pull-right-container"> <span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i> <i class="fa fa-angle-left pull-right"></i>
</span> </span>
</a> </a>
<ul class="treeview-menu"> <ul class="treeview-menu">
{{#each children}} {{#if children}}
<li class="treeview"> {{#each children}}
<a href="javascript:" data-href="{{url}}" class="addTabPage" title="{{text}}" <li class="treeview">
data-code="{{id}}"> {{#if url}}
<i class="fa fa-fw {{icon}}"></i> <a href="javascript:" data-href="{{url}}" class="addTabPage" title="{{text}}"
<span>{{text}}</span> data-code="{{id}}">
</a> <i class="fa fa-fw {{icon}}"></i>
</li> <span>{{text}}</span>
{{/each}} </a>
</ul> {{else}}
</li> <a href="javascript:" title="{{text}}" data-code="{{id}}">
{{/if}} <i class="fa fa-fw {{icon}}"></i>
<span>{{text}}</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
{{/if}}
<ul class="treeview-menu">
{{#if children}}
{{#each children}}
<li class="treeview">
<a href="javascript:" data-href="{{url}}" class="addTabPage" title="{{text}}"
data-code="{{id}}">
<i class="fa fa-fw {{icon}}"></i>
<span>{{text}}</span>
</a>
</li>
{{/each}}
{{/if}}
</ul>
</li>
{{/each}}
{{/if}}
</ul>
</li>
{{/if}}
{{/menu}} {{/menu}}

View File

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