<template>
  <section class="app-main">
    <router-view v-slot="{ Component, route }">
      <!-- <transition name="fade-transform" mode="out-in"> -->
      <keep-alive :include="tagsViewStore.cachedViews">
        <component v-if="!route.meta.link" :is="Component" :key="route.path" />
      </keep-alive>
      <!-- </transition> -->
    </router-view>
    <iframe-toggle />
    <iframe id="myIframe" :src="srcUrl" style="width: 100%;height: 100%;" frameborder="0"
      v-show="pathUrl == '/index' || pathUrl == '/system/building'"></iframe>
    <iframe id="myIframeil" :src="srcUrl1" style="width: 100%;height: 100%;" frameborder="0"
      v-if="pathUrl != '/index' && pathShow || pathShow && pathUrl != '/system/lighting'"></iframe>
  </section>
</template>

<script setup>
import iframeToggle from "./IframeToggle/index"
import useTagsViewStore from '@/store/modules/tagsView'
const route = useRoute()
const tagsViewStore = useTagsViewStore()
const pathUrl = ref('')
const pathShow = ref(false)
const srcUrl = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd1'
// const srcUrl = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd1'
const srcUrl1 = ref('')
onMounted(() => {
  addIframe()
})
watch(() => route, (newVal) => {
  pathUrl.value = newVal.path
  if (pathUrl.value == '/system/lighting') {
    // 照明系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd3'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd3'
  } else if (pathUrl.value == '/system/elevator') {
    // 电梯系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd2'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd2'
  } else if (pathUrl.value == '/system/broadcast') {
    // 公共广播
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU12'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU12'
  } else if (pathUrl.value == '/system/tenement') {
    // 物业管理
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU13'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU13'
  } else if (pathUrl.value == '/system/message') {
    // 信息发布
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd8'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd8'
  } else if (pathUrl.value == '/system/energy') {
    // 能源管理
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd4'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd4'
  } else if (pathUrl.value == '/system/video') {
    // 视频监控
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd5'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd5'
  } else if (pathUrl.value == '/system/intruderalarm') {
    // 入侵报警
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd6'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd6'
  } else if (pathUrl.value == '/system/passageway') {
    // 出入口控制
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU15'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU15'
  } else if (pathUrl.value == '/system/inspection') {
    // 电子巡查
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd7'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd7'
  } else if (pathUrl.value == '/system/visitor') {
    // 访客系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU11'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU11'
  } else if (pathUrl.value == '/system/passengerFlow') {
    // 客流统计
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU10'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU10'
  } else if (pathUrl.value == '/system/entranceguard') {
    // 门禁系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd9'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd9'
  } else if (pathUrl.value == '/system/receptiondesk') {
    // 会议系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU14'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU14'
  } else if (pathUrl.value == '/system/airConditioner') {
    // 空调系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU17'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU17'
  } else if (pathUrl.value == '/system/wastewater') {
    // 给排水系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU18'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU18'
  } else if (pathUrl.value == '/system/wirelessIntercom') {
    // 无线对讲系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU19'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU19'
  } else if (pathUrl.value == '/system/sceneLighting') {
    // 景观照明系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU20'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU20'
  } else if (pathUrl.value == '/system/floodlighting') {
    // 泛光照明系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU21'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU21'
  } else if (pathUrl.value == '/system/fireAlarm') {
    // 火灾报警系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU22'
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU22'
  } else if (pathUrl.value == '/system/dynamicEnvironment') {
    // 动力环境监控系统
    srcUrl1.value = 'http://10.1.80.103:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTU23'
  }
  pathShow.value = true
  if (pathUrl.value == '/system/building') {
    // 楼宇自控
    pathShow.value = false
    // srcUrl1.value = 'http://192.168.11.88:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUd1'
  } else if (pathUrl.value == '/index' || pathUrl.value == '/') {
    pathShow.value = false
  }
  // console.log(pathUrl.value, 998);
  addIframe()
}, { deep: true, immediate: true } // 开启深度监听
)
function addIframe() {
  if (route.meta.link) {
    useTagsViewStore().addIframeView(route)
  }
}
</script>

<style lang="scss" scoped>
.app-main {
  height: 100%;
  // width: 100%;
  position: relative;
  overflow: hidden;
}

#myIframe {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  user-select: none;
}

#myIframeil {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  user-select: none;
}

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    min-height: calc(100vh - 84px);
  }

  .fixed-header+.app-main {
    padding-top: 84px;
  }
}
</style>

<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 6px;
  }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background-color: #c0c0c0;
  border-radius: 3px;
}
</style>
