index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 router from '../router';
  21. const store = useStore();
  22. const theme = computed(() => store.state.settings.theme);
  23. const sideTheme = computed(() => store.state.settings.sideTheme);
  24. const sidebar = computed(() => store.state.app.sidebar);
  25. const device = computed(() => store.state.app.device);
  26. const needTagsView = computed(() => store.state.settings.tagsView);
  27. const fixedHeader = computed(() => store.state.settings.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. watch(() => device.value, () => {
  35. if (device.value === 'mobile') {
  36. router.replace("/mb")
  37. }
  38. })
  39. const { width, height } = useWindowSize();
  40. const WIDTH = 992; // refer to Bootstrap's responsive design
  41. watchEffect(() => {
  42. if (device.value === 'mobile' && sidebar.value.opened) {
  43. store.dispatch('app/closeSideBar', { withoutAnimation: false })
  44. }
  45. if (width.value - 1 < WIDTH) {
  46. store.dispatch('app/toggleDevice', 'mobile')
  47. store.dispatch('app/closeSideBar', { withoutAnimation: true })
  48. } else {
  49. store.dispatch('app/toggleDevice', 'desktop')
  50. }
  51. })
  52. function handleClickOutside() {
  53. store.dispatch('app/closeSideBar', { withoutAnimation: false })
  54. }
  55. const settingRef = ref(null);
  56. function setLayout() {
  57. settingRef.value.openSetting();
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. @import "@/assets/styles/mixin.scss";
  62. @import "@/assets/styles/variables.module.scss";
  63. body{
  64. background: #eef2f8;
  65. }
  66. .app-wrapper {
  67. @include clearfix;
  68. position: relative;
  69. height: 100%;
  70. width: 100%;
  71. &.mobile.openSidebar {
  72. position: fixed;
  73. top: 0;
  74. }
  75. }
  76. .drawer-bg {
  77. background: #000;
  78. opacity: 0.3;
  79. width: 100%;
  80. top: 0;
  81. height: 100%;
  82. position: absolute;
  83. z-index: 999;
  84. }
  85. .fixed-header {
  86. position: fixed;
  87. top: 0;
  88. right: 0;
  89. z-index: 9;
  90. width: calc(100% - #{$base-sidebar-width});
  91. transition: width 0.28s;
  92. }
  93. .hideSidebar .fixed-header {
  94. width: calc(100% - 54px);
  95. }
  96. .sidebarHide .fixed-header {
  97. width: 100%;
  98. }
  99. .mobile .fixed-header {
  100. width: 100%;
  101. }
  102. </style>