百度富文本编辑器
本模块为系统添加百度富文本编辑器

模块介绍

为系统添加 百度(UEditor) 富文本编辑器,此编辑器插件是一款适用于BuildAdmin后台的富文本编辑器,功能精简,加载速度更快,可以将后台的默认编辑器替换为UEditor-V3编辑器。

编辑器官方文档地址
UEditor-vue3 插件文档

功能特性

  • 支持拖拽图片上传
  • 支持微信截图、QQ截图后粘贴上传图片
  • 支持图片传第三方云存储
  • 支持公式编辑
  • 支持地图插入
  • 支持表情插入
  • 支持附件图片插入
  • 支持 自定义按钮
  • 支持 自定义弹窗
  • 支持 粘贴图片
  • 支持 图片伸缩
  • 支持图片拖动改变大小
  • 兼容系统FormItem组件生态用法
  • 内置集成 135编辑器、非常适用于内容发布平台,如:公众号、新闻媒体等内容排版
  • 支持集成第三方插件

重点特性(与135编辑器互通)(2.0.0 新增)

内置集成 135编辑器,支持绑定 135编辑器的 appKep 实现免登录,支持与135编辑器内容双向互通,支持自动转存135编辑器图片
非常适用于内容发布平台,如:公众号、新闻媒体等内容排版

编辑内容展示:

属性Props

事件需要配合FormIteminputAttr属性使用

UEditor 各项配置说明,请自行查阅 UEditor文档 配置项说明
注意事项:UEditor 默认配置文件为 ueditor.config.js(在前端),但本模块的 默认配置文件为 config/ueditor.php(在后端)

属性名 说明 类型 默认值 备注
config UEditor配置项 Object 查看config/ueditor.php 的 配置项 1.1.0新增
toolbars 工具栏功能按钮 2D Array 查看 config/ueditor.php 1.1.0新增
cssJsDependencies CssJs插件依赖项 Array 一般用于二开和插件集成依赖项加载 2.0.0新增
editor135 135编辑器配置 Object 2.0.0新增

135编辑器配置说明

属性名 说明 类型 默认值 备注
enable 是否启用 Boolean false 2.0.0新增
appKey 免登录appKey String 2.0.0新增
imgAutoTransfer 图片转存 Boolean false 2.0.0新增
height 弹窗高度 int window.screen.availHeight - 100 2.0.0新增
width 弹窗宽度 int window.screen.availWidth - 100 2.0.0新增

事件Events

事件需要配合FormIteminputAttr属性使用

事件名 说明 回调参数
before-init UEditor 编辑器初始化之前触发 editorId: string
ready UEditor ready 时触发 editor: UEditor 实例

关于的 属性Props事件Events的详细说明 以及 其他属性 请自行查阅 组件API说明

关于二开(新增功能)

不了解二次开发的同学,可以先阅读一下 UEditor 官网关于二次开发的介绍
自定义按钮自定义弹窗自定义Vue弹窗

集成第三方插件

以集成 秀米 为例 (推荐使用方式二)

  1. 秀米的第三方对接方案 参考地址
  2. 集成秀米效果预览 请参考 秀米图文排版UEditor插件示例

关于配置文件

UEditor 默认配置文件为 ueditor.config.js
本模块为方便统一管理和修改,已经将常用配置迁移至 后端 config/ueditor.php

更多使用技巧:请阅读编辑器官方文档地址: http://fex-team.github.io/ueditor/#start-start

使用代码示例

VUE 复制代码
<template>
    <div>
    <!-- 其他代码 省略 -->
    
    <FormItem :label="t('ueditor.editor')" type="editor" v-model="baTable.form.items!.editor" prop="editor" @keyup.enter.stop="" @keyup.ctrl.enter="baTable.onSubmit(formRef)" :placeholder="t('Please input field', { field: t('ueditor.editor') })"
    :input-attr= "{
        // UEditor 编辑器初始化之前触发 事件
        onBeforeInit: (editorId: string) => beforeInit(editorId),
        // UEditor ready 时触发
        onReady:  (editor: Object) => reaady(editor),
        // 基础配置项
        config: {
            // zIndex: 9999 ,  //编辑器层级的基数,默认是2025  可解决层级穿透和错乱问题
            // initialFrameHeight: 6666,  //初始化编辑器高度,默认5000
            // 其他更多的配置项
            // 参考 config/ueditor.php 的 base 配置项
            // 查阅 UEditor文档 配置项说明 http://fex-team.github.io/ueditor/#start-config
        },
        // 工具栏上的所有的功能按钮 参考 config/ueditor.php 的 toolbars 配置项
        toolbars: [[
            '', '|', 'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote','pasteplain', '|',
        ]],
        // 需要额外引入 的 css 和  js
        // 一般用于 二开 和 插件 集成
        cssJsDependencies: [],
        // 135 编辑器
        editor135: {
            enable: true, // 是否启用
            appKey: '', // 免登录 的 appKey
            imgAutoTransfer: true, // 图片是否自动转存
            // height: '500', // 弹窗 高度
            // width: '500'  // 弹窗 宽度
        },
    }" />
    
    <!-- 其他代码 省略 -->
    
      <teleport to="body">
        <div v-if="showCustomVueDialog" class="modal-mask">
          <div class="modal-content">
            <p>hi! Vue Dialog!</p>
            <button @click="onVueDialogClose">关闭</button>
          </div>
        </div>
      </teleport>
  </div>
