Browse Source

富文本处理

test
Enzo 4 years ago
parent
commit
4ea5197b80
  1. 22
      pages/message/detail.vue
  2. 22
      pages/notice/article.vue
  3. 22
      pages/notice/notice.vue

22
pages/message/detail.vue

@ -13,7 +13,7 @@
</view>
</view>
</view>
<rich-text :nodes="content" v-if="$isRight(content)"></rich-text>
<rich-text :nodes="formatRichText(content)" v-if="$isRight(content)"></rich-text>
<lf-nocontent v-else></lf-nocontent>
<!-- 回到顶部 -->
<u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
@ -36,6 +36,26 @@
}
},
methods: {
//
formatRichText(richText){
if(richText != null){
let newRichText= richText.replace(/<img[^>]*>/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(/<br[^>]*\/>/gi, '');
newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
return newRichText;
}else{
return null;
}
},
getData(){
this.$http(this.API.API_MESSAGEDETAILS,{id: this.news_id}).then(res => {
this.content = res.data?.content;

22
pages/notice/article.vue

@ -14,7 +14,7 @@
</view>
</view>
</view>
<rich-text :nodes="content" v-if="content"></rich-text>
<rich-text :nodes="formatRichText(content)" v-if="content"></rich-text>
<lf-nocontent v-else></lf-nocontent>
</view>
<!-- 活动列表 -->
@ -63,6 +63,26 @@
}
},
methods: {
//
formatRichText(richText){
if(richText != null){
let newRichText= richText.replace(/<img[^>]*>/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(/<br[^>]*\/>/gi, '');
newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
return newRichText;
}else{
return null;
}
},
getData(){
this.$http(this.API.API_FINDARTICLEDETAILS,{id: this.article_id}).then(res => {
this.content = res.data?.content;

22
pages/notice/notice.vue

@ -13,7 +13,7 @@
</view>
</view>
</view>
<rich-text :nodes="content" v-if="content"></rich-text>
<rich-text :nodes="formatRichText(content)" v-if="content"></rich-text>
<lf-nocontent v-else></lf-nocontent>
<!-- 回到顶部 -->
<u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
@ -36,6 +36,26 @@
}
},
methods: {
//
formatRichText(richText){
if(richText != null){
let newRichText= richText.replace(/<img[^>]*>/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(/<br[^>]*\/>/gi, '');
newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
return newRichText;
}else{
return null;
}
},
getData(){
this.$http(this.API.API_NOTICEDETAILS,{id:this.notice_id}).then(res => {
this.content = res.data?.content;

Loading…
Cancel
Save