<template>
  <view>
    <web-view :src="url"></web-view>
  </view>
</template>

<script>
  import env from '@/config/env'

  export default {
    data() {
      return {
        url: '',
        env: null
      }
    },
    async onLoad(options) {
      if (options.url) {
        this.url = decodeURIComponent(options.url)
      } else {
        this.env = await env[await getApp().globalData.getEnvConfig()]
        const officialAccounts = {
          default: {
            url: '/app/introduce',
            name: '介绍'
          },
          userAgreement: {
            url: '/app/userAgreement',
            name: '用户协议'
          },
          privacy: {
            url: '/app/privacy',
            name: '隐私政策'
          }
        }
        const item = officialAccounts[options?.type] || officialAccounts.default
        this.url = this.env.webviewBaseUrl + item.url
        uni.setNavigationBarTitle({
          title: item.name
        })
      }
    }
  }
</script>
