<template>
  <div :class="classObj" class="app-wrapper">
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
    <app-header class="app-header"/>
    <div class="app-body">
      <!--侧边栏-->
      <sidebar class="sidebar-container"/>
      <!--右半部分-->
      <div class="main-container">
        <!--上方导航-->
        <navbar/>
        <!--标签栏-->
        <tags-view/>
        <!--主页-->
        <el-scrollbar>
          <app-main/>
        </el-scrollbar>

      </div>
    </div>
  </div>
</template>

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

export default {
  name: 'Layout',
  components: {
    TagsView,
    AppHeader,
    Navbar,
    Sidebar,
    AppMain
  },
  mixins: [ResizeMixin],
  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    device() {
      return this.$store.state.app.device
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    }
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('CloseSideBar', { withoutAnimation: false })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/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: 999;
  }
  .el-scrollbar{
    height: calc(100vh - 80px);
  }
</style>
