<template> <div class="tinymce-boxz"> <Editor v-model="content" :init="init"/> <- <Editor v-model="content" :api-key="apiKey" :init="init" /> -> </div> </template>
<script> import Editor from '@tinymce/tinymce-vue'; import { reactive, ref, toRefs, watch } from 'vue';
export default { name: 'tinyMce', components: { Editor, }, props: ["age"], setup(props, {emit}) { const content = ref(props.age); const tiny = reactive({ init: { language: 'zh_CN', placeholder: '请输入......', auto_focus : true, min_height: 220, resize: 'true', branding: false, elementpath: false, font_formats: '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;', plugins: 'powerpaste autoresize print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template code codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount textpattern autosave emoticons',
menubar: false, toolbar: "undo redo | fullscreen | formatselect alignleft aligncenter alignright alignjustify | link unlink | numlist bullist | image media table | fontselect fontsizeselect forecolor backcolor | bold italic underline strikethrough | indent outdent | superscript subscript | removeformat |", toolbar_drawer: "sliding", paste_data_images: true, images_upload_handler: (blobInfo, success) => { let reader = new FileReader(); reader.readAsDataURL(blobInfo.blob()); reader.onloadend = function () { const imgbase64 = reader.result; success(imgbase64); }; },
file_picker_types: 'file image media', file_picker_callback: function (callback, value, meta) {
let filetype; if (meta.filetype == 'image') { filetype = '.jpg, .jpeg, .png, .gif, .ico, .svg'; } else if (meta.filetype == 'media') { filetype = '.mp3, .mp4, .avi, .mov'; } else { filetype = '.pdf555, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .mp4, .jpg, .jpeg, .png, .gif, .ico, .svg'; } let inputElem = document.createElement('input'); inputElem.setAttribute('type', 'file'); inputElem.setAttribute('accept', filetype); inputElem.click(); inputElem.onchange = () => { let file = inputElem.files[0];
let reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function () { let id = 'blobid' + new Date().getTime(); let blobCache = tinymce.activeEditor.editorUpload.blobCache; let base64 = reader.result.split(',')[1]; let blobInfo = blobCache.create(id, file, base64); blobCache.add(blobInfo);
callback(blobInfo.blobUri(), {title: file.name}); }; }; }, external_plugins: { powerpaste: '/tinymce/js/tinymce/plugins/powerpaste/powerpaste/plugin.min.js' }, powerpaste_word_import: 'merge', powerpaste_html_import: 'merge', powerpaste_allow_local_images: true, }, }); const toFather = () => { emit('updContent', {content: content.value}); }; watch( () => content.value, () => { toFather(); } ); const eliminate = () => { content.value = ''; }; return { content, eliminate, ...toRefs(tiny), }; }, }; </script> <style scoped> .tinymce-boxz > textarea { display: none; } </style> <style>
.tox-notifications-container .tox-notification--warning { display: none !important; }
.tox.tox-tinymce { max-width: 100%; } </style>
|