login.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var captchaCountTimer;
  2. var captchaCount=60;
  3. function getCaptchaCount(){
  4. $("#mobile_j_otp_captcha_button").val("重新获取("+captchaCount+")秒");
  5. captchaCount--;
  6. if(captchaCount==0){
  7. $("#mobile_j_otp_captcha_button").val("发送验证码");
  8. captchaCount=60;
  9. clearInterval(captchaCountTimer);
  10. }
  11. }
  12. var fullYear=currentDate.getFullYear();
  13. var month=currentDate.getMonth()+1;
  14. var date=currentDate.getDate();
  15. var hours=currentDate.getHours();
  16. var minutes=currentDate.getMinutes();
  17. var seconds=currentDate.getSeconds();
  18. var strTime="";
  19. function formatTime(){
  20. strTime=fullYear+"-";
  21. strTime+=(month<10?"0"+month:month)+"-";
  22. strTime+=(date<10?"0"+date:date)+" ";
  23. strTime+=(hours<10?"0"+hours:hours)+":";
  24. strTime+=(minutes<10?"0"+minutes:minutes)+":";
  25. strTime+=(seconds<10?"0"+seconds:seconds);
  26. }
  27. function currentTime(){
  28. seconds++;
  29. if(seconds>59){
  30. minutes++;
  31. seconds=0;
  32. }
  33. if(minutes>59){
  34. hours++;
  35. minutes=0;
  36. }
  37. if(hours>23){
  38. date++;
  39. hours=0;
  40. }
  41. formatTime();
  42. //for timebase token
  43. getTimeBaseCount();
  44. $("#currentTime").val(strTime);
  45. }
  46. var timeBaseCount;
  47. function getTimeBaseCount(){
  48. if(seconds<30){
  49. timeBaseCount=30-seconds;
  50. }else{
  51. timeBaseCount=30-(seconds-30);
  52. }
  53. $("#tfa_j_otp_captcha_button").val("剩余时间("+timeBaseCount+")秒");
  54. };
  55. var currentSwitchTab="normalLogin";
  56. function doLoginSubmit(){
  57. $.cookie("mxk_login_username", $("#"+currentSwitchTab+"Form input[name=username]").val(), { expires: 7 });
  58. $("#"+currentSwitchTab+"SubmitButton").click();
  59. $.cookie("mxk_login_switch_tab", currentSwitchTab, { expires: 7 });
  60. };
  61. function switchTab(id){
  62. if($("#"+id+"Form input[name=username]").val()==""){
  63. $("#"+id+"Form input[name=username]").focus();
  64. }else{
  65. $("#"+id+"Form input[name=password]").focus();
  66. }
  67. currentSwitchTab=id;
  68. }
  69. document.onkeydown=function(event){
  70. var e = event || window.event || arguments.callee.caller.arguments[0];
  71. if(e && e.keyCode==13){
  72. doLoginSubmit();
  73. };
  74. };
  75. $(function(){
  76. //setInterval("currentTime()", 1000);
  77. $(".doLoginSubmit").on("click",function(){
  78. doLoginSubmit();
  79. });
  80. var cookieLoginUsername = $.cookie("mxk_login_username");
  81. if(cookieLoginUsername != undefined && cookieLoginUsername != ""){
  82. var switch_tab=$.cookie("mxk_login_switch_tab")==undefined ? "normalLogin" : $.cookie("mxk_login_switch_tab");
  83. $("#"+switch_tab).click();
  84. $("#"+switch_tab+"Form input[name=username]").val(cookieLoginUsername ==undefined ? "" : cookieLoginUsername);
  85. $("#div_"+switch_tab+" input[name=password]").focus();
  86. }else{
  87. $("#div_normalLogin input[name=username]").focus();
  88. }
  89. $("#mobile_j_otp_captcha_button").on("click",function(){
  90. if(captchaCount<60){
  91. return;
  92. }
  93. var loginName = $("#mobile_j_username").val();
  94. if(loginName == ""){
  95. return;
  96. }
  97. $.get(webContextPath +"/login/sendsms/"+loginName,function(data,status){
  98. //alert("Data: " + data + "\nStatus: " + status);
  99. });
  100. captchaCountTimer=setInterval("getCaptchaCount()", 1000);
  101. });
  102. });