layui.define(['layer','element', 'forTree'], function(exports) { var layer = layui.layer; var element = layui.element(); var forTree = layui.forTree; var $ = layui.jquery; var nav = null; var tab = null; var tabContent = null; var tabTitle = null; var navFilter = null; var tabFilter = null; /** * 添加导航 */ function addNav(data, topId, idName, pidName, nodeName, urlName) { topId = topId || 0; idName = idName || 'id'; pidName = pidName || 'pid'; nodeName = nodeName || 'node'; urlName = urlName || 'url'; var myTree = new forTree(data, idName, pidName, topId); var html = ''; myTree.forBefore = function (v, k, hasChildren) { html += '
  • '; }; myTree.forCurr = function(v, k, hasChildren) { html += ''; html += v[nodeName]; html += ''; }; myTree.callBefore = function (v, k) { html += ''; }; myTree.forAfter = function (v, k, hasChildren) { html += '
  • '; }; myTree.each(); nav.append(html); element.init('nav('+navFilter+')'); } /** * 将侧边栏与顶部切换卡进行绑定 */ function bind(height) { height = height || 60 + 41 + 44; //头部高度 顶部切换卡标题高度 底部高度 /** * iframe自适应 */ $(window).resize(function() { //设置顶部切换卡容器度 tabContent.height($(this).height() - height); //设置顶部切换卡容器内每个iframe高度 tabContent.find('iframe').each(function () { $(this).height(tabContent.height()); }); }).resize(); /** * 监听侧边栏导航点击事件 */ element.on('nav('+navFilter+')', function(elem) { var a = elem.children('a'); var title = a.text(); var src = elem.children('a').attr('data-url'); var id = elem.children('a').attr('data-id'); var frame = tabContent.find('iframe[data-id='+id+']').eq(0); var tabIndex = (new Date()).getTime(); if(src != undefined && src != null && id != undefined && id != null) { if(frame.length) { //存在 iframe //获取iframe身上的tab index tabIndex = frame.attr('data-tabindex'); }else{ //不存在 iframe //显示加载层 var tmpIndex = layer.load(); //设置1秒后再次关闭loading setTimeout(function() { layer.close(tmpIndex); }, 1000); //拼接iframe var newFrame = '