项目需求:

vue项目中实现多图片批量上传功能

问题:

tinymce富文本编辑器的多图片批量上传插件 支持版本:5.0.4+
项目中现有的富文本编辑器版本:4.9.4
为实现这一功能选择更换tinymce版本 于是开启踩坑之旅。。

实现:

1.替换项目中tinymce文件 本项目放在\static\plugins文件夹

将tinymce.4.9.4更换成从官网上 http://download.tiny.cloud/tinymce/community/tinymce_5.7.0.zip
下载下来解压过的文件

并将语言包下载解压放到tinymce文件中 langs文件夹的zh_CN.js文件

2.更换路径

index.html文件内部的引入路径

<script src="./static/plugins/tinymce.4.9.4/tinymce.min.js"></script>
<script src="./static/plugins/tinymce.4.9.4/zh_CN.js"></script>

更换成自己替换后的文件:

<script src="./static/plugins/tinymce/tinymce.min.js"></script>
<script src="./static/plugins/tinymce/langs/zh_CN.js"></script>

static\config中init.js文件内部

'https://cdn.bootcss.com/tinymce/4.9.4/tinymce.min.js',
window.SITE_CONFIG.cdnUrl + '/static/plugins/tinymce.4.9.4/zh_CN.js',

同样作替换(用外部链接之后页面出现加载太慢问题,这里作下调整):

window.SITE_CONFIG.cdnUrl + '/static/plugins/tinymce/tinymce.min.js',
window.SITE_CONFIG.cdnUrl + '/static/plugins/tinymce/langs/zh_CN.js',

根据自己修改后的路径进行正确替换即可 如果此时页面上没有富文本编辑器可能不是你路径问题

3.富文本编辑器不出现原因

排查之后是theme: 'modern', 这个主题问题
改成TinyMCE随附的默认主题silver theme: 'silver', 之后 成功显示在页面 可参考文档做主题替换

4.工具栏内容不出现

通过查看文档http://tinymce.ax-z.cn/general/basic-setup.php 在toolbar逐步添加自己需要的工具
通过参照文档在plugins添加需要的插件

此时可以参考文档加入多图片批量上传插件


tinymce文档代码:

