detail.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. <view class="textOne" @tap="toView(info.path)">更多内容</view>
  9. </view>
  10. <view class="two" v-if="info.file.length>0">
  11. <swiperImg :imgsList='info.file'></swiperImg>
  12. </view>
  13. <view class="thr">
  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) {
  45. that.$set(that, `user`, res);
  46. }
  47. } catch (e) {
  48. uni.showToast({
  49. title: err.errmsg,
  50. icon: 'error',
  51. duration: 2000
  52. });
  53. }
  54. },
  55. async search() {
  56. const that = this;
  57. if (that.id) {
  58. const res = await that.$api(`/notice/${that.id}`, 'GET', {})
  59. if (res.errcode == '0') {
  60. that.$set(that, `info`, res.data)
  61. } else {
  62. uni.showToast({
  63. title: res.errmsg,
  64. });
  65. }
  66. }
  67. },
  68. // 处理富文本
  69. formatRichText(html) {
  70. // 富文本内容格式化
  71. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  72. // 查找所有的 img 元素
  73. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  74. '')
  75. // 删除找到的所有 img 元素中的 style 属性
  76. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  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. padding: 2vw;
  105. .image {
  106. width: 50vw;
  107. height: 50vw;
  108. }
  109. }
  110. .thr {
  111. padding: 2vw;
  112. }
  113. }
  114. </style>