Commit c5f5ba4c authored by 吴春's avatar 吴春

11

parent 6f8886fe
......@@ -71,6 +71,7 @@
</view>
</view>
<view class="acdetailBottom">
<!-- <rich-text class="newsInDetail_Intro" :nodes="richtext"></rich-text> -->
<view class="newsInDetail_Intro" v-html="richtext"></view>
</view>
</view>
......@@ -109,10 +110,26 @@
if (res.resultCode == 1) {
this.dataList = res.data;
let html = this.dataList.NewsInfo
// 1. 处理图片:强制 max-width:100% (你原有的逻辑)
console.log("html", html);
// 1. 处理图片:优先使用 data-src(懒加载原图),同时强制 max-width:100%
html = html.replace(/<img[^>]*>/gi, function(match) {
return match.replace(/style=\"(.*)\"/gi,
// 优先使用 data-src 的图片地址
const dataSrcMatch = match.match(/data-src=["']([^"']+)["']/);
if (dataSrcMatch) {
const originalUrl = dataSrcMatch[1];
// 移除懒加载参数(tp=webp, wxfrom=5, wx_lazy=1, imgIndex)
const cleanUrl = originalUrl
.replace(/&tp=webp/gi, '')
.replace(/&wxfrom=\d+/gi, '')
.replace(/&wx_lazy=\d+/gi, '')
.replace(/#imgIndex=\d+/gi, '');
// 移除原有的 src 属性,替换为干净的 data-src
match = match.replace(/\s*src=["'][^"']*["']/gi, '');
match = match.replace(/\s*data-src=["'][^"']*["']/gi, '');
return `<img src="${cleanUrl}" style="max-width:100% !important;height:auto;display:block;" />`;
}
// 如果没有 data-src,只处理已有的 src
return match.replace(/style="(.*)"/gi,
'style="max-width:100% !important; height:auto;"');
});
......
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