2022-04-26 13:51:46 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div class="tinymce-editor">
|
|
|
|
|
<editor
|
|
|
|
|
v-if="!reloading"
|
|
|
|
|
v-model="myValue"
|
|
|
|
|
:init="init"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
@onClick="onClick">
|
|
|
|
|
</editor>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import tinymce from 'tinymce/tinymce'
|
|
|
|
|
import Editor from '@tinymce/tinymce-vue'
|
|
|
|
|
import 'tinymce/themes/silver/theme'
|
|
|
|
|
import 'tinymce/plugins/image'
|
2024-03-18 14:29:38 +08:00
|
|
|
|
//import 'tinymce/plugins/link'
|
|
|
|
|
import '@/components/jeecg/tinymce/plugins/link2'
|
2022-04-26 13:51:46 +08:00
|
|
|
|
import 'tinymce/plugins/media'
|
|
|
|
|
import 'tinymce/plugins/table'
|
|
|
|
|
import 'tinymce/plugins/lists'
|
|
|
|
|
import 'tinymce/plugins/contextmenu'
|
|
|
|
|
import 'tinymce/plugins/wordcount'
|
|
|
|
|
import 'tinymce/plugins/colorpicker'
|
|
|
|
|
import 'tinymce/plugins/textcolor'
|
|
|
|
|
import 'tinymce/plugins/fullscreen'
|
|
|
|
|
import 'tinymce/icons/default'
|
|
|
|
|
import { uploadAction,getFileAccessHttpUrl } from '@/api/manage'
|
|
|
|
|
import { getVmParentByName } from '@/utils/util'
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
Editor
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
value: {
|
|
|
|
|
type: String,
|
|
|
|
|
required:false
|
|
|
|
|
},
|
|
|
|
|
triggerChange:{
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
required:false
|
|
|
|
|
},
|
|
|
|
|
disabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
plugins: {
|
|
|
|
|
type: [String, Array],
|
|
|
|
|
default: 'lists image link media table textcolor wordcount contextmenu fullscreen'
|
|
|
|
|
},
|
|
|
|
|
toolbar: {
|
|
|
|
|
type: [String, Array],
|
2022-07-05 14:56:18 +08:00
|
|
|
|
default: ["undo redo save | cut copy paste | forecolor backcolor bold italic underline strikethrough link unlink " +
|
|
|
|
|
"openlink anchor | alignleft aligncenter alignright alignjustify alignnone outdent indent | " +
|
|
|
|
|
"bullist numlist ",
|
|
|
|
|
"styleselect formatselect fontselect fontsizeselect | table tabledelete tablecellprops tablemergecells| blockquote subscript superscript removeformat | ltr rtl " +
|
|
|
|
|
"tablesplitcells tableinsertrowbefore tableinsertrowafter tabledeleterow tablerowprops tablecutrow " +
|
|
|
|
|
"tablecopyrow tablepasterowbefore tablepasterowafter tableinsertcolbefore tableinsertcolafter tabledeletecol | " +
|
2024-03-18 14:29:38 +08:00
|
|
|
|
"image media fullscreen lineheight",
|
2022-07-05 14:56:18 +08:00
|
|
|
|
"insertdatetime charmap emoticons hr pagebreak template code pastetext print visualblocks visualchars " +
|
2024-03-18 14:29:38 +08:00
|
|
|
|
"nonbreaking searchreplace preview kityformula-editor indent2em ",
|
2022-07-05 14:56:18 +08:00
|
|
|
|
],
|
2022-04-26 13:51:46 +08:00
|
|
|
|
branding:false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
//初始化配置
|
|
|
|
|
init: {
|
|
|
|
|
language_url: '/tinymce/langs/zh_CN.js',
|
|
|
|
|
language: 'zh_CN',
|
|
|
|
|
skin_url: '/tinymce/skins/lightgray',
|
2024-03-18 14:29:38 +08:00
|
|
|
|
height: 500,
|
2022-04-26 13:51:46 +08:00
|
|
|
|
plugins: this.plugins,
|
|
|
|
|
toolbar: this.toolbar,
|
2024-03-18 14:29:38 +08:00
|
|
|
|
contextmenu: false,
|
|
|
|
|
//contextmenu_never_use_native: true,
|
|
|
|
|
lineheight_formats: '1 1.1 1.2 1.3 1.4 1.5 2 2.5 3 3.5',
|
2022-04-26 13:51:46 +08:00
|
|
|
|
branding: false,
|
|
|
|
|
menubar: false,
|
|
|
|
|
toolbar_drawer: false,
|
|
|
|
|
images_upload_handler: (blobInfo, success) => {
|
|
|
|
|
let formData = new FormData()
|
|
|
|
|
formData.append('file', blobInfo.blob(), blobInfo.filename());
|
|
|
|
|
formData.append('biz', "jeditor");
|
|
|
|
|
formData.append("jeditor","1");
|
|
|
|
|
uploadAction(window._CONFIG['domianURL']+"/sys/common/upload", formData).then((res) => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
if(res.message == 'local'){
|
|
|
|
|
const img = 'data:image/jpeg;base64,' + blobInfo.base64()
|
|
|
|
|
success(img)
|
|
|
|
|
}else{
|
|
|
|
|
let img = getFileAccessHttpUrl(res.message)
|
|
|
|
|
success(img)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
myValue: this.value,
|
|
|
|
|
reloading: false,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.initATabsChangeAutoReload()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
|
this.reloading = true
|
|
|
|
|
this.$nextTick(() => this.reloading = false)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onClick(e) {
|
|
|
|
|
this.$emit('onClick', e, tinymce)
|
|
|
|
|
},
|
|
|
|
|
//可以添加一些自己的自定义事件,如清空内容
|
|
|
|
|
clear() {
|
|
|
|
|
this.myValue = ''
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 自动判断父级是否是 <a-tabs/> 组件,然后添加事件监听,自动触发reload()
|
|
|
|
|
*
|
|
|
|
|
* 由于 tabs 组件切换会导致 tinymce 无法输入,
|
|
|
|
|
* 只有重新加载才能使用(无论是vue版的还是jQuery版tinymce都有这个通病)
|
|
|
|
|
*/
|
|
|
|
|
initATabsChangeAutoReload() {
|
|
|
|
|
// 获取父级
|
|
|
|
|
let tabs = getVmParentByName(this, 'ATabs')
|
|
|
|
|
let tabPane = getVmParentByName(this, 'ATabPane')
|
|
|
|
|
if (tabs && tabPane) {
|
|
|
|
|
// 用户自定义的 key
|
|
|
|
|
let currentKey = tabPane.$vnode.key
|
|
|
|
|
// 添加事件监听
|
|
|
|
|
tabs.$on('change', (key) => {
|
|
|
|
|
// 切换到自己时执行reload
|
|
|
|
|
if (currentKey === key) {
|
|
|
|
|
this.reload()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
//update--begin--autor:wangshuai-----date:20200724------for:富文本编辑器切换tab无法修改------
|
|
|
|
|
let tabLayout = getVmParentByName(this, 'TabLayout')
|
|
|
|
|
tabLayout.excuteCallback(()=>{
|
|
|
|
|
this.reload()
|
|
|
|
|
})
|
|
|
|
|
//update--begin--autor:wangshuai-----date:20200724------for:文本编辑器切换tab无法修改------
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
value(newValue) {
|
|
|
|
|
this.myValue = (newValue == null ? '' : newValue)
|
|
|
|
|
},
|
|
|
|
|
myValue(newValue) {
|
|
|
|
|
if(this.triggerChange){
|
|
|
|
|
this.$emit('change', newValue)
|
|
|
|
|
}else{
|
|
|
|
|
this.$emit('input', newValue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
2024-03-18 14:29:38 +08:00
|
|
|
|
<style scoped lang="less">
|
|
|
|
|
.tox-sidebar-wrap{
|
|
|
|
|
height: 1600px;
|
|
|
|
|
}
|
2022-04-26 13:51:46 +08:00
|
|
|
|
</style>
|