This commit is contained in:
2025-01-24 15:13:29 +08:00
parent 93c4e4941e
commit 8030ede931
3 changed files with 20 additions and 14 deletions

View File

@@ -18,6 +18,11 @@ const capitalizeFirstLetter = function (text) {
});
};
export default {
decodeHtml(html) {
var txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
},
//去掉最外层自定义的span标签
extractContentWithoutOuterSpan(cell) {
var str = ''

View File

@@ -1,6 +1,5 @@
<template>
<div class="tinymce-container editor-container">
<textarea class="tinymce-textarea" :id="tinymceId"></textarea>
</div>
</template>
@@ -138,9 +137,7 @@ export default {
},
isEdit: {},
toolbar: {
required: false,
required: false
},
menubar: {
default: 'file edit insert view format table '
@@ -269,10 +266,11 @@ export default {
this.$forceUpdate();
},
initTinymce() {
var _this = this;
window.tinymce.init({
inline: false, // 使用 iframe 模式
inline: false, // 使用 iframe 模式
selector: `#${this.tinymceId}`,
content_css: false, // 禁用默认样式
table_resize_bars: true, // 启用拖动调整功能
@@ -357,7 +355,8 @@ export default {
statusbar: false, // 关闭底部状态栏
custom_colors: false,
color_map: ['0082AA', 'TMR Blue'],
plugins: 'forecolor code paste table image mathType searchreplace', // 启用 forecolor 和 code 插件
// plugins: 'forecolor code paste table image mathType searchreplace raw', // 启用 forecolor 和 code 插件
end_container_on_empty_block: true,
content_css: 'default', // 加载 TinyMCE 默认样式表
mathjax: {
@@ -411,18 +410,18 @@ export default {
// callback(menuItems);
// }
// });
ed.on('init', function () {
_this.$commonJS.inTinymceButtonClass();
const editorBody = ed.getBody();
// 创建 MutationObserver 监听内容变化
const observer = new MutationObserver(() => {
const currentContent = ed.getContent();
if (_this.isAutomaticUpdate) {
_this.$emit('updateChange', ed.getContent());
_this.$emit('updateChange', _this.$commonJS.decodeHtml(currentContent));
}
});
@@ -509,8 +508,10 @@ export default {
window.tinymce.get(this.tinymceId).setContent(value);
},
//获取内容
getContent(type) {
async getContent(type) {
var content = window.tinymce.get(this.tinymceId).getContent();
content= await this.$commonJS.decodeHtml(content)
console.log('content at line 513:', content)
content = content.replace(/<strong>/g, '<b>').replace(/<\/strong>/g, '</b>');
content = content.replace(/<em>/g, '<i>').replace(/<\/em>/g, '</i>');
content = content.replace(/&nbsp;/g, ' '); // 将所有 &nbsp; 替换为空格

View File

@@ -723,7 +723,7 @@ export default {
table_resize_bars: true,
image_advtab: false, // 禁用图片高级选项卡(防止自动调整大小)
valid_elements: '*[*]',
entity_encoding: 'raw', // 不编码 > 等字符
plugins: 'forecolor code paste table image resize dragdrop',
menubar: false,
@@ -782,7 +782,7 @@ export default {
table_resize_bars: true,
image_advtab: false, // 禁用图片高级选项卡(防止自动调整大小)
valid_elements: '*[*]',
plugins: 'forecolor code paste table image resize ',
content_style: `${tableStyle + this.wordStyle}
@@ -870,8 +870,8 @@ export default {
image_advtab: false, // 禁用图片高级选项卡(防止自动调整大小)
plugins: 'forecolor code paste table image resize ',
content_style: `${tableStyle + this.wordStyle}
`,
`,entity_encoding: 'raw', // 不编码 > 等字符
menubar: false,
toolbar: _this.isEditComment ? ['commentAdd |delete| addRow|Edit'] : ['delete| addRow|Edit'],
end_container_on_empty_block: true,