index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 useAppStore from '@/store/modules/app'
  20. import useSettingsStore from '@/store/modules/settings'
  21. const settingsStore = useSettingsStore()
  22. const theme = computed(() => settingsStore.theme)
  23. const sideTheme = computed(() => settingsStore.sideTheme)
  24. const sidebar = computed(() => useAppStore().sidebar)
  25. const device = computed(() => useAppStore().device)
  26. const needTagsView = computed(() => settingsStore.tagsView)
  27. const fixedHeader = computed(() => settingsStore.fixedHeader)
  28. const classObj = computed(() => ({
  29. hideSidebar: !sidebar.value.opened,
  30. openSidebar: sidebar.value.opened,
  31. withoutAnimation: sidebar.value.withoutAnimation,
  32. mobile: device.value === 'mobile'
  33. }))
  34. const { width, height } = useWindowSize()
  35. const WIDTH = 992 // refer to Bootstrap's responsive design
  36. watch(() => device.value, () => {
  37. if (device.value === 'mobile' && sidebar.value.opened) {
  38. useAppStore().closeSideBar({ withoutAnimation: false })
  39. }
  40. })
  41. watchEffect(() => {
  42. if (width.value - 1 < WIDTH) {
  43. useAppStore().toggleDevice('mobile')
  44. useAppStore().closeSideBar({ withoutAnimation: true })
  45. } else {
  46. useAppStore().toggleDevice('desktop')
  47. }
  48. })
  49. function handleClickOutside() {
  50. useAppStore().closeSideBar({ withoutAnimation: false })
  51. }
  52. const settingRef = ref(null)
  53. function setLayout() {
  54. settingRef.value.openSetting()
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. @use "@/assets/styles/mixin.scss" as mix;
  59. @use "@/assets/styles/variables.module.scss" as vars;
  60. .app-wrapper {
  61. @include mix.clearfix;
  62. position: relative;
  63. height: 100%;
  64. width: 100%;
  65. &.mobile.openSidebar {
  66. position: fixed;
  67. top: 0;
  68. }
  69. }
  70. .main-container:has(.fixed-header) {
  71. height: 100vh;
  72. overflow: hidden;
  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% - #{vars.$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>