<!DOCTYPE html>
|
<html lang="en">
|
<head>
|
<meta charset="UTF-8">
|
<meta name="viewport" content="width=device-width, target-densitydpi=high-dpi, initial-scale=1.0, user-scalable=no"/>
|
<title>系统登录</title>
|
<script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
|
<style>
|
.login-form input {
|
display: block;
|
}
|
.login-form button {
|
display: block;
|
}
|
</style>
|
</head>
|
<body>
|
<h1>中扬物流</h1>
|
<div class="login-form">
|
<div>
|
<span>账号</span>
|
<input type="text" id="mobile" value="super">
|
</div>
|
<div>
|
<span>密码</span>
|
<input type="password" id="password" value="xltys1995">
|
</div>
|
<div>
|
<button onclick="login()">登录</button>
|
</div>
|
|
</div>
|
</body>
|
<script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
|
<script type="text/javascript" src="../../static/js/tools/md5.js"></script>
|
<script type="text/javascript">
|
document.onkeydown = function(e) {
|
//捕捉回车事件
|
var ev = (typeof event!= 'undefined') ? window.event : e;
|
if(ev.keyCode === 13 && document.activeElement.id === "key") {
|
login()
|
}
|
}
|
document.onkeyup = function (e) {
|
if (window.event)//如果window.event对象存在,就以此事件对象为准
|
e = window.event;
|
var code = e.charCode || e.keyCode;
|
if (code === 13) {
|
login()
|
}
|
}
|
function login(){
|
httpRequest({
|
httpUrl: baseUrl+"/login.action",
|
type: 'post',
|
data: {
|
mobile: document.getElementById('mobile').value,
|
password: hex_md5(document.getElementById('password').value)
|
}
|
}, function (res) {
|
if (res.code === 200) {
|
window.location.href = "index.html";
|
} else {
|
alert(res.msg);
|
}
|
|
})
|
}
|
|
function httpRequest(paramObj,fun,errFun) {
|
var xmlhttp = null;
|
/*创建XMLHttpRequest对象,
|
*老版本的 Internet Explorer(IE5 和 IE6)使用 ActiveX 对象:new ActiveXObject("Microsoft.XMLHTTP")
|
* */
|
if(window.XMLHttpRequest) {
|
xmlhttp = new XMLHttpRequest();
|
}else if(window.ActiveXObject) {
|
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
}
|
/*判断是否支持请求*/
|
if(xmlhttp == null) {
|
alert('你的浏览器不支持XMLHttp');
|
return;
|
}
|
/*请求方式,并且转换为大写*/
|
var httpType = (paramObj.type || 'GET').toUpperCase();
|
/*数据类型*/
|
var dataType = paramObj.dataType || 'json';
|
/*请求接口*/
|
var httpUrl = paramObj.httpUrl || '';
|
/*是否异步请求*/
|
var async = paramObj.async || true;
|
/*请求参数--post请求参数格式为:foo=bar&lorem=ipsum*/
|
var paramData = paramObj.data || [];
|
var requestData = '';
|
for(var name in paramData) {
|
requestData += name + '='+ paramData[name] + '&';
|
}
|
requestData = requestData === '' ? '' : requestData.substring(0,requestData.length - 1);
|
|
/*请求接收*/
|
xmlhttp.onreadystatechange = function() {
|
if(xmlhttp.readyState === 4 && xmlhttp.status === 200) {
|
/*成功回调函数*/
|
fun(JSON.parse(xmlhttp.responseText));
|
}else{
|
/*失败回调函数*/
|
errFun;
|
}
|
}
|
|
/*接口连接,先判断连接类型是post还是get*/
|
if(httpType === 'GET') {
|
xmlhttp.open("GET",httpUrl,async);
|
xmlhttp.send(null);
|
}else if(httpType === 'POST'){
|
xmlhttp.open("POST",httpUrl,async);
|
//发送合适的请求头信息
|
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
xmlhttp.send(requestData);
|
}
|
}
|
</script>
|
</html>
|