detail.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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) {
  50. that.$set(that, `user`, res);
  51. }
  52. } catch (e) {
  53. uni.showToast({
  54. title: err.errmsg,
  55. icon: 'error',
  56. duration: 2000
  57. });
  58. }
  59. },
  60. async search() {
  61. const that = this;
  62. if (that.id) {
  63. const res = await that.$api(`/news/${that.id}`, 'GET', {})
  64. if (res.errcode == '0') {
  65. const type = that.typeList.find(i => i.value == res.data.type)
  66. if (type) res.data.zhType = type.label
  67. that.$set(that, `info`, res.data)
  68. } else {
  69. uni.showToast({
  70. title: res.errmsg,
  71. });
  72. }
  73. }
  74. },
  75. // 处理富文本
  76. formatRichText(html) {
  77. if (html) {
  78. // 富文本内容格式化
  79. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  80. // 查找所有的 img 元素
  81. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  82. '')
  83. // 删除找到的所有 img 元素中的 style 属性
  84. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  85. }
  86. },
  87. // 查询其他信息
  88. async searchOther() {
  89. const that = this;
  90. let res;
  91. // 查询类型
  92. res = await that.$api(`/dictData`, 'GET', {
  93. type: 'news_type',
  94. is_use: '0',
  95. })
  96. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .main {
  103. .one {
  104. padding: 4vw 2vw;
  105. text-align: center;
  106. .one_1 {
  107. padding: 1vw 0;
  108. font-weight: bold;
  109. font-size: var(--font16Size);
  110. }
  111. .one_2 {
  112. color: var(--f85Color);
  113. font-size: var(--font12Size);
  114. }
  115. }
  116. .two {
  117. text-align: center;
  118. .button {
  119. margin: 1vw 0 0 0;
  120. background-color: var(--f3CColor);
  121. color: var(--mainColor);
  122. font-size: var(--font14Size);
  123. }
  124. }
  125. .thr {
  126. text-align: center;
  127. padding: 2vw;
  128. .image {
  129. width: 50vw;
  130. height: 50vw;
  131. }
  132. }
  133. .four {
  134. padding: 2vw;
  135. }
  136. }
  137. </style>