</template>
<script setup lang="ts">
 <!-- 其他代码 省略 -->

// 定义一个处理方法 新增 自定义按钮、自定义弹窗、自定义Vue弹窗
const beforeInit = (editorId: any) => {
    // 自定义按钮
    window.UE.registerUI(
        'my-custom-button',
        (editor, uiName) => {
            // 注册按钮执行时的 command 命令,使用命令默认就会带有回退操作
            editor.registerCommand(uiName, {
                execCommand() {
                    editor.execCommand('inserthtml', `<span>这是一段由自定义按钮添加的文字</span>`);
                },
            });

            // 创建一个 button
            const btn = new window.UE.ui.Button({
                // 按钮的名字
                name: uiName,
                // 提示
                title: '鼠标悬停时的提示文字-自定义按钮',
                // 需要添加的额外样式,可指定 icon 图标
                cssRules: `background-image: url('https://haochuan9421.github.io/vue-ueditor-wrap/UEditor/custom/my-custom-button.png') !important; background-size: cover;`,
                // 点击时执行的命令
                onclick() {
                    // 这里可以不用执行命令,做你自己的操作也可
                    editor.execCommand(uiName);
                },
            });

            // 当点到编辑内容上时,按钮要做的状态反射
            editor.addListener('selectionchange', function () {
                const state = editor.queryCommandState(uiName);
                if (state === -1) {
                    btn.setDisabled(true);
                    btn.setChecked(false);
                } else {
                    btn.setDisabled(false);
                    btn.setChecked(state);
                }
            });

            // 因为你是添加 button,所以需要返回这个 button
            return btn;
        },
        0 , /* 指定添加到工具栏上的哪个位置,默认时追加到最后 */
        editorId /* 指定这个 UI 是哪个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮 */
    );

    // 自定义弹窗
    window.UE.registerUI(
        'my-custom-dialog',
        (editor, uiName) => {
            // 创建 dialog
            const dialog = new window.UE.ui.Dialog({
                // 指定弹出层中页面的路径,这里只能支持页面
                iframeUrl: `https://doc.buildadmin.com/senior/web/formItem.html`,
                // 需要指定当前的编辑器实例
                editor,
                // 指定 dialog 的名字
                name: uiName,
                // dialog 的标题
                title: '这是一个自定义的 Dialog 浮层',
                // 指定 dialog 的外围样式
                cssRules: 'width:600px; height:300px;',
                // 如果给出了 buttons 就代表 dialog 有确定和取消
                buttons: [
                    {
                        className: 'edui-okbutton',
                        label: '确定',
                        onclick() {
                            dialog.close(true);
                        },
                    },
                    {
                        className: 'edui-cancelbutton',
                        label: '取消',
                        onclick() {
                            dialog.close(false);
                        },
                    },
                ],
            });

            // 参考上面的自定义按钮
            return new window.UE.ui.Button({
                name: 'my-custom-dialog-btn',
                title: '鼠标悬停时的提示文字-自定义弹窗',
                cssRules: `background-image: url('https://haochuan9421.github.io/vue-ueditor-wrap/UEditor/custom/my-custom-dialog.png') !important; background-size: cover;`,
                onclick() {
                    // 渲染dialog
                    dialog.render();
                    dialog.open();
                },
            });
        },
        0 /* 指定添加到工具栏上的那个位置,不指定默认时追加到最后 */,
        editorId /* 指定这个UI是哪个编辑器实例上的,不指定默认是页面上所有的编辑器都会添加这个按钮 */
    );

    // 自定义Vue弹窗
    window.UE.registerUI(
        'my-custom-button1',
        (editor, uiName) => {
            return new window.UE.ui.Button({
                name: uiName,
                title: '鼠标悬停时的提示文字-自定义Vue弹窗',
                cssRules: `background-image: url('//cdn.zhenghaochuan.com/p/vue-ueditor-wrap/static/UEditor/utf8-php/custom/my-custom-button.png') !important; background-size: cover;`,
                onclick: () => {
                    showCustomVueDialog.value = true;
                },
            });
        },
        0,
        editorId
    );
    
    // 集成秀米
    window.UE.registerUI(
        'xiumi-dialog',
        (editor: anyObj, uiName: string) => {
            // 创建 “秀米弹窗”
            const dialog = new window.UE.ui.Dialog({
                // 注意:这是 xiumi-ue-dialog-v5.html 文件的访问链接,这个页面会通过 iframe 的方式嵌入到弹窗里
                iframeUrl: '/assets/xiumi/xiumi-ue-dialog-v5.html',
                editor,
                name: uiName,
                title: '秀米图文消息助手',
                cssRules: 'width: ' + (window.innerWidth - 60) + 'px; height: ' + (window.innerHeight - 60) + 'px;',
            })
            
            // 添加自定义按钮用于唤起“秀米弹窗”
            return new window.UE.ui.Button({
                name: 'xiumi-connect',
                title: '秀米',
                // class 类名 
                // className:'edui-for-xiumi', //  与 cssRules 二选一
                // css样式  与 className 二选一
                cssRules: `background-image: url('//dl.xiumi.us/connect/ue/xiumi-connect-icon.png') !important; background-size: contain;`,
                onclick() {
                    dialog.render()
                    dialog.open()
                },
            })
        }, undefined,  /* 0时插入第一位置,undefined时追加到最后 */,
        editorId
    )
    // 您的 其他 功能 或 插件集成 
    // 一切皆有可能、请发挥 您聪明的大脑吧
}

