admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
$(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);
            } else {
                window.location.href = "login.html";
            }
        },
        error : function() {
            window.location.href = "login.html";
        }
    });
}
 
function setNav(username) {
 
    $(".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' style='color:#FF3083' href='#'>&nbsp;&nbsp;&nbsp;布&nbsp;心&nbsp;街&nbsp;后&nbsp;台&nbsp;管&nbsp;理&nbsp;系&nbsp;统&nbsp;&nbsp;&nbsp;</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 : 3000, // 设定超时
                cache : false, // 禁用缓存
                error : function(request, textStatus, errorThrown) {
                    // alert(textStatus+"加载XML文档出错!"+errorThrown);
                    // alert(request.status+":"+request.readyState);
                },
                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'><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);
 
                    // 设置选中
                    $("#menu-top li").removeClass("active");
                    $("#menu-top li").eq(firstIndex).addClass("active");
                    $("#sidebar div").eq(secondIndex).addClass("cebiandh1");
                    $("#sidebar div").eq(secondIndex).removeClass("cebiandh");
                    
                    $.ajax({
                        url : '../../client/html/api/v1/config/getSystemName',
                        type : 'GET',
                        dataType : 'json',
                        // timeout : 3000, // 设定超时
                        cache : false, // 禁用缓存
                        error : function(request, textStatus, errorThrown) {
                        },
                        success : function(data) {
                            $(".navbar-brand").eq(0).html(data.data);
                            $("title").html(data.data);
                        }
                    });
                } // 设置成功后回调函数
            });
 
    
 
}