login.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. function isChrome(){
  2. return /\bchrome\b/.test(navigator.userAgent.toLowerCase());
  3. }
  4. $(function() {
  5. if(!isChrome()){
  6. $('#toolBox').css('display', 'block');
  7. $('#toolBox .close').click(function(){
  8. $('#toolBox').css('display', 'none');
  9. });
  10. }
  11. $("#loading").hide();
  12. $("#waitMsg").hide();
  13. $("#username").focus();
  14. $("#username").val(username_cookie);
  15. $("#password").val(password_cookie);
  16. if(master_cookie != null && master_cookie != '') {
  17. $("#master").val(master_cookie);
  18. }
  19. if(rmbUser != null && rmbUser == 0) {
  20. $("#RmbUser").attr("checked", false);
  21. };
  22. /* //获取最新的Android客户端下载地址
  23. $.ajax({
  24. url: basePath + 'common/cross.action',
  25. type: 'GET',
  26. data: {
  27. path: 'http://218.17.158.219:8001/artifactory/libs-release-local/com/uas/android/pm/maven-metadata.xml'
  28. },
  29. dataType: 'xml',
  30. success: function(data) {
  31. if (data) {
  32. // latest version
  33. var version = $(data).find("metadata").find("versioning").find("latest").text();
  34. $('#qrcode').attr('src', basePath + 'mobile/qr/encode.action?code=http://www.usoftchina.com/usoft/uas_client.html?android='+version);
  35. }
  36. }
  37. });*/
  38. $("#validcode").bind("keyup", function() {
  39. if ($("#validcode").val().length == 4) {
  40. setTimeout(function() {
  41. if ($("#validcode").val().length == 4 && _postflag == 0) {
  42. _postflag = 1;
  43. $.post(basePath + "common/validCode.action", {
  44. code : $("#validcode").val()
  45. }, function(a) {
  46. _postflag = 0;
  47. if (!a.success) {
  48. $.showtip("验证码错误!", 3000);
  49. refreshImg();
  50. $("#validcode").val("");
  51. $("#validcode").focus()
  52. }
  53. })
  54. }
  55. }, 300)
  56. } else {
  57. if ($("#validcode").val().length > 4) {
  58. $("#validcode").val($("#validcode").val().substring(0, 4))
  59. }
  60. }
  61. })
  62. });
  63. function getUrlParam(name){
  64. var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  65. var r=window.location.search.substr(1).match(reg);
  66. if (r!=null) return decodeURI(r[2]);
  67. return null;
  68. }
  69. var username_cookie = getCookie("username");
  70. if (username_cookie == null || username_cookie == "null") {
  71. username_cookie = ""
  72. }
  73. var password_cookie = getCookie("password");
  74. if (password_cookie == null || password_cookie == "null") {
  75. password_cookie = ""
  76. }
  77. var master_cookie = getCookie("master");
  78. var _postflag = 0;
  79. var _count = 0;
  80. var rmbUser = getCookie('_rmb');
  81. function login() {
  82. if ($("#validcode").val() == "") {
  83. $.showtip("请输入验证码!", 3000);
  84. refreshImg();
  85. $("#validcode").focus();
  86. return
  87. } else {
  88. $.post(basePath + "common/validCode.action", {
  89. code : $("#validcode").val()
  90. }, function(a) {
  91. if (a.success) {
  92. if ($("#username").val() == "") {
  93. $.showtip("请输入用户名!", 3000);
  94. refreshImg();
  95. $("#username").focus();
  96. return
  97. } else {
  98. if ($("#password").val() == "") {
  99. $.showtip("请输入密码!", 3000);
  100. refreshImg();
  101. $("#password").focus();
  102. return
  103. } else {
  104. $("#loading").show();
  105. $("#waitMsg").show();
  106. var b = {};
  107. b.username = $("#username").val();
  108. b.password = $("#password").val();
  109. b.language = $(":radio:checked").val();
  110. _postflag = 1;
  111. $.ajax({
  112. type : "POST",
  113. contentType : "application/json",
  114. url : basePath + "common/login.action?username="
  115. + b.username + "&password=" + b.password
  116. + "&language=" + b.language + "&sob="
  117. + $("#master")[0].value,
  118. success : function(c) {
  119. $("#loading").hide();
  120. $("#waitMsg").hide();
  121. _postflag = 0;
  122. if (c.success) {
  123. SetCookie("master", $("#master")[0].value);
  124. SetCookie("username", b.username);
  125. if ($("#RmbUser").attr("checked")) {
  126. delCookie('_rmb');
  127. SetCookie("password", b.password)
  128. } else {
  129. SetCookie("_rmb", '0');
  130. SetCookie("password", "")
  131. }
  132. SetCookie("language", b.language);
  133. var path = basePath, mobile = getUrlParam("mobile");
  134. if(mobile != null) {
  135. path += "?mobile=0";
  136. }
  137. document.location.href = path;
  138. } else {
  139. if (c.reason) {
  140. $.showtip(c.reason, 6000);
  141. _count += 1;
  142. if(_count > 5) {
  143. $.showtip("错误5次以上,您的页面将会在3秒后关闭!", 6000);
  144. setTimeout(function(){
  145. window.opener = null;
  146. window.open('', '_self');
  147. window.close();
  148. }, 3000);
  149. }
  150. } else {
  151. $.showtip(c.exceptionInfo, 6000)
  152. }
  153. }
  154. }
  155. })
  156. }
  157. }
  158. } else {
  159. if (a.ex) {
  160. $.showtip(a.ex, 8000)
  161. } else {
  162. $.showtip("验证码错误!", 3000);
  163. refreshImg();
  164. $("#validcode").focus()
  165. }
  166. }
  167. })
  168. }
  169. }
  170. function SetCookie(c, a) {
  171. var d = 30;
  172. var b = new Date();
  173. b.setTime(b.getTime() + d * 24 * 60 * 60 * 1000);
  174. document.cookie = c + "=" + escape(a) + ";expires=" + b.toGMTString()
  175. }
  176. function getCookie(b) {
  177. var a = document.cookie.match(new RegExp("(^| )" + b + "=([^;]*)(;|$)"));
  178. if (a != null) {
  179. return unescape(a[2])
  180. }
  181. return null
  182. }
  183. function delCookie(b) {
  184. var a = new Date();
  185. a.setTime(a.getTime() - 1);
  186. var c = getCookie(b);
  187. if (c != null) {
  188. document.cookie = b + "=" + c + ";expires=" + a.toGMTString()
  189. }
  190. }
  191. function keyDown(b) {
  192. var a = (navigator.appName == "Netscape") ? b.which : b.keyCode;
  193. if (a == 13) {
  194. login()
  195. }
  196. };