index.vue 1.8 KB

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