index.vue 2.6 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. <tags-view v-if="needTagsView" />
  9. </div>
  10. <app-main />
  11. <right-panel v-if="showSettings">
  12. <settings />
  13. </right-panel>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import RightPanel from '@/components/RightPanel'
  19. import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
  20. import ResizeMixin from './mixin/ResizeHandler'
  21. import { mapState } from 'vuex'
  22. export default {
  23. name: 'Layout',
  24. components: {
  25. AppMain,
  26. Navbar,
  27. RightPanel,
  28. Settings,
  29. Sidebar,
  30. TagsView
  31. },
  32. mixins: [ResizeMixin],
  33. computed: {
  34. ...mapState({
  35. sidebar: state => state.app.sidebar,
  36. device: state => state.app.device,
  37. showSettings: state => state.settings.showSettings,
  38. needTagsView: state => state.settings.tagsView,
  39. fixedHeader: state => state.settings.fixedHeader
  40. }),
  41. classObj() {
  42. return {
  43. hideSidebar: !this.sidebar.opened,
  44. openSidebar: this.sidebar.opened,
  45. withoutAnimation: this.sidebar.withoutAnimation,
  46. mobile: this.device === 'mobile'
  47. }
  48. }
  49. },
  50. created() {
  51. // console.log('\u611f\u8c22\u60a8\u4f7f\u7528\u672c\u7cfb\u7edf\uff0c\u5982\u679c\u53ef\u4ee5\u8bf7\u60a8\u5728github\u4e0a\u70b9\u4e0a\u4e00\u4e2a\u5c0f\u5c0f\u7684star\uff0c\u60a8\u7684\u652f\u6301\uff0c\u6211\u7684\u52a8\u529b\u3002\nhttps://github.com/lanyulei/ferry\n\u6709\u4efb\u4f55\u95ee\u9898\u6b22\u8fce\u52a0\u7fa4\u8be2\u95ee\uff1a1127401830')
  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>