index.js 15.1 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 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
var $, tab, sysDic = { data: null, method: null };

var timeout = null;
Date.prototype.format = function (format) {
    var o =
    {
        "M+": this.getMonth() + 1,                   //month
        "d+": this.getDate(),                        //day
        "h+": this.getHours(),                       //hour
        "m+": this.getMinutes(),                     //minute
        "s+": this.getSeconds(),                     //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds()                  //millisecond
    }
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

// 防抖
function debounce(fn, delay) {
    return function () {
        clearTimeout(timeout);
        timeout = setTimeout(() => {
            fn.apply(this, arguments);
        }, delay);
    };
}

function Cancellation() {
    layer.confirm('确认要注销吗?', {
        btn: ['确定', '取消']//按钮
    }, function (index) {
        window.sessionStorage.removeItem("menu");
        menu = [];
        window.sessionStorage.removeItem("curmenu");
        window.location = "/Login/Logout";
    }, function (index) {
        layer.close(index);
    });
}

layui.config({
    base: "/js/"
}).use(['bodytab', 'form', 'element', 'layer', 'jquery'], function () {
    var form = layui.form,
        layer = layui.layer,
        element = layui.element;
    $ = layui.jquery;
    //【openTabNum】最大可打开窗口数量
    tab = layui.bodytab({ openTabNum: "50", url: "/base/UserSession/GetModulesTree" });

    function getSysDic() {
        $.ajax({
            url: "/base/SysDictTypes/GetSysDictList",
            type: "post",
            dataType: "json",
            async: false,
            success: function (json) {
                if (json.Code === 200) {
                    sysDic.data = json.Result;
                } else {
                    layer.alert("获取字典数据错误", { icon: 2, shadeClose: true, title: "错误提示" });
                }
            }
        });
    }

    setTimeout(() => { getSysDic(); }, 2500);

    //其他页面获取  window.top.sysDic.method();
    sysDic.method = getSysDic;

    $("#Name").html(localStorage.getItem("Account"));
    $("#loginInfo").html("<i class= 'layui-icon'>&#xe66f;</i>&nbsp;" + localStorage.getItem("Name"));
    $("#loginTime").html("<i class= 'layui-icon'>&#xe60e;</i>&nbsp;" + new Date().format("yyyy-MM-dd"));

    //退出
    $(".signOut").click(function () {

    });

    //隐藏左侧导航
    $(".hideMenu").click(function () {
        $(".layui-layout-admin").toggleClass("showMenu");
        //渲染顶部窗口
        tab.tabMove();
    });

    //渲染左侧菜单
    tab.render();

    //抽屉
    $("i[lay-event=btnColseJson]").click(function () {
        $("#sys-drawer-conent").hide("fast");
    });

    $("i[lay-event=btnCopyJson]").click(function () {
        // 获取要复制的文本内容
        var textToCopy = document.getElementById("sys-json-val").value;

        // 创建一个临时文本框
        var tempInput = document.createElement("textarea");
        tempInput.value = textToCopy;
        document.body.appendChild(tempInput);

        // 选中文本并复制
        tempInput.select();
        document.execCommand("copy");

        // 删除临时文本框
        document.body.removeChild(tempInput);
        layer.msg("文本内容已复制好,可ctrl+v贴粘使用!", { icon: 1, shade: 0.4, time: 1500 });
    });

    //锁屏
    function lockPage() {
        layer.open({
            title: false,
            type: 1,
            content: '	<div class="admin-header-lock" id="lock-box">' +
                '<div class="admin-header-lock-img"><img src="/images/lock.png"/></div>' +
                '<div class="admin-header-lock-name" id="lockUserName">System</div>' +
                '<div class="input_btn">' +
                '<input type="password" class="admin-header-lock-input layui-input" autocomplete="off" placeholder="请输入密码解锁.." name="lockPwd" id="lockPwd" />' +
                '<button class="layui-btn" id="unlock">解锁</button>' +
                '</div>' +
                '</div>',
            closeBtn: 0,
            shade: 0.9
        }),
            $(".admin-header-lock-input").focus();
        if ($("#usernametop").html() != "") {
            $("#lockUserName").html($("#usernametop").html());
        }
    }
    $(".lockcms").on("click", function () {
        window.sessionStorage.setItem("lockcms", true);
        lockPage();
    });

    // 判断是否显示锁屏
    if (window.sessionStorage.getItem("lockcms") == "true") {
        lockPage();
    }
    // 解锁
    $("body").on("click", "#unlock", function () {
        if ($(this).siblings(".admin-header-lock-input").val() == '') {
            layer.alert("请输入解锁密码!", { icon: 2, shadeClose: true, title: "错误信息" });
            $(this).siblings(".admin-header-lock-input").focus();
        } else {

            $.post("/Login/Login"
                , {
                    username: $("#lockUserName").html(),
                    password: $(this).siblings(".admin-header-lock-input").val(),
                }
                , function (data) {
                    var dataJson = JSON.parse(data);
                    if (dataJson.Code == 200) {
                        window.sessionStorage.setItem("lockcms", false);
                        $(this).siblings(".admin-header-lock-input").val('');
                        layer.closeAll("page");
                    } else {
                        layer.alert("密码错误,请重新输入!", { icon: 2, shadeClose: true, title: "错误信息" });
                        $(this).siblings(".admin-header-lock-input").val('').focus();
                    }
                });
        }
    });

    // 添加新窗口
    $("body").on("click", ".layui-nav .layui-nav-item a", function () {
        var thisInfo = $(this),
            url = thisInfo.attr("data-url");
        //默认加上缓存的动态参数
        if (url != null && url.indexOf("sysWhere") == -1) {
            var urlWhere = Object.keys(localStorage)
                                 .filter(x => x.includes("sysWhere"))
                                 .map(x => `${x}=${localStorage.getItem(x)}`)
                                 .join("&");
            if (urlWhere!="") {
                url = url.includes("?") ? `${url}&${urlWhere}` : `${url}?${urlWhere}`;
            }
            thisInfo.attr("data-url", url);
            url = thisInfo.attr("data-url");
        }
        //如果不存在子级 _x
        if (thisInfo.siblings().length == 0 && url != undefined) {
            if (url && url.indexOf("fullScreen") > -1) {
                window.open(url, url);
            } else {
                tab.tabAdd($(this));
            }
            $('body').removeClass('site-mobile');  //移动端点击菜单关闭菜单层
        }
        thisInfo.parent("li").siblings().removeClass("layui-nav-itemed");
    });

    //刷新当前
    $(".refresh").on("click", function () {
        $(".clildFrame .layui-tab-item.layui-show").find("iframe")[0].contentWindow.location.reload(true);
    });

    //关闭其他
    $(".closePageOther").on("click", function () {
        if ($("#top_tabs li").length > 2 && $("#top_tabs li.layui-this cite").text() != "首页") {
            var menu = JSON.parse(window.sessionStorage.getItem("menu"));
            $("#top_tabs li").each(function () {
                if ($(this).attr("lay-id") != '' && !$(this).hasClass("layui-this")) {
                    element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
                    //此处将当前窗口重新获取放入session,避免一个个删除来回循环造成的不必要工作量
                    for (var i = 0; i < menu.length; i++) {
                        if ($("#top_tabs li.layui-this cite").text() == menu[i].title) {
                            menu.splice(0, menu.length, menu[i]);
                            window.sessionStorage.setItem("menu", JSON.stringify(menu));
                        }
                    }
                }
            })
        } else if ($("#top_tabs li.layui-this cite").text() == "首页" && $("#top_tabs li").length > 1) {
            $("#top_tabs li").each(function () {
                if ($(this).attr("lay-id") != '' && !$(this).hasClass("layui-this")) {
                    element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
                    window.sessionStorage.removeItem("menu");
                    menu = [];
                    window.sessionStorage.removeItem("curmenu");
                }
            })
        } else {
            layer.alert("没有可以关闭的窗口了@_@", { icon: 2, shadeClose: true, title: "错误信息" });
        }
        //渲染顶部窗口
        tab.tabMove();
    })

    //关闭全部
    $(".closePageAll").on("click", function () {
        if ($("#top_tabs li").length > 1) {
            $("#top_tabs li").each(function () {
                if ($(this).attr("lay-id") != '') {
                    element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
                    window.sessionStorage.removeItem("menu");
                    menu = [];
                    window.sessionStorage.removeItem("curmenu");
                }
            })
        } else {
            layer.alert("没有可以关闭的窗口了@_@", { icon: 2, shadeClose: true, title: "错误信息" });
        }
        //渲染顶部窗口
        tab.tabMove();
    });

    //修改密码
    $(".changepwd").on("click", function () {
        layer.open({
            title: "修改密码",
            shift: 2,
            type: 2,
            content: '/base/SysUser/ChangePassword',
            area: ['450px', '280px'], //宽高
            shade: 0.9
        });
    });

    $("#inputSearch").on('input', function (e) {
        var strings = e.delegateTarget.value;
        if (strings.replace(/(^s*)|(s*$)/g, "").length > 0) {
            tab.renderMenu({ value: strings });
        } else {
            tab.renderMenu({ value: "" });
        }
    });

    $("#inputSearch").keypress(function (e) {
        if (e.which == 13 && $("#inputSearch").val() != "") {
            tab.selectedMenu();
        }
    });

    $(document).bind("keydown", function (e) {
        //禁用页面F5刷新
        if (e.which == 116) {
            e.preventDefault(); //Skip default behavior of the enter key
        }
    });
});

var qp = {
    //全屏 类
    fullScreen: function () {
        var isFullScreen = false;
        var requestFullScreen = function () { //全屏
            var de = document.documentElement;
            if (de.requestFullscreen) {
                de.requestFullscreen();
            } else if (de.mozRequestFullScreen) {
                de.mozRequestFullScreen();
            } else if (de.webkitRequestFullScreen) {
                de.webkitRequestFullScreen();
            } else {
                alert("该浏览器不支持全屏");
            }
        };

        //退出全屏 判断浏览器种类
        var exitFull = function () {
            // 判断各种浏览器,找到正确的方法
            var exitMethod = document.exitFullscreen || //W3C
                document.mozCancelFullScreen || //Chrome等
                document.webkitExitFullscreen || //FireFox
                document.webkitExitFullscreen; //IE11
            if (exitMethod) {
                exitMethod.call(document);
            } else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
                var wscript = new ActiveXObject("WScript.Shell");
                wscript.SendKeys("{F11}");
            }
        };

        return {
            handleFullScreen: function ($this) {
                $this = $($this);
                if (isFullScreen) {
                    exitFull();
                    isFullScreen = false;
                    $this.find("i").removeClass("wb-contract");
                    $this.find("i").addClass("wb-expand");
                } else {
                    requestFullScreen();
                    isFullScreen = true;
                    $this.find("i").removeClass("wb-expand");
                    $this.find("i").addClass("wb-contract");
                }
            },
        };
    }()
}


