detail.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 v-if="info.path" class="one_2" @tap="toView(info.path)">公告链接:{{info.path||'暂无'}}</view>
  7. </view>
  8. <view class="two" v-if="info.file.length>0">
  9. <swiperImg :imgsList='info.file'></swiperImg>
  10. </view>
  11. <view class="thr">
  12. <rich-text :nodes="formatRichText(info.content)"></rich-text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import swiperImg from '../../components/swiper/index.vue';
  18. export default {
  19. components: {
  20. swiperImg
  21. },
  22. data() {
  23. return {
  24. id: '',
  25. user: {},
  26. info: {
  27. file: []
  28. },
  29. }
  30. },
  31. onLoad: async function(e) {
  32. const that = this;
  33. that.$set(that, `id`, e && e.id || '');
  34. that.searchToken();
  35. that.search();
  36. },
  37. methods: {
  38. searchToken() {
  39. const that = this;
  40. try {
  41. const res = uni.getStorageSync('token');
  42. if (res) {
  43. that.$set(that, `user`, res);
  44. }
  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. // 富文本内容格式化
  69. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  70. // 查找所有的 img 元素
  71. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  72. '')
  73. // 删除找到的所有 img 元素中的 style 属性
  74. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  75. },
  76. // 查看公告链接
  77. toView(url) {
  78. uni.navigateTo({
  79. url: `/pagesHome/weather/index?url=${url}`
  80. })
  81. },
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .main {
  87. .one {
  88. padding: 4vw 2vw;
  89. text-align: center;
  90. .one_1 {
  91. padding: 1vw 0;
  92. font-weight: bold;
  93. font-size: var(--font16Size);
  94. }
  95. .one_2 {
  96. color: var(--f85Color);
  97. font-size: var(--font12Size);
  98. }
  99. }
  100. .two {
  101. text-align: center;
  102. padding: 2vw;
  103. .image {
  104. width: 50vw;
  105. height: 50vw;
  106. }
  107. }
  108. .thr {
  109. padding: 2vw;
  110. }
  111. }
  112. </style>