index.vue 1.85 KB
Newer Older
Pan's avatar
Pan committed
1
<template>
2
  <div :class="classObj" class="app-wrapper">
花裤衩's avatar
花裤衩 committed
3 4
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
    <sidebar class="sidebar-container" />
Pan's avatar
Pan committed
5
    <div class="main-container">
花裤衩's avatar
花裤衩 committed
6 7 8 9
      <div :class="{'fixed-header':fixedHeader}">
        <navbar />
      </div>
      <app-main />
Pan's avatar
Pan committed
10 11
    </div>
  </div>
Pan's avatar
Pan committed
12 13 14
</template>

<script>
15 16
import { Navbar, Sidebar, AppMain } from './components'
import ResizeMixin from './mixin/ResizeHandler'
Pan's avatar
Pan committed
17

Pan's avatar
Pan committed
18
export default {
19
  name: 'Layout',
Pan's avatar
Pan committed
20 21 22 23 24
  components: {
    Navbar,
    Sidebar,
    AppMain
  },
25
  mixins: [ResizeMixin],
Pan's avatar
Pan committed
26 27 28
  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
29 30 31 32
    },
    device() {
      return this.$store.state.app.device
    },
花裤衩's avatar
花裤衩 committed
33 34 35
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    },
36 37 38
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
39
        openSidebar: this.sidebar.opened,
40 41 42
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
Pan's avatar
Pan committed
43
    }
44 45 46
  },
  methods: {
    handleClickOutside() {
47
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
48
    }
Pan's avatar
Pan committed
49 50
  }
}
Pan's avatar
Pan committed
51 52
</script>

花裤衩's avatar
花裤衩 committed
53 54 55 56
<style lang="scss" scoped>
  @import "~@/styles/mixin.scss";
  @import "~@/styles/variables.scss";

57 58 59 60 61
  .app-wrapper {
    @include clearfix;
    position: relative;
    height: 100%;
    width: 100%;
62 63 64 65
    &.mobile.openSidebar{
      position: fixed;
      top: 0;
    }
66
  }
67 68 69 70 71 72 73 74 75
  .drawer-bg {
    background: #000;
    opacity: 0.3;
    width: 100%;
    top: 0;
    height: 100%;
    position: absolute;
    z-index: 999;
  }
花裤衩's avatar
花裤衩 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

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

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

  .mobile .fixed-header {
    width: 100%;
  }
Pan's avatar
Pan committed
93
</style>