index.vue 2.5 KB

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