| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /*
- * 描 述:登录页面前端脚本
- */
- (function ($) {
- "use strict";
- var wmsPage = {
- init: function () {
- $('#psw_change').css({
- 'background': 'url(' + $.rootUrl + '/Content/images/Login/psw0.png) no-repeat center center'
- });
- var error = request('error');
- if (error == "ip") {
- wmsPage.tip("登录IP限制。");
- }
- else if (error == "time") {
- wmsPage.tip("登录时间限制。");
- }
- else if (error == "logintimeout") {
- wmsPage.tip("登录超时。");
- }
- if (window.location.href != top.window.location.href) {
- top.window.location.href = window.location.href;
- }
- var isIE = !!window.ActiveXObject;
- var isIE6 = isIE && !window.XMLHttpRequest;
- if (isIE6) {
- window.location.href = $.rootUrl + "/Error/ErrorBrowser";
- }
- wmsPage.bind();
- },
- bind: function () {
- // 回车键
- document.onkeydown = function (e) {
- e = e || window.event;
- if ((e.keyCode || e.which) == 13) {
- $('#wms_login_btn').trigger('click');
- }
- }
- //输入框获取焦点
- $('.wms-login-input input').on('focus', function () {
- var src = $(this).prev().attr('src');
- $(this).prev().attr('src', src.replace(/0.png$/, '1.png'));
- }).on('blur', function () {
- var src = $(this).prev().attr('src');
- $(this).prev().attr('src', src.replace(/1.png$/, '0.png'));
- });
- // 点击切换验证码
- $("#wms_verifycode_img").click(function () {
- $("#wms_verifycode_input").val('');
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: $.rootUrl + "/Login/VerifyCode",
- headers: { __RequestVerificationToken: $.wmsToken },
- success: function (data) {
- //将图片的Base64编码设置给src
- $("#wms_verifycode_img").attr("src", "data:image/Gif;base64," + data);
- }
- });
- });
- var errornum = $('#errornum').val();
- if (errornum >= 3) {
- $('.wms-login-bypsw').removeClass('noreg');
- $("#wms_verifycode_img").trigger('click');
- }
- //点击密码icon 显示/隐藏
- $('#psw_change').click(function (event) {
- var event = event || window.event;
- event.stopPropagation();
- var $this = $(this);
- $this.toggleClass('psw_show');
- //如果当前隐藏 变显示
- if ($this.hasClass('psw_show')) {
- $this.css({
- 'background': 'url(' + $.rootUrl + '/Content/images/Login/psw1.png) no-repeat center center'
- });
- $this.prev().attr('type', 'text');
- } else {
- $this.css(
- 'background', 'url(/Content/images/Login/psw0.png) no-repeat center center'
- );
- $this.prev().attr('type', 'password');
- }
- });
- // 登录按钮事件
- $("#wms_login_btn").on('click', function () {
- wmsPage.login();
- });
- }, newGuid: function () {
- var guid = "";
- for (var i = 1; i <= 32; i++) {
- var n = Math.floor(Math.random() * 16.0).toString(16);
- guid += n;
- if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-";
- }
- return guid;
- },
- login : function () {
- wmsPage.tip();
- var $textu = $("#wms_username"), $textp = $("#wms_p"), $textv = $("#wms_verifycode_input");
- var textu = $.trim($textu.val()), textp = $.trim($textp.val()), textv = $.trim($textv.val());
- if (textu == "") {
- wmsPage.tip('请输入账户');
- $textu.focus();
- return false;
- }
- if (textp == "") {
- wmsPage.tip('请输入密码');
- $textp.focus();
- return false;
- }
- if ($("#wms_verifycode_input").is(":visible") && textv == "") {
- wmsPage.tip('请输入验证码');
- $textv.focus();
- return false;
- }
- wmsPage.logining(true);
- $.ajax({
- url: $.rootUrl + "/Login/LoginUserCheck",
- headers: { __RequestVerificationToken: $.wmsToken },
- data: { JsonData: JSON.stringify({ TextU: textu, TextP: textp, TextV: textv }) },
- type: "post",
- dataType: "json",
- success: function (res) {
- if (res.IsSucc) {
- // var key = wmsPage.newGuid();
- // sessionStorage.setItem(key, res.data.JWTToken);
- // window.location.href = $.rootUrl + '/Home/Index?k=' + key;
- //// window.location.href = $.rootUrl + '/Home/Index';
-
- if (sessionStorage) {
- var key = wmsPage.newGuid();
- sessionStorage.setItem(key, res.data.JWTToken);
- window.location.href = $.rootUrl + '/Home/Index?k=' + key;
- }
- else {
- window.location.href = $.rootUrl + '/Home/Index?s=' + res.data;
- }
- }
- else if (res.code == -3 || res.code == -4) {
- wmsPage.logining(false);
- wmsPage.tip(res.info, true);
- window.location.href = $.rootUrl + '/Login/EditPIndex?username=' + textu; // 修改密码页面
- }
- else if (res.code == -1) {
- console.error(res.info);
- wmsPage.logining(false);
- wmsPage.tip('服务端异常,请联系管理员', true);
- }
- else {
- wmsPage.logining(false);
- wmsPage.tip(res.info, true);
- $('#errornum').val(res.data);
- if (res.data >= 3) {
- $('#wms_verifycode_input').parent().show();
- $("#wms_verifycode_img").trigger('click');
- }
- }
- }
- });
- },
- logining: function (isShow) {
- if (isShow) {
- $('input').attr('disabled', 'disabled');
- $("#wms_login_btn").addClass('active').attr('disabled', 'disabled').find('span').hide();
- $("#wms_login_btn").css('background', '#eeecec url(/Content/images/Login/loading.gif) no-repeat center 10px');
- }
- else {
- $('input').removeAttr('disabled');
- $("#wms_login_btn").removeClass('active').removeAttr('disabled').find('span').show();
- $("#wms_login_btn").css('background', '#268fe2');
- }
- },
- tip: function (msg) {
- var $tip = $('.error_info');
- $tip.hide();
- if (!!msg) {
- $tip.find('span').html(msg);
- $tip.show();
- }
- }
- };
- $(function () {
- wmsPage.init();
- });
- })(window.jQuery)
|