<template>
  <div v-if="!inIframe" :class="classObj" class="app-wrapper">
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
    <!-- todo 后续加入全局头部 -->
    <Banner v-if="!inIframe" />
    <sidebar v-if="!inIframe" class="sidebar-container" />
    <div class="main-container">
      <div v-if="!inIframe" :class="{'fixed-header':fixedHeader}">
        <navbar />
      </div>
      <app-main />
      <footer>版权所有：广州市市场监督管理局 | 技术支持：广东众望通科技股份有限公司</footer>
    </div>
  </div>
  <div v-else :class="classObj" class="app-wrapper">
    <app-main />
  </div>
</template>

<script>
import { Navbar, Sidebar, AppMain } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import Banner from './components/Banner'
export default {
  name: 'Layout',
  components: {
    Navbar,
    Sidebar,
    AppMain,
    Banner
  },
  mixins: [ResizeMixin],
  computed: {
    inIframe() {
      // url携带shrink 也返回true
      if (this.$route.query.shrink) {
        return true
      }
      return window.top !== window.self
      // return true
    },
    sidebar() {
      return this.$store.state.app.sidebar
    },
    device() {
      return this.$store.state.app.device
    },
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    }
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
@import "~@/styles/variables.scss";

.app-wrapper {
  @include clearfix;
  position: relative;
  height: 100%;
  width: 100%;
  background-color: $BGColor;
  &.mobile.openSidebar {
    position: fixed;
    top: 0;
  }
}
.drawer-bg {
  background: #000;
  opacity: 0.3;
  width: 100%;
  top: 0;
  height: 100%;
  position: absolute;
  z-index: 999;
}

.fixed-header {
  position: fixed;
  top: 100px;
  right: 0;
  z-index: 9;
  width: calc(100% - #{$sideBarWidth + 5px});
  transition: width 0.28s;
}

.hideSidebar .fixed-header {
  width: calc(100% - 54px);
}

.mobile .fixed-header {
  width: 100%;
}
footer {
  text-align: center;
  font-size: 13px;
  line-height: 30px;
  background-color: #f4f8f9;
  width: 100%;
}
</style>
