login.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. $(function() {
  2. // cookie取用户名
  3. var username = $.cookie('s_username');
  4. if(username) {
  5. $('#s_username').val(username);
  6. $('#s_password').focus();
  7. } else
  8. $('#s_username').focus();
  9. // 帐套切换
  10. var master = $.cookie('s_master');
  11. var menu = $('#master_list'), items = $('li>a', menu), masterWrap = $('#master'), b = false;
  12. $.each(items, function(){
  13. if($(this).data('name') == master) {
  14. b = true;
  15. masterWrap.text($(this).text());
  16. }
  17. });
  18. if(!b) {
  19. master = items.first().data('name');
  20. masterWrap.text(items.first().text());
  21. }
  22. window.master = master;
  23. if(items.length > 1) {
  24. $('#master_list_toggle').on('click', function(){
  25. menu.css('display', 'block');
  26. });
  27. items.on('click', function(){
  28. menu.css('display', 'none');
  29. masterWrap.text($(this).text());
  30. window.master = $(this).data('name');
  31. });
  32. }
  33. });
  34. /**
  35. * 登录方法
  36. */
  37. function login() {
  38. var t_user = $('#s_username'), v_user = t_user.val(), t_pwd = $('#s_password'), v_pwd = t_pwd.val();
  39. if (!v_user) {
  40. warn('账号不能为空!');
  41. t_user.focus();
  42. } else if (!v_pwd) {
  43. warn('请填写密码!');
  44. t_pwd.focus();
  45. } else {
  46. setLoading(true);
  47. $.ajax({
  48. type : 'POST',
  49. contentType : 'application/json',
  50. url : 'common/login.action?username=' + v_user + '&password=' + v_pwd + '&sob=' + window.master,
  51. success : function(data) {
  52. setLoading(false);
  53. if(data.exceptionInfo){
  54. warn(data.exceptionInfo);
  55. }else{
  56. $.cookie('s_username', v_user);
  57. window.location.reload();
  58. }
  59. },
  60. error : function(s) {
  61. setLoading(false);
  62. warn($.parseJSON(s.responseText).exceptionInfo);
  63. t_user.focus();
  64. }
  65. });
  66. }
  67. }
  68. /**
  69. * 消息框
  70. */
  71. function warn(msg) {
  72. toastr.clear();
  73. toastr.warning(msg, "警告", {positionClass: 'toast-top-center'});
  74. }
  75. function setLoading(bool) {
  76. if(bool)
  77. $('#loading').addClass('in');
  78. else
  79. $('#loading').removeClass('in');
  80. }
  81. function keyDown(b) {
  82. var a = (navigator.appName == "Netscape") ? b.which : b.keyCode;
  83. if (a == 13) {
  84. login()
  85. }
  86. };