login.js 5.6 KB

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