/**
* 不带验证码的登录框
*/
Ext.onReady(function() {
// 使用表单提示
Ext.QuickTips.init();
// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = "side";
// 定义一个输入表单
var simple = new Ext.FormPanel({
baseCls : "x-plain",
defaultType : "textfield",
buttonAlign : 'center',
layout:'table',
layoutConfig: {columns:3},
items : [{
xtype : 'label',
html : '<span style="font-size:12px;line-height:30px;">帐 号:</span>',
width: 45,
colspan:1
},{
name : "user.loginName",
allowBlank : false,
blankText : "帐号不能为空",
width : 160,
colspan: 2
},{
xtype : 'label',
html : '<span style="font-size:12px;line-height:30px;">密 码:</span>',
width: 45,
colspan:1
}, {
inputType : "password",
name : "user.password",
allowBlank : false,
blankText : "密码不能为空",
width : 160,
colspan:2
},{
xtype : 'label',
html : '<span style="font-size:12px;line-height:30px;">验证码:</span>',
width: 45,
colspan:1
}, {
name : "user.loginName",
allowBlank : false,
blankText : "验证码不能为空",
width : 50,
colspan:1
}, {
xtype : 'panel',
html : '<a href="login.jsp"><img src="imgcode" alt="看不清?点击换一个"/></a>',
colspan:1,
width:60
}],
buttons : [{
width : 50,
text : "<span style='font-size:12px;'>登录</span>",
type : "submit",
handler : function() {
if (simple.form.isValid()) {
Ext.MessageBox.show({
title : "请稍等",
msg : "正在加载.....",
progressText : "",
width : 300,
progress : true,
closable : false,
animEl : "loding"
});
var f = function(v) {
return function() {
var i = v / 11;
Ext.MessageBox.updateProgress(i, '');
}
}
for (var i = 1; i < 13; i++) {
setTimeout(f(i), i * 150);
}
// 提交到服务器操作
simple.form.doAction("submit", {
url : "Login.action",
method : "post",
params : "",
success : function(form, action) {
document.location = 'index.jsp';
Ext.Msg.alert("登录成功!",
action.result.message);
},
failure : function(form, action) {
Ext.Msg
.alert('登陆失败',
action.result.message);
}
});
}
}
}, {
width : 50,
text : "<span style='font-size:12px;'>重置</span>",
handler : function() {
// 重置表单
simple.form.reset();
}
}]
});
// 定义窗体
var _window = new Ext.Window({
title : "<span style='font-size:14px;'>用户登录</span>",
layout : "fit",
width : 250,
height : 170,
plain : true,
bodyStyle : "padding:10px;padding-bottom:0px;",
maximizable : false,
resizable : false,
closeAction : "close",
closable : false,
collapsible : true,
plain : true,
buttonAlign : "center",
items : simple
});
_window.show()
});
package com.hisoft.ems.action;
import com.hisoft.ems.model.User;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private boolean success;
private String message;
private User user;
public String login() {
if ("admin".equals(user.getLoginName().trim())
&& "admin".equals(user.getPassword().trim())) {
this.success = true;
this.message = "您的帐号是"+user.getLoginName()+",密码是"+user.getPassword();
} else {
this.success = false;
this.message = "对不起,未授权用户不能使用本系统";
}
return SUCCESS;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="json-default">
<action name="Login" class="com.hisoft.ems.action.UserAction"
method="login">
<result type="json"></result>
</action>
<action name="List" class="com.hisoft.ems.action.ClientAction" method="list">
<result name="success">/clientManagerList.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
Morik.Office.CompanyPanel = function(config) {
Morik.Office.CompanyPanel.superclass.constructor.call(this, config);
// 加上服务器上的jsp数据生成
// 生成Company类型
var proxy = new Ext.data.HttpProxy( {
url : 'company.jsp'
});
var recordType = new Ext.data.Record.create([ {
name : "id",
type : "int"
}, {
name : "comNum",
type : "string"
}, {
name : "comName",
type : "string"
}, {
name : "comAddress",
type : "string"
}]);
// 定义分析器
var reader = new Ext.data.JsonReader( {
totalProperty : "results",
root : "rows",
id : "id"
}, recordType);
// 定义store
var ds = new Ext.data.Store( {
proxy : proxy,
reader : reader
});
this.ds=ds;
// 第二,讲一下cm,grid
var cm = new Ext.grid.ColumnModel( {
defaultSortable : true,
defaultWidth : 180,
columns : [ {
header : '编号',
dataIndex : 'comNum'
}, {
header : '名称',
dataIndex : 'comName'
}, {
header : '公司地址',
width : 300,
dataIndex : 'comAddress'
}]
});
var pagingBar = new Ext.PagingToolbar({
pageSize: 10,
store: ds,
displayInfo: true,
displayMsg: '共有 {2},当前显示 {0} - {1}条',
emptyMsg: "没有数据"
});
var grid = new Ext.grid.GridPanel( {
cm : cm,
store : ds,
width : 660,
height : 400,
bbar:pagingBar,
loadMask:{msg:'正在载入数据,请稍等...'},
title : '公司列表'
});
//ds.load();
this.add(grid);
// 第三、调整,tbar分页,工具栏
}
Ext.extend(Morik.Office.CompanyPanel, Ext.Panel, {});