index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. {{info.title||'暂无标题'}}
  5. </view>
  6. <view class="two">
  7. <view class="two_1">{{info.doctor.name||'暂无'}}</view>
  8. <view class="two_2">{{info.create_time||'暂无'}}</view>
  9. </view>
  10. <view class="thr">
  11. <rich-text :nodes="formatRichText(info.content)"></rich-text>
  12. </view>
  13. <view class="four">
  14. 来源 | {{info.origin||'暂无来源'}}
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. id: '',
  23. info: {},
  24. }
  25. },
  26. onLoad: async function(e) {
  27. const that = this;
  28. that.$set(that, `id`, e && e.id || '');
  29. uni.setNavigationBarTitle({
  30. title: e && e.title || '科学普及详情'
  31. });
  32. that.search();
  33. },
  34. methods: {
  35. async search() {
  36. const that = this;
  37. if (that.id) {
  38. const res = await that.$api(`/article/${that.id}`, 'GET', {})
  39. if (res.errcode == '0') {
  40. that.$set(that, `info`, res.data)
  41. } else {
  42. uni.showToast({
  43. title: res.errmsg,
  44. icon: 'none'
  45. });
  46. }
  47. }
  48. },
  49. // 处理富文本
  50. formatRichText(html) {
  51. if (html) {
  52. // 富文本内容格式化
  53. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  54. // 查找所有的 img 元素
  55. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  56. '')
  57. // 删除找到的所有 img 元素中的 style 属性
  58. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  59. }
  60. },
  61. }
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .main {
  66. padding: 2vw;
  67. .one {
  68. font-size: var(--font18Size);
  69. font-weight: bold;
  70. padding: 2vw 0;
  71. }
  72. .two {
  73. display: flex;
  74. align-items: center;
  75. font-size: var(--font14Size);
  76. .two_1 {
  77. color: var(--f191Color);
  78. }
  79. .two_2 {
  80. color: var(--f99Color);
  81. padding: 0 2vw;
  82. }
  83. }
  84. .thr {
  85. padding: 3vw 0;
  86. }
  87. .four {
  88. padding: 4vw 0;
  89. font-size: var(--font14Size);
  90. }
  91. }
  92. </style>