|
1
2
3
|
<template>
<div class="tinymce-editor">
<editor
|
|
4
|
v-if="!reloading"
|
|
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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'
|
|
18
|
import 'tinymce/plugins/link'
|
|
19
20
21
22
23
24
25
|
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'
|
|
26
|
import 'tinymce/plugins/fullscreen'
|
|
27
|
import 'tinymce/icons/default'
|
|
28
|
import { uploadAction,getFileAccessHttpUrl } from '@/api/manage'
|
|
29
|
import { getVmParentByName } from '@/utils/util'
|
|
30
31
32
33
34
35
36
37
38
|
export default {
components: {
Editor
},
props: {
value: {
type: String,
required:false
},
|
|
39
40
41
42
43
|
triggerChange:{
type: Boolean,
default: false,
required:false
},
|
|
44
45
46
47
48
49
|
disabled: {
type: Boolean,
default: false
},
plugins: {
type: [String, Array],
|
|
50
|
default: 'lists image link media table textcolor wordcount contextmenu fullscreen'
|
|
51
52
53
|
},
toolbar: {
type: [String, Array],
|
|
54
55
|
default: 'undo redo | formatselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists link unlink image media table | removeformat | fullscreen',
branding:false
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
}
},
data() {
return {
//初始化配置
init: {
language_url: '/tinymce/langs/zh_CN.js',
language: 'zh_CN',
skin_url: '/tinymce/skins/lightgray',
height: 300,
plugins: this.plugins,
toolbar: this.toolbar,
branding: false,
menubar: false,
|
|
70
|
toolbar_drawer: false,
|
|
71
|
images_upload_handler: (blobInfo, success) => {
|
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
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)
}
}
})
|
|
87
88
|
}
},
|
|
89
90
|
myValue: this.value,
reloading: false,
|
|
91
92
93
|
}
},
mounted() {
|
|
94
|
this.initATabsChangeAutoReload()
|
|
95
96
97
|
},
methods: {
|
|
98
99
100
101
102
|
reload() {
this.reloading = true
this.$nextTick(() => this.reloading = false)
},
|
|
103
104
105
106
107
108
|
onClick(e) {
this.$emit('onClick', e, tinymce)
},
//可以添加一些自己的自定义事件,如清空内容
clear() {
this.myValue = ''
|
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
},
/**
* 自动判断父级是否是 <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()
}
})
|
|
131
132
133
|
//update--begin--autor:liusq-----date:20210316------for:富文本编辑器tab父组件可能导致的赋值问题------
this.reload()
//update--end--autor:liusq-----date:20210316------for:富文本编辑器tab父组件可能导致的赋值问题------
|
|
134
135
136
|
}else{
//update--begin--autor:wangshuai-----date:20200724------for:富文本编辑器切换tab无法修改------
let tabLayout = getVmParentByName(this, 'TabLayout')
|
|
137
138
139
140
141
142
143
144
145
146
147
|
//update--begin--autor:liusq-----date:20210713------for:处理特殊情况excuteCallback不能使用------
try {
tabLayout.excuteCallback(() => {
this.reload()
})
} catch (error) {
if (tabLayout) {
this.reload()
}
}
//update--end--autor:liusq-----date:20210713------for:处理特殊情况excuteCallback不能使用------
|
|
148
|
//update--begin--autor:wangshuai-----date:20200724------for:文本编辑器切换tab无法修改------
|
|
149
150
151
|
}
},
|
|
152
153
154
|
},
watch: {
value(newValue) {
|
|
155
|
this.myValue = (newValue == null ? '' : newValue)
|
|
156
157
|
},
myValue(newValue) {
|
|
158
159
160
161
162
|
if(this.triggerChange){
this.$emit('change', newValue)
}else{
this.$emit('input', newValue)
}
|
|
163
164
165
166
167
168
169
|
}
}
}
</script>
<style scoped>
</style>
|