index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div :class="classObj" class="app-wrapper">
  3. <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
  4. <sidebar class="sidebar-container" />
  5. <div class="main-container">
  6. <div :class="{'fixed-header':fixedHeader}">
  7. <navbar />
  8. </div>
  9. <app-main />
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import { Navbar, Sidebar, AppMain } from './components'
  15. import ResizeMixin from './mixin/ResizeHandler'
  16. export default {
  17. name: 'Layout',
  18. components: {
  19. Navbar,
  20. Sidebar,
  21. AppMain
  22. },
  23. mixins: [ResizeMixin],
  24. computed: {
  25. sidebar() {
  26. return this.$store.state.app.sidebar
  27. },
  28. device() {
  29. return this.$store.state.app.device
  30. },
  31. fixedHeader() {
  32. return this.$store.state.settings.fixedHeader
  33. },
  34. classObj() {
  35. return {
  36. hideSidebar: !this.sidebar.opened,
  37. openSidebar: this.sidebar.opened,
  38. withoutAnimation: this.sidebar.withoutAnimation,
  39. mobile: this.device === 'mobile'
  40. }
  41. }
  42. },
  43. methods: {
  44. handleClickOutside() {
  45. this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
  46. }
  47. }
  48. }
  49. </script>
  50. <style lang="scss" scoped>
  51. @import "~@/styles/mixin.scss";
  52. @import "~@/styles/variables.scss";
  53. .app-wrapper {
  54. @include clearfix;
  55. position: relative;
  56. height: 100%;
  57. width: 100%;
  58. &.mobile.openSidebar{
  59. position: fixed;
  60. top: 0;
  61. }
  62. }
  63. .drawer-bg {
  64. background: #000;
  65. opacity: 0.3;
  66. width: 100%;
  67. top: 0;
  68. height: 100%;
  69. position: absolute;
  70. z-index: 999;
  71. }
  72. .fixed-header {
  73. position: fixed;
  74. top: 0;
  75. right: 0;
  76. z-index: 9;
  77. width: calc(100% - #{$sideBarWidth});
  78. transition: width 0.28s;
  79. }
  80. .hideSidebar .fixed-header {
  81. width: calc(100% - 54px)
  82. }
  83. .mobile .fixed-header {
  84. width: 100%;
  85. }
  86. </style>