Ext.create('Ext.form.Panel', {
title: '文件上传',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: 'file',
fieldLabel: '选择文件',
labelWidth: 100,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: '浏览...'
}],
buttons: [{
text: '上传',
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: '你的服务器接口URL', // 替换为你的文件上传接口URL
waitMsg: '正在上传文件...',
success: function(form, action) {
Ext.Msg.alert('成功', '文件上传成功!');
// 可以在这里处理服务器返回的响应,例如刷新页面或显示上传的文件信息
},
failure: function(form, action) {
if (action.failureType === Ext.form.action.Action.CLIENT_INVALID) {
Ext.Msg.alert('错误', '表单验证失败,请检查输入!');
} else {
Ext.Msg.alert('错误', '文件上传失败!');
}
}
});
}
}
}]
});