index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div :class="classObj" class="app-wrapper" :style="{ '--current-color': theme }">
  3. <el-scrollbar>
  4. <div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
  5. <sidebar v-if="!sidebar.hide" class="sidebar-container" />
  6. <div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container">
  7. <div :class="{ 'fixed-header': fixedHeader }">
  8. <navbar @setLayout="setLayout" />
  9. <tags-view v-if="needTagsView" />
  10. </div>
  11. <app-main />
  12. <settings ref="settingRef" />
  13. </div>
  14. </el-scrollbar>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { useWindowSize } from '@vueuse/core'
  19. import Sidebar from './components/Sidebar/index.vue'
  20. import { AppMain, Navbar, Settings, TagsView } from './components'
  21. import defaultSettings from '@/settings'
  22. import useAppStore from '@/store/modules/app'
  23. import useSettingsStore from '@/store/modules/settings'
  24. const settingsStore = useSettingsStore()
  25. const theme = computed(() => settingsStore.theme);
  26. const sideTheme = computed(() => settingsStore.sideTheme);
  27. const sidebar = computed(() => useAppStore().sidebar);
  28. const device = computed(() => useAppStore().device);
  29. const needTagsView = computed(() => settingsStore.tagsView);
  30. const fixedHeader = computed(() => settingsStore.fixedHeader);
  31. const classObj = computed(() => ({
  32. hideSidebar: !sidebar.value.opened,
  33. openSidebar: sidebar.value.opened,
  34. withoutAnimation: sidebar.value.withoutAnimation,
  35. mobile: device.value === 'mobile'
  36. }))
  37. const { width, height } = useWindowSize();
  38. const WIDTH = 992; // refer to Bootstrap's responsive design
  39. watchEffect(() => {
  40. if (device.value === 'mobile' && sidebar.value.opened) {
  41. useAppStore().closeSideBar({ withoutAnimation: false })
  42. }
  43. if (width.value - 1 < WIDTH) {
  44. useAppStore().toggleDevice('mobile')
  45. useAppStore().closeSideBar({ withoutAnimation: true })
  46. } else {
  47. useAppStore().toggleDevice('desktop')
  48. }
  49. })
  50. function handleClickOutside() {
  51. useAppStore().closeSideBar({ withoutAnimation: false })
  52. }
  53. const settingRef = ref(null);
  54. function setLayout() {
  55. settingRef.value.openSetting();
  56. }
  57. </script>
  58. <style lang="scss" scoped>
  59. @import "@/assets/styles/mixin.scss";
  60. @import "@/assets/styles/variables.module.scss";
  61. .app-wrapper {
  62. @include clearfix;
  63. position: relative;
  64. height: 100%;
  65. width: 100%;
  66. .el-scrollbar {
  67. height: 100%;
  68. }
  69. :deep(.el-scrollbar__bar).is-vertical {
  70. z-index: 10;
  71. }
  72. :deep(.el-scrollbar__wrap) {
  73. overflow-x: hidden;
  74. }
  75. &.mobile.openSidebar {
  76. position: fixed;
  77. top: 0;
  78. }
  79. }
  80. .drawer-bg {
  81. background: #000;
  82. opacity: 0.3;
  83. width: 100%;
  84. top: 0;
  85. height: 100%;
  86. position: absolute;
  87. z-index: 999;
  88. }
  89. .fixed-header {
  90. position: fixed;
  91. top: 0;
  92. right: 0;
  93. z-index: 9;
  94. width: calc(100% - #{$base-sidebar-width});
  95. transition: width 0.28s;
  96. }
  97. .hideSidebar .fixed-header {
  98. width: calc(100% - 54px);
  99. }
  100. .sidebarHide .fixed-header {
  101. width: 100%;
  102. }
  103. .mobile .fixed-header {
  104. width: 100%;
  105. }
  106. </style>