login.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. function resetImage() {
  2. var obj = document.getElementById("code_img");
  3. document.getElementById("code_img").src = "Handler/GetCaptchaImage.ashx?" + Math.random() * 100;
  4. console.log("resetImage");
  5. }
  6. function clearMsg() {
  7. var obj = document.getElementById("lblMsg");
  8. if (obj != undefined && obj != null) {
  9. obj.innerHTML = "";
  10. }
  11. }
  12. setTimeout("clearMsg()", 10000);
  13. $(function () {
  14. $(document).keydown(function (event) {
  15. if (event.keyCode == 13) {
  16. $("#btn").click();
  17. }
  18. });
  19. $('.loginbox').css({ 'position': 'absolute', 'left': ($(window).width() - 692) / 2 });
  20. $(window).resize(function () {
  21. $('.loginbox').css({ 'position': 'absolute', 'left': ($(window).width() - 692) / 2 });
  22. });
  23. var ct = $("#hCT").val();
  24. if (ct != "" && parseInt(ct) >= 3) {
  25. $("#sp_code").show();
  26. resetImage();
  27. }
  28. });
  29. function loginFn() {
  30. var user = $("#txtUser").val();
  31. var pwd = $("#txtPwd").val();
  32. if (user == "") {
  33. showMsg("请输入账号!");
  34. $("#txtUser").focus();
  35. return;
  36. }
  37. if (pwd == "") {
  38. showMsg("请输入密码!");
  39. $("#txtPwd").focus();
  40. return;
  41. }
  42. var code = $("#txtCode").val();
  43. var ct = $("#hCT").val();
  44. if (ct != "" && parseInt(ct) >= 3 && code == "") {
  45. showMsg("请输入验证码");
  46. $("#txtCode").focus();
  47. return;
  48. }
  49. $("#btn").attr("disabled", "disabled");
  50. postAjax("Handler/login.ashx?", "erp_user_login", "user=" + user + "&pwd=" + pwd + "&code=" + code, function (data) {
  51. showMsg("<span style=\"color:#0000FF\">登录成功</span>");
  52. window.location.href = 'index.aspx';
  53. }, function (data) {
  54. $("#btn").removeAttr("disabled");
  55. if (data.indexOf("验证码") != -1) {
  56. $("#txtCode").val("");
  57. $("#txtCode").focus();
  58. showMsg(data);
  59. resetImage();
  60. }
  61. else if (data.indexOf("|") != -1) {
  62. var dArr = data.split('|');
  63. showMsg(dArr[1]);
  64. var c = dArr[0];
  65. $("#hCT").val(c);
  66. if (parseInt(c) >= 3) {
  67. $("#sp_code").show();
  68. $("#txtCode").val("");
  69. resetImage();
  70. }
  71. } else {
  72. showMsg(data);
  73. }
  74. });
  75. }
  76. function postAjax(urlStr, type, queryString, sFn, eFn, hps) {
  77. if (hps != false) progressShow();
  78. $.ajax({
  79. url: urlStr + "t=" + type,
  80. type: "POST",
  81. data: queryString,
  82. datatype: "json",
  83. success: function (result) {
  84. if (result == "") {
  85. alert("操作发生错误!");
  86. progressHide();
  87. return;
  88. }
  89. var data = $.parseJSON(result);
  90. if (data.type == "success") {
  91. progressHide();
  92. sFn(data.result);
  93. } else {
  94. progressHide();
  95. if (eFn != undefined) eFn(data.result);
  96. else alert(data.result);
  97. }
  98. },
  99. error: function (data) {
  100. progressHide();
  101. alert("操作发生错误!");
  102. }
  103. });
  104. }
  105. function progressHide() {
  106. $(".login_msg").empty();
  107. }
  108. function progressShow() {
  109. $(".login_msg").html("登录中...");
  110. }
  111. function showMsg(msg) {
  112. $(".login_msg").html(msg);
  113. }