//信息提示
let LogTipsIndex = 0;
var infoTips = {
    LogTips: function () {
        $.ajax({
            url: "/Home/LogTips",
            type: "get",
            dataType: "json",
            async: true,
            success: function (json) {
                if (json.Code != 200) return
                var isOnline = json.Result.clientOnlineInfo.length > 0;
                var isSqlServer = json.Result.sqlServerLog == null;
                if (!json.Result.interLog && !json.Result.jobLog && !json.Result.serverLog && !json.Result.pdaLog && !isOnline && isSqlServer) return;

                // 生成客户端在线信息
                var clientOnlineInfo = json.Result.clientOnlineInfo.map(x =>
                    `<span class="client-info" onclick="infoTips.updateLogTips('offline')">${x.clientName} - <span style="color:red;">离线</span></span><br>`
                ).join('');

                // 磁盘信息
                var driveInfo = "";
                if (!isSqlServer) {
                    driveInfo = json.Result.sqlServerLog.map(x =>
                        `<span class="client-info">${x.drive}盘可用: <span style="color:red;">${(x.freeSpaceMB / 1024).toFixed(1)}G</span></span><br>`
                    ).join('');
                }
                $("#inter-body").text(json.Result.interLog);
                $("#job-body").text(json.Result.jobLog);
                $("#pda-body").text(json.Result.pdaLog);
                $("#server-body").text(json.Result.serverLog);

                $("#client-body").html("").html(clientOnlineInfo);
                $("#sqlServer-body").html("").html(driveInfo);
                if (LogTipsIndex > 0) return;

                LogTipsIndex = layer.open({
                    title: "系统信息提示",
                    type: 1,
                    area: ['300px', '320px'],
                    offset: 'rb',
                    id: 'logStatisticsWindow',
                    content: $('.LogTips'),
                    shade: 0
                });
            }
        });
    },
    updateLogTips: function (falg) {
        if (falg == "job") {
            $("#SysJobLog").trigger("click");
        }
        else if (falg == "offline") {
            $("#daq_client_status").trigger("click");        }
        else {
            $("#SysInterfaceLog").trigger("click");
        }
        $.ajax({
            url: "/Home/UpdateLogTips?flag=" + falg,
            type: "get",
            success: function (val) {
                layer.close(LogTipsIndex);
                LogTipsIndex = 0;
            }
        });
    }
}


setTimeout(() => {
    infoTips.LogTips();
}, 5000)
//2分钟
setInterval(() => {
    infoTips.LogTips();
}, 120000);