var pagesPath = getContextPath();
var ctxPath = "http://192.168.0.14:42880/czldp";

function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0, index + 1);
    return result;
}

/**
 * 获取当日时间
 */
function getNowTime() {
    var nowDate = new Date();
    var year = nowDate.getFullYear();
    var month =
        nowDate.getMonth() + 1 < 10
            ? "0" + (nowDate.getMonth() + 1)
            : nowDate.getMonth() + 1;
    var day =
        nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
    var h = nowDate.getHours();
    h = h < 10 ? "0" + h : h;
    var m = nowDate.getMinutes();
    m = m < 10 ? "0" + m : m;
    var s = nowDate.getSeconds();
    s = s < 10 ? "0" + s : s;
    var dateStr = year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
    return dateStr;
}

// 全局监听ajax请求
$(document).ajaxComplete(function (event, xhr, settings) {
    if (xhr.status === 401) {
        // token过期返回401
        window.location.href = pagesPath + "/login.html"; // 跳转到登录页
    }
});
