detail.vue 2.3 KB

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