<template>
  <div :class="classObj" class="app-wrapper">
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
    <sidebar v-if="!isFullScreen" class="sidebar-container" />
    <navbar />
    <div v-if="!isFullScreen" :class="{hasTagsView:needTagsView}" class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <tags-view v-if="needTagsView" />
      </div>
      <app-main :is-full-screen="isFullScreen" />
    </div>
    <div v-if="isFullScreen" class="main-container-full">
      <app-main :is-full-screen="isFullScreen" />
    </div>
  </div>
</template>

<script>
import { Navbar, Sidebar, AppMain, TagsView } from './components'
import ResizeMixin from './mixin/ResizeHandler'

export default {
  name: 'Layout',
  components: {
    Navbar,
    Sidebar,
    AppMain,
    TagsView
  },
  mixins: [ResizeMixin],
  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    device() {
      return this.$store.state.app.device
    },
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    },
    needTagsView() {
      return this.$store.state.settings.tagsView
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    },
    isFullScreen() {
      const FullScreenRouter = ['screen-view', 'video-regulate', 'video1', 'fast/meeting', 'knowledge-search'] // 需要全屏的路由  屏蔽左侧菜单
      let index = FullScreenRouter.findIndex(v => (this.$route.fullPath.indexOf(v) >= 0))
      return index >= 0
    }
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    }
  }
}
</script>

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

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

.fixed-header {
  position: fixed;
  top: 80px;
  right: 0;
  z-index: 1000;
  width: calc(100% - 210px);
  transition: width 0.28s;
}

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

.mobile .fixed-header {
  width: 100%;
}
</style>
