index.vue 3.1 KB

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