<template>
    <!-- index.wxml -->
    <view class="wrap">
        <view class="wrap_nr">
            <rich-text :nodes="htmlSnip"></rich-text>
        </view>
    </view>
</template>

<script>
// index.js
let myPro = require('../../utils/wxRequest.js');

let util = require('../../utils/util.js');

export default {
    data() {
        return {
            id: '',
            htmlSnip: ''
        };
    },
    onLoad: function (options) {
        // Do some initialize when page load.
        let that = this;
        that.setData({
            id: options.id
        });
    },
    onShow: function () {
        // Do something when page show.
        let that = this;
        that.getContent();
    },
    onReady: function () {
        // Do something when page ready.
    },
    onHide: function () {
        // Do something when page hide.
    },
    onUnload: function () {
        // Do something when page close.
    },
    onPullDownRefresh: function () {
        // Do something when pull down.
    },
    onReachBottom: function () {
        // Do something when page reach bottom.
    },
    onPageScroll: function () {
        // Do something when page scroll
    },
    onResize: function () {
        // Do something when page resize
    },
    methods: {
        // 获取单页内容
        getContent() {
            let that = this;
            let params = {
                id: that.id
            };
            myPro
                .wxRequest('user/v3/article/detail', 'GET', params)
                .then((res) => {
                    let contents = res.result.content; // 小程序内置,转富文本标签,仅对rich-text 中的 class 生效

                    contents = contents.replace(/\<img /g, '<img class="richimg" '); // contents = contents.replace(/\<img src\=\"\/upload/g, '<img class="richimg" src="'+ that.data.domain +'upload');

                    contents = contents.replace(/\<p/g, '<p class="richtxt" ');
                    contents = contents.replace(/\<br\>/g, '');
                    that.setData({
                        htmlSnip: contents
                    });
                })
                .catch((err) => {
                    console.log('报错信息', err);
                    uni.showToast({
                        title: err,
                        icon: 'none'
                    });
                });
        }
    }
};
</script>
<style>
/**index.wxss**/
.richimg {
    width: 100% !important;
    height: auto !important;
}
.wrap_nr {
    padding: 30rpx;
}
</style>
