$(function () {
|
setLogin();
|
});
|
|
function setLogin() {
|
$.ajax({
|
url: "api/login/getLoginName",
|
async: true,
|
dataType: "json",
|
success: function (data) {
|
if (data.code == 0) {
|
var username = data.info.name;
|
setNav(username, data.systems);
|
} else {
|
window.location.href = "login.html";
|
}
|
},
|
error: function () {
|
window.location.href = "login.html";
|
}
|
});
|
}
|
|
function setNav(username, systems) {
|
|
var selectApp;
|
for (var i = 0; i < systems.length; i++) {
|
if (systems[i].selected) {
|
selectApp = systems[i];
|
}
|
}
|
|
var appNameStr = "";
|
for (var i = 0; i < selectApp.name.length; i++) {
|
appNameStr += selectApp.name.substr(i, 1) + " ";
|
}
|
|
$(".navbar").eq(0).empty();
|
var html = "";
|
html += "<div class='container-fluid'>";
|
html += " <div class='navbar-header'>";
|
html += " <button type='button' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#bs-example-navbar-collapse-1'> <span class='sr-only'>Toggle navigation</span> <span class='icon-bar'></span> <span class='icon-bar'></span> <span class='icon-bar'></span> </button>";
|
html += " <a class='navbar-brand' href='#'> " + appNameStr + "后 台 管 理 系 统 </a> </div>";
|
html += " <div class='collapse navbar-collapse' id='bs-example-navbar-collapse-1'> ";
|
html += " <ul class='nav navbar-nav navbar-left' id='menu-top'>";
|
|
$.ajax({
|
url: './js/navsetting.xml',
|
type: 'GET',
|
dataType: 'xml',
|
timeout: 1000, // 设定超时
|
cache: true, // 禁用缓存
|
error: function (xml) {
|
alert("加载XML文档出错!");
|
},
|
success: function (data) {
|
var firstIndex = -1;
|
var secondIndex = -1;
|
$(data).find("topNav").each(
|
function (index, ele) {
|
html += " <li><a href='" + $(ele).attr("url") + "'>"
|
+ $(ele).attr("name") + "</a></li>";
|
|
|
$(ele).find("secondNav").each(function (index1, ele1) {
|
var choosed = 0;
|
var secondUrl = $(ele1).attr("url");
|
$(ele1).find("url").each(function (index2, ele2) {
|
if (document.location.href.indexOf($(ele2).text()) > 0)
|
choosed = 1;
|
});
|
if (document.location.href.indexOf(secondUrl) > 0)
|
choosed = 1;
|
|
if (choosed == 1 && secondIndex == -1) {
|
firstIndex = index;
|
secondIndex = index1;
|
console.log("找到:" + $(ele).attr("name") + "-" + secondIndex);
|
}
|
});
|
if (secondIndex > -1 && firstIndex == index) {
|
console.log(index + "-" + secondIndex);
|
var htmlChild = "<dl>";
|
$(ele).find("secondNav").each(function (index1, ele1) {
|
htmlChild += "<dd><a href=" + $(ele1).attr("url") + ">";
|
htmlChild += "<div class='cebiandh'>" + $(ele1).attr("name")
|
+ "</div>";
|
htmlChild += "</a></dd>";
|
|
});
|
htmlChild += "</dl>";
|
$("#sidebar").empty();
|
$("#sidebar").html(htmlChild);
|
}
|
|
});
|
|
html += " </ul>";
|
html += " <ul class='nav navbar-nav navbar-right'>";
|
html += " <li class='hover'><select class='form-control' id='systemChange' style='margin-top: 8px;'>";
|
for (var i = 0; i < systems.length; i++) {
|
if (systems[i].selected) {
|
selectApp = systems[i];
|
html += "<option value='" + selectApp.id + "' selected>" + selectApp.name + "</option>";
|
} else {
|
html += "<option value='" + systems[i].id + "'>" + systems[i].name + "</option>";
|
}
|
}
|
html += "</select></a></li>";
|
html += " <li class='hover'><a href='#'>" + (username) + "</a></li>";
|
html += " <li><a href='api/login/loginExit'>退出登录</a></li>";
|
html += " </ul>";
|
html += " </div>";
|
|
html += " </div>";
|
$(".navbar").eq(0).html(html);
|
|
$("#systemChange").bind("change", function (e) {
|
var system = $(this).val();
|
$.ajax({
|
url: "api/login/selectSystem",
|
async: true,
|
data: {
|
system: system
|
},
|
dataType: "json",
|
success: function (data) {
|
if (data.code == 0) {
|
window.location.reload();
|
} else {
|
alert(data.error);
|
}
|
},
|
error: function () {
|
window.location.href = "login.html";
|
}
|
});
|
});
|
|
|
//设置选中
|
$("#menu-top li").removeClass("active");
|
$("#menu-top li").eq(firstIndex).addClass("active");
|
$("#sidebar div").eq(secondIndex).addClass("cebiandh1");
|
$("#sidebar div").eq(secondIndex).removeClass("cebiandh");
|
|
} // 设置成功后回调函数
|
});
|
}
|