diff --git a/erp_web/pages/template/menu.html b/erp_web/pages/template/menu.html index 1b87c815..fcbbe22f 100644 --- a/erp_web/pages/template/menu.html +++ b/erp_web/pages/template/menu.html @@ -1,25 +1,50 @@ {{#menu}} - {{#if children}} -
  • - - - {{text}} - - - - - -
  • - {{/if}} +{{#if children}} +
  • + + + {{text}} + + + + + +
  • +{{/if}} {{/menu}} diff --git a/src/main/java/com/jsh/erp/controller/FunctionsController.java b/src/main/java/com/jsh/erp/controller/FunctionsController.java index 218ecab9..7b87bf09 100644 --- a/src/main/java/com/jsh/erp/controller/FunctionsController.java +++ b/src/main/java/com/jsh/erp/controller/FunctionsController.java @@ -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 dataList = functionsService.getRoleFunctions(pNumber); - if (null != dataList) { - for (Functions functions : dataList) { - JSONObject item = new JSONObject(); - item.put("id", functions.getId()); - List 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 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 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 dataList, String fc) throws Exception { + JSONArray dataArray = new JSONArray(); + for (Functions functions : dataList) { + JSONObject item = new JSONObject(); + List 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; }