leftNav.js
3.72 KB
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
function navBar(strData, parValue) {
var data;
if (typeof (strData) == "string") {
var data = JSON.parse(strData); //部分用户解析出来的是字符串,转换一下
} else {
data = strData;
}
var isFirst = true;
var ulHtml = '<ul class="layui-nav layui-nav-tree">';
for (var i = 0; i < data.length; i++) {
if (data[i].Item.IsShow == 0) {
continue;
}
var strHtml = "";
if (data[i].Children != undefined && data[i].Children.length > 0) {
var strItem = "";
for (var j = 0; j < data[i].Children.length; j++) {
if (data[i].Children[j].Item.IsShow == 0) {
continue;
}
if (parValue == "" || data[i].Children[j].Item.Name.indexOf(parValue) >= 0) {
var itemName = data[i].Children[j].Item.Code;
if (isFirst && parValue != "") {
isFirst = false;
itemName = "firstMenu";
}
if (data[i].Children[j].target == "_blank") {
strItem += '<dd><a title=' + data[i].Children[j].Item.Name +' href="javascript:;" id="' + itemName + '" data-url="' + data[i].Children[j].Item.Url + '" target="' + data[i].Children[j].target + '">';
} else {
strItem += '<dd><a title=' + data[i].Children[j].Item.Name +' href="javascript:;" id="' + itemName + '" data-url="' + data[i].Children[j].Item.Url + '">';
}
if (data[i].Children[j].Item.IconName != undefined && data[i].Children[j].Item.IconName != '') {
if (data[i].Children[j].Item.IconName.indexOf("icon-") != -1) {
strItem += '<i class="iconfont ' + data[i].Children[j].Item.IconName + '" data-icon="' + data[i].Children[j].Item.IconName + '"></i>';
} else {
strItem += '<i class="layui-icon" data-icon="' + data[i].Children[j].Item.IconName + '">' + data[i].Children[j].Item.IconName + '</i>';
}
}
strItem += '<cite >' + data[i].Children[j].Item.Name + '</cite></a></dd>';
}
}
if (parValue == "" || strItem != "") {
strHtml += '<a title=' + data[i].Item.Name +' href="javascript:;" data-sortNo="' + data[i].Item.SortNo + '">';
if (data[i].Item.IconName != undefined && data[i].Item.IconName != '') {
if (data[i].Item.IconName.indexOf("icon-") != -1) {
strHtml += '<i class="iconfont ' + data[i].Item.IconName + '" data-icon="' + data[i].Item.IconName + '"></i>';
} else {
strHtml += '<i class="layui-icon" data-icon="' + data[i].Item.IconName + '">' + data[i].Item.IconName + '</i>';
}
}
strHtml += '<cite>' + data[i].Item.Name + '</cite>';
strHtml += '<span class="layui-nav-more"></span>';
strHtml += '</a>';
strHtml += '<dl class="layui-nav-child">';
strHtml += strItem;
strHtml += "</dl>";
}
} else {
if (parValue == "") {
if (data[i].target == "_blank") {
strHtml += '<a title=' + data[i].Item.Name +' href="javascript:;" id="' + data[i].Item.Code + '" data-url="' + data[i].Item.Url + '" target="' + data[i].target + '">';
} else {
strHtml += '<a title=' + data[i].Item.Name +' href="javascript:;" id="' + data[i].Item.Code + '" data-url="' + data[i].Item.Url + '">';
}
if (data[i].Item.IconName != undefined && data[i].Item.IconName != '') {
if (data[i].Item.IconName.indexOf("icon-") != -1) {
strHtml += '<i class="iconfont ' + data[i].Item.IconName + '" data-icon="' + data[i].Item.IconName + '"></i>';
} else {
strHtml += '<i class="layui-icon" data-icon="' + data[i].Item.IconName + '">' + data[i].Item.IconName + '</i>';
}
}
strHtml += '<cite>' + data[i].Item.Name + '</cite></a>';
}
}
//if (data[i].spread) {
if (parValue != "" && strHtml != "") {
ulHtml += '<li class="layui-nav-item layui-nav-itemed">';
ulHtml += strHtml;
} else {
ulHtml += '<li class="layui-nav-item">';
ulHtml += strHtml;
}
ulHtml += '</li>';
}
ulHtml += '</ul>';
return ulHtml;
}