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

11

parent 7ada8ee0
......@@ -54,13 +54,14 @@
<view class="newsInDetail" style="height:100vh;">
<view class="acdetailTop">
<view class="acdetaiTitle">
<template v-if="dataList&&dataList.Title">
{{dataList.Title}}
</template>
<template v-if="dataList&&dataList.Title">
{{dataList.Title}}
</template>
</view>
<view class="acdetaiWriter">
<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>
<template v-if="dataList&&dataList.PublishTimeStr">
{{dataList.PublishTimeStr}}
......@@ -85,7 +86,7 @@
},
dataList: {},
richtext: '',
mainColor:''
mainColor: ''
}
},
created() {},
......@@ -106,16 +107,45 @@
},
(res) => {
if (res.resultCode == 1) {
this.dataList = res.data
this.richtext = this.dataList.NewsInfo.replace(/<img[^>]*>/gi, function(match, capture) {
var match = match.replace(/style=\"(.*)\"/gi,
'style="max-width:100% !important"');
return match;
this.dataList = res.data;
let html = this.dataList.NewsInfo
// 1. 处理图片:强制 max-width:100% (你原有的逻辑)
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;
// });
}
}
);
}
}
}
</script>
</script>
\ No newline at end of file
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