vue 后台管理系统富文本组件(四)UEditor(集成 135 编辑器插件)

简介

135 编辑器应用于微信文章、企业网站、以及论坛等多种平台,支持秒刷、一键排版、全文配色、公众号管理、微信变量回复、48 小时群发、定时群发、云端草稿、文本校对等 40 多项功能与服务, 像拼积木一样组合排版的文章。 135 编辑器因其简单的操作,强大的功能和美观的排版深受广大用户喜爱。135 编辑器本质是基于百度 UEditor 二次开发的,因公司业务需求开发了本文组件。

本文章源码-GitHub仓库地址

准备工作

  1. 下载 UEditor

    UEditor 官网下载链接 如图下载开发版 1.4.3.3 完整源码-点击下载

    下载完成后的目录如下

    其中好多文件目录我们并不需要,如下只保留这些文件。editor_api.js文件来自 _examples文件夹,_examples文件夹删除前把这个文件提取出来。

  2. 基于vue-cli 3 搭建项目,主要依赖说明 (先安装,scss和element-ui先配置,步骤略)

    {"axios": "^0.19.0","core-js": "^3.4.4","element-ui": "^2.13.0","vue": "^2.6.10","vue-router": "^3.1.3","vuex": "^3.1.2"
    }
    
  3. vue.config.js 配置如下,( assetsDirstaticpublicPath"./"

    module.exports = {publicPath: "./",outputDir: "dist",assetsDir: "static",productionSourceMap: false,lintOnSave: true,devServer: {port: 8080,open: true,overlay: {warnings: true,errors: true}}
    };
    

    VueRouter 的模式改成hash模式

    const router = new VueRouter({mode: 'hash',base: process.env.BASE_URL,routes
    })
    
  4. 然后在public 里新建文件夹static 把下载的ueditor文件夹整个拿过来,放到static目录下

  5. 修改editor_api.js文件里的 baseURL变量

    baseURL = '../_src/' 改为 baseURL = 'static/ueditor/_src/'

  6. 添加 135 插件,添加 135 插件文档

    a. 下载
    http://www.135editor.com/js/ueditor/plugins/135editor.js

    http://www.135editor.com/js/ueditor/dialogs/135editor/135EditorDialogPage.html

    b.放置文件
    135editor.js文件放到 public/static/ueditor/_src/plugins 文件夹下

    135EditorDialogPage.html文件放到public/static/ueditor/dialogs/135editor 文件夹下 没有135editor文件夹需要新建)

    c. 修改配置文件
    在 ueditor.config.js 中 toolbars 项里增加一个 135editor 菜单项

      toolbars: [ ['135editor', 'fullscreen', 'source', '|',  'undo', redo', .... ]]
    

    d.添加 css (在后文 src/components/UEditor/index.vue 文件里添加)

    .edui-button.edui-for-135editor.edui-button-wrap.edui-button-body.edui-icon {background-image: url("http://static.135editor.com/img/icons/editor-135-icon.png") !important;background-size: 85%;background-position: center;background-repeat: no-repeat;
    }
    
  7. public/index.html 里添加文件 ueditor.config.js,editor_api.js,zh-cn.js

    <!DOCTYPE html>
    <html lang="en"><head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width,initial-scale=1.0" /><link rel="icon" href="<%= BASE_URL %>favicon.ico" /><title>135</title></head><body><noscript><strong>We're sorry but 135 doesn't work properly without JavaScriptenabled. Please enable it to continue.</strong></noscript><div id="app"></div><!-- built files will be auto injected --><!-- ueditor --><scripttype="text/javascript"src="static/ueditor/ueditor.config.js"></script><scripttype="text/javascript"src="static/ueditor/editor_api.js"></script><scripttype="text/javascript"src="static/ueditor/lang/zh-cn/zh-cn.js"></script></body>
    </html>
    

组件

  1. 文件目录

  2. 核心代码
    src/components/UEditor/index.vue

    <template><div class="custom-ueditor-container"><div:id="id":style="{ width: width + 'px', height: height + 'px' }"></div><multiple-uploadclass="custom-upload-button":button-style="buttonStyle"@success="imageSuccess"/></div>
    </template>
    <script>/* eslint-disable eqeqeq *//* eslint-disable no-undef *//* eslint-disable no-unused-vars *//* eslint-disable space-in-parens */import axios from "axios";import config from "./config"; // 配置文件见下文import MultipleUpload from "../MultipleUpload";  // MultipleUpload组件参考 https://blog.csdn.net/qq_39953537/article/details/100039094import { uploadHtml } from "@/api/upload"; // 接口根据自己后端提供的写const UE = window.UE;// 设置 UEDITOR_HOME_URLwindow.UEDITOR_HOME_URL = "static/ueditor";export default {components: {MultipleUpload},props: {width: {type: Number,default: 750},height: {type: Number,default: 400},html: {type: String,default: ""}},data() {return {ueditor: null,buttonStyle: {padding: "3px 6px"}};},computed: {// 生成唯一idid() {const id =Math.random().toString(36).substring(2, 15) +"-ueditor-" ++new Date();return id;}},watch: {html(val) {this.loadUrl(val);}},mounted() {this.init();},beforeDestroy() {this.destroyEditor();},methods: {// 编辑器初始化init() {this.ueditor = UE.getEditor(this.id, { ...config });if (this.html) {this.loadUrl(this.html);}},// 加载html内容async loadUrl(url) {try {const { data } = await axios.get(url);this.setContent(data);} catch (error) {this.setContent("服务器数据加载失败,请重试!");}},// 图片上传成功添加到编辑器async imageSuccess(urlList) {try {let imageTemplateList = "";urlList.forEach(item => {const image = `<img style="max-width:100%;" src="${item}">`;imageTemplateList = imageTemplateList + image;});this.inserthtml(imageTemplateList, true);this.$message.success("上传成功!");} catch (error) {console.log(error);this.$message.error(error);}},// 编辑器内容上传到cos,调用返回urlasync content2Url() {try {if (!this.hasContent()) {throw new Error("未输入内容");}const content = this.getContent();const res = await uploadHtml(content);return res;} catch (error) {throw new Error(error);}},// 设置编辑器内容  isAppendTo为true时是追加内容到编辑器,false是覆盖setContent(content, isAppendTo) {if (!content) return;this.ueditor.ready(() => {this.ueditor.setContent(content, isAppendTo);});},// 在当前光标位置插入html内容inserthtml(content) {if (!content) return;this.ueditor.execCommand("inserthtml", content);},// 获取编辑器内容getContent() {return this.ueditor.getContent();},// 设置编辑器聚焦setFocus() {this.ueditor.focus();},// 判断编辑器是否有内容hasContent() {return this.ueditor.hasContents();},// 销毁编辑器destroyEditor() {this.ueditor.destroy();}}};
    </script>
    <style lang="scss" scoped>.custom-ueditor-container {position: relative;color: #373737;line-height: 22px;.custom-upload-button {position: absolute;left: 650px;top: 32px;z-index: 99;}}
    </style><style>
    /* 添加135编辑器插件样式 */.edui-button.edui-for-135editor.edui-button-wrap.edui-button-body.edui-icon {background-image: url("http://static.135editor.com/img/icons/editor-135-icon.png") !important;background-size: 85%;background-position: center;background-repeat: no-repeat;}
    </style>
    

    src/components/UEditor/config/index.js

    import toolbars from "./toolbars";
    const config = {toolbars,zIndex: 99, // 编辑器层级的基数,默认是900wordCount: false, // 是否开启字数统计wordCountMsg: "", // 输入提示maximumWords: Number.MAX_VALUE, // 允许的最大字符数serverUrl: "", // 服务器统一请求接口路径enableAutoSave: false, // 不自动保存enableContextMenu: false, // 禁用右键autoHeightEnabled: false, // 不自动扩展编辑器高度elementPathEnabled: false // 不显示html元素路径
    };export default config;
    

    src/components/UEditor/config/toolbars.js

    const toolbars = [[// 'fullscreen', // 全屏// 'source',  // 源代码// '|',// 'undo',// 'redo',// '|',"bold","italic","underline","fontborder","strikethrough","superscript","subscript","removeformat","formatmatch","autotypeset","blockquote","pasteplain","|","forecolor","backcolor",// 'insertorderedlist',  // 有序// 'insertunorderedlist', // 无序"selectall","cleardoc","|","rowspacingtop","rowspacingbottom","lineheight","|",// 'customstyle',"paragraph",// 'fontfamily',"fontsize","|",// 'directionalityltr',  // 文字方向// 'directionalityrtl', // 文字方向"indent","|","justifyleft","justifycenter","justifyright","justifyjustify","|","touppercase","tolowercase",// '|',// 'link',// 'unlink',// 'anchor',"|","imagenone","imageleft","imageright","imagecenter","|",// 'simpleupload',// 'insertimage',"emotion",// 'scrawl', // 涂鸦// 'insertvideo',// 'music',// 'attachment', // 附件// 'map',// 'gmap',// 'insertframe',// 'insertcode',// 'webapp',// 'pagebreak', // 分页"template",// 'background', // 编辑器背景"|","horizontal","date","time","spechars",// 'snapscreen', // 截图// 'wordimage',// '|',// 'inserttable',// 'deletetable',// 'insertparagraphbeforetable',// 'insertrow',// 'deleterow',// 'insertcol',// 'deletecol',// 'mergecells',// 'mergeright',// 'mergedown',// 'splittocells',// 'splittorows',// 'splittocols',// 'charts',"|",// 'print',// 'preview',"searchreplace"// 'help',// 'drafts']
    ];export default toolbars;
    
  3. 使用

    <template><div class="demo"><u-editor ref="editor" :height="500" :html="html" @input="getContent" /><div class="get-url-btn-warpper"><el-button type="primary" size="small" @click="getContentUrl">获取上传后的链接</el-button></div></div>
    </template><script>
    import UEditor from '@/components/UEditor'
    export default {name: 'UEditorDemo',components: {UEditor},data() {return {html: '',content: ''}},methods: {// 获取商品详情编辑器内容getContent(content) {this.content = content},// 获取上传后的链接async getContentUrl() {try {const url = await this.$refs.editor.content2Url()console.log(url)} catch (error) {this.$message.warning(error.message)}}}
    }
    </script><style lang="scss">
    .demo {margin: 50px;
    }
    .get-url-btn-warpper {margin-top: 10px;
    }
    </style>
    
  4. 使用效果

    参考链接

    1. http://www.135plat.com/135_ueditor_plugin.html
    2. http://fex.baidu.com/ueditor/
    3. http://ueditor.baidu.com/doc/

vue 后台管理系统富文本组件(四)UEditor(集成 135 编辑器插件)相关推荐

  1. vue + wangeditor封装富文本组件

    一.介绍 wangEditor -- 轻量级 web 富文本编辑器,配置方便,使用简单. 官网:https://www.wangeditor.com/ 文档:https://www.wangedito ...

  2. UEditor(集成 135 编辑器插件)(附源码)

    效果图 可以看到第一个菜单是135,点击135跳到135编辑器,点击完成编辑即可 准备工作 1.npm npm install vue-ueditor-wrap // 或者 yarn add vue- ...

  3. 基于nuxt和iview搭建OM后台管理系统实践(2)-quill富文本组件的封装

    目录结构 这是<基于nuxt和iview搭建OM后台管理系统实践>这一个系列文章的目录,大致思路如下: 简要介绍OM后台管理系统,以及开发环境 自行开发的公共组件(富文本.地图.上传)介绍 ...

  4. vue使用百度富文本编辑器(ueditor)

    文章目录 vue使用百度富文本编辑器(ueditor) 1.进入官网或者github下载源码 2.使用grunt编译 4.安装`vue-ueditor-wrap` 5.组件中引入,自定义组件 6.后端 ...

  5. Vue中引入富文本编辑器

    这里使用的是 vue-quill-editor 富文本组件 先安装一下: npm i vue-quill-editor -s 下载之后 去components文件夹中新建一个文件夹 KEditor,然 ...

  6. 基于 Element-ui 的富文本组件quillEditor

    开发后台管理系统经常需要用到富文本组件用来编辑文章,或者商城类的管理系统需要富文本编辑商品详情,但是有些富文本里面的上传图片功能实质是把图片转成base64字符串传给后台,如果上传的图片一多,那后台估 ...

  7. 哔哩哔哩Allen前端vue后台管理系统笔记

    哔哩哔哩Allen前端vue后台管理系统笔记 Element ui 引入 全局引入 按需引入 嵌套路由 左侧菜单栏的样式 Container布局,左侧菜单栏commonAside组件 commonAs ...

  8. vue后台管理系统搭建

    vue后台管理系统搭建 前提 安装node.js 控制台安装yarn:npm install -g yarn 查看yarn版本:yarn --version 注:-g表示的是全局安装 淘宝镜像安装:n ...

  9. weui上传组件的图片封装到formdata_自定义toast-ui富文本组件的图片黏贴上传

    最近博客中用到了这个富文本组件,发现这组件的图片无法支持 截图黏贴以及上传图片是一长串base64字符串,非常不方便,所以通过文档,自定义一个一下上传方式,效果如图 其中,上传图片是调用组件自带的ho ...

  10. P6-Vue3后台管理系统-构建业务组件连通公共组件

    P6-Vue3后台管理系统-构建业务组件连通公共组件 1.概述 这篇文章我们将创建业务模块,并且与公共组件进行连通. 2.构建业务模块 2.1.构建Home 2.2.构建VideoManage 2.3 ...

最新文章

  1. C# 日志框架的添加
  2. git merge 和 git merge --no-ff
  3. 行波和驻波动画演示gif_新技能get√ | 语文课上的笔顺动画可以这么做
  4. Eclipse Source not found
  5. Flask-请求上下文
  6. ML之预测:玩转2018世界杯—采用机器学习预测小组赛、十六比赛、四决赛、半决赛、决赛以及世界杯总冠军的各个队伍
  7. java jni librtmp_librtmp 编译集成
  8. jeecg 导出的excel不能使用公式_微软:Excel公式是世界上使用最广泛的编程语言...
  9. 信息学奥赛C++语言:求阶乘
  10. 晚上没有路灯,我骑的很慢
  11. teamviewer 可用设备上限_河北环保碎石机价格-设备_久诺机械设备
  12. 【硬件】存储的RAID技术详解
  13. 【react】XXX项目创建这个过程
  14. Matlab实现Hough变换检測图像中的直线
  15. 旧版创维电视怎么投屏?不用数据线就能投屏的方法
  16. mysql导入大量数据时jbd2 io过高效率低下问题
  17. 解密搭建平台赚钱的方法一:详解搭建网站收入的几个来源
  18. 工具及方法 - 使用DOS批处理给Windows文件批量改名
  19. 《浅入浅出》-RocketMQ
  20. link library 、target library、symbol library、synthetic library对照分析-基础小知识(九)

热门文章

  1. IDEA设置签名与导入主题
  2. Android Gradle学习(五) Extension详解
  3. ThoughtWorks 2018校招作业
  4. 使用x264压制视频简介
  5. ORACLE通过身份证号计算年龄
  6. 关于在Onenote online导出笔记的笔记
  7. 《一树梨花》旋转特效
  8. C++中的取地址符()
  9. 如何看懂常用原理图符号、如何阅读原理图
  10. 【Racket】安装与入门