login.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. $(function() {
  2. validateKickout();
  3. validateRule();
  4. $('.imgcode').click(function() {
  5. var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
  6. $(".imgcode").attr("src", url);
  7. });
  8. });
  9. $.validator.setDefaults({
  10. submitHandler: function() {
  11. login();
  12. }
  13. });
  14. function login() {
  15. $.modal.loading($("#btnSubmit").data("loading"));
  16. var username = $.common.trim($("input[name='username']").val());
  17. var password = $.common.trim($("input[name='password']").val());
  18. var validateCode = $("input[name='validateCode']").val();
  19. var rememberMe = $("input[name='rememberme']").is(':checked');
  20. $.ajax({
  21. type: "post",
  22. url: ctx + "login",
  23. data: {
  24. "username": username,
  25. "password": password,
  26. "validateCode": validateCode,
  27. "rememberMe": rememberMe
  28. },
  29. success: function(r) {
  30. if (r.code == web_status.SUCCESS) {
  31. location.href = ctx + 'index';
  32. } else {
  33. $.modal.closeLoading();
  34. $('.imgcode').click();
  35. $(".code").val("");
  36. $.modal.msg(r.msg);
  37. }
  38. }
  39. });
  40. }
  41. function validateRule() {
  42. var icon = "<i class='fa fa-times-circle'></i> ";
  43. $("#signupForm").validate({
  44. rules: {
  45. username: {
  46. required: true
  47. },
  48. password: {
  49. required: true
  50. }
  51. },
  52. messages: {
  53. username: {
  54. required: icon + "请输入您的用户名",
  55. },
  56. password: {
  57. required: icon + "请输入您的密码",
  58. }
  59. }
  60. })
  61. }
  62. function validateKickout() {
  63. if (getParam("kickout") == 1) {
  64. layer.alert("<font color='red'>您已在别处登录,请您修改密码或重新登录</font>", {
  65. icon: 0,
  66. title: "系统提示"
  67. },
  68. function(index) {
  69. //关闭弹窗
  70. layer.close(index);
  71. if (top != self) {
  72. top.location = self.location;
  73. } else {
  74. var url  =  location.search;
  75. if (url) {
  76. var oldUrl  = window.location.href;
  77. var newUrl  = oldUrl.substring(0,  oldUrl.indexOf('?'));
  78. self.location  = newUrl;
  79. }
  80. }
  81. });
  82. }
  83. }
  84. function getParam(paramName) {
  85. var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
  86. var r = window.location.search.substr(1).match(reg);
  87. if (r != null) return decodeURI(r[2]);
  88. return null;
  89. }