$(function() { // cookie取用户名 var username = $.cookie('s_username'); if(username) { $('#s_username').val(username); $('#s_password').focus(); } else $('#s_username').focus(); // 帐套切换 var master = $.cookie('s_master'); var menu = $('#master_list'), items = $('li>a', menu), masterWrap = $('#master'), b = false; $.each(items, function(){ if($(this).data('name') == master) { b = true; masterWrap.text($(this).text()); } }); if(!b) { master = items.first().data('name'); masterWrap.text(items.first().text()); } window.master = master; if(items.length > 1) { $('#master_list_toggle').on('click', function(){ menu.css('display', 'block'); }); items.on('click', function(){ menu.css('display', 'none'); masterWrap.text($(this).text()); window.master = $(this).data('name'); }); } }); /** * 登录方法 */ function login() { var t_user = $('#s_username'), v_user = t_user.val(), t_pwd = $('#s_password'), v_pwd = t_pwd.val(); if (!v_user) { warn('账号不能为空!'); t_user.focus(); } else if (!v_pwd) { warn('请填写密码!'); t_pwd.focus(); } else { setLoading(true); $.ajax({ type : 'POST', contentType : 'application/json', url : 'common/login.action?username=' + v_user + '&password=' + v_pwd + '&sob=' + window.master, success : function(data) { setLoading(false); if(data.exceptionInfo){ warn(data.exceptionInfo); }else{ $.cookie('s_username', v_user); window.location.reload(); } }, error : function(s) { setLoading(false); warn($.parseJSON(s.responseText).exceptionInfo); t_user.focus(); } }); } } /** * 消息框 */ function warn(msg) { toastr.clear(); toastr.warning(msg, "警告", {positionClass: 'toast-top-center'}); } function setLoading(bool) { if(bool) $('#loading').addClass('in'); else $('#loading').removeClass('in'); } function keyDown(b) { var a = (navigator.appName == "Netscape") ? b.which : b.keyCode; if (a == 13) { login() } };