多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.0 KiB

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