fix: 🐛 布局切换问题修复

This commit is contained in:
hxr
2024-02-18 23:23:28 +08:00
parent 4c0baa8bb7
commit 53250a28dd
5 changed files with 45 additions and 17 deletions

View File

@@ -70,4 +70,10 @@ const cachedViews = computed(() => tagsViewStore.cachedViews); // 缓存页面
} }
} }
} }
.layout-top {
.fixed-header + .app-main {
padding-top: $tags-view-height;
}
}
</style> </style>

View File

@@ -91,9 +91,9 @@ import { Sunny, Moon } from "@element-plus/icons-vue";
const route = useRoute(); const route = useRoute();
const appStore = useAppStore();
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
const permissionStore = usePermissionStore(); const permissionStore = usePermissionStore();
const appStore = useAppStore();
function findOutermostParent(tree: any[], findName: string) { function findOutermostParent(tree: any[], findName: string) {
let parentMap: any = {}; let parentMap: any = {};
@@ -122,12 +122,6 @@ function findOutermostParent(tree: any[], findName: string) {
return null; return null;
} }
const againActiveTop = (newVal: string) => {
const parent = findOutermostParent(permissionStore.routes, newVal);
if (appStore.activeTopMenu !== parent.path) {
appStore.activeTopMenu(parent.path);
}
};
/** /**
* 切换布局 * 切换布局
@@ -136,6 +130,15 @@ function changeLayout(layout: string) {
settingsStore.changeSetting({ key: "layout", value: layout }); settingsStore.changeSetting({ key: "layout", value: layout });
if (layout === "mix") { if (layout === "mix") {
route.name && againActiveTop(route.name as string); route.name && againActiveTop(route.name as string);
} else if (layout === "top") {
appStore.openSideBar();
}
}
function againActiveTop(newVal: string) {
const parent = findOutermostParent(permissionStore.routes, newVal);
if (appStore.activeTopMenu !== parent.path) {
appStore.activeTopMenu(parent.path);
} }
} }

View File

@@ -53,5 +53,11 @@ const logo = ref(new URL(`../../../../assets/logo.png`, import.meta.url).href);
.logo-container { .logo-container {
width: $sidebar-width; width: $sidebar-width;
} }
&.hideSidebar {
.logo-container {
width: $sidebar-width-collapsed;
}
}
} }
</style> </style>

View File

@@ -20,9 +20,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { useSettingsStore, usePermissionStore, useAppStore } from "@/store"; import { useSettingsStore, usePermissionStore, useAppStore } from "@/store";
const appStore = useAppStore();
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
const permissionStore = usePermissionStore(); const permissionStore = usePermissionStore();
const appStore = useAppStore();
const { sidebarLogo } = settingsStore; const sidebarLogo = settingsStore.sidebarLogo;
const layout = computed(() => settingsStore.layout); const layout = computed(() => settingsStore.layout);
</script> </script>

View File

@@ -48,13 +48,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { useAppStore, useSettingsStore, usePermissionStore } from "@/store"; import { useAppStore, useSettingsStore, usePermissionStore } from "@/store";
const permissionStore = usePermissionStore();
const { width } = useWindowSize();
const WIDTH = 992; // 响应式布局容器固定宽度 大屏(>=1200px 中屏(>=992px 小屏(>=768px
const appStore = useAppStore(); const appStore = useAppStore();
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
const permissionStore = usePermissionStore();
const fixedHeader = computed(() => settingsStore.fixedHeader); const fixedHeader = computed(() => settingsStore.fixedHeader);
const showTagsView = computed(() => settingsStore.tagsView); const showTagsView = computed(() => settingsStore.tagsView);
@@ -90,6 +87,9 @@ const classObj = computed(() => ({
"layout-mix": layout.value === "mix", "layout-mix": layout.value === "mix",
})); }));
const width = useWindowSize().width;
const WIDTH = 992; // 响应式布局容器固定宽度 大屏(>=1200px 中屏(>=992px 小屏(>=768px
watchEffect(() => { watchEffect(() => {
if (width.value < WIDTH) { if (width.value < WIDTH) {
appStore.toggleDevice("mobile"); appStore.toggleDevice("mobile");
@@ -166,13 +166,19 @@ function toggleSidebar() {
} }
:deep(.el-menu-item), :deep(.el-menu-item),
:deep(.el-sub-menu__title) { :deep(.el-sub-menu__title),
:deep(.el-menu--horizontal) {
height: $navbar-height; height: $navbar-height;
line-height: $navbar-height; line-height: $navbar-height;
} }
:deep(.el-menu--collapse) {
width: 100%;
}
} }
.main-container { .main-container {
margin-top: $navbar-height;
margin-left: 0; margin-left: 0;
} }
} }
@@ -199,9 +205,10 @@ function toggleSidebar() {
} }
} }
.fixed-header { &.hideSidebar {
top: $navbar-height; .sidebar-container {
width: calc(100% - $sidebar-width); width: 100% !important;
}
} }
.mix-container { .mix-container {
@@ -244,6 +251,10 @@ function toggleSidebar() {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
margin-left: 0; margin-left: 0;
.fixed-header {
top: $navbar-height;
}
} }
} }
} }
@@ -262,6 +273,7 @@ function toggleSidebar() {
} }
.fixed-header { .fixed-header {
left: $sidebar-width-collapsed;
width: calc(100% - $sidebar-width-collapsed); width: calc(100% - $sidebar-width-collapsed);
} }