Няма описание

login.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. }
  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 = "index.html"
  77. } else {
  78. toHrefUrl = thisUrl.split('/')
  79. toHrefUrl.pop();
  80. toHrefUrl = toHrefUrl.join("/") + "/index.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. toHrefUrl = "http://192.168.24.64:8880/index.html"
  91. window.location.href = toHrefUrl;
  92. }
  93. })
  94. } else {
  95. window.location.href = toHrefUrl;
  96. }
  97. }
  98. function sendMsg(mobile, pass) {
  99. var currenttime = CurentTime();
  100. $.ajax({
  101. type: "post",
  102. url: huayi.config.callcenter_url + "Login/SendCode",
  103. async: true,
  104. dataType: 'json',
  105. data: {
  106. usercode: mobile,
  107. Password: pass,
  108. LoginTime: currenttime
  109. },
  110. success: function(data) {
  111. if(data.state == "success") {
  112. layer.msg('发送成功')
  113. verifi();
  114. }else{
  115. layer.msg(data.message)
  116. }
  117. }
  118. });
  119. }
  120. function verifi() {
  121. var time = 60;
  122. var timer = null;
  123. $('.btnVerifi').text(time + '秒后重新发送');
  124. $('.btnVerifi').attr('disabled', 'disabled'); // 禁用按钮
  125. $('.btnVerifi_user').text(time + '秒后重新发送');
  126. $('.btnVerifi_user').attr('disabled', 'disabled'); // 禁用按钮
  127. timer = setInterval(function() {
  128. // 定时器到底了 兄弟们回家啦
  129. if(time == 1) {
  130. clearInterval(timer);
  131. $('.btnVerifi').text("获取验证码")
  132. $('.btnVerifi_user').text('获取验证码')
  133. $('.btnVerifi').removeAttr('disabled')
  134. $('.btnVerifi_user').removeAttr('disabled')
  135. } else {
  136. time--;
  137. $('.btnVerifi').text(time + '秒后重新发送');
  138. $('.btnVerifi_user').text(time + '秒后重新发送');
  139. }
  140. }, 1000)
  141. }
  142. function CurentTime() {
  143. var now = new Date();
  144. var year = now.getFullYear(); //年
  145. var month = now.getMonth() + 1; //月
  146. var day = now.getDate(); //日
  147. var hh = now.getHours(); //时
  148. var mm = now.getMinutes(); //分
  149. var ss = now.getSeconds(); //秒
  150. var clock = year + "-";
  151. if(month < 10)
  152. clock += "0";
  153. clock += month + "-";
  154. if(day < 10)
  155. clock += "0";
  156. clock += day + " ";
  157. if(hh < 10)
  158. clock += "0";
  159. clock += hh + ":";
  160. if(mm < 10) clock += '0';
  161. clock += mm + ":";
  162. if(ss < 10) clock += '0';
  163. clock += ss;
  164. return(clock);
  165. }