Extjs引入wangEditor富文本编辑器

wangEditor —— 轻量级 web 富文本编辑器,配置方便,使用简单。支持 IE10+ 浏览器。

一、wangEditor的引入

wangEditor官网:http://www.wangeditor.com/
官方在线开发文档:https://www.kancloud.cn/wangfupeng/wangeditor3/332599
我们可以先到官网下载wangEditor

<script type="text/javascript" src="./wangEditor/wangEditor.js"></script>
<script type="text/css" src="./wangEditor/wangEditor.css"></script>

二、wangEditor的封装

Ext.define('App.ux.MyWangEditor', {
    extend: 'Ext.form.field.Display',
    alias: ['widget.wangEditor'],
    // 创建全局编辑器
    editors: null,
    // 传入id
    id: null,
    showId: null,

    // 初始化组件和编辑器
    initComponent: function () {
        var me = this;
        me.callParent(arguments);
        this.initEditor();
    },

    afterRender: function () {
        var me = this;
        me.callParent(arguments);
        me.create();
    },

    // 初始化编辑器配置
    initEditor: function () {
        var me = this;
        // 创建wangEditor
        var E = window.wangEditor;
        var v = "#" + me.id;
        me.editors = new E(v);
        // 自定义文件上传方法
        me.editors.customConfig.customUploadImg = function (files, insert) {
            me.upload(files, insert);
        }
        // 自定义菜单配置
        me.editors.customConfig.menus = me.menusConfig;
    },

    create: function () {
        var me = this;
        me.editors.create();
        me.loade();
    },

    loade: function () {
        var me = this;
        me.synHtml();
        me.editors.create();
        var html = Ext.getCmp(me.showId).getValue();
        if (Ext.isEmpty(html)) {
            me.editors.txt.clear();
        } else {
            me.editors.txt.html(html);
        }
    },

    // 监控变化,同步更新
    synHtml: function () {
        var me = this;
        var $text1 = Ext.getCmp(me.showId);
        me.editors.customConfig.onchange = function (html) {
            $text1.setRawValue(html);
        }
    },

    // 自定义上传方法
    upload: function (files, insert) {
        // 图片url
        var imgUrl = '';
        // files 是 input 中选中的文件列表,拼接formData
        var formData = new FormData();
        formData.append("fileFiled", files[0]);
        formData.append("fileCode", null);
        $.ajax({
            url: SystemUtil.getRequestUrl('folder/uploadFile2'),
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function (respone) {
                // 上传代码返回结果之后,将图片插入到编辑器中
                imgUrl = "http://f.xxxx.com/" + respone.result.path;
                insert(imgUrl);
            },
            error: function (respone) {
                // 上传失败打印错误信息
                me.console(respone.message);
            }
        });
    },

    // 菜单配置
    menusConfig: [
        'head',  // 标题
        'bold',  // 粗体
        'fontSize',  // 字号
        'fontName',  // 字体
        'italic',  // 斜体
        'underline',  // 下划线
        'strikeThrough',  // 删除线
        'foreColor',  // 文字颜色
        'backColor',  // 背景颜色
        'link',  // 插入链接
        'list',  // 列表
        'justify',  // 对齐方式
        'quote',  // 引用
        'emoticon',  // 表情
        'image',  // 插入图片
        'table',  // 表格
        'video',  // 插入视频
        'code',  // 插入代码
        'undo',  // 撤销
        'redo'  // 重复
    ]
});

三、引入封装的编辑器

			{
                    xtype: 'fieldset',
                    columnWidth: 1,
                    collapsible: true,
                    title: '通知内容',
                    layout: 'column',
                    defaults: {
                        margin: '5 5 5 5',
                        columnWidth: 1,
                        labelWidth: 80,
                        xtype: 'textfield'
                    },
                    items: [{
                        xtype: 'wangEditor', // 引入包装好的编辑器
                        id: 'weShow' 
                    },{
                        allowBlank: false,
                        xtype: 'textareafield', // 编辑器内容提交所依赖的文本域
                        id: 'editors',
                        hidden: true,
                        name: 'content'
                    }]
                }

最后附上引入的wangEditor3编辑器的图

在这里插入图片描述

转载请注明出处!

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要给ExtJS中整合了Layui富文本编辑器的编辑框添加样式,可以使用Layui富文本编辑器提供的工具栏按钮或手动添加HTML标签来实现。 首先,在ExtJS中创建一个textarea元素,然后使用Layui的富文本编辑器组件将其转换为富文本编辑器。示例代码如下: ``` var textarea = Ext.create('Ext.form.field.TextArea', { fieldLabel: '内容', name: 'content', id: 'content', listeners: { render: function() { layui.use(['layedit'], function() { var layedit = layui.layedit; var index = layedit.build('content'); }); } } }); Ext.create('Ext.form.Panel', { renderTo: Ext.getBody(), items: [textarea] }); ``` 这里使用了Layui的`layedit.build()`方法将textarea元素转换为富文本编辑器,并返回一个索引值,通过这个索引值可以获取到编辑器实例。 接下来,可以使用Layui富文本编辑器提供的工具栏按钮来添加样式。例如,使用加粗工具栏按钮可以将文本加粗,使用斜体工具栏按钮可以将文本变为斜体。示例代码如下: ``` layui.use(['layedit'], function() { var layedit = layui.layedit; var index = layedit.build('content'); // 加粗 layedit.setFont('bold'); // 斜体 layedit.setFont('italic'); }); ``` 除了使用工具栏按钮,还可以手动向编辑器中添加HTML标签来实现样式。示例代码如下: ``` layui.use(['layedit'], function() { var layedit = layui.layedit; var index = layedit.build('content'); // 向编辑器中添加HTML标签 layedit.setContent('<p style="font-weight:bold">这是加粗文本</p>'); }); ``` 这里使用了`layedit.setContent()`方法向编辑器中添加HTML标签,从而实现了文本加粗的效果。可以根据需要添加不同的HTML标签来实现不同的样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值