refactor: ♻️ 重构布局样式(解决页面抖动问题)

This commit is contained in:
cshaptx4869
2024-05-28 14:54:01 +08:00
parent e8d7c004c4
commit 6822a490c7
3 changed files with 22 additions and 124 deletions

View File

@@ -1,5 +1,5 @@
<template> <template>
<section class="app-main"> <section class="app-main" :style="{ minHeight: minHeight }">
<router-view> <router-view>
<template #default="{ Component, route }"> <template #default="{ Component, route }">
<transition <transition
@@ -16,67 +16,22 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useTagsViewStore } from "@/store"; import { useSettingsStore, useTagsViewStore } from "@/store";
import variables from "@/styles/variables.module.scss";
const cachedViews = computed(() => useTagsViewStore().cachedViews); // 缓存页面集合 const cachedViews = computed(() => useTagsViewStore().cachedViews); // 缓存页面集合
const minHeight = computed(() => {
if (useSettingsStore().tagsView) {
return `calc(100vh - ${variables["navbar-height"]} - ${variables["tags-view-height"]})`;
} else {
return `calc(100vh - ${variables["navbar-height"]})`;
}
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.app-main { .app-main {
position: relative; position: relative;
width: 100%;
min-height: calc(100vh - $navbar-height);
overflow: hidden;
background-color: var(--el-bg-color-page); background-color: var(--el-bg-color-page);
} }
.hasTagsView .app-main {
min-height: calc(100vh - $navbar-height - $tags-view-height);
}
.fixed-header + .app-main {
min-height: 100vh;
padding-top: $navbar-height;
}
.hasTagsView .fixed-header + .app-main {
min-height: 100vh;
padding-top: $navbar-height + $tags-view-height;
}
.layout-mix,
.layout-top {
.fixed-header + .app-main {
padding-top: 0;
}
}
.layout-mix {
.app-main {
height: calc(100vh - $navbar-height);
padding-top: 0;
overflow-y: auto;
}
.hasTagsView .app-main {
height: calc(100vh - $navbar-height - $tags-view-height);
min-height: calc(100vh - $navbar-height - $tags-view-height);
}
.fixed-header + .app-main {
min-height: calc(100vh - $navbar-height);
}
.hasTagsView .fixed-header + .app-main {
height: calc(100vh - $navbar-height);
min-height: calc(100vh - $navbar-height);
padding-top: $tags-view-height;
}
}
.layout-top {
.hasTagsView .fixed-header + .app-main {
padding-top: $tags-view-height;
}
}
</style> </style>

View File

@@ -109,15 +109,6 @@ watch(route, () => {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.fixed-header {
position: fixed;
top: 0;
right: 0;
z-index: 9;
width: calc(100% - $sidebar-width);
transition: width 0.28s;
}
.sidebar-container { .sidebar-container {
position: fixed; position: fixed;
top: 0; top: 0;
@@ -125,8 +116,6 @@ watch(route, () => {
left: 0; left: 0;
z-index: 999; z-index: 999;
width: $sidebar-width; width: $sidebar-width;
height: 100%;
overflow: hidden;
background-color: $menu-background; background-color: $menu-background;
transition: width 0.28s; transition: width 0.28s;
@@ -137,18 +126,22 @@ watch(route, () => {
.main-container { .main-container {
position: relative; position: relative;
min-height: 100%; height: 100%;
margin-left: $sidebar-width; margin-left: $sidebar-width;
overflow-y: auto;
transition: margin-left 0.28s; transition: margin-left 0.28s;
.fixed-header {
position: sticky;
top: 0;
z-index: 9;
transition: width 0.28s;
}
} }
.layout-top { .layout-top {
.fixed-header {
top: $navbar-height;
width: 100%;
}
.sidebar-container { .sidebar-container {
position: sticky;
z-index: 999; z-index: 999;
display: flex; display: flex;
width: 100% !important; width: 100% !important;
@@ -172,8 +165,7 @@ watch(route, () => {
} }
.main-container { .main-container {
min-height: calc(100vh - $navbar-height); height: calc(100vh - $navbar-height);
padding-top: $navbar-height;
margin-left: 0; margin-left: 0;
} }
} }
@@ -240,30 +232,16 @@ watch(route, () => {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
margin-left: 0; margin-left: 0;
.fixed-header {
top: $navbar-height;
}
} }
} }
} }
.hideSidebar { .hideSidebar {
.fixed-header {
left: $sidebar-width-collapsed;
width: calc(100% - $sidebar-width-collapsed);
}
.main-container { .main-container {
margin-left: $sidebar-width-collapsed; margin-left: $sidebar-width-collapsed;
} }
&.layout-top { &.layout-top {
.fixed-header {
left: 0;
width: 100%;
}
.main-container { .main-container {
margin-left: 0; margin-left: 0;
} }
@@ -272,7 +250,6 @@ watch(route, () => {
&.layout-mix { &.layout-mix {
.fixed-header { .fixed-header {
left: $sidebar-width-collapsed; left: $sidebar-width-collapsed;
width: calc(100% - $sidebar-width-collapsed);
} }
.sidebar-container { .sidebar-container {
@@ -308,39 +285,4 @@ watch(route, () => {
} }
} }
} }
.mobile {
.fixed-header {
left: 0;
width: 100%;
}
.main-container {
margin-left: 0;
}
&.layout-top {
.sidebar-container {
z-index: 999;
display: flex;
width: 100% !important;
height: $navbar-height;
:deep(.el-scrollbar) {
flex: 1;
min-width: 0;
height: $navbar-height;
}
}
.main-container {
padding-top: $navbar-height;
margin-left: 0;
overflow: hidden;
}
// 顶部模式全局变量修改
--el-menu-item-height: $navbar-height;
}
}
</style> </style>

View File

@@ -2,6 +2,7 @@
:export { :export {
sidebar-width: $sidebar-width; sidebar-width: $sidebar-width;
navbar-height: $navbar-height; navbar-height: $navbar-height;
tags-view-height: $tags-view-height;
menu-background: $menu-background; menu-background: $menu-background;
menu-text: $menu-text; menu-text: $menu-text;
menu-active-text: $menu-active-text; menu-active-text: $menu-active-text;