This commit is contained in:
2025-02-14 16:19:10 +08:00
parent 8f08c747b8
commit 691ec823e7
4 changed files with 72 additions and 57 deletions

View File

@@ -496,19 +496,15 @@ export default {
},
async getContent(type, content) {
console.log('content at line 498:', content)
if (type == 'content') {
// 使用正则表达式移除所有不允许的标签
// 1. 移除不允许的标签
content = content.replace(/<(?!\/?(img|b|i|sub|sup|span|strong|em |blue)\b)[^>]+>/g, '');
// 2. 移除所有 style 属性
content = content.replace(/\s*style="[^"]*"/g, '');
// 3. 将 <strong> 转换为 <b><em> 转换为 <i>
var div = document.createElement('div');
div.innerHTML = content; // 将 HTML 字符串加载到 div 中
// 替换所有 <strong> 为 <b>
var strongTags = div.getElementsByTagName('strong');
for (var i = 0; i < strongTags.length; i++) {
@@ -516,7 +512,6 @@ export default {
bTag.innerHTML = strongTags[i].innerHTML; // 保留内容
strongTags[i].parentNode.replaceChild(bTag, strongTags[i]);
}
// 替换所有 <em> 为 <i>
var emTags = div.getElementsByTagName('em');
for (var i = 0; i < emTags.length; i++) {
@@ -529,14 +524,6 @@ export default {
content = div.innerHTML;
console.log('content at line 486:', content);
// // 4. 去除多余的空格:替换连续的空格、换行符、制表符等
// content = content.replace(/\s+/g, ' ').trim(); // 将多个空白字符替换为一个空格,并去除前后空白
// // 5. 去除标签之间的空格
// content = content.replace(/>\s+</g, '><'); // 去除标签之间的空格
// 6. 如果需要,还可以去除 <span> 标签内部的空格
// content = content.replace(/<span[^>]*>\s*([^<]+)\s*<\/span>/g, '<span>$1</span>'); // 清理 <span> 标签内部的空格
this.saveContent(content, this.currentContent.am_id);
} else if (type == 'table') {
@@ -544,6 +531,30 @@ export default {
} else if (type == 'comment') {
this.addComment(content);
}
},
async saveContent(content, am_id) {
var that = this;
var str = content.replace(/^<p>(.*?)<\/p>$/, '$1') ? content.replace(/^<p>(.*?)<\/p>$/, '$1') : '';
if (str == '') {
this.$message({
type: 'warning',
message: 'Please enter the content!'
});
}
str= await that.$commonJS.decodeHtml(str)
await that.$api
.post(that.urlList.editContent, {
am_id: am_id,
content: str
})
.then(async (res) => {
if (res.code == 0) {
this.editVisible = false;
this.getDate();
this.getCommentList();
}
});
},
deleteComment(comment, index) {
console.log('comment at line 480:', comment);
@@ -571,28 +582,7 @@ export default {
.catch(() => {});
}
},
async saveContent(content, am_id) {
var that = this;
var str = content.replace(/^<p>(.*?)<\/p>$/, '$1') ? content.replace(/^<p>(.*?)<\/p>$/, '$1') : '';
if (str == '') {
this.$message({
type: 'warning',
message: 'Please enter the content!'
});
}
await that.$api
.post(that.urlList.editContent, {
am_id: am_id,
content: str
})
.then(async (res) => {
if (res.code == 0) {
this.editVisible = false;
this.getDate();
this.getCommentList();
}
});
},
async huifu(id) {
var that = this;
await this.$confirm(this.$t('commonTable.reContent'), 'Prompt', {
@@ -972,6 +962,7 @@ export default {
}
},
updateChange(content, type) {
console.log('content at line 976:', content)
var str = this.$commonJS.transformHtmlString(content);
if (type == 'imgNote') {
this.picStyle.note = str;
@@ -1014,7 +1005,9 @@ export default {
this.lineStyle.visiTitle = 'Edit Table';
this.threeVisible = true;
} else {
data.content = data.content.replace(/<span[^>]*>/g, '').replace(/<\/span>/g, ''); // 去除span标签
this.currentContent = data;
this.editVisible = true;
this.currentId = dataId;
}
@@ -1337,15 +1330,16 @@ export default {
},
// 确定保存图片
savePic() {
async savePic() {
this.picStyle.picUrl;
var str=this.picStyle.note
str= await this.$commonJS.decodeHtml(str)
if (this.picStyle.visiTitle == 'Edit Figure') {
this.$api
.post(this.urlList.editImage, {
ami_id: this.picStyle.ami_id,
url: this.picStyle.picUrl,
note: this.picStyle.note
note:str
})
.then((res) => {
if (res.code == 0) {
@@ -1397,9 +1391,16 @@ export default {
this.$refs.tinymceChildComment.getContent('comment');
});
},
saveTable(content) {
async saveTable(content) {
console.log('content at line 998:', content);
var strTitle=this.lineStyle.title
strTitle= await this.$commonJS.decodeHtml(strTitle)
var strNote=this.lineStyle.note
if(strNote!=''){
strNote= await this.$commonJS.decodeHtml(strNote)
}
if (content && content.table && content.table.length > 0) {
if (this.lineStyle.visiTitle == 'Edit Table') {
this.$api
@@ -1407,8 +1408,8 @@ export default {
amt_id: this.lineStyle.amt_id,
table_data: JSON.stringify(content.table),
html_data: content.html_data,
note: this.lineStyle.note,
title: this.lineStyle.title
note: strNote,
title: strTitle
})
.then((res) => {
if (res.code == 0) {

View File

@@ -1149,6 +1149,7 @@ export default {
},
// 文章html弹出层
async htmlContet(e) {
console.log('e at line 1151:', e)
this.htmlContent=''
this.articleId = e.article_id;
this.tg_article_id = e.tg_article_id;

View File

@@ -421,7 +421,8 @@ export default {
if (_this.isAutomaticUpdate) {
_this.$emit('updateChange', _this.$commonJS.decodeHtml(currentContent));
// _this.$emit('updateChange', _this.$commonJS.decodeHtml(currentContent));
_this.$emit('updateChange',currentContent);
}
});
@@ -510,13 +511,14 @@ export default {
//获取内容
async getContent(type) {
var content = window.tinymce.get(this.tinymceId).getContent();
content= await this.$commonJS.decodeHtml(content)
content = content.replace(/<span[^>]*>/g, '').replace(/<\/span>/g, ''); // 去除span标签
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; 替换为空格
this.$emit('getContent', type, content);
console.log('window.tinymce.get(this.tinymceId).getContent() at line 431:', content);
this.$emit('getContent', type, content);
},
async export(type, data) {