<template>
  <router-view />
  <teleport to="body">
    <Transition name="toast-transition">
      <ToastComp v-if="isShowToast" />
    </Transition>
    <!-- 禁止竖屏 -->
    <!-- <div
      v-if="$isMobile && windowOrientation === 'portrait' && route.meta.windowOrientation === 'landscape'"
      class="force-landscape window-orientation-tip "
    >
      <div class="wrap">
        <img
          class=""
          src="@/assets/images/force-landscape.png"
          alt=""
          draggable="false"
        >
        <div class="txt">
          请开启自动旋转后
        </div>
        <div class="txt">
          横屏播放
        </div>
      </div>
    </div> -->
    <div
      v-if="$isMobile"
      class="force-landscape window-orientation-tip "
    >
      <div class="wrap">
        <img
          class=""
          src="@/assets/images/force-landscape.png"
          alt=""
          draggable="false"
        >
        <div class="txt">
          请开启自动旋转后
        </div>
        <div class="txt">
          横屏播放
        </div>
      </div>
    </div>
    <!-- <div
      v-if="$isMobile && windowOrientation === 'landscape' && route.meta.windowOrientation === 'portrait'"
      class="force-portrait window-orientation-tip"
    >
      <div class="wrap">
        <img
          class=""
          src="@/assets/images/force-portrait.png"
          alt=""
          draggable="false"
        >
        <div class="txt">
          请竖屏播放
        </div>
      </div>
    </div> -->
  </teleport>
</template>

<script setup>
import { useWindowSize } from '@vueuse/core'
import { computed, inject, ref, onMounted } from 'vue'
import ToastComp from "@/components/ToastComp.vue"
import { isShowToast } from "@/store/index.js"
import { useRoute, useRouter } from "vue-router"

const route = useRoute()
const router = useRouter()

const {
  windowSizeInCssForRef,
  windowSizeWhenDesignForRef,
} = useSizeAdapt()

const $isMobile = inject('$isMobile')

const { width: windowWidth, height: windowHeight } = useWindowSize()
console.log(windowWidth)
const windowOrientation = computed(() => {
  return windowWidth.value >= windowHeight.value ? 'landscape' : 'portrait'
})

const time = ref({
  current: null
})
onMounted(() => {
  // 移动端
  // 监听窗口变化进行高度重置
  window.addEventListener(
    "resize",
    () => {
      // // @ts-ignore
      clearTimeout(time.value.current)
      time.value.current = window.setTimeout(() => {
        const dom = document.querySelector("body")
        if (dom && document.documentElement.clientWidth < 480) {
          const orientation = (window.innerWidth > windowHeight) ? "landscape" : "portrait"
          if (orientation == 'landscape') {
            // 更新横屏高度
            dom.style.height = document.documentElement.clientHeight + "px"
          }
        }
      }, 50)
    },
    true
  )
  window.WeixinJSBridge.call('hideToolbar')
  window.WeixinJSBridge.call('hideOptionMenu')
})
</script>

<style lang="less">
// html, body {
//   overscroll-behavior: none;
//   overflow: hidden;
// }

* {
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  width: 100vw;
  height: 100%;
}

// 360浏览器不支持not()
input,
textarea {
  user-select: initial;
}

// 字体
@font-face {
  font-family: 'jiangxizhuokai-Regular';
  src: url('@/assets/style/jiangxizhuokai-Regular.ttf');
}

// @font-face {
//   font-family: 'Source Han Serif CN';
//   src: url('@/assets/style/SourceHanSerifCN-Regular.otf');
// }
@font-face {
  font-family: 'Source Han Serif CN-Bold';
  src: url('@/assets/style/SourceHanSerifCN-Bold.otf');
}

// i {
//   font-style: italic;
// }

// 滚动条
// ::-webkit-scrollbar { background: #dddecc; width: 0.3rem; height: 0.3rem; } /*宽度是对垂直滚动条而言，高度是对水平滚动条而言*/
// ::-webkit-scrollbar-thumb { background: #828a5b; border-radius: 0.15rem; }
// ::-webkit-scrollbar-corner { background: #dddecc; }

/**
 * vue组件过渡效果
 */
.fade-in-enter-active {
  transition: opacity 1s;
}

.fade-in-enter-from {
  opacity: 0;
}

.fade-out-leave-active {
  transition: opacity 1s;
  pointer-events: none;
}

.fade-out-leave-to {
  opacity: 0;
}

.tool-fade-in-out-enter-active {
  transition: opacity 0.5s;
  pointer-events: none;
}

.tool-fade-in-out-leave-active {
  transition: opacity 0.5s;
  pointer-events: none;
}

.tool-fade-in-out-enter-from {
  opacity: 0 !important;
}

.tool-fade-in-out-leave-to {
  opacity: 0 !important;
}

.toast-transition-leave-active {
  transition: opacity 0.5s;
  pointer-events: none;
}

.toast-transition-leave-to {
  opacity: 0;
}

// 不断渐变显隐 animation
.animation-show-hide {
  animation: show-hide 1.8s infinite;
}

@keyframes show-hide {
  0% {
    opacity: 0;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

// vue-viewer
.viewer-container {
  background-color: rgba(0, 0, 0, 80%) !important;
  backdrop-filter: blur(5px);
}

// 或者
// .viewer-backdrop {
//   background-color: rgba(0, 0, 0, 90%) !important;
// }
</style>

<style lang="less" scoped>
.window-orientation-tip {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(calc(90 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef')));
  display: flex;
  justify-content: center;
  align-items: center;

  >.wrap {
    text-align: center;

    >img {
      width: calc(113 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
      height: calc(113 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
      margin-bottom: calc(39 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
    }

    >.txt {
      font-size: calc(20 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
      font-family: Microsoft YaHei-Regular, Microsoft YaHei;
      font-weight: 400;
      color: rgba(255, 255, 255, 0.7);
      line-height: calc(34 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
      letter-spacing: calc(1 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
    }
  }
}

/*竖屏*/
@media screen and (orientation: portrait) {
  .window-orientation-tip {
    .window-orientation-tip {
      display: block;
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      z-index: 9999;
      background: rgba(0, 0, 0, 0.7);
      backdrop-filter: blur(calc(90 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef')));
      display: flex;
      justify-content: center;
      align-items: center;

      >.wrap {
        text-align: center;

        >img {
          width: calc(113 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
          height: calc(113 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
          margin-bottom: calc(39 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
        }

        >.txt {
          font-size: calc(20 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
          font-family: Microsoft YaHei-Regular, Microsoft YaHei;
          font-weight: 400;
          color: rgba(255, 255, 255, 0.7);
          line-height: calc(34 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
          letter-spacing: calc(1 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
        }
      }
    }
  }
}

/*横屏*/
@media screen and (orientation: landscape) {
  .window-orientation-tip {
    display: none;
  }
}
</style>