加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ext Swfupload 进度条 多文上传

发布时间:2020-12-15 06:16:19 所属栏目:百科 来源:网络整理
导读:由于工作需要,自己使用extjs+swfupload写的一个多文件上传插件。 废话不说了,直接贴代码。 Ext.ux.UploadWindow = Ext.extend(Ext.Window,{ width:700,height:400,tree:null,grid:null,layout:'border',store:null,progressBar:null,animateTarget:'ux-tas
由于工作需要,自己使用extjs+swfupload写的一个多文件上传插件。

废话不说了,直接贴代码。


    Ext.ux.UploadWindow = Ext.extend(Ext.Window,{  
        width:700,height:400,tree:null,grid:null,layout:'border',store:null,progressBar:null,animateTarget:'ux-taskbar-start',constrainHeader:true,initComponent:function(){  
            this.bbar = [];  
            this.items = [];  
            this.initTree();  
            this.initProgressBar();  
            this.initGrid();  
            this.rec = Ext.data.Record.create([  
                     {name: 'name'},{name: 'size'},{name: 'id'},{name: 'type'},{name: 'creationdate',type: 'date',dateFormat: 'm/d/Y'},{name: 'filestatus'}  
            ]);  
            Ext.ux.UploadWindow.superclass.initComponent.call(this);  
        },initTree:function(){  
            this.tree = new Ext.Panel({  
                region:'west',width:200,collapsible:true,split:true,title:'folder list'  
            });  
            this.items.push(this.tree);  
        },renderFileStatus:function(v){  
            switch(v) {  
                case -1: return('<font 

color="red">pending..</font>');  
                case 1: return('<font 

color="red">uploading...</font>');  
                case 2: return('<font color="green">finished!

</font>');  
                case 3: return('<font color="red">failure!

</font>');  
                default:  
                    return v;  
            }  
        },...................................  
        initGrid:function(){  
            this.sm = new Ext.grid.CheckboxSelectionModel({  
                singleSelect :false,listeners: {  
                    selectionchange: function(sm) {  
                        if (sm.getCount()) {  
                            Ext.getCmp('startUpload').setDisabled(false);  
                        } else {  
                            Ext.getCmp('startUpload').setDisabled(true);  
                        }  
                    }  
                }  
            });  
            var cm = new Ext.grid.ColumnModel({  
                defaults: {  
                    sortable: true             
                },columns: [this.sm,{  
                    id: 'name',header: 'name',dataIndex: 'name',width: 220,editor: new Ext.form.TextField({  
                        allowBlank: false  
                    })  
                },{  
                    header: 'size',dataIndex: 'size',renderer:this.formatBytes  
                },{  
                    header: 'type',dataIndex: 'type'  
                },{  
                    header: 'status',dataIndex: 'filestatus',renderer:this.renderFileStatus  
                }   
                ]  
            });  
      
            this.store = new Ext.data.Store({  
                reader: new Ext.data.JsonReader({  
                          id: 'id'  
                     },this.rec)  
            });  
      
            this.grid = new Ext.grid.GridPanel({  
                region:'center',layout:'fit',border:false,store:this.store,cm:cm,sm:this.sm,draggable:false,tbar:[{text:'selectAll',handler:this.selectAll.createDelegate(this)},{text:'Deselect',handler:this.deselectRange.createDelegate(this)},{text:'Start',iconCls:'add',id:'startUpload',disabled:true,handler:this.startUpload.creat

eDelegate(this)},'->',{id:'selectBtn',cls:'selectBtn',handle:function(){  
                }}],autoExpandColumn:'name'  
            });  
            this.items.push(this.grid);  
        },startUpload:function(){  
            this.upload.startUpload();  
        },selectAll:function(){  
            this.sm.selectAll();  
        },initProgressBar:function(){  
            this.progressBar = new Ext.ProgressBar({  
                value:.5,text:'ProgressBar',width:'100%'  
            });  
            this.bbar.push(this.progressBar);  
        },deselectRange:function(){  
            var startRow = 0,endRow = this.store.data.items.length-1;  
            this.sm.deselectRange(startRow,endRow);  
        },upload:null,flashUrl:null,..................................................................  
    });  
    Ext.reg('uploadwindow',Ext.ux.UploadWindow);  




备注,若后台在文件上传时遇到提交失败,那可能是你在提交到后台文件时进行了权限验证,因为flash中的session数据跟浏览器本身使用的session不是同一个,在这里进行权限验证时需进行另外的处理,否则直接使用session进行权限验证将会导致因权限不足导致文件上传失败。

解决方法:可以在页面加载时候首先获取到PHPSESSID,然后赋值javascript,再由flash递交到后台。这样可以保证flash和浏览器直接的session使用的是同样数据。

代码下载地址:http://download.csdn.net/detail/phiberg/4172462

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读