login.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. $(document).ready(function() {
  2. //author:scott---date:20160426---for:判断浏览器跳转兼容风格
  3. var navigatorName = "Microsoft Internet Explorer";
  4. if( navigator.appName == navigatorName ){
  5. //--author:zhaohualong-----start----date: 2017年12月8日--------for:剔除IE下登录页面提示框------
  6. //alert("IE浏览器采用传统首页风格,更佳体验建议使用Chrome浏览器!")
  7. //--author:zhaohualong-----start----date: 2017年12月8日--------for:剔除IE下登录页面提示框------
  8. //update-begin--Author:gengjiajia Date:20160727 for:TASK #1217 【IE兼容】jeecg h+首页兼容性问题,不兼容的浏览器直接切换套shortcut风格
  9. //setCookie("JEECGINDEXSTYLE","shortcut");
  10. $.cookie('JEECGINDEXSTYLE', 'shortcut');
  11. //update-end--Author:gengjiajia Date:20160727 for:TASK #1217 【IE兼容】jeecg h+首页兼容性问题,不兼容的浏览器直接切换套shortcut风格
  12. }else{
  13. }
  14. //update--begin--author:zhangjiaqiang date:20170626 for:修订ie列表操作按钮的样式
  15. $.cookie("BROWSER_TYPE",navigator.appName);
  16. //update--end--author:zhangjiaqiang date:20170626 for:修订ie列表操作按钮的样式
  17. $("#userName").attr("nullmsg",pleaseinutusername);
  18. $("#userName").attr("title",username);
  19. $("#password").attr("nullmsg",pleaseinutpassword);
  20. $("#password").attr("title",password);
  21. $("#randCode").attr("nullmsg",pleaseinputvalidatecode);
  22. $("#randCode").attr("title",validatecode);
  23. getCookie();
  24. onfocus();
  25. $(".on_off_checkbox").iphoneStyle();
  26. $('.tip a ').tipsy({
  27. gravity : 'sw'
  28. });
  29. $('#login').show().animate({
  30. opacity : 1
  31. }, 2000);
  32. $('.logo').show().animate({
  33. opacity : 1,
  34. top : '32%'
  35. }, 800, function() {
  36. $('.logo').show().delay(1200).animate({
  37. opacity : 1,
  38. top : '1%'
  39. }, 300, function() {
  40. $('.formLogin').animate({
  41. opacity : 1,
  42. left : '0'
  43. }, 300);
  44. $('.userbox').animate({
  45. opacity : 0
  46. }, 200).hide();
  47. });
  48. });
  49. });
  50. $('.userload').click(function(e) {
  51. $('.formLogin').animate({
  52. opacity : 1,
  53. left : '0'
  54. }, 300);
  55. $('.userbox').animate({
  56. opacity : 0
  57. }, 200, function() {
  58. $('.userbox').hide();
  59. });
  60. });
  61. //update-begin--Author:zhangguoming Date:20140226 for:添加验证码
  62. $('#randCodeImage').click(function(){
  63. reloadRandCodeImage();
  64. });
  65. /**
  66. * 刷新验证码
  67. */
  68. function reloadRandCodeImage() {
  69. var date = new Date();
  70. var img = document.getElementById("randCodeImage");
  71. img.src='randCodeImage?a=' + date.getTime();
  72. }
  73. //update-end--Author:zhangguoming Date:20140226 for:添加验证码
  74. // 重置
  75. $('#forgetpass').click(function(e) {
  76. $(":input").each(function() {
  77. $('#'+this.name).val("");
  78. });
  79. });
  80. // 点击登录
  81. $('#but_login').click(function(e) {
  82. submit();
  83. });
  84. //update--begin--author:zhangjiaqiang date:20170523 for:修订登陆页面回车登陆处理两次
  85. ////回车登录
  86. //$(document).keydown(function(e){
  87. // if(e.keyCode == 13) {
  88. // submit();
  89. // }
  90. //});
  91. //update--end--author:zhangjiaqiang date:20170523 for:修订登陆页面回车登陆处理两次
  92. //表单提交
  93. function submit()
  94. {
  95. var submit = true;
  96. $("input[nullmsg]").each(function() {
  97. if ($("#" + this.name).val() == "") {
  98. showError($("#" + this.name).attr("nullmsg"), 500);
  99. jrumble();
  100. setTimeout('hideTop()', 1000);
  101. submit = false;
  102. return false;
  103. }
  104. });
  105. if (submit) {
  106. hideTop();
  107. try {
  108. loading(checking, 1);
  109. } catch (e) {
  110. // TODO: handle exception
  111. }
  112. setTimeout("unloading()", 1000);
  113. setTimeout("Login()", 1000);
  114. }
  115. }
  116. function zhanggm(orgId) {
  117. alert("zhanggm test in login.js: orgId= " +orgId);
  118. }
  119. //登录处理函数
  120. function Login(orgId) {
  121. setCookie();
  122. var actionurl=$('form').attr('action');//提交路径
  123. var checkurl=$('form').attr('check');//验证路径
  124. var formData = new Object();
  125. var data=$(":input").each(function() {
  126. formData[this.name] =$("#"+this.name ).val();
  127. });
  128. formData['orgId'] = orgId ? orgId : "";
  129. // update-begin--Author:ken Date:20140629 for:添加语言选择
  130. formData['langCode']=$("#langCode").val();
  131. // update-end--Author:ken Date:20140629 for:添加语言选择
  132. formData['langCode'] = $("#langCode option:selected").val();
  133. $.ajax({
  134. async : false,
  135. cache : false,
  136. type : 'POST',
  137. url : checkurl,// 请求的action路径
  138. data : formData,
  139. error : function() {// 请求失败处理函数
  140. },
  141. success : function(data) {
  142. var d = data; // ------ $.parseJSON(data);
  143. if (d.success) {
  144. loginsuccess();
  145. // update-start--Author:zhangguoming Date:20140825 for:用户有多个组织机构,则弹出选择组织架构页面
  146. // todo zhanggm 没有处理多语言,暂时这样判断下吧
  147. var title, okButton;
  148. if($("#langCode").val() == 'en') {
  149. title = "Please select Org";
  150. okButton = "Ok";
  151. } else {
  152. title = "请选择组织机构";
  153. okButton = "确定";
  154. }
  155. if (d.attributes.orgNum > 1) {
  156. $.dialog({
  157. id: 'LHG1976D',
  158. title: title,
  159. max: false,
  160. min: false,
  161. drag: false,
  162. resize: false,
  163. content: 'url:userController.do?userOrgSelect&userId=' + d.attributes.user.id,
  164. lock:true,
  165. button : [ {
  166. name : okButton,
  167. focus : true,
  168. callback : function() {
  169. iframe = this.iframe.contentWindow;
  170. var orgId = $('#orgId', iframe.document).val();
  171. Login(orgId);
  172. this.close();
  173. return false;
  174. }
  175. }],
  176. close: function(){
  177. window.location.href = actionurl;
  178. }
  179. });
  180. } else {
  181. setTimeout("window.location.href='"+actionurl+"'", 1000);
  182. }
  183. // update-end--Author:zhangguoming Date:20140825 for:用户有多个组织机构,则弹出选择组织架构页面
  184. } else {
  185. if(d.msg == "a"){
  186. $.dialog.confirm("数据库无数据,是否初始化数据?", function(){
  187. window.location = "init.jsp";
  188. }, function(){
  189. //
  190. });
  191. } else
  192. showError(d.msg);
  193. }
  194. }
  195. });
  196. }
  197. //设置cookie
  198. function setCookie()
  199. {
  200. if ($('#on_off').val() == '1') {
  201. $("input[iscookie='true']").each(function() {
  202. $.cookie(this.name, $("#"+this.name).val(), "/",24);
  203. $.cookie("COOKIE_NAME","true", "/",24);
  204. });
  205. } else {
  206. $("input[iscookie='true']").each(function() {
  207. $.cookie(this.name,null);
  208. $.cookie("COOKIE_NAME",null);
  209. });
  210. }
  211. }
  212. //读取cookie
  213. function getCookie()
  214. {
  215. var COOKIE_NAME=$.cookie("COOKIE_NAME");
  216. if (COOKIE_NAME !=null) {
  217. $("input[iscookie='true']").each(function() {
  218. $($("#"+this.name).val( $.cookie(this.name)));
  219. // update-begin--Author:zhangguoming Date:20140429 for:是否记住用户名优化
  220. if("admin" == $.cookie(this.name)) {
  221. $("#randCode").focus();
  222. } else {
  223. $("#password").val("");
  224. $("#password").focus();
  225. }
  226. // update-end--Author:zhangguoming Date:20140429 for:是否记住用户名优化
  227. });
  228. $("#on_off").attr("checked", true);
  229. $("#on_off").val("1");
  230. }
  231. else
  232. {
  233. $("#on_off").attr("checked", false);
  234. $("#on_off").val("0");
  235. // update-begin--Author:zhangguoming Date:20140429 for:是否记住用户名优化
  236. $("#randCode").focus();
  237. // update-end--Author:zhangguoming Date:20140429 for:是否记住用户名优化
  238. }
  239. }
  240. //点击消息关闭提示
  241. $('#alertMessage').click(function() {
  242. hideTop();
  243. });
  244. //显示错误提示
  245. function showError(str) {
  246. $('#alertMessage').addClass('error').html(str).stop(true, true).show().animate({
  247. opacity : 1,
  248. right : '0'
  249. }, 500);
  250. }
  251. //验证通过加载动画
  252. function loginsuccess()
  253. {
  254. $("#login").animate({
  255. opacity : 1,
  256. top : '49%'
  257. }, 200, function() {
  258. $('.userbox').show().animate({
  259. opacity : 1
  260. }, 500);
  261. $("#login").animate({
  262. opacity : 0,
  263. top : '60%'
  264. }, 500, function() {
  265. $(this).fadeOut(200, function() {
  266. $(".text_success").slideDown();
  267. $("#successLogin").animate({
  268. opacity : 1,
  269. height : "200px"
  270. }, 1000);
  271. });
  272. });
  273. });
  274. }
  275. function showSuccess(str) {
  276. $('#alertMessage').removeClass('error').html(str).stop(true, true).show().animate({
  277. opacity : 1,
  278. right : '0'
  279. }, 500);
  280. }
  281. function onfocus() {
  282. if ($(window).width() > 480) {
  283. $('.tip input').tipsy({
  284. trigger : 'focus',
  285. gravity : 'w',
  286. live : true
  287. });
  288. } else {
  289. $('.tip input').tipsy("hide");
  290. }
  291. }
  292. function hideTop() {
  293. $('#alertMessage').animate({
  294. opacity : 0,
  295. right : '-20'
  296. }, 500, function() {
  297. $(this).hide();
  298. });
  299. }
  300. //加载信息
  301. function loading(name, overlay) {
  302. $('body').append('<div id="overlay"></div><div id="preloader">' + name + '..</div>');
  303. if (overlay == 1) {
  304. $('#overlay').css('opacity', 0.1).fadeIn(function() {
  305. $('#preloader').fadeIn();
  306. });
  307. return false;
  308. }
  309. $('#preloader').fadeIn();
  310. }
  311. function unloading() {
  312. $('#preloader').fadeOut('fast', function() {
  313. $('#overlay').fadeOut();
  314. });
  315. //update--begin--author:zhangjiaqiang date:20170526 for:登陆loading信息多次显示
  316. $("#overlay").remove();
  317. $("#preloader").remove();
  318. //update--end--author:zhangjiaqiang date:20170526 for:登陆loading信息多次显示
  319. }
  320. // 表单晃动
  321. function jrumble() {
  322. $('.inner').jrumble({
  323. x : 4,
  324. y : 0,
  325. rotation : 0
  326. });
  327. $('.inner').trigger('startRumble');
  328. setTimeout('$(".inner").trigger("stopRumble")', 500);
  329. }
  330. function setCookie(name,value)
  331. {
  332. var Days = 30;
  333. var exp = new Date();
  334. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  335. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  336. }