/** * @author ZhangYi */ var LOGIN_WIN_STATE = 0;//多次调用且不关闭,会出现bug function getLoginWin(para) { if(LOGIN_WIN_STATE || document.getElementById("globalLoginWin")) {//已经打开了登录面板 return ; } LOGIN_WIN_STATE = 1; para = para || {}; //验证.. function valid(id) { var elem = $("#"+id); if(elem.val() == "") { elem.trigger("focus"); return ; } else { return true; } } //登录 function loginHandler() { if( formPanel.getForm().isValid() ) { var values = formPanel.getForm().getValues(); values['m'] = "login"; GameOIS.showLoading("正在验证,请稍候..."); GameOIS.ajax("/login.do", values, function(json) { if(json.code == "0") {//登录成功 LOGIN_WIN_STATE = 0; (para.callback || Ext.emptyFn)(json, win); } else { Ext.MessageBox.hide(); GameOIS.ajaxErr(json.msg); //刷新验证码 $("#verifyCodeImg").prev().val("").trigger("click"); } }); } else { valid("SLoginCode") && valid("SPasswd") && valid("randCode") } } var formPanel = new Ext.form.FormPanel({ baseCls : 'x-plain', style : "padding-top:100px;padding-bottom:30px; background:#fff url(/global/img/common/logo.jpg) no-repeat center 5px;", bodyStyle : 'color:#222;280px;margin:0 auto;', defaultType : 'textfield', labelSeparator : ":", labelWidth : 60, labelAlign : "right", frame: false, items : [{ id : "SLoginCode", name : "SLoginCode", width : 180, fieldLabel : "用户名", allowBlank : false, blankText : "用户名不能为空" }, { id : "SPasswd", name : "SPasswd", inputType : "password", width : 180, fieldLabel : "密 码", allowBlank : false, blankText : "密码不能为空" }, { id : "randCode", name : "randCode", width : 120, fieldLabel : "验证码", allowBlank : false, blankText : "请输入验证码", maxLength : 4, regex : /^\w{4}$/, regexText : "验证码输入不符合要求" }] }); var win = new Ext.Window({ width : 450, height : "auto", id : "globalLoginWin", title : para.title || "重新登录", buttons : [{ text : "登 录", width : 60, handler : loginHandler }], closable : para.closable || false, resizable : para.resizable || false, draggable : para.draggable || false, border : false, modal : para.modal || false, items : [formPanel] }); //加载登录框并隐藏 win.show(); //增加验证码 Ext.get(Ext.getDom("randCode").parentNode).createChild({ tag : "img", id : "verifyCodeImg", src : "/login.do?m=verifyCode&kk="+(+new Date()), style : "padding-left:3px;60px;height:22px;border:none;cursor:pointer;", title : "点击刷新验证码!", align : "absbottom" }); //刷新验证码 $("#verifyCodeImg").click(function() { this.src = this.src.replace(/\d+$/, +new Date()); $(this).prev().trigger("select"); return false; }); //响应回车 new Ext.KeyMap(win.getEl(), { key : Ext.EventObject.ENTER, fn : loginHandler, scope : win }); //居显示 win.doLayout(); win.center(); setTimeout(function() { $("#SLoginCode").trigger("focus"); }, 300); return win; }