Ext4.x之HtmlEditor擴充圖片上傳功能

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   sp   for   

1.實現非常簡單,稍後跟上,廢話不說先。

2.類的定義:

Ext.define(‘Ext.ux.XHtmlEditor‘,{        extend:‘Ext.form.field.HtmlEditor‘,        alias:‘widget.xhtmleditor‘,        //擴充的屬性        uploadConfig:{            url:‘‘//後台上傳地址        },        initComponent : function(){            this.callParent(arguments);            var me = this;            //建立組件            me.initExtFun = function(){                Ext.create(‘Ext.window.Window‘,{                    title:‘插入圖片‘,                    resizable:false,                    border:false,                    modal:true,                    frame:false,                    iconCls:‘Picture-Sunset‘,                    items:[                        {                            xtype:‘form‘,                            width:320,                            height:70,                            padding:10,                            border:false,                            items:[                                {                                    width:280,                                    labelAlign:‘right‘,                                    labelWidth:60,                                    xtype:‘filefield‘,                                    name:‘file‘,                                    allowBlank:false,                                    fieldLabel:‘選擇圖片‘,                                    buttonText:‘瀏覽...‘                                }                            ]                        }                    ],                    buttons:[                        {                            text:‘上傳‘,                            handler:function(b,e){                                //實現上傳,完成之後插入帶編輯器                                var form = b.up(‘window‘).down(‘form‘);                                form.submit({                                    waitMsg:‘正在上傳...‘,                                    clientValidation: true,                                    url:me.uploadConfig.url,                                    success:function(form,action){                                        //返回圖片路徑                                        var path = action.result.message;                                        //將圖片插入到游標所在的位置                                        me.insertAtCursor("<img src=‘"+path+"‘ />");                                        b.up(‘window‘).close();                                    },                                    failure:function(form,action){                                            switch (action.failureType) {                                                case Ext.form.action.Action.CLIENT_INVALID:                                                    Ext.Msg.alert(‘提示‘,‘用戶端驗證不通過!‘);                                                    break;                                                default:                                                    Ext.Msg.alert(‘儲存失敗,‘,action.result.message);                                            }                                        }                                        });                            }                        },                        {                            text:‘取消‘,                            handler:function(b,e){                                b.up(‘window‘).close();                            }                        }                    ]                }).show();            }            var b = Ext.create(‘Ext.button.Button‘,{                xtype:‘button‘,                iconCls:‘Picture-Sunset‘,                tooltip:‘上傳圖片‘,                text:‘‘,                listeners:{                    click:function(b,e){                         me.initExtFun();                    }                }            });            me.getToolbar().add(b);        }    });    

3.用法很簡單,首載入在上面的類,然後這樣引用。xtype:‘xhtmleditor‘

          {                        xtype:‘xhtmleditor‘,                        uploadConfig:{                            url:‘/app/uploadImage‘                        }                 }

4.後台實現上傳就省了,方法賊多。但要注意的是後台預設接收圖片的name是file,在上面類中有定義,可以隨意改。

Ext4.x之HtmlEditor擴充圖片上傳功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.