Commit 6f8886fe authored by 吴春's avatar 吴春

11

parent 7ada8ee0
...@@ -60,7 +60,8 @@ ...@@ -60,7 +60,8 @@
</view> </view>
<view class="acdetaiWriter"> <view class="acdetaiWriter">
<view> <view>
<u-tag v-if="dataList&&dataList.Industry" :text="dataList.Industry" type="primary" style="margin-right: 12px;"></u-tag> <u-tag v-if="dataList&&dataList.Industry" :text="dataList.Industry" type="primary"
style="margin-right: 12px;"></u-tag>
<text> <text>
<template v-if="dataList&&dataList.PublishTimeStr"> <template v-if="dataList&&dataList.PublishTimeStr">
{{dataList.PublishTimeStr}} {{dataList.PublishTimeStr}}
...@@ -85,7 +86,7 @@ ...@@ -85,7 +86,7 @@
}, },
dataList: {}, dataList: {},
richtext: '', richtext: '',
mainColor:'' mainColor: ''
} }
}, },
created() {}, created() {},
...@@ -106,12 +107,41 @@ ...@@ -106,12 +107,41 @@
}, },
(res) => { (res) => {
if (res.resultCode == 1) { if (res.resultCode == 1) {
this.dataList = res.data this.dataList = res.data;
this.richtext = this.dataList.NewsInfo.replace(/<img[^>]*>/gi, function(match, capture) { let html = this.dataList.NewsInfo
var match = match.replace(/style=\"(.*)\"/gi,
'style="max-width:100% !important"'); // 1. 处理图片:强制 max-width:100% (你原有的逻辑)
return match; html = html.replace(/<img[^>]*>/gi, function(match) {
return match.replace(/style=\"(.*)\"/gi,
'style="max-width:100% !important; height:auto;"');
});
// 2. 处理 table:强制宽度 100%,并移除固定 width 属性
html = html.replace(/<table[^>]*>/gi, function(match) {
// 先移除原有的 width 属性(可能是 width="657" 或 width="100%")
let newMatch = match.replace(/\s*width\s*=\s*["'][^"']*["']/gi, '');
// 再处理 style,添加或覆盖 width:100%
if (/style\s*=\s*["'][^"']*["']/i.test(newMatch)) {
// 已有 style 属性,添加 width:100%
newMatch = newMatch.replace(/style\s*=\s*["']([^"']*)["']/i, function(
styleMatch, styleContent) {
// 如果 style 中已有 width,先移除
styleContent = styleContent.replace(/width\s*:[^;]+;?/gi, '');
return `style="${styleContent}; width:100%;"`;
}); });
} else {
// 没有 style 属性,直接添加
newMatch = newMatch.replace(/<table/, '<table style="width:100%;"');
}
return newMatch;
});
this.richtext = html;
// this.richtext = this.dataList.NewsInfo.replace(/<img[^>]*>/gi, function(match, capture) {
// var match = match.replace(/style=\"(.*)\"/gi,
// 'style="max-width:100% !important"');
// return match;
// });
} }
} }
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment