<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" @mousemove="handleScroll"
      @load="onLoad"></iframe> -->
  </section>
</template>

<script setup>
import iframeToggle from "./IframeToggle/index"
import useTagsViewStore from '@/store/modules/tagsView'
const route = useRoute()
const tagsViewStore = useTagsViewStore()
const srcUrl = 'http://192.168.11.59:9191/ViewRun?T_ViewID=41rwFKnP9R7DAQXGYkz2S8Vcba3qTUdp'
onMounted(() => {
  addIframe()
})

const onLoad = () => {
  let num = 1
  console.log('----------------------加载完成');
  // 向 iframe 发送消息
  const iframe = document.getElementById("myIframe");
  iframe.contentWindow.postMessage(
    `window.iot3d.ParkSwitch(${num});`,
    "*" // 必须与 iframe 的域名一致
  );
  if (num == 0) {
    num = 1
  } else {
    num = 0
  }
}
function handleScroll() {
  console.log('Iframe scrolled!');
}
watch((route) => {
  addIframe()
})

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;
}

.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>
