login.js 2.9 KB

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