<template>
  <div>
    <FromIframe :url="url" v-if="show" />
  </div>
</template>

<script>
import FromIframe from './components/FromIframe'
import { mapState } from 'vuex'
export default {
  components: { FromIframe },
  data() {
    return {
      url: '',
      show: false
    }
  },
  computed: {
    ...mapState(['env']),
  },
  watch: {
    $route: {
      handler: function (val) {
        this.getToken(val.path)
      },
      immediate: true,
    }
  },
  methods: {
    getToken(route) {
      this.show = false
      this.$get(
        this.env.VUE_APP_SUPERVISE_PORT + '/getAccessToken',
        {},
        data => {
          this.show = true
          if (route.indexOf('/yth') == 0) {
            let path = route.replace('/yth', '/other/yth')
            this.url = `${this.env.VUE_APP_SI_KU}/#${path}?code=${data.data}`
          }
        }, error => {
          this.$message.error(error.msg)
          this.show = true
        }
      )
    }
  }
}
</script>