noticedetail.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="detail">
  3. <view class="detbox">
  4. <view class="detboxa">
  5. <!-- <view class="tit ffz txc">{{title}}</view> -->
  6. <view class="txt">{{noticeTitle}}</view>
  7. <view class="time"><block v-if="createTime">发布时间: {{createTime}}</block></view>
  8. <view class="dbox">
  9. <rich-text :nodes="infoContent"></rich-text>
  10. </view>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import {getNoticeDet} from "@/api/common.js"
  17. import config from '@/config'
  18. const baseUrlimg=config.baseUrl
  19. export default{
  20. components:{},
  21. data(){
  22. return{
  23. // newsid:'',
  24. // datainfo:'',
  25. // title:"新闻资讯",
  26. infoContent:'',
  27. id:'',
  28. ptype:'',
  29. noticeTitle:'',
  30. createTime:'',
  31. }
  32. },
  33. onLoad(e) {
  34. this.id=e.id;
  35. this.ptype=e.type;
  36. this.getNewsDetail(e.id)
  37. },
  38. methods:{
  39. getNewsDetail(id){
  40. getNoticeDet(id).then(res=>{
  41. if(res.code==200){
  42. this.noticeTitle=res.data.noticeTitle;
  43. this.createTime=res.data.createTime;
  44. if(res.data.noticeContent){
  45. this.infoContent=this.formatRichText(res.data.noticeContent);
  46. }
  47. }
  48. })
  49. },
  50. //解析富文本方法
  51. formatRichText(html) {
  52. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  53. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  54. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  55. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  56. return match;
  57. });
  58. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  59. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  60. return match;
  61. });
  62. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  63. newContent = newContent.replace(/\<img src="/gi,
  64. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +baseUrlimg);
  65. return newContent;
  66. },
  67. }
  68. }
  69. </script>
  70. <style scoped lang="scss">
  71. .detail{height: 100vh;display: flex;flex-direction: column;background-color: #ffffff;
  72. .detbox{flex: 1;padding-top: 20rpx;overflow: auto;z-index: 2;
  73. .detboxa{border-radius: 30rpx 30rpx 0 0; background-color: #ffffff;padding:36rpx 24rpx;
  74. .tit{font-size: 32rpx;color: #321E1E;margin-bottom: 44rpx;}
  75. .txt{font-size: 30rpx;font-weight: bold;color: #321E1E;line-height: 48rpx;padding: 0 22rpx;margin-bottom: 20rpx;}
  76. .time{padding: 0 22rpx;font-size: 24rpx;font-weight: 500;color: #AAAAAA;margin-bottom: 36rpx;}
  77. .dbox{border-top:2rpx solid #E6E6E6;padding: 40rpx 22rpx;
  78. view{
  79. text-indent: 2rem;font-size: 26rpx;color: #321F1B;line-height: 48rpx;
  80. }
  81. }
  82. }
  83. }
  84. }
  85. </style>