仅仅是一个demo,用来给团队示例讲解
/**
* 2019-09-08.
*/
/**
* 创建一级菜单项,没有url,easyUI要求放在panel内部
* @param title
*/
function getPanelHeader(title){
var topMenu = [];
topMenu.push(' <div class="panel-header panel-header-noborder accordion-header accordion-header-selected" style="height: 16px; width: 189px;">');
topMenu.push(' <div class="panel-title panel-with-icon">' + title + '</div>');
topMenu.push(' <div class="panel-tool"> <a href="javascript:void(0)" class="accordion-collapse"></a></div>');
topMenu.push(' </div>');
return topMenu.join("").toString();
}
/**
* 创建子菜单项的容器
*/
function getPanelBody(menuItems){
var topMenu = [];
topMenu.push('<div title="" class="panel-body panel-body-noborder accordion-body" style="display: block; width: 199px;">');
topMenu.push(' <ul class="navlist">');
topMenu.push( menuItems);
topMenu.push( '</ul>');
topMenu.push('</div>');
return topMenu.join("").toString();
}
/**
* 创建菜单子项
* @param title
* @param url
* @returns {string}
*/
function getPanelBoyInsideMenuItem(title,url){
var topMenu = [];
topMenu.push('<li>');
topMenu.push(' <div>');
topMenu.push(' <a href="#" pageUrl="'+ url +'"><img src="../images/increase.png"> <span class="nav">' + title + '</span></a>');
topMenu.push(' </div>');
topMenu.push('</li>');
return topMenu.join("").toString();
}
/**
* 获取本系统菜单数据
* @param iscMenuJson 树的json对象
* @returns {*}
*/
function getMenuData(iscMenuJson){
var funcNode = iscMenuJson.funcNode;
if(funcNode != null && funcNode.length >0){
var menus = funcNode[0];
if(menus != null && menus.length != 0){
return menus.nextNode;
}else{
return null;
}
}
}
function create(node){
var menus = [];
var name = node.currentNode.name;
var url = node.currentNode.url;
var panelHead = getPanelHeader(name);
menus.push(panelHead);
if(hasChildNode(node)){
var childNodes = getChildNode(node);
var items = [];
for(var i = 0; i < childNodes.length;i++){
var childName = childNodes[i].currentNode.name;
var childUrl = childNodes[i].currentNode.url;
if(hasChildNode(childNodes[i])){
items.push(create(childNodes[i]));//递归
}else{
var childItem = getPanelBoyInsideMenuItem(childName,childUrl);
//子节点缓存
items.push(childItem);
}
}
var panelBody = getPanelBody(items.join("").toString());
menus.push(panelBody);
}
return menus.join("").toString();
}
function getChildNode(currentNode){
if(hasChildNode(currentNode)){
return currentNode.nextNode;
}
return null;
}
function hasChildNode(currentNode){
if(currentNode && currentNode.nextNode){
var nextNode = currentNode.nextNode;
return nextNode && nextNode.length != 0;
}
}
网友评论