login.js
4.31 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
// 文本对象,里面的字段名为文本对应的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);
}