[update 89966] 富文本组件:去掉不能用的功能、解决火狐浏览器格式刷异常、解决显示错位

This commit is contained in:
danshihao
2024-09-18 18:17:10 +08:00
parent 7e4531321c
commit 4b063ce99b
7 changed files with 66 additions and 48 deletions
+28 -11
View File
@@ -1,6 +1,6 @@
<template>
<div>
<script id="editor" type="text/plain" ></script>
<div ref="editorBoxRef">
<script :id="id" type="text/plain" ></script>
</div>
</template>
@@ -35,11 +35,22 @@ export default {
},
getContentLength () {
return this.editor.getContentLength()
},
// 解决火狐浏览器失去焦点后,下次获取焦点,会保留上次光标位置导致格式刷异常
editorBlur (e) {
// e.preventDefault()
e.target.blur()
this.$refs.editorBoxRef.querySelector('iframe').contentDocument.body.blur()
setTimeout(() => {
this.$refs.editorBoxRef.querySelector('iframe').contentDocument.body.blur()
this.$refs.editorBoxRef.querySelector('iframe').contentDocument.body.focus()
}, 100)
}
},
props: {
id: {
type: String
type: String,
default: 'editor'
},
config: {
type: Object
@@ -74,27 +85,33 @@ export default {
}
UEDITOR_CONFIG.UEDITOR_HOME_URL = '../../../public/ueditor/'
// 初始化UE
this.editor = UE.delEditor('editor')
this.editor = UE.getEditor('editor', this.config)
this.editor = UE.delEditor(this.id)
this.editor = UE.getEditor(this.id, this.config)
const _this = this
UE.getEditor('editor').addListener('blur', function (editor) {
UE.getEditor(this.id).addListener('blur', function (editor) {
_this.$emit('editor-onChange', _this.getUEContent())
})
UE.getEditor('editor').ready(function () {
UE.getEditor(this.id).ready(() => {
console.log('aaa', UE.getEditor(this.id))
// 火狐浏览器格式刷会有问题,让页面失去焦点解决该问题
UE.getEditor(this.id).body.addEventListener('blur', this.editorBlur)
if (_this.fontfamily !== '') {
UE.getEditor('editor').execCommand('fontfamily', _this.fontfamily)
UE.getEditor(this.id).execCommand('fontfamily', _this.fontfamily)
}
if (_this.content !== '') {
UE.getEditor('editor').setContent(_this.content)
UE.getEditor(this.id).setContent(_this.content)
}
if (_this.fontsize !== '') {
UE.getEditor('editor').execCommand('fontsize', _this.fontsize)
UE.getEditor(this.id).execCommand('fontsize', _this.fontsize)
}
if (_this.bold) {
UE.getEditor('editor').execCommand('bold')
UE.getEditor(this.id).execCommand('bold')
}
})
},
beforeDestroy () {
UE.getEditor(this.id).removeEventListener('blur', this.editorBlur)
},
destoryed () {
this.editor.destory()
}