detail.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="detail main-bg">
  3. <view class="title font-thirty font-color3">
  4. {{list.noticeTitle}}
  5. </view>
  6. <view class="time font-twenty-four font-color4">
  7. <span class="padding">创建时间: {{list.createTime}}</span><span>创建人: {{list.createBy}}</span>
  8. </view>
  9. <image class="header-img" src="/static/img.png"></image>
  10. <!-- <view class="content">{{list.content}}</view> -->
  11. <view style="width:100%; overflow: hidden;">
  12. <rich-text :nodes="noticeContent"></rich-text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import server from "@/api/index";
  18. export default {
  19. data() {
  20. return {
  21. id: null,
  22. noticeContent: null,
  23. list:{},
  24. }
  25. },
  26. onLoad(e) {
  27. console.log(e);
  28. this.id = e.id;
  29. this.getListFn();
  30. },
  31. methods: {
  32. formatRichText(html){
  33. let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
  34. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  35. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  36. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  37. return match;
  38. });
  39. newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
  40. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  41. return match;
  42. });
  43. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  44. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"');
  45. return newContent;
  46. },
  47. getListFn(){
  48. let that = this;
  49. server.getNewsInfo(this.id).then(res =>{
  50. if(res){
  51. this.list = res;
  52. console.log('res.noticeContent', res.noticeContent)
  53. this.noticeContent = this.formatRichText(res.noticeContent);
  54. console.log("999", this.noticeContent)
  55. }else{
  56. this.list={
  57. url: '',
  58. noticeTitle: '',
  59. createTime: '',
  60. createBy: '',
  61. noticeContent: ''
  62. }
  63. }
  64. })
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .detail{
  71. width: 100%;
  72. padding: 30rpx;
  73. min-height: 100vh;
  74. height: auto;
  75. .title{
  76. letter-spacing: 2rpx;
  77. font-weight: 550;
  78. }
  79. .time{
  80. height: 93rpx;
  81. line-height: 93rpx;
  82. .padding{
  83. padding-right: 30rpx;
  84. }
  85. }
  86. .header-img{
  87. width: 100%;
  88. height: 360rpx;
  89. margin-bottom: 30rpx;
  90. border-radius: 24rpx;
  91. }
  92. }
  93. </style>