index.vue 1.9 KB

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