Brak opisu

login.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. $(function() {
  2. /*cook存储数据*/
  3. if($.cookie("username")) {
  4. //取值如果存在则赋值
  5. $(".gl_user").val($.cookie("user")); //用户名
  6. $("zx_fj").val($.cookie("fj"));
  7. $(".zx_user").val($.cookie("user"));
  8. }
  9. })
  10. //键盘登录事件
  11. $('input').bind('keypress', function(event) {
  12. if(event.keyCode == "13") {
  13. $(".login_gl").trigger("click");
  14. }
  15. });
  16. $(".btnVerifi_user").click(function() {
  17. if(!$(".gl_user").val()) {
  18. layer.msg('请输入账号')
  19. return false;
  20. }
  21. var mobile = $(".gl_user").val();
  22. var user_psw = DOMPurify.sanitize($(".gl_psw").val());
  23. var encrypted = encryptFn($.md5(zx_psw))
  24. var pass = encrypted.toString()
  25. sendMsg(mobile, pass);
  26. })
  27. //用户登录
  28. $('.login_gl').click(function() {
  29. localStorage.setItem('loginPassword', $('.gl_psw').val())
  30. var gl_user = DOMPurify.sanitize($(".gl_user").val());
  31. var gl_psw = DOMPurify.sanitize($(".gl_psw").val());
  32. if(gl_user == "" || gl_psw == "") {
  33. $(".error_gl").addClass('errorShow');
  34. if(gl_user == "") {
  35. $(".gl_user").focus(function() {
  36. $(".error_gl").removeClass('errorShow');
  37. });
  38. } else {
  39. $(".error_gl_user").removeClass('errorShow');
  40. }
  41. } else {
  42. var currenttime = CurentTime();
  43. var datatime = currenttime.split(' ')[1].split(':').join('')
  44. var encrypted = encryptFn($.md5(gl_psw))
  45. /*请求后台*/
  46. $.ajax({
  47. type: "post",
  48. url: huayi.config.callcenter_url + "/Login/login",
  49. dataType: 'json',
  50. async: true,
  51. data: {
  52. username: gl_user,
  53. password: encrypted.toString(),
  54. LoginTime: currenttime,
  55. Code: $(".verification_user").val()
  56. },
  57. success: function(data) {
  58. /*验证请求*/
  59. if(data.state == "success") {
  60. $.cookie("token", data.data.token, {
  61. expires: 7
  62. });
  63. $.cookie("zx_user", gl_user, {
  64. expires: 7
  65. });
  66. loginHref()
  67. }
  68. }
  69. });
  70. }
  71. })
  72. function loginHref() {
  73. var thisUrl = window.document.location.href
  74. var toHrefUrl = ""
  75. if(thisUrl.indexOf("127.0.0.1") > 0) {
  76. toHrefUrl = "home.html"
  77. } else {
  78. toHrefUrl = thisUrl.split('/')
  79. toHrefUrl.pop();
  80. toHrefUrl = toHrefUrl.join("/") + "/home.html"
  81. }
  82. if(huayi.config.callcenter_url.indexOf("https") !== -1) {
  83. $.getJSON(
  84. huayi.config.callcenter_url + "UserAccount/GetNowUser", {
  85. token: $.cookie("token"),
  86. },
  87. function(result) {
  88. if(result.state.toLowerCase() == "success") {
  89. toHrefUrl = "http://12345rx.zwfw.anyang.gov.cn:65525/index.html"
  90. window.location.href = toHrefUrl;
  91. }
  92. })
  93. } else {
  94. window.location.href = toHrefUrl;
  95. }
  96. }
  97. function sendMsg(mobile, pass) {
  98. var currenttime = CurentTime();
  99. $.ajax({
  100. type: "post",
  101. url: huayi.config.callcenter_url + "Login/SendCode",
  102. async: true,
  103. dataType: 'json',
  104. data: {
  105. usercode: mobile,
  106. Password: pass,
  107. LoginTime: currenttime
  108. },
  109. success: function(data) {
  110. if(data.state == "success") {
  111. layer.msg('发送成功')
  112. verifi();
  113. }else{
  114. layer.msg(data.message)
  115. }
  116. }
  117. });
  118. }
  119. function verifi() {
  120. var time = 60;
  121. var timer = null;
  122. $('.btnVerifi').text(time + '秒后重新发送');
  123. $('.btnVerifi').attr('disabled', 'disabled'); // 禁用按钮
  124. $('.btnVerifi_user').text(time + '秒后重新发送');
  125. $('.btnVerifi_user').attr('disabled', 'disabled'); // 禁用按钮
  126. timer = setInterval(function() {
  127. // 定时器到底了 兄弟们回家啦
  128. if(time == 1) {
  129. clearInterval(timer);
  130. $('.btnVerifi').text("获取验证码")
  131. $('.btnVerifi_user').text('获取验证码')
  132. $('.btnVerifi').removeAttr('disabled')
  133. $('.btnVerifi_user').removeAttr('disabled')
  134. } else {
  135. time--;
  136. $('.btnVerifi').text(time + '秒后重新发送');
  137. $('.btnVerifi_user').text(time + '秒后重新发送');
  138. }
  139. }, 1000)
  140. }
  141. function CurentTime() {
  142. var now = new Date();
  143. var year = now.getFullYear(); //年
  144. var month = now.getMonth() + 1; //月
  145. var day = now.getDate(); //日
  146. var hh = now.getHours(); //时
  147. var mm = now.getMinutes(); //分
  148. var ss = now.getSeconds(); //秒
  149. var clock = year + "-";
  150. if(month < 10)
  151. clock += "0";
  152. clock += month + "-";
  153. if(day < 10)
  154. clock += "0";
  155. clock += day + " ";
  156. if(hh < 10)
  157. clock += "0";
  158. clock += hh + ":";
  159. if(mm < 10) clock += '0';
  160. clock += mm + ":";
  161. if(ss < 10) clock += '0';
  162. clock += ss;
  163. return(clock);
  164. }