index.vue 2.3 KB

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