index.vue 3.0 KB

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