detail.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <view class="one_1">{{info.name||'暂无'}}</view>
  5. <view class="one_2">{{info.create_time||'暂无'}}</view>
  6. </view>
  7. <view class="two" v-if="info.path">
  8. <button class="button" type="primary" size="mini" @click="toView(info.path)">更多内容</button>
  9. </view>
  10. <view class="thr" v-if="info.file.length>0">
  11. <swiperImg :imgsList='info.file'></swiperImg>
  12. </view>
  13. <view class="four">
  14. <rich-text :nodes="formatRichText(info.content)"></rich-text>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import swiperImg from '../../components/swiper/index.vue';
  20. export default {
  21. components: {
  22. swiperImg
  23. },
  24. data() {
  25. return {
  26. id: '',
  27. user: {},
  28. info: {
  29. file: []
  30. },
  31. }
  32. },
  33. onLoad: async function(e) {
  34. const that = this;
  35. that.$set(that, `id`, e && e.id || '');
  36. that.searchToken();
  37. that.search();
  38. },
  39. methods: {
  40. searchToken() {
  41. const that = this;
  42. try {
  43. const res = uni.getStorageSync('token');
  44. if (res) that.$set(that, `user`, res);
  45. } catch (e) {
  46. uni.showToast({
  47. title: err.errmsg,
  48. icon: 'error',
  49. duration: 2000
  50. });
  51. }
  52. },
  53. async search() {
  54. const that = this;
  55. if (that.id) {
  56. const res = await that.$api(`/notice/${that.id}`, 'GET', {})
  57. if (res.errcode == '0') {
  58. that.$set(that, `info`, res.data)
  59. } else {
  60. uni.showToast({
  61. title: res.errmsg,
  62. });
  63. }
  64. }
  65. },
  66. // 处理富文本
  67. formatRichText(html) {
  68. if (html) {
  69. // 富文本内容格式化
  70. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  71. // 查找所有的 img 元素
  72. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  73. '')
  74. // 删除找到的所有 img 元素中的 style 属性
  75. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  76. }
  77. },
  78. // 查看公告链接
  79. toView(url) {
  80. uni.navigateTo({
  81. url: `/pagesHome/weather/index?url=${url}`
  82. })
  83. },
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .main {
  89. .one {
  90. padding: 4vw 2vw;
  91. text-align: center;
  92. .one_1 {
  93. padding: 1vw 0;
  94. font-weight: bold;
  95. font-size: var(--font16Size);
  96. }
  97. .one_2 {
  98. color: var(--f85Color);
  99. font-size: var(--font12Size);
  100. }
  101. }
  102. .two {
  103. text-align: center;
  104. .button {
  105. margin: 1vw 0 0 0;
  106. background-color: var(--f3CColor);
  107. color: var(--mainColor);
  108. font-size: var(--font14Size);
  109. }
  110. }
  111. .thr {
  112. text-align: center;
  113. padding: 2vw;
  114. .image {
  115. width: 50vw;
  116. height: 50vw;
  117. }
  118. }
  119. .four {
  120. padding: 2vw;
  121. }
  122. }
  123. </style>