暫無描述

login.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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(user_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. }else {
  68. layer.confirm(data.message, {
  69. btn: ['确定'] //按钮
  70. });
  71. }
  72. }
  73. });
  74. }
  75. })
  76. function loginHref() {
  77. var thisUrl = window.document.location.href
  78. var toHrefUrl = ""
  79. if(thisUrl.indexOf("127.0.0.1") > 0) {
  80. toHrefUrl = "index.html"
  81. } else {
  82. toHrefUrl = thisUrl.split('/')
  83. toHrefUrl.pop();
  84. toHrefUrl = toHrefUrl.join("/") + "/index.html"
  85. }
  86. if(huayi.config.callcenter_url.indexOf("https") !== -1) {
  87. $.getJSON(
  88. huayi.config.callcenter_url + "UserAccount/GetNowUser", {
  89. token: $.cookie("token"),
  90. },
  91. function(result) {
  92. if(result.state.toLowerCase() == "success") {
  93. toHrefUrl = "http://12345rx.zwfw.anyang.gov.cn:65525/index.html"
  94. window.location.href = toHrefUrl;
  95. }
  96. })
  97. } else {
  98. window.location.href = toHrefUrl;
  99. }
  100. }
  101. function sendMsg(mobile, pass) {
  102. var currenttime = CurentTime();
  103. console.log(mobile, pass, currenttime)
  104. $.ajax({
  105. type: "post",
  106. url: huayi.config.callcenter_url + "Login/SendCode",
  107. async: true,
  108. dataType: 'json',
  109. data: {
  110. usercode: mobile,
  111. Password: pass,
  112. LoginTime: currenttime
  113. },
  114. success: function(data) {
  115. if(data.state == "success") {
  116. layer.msg('发送成功')
  117. verifi();
  118. }else{
  119. layer.msg(data.message)
  120. }
  121. }
  122. });
  123. }
  124. function verifi() {
  125. var time = 60;
  126. var timer = null;
  127. $('.btnVerifi').text(time + '秒后重新发送');
  128. $('.btnVerifi').attr('disabled', 'disabled'); // 禁用按钮
  129. $('.btnVerifi_user').text(time + '秒后重新发送');
  130. $('.btnVerifi_user').attr('disabled', 'disabled'); // 禁用按钮
  131. timer = setInterval(function() {
  132. // 定时器到底了 兄弟们回家啦
  133. if(time == 1) {
  134. clearInterval(timer);
  135. $('.btnVerifi').text("获取验证码")
  136. $('.btnVerifi_user').text('获取验证码')
  137. $('.btnVerifi').removeAttr('disabled')
  138. $('.btnVerifi_user').removeAttr('disabled')
  139. } else {
  140. time--;
  141. $('.btnVerifi').text(time + '秒后重新发送');
  142. $('.btnVerifi_user').text(time + '秒后重新发送');
  143. }
  144. }, 1000)
  145. }
  146. function CurentTime() {
  147. var now = new Date();
  148. var year = now.getFullYear(); //年
  149. var month = now.getMonth() + 1; //月
  150. var day = now.getDate(); //日
  151. var hh = now.getHours(); //时
  152. var mm = now.getMinutes(); //分
  153. var ss = now.getSeconds(); //秒
  154. var clock = year + "-";
  155. if(month < 10)
  156. clock += "0";
  157. clock += month + "-";
  158. if(day < 10)
  159. clock += "0";
  160. clock += day + " ";
  161. if(hh < 10)
  162. clock += "0";
  163. clock += hh + ":";
  164. if(mm < 10) clock += '0';
  165. clock += mm + ":";
  166. if(ss < 10) clock += '0';
  167. clock += ss;
  168. return(clock);
  169. }