index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 setup>
  16. import { useWindowSize } from '@vueuse/core'
  17. import Sidebar from './components/Sidebar/index.vue'
  18. import { AppMain, Navbar, Settings, TagsView } from './components'
  19. import defaultSettings from '@/settings'
  20. import useAppStore from '@/store/modules/app'
  21. import useSettingsStore from '@/store/modules/settings'
  22. const settingsStore = useSettingsStore()
  23. const theme = computed(() => settingsStore.theme);
  24. const sideTheme = computed(() => settingsStore.sideTheme);
  25. const sidebar = computed(() => useAppStore().sidebar);
  26. const device = computed(() => useAppStore().device);
  27. const needTagsView = computed(() => settingsStore.tagsView);
  28. const fixedHeader = computed(() => settingsStore.fixedHeader);
  29. const classObj = computed(() => ({
  30. hideSidebar: !sidebar.value.opened,
  31. openSidebar: sidebar.value.opened,
  32. withoutAnimation: sidebar.value.withoutAnimation,
  33. mobile: device.value === 'mobile'
  34. }))
  35. const { width, height } = useWindowSize();
  36. const WIDTH = 992; // refer to Bootstrap's responsive design
  37. watchEffect(() => {
  38. if (device.value === 'mobile' && sidebar.value.opened) {
  39. useAppStore().closeSideBar({ withoutAnimation: false })
  40. }
  41. if (width.value - 1 < WIDTH) {
  42. useAppStore().toggleDevice('mobile')
  43. useAppStore().closeSideBar({ withoutAnimation: true })
  44. } else {
  45. useAppStore().toggleDevice('desktop')
  46. }
  47. })
  48. function handleClickOutside() {
  49. useAppStore().closeSideBar({ withoutAnimation: false })
  50. }
  51. const settingRef = ref(null);
  52. function setLayout() {
  53. settingRef.value.openSetting();
  54. }
  55. </script>
  56. <style lang="scss" scoped>
  57. @import "@/assets/styles/mixin.scss";
  58. @import "@/assets/styles/variables.module.scss";
  59. .app-wrapper {
  60. @include clearfix;
  61. position: relative;
  62. height: 100%;
  63. width: 100%;
  64. &.mobile.openSidebar {
  65. position: fixed;
  66. top: 0;
  67. }
  68. }
  69. .drawer-bg {
  70. background: #000;
  71. opacity: 0.3;
  72. width: 100%;
  73. top: 0;
  74. height: 100%;
  75. position: absolute;
  76. z-index: 999;
  77. }
  78. .fixed-header {
  79. position: fixed;
  80. top: 0;
  81. right: 0;
  82. z-index: 9;
  83. width: calc(100% - #{$base-sidebar-width});
  84. transition: width 0.28s;
  85. }
  86. .hideSidebar .fixed-header {
  87. width: calc(100% - 54px);
  88. }
  89. .sidebarHide .fixed-header {
  90. width: 100%;
  91. }
  92. .mobile .fixed-header {
  93. width: 100%;
  94. }
  95. </style>