index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. that.search();
  30. },
  31. methods: {
  32. async search() {
  33. const that = this;
  34. if (that.id) {
  35. const res = await that.$api(`/article/${that.id}`, 'GET', {})
  36. if (res.errcode == '0') {
  37. that.$set(that, `info`, res.data)
  38. } else {
  39. uni.showToast({
  40. title: res.errmsg,
  41. });
  42. }
  43. }
  44. },
  45. // 处理富文本
  46. formatRichText(html) {
  47. if (html) {
  48. // 富文本内容格式化
  49. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  50. // 查找所有的 img 元素
  51. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  52. '')
  53. // 删除找到的所有 img 元素中的 style 属性
  54. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  55. }
  56. },
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .main {
  62. padding: 2vw 3vw;
  63. .one {
  64. font-size: var(--font18Size);
  65. font-weight: bold;
  66. padding: 2vw 0;
  67. }
  68. .two {
  69. display: flex;
  70. align-items: center;
  71. font-size: var(--font14Size);
  72. .two_1 {
  73. color: var(--f191Color);
  74. }
  75. .two_2 {
  76. color: var(--f99Color);
  77. padding: 0 2vw;
  78. }
  79. }
  80. .thr {
  81. padding: 3vw 0;
  82. }
  83. .four {
  84. padding: 4vw 0;
  85. font-size: var(--font14Size);
  86. }
  87. }
  88. </style>