Keine Beschreibung

login.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 user_psw = CryptoJS.enc.Utf8.parse($.md5(user_psw));
  24. var currenttime = CurentTime();
  25. var datatime = currenttime.split(' ')[1].split(':').join('')
  26. var key = CryptoJS.enc.Utf8.parse(")O[9d]6,YF}+efcaj{+8>Z'e9M" + datatime);
  27. var encrypted = CryptoJS.AES.encrypt(user_psw, key, {
  28. mode: CryptoJS.mode.ECB,
  29. padding: CryptoJS.pad.Pkcs7
  30. });
  31. var pass = encrypted.toString()
  32. sendMsg(mobile, pass);
  33. })
  34. //用户登录
  35. $('.login_gl').click(function() {
  36. localStorage.setItem('loginPassword', $('.gl_psw').val())
  37. var gl_user = DOMPurify.sanitize($(".gl_user").val());
  38. var gl_psw = DOMPurify.sanitize($(".gl_psw").val());
  39. if(gl_user == "" || gl_psw == "") {
  40. $(".error_gl").addClass('errorShow');
  41. if(gl_user == "") {
  42. $(".gl_user").focus(function() {
  43. $(".error_gl").removeClass('errorShow');
  44. });
  45. } else {
  46. $(".error_gl_user").removeClass('errorShow');
  47. }
  48. } else {
  49. var currenttime = CurentTime();
  50. var datatime = currenttime.split(' ')[1].split(':').join('')
  51. var key = CryptoJS.enc.Utf8.parse(")O[9d]6,YF}+efcaj{+8>Z'e9M" + datatime);
  52. var gl_psw = CryptoJS.enc.Utf8.parse($.md5(gl_psw));
  53. var encrypted = CryptoJS.AES.encrypt(gl_psw, key, {
  54. mode: CryptoJS.mode.ECB,
  55. padding: CryptoJS.pad.Pkcs7
  56. });
  57. /*请求后台*/
  58. $.ajax({
  59. type: "post",
  60. url: huayi.config.callcenter_url + "/Login/login",
  61. dataType: 'json',
  62. async: true,
  63. data: {
  64. username: gl_user,
  65. password: encrypted.toString(),
  66. LoginTime: currenttime,
  67. Code: $(".verification_user").val()
  68. },
  69. success: function(data) {
  70. /*验证请求*/
  71. if(data.state == "success") {
  72. $.cookie("token", data.data.token, {
  73. expires: 7
  74. });
  75. $.cookie("zx_user", gl_user, {
  76. expires: 7
  77. });
  78. loginHref()
  79. }else{
  80. layer.msg(data.message)
  81. }
  82. }
  83. });
  84. }
  85. })
  86. function loginHref() {
  87. var thisUrl = window.document.location.href
  88. var toHrefUrl = ""
  89. if(thisUrl.indexOf("127.0.0.1") > 0) {
  90. toHrefUrl = "index.html"
  91. } else {
  92. toHrefUrl = thisUrl.split('/')
  93. toHrefUrl.pop();
  94. toHrefUrl = toHrefUrl.join("/") + "/index.html"
  95. }
  96. if(huayi.config.callcenter_url.indexOf("https") !== -1) {
  97. $.getJSON(
  98. huayi.config.callcenter_url + "UserAccount/GetNowUser", {
  99. token: $.cookie("token"),
  100. },
  101. function(result) {
  102. if(result.state.toLowerCase() == "success") {
  103. toHrefUrl = "http://12345rx.zwfw.anyang.gov.cn:65525/index.html"
  104. window.location.href = toHrefUrl;
  105. }
  106. })
  107. } else {
  108. window.location.href = toHrefUrl;
  109. }
  110. }
  111. function sendMsg(mobile, pass) {
  112. var currenttime = CurentTime();
  113. console.log(mobile, pass, currenttime)
  114. $.ajax({
  115. type: "post",
  116. url: huayi.config.callcenter_url + "Login/SendCode",
  117. async: true,
  118. dataType: 'json',
  119. data: {
  120. usercode: mobile,
  121. Password: pass,
  122. LoginTime: currenttime
  123. },
  124. success: function(data) {
  125. if(data.state == "success") {
  126. layer.msg('发送成功')
  127. verifi();
  128. }else{
  129. layer.msg(data.message)
  130. }
  131. }
  132. });
  133. }
  134. function verifi() {
  135. var time = 60;
  136. var timer = null;
  137. $('.btnVerifi').text(time + '秒后重新发送');
  138. $('.btnVerifi').attr('disabled', 'disabled'); // 禁用按钮
  139. $('.btnVerifi_user').text(time + '秒后重新发送');
  140. $('.btnVerifi_user').attr('disabled', 'disabled'); // 禁用按钮
  141. timer = setInterval(function() {
  142. // 定时器到底了 兄弟们回家啦
  143. if(time == 1) {
  144. clearInterval(timer);
  145. $('.btnVerifi').text("获取验证码")
  146. $('.btnVerifi_user').text('获取验证码')
  147. $('.btnVerifi').removeAttr('disabled')
  148. $('.btnVerifi_user').removeAttr('disabled')
  149. } else {
  150. time--;
  151. $('.btnVerifi').text(time + '秒后重新发送');
  152. $('.btnVerifi_user').text(time + '秒后重新发送');
  153. }
  154. }, 1000)
  155. }
  156. function CurentTime() {
  157. var now = new Date();
  158. var year = now.getFullYear(); //年
  159. var month = now.getMonth() + 1; //月
  160. var day = now.getDate(); //日
  161. var hh = now.getHours(); //时
  162. var mm = now.getMinutes(); //分
  163. var ss = now.getSeconds(); //秒
  164. var clock = year + "-";
  165. if(month < 10)
  166. clock += "0";
  167. clock += month + "-";
  168. if(day < 10)
  169. clock += "0";
  170. clock += day + " ";
  171. if(hh < 10)
  172. clock += "0";
  173. clock += hh + ":";
  174. if(mm < 10) clock += '0';
  175. clock += mm + ":";
  176. if(ss < 10) clock += '0';
  177. clock += ss;
  178. return(clock);
  179. }