Commit cf5e77cc by 梁建民

js

parent 902f40de
;!function () { ;!function () {
window.loginController = { window.loginController = {
'code': "#code",//验证码
'submit': "#submit",//提交按钮
init: function () { init: function () {
this.handleBind(this); this.handleBind(this);
}, },
...@@ -24,7 +26,7 @@ ...@@ -24,7 +26,7 @@
} }
return false; return false;
}, },
getData: function (params,callback) { getData: function (params, callback) {
$.ajax({ $.ajax({
url: _URL_ + '/api/ApiLogin', url: _URL_ + '/api/ApiLogin',
type: 'post', type: 'post',
...@@ -33,13 +35,14 @@ ...@@ -33,13 +35,14 @@
dataType: 'json', dataType: 'json',
timeout: 10000, timeout: 10000,
success: function (res) { success: function (res) {
typeof callback == 'function' && callback(res); if (resp.code > 0) {
/* if (resp.code > 0) { layer.msg(resp.msg);
alert(resp.msg)
} else { } else {
setCookie('yunxin_token', resp.data) typeof callback == 'function' && callback(res);
window.location.href = "/web/orderList" }
}*/ },
error: function (res) {
layer.msg('网络出现问题,请重试!')
} }
}) })
}, },
...@@ -64,73 +67,35 @@ ...@@ -64,73 +67,35 @@
return true; return true;
}, },
handleBind: function (opt) { 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)) { if (opt.calcForm(opt)) {
opt.getData(function (res) { opt.getData(function (res) {
console.log(res) setCookie('yunxin_token', resp.data)
}); window.location.href = "/web/orderList"
});
} }
}); });
$("input[name='username']").on('blur', function () { $("input[name='username']").on('blur', function () {
opt.calcForm(opt); opt.calcForm(opt);
}); });
$("input[name='pwd']").on('blur', function () { $("input[name='pwd']").on('blur', function () {
opt.calcForm(opt); opt.calcForm(opt);
}); });
$("input[name='code']").on('blur', function () { $("input[name='code']").on('blur', function () {
opt.calcForm(opt); opt.calcForm(opt);
}); });
return this; return this;
}, },
}, $(function () { }, $(function () {
loginController.init(); loginController.init();
}) })
}(); }();
\ No newline at end of file
/**
* 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;
}
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<div class="code-inp fl"> <div class="code-inp fl">
<input type="text" placeholder="请输入验证码" name="code"> <input type="text" placeholder="请输入验证码" name="code">
</div> </div>
<div class="code-img fr"> <div class="code-img fr" id="code">
<img src="/helper/captcha" alt=""> <img src="/helper/captcha" alt="">
<a href="javascript:;">换一张</a> <a href="javascript:;">换一张</a>
</div> </div>
...@@ -175,7 +175,8 @@ ...@@ -175,7 +175,8 @@
</div> </div>
<!--footer end--> <!--footer end-->
<script type="text/javascript" src="/pc/js/jquery.min.js"></script> <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/md5/jquery.md5.js"></script>
<script type="text/javascript" src="/pc/js/controller/Login.js"></script> <script type="text/javascript" src="/pc/js/controller/Login.js"></script>
</body> </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