1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | <!--layui.js文件必须放到HTML内容的最后-->
<script></script>
layui. use ([ 'element' , 'layer' , 'jquery' , 'tree' ], function (){
var element = layui.element;
var layer = layui.layer;
var $ = layui.jquery;
var menuData = [
{
name: '常用文件夹'
,id: '1'
,children: [
{
name: '所有未读'
,id: '11'
,url: 'http://www.layui.com/'
}, {
name: '置顶邮件'
,id: '12'
}, {
name: '标签邮件'
,id: '13'
}
]
}, {
name: '我的邮箱'
,id: '2'
,children: [
{
name: 'QQ邮箱'
,id: '21'
,spread: true
,children: [
{
name: '收件箱'
,id: '211'
,children: [
{
name: '所有未读'
,id: '2111'
}, {
name: '置顶邮件'
,id: '2112'
}, {
name: '标签邮件'
,id: '2113'
}
]
}, {
name: '已发出的邮件'
,id: '212'
}, {
name: '垃圾邮件'
,id: '213'
}
]
}, {
name: '阿里云邮'
,id: '22'
,children: [
{
name: '收件箱'
,id: '221'
}, {
name: '已发出的邮件'
,id: '222'
}, {
name: '垃圾邮件'
,id: '223'
}
]
}
]
}
]
layui.tree({
elem: '#sidemenubar'
,skin: 'sidebar'
,nodes:menuData
,click: function (node,item){
$( '#sidemenubar a' ).removeClass( 'active' );
$(item).addClass( 'active' );
$(item).siblings( '.layui-tree-spread' ).click();
activeTab.init(node.name,node.url,node.id);
}
});
var activeTab = {
tabTit : '' ,
tabUrl : '' ,
tabId : '' ,
tabCon : function (){
var result;
$.ajax({
type: 'get' ,
url: this.tabUrl,
dataType: 'html' ,
success: function (data){
result = data;
}
})
return result;
},
addTab : function (){
element.tabAdd( 'demo' , {
title: this.tabTit
,content: '<iframe></iframe>'
,id: this.tabId
})
},
changeTab: function (){
element.tabChange( 'demo' , this.tabId);
},
ishasTab : function (){
var _this = this;
var dataId,isflag;
var arrays = $( '.layui-tab-title li' );
$.each(arrays, function (idx,ele){
dataId = $(ele).attr( 'lay-id' );
if (dataId === _this.tabId){
isflag = true
return false
} else {
isflag = false
}
})
return isflag
},
init : function (tabtit,taburl,tabid){
var _this = this;
_this.tabUrl = taburl;
_this.tabId = tabid;
_this.tabTit = tabtit;
if (taburl){
if (!_this.ishasTab()){
_this.addTab();
}
_this.changeTab();
} else {
return false
}
}
}
});
|