index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view>
  3. <JHeader title="公告详情" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view class="messageDetail">
  5. <h3 class="detailTit">{{ messageDateils.noticeTitle }}</h3>
  6. <view v-if="messageDateils.createTime" class="detailTime">时间:{{ messageDateils.createTime }}</view>
  7. <view class="detailInfo">
  8. <rich-text :nodes="htmlData"></rich-text>
  9. <img :src="common.seamingImgUrl(messageDateils.image)" alt="">
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import parse from 'mini-html-parser2'
  16. import { getByIdNoticeMessageDateilsApi, updateReadNoticeApi } from '../../../api/anotherTFInterface'
  17. export default {
  18. name: 'MessageDetail',
  19. data() {
  20. return {
  21. onlyid: 0,
  22. messageDateils: {},
  23. htmlData: []
  24. }
  25. },
  26. onShow() {
  27. this.getNotice()
  28. },
  29. onLoad(options) {
  30. this.onlyid = options.noticeId
  31. this.getNotice()
  32. },
  33. methods: {
  34. formatRichText(html) {
  35. let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
  36. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
  37. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
  38. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
  39. return match
  40. })
  41. newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
  42. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(
  43. /width:[^;]+;/gi,
  44. 'max-width:100%;'
  45. )
  46. return match
  47. })
  48. newContent = newContent.replace(/<br[^>]*\/>/gi, '')
  49. newContent = newContent.replace(
  50. /\<img/gi,
  51. '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
  52. )
  53. return newContent
  54. },
  55. gitMassageDateils() {
  56. getByIdNoticeMessageDateilsApi({
  57. noticeId: this.onlyid
  58. }).then((res) => {
  59. this.messageDateils = res.data
  60. this.messageDateils.noticeContent = this.formatRichText(this.messageDateils.noticeContent)
  61. parse(this.messageDateils.noticeContent, (err, htmlData) => {
  62. this.htmlData = htmlData
  63. })
  64. uni.hideLoading()
  65. })
  66. .catch((e) => {
  67. uni.hideLoading()
  68. })
  69. },
  70. getNotice() {
  71. // uni.showLoading({
  72. // title: '加载中...',
  73. // })
  74. updateReadNoticeApi({
  75. noticeId: this.onlyid
  76. }).then((res) => {
  77. uni.hideLoading()
  78. this.gitMassageDateils()
  79. })
  80. .catch((e) => {
  81. uni.hideLoading()
  82. })
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="less" scoped>
  88. .messageDetail {
  89. padding: 30upx;
  90. h3 {
  91. font-size: 36upx;
  92. color: #333333;
  93. margin-bottom: 40upx;
  94. }
  95. .detailTime {
  96. font-size: 28upx;
  97. color: #666666;
  98. margin-bottom: 50upx;
  99. }
  100. .detailInfo {
  101. word-wrap: break-word;
  102. p {
  103. font-size: 28upx;
  104. color: #333333;
  105. line-height: 48upx;
  106. text-indent: 1em;
  107. margin-bottom: 50upx;
  108. }
  109. img {
  110. width: 100%;
  111. }
  112. }
  113. }
  114. </style>