detail.vue 3.2 KB

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