index.vue 3.2 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. <sidebar v-if="!sidebar.hide" class="sidebar-container" />
  5. <div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container">
  6. <div :class="{ 'fixed-header': fixedHeader }">
  7. <navbar @setLayout="setLayout" />
  8. <headerBar></headerBar>
  9. <tags-view v-if="needTagsView" />
  10. </div>
  11. <app-main />
  12. <settings ref="settingRef" />
  13. </div>
  14. </div>
  15. </template>
  16. <script setup>
  17. import { useWindowSize } from "@vueuse/core";
  18. import Sidebar from "./components/Sidebar/index.vue";
  19. import { AppMain, Navbar, Settings, TagsView } from "./components";
  20. import defaultSettings from "@/settings";
  21. import headerBar from "@/components/headerBar/header-bar";
  22. import useAppStore from "@/store/modules/app";
  23. import useSettingsStore from "@/store/modules/settings";
  24. const { proxy } = getCurrentInstance();
  25. const settingsStore = useSettingsStore();
  26. const theme = computed(() => settingsStore.theme);
  27. const sideTheme = computed(() => settingsStore.sideTheme);
  28. const sidebar = computed(() => useAppStore().sidebar);
  29. const device = computed(() => useAppStore().device);
  30. const needTagsView = computed(() => settingsStore.tagsView);
  31. const fixedHeader = computed(() => settingsStore.fixedHeader);
  32. const classObj = computed(() => ({
  33. hideSidebar: !sidebar.value.opened,
  34. openSidebar: sidebar.value.opened,
  35. withoutAnimation: sidebar.value.withoutAnimation,
  36. mobile: device.value === "mobile",
  37. }));
  38. const { width, height } = useWindowSize();
  39. const WIDTH = 992; // refer to Bootstrap's responsive design
  40. watchEffect(() => {
  41. if (device.value === "mobile" && sidebar.value.opened) {
  42. useAppStore().closeSideBar({ withoutAnimation: false });
  43. }
  44. if (width.value - 1 < WIDTH) {
  45. useAppStore().toggleDevice("mobile");
  46. useAppStore().closeSideBar({ withoutAnimation: true });
  47. } else {
  48. useAppStore().toggleDevice("desktop");
  49. }
  50. });
  51. function handleClickOutside() {
  52. useAppStore().closeSideBar({ withoutAnimation: false });
  53. }
  54. const settingRef = ref(null);
  55. function setLayout() {
  56. settingRef.value.openSetting();
  57. }
  58. const getAllDict = () => {
  59. proxy
  60. .useUserStore()
  61. .allDictMap()
  62. .then(() => {})
  63. .catch(() => {});
  64. };
  65. getAllDict();
  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. ::v-deep(.is-text) {
  107. outline: 0px !important;
  108. }
  109. ::v-deep(.el-button:focus-visible) {
  110. outline: 0px !important;
  111. }
  112. </style>