Commit cf5e77cc by 梁建民

js

parent 902f40de
;!function () {
window.loginController = {
'code': "#code",//验证码
'submit': "#submit",//提交按钮
init: function () {
this.handleBind(this);
},
......@@ -24,7 +26,7 @@
}
return false;
},
getData: function (params,callback) {
getData: function (params, callback) {
$.ajax({
url: _URL_ + '/api/ApiLogin',
type: 'post',
......@@ -33,13 +35,14 @@
dataType: 'json',
timeout: 10000,
success: function (res) {
typeof callback == 'function' && callback(res);
/* if (resp.code > 0) {
alert(resp.msg)
if (resp.code > 0) {
layer.msg(resp.msg);
} else {
setCookie('yunxin_token', resp.data)
window.location.href = "/web/orderList"
}*/
typeof callback == 'function' && callback(res);
}
},
error: function (res) {
layer.msg('网络出现问题,请重试!')
}
})
},
......@@ -64,73 +67,35 @@
return true;
},
handleBind: function (opt) {
//验证码
$(opt.code).on('click', function () {
$(this).find('img').attr('src', '/helper/captcha?' + new Date().getTime())
});
//提交
$("#submit").on('click', function () {
$(opt.submit).on('click', function () {
if (opt.calcForm(opt)) {
opt.getData(function (res) {
console.log(res)
});
opt.getData(function (res) {
setCookie('yunxin_token', resp.data)
window.location.href = "/web/orderList"
});
}
});
$("input[name='username']").on('blur', function () {
opt.calcForm(opt);
});
$("input[name='pwd']").on('blur', function () {
opt.calcForm(opt);
});
$("input[name='code']").on('blur', function () {
opt.calcForm(opt);
});
return this;
},
}, $(function () {
loginController.init();
})
}();
/**
* Created by hcy on 2019/2/19.
*/
var _URL_ = "http://yunxin.liexin.com";
function login() {
$.ajax({
url: _URL_ + '/api/ApiLogin',
type: 'post',
data: {
'mobile': $("#mobile").val(),
'password': $.md5($("#password").val()),
'code': $("#code").val()
},
async: false,
dataType: 'json',
timeout: 10000,
success: function (resp) {
if (resp.code > 0) {
alert(resp.msg)
} else {
setCookie('yunxin_token', resp.data)
window.location.href = "/web/orderList"
}
}
})
}
function setCookie(name, value) {
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 30);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
}();
\ No newline at end of file
......@@ -50,7 +50,7 @@
<div class="code-inp fl">
<input type="text" placeholder="请输入验证码" name="code">
</div>
<div class="code-img fr">
<div class="code-img fr" id="code">
<img src="/helper/captcha" alt="">
<a href="javascript:;">换一张</a>
</div>
......@@ -175,7 +175,8 @@
</div>
<!--footer end-->
<script type="text/javascript" src="/pc/js/jquery.min.js"></script>
<script type="text/javascript" src="/pc/js/layui/layui.js"></script>
<script type="text/javascript" src="/pc/js/global.js"></script>
<script type="text/javascript" src="/pc/js/layui/layui.all.js"></script>
<script type="text/javascript" src="/pc/js/md5/jquery.md5.js"></script>
<script type="text/javascript" src="/pc/js/controller/Login.js"></script>
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment