|
@@ -286,6 +286,25 @@
|
|
|
// 处理富文本
|
|
|
formatRichText(html) {
|
|
|
if (html) {
|
|
|
+ html = html.replace(/<table[^>]*>/gi, match => {
|
|
|
+ // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
|
|
|
+ return match.replace(/style="[^"]+"/gi, `style="border-collapse: collapse; width: 100%;"`)
|
|
|
+ .replace(/<table/gi, `<table style="border-collapse: collapse; width: 100%;"`);
|
|
|
+ });
|
|
|
+ html = html.replace(/<th[^>]*>/gi, match => {
|
|
|
+ // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
|
|
|
+ return match.replace(/style="[^"]+"/gi,
|
|
|
+ `style="border: 1px solid #ddd; padding: 8px; background-color: #f2f2f2;"`)
|
|
|
+ .replace(/<table/gi,
|
|
|
+ `<table style="border: 1px solid #ddd; padding: 8px; background-color: #f2f2f2;"`);
|
|
|
+ });
|
|
|
+ html = html.replace(/<td[^>]*>/gi, match => {
|
|
|
+ // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
|
|
|
+ return match.replace(/style="[^"]+"/gi,
|
|
|
+ `style="border: 1px solid #ddd; padding: 8px;"`)
|
|
|
+ .replace(/<table/gi,
|
|
|
+ `<table style="border: 1px solid #ddd; padding: 8px;"`);
|
|
|
+ });
|
|
|
// 富文本内容格式化
|
|
|
return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
|
|
|
// 查找所有的 img 元素
|
|
@@ -294,7 +313,7 @@
|
|
|
// 删除找到的所有 img 元素中的 style 属性
|
|
|
}).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
</script>
|