index.vue 3.5 KB

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