From 4ea5197b8013f315d7989303347ea8cf06251940 Mon Sep 17 00:00:00 2001 From: Enzo <1284707383@qq.com> Date: Wed, 15 Sep 2021 09:46:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/message/detail.vue | 22 +++++++++++++++++++++- pages/notice/article.vue | 22 +++++++++++++++++++++- pages/notice/notice.vue | 22 +++++++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/pages/message/detail.vue b/pages/message/detail.vue index 950b102..79130df 100644 --- a/pages/message/detail.vue +++ b/pages/message/detail.vue @@ -13,7 +13,7 @@ - + @@ -36,6 +36,26 @@ } }, methods: { + // 富文本处理 + formatRichText(richText){ + if(richText != null){ + let newRichText= richText.replace(/]*>/gi, function(match, capture){ + match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); + match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); + match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); + return match; + }); + newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){ + match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;'); + return match; + }); + newRichText = newRichText.replace(/]*\/>/gi, ''); + newRichText = newRichText.replace(/\ { this.content = res.data?.content; diff --git a/pages/notice/article.vue b/pages/notice/article.vue index cbf7d58..a9c42ca 100644 --- a/pages/notice/article.vue +++ b/pages/notice/article.vue @@ -14,7 +14,7 @@ - + @@ -63,6 +63,26 @@ } }, methods: { + // 富文本处理 + formatRichText(richText){ + if(richText != null){ + let newRichText= richText.replace(/]*>/gi, function(match, capture){ + match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); + match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); + match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); + return match; + }); + newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){ + match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;'); + return match; + }); + newRichText = newRichText.replace(/]*\/>/gi, ''); + newRichText = newRichText.replace(/\ { this.content = res.data?.content; diff --git a/pages/notice/notice.vue b/pages/notice/notice.vue index 18f6ed1..a568967 100644 --- a/pages/notice/notice.vue +++ b/pages/notice/notice.vue @@ -13,7 +13,7 @@ - + @@ -36,6 +36,26 @@ } }, methods: { + // 富文本处理 + formatRichText(richText){ + if(richText != null){ + let newRichText= richText.replace(/]*>/gi, function(match, capture){ + match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); + match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); + match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); + return match; + }); + newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){ + match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;'); + return match; + }); + newRichText = newRichText.replace(/]*\/>/gi, ''); + newRichText = newRichText.replace(/\ { this.content = res.data?.content;