<template>
  <view class="container">
    <div class="body">
      <rich-text style="width: 100%" :nodes="richTextHtml" />
    </div>
  </view>
</template>

<script>
import { getSiteConfig } from '@/api/system/config'
import parser from 'rich-text-parser'
  export default {
    filters: {
      formatRichText(html) { // 控制小程序中图片大小
        // console.log(html)
        const nodes = parser.getRichTextJson(html)
        return nodes.children
      }
    },
    data() {
      return {
        richTextHtml: '',
      }
    },
    onLoad(options) {
      uni.setNavigationBarTitle({
        title: options.title
      })
      this.getRichTextHtml(options.code)
    },
    methods:{
      async getRichTextHtml(code){
        let that = this
        getSiteConfig({code:code}).then(res => {
          let json = JSON.parse(res.data)
          that.richTextHtml = json[0].value
        }).catch((e) => {
          uni.showToast({
            icon: 'error',
            duration: 2000,
            title: e
          });
        })
      },
    }
  }
</script>

<style scoped lang="scss">
.container {
  height: 100%;
  padding: 20rpx;
  background: white;
  display: flex;
  flex-direction: column;
  .body{
    flex: 1;
    height: 0;
    overflow: auto;
  }
}
</style>
