<template>
  <div>
    <FromIframe :url="url" />
  </div>
</template>

<script>
import { mapState } from 'vuex'
import FromIframe from './components/FromIframe'
export default {
  components: { FromIframe },
  data() {
    return {
      url: ''
    }
  },
  computed: {
    ...mapState(['token', 'env']),
  },

  created(){
    // console.log(this.$route.path)
    // this.url = `${this.env.VUE_APP_JXY_WEB}/#${this.$route.path}?code=${this.token}`
  },

  watch: {
    $route: {
      handler: function (val) {
          if (this.token){
              let path = val.path
              if (path.startsWith("/zhjg/")) { //智慧监管
                  path =path.replace('/html/','?html=');
                  path = `${this.env.VUE_APP_JCJG_WEB}${path}`
                  if (path.includes("?")) {
                      this.url = `${path}&code=${this.token}&appType=govt`
                  } else {
                      this.url = `${path}?code=${this.token}&appType=govt`
                  }
              }else if (path.startsWith("/zhgdAttn/")) { //实名制6036
                  path =path.replace('/zhgdAttn/','/');
                  path = `${this.env.VUE_APP_ATTN_WEB}${path}`
                  this.url = `${path}?code=${this.token}&appType=govt`
              }else if (path.startsWith("/zhgdAttnDevice/")) { //实名制设备6033
                  path =path.replace('/zhgdAttnDevice/','/');
                  path = `${this.env.VUE_APP_ATTN_DEVICE_WEB}${path}`
                  this.url = `${path}?code=${this.token}&appType=govt`
              }else if (path.startsWith("/csmgt-admin/")) { //文明施工
                  path = `${this.env.VUE_APP_JCJG_MGT}${path}`
                  this.url = `${path}?code=${this.token}&appType=govt`
              }else {
                  path = `${this.env.VUE_APP_JXY}${path}`
                  this.url = `${path}?code=${this.token}`
              }
              console.log('code：'+this.token);
              console.log(this.url);
         }
      },
      immediate: true,
    }
  },
}
</script>

<style lang="scss" scoped>
</style>