Index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * 描 述:登录页面前端脚本
  3. */
  4. (function ($) {
  5. "use strict";
  6. var wmsPage = {
  7. init: function () {
  8. $('#psw_change').css({
  9. 'background': 'url(' + $.rootUrl + '/Content/images/Login/psw0.png) no-repeat center center'
  10. });
  11. var error = request('error');
  12. if (error == "ip") {
  13. wmsPage.tip("登录IP限制。");
  14. }
  15. else if (error == "time") {
  16. wmsPage.tip("登录时间限制。");
  17. }
  18. else if (error == "logintimeout") {
  19. wmsPage.tip("登录超时。");
  20. }
  21. if (window.location.href != top.window.location.href) {
  22. top.window.location.href = window.location.href;
  23. }
  24. var isIE = !!window.ActiveXObject;
  25. var isIE6 = isIE && !window.XMLHttpRequest;
  26. if (isIE6) {
  27. window.location.href = $.rootUrl + "/Error/ErrorBrowser";
  28. }
  29. wmsPage.bind();
  30. },
  31. bind: function () {
  32. // 回车键
  33. document.onkeydown = function (e) {
  34. e = e || window.event;
  35. if ((e.keyCode || e.which) == 13) {
  36. $('#wms_login_btn').trigger('click');
  37. }
  38. }
  39. //输入框获取焦点
  40. $('.wms-login-input input').on('focus', function () {
  41. var src = $(this).prev().attr('src');
  42. $(this).prev().attr('src', src.replace(/0.png$/, '1.png'));
  43. }).on('blur', function () {
  44. var src = $(this).prev().attr('src');
  45. $(this).prev().attr('src', src.replace(/1.png$/, '0.png'));
  46. });
  47. // 点击切换验证码
  48. $("#wms_verifycode_img").click(function () {
  49. $("#wms_verifycode_input").val('');
  50. $.ajax({
  51. type: 'post',
  52. dataType: 'json',
  53. url: $.rootUrl + "/Login/VerifyCode",
  54. headers: { __RequestVerificationToken: $.wmsToken },
  55. success: function (data) {
  56. //将图片的Base64编码设置给src
  57. $("#wms_verifycode_img").attr("src", "data:image/Gif;base64," + data);
  58. }
  59. });
  60. });
  61. var errornum = $('#errornum').val();
  62. if (errornum >= 3) {
  63. $('.wms-login-bypsw').removeClass('noreg');
  64. $("#wms_verifycode_img").trigger('click');
  65. }
  66. //点击密码icon 显示/隐藏
  67. $('#psw_change').click(function (event) {
  68. var event = event || window.event;
  69. event.stopPropagation();
  70. var $this = $(this);
  71. $this.toggleClass('psw_show');
  72. //如果当前隐藏 变显示
  73. if ($this.hasClass('psw_show')) {
  74. $this.css({
  75. 'background': 'url(' + $.rootUrl + '/Content/images/Login/psw1.png) no-repeat center center'
  76. });
  77. $this.prev().attr('type', 'text');
  78. } else {
  79. $this.css(
  80. 'background', 'url(/Content/images/Login/psw0.png) no-repeat center center'
  81. );
  82. $this.prev().attr('type', 'password');
  83. }
  84. });
  85. // 登录按钮事件
  86. $("#wms_login_btn").on('click', function () {
  87. wmsPage.login();
  88. });
  89. }, newGuid: function () {
  90. var guid = "";
  91. for (var i = 1; i <= 32; i++) {
  92. var n = Math.floor(Math.random() * 16.0).toString(16);
  93. guid += n;
  94. if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-";
  95. }
  96. return guid;
  97. },
  98. login : function () {
  99. wmsPage.tip();
  100. var $textu = $("#wms_username"), $textp = $("#wms_p"), $textv = $("#wms_verifycode_input");
  101. var textu = $.trim($textu.val()), textp = $.trim($textp.val()), textv = $.trim($textv.val());
  102. if (textu == "") {
  103. wmsPage.tip('请输入账户');
  104. $textu.focus();
  105. return false;
  106. }
  107. if (textp == "") {
  108. wmsPage.tip('请输入密码');
  109. $textp.focus();
  110. return false;
  111. }
  112. if ($("#wms_verifycode_input").is(":visible") && textv == "") {
  113. wmsPage.tip('请输入验证码');
  114. $textv.focus();
  115. return false;
  116. }
  117. wmsPage.logining(true);
  118. $.ajax({
  119. url: $.rootUrl + "/Login/LoginUserCheck",
  120. headers: { __RequestVerificationToken: $.wmsToken },
  121. data: { JsonData: JSON.stringify({ TextU: textu, TextP: textp, TextV: textv }) },
  122. type: "post",
  123. dataType: "json",
  124. success: function (res) {
  125. if (res.IsSucc) {
  126. // var key = wmsPage.newGuid();
  127. // sessionStorage.setItem(key, res.data.JWTToken);
  128. // window.location.href = $.rootUrl + '/Home/Index?k=' + key;
  129. //// window.location.href = $.rootUrl + '/Home/Index';
  130. if (sessionStorage) {
  131. var key = wmsPage.newGuid();
  132. sessionStorage.setItem(key, res.data.JWTToken);
  133. window.location.href = $.rootUrl + '/Home/Index?k=' + key;
  134. }
  135. else {
  136. window.location.href = $.rootUrl + '/Home/Index?s=' + res.data;
  137. }
  138. }
  139. else if (res.code == -3 || res.code == -4) {
  140. wmsPage.logining(false);
  141. wmsPage.tip(res.info, true);
  142. window.location.href = $.rootUrl + '/Login/EditPIndex?username=' + textu; // 修改密码页面
  143. }
  144. else if (res.code == -1) {
  145. console.error(res.info);
  146. wmsPage.logining(false);
  147. wmsPage.tip('服务端异常,请联系管理员', true);
  148. }
  149. else {
  150. wmsPage.logining(false);
  151. wmsPage.tip(res.info, true);
  152. $('#errornum').val(res.data);
  153. if (res.data >= 3) {
  154. $('#wms_verifycode_input').parent().show();
  155. $("#wms_verifycode_img").trigger('click');
  156. }
  157. }
  158. }
  159. });
  160. },
  161. logining: function (isShow) {
  162. if (isShow) {
  163. $('input').attr('disabled', 'disabled');
  164. $("#wms_login_btn").addClass('active').attr('disabled', 'disabled').find('span').hide();
  165. $("#wms_login_btn").css('background', '#eeecec url(/Content/images/Login/loading.gif) no-repeat center 10px');
  166. }
  167. else {
  168. $('input').removeAttr('disabled');
  169. $("#wms_login_btn").removeClass('active').removeAttr('disabled').find('span').show();
  170. $("#wms_login_btn").css('background', '#268fe2');
  171. }
  172. },
  173. tip: function (msg) {
  174. var $tip = $('.error_info');
  175. $tip.hide();
  176. if (!!msg) {
  177. $tip.find('span').html(msg);
  178. $tip.show();
  179. }
  180. }
  181. };
  182. $(function () {
  183. wmsPage.init();
  184. });
  185. })(window.jQuery)