<template>
<tinymce :init="config"></tinymce>
</template>
<script>
import tinymce from '@tinymce/tinymce-vue';
export default {
name: 'tinyEditor',
components: { tinymce },
props: { params: Object },
computed: {
config () {
return Object.assign({
// fullscreen_native: true, // 使用浏览器的全屏功能,默认false
language: /^zh/i.exec(window.navigator.language) ? 'zh_CN' : 'en',
toolbar_mode: 'sliding',
convert_urls: false,
height: 400,
toolbar: 'fullscreen | fontselect fontsizeselect formatselect | undo redo | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap emoticons | preview save print | insertfile image media pageembed template link anchor codesample | a11ycheck ltr rtl | showcomments addcomment kityformula-editor tiny_mce_wiris_formulaEditor tiny_mce_wiris_formulaEditorChemistry',
plugins: 'print preview powerpaste casechange importcss searchreplace autolink autosave save directionality advcode visualblocks visualchars fullscreen image link media mediaembed template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists checklist wordcount a11ychecker imagetools textpattern noneditable help formatpainter permanentpen pageembed charmap mentions quickbars linkchecker emoticons advtable export',
setup: this.editorSetup,
draggable_modal: true
}, this.params);
}
},
methods: {
editorSetup (editor) {
/**
* 解决与element UI弹窗的冲突:
* 在编辑器初始化阶段向整个编辑器添加Mousemove监听事件,通过获取根节点最高层数赋给编辑器和弹窗层;
* 编辑区阻止事件冒泡,所以会出现当鼠标停留在编辑区中,无法显示菜单。
* 这种选择弹层方式,需要在tinymce/themes/silver/theme.min.js中的弹窗class名(tox-tinymce-aux)处加上实例ID,如下图中的 d.id;
* 监听多个事件是为了尽可能规避,无法显示菜单和弹窗的问题;
*/
function overlay (aux) {
return function (e) {
let index = 1;
document.body.childNodes.forEach(function(element) {
if (element.style && element.style.zIndex > index) {
index = parseInt(element.style.zIndex);
}
});
if ((parseFloat(aux.style.zIndex) || 0) < index) {
e.target.style.zIndex = aux.style.zIndex = index;
}
};
}
editor.on('init', function (e) {
const aux = document.querySelector('.' + e.target.id);
e.target.editorContainer.addEventListener('mouseenter', overlay(aux), false);
e.target.editorContainer.addEventListener('mousedown', overlay(aux), false);
});
}
}
};
</script>


该文章介绍了一个基于TinyMCE的富文本编辑器组件的初始化配置,包括语言设置、工具栏、插件、全屏模式等,并针对与elementUI弹窗的冲突提出了解决方案,通过监听鼠标事件动态调整zIndex来确保编辑器和弹窗的正常显示。
66

被折叠的 条评论
为什么被折叠?



