index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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" @set-layout="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. import { initWebSocket } from '@/utils/websocket';
  29. const settingsStore = useSettingsStore();
  30. const theme = computed(() => settingsStore.theme);
  31. const sidebar = computed(() => useAppStore().sidebar);
  32. const device = computed(() => useAppStore().device);
  33. const needTagsView = computed(() => settingsStore.tagsView);
  34. const fixedHeader = computed(() => settingsStore.fixedHeader);
  35. const classObj = computed(() => ({
  36. hideSidebar: !sidebar.value.opened,
  37. openSidebar: sidebar.value.opened,
  38. withoutAnimation: sidebar.value.withoutAnimation,
  39. mobile: device.value === 'mobile'
  40. }));
  41. const { width } = useWindowSize();
  42. const WIDTH = 992; // refer to Bootstrap's responsive design
  43. watchEffect(() => {
  44. if (device.value === 'mobile' && sidebar.value.opened) {
  45. useAppStore().closeSideBar({ withoutAnimation: false });
  46. }
  47. if (width.value - 1 < WIDTH) {
  48. useAppStore().toggleDevice('mobile');
  49. useAppStore().closeSideBar({ withoutAnimation: true });
  50. } else {
  51. useAppStore().toggleDevice('desktop');
  52. }
  53. });
  54. const navbarRef = ref<InstanceType<typeof Navbar>>();
  55. const settingRef = ref<InstanceType<typeof Settings>>();
  56. onMounted(() => {
  57. nextTick(() => {
  58. navbarRef.value?.initTenantList();
  59. });
  60. });
  61. onMounted(() => {
  62. let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
  63. initWebSocket(protocol + window.location.host + import.meta.env.VITE_APP_BASE_API + '/resource/websocket');
  64. });
  65. const handleClickOutside = () => {
  66. useAppStore().closeSideBar({ withoutAnimation: false });
  67. };
  68. const setLayout = () => {
  69. settingRef.value?.openSetting();
  70. };
  71. </script>
  72. <style lang="scss" scoped>
  73. @import '@/assets/styles/mixin.scss';
  74. @import '@/assets/styles/variables.module.scss';
  75. .app-wrapper {
  76. @include clearfix;
  77. position: relative;
  78. height: 100%;
  79. width: 100%;
  80. &.mobile.openSidebar {
  81. position: fixed;
  82. top: 0;
  83. }
  84. }
  85. .drawer-bg {
  86. background: #000;
  87. opacity: 0.3;
  88. width: 100%;
  89. top: 0;
  90. height: 100%;
  91. position: absolute;
  92. z-index: 999;
  93. }
  94. .fixed-header {
  95. position: fixed;
  96. top: 0;
  97. right: 0;
  98. z-index: 9;
  99. width: calc(100% - #{$base-sidebar-width});
  100. transition: width 0.28s;
  101. background: $fixed-header-bg;
  102. }
  103. .hideSidebar .fixed-header {
  104. width: calc(100% - 54px);
  105. }
  106. .sidebarHide .fixed-header {
  107. width: 100%;
  108. }
  109. .mobile .fixed-header {
  110. width: 100%;
  111. }
  112. </style>