1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <template> <div class="richtext-container"> <Editor id="myedit" v-model="content" :init="initProps" :disabled="readonly" /> </div> </template>
<script setup lang="ts"> import {reactive, ref, onMounted, watch, watchEffect} from 'vue' import tinymce from 'tinymce/tinymce' import Editor from '@tinymce/tinymce-vue' import QiniuUpload from '@/utils/qnUpload'
import "tinymce/themes/silver" import "tinymce/icons/default" import "tinymce/icons/default/icons"
import 'tinymce/plugins/image' import 'tinymce/plugins/paste'
const props = defineProps({ modelValue:{ type: String, default: "" }, height:{ type: Number, default: 278 }, readonly:{ type: Boolean, default: true } }) const emits = defineEmits(['update:modelValue']) let content = ref() const initProps = reactive({ selector: '#myedit', readonly: props.readonly, height: props.height, resize: false, language_url: "/tinymce/langs/zh-Hans.js", language: "zh-Hans", skin_url: "/tinymce/skins/ui/custom", content_css: '/tinymce/skins/ui/custom/content.min.css', branding: false, menubar: false, toolbar_sticky: true, toolbar_groups: false, elementpath: false, toolbar: `undo redo bold italic underline strikethrough removeformat subscript superscript | alignleft aligncenter alignright alignjustify outdent indent | paste image`, plugins: 'image paste', paste_data_images: true, images_upload_handler: async(blobInfo:any, succFun:any, failFun:any)=>{ let file = blobInfo.blob() try { const data:any = await QiniuUpload(file,'image','xxx') succFun(data?.real_url) } catch (error) { failFun(error) } }, })
onMounted(() => {tinymce.init({})})
watchEffect(()=>{ content.value = props.modelValue }) watch(content,()=>{ updateData() })
const updateData = ()=>{ emits('update:modelValue',content.value) } </script>
<style lang="less" scoped> .richtext-container{ :deep(.tox){ .tox-statusbar{ display: none; } } } </style>
|