dataease/frontend/src/components/canvas/custom-component/DeRichText.vue

207 lines
6.5 KiB
Vue
Raw Normal View History

2021-07-01 12:12:43 +08:00
<template>
2022-05-20 20:16:29 +08:00
<div class="rich-main-class" @dblclick="setEdit">
2021-07-01 12:12:43 +08:00
<Editor
2022-05-20 20:16:29 +08:00
v-if="editShow"
2021-07-01 12:12:43 +08:00
:id="tinymceId"
v-model="myValue"
2022-05-19 14:00:00 +08:00
style="width: 100%;height: 100%"
2021-07-01 12:12:43 +08:00
:init="init"
2022-05-20 20:16:29 +08:00
:disabled="!canEdit"
2021-07-01 12:12:43 +08:00
@onClick="onClick"
/>
2022-05-19 14:00:00 +08:00
</div>
2021-07-01 12:12:43 +08:00
</template>
<script>
import tinymce from 'tinymce/tinymce' // tinymce默认hidden不引入不显示
import Editor from '@tinymce/tinymce-vue'// 编辑器引入
import 'tinymce/themes/silver/theme'// 编辑器主题
import 'tinymce/icons/default' // 引入编辑器图标icon不引入则不显示对应图标
// 引入编辑器插件(基本免费插件都在这儿了)
import 'tinymce/plugins/advlist' // 高级列表
import 'tinymce/plugins/autolink' // 自动链接
import 'tinymce/plugins/link' // 超链接
import 'tinymce/plugins/image' // 插入编辑图片
import 'tinymce/plugins/lists' // 列表插件
import 'tinymce/plugins/charmap' // 特殊字符
import 'tinymce/plugins/media' // 插入编辑媒体
import 'tinymce/plugins/wordcount'// 字数统计
2022-05-19 14:00:00 +08:00
import 'tinymce/plugins/table'// 表格
2022-05-20 20:16:29 +08:00
import 'tinymce/plugins/contextmenu'// contextmenu
import 'tinymce/plugins/directionality'
import 'tinymce/plugins/nonbreaking'
import 'tinymce/plugins/pagebreak'
2022-05-19 14:00:00 +08:00
import { mapState } from 'vuex'
2021-07-01 12:12:43 +08:00
// const fonts = [
// '宋体=宋体',
// '微软雅黑=微软雅黑',
// '新宋体=新宋体',
// '黑体=黑体',
// '楷体=楷体',
// '隶书=隶书',
// 'Courier New=courier new,courier',
// 'AkrutiKndPadmini=Akpdmi-n',
// 'Andale Mono=andale mono,times',
// 'Arial=arial,helvetica,sans-serif',
// 'Arial Black=arial black,avant garde',
// 'Book Antiqua=book antiqua,palatino',
// 'Comic Sans MS=comic sans ms,sans-serif',
// 'Courier New=courier new,courier',
// 'Georgia=georgia,palatino',
// 'Helvetica=helvetica',
// 'Impact=impact,chicago',
// 'Symbol=symbol',
// 'Tahoma=tahoma,arial,helvetica,sans-serif',
// 'Terminal=terminal,monaco',
// 'Times New Roman=times new roman,times',
// 'Trebuchet MS=trebuchet ms,geneva',
// 'Verdana=verdana,geneva',
// 'Webdings=webdings',
// 'Wingdings=wingdings,zapf dingbats'
// ]
export default {
2022-05-19 14:00:00 +08:00
name: 'DeRichText',
2021-07-01 12:12:43 +08:00
components: {
Editor
},
props: {
2022-05-19 14:00:00 +08:00
propValue: {
type: String,
require: true
},
element: {
type: Object
},
editMode: {
2021-07-01 12:12:43 +08:00
type: String,
2022-05-19 14:00:00 +08:00
require: false,
default: 'preview'
},
active: {
type: Boolean,
require: false,
default: false
2021-07-01 12:12:43 +08:00
},
// 是否禁用
disabled: {
type: Boolean,
default: false
}
},
data() {
return {
2022-05-20 20:16:29 +08:00
editShow: true,
2022-05-19 14:00:00 +08:00
canEdit: false,
2021-07-01 12:12:43 +08:00
// 初始化配置
tinymceId: 'tinymce-' + this.element.id,
2022-05-19 14:00:00 +08:00
myValue: this.propValue,
2021-07-01 12:12:43 +08:00
init: {
selector: '#tinymce-' + this.element.id,
2021-07-01 12:12:43 +08:00
toolbar_items_size: 'small',
language_url: '/tinymce/langs/zh_CN.js', // 汉化路径是自定义的一般放在public或static里面
language: 'zh_CN',
skin_url: '/tinymce/skins/ui/oxide', // 皮肤
content_css: '/tinymce/skins/content/default/content.css',
2022-05-20 20:16:29 +08:00
plugins: 'advlist autolink link image lists charmap media wordcount table contextmenu directionality pagebreak', // 插件
2021-07-01 12:12:43 +08:00
// 工具栏
2022-05-20 20:16:29 +08:00
// toolbar: 'undo redo | fontsizeselect fontselect | bold italic forecolor backcolor underline strikethrough | alignleft aligncenter alignright | lists image media table link | bullist numlist ',
2022-05-25 17:51:19 +08:00
toolbar: 'undo redo |formatselect fontselect fontsizeselect forecolor backcolor bold italic underline strikethrough link | ' +
2022-05-20 20:16:29 +08:00
'alignleft aligncenter alignright | bullist numlist |' +
' blockquote subscript superscript removeformat | table image media | fullscreen ' +
'| bdmap indent2em lineheight formatpainter axupimgs',
2021-07-01 12:12:43 +08:00
toolbar_location: '/',
2022-05-25 17:51:19 +08:00
font_formats: '微软雅黑=Microsoft YaHei;宋体=SimSun;黑体=SimHei;仿宋=FangSong;华文黑体=STHeiti;华文楷体=STKaiti;华文宋体=STSong;华文仿宋=STFangsong;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings',
2021-07-01 12:12:43 +08:00
fontsize_formats: '12px 14px 16px 18px 20px 22px 24px 28px 32px 36px 48px 56px 72px', // 字体大小
menubar: false,
2022-05-19 14:00:00 +08:00
placeholder: '双击输入文字',
inline: true, // 开启内联模式
2021-07-01 12:12:43 +08:00
branding: false
}
}
},
2022-05-19 14:00:00 +08:00
computed: {
editStatus() {
return this.editMode === 'edit' && !this.mobileLayoutStatus
},
...mapState([
'mobileLayoutStatus'
])
},
2021-07-01 12:12:43 +08:00
watch: {
// 监听内容变化
2022-05-19 14:00:00 +08:00
active(val) {
if (!val) {
this.canEdit = false
this.reShow()
2022-05-19 14:00:00 +08:00
}
},
// 监听内容变化
propValue(newValue) {
2021-07-01 12:12:43 +08:00
this.myValue = (newValue == null ? '' : newValue)
},
myValue(newValue) {
2022-05-19 14:00:00 +08:00
this.element.propValue = newValue
this.$store.state.styleChangeTimes++
2021-07-01 12:12:43 +08:00
}
},
mounted() {
tinymce.init({})
},
methods: {
onClick(e) {
this.$emit('onClick', e, tinymce)
},
2022-05-19 14:00:00 +08:00
setEdit() {
2022-05-20 20:16:29 +08:00
if (this.editStatus) {
this.canEdit = true
this.element.editing = true
this.reShow()
2022-05-20 20:16:29 +08:00
}
},
reShow() {
this.editShow = false
this.$nextTick(() => {
this.editShow = true
})
2021-07-01 12:12:43 +08:00
}
}
}
</script>
2022-05-19 14:00:00 +08:00
<style lang="scss" scoped>
.rich-main-class {
width: 100%;
height: 100%;
overflow-y: auto!important;
}
::-webkit-scrollbar {
width: 0px!important;
height: 0px!important;
}
2022-05-20 20:16:29 +08:00
::v-deep ol {
display: block!important;
list-style-type: decimal;
margin-block-start: 1em!important;
margin-block-end: 1em!important;
margin-inline-start: 0px!important;
margin-inline-end: 0px!important;
padding-inline-start: 40px!important;
}
::v-deep ul {
display: block!important;
list-style-type: disc;
margin-block-start: 1em!important;
margin-block-end: 1em!important;
margin-inline-start: 0px!important;
margin-inline-end: 0px!important;
padding-inline-start: 40px!important;
}
::v-deep li {
display: list-item!important;
text-align: -webkit-match-parent!important;
}
2022-05-19 14:00:00 +08:00
</style>