const reaady = (editor: Object) => {
    UEditor.value = editor
    // 您的 其他 业务代码
}

const onVueDialogClose = () => {
    showCustomVueDialog.value = false;
    UEditor.value && UEditor.value.execCommand('inserthtml', `<span>弹窗被关闭了!</span>`);
}
 <!-- 其他代码 省略 -->

</script>

<style scoped lang="scss">
 <!-- 其他代码 省略 -->
 
:deep(.edui-button.edui-for-xiumi .edui-button-wrap .edui-button-body .edui-icon) {
    background-image: url("//dl.xiumi.us/connect/ue/xiumi-connect-icon.png") !important;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}
</style>

常见问题

  1. 为何修改配置文件ueditor.config.js不生效???

配置修改 请直接修改 config/ueditor.php 即可
UEditor 默认配置文件为 ueditor.config.js(前端)、本模块为方便统一管理和修改,已经将常用配置迁移至 后端 config/ueditor.php

  1. 图片为何不自动转存?

图片自动转存 默认开启 白名单机制,请在 config/ueditor.php 的 secureImageFetcher 配置 白名单域名 和 文件类型、文件大小
当然 也可以自行关闭 白名单机制 模式,但是不建议,如关闭白名单机制,潜在的风险需自行承担

  1. 层级错乱问题

遇到层级问题,请 通过传递 zIndex 进行覆盖,可解决层级穿透和错乱问题 , 示例如下:
:input-attr= "{config: { zIndex: 9999 ,//尽可能设置大一些 }}"

更新日志

  • 2025-05-14 11:24:46

    v2.0.1

    修复全屏模式下部分弹窗层级问题
    • 修复全屏模式下部分弹窗层级问题
  • 2025-05-03 14:23:30

    v2.0.0

    新增、优化和修复多个功能
    • 新增 cssJsDependencies 属性,CssJs 插件依赖项、一般用于二开和插件集成依赖项加载
    • 新增 editor135 属性,内置集成 135编辑器、支持与135编辑器内容双向互通、非常适用于内容发布平台,如:公众号、新闻媒体等内容排版
    • 新增 第三方图片自动转存、可转存本地 或 可转存云存储
    • 优化 默认配置值 以修复部分潜在问题
    • 优化 默认样式 以修复部分潜在问题
    • 修复 图片、视频、附件 适应 云存储 的问题
    • 修复 工具栏会穿透的问题
    • 修复 全屏在恢复后样式显示问题
  • 2025-03-17 17:07:34

    v1.1.0

    新增功能和修复已知问题
    • 新增 config 属性,旨在为满足独立自定义需求,可单独传入配置覆盖全局基础配置
    • 新增 toolbars 属性,旨在为满足独立自定义需求,可单独传入配置定义工具栏上的功能按钮
    • 修复在单页面存在多富文本编辑器不显示的问题
    • 修复优化组件弹窗可能出现穿透覆盖错乱的问题
  • 2025-01-17 22:32:17

    v1.0.0

    首次发布

    无详细更新日志

PHP_Daemon
PHP_Daemon
PHP_Daemon,PHP常驻内存研究-workerman、swoole
模块授权
正版授权,允许商业使用
自购买起一年内免费下载和升级更新
不加密源代码,私有部署,二开方便
可复制产品,不支持七天无理由退款
禁止转售、分享等任何形式的再分发
仅 BuildAdmin 后台管理系统可以使用
模块信息
模块价格
¥29.90
访问次数
1934
模块标识
ueditorv3
下载次数
86
模块分类
基础设施
上次更新
2025-05-14 11:24:46
开发者主页
-
购买送积分
-
纯WEB端TypeScript