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