extjs 图片上传带有预览功能


     xtype: 'textfield', //注意此处为textfield, inputType: 'image'
     fieldLabel: '照片',
     inputType: 'image',
     width: 130,
     height: 125,
     id: 'emp_photo',
     autoCreate : {
      tag:'image',
     //tag : "input",
    //    type : "image",
     src : "img/default.gif",
     name: 'emp.empPhoto'
     //autocomplete:  "off"
     }
    },{
     style: 'margin-left: 110px;',
     xtype: 'button',
     width: 50,
     text: '上传照片',
     handler: upload
    },

UploadWin = Ext.extend(Ext.Window,{
 id: 'upLoad',
 uploadPanel: null,
 constructor: function(){
  this.uploadPanel =  new Ext.form.FormPanel({
   fileUpload: true,//允许上传
   baseCls: 'x-plain',//作用在面板元素上的CSS样式类 (默认为 'x-panel')
   layout: 'form',
   labelWidth: 60,
   id: 'uploadformPanel',
   items: [{
    xtype: 'fileuploadfield',//引入插件
    //inputType: 'file',
    fieldLabel: '上传照片',
    //allowBlank: false,
    id: 'photo',
    name: 'upload',
    buttonText: '选择'
   }]
   
 });
  //调用父类构造方法
  UploadWin.superclass.constructor.call(this,{
   title: '上传照片',
   modal: true,
   width: 300,
   height: 130,
   plain: true,
   bodyStyle: 'padding: 15px;',
   items:[this.uploadPanel],
   buttonAlign: 'center',
   buttons:[{
    text: '确定',
    handler: function(){
     Ext.getCmp('uploadformPanel').getForm().submit({
      url: 'emp_upload.action',
      method: 'post',
      waitTitle: '提示',
      waitMsg: '正在上传,请稍后...',
      success: uploadSuccess,
      failure: uploadFailure,
      scope: this
     });
    }
   },{
    text: '取消',
    handler: function(){
     Ext.getCmp('uploadformPanel').getForm().reset();
     Ext.get('emp_photo').dom.src = 'img/default.gif';
     uploadWin.destroy();
    }
   }]
  })
 }
});
 uploadSuccess = function(form,action){
  //console.log('success');
  Ext.getCmp('uploadformPanel').getForm().reset();
  uploadWin.destroy();
  Ext.Msg.alert('提示',action.result.msg,function(){
   Ext.getCmp('emp_photo').getEl().dom.src = action.result.path;
  });
 };
 uploadFailure = function(form,action){
  //console.log('failure');
  Ext.Msg.alert('提示', '连接失败');
 };

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值