123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /**
- * 登录相关js
- *
- * @author CaiAoLin
- * @date 2017/6/8
- * @version
- */
- $(document).ready(function () {
- let referer = scUrlUtil.GetQueryString('referer');
- $("#login").click(function () {
- if (!valid()) {
- return false;
- }
- let account = $("#inputEmail").val();
- let pw = $("#inputPassword").val();
- $.ajax({
- url: '/login',
- type: 'post',
- data: {"account": account, "pw": pw},
- success: function (response) {
- if (response.error === 0) {
- if (response.login_ask === 0) {
- location.href = '/pm';
- } else {
- $('#ver').modal('show');
- }
- // if (referer) {
- // location.href = referer;
- // } else {
- // location.href = '/';
- // }
- } else {
- let msg = response.msg !== undefined ? response.msg : '未知错误';
- showError(msg, $("input"));
- }
- },
- error: function (result) {
- showError('内部程序错误', null);
- }
- });
- });
- $("input").blur(function () {
- cleanError();
- });
- $(".form-control").on('input', function () {
- $('#hint').html(' ');
- });
- });
- /**
- * 验证数据
- *
- * @return {boolean}
- */
- function valid() {
- let result = true;
- let account = $("#inputEmail").val();
- if (account === undefined || account === '') {
- showError('用户名不能为空!', $("#inputEmail"));
- return false;
- }
- let password = $("#inputPassword").val();
- if (password === undefined || password === '') {
- showError('密码不能为空!', $("#inputPassword"));
- return false;
- }
- return result;
- }
- /**
- * 提示错误
- *
- * @param {string} msg
- * @param {object} element
- * @return {void}
- */
- function showError(msg, element) {
- if (element !== null) {
- element.parent().addClass('has-danger');
- }
- $("#message").text(msg);
- $("#error-tips").show("fast");
- }
- /**
- * 清除错误提示
- *
- * @return {void}
- */
- function cleanError() {
- $("input").parent().removeClass('has-danger');
- $("#message").text('');
- $("#error-tips").hide("fast");
- }
|