tinymce.init({selector: '#tinydemo',plugins: "code image axupimgs",toolbar: "code axupimgs",images_upload_base_path: '/demo',images_upload_handler: function (blobInfo, succFun, failFun) {var xhr, formData;var file = blobInfo.blob();//转化为易于理解的file对象xhr = new XMLHttpRequest();xhr.withCredentials = false;xhr.open('POST', '/demo/upimg2.php');xhr.onload = function() {var json;if (xhr.status != 200) {failFun('HTTP Error: ' + xhr.status);return;}json = JSON.parse(xhr.responseText);if (!json || typeof json.location != 'string') {failFun('Invalid JSON: ' + xhr.responseText);return;}succFun(json.location);};formData = new FormData();formData.append('file', file, file.name );xhr.send(formData);}
});

5.点击菜单和部分工具栏没反应

搞半天发现是层级问题 因为是在弹框上使用该富文本编辑器 弹框层级过高 修改部分样式即可解决这一问题

最后附上富文本编辑器代码 这个项目是封装成了一个组件

<template><div class="tinymce" ><textarea :id="tinymceId"></textarea></div>
</template><script>
import { getUUID } from '@/utils'
export default {data () {const tinymceId = 'tinymce' + getUUID()return {flag: true,tinymceId: tinymceId,myEditor: null}},props: {value: {default: ''},tinymceHeight: {default: 500,type: Number}},watch: {value (val) {if (this.flag) {this.setContent(val)}this.flag = true}},mounted () {this.init()},beforeDestroy () {tinymce.remove(`#${this.tinymceId}`)},methods: {init () {const self = thisthis.Editor = tinymce.init({// 默认配置...this.getDefalutConfig(),// 图片上传images_upload_handler: (blobInfo, success, failure) => {if (blobInfo.blob().size > self.maxSize) {failure('文件体积过大')}const formData = new FormData()formData.append('editorFile', blobInfo.blob())this.$http({url: this.$http.adornUrl(`/admin/file/upload/tinymceEditor`),headers: {'Content-Type': 'multipart/form-data','token': this.$cookie.get('token')},method: 'post',data: formData}).then(({ data }) => {success(data)}).catch(() => {failure('服务器出了点小差')})},// prop内传入的的config...this.config,// 挂载的DOM对象selector: `#${this.tinymceId}`,setup: (editor) => {self.myEditor = editoreditor.on('init', () => {self.loading = falseif (self.value) {editor.setContent(self.value)} else {editor.setContent('')}})// 抛出 'input' 事件钩子,同步value数据editor.on('input change undo redo execCommand', () => {self.flag = falseself.$emit('input', editor.getContent())})}})},getDefalutConfig () {return {// GLOBALheight: this.tinymceHeight,theme: 'silver',language: 'zh_CN',menubar: 'file edit insert view format table tools help',branding: false,// toolbar: `insertfile`, // 需要的工具栏toolbar:`undo redo | styleselect | formatselect | fontselect | fontsizeselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | image axupimgs link | insert paste code | numlist bullist | table fullscreen | forecolor backcolor hr | preview removeformat`,plugins:`image link paste code lists advlist importcss table fullscreen media hr preview axupimgs`,// plugins: `//     textcolor//     colorpicker//   `,// CONFIGforced_root_block: 'p',//将任何非块元素或文本节点都包装在块元素中// force_p_newlines: true,importcss_append: true,//将导入的样式附加到Format菜单的末尾,并将替换默认格式fullscreen_native: true,toolbar_mode:'sliding',//工具栏模式// CONFIG: ContentStyle 这块很重要, 在最后呈现的页面也要写入这个基本样式保证前后一致, `table`和`img`的问题基本就靠这个来填坑了content_style: `*                         { padding:0; margin:0; }html, body                { height:100%; }img                       { max-width:100%; display:block;height:auto; }a                         { text-decoration: none; }iframe                    { width: 100%; }p                         { line-height:1.6; margin: 0px; }table                     { word-wrap:break-word; word-break:break-all; max-width:100%; border:none; border-color:#999; }.mce-object-iframe        { width:100%; box-sizing:border-box; margin:0; padding:0; }ul,ol                     { list-style-position:inside; }`,// insert_button_items: 'image link | inserttable',  已删除该配置setup: function (editor) {editor.ui.registry.addMenuButton('insert', {icon: 'plus',tooltip: 'Insert',fetch: function (callback) {callback('image link | inserttable');}});},// CONFIG: Pastepaste_retain_style_properties: 'all', //贴内容时要保留的样式paste_word_valid_elements: '*[*]',        // word需要它paste_data_images: true,                  // 粘贴的同时能把内容里的图片自动上传,非常强力的功能paste_convert_word_fake_lists: true,     // 插入word文档需要该属性paste_webkit_styles: 'all',   //指定粘贴到WebKit中时要保留的样式paste_merge_formats: true,   //合并相同的文本格式元素nonbreaking_force_tab: false,   //按下键盘tab键时强制TinyMCE插入三个实体// paste_auto_cleanup_on_paste: false,// CONFIG: Fontfontsize_formats: '10px 11px 12px 14px 16px 18px 20px 24px',//文字大小列表// CONFIG: StyleSelect 自定义段落样式格式style_formats: [{title: '首行缩进',block: 'p',styles: { 'text-indent': '2em' }},{title: '行高',items: [{ title: '1', styles: { 'line-height': '1' }, inline: 'span' },{ title: '1.5', styles: { 'line-height': '1.5' }, inline: 'span' },{ title: '2', styles: { 'line-height': '2' }, inline: 'span' },{ title: '2.5', styles: { 'line-height': '2.5' }, inline: 'span' },{ title: '3', styles: { 'line-height': '3' }, inline: 'span' }]}],// FontSelect 字体列表font_formats: `微软雅黑=微软雅黑;宋体=宋体;黑体=黑体;仿宋=仿宋;楷体=楷体;隶书=隶书;幼圆=幼圆;Andale Mono=andale mono,times;Arial=arial, helvetica,sans-serif;Arial Black=arial black, avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats`,// Tabtabfocus_elements: ':prev,:next',//按下Tab键时,此设置可用于更改编辑器的焦点行为object_resizing: true,//可以打开/关闭图像,表格或媒体对象的大小调整手柄// Imageimagetools_toolbar: 'rotateleft rotateright | flipv fliph | editimage imageoptions'//控制将在上下文工具栏上显示的按钮的确切选择}},setContent (content) {if (content != "") {this.myEditor.setContent(content)}else{this.myEditor.setContent('')}},getContent () {return this.myEditor.getContent()}}
}
</script><style >
.tinymce{
width: 850px!important
}
.tox-tinymce-aux {z-index: 2006!important;
}
.tox .tox-dialog-wrap__backdrop {display: none;
}
.tox .tox-dialog {box-shadow: none;
}
.tox-dialog tox-dialog--width-lg {z-index: 2006!important;
}
</style>

以上是我踩过的坑 欢迎来踩

vue项目中更换tinymce版本踩坑相关推荐

  1. Vue项目中加载图片的坑

    Vue项目中加载图片时,遇到的坑 1.当直接在标签中,使用图片路径,此时可以正常显示. <img src='img_src' /> 正常显示 2.当img标签的src属性为变量时,且该变量 ...

  2. Swift原生项目中集成RN的踩坑笔记

    学习Reate Native的踩坑之路 搭建环境 官方环境搭建地址.官方原生集成地址 本人环境:mac10.15.4.Xcode11.4.brew:2.2.16.Pods:1.9.1.npm:6.14 ...

  3. Vue项目中使用Tinymce

    前言 最近因为公司项目的后台管理端需要实现编辑器功能, 一方面满足编辑各类文章内容需求,另一方面要自己编辑一些课程相关的介绍,于是就花了一些时间对比体验现有的一些开源的编辑器. 编辑器之间的简单比较 ...

  4. Vue项目中使用 tinymce 富文本编辑器的方法,附完整源码

    来源 | https://blog.csdn.net/xingmeiok/article/deta 1.tinymce相关参考资料 tinymce版资料: http://tinymce.ax-z.cn ...

  5. Vue项目对接微信公众号踩坑日记

    之前做项目都是pc端的,还是第一次做移动端项目,而且上来就要接入app 和微信公众号两个平台,最终查阅多方文档,耗费几周时间还是完成了项目,这篇文章也算是记录一下自己的完成思路以及一些想法,希望能帮到 ...

  6. java web项目中的根路径踩坑

    以下总结来自于颜群老师课堂笔记. java web项目中的"/"怎样区分? 项目根目录: WebContent \ src(所有的构建目录) 如果WebContent中有一个文件i ...

  7. vue项目中更新element-ui版本

    一.升级element-ui需要先卸载原先的版本,在cmd中输入 npm uninstall element-ui 二.然后重新安装element-ui npm i element-ui -S

  8. 在vue3.0项目中使用tinymce富文本编辑器

    目录 一.安装 二.完整代码 三.事项说明 四.参考文档   之前看了好几篇关于 vue项目中使用 tinymce的文章, import引入大量 tinymce插件, /node_modules/ti ...

  9. 学习踩坑:在Vue项目中使用svg标签却无法改变图标的颜色

    在Vue项目中使用svg标签却无法改变图标的颜色 在学习 vue 实战项目的过程中,用到了 svg 模块,对其使用了 fill 属性后,图标的颜色却没有任何的改变,反复查看了视频,步骤是一模一样的,却 ...

最新文章

  1. POJ2513Colored Sticks(欧拉路加字典树)
  2. Java集合HashSet
  3. 各大公司java面试整理对应问题博客整理
  4. message:MCODE参数不存在,mobile类型mcode参数必需
  5. 只有22%的人做对了这道数据分析题,你来试试吗?
  6. 搭建Flink集群环境
  7. C++中类成员变量在初始化列表中的初始化顺序
  8. 任秀计算机音乐,重磅丨15家主流媒体聚焦全球音乐院校校长交流季
  9. c语言位操作的高级应用
  10. 网络字节序与主机字节序 高低位
  11. 【三人行必有我师】同学提分经验分享大全,进步原来如此简单!
  12. 医学病理图片(SVS格式)的格式转换与显示——python实现
  13. maven 解决Cannot access alimaven以及Process terminated
  14. 生死看淡,不服就GAN——GAN的种类
  15. 可转债量化系列之二:估值择时策略初探
  16. 云服务器性能不如物理服务器,云服务器性能不如物理服务器
  17. github上提交pr的完整流程
  18. 22222222222222222222222
  19. 深入浅出WPF(8)——数据的绿色通道,Binding(中)
  20. Linux临时解决命令行cat命令中文乱码

热门文章

  1. 机器人炒菜感想_机器人也食人间烟火,炒菜炒的不亦乐乎!
  2. mastercam9.1中怎么把程序直接生成记事本显示
  3. android+曝光时间软件,Camera FV-5相机
  4. 湘潭大学oj 1191 Hard Wuxing
  5. Python实现图片转jpg格式
  6. 我的世界java版特性_我的世界Java版特性展望直面会爆料
  7. ubuntu下libmodbus库的使用
  8. 中国标志性的图片简笔画,互联网简笔画图片大全
  9. 《ASP.NET应用程序设计》答案
  10. Java设计者模式之装饰器模式