index.vue 3.1 KB

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