noticedetail.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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,getRemindDet} 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. if(this.ptype=='xttz'){
  41. getNoticeDet(id).then(res=>{
  42. if(res.code==200){
  43. this.noticeTitle=res.data.noticeTitle;
  44. this.createTime=res.data.createTime;
  45. if(res.data.noticeContent){
  46. this.infoContent=this.formatRichText(res.data.noticeContent);
  47. }
  48. }
  49. })
  50. }else{
  51. getRemindDet(id).then(res=>{
  52. if(res.code==200){
  53. this.noticeTitle=res.data.remindTitle;
  54. this.createTime=res.data.remindTime;
  55. if(res.data.noticeContent){
  56. this.infoContent=this.formatRichText(res.data.remindContent);
  57. }
  58. }
  59. })
  60. }
  61. },
  62. //解析富文本方法
  63. formatRichText(html) {
  64. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  65. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  66. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  67. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  68. return match;
  69. });
  70. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  71. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  72. return match;
  73. });
  74. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  75. newContent = newContent.replace(/\<img src="/gi,
  76. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +baseUrlimg);
  77. return newContent;
  78. },
  79. }
  80. }
  81. </script>
  82. <style scoped lang="scss">
  83. .detail{height: 100vh;display: flex;flex-direction: column;background-color: #ffffff;
  84. .detbox{flex: 1;padding-top: 20rpx;overflow: auto;z-index: 2;
  85. .detboxa{border-radius: 30rpx 30rpx 0 0; background-color: #ffffff;padding:36rpx 24rpx;
  86. .tit{font-size: 32rpx;color: #321E1E;margin-bottom: 44rpx;}
  87. .txt{font-size: 30rpx;font-weight: bold;color: #321E1E;line-height: 48rpx;padding: 0 22rpx;margin-bottom: 20rpx;}
  88. .time{padding: 0 22rpx;font-size: 24rpx;font-weight: 500;color: #AAAAAA;margin-bottom: 36rpx;}
  89. .dbox{border-top:2rpx solid #E6E6E6;padding: 40rpx 22rpx;
  90. view{
  91. text-indent: 2rem;font-size: 26rpx;color: #321F1B;line-height: 48rpx;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. </style>