login.js 4.31 KB
// 文本对象,里面的字段名为文本对应的key值
var messages = {
    text_info: "",
    user_text_empty: "",
    password_text_empty: "",
    login_error: ""
};
// 加载语言,解析页面,并执行回调
loadLanguage(function() {
    // 加载EasyUI组件
    loadEasyuiModules("messager");
    $(document).ready(function() {
        //增加回车登陆事件
        $(document).keypress(function(event) {
            if (event.keyCode == "13") {
                //如果对话框已经打开,关掉对话框
                var isDialogOpened = isLoginDialogShowed();
                //如果对话框已打开,关闭
                if (isDialogOpened && dialogWin) {
                    dialogWin.window("window", "close");
                    if (focus == 0) {
                        $("#LoginCode").focus(); //.focus();
                    } else if (focus == 1) {
                        $("#LoginPwd").focus();
                    }
                } else {
                    $("#btnLogin").click();
                }
            }
        });
        $("#btnLogin").click(login);
        $("#LoginCode").focus();
    });
}, messages);

var dialogWin = undefined;
var focus = 0;

function txtInputFocus(event) {
    var target = $(this);
    if (target.val() == $(this).attr("data-hint")) {
        $(this).val("");
    }
}

function txtInputBlur(event) {
    var target = $(this);
    if (target.val() == "") {
        $(this).val($(this).attr("data-hint"));
    }
}

//登录事件
function login() {
    var params = {
        usr: $("#LoginCode").val(),
        pwd: $("#LoginPwd").val()
    };

    if (params.usr == "" || params.usr == $("#LoginCode").attr("data-hint")) {
        focus = 0;
        dialogWin = $.messager.alert(
            messages.text_info,
            messages.user_text_empty,
            "info"
        );
        return false;
    }
    if (params.pwd == "" || params.pwd == $("#LoginPwd").attr("data-hint")) {
        focus = 1;
        dialogWin = $.messager.alert(
            messages.text_info,
            messages.password_text_empty,
            "info"
        );
        return false;
    }

    $.ajax({
        type: "get",
        url: "/do/trafficController/userLogin",
        data: params,
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        dataType: "json",
        success: function(msg) {
            if (msg.error) {
                // 获取语言
                var lang = $.i18n.normaliseLanguageCode();
                var indexUrl = "index.esp";
                if (lang) {
                    indexUrl += "?lang=" + lang;
                }
                window.location.replace(indexUrl);
            } else {
                if (msg.key == "3") {
                    // 密码错误
                    focus = 1;
                } else if (msg.key == "2") {
                    focus = 0;
                }
                dialogWin = $.messager.alert(
                    messages.text_info,
                    msg.feedback.Msg,
                    "error"
                );
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            dialogWin = $.messager.alert(
                messages.text_info,
                messages.login_error
            );
        }
    });
}

function isLoginDialogShowed() {
    var dialogObj = $(".messager-window");
    if (dialogObj.length > 0) {
        return true;
    }
    return false;
}

//显示下载插件对话框
function showDownloadDialog() {
    var content =
        '<ul><li><a href="../OcxInstall/NvrClientInstall.exe" style="color:black;"><img src="../OcxInstall/down.ico" width=16 height=16 style="display: inline; margin-right:5px" />NVR视频录像插件</a></li><li><a href="../OcxInstall/VionDownloaderInstall.exe" style="color:black;"><img src="../OcxInstall/down.ico" width=16 height=16 style="display: inline; margin-right:5px" />图片文件下载插件</a></li><li><a href="../OcxInstall/VionVideo.exe" style="color:black;"><img src="../OcxInstall/down.ico" width=16 height=16 style="display: inline; margin-right:5px" />视频播放插件</a></li></ul>';
    var options = {
        showType: "slide",
        showSpeed: 600,
        width: 210,
        height: 110,
        title: "下载控件",
        msg: content,
        timeout: 0
    };
    $.messager.show(options);
}