123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template>
- <view class="main">
- <view class="one">
- {{info.title||'暂无标题'}}
- </view>
- <view class="two">
- <view class="two_1">{{info.doctor.name||'暂无'}}</view>
- <view class="two_2">{{info.create_time||'暂无'}}</view>
- </view>
- <view class="thr">
- <rich-text :nodes="formatRichText(info.content)"></rich-text>
- </view>
- <view class="four">
- 来源 | {{info.origin||'暂无来源'}}
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- id: '',
- info: {},
- }
- },
- onLoad: async function(e) {
- const that = this;
- that.$set(that, `id`, e && e.id || '');
- that.search();
- },
- methods: {
- async search() {
- const that = this;
- if (that.id) {
- const res = await that.$api(`/article/${that.id}`, 'GET', {})
- if (res.errcode == '0') {
- that.$set(that, `info`, res.data)
- } else {
- uni.showToast({
- title: res.errmsg,
- });
- }
- }
- },
- // 处理富文本
- formatRichText(html) {
- if (html) {
- // 富文本内容格式化
- return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
- // 查找所有的 img 元素
- return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
- '')
- // 删除找到的所有 img 元素中的 style 属性
- }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
- }
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- padding: 2vw 3vw;
- .one {
- font-size: var(--font18Size);
- font-weight: bold;
- padding: 2vw 0;
- }
- .two {
- display: flex;
- align-items: center;
- font-size: var(--font14Size);
- .two_1 {
- color: var(--f191Color);
- }
- .two_2 {
- color: var(--f99Color);
- padding: 0 2vw;
- }
- }
- .thr {
- padding: 3vw 0;
- }
- .four {
- padding: 4vw 0;
- font-size: var(--font14Size);
- }
- }
- </style>
|