Skip to content

Commit

Permalink
refactor: ♻️ 重构布局样式(解决页面抖动问题)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshaptx4869 committed May 28, 2024
1 parent e8d7c00 commit 6822a49
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 123 deletions.
65 changes: 10 additions & 55 deletions src/layout/components/AppMain/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<section class="app-main">
<section class="app-main" :style="{ minHeight: minHeight }">
<router-view>
<template #default="{ Component, route }">
<transition
Expand All @@ -16,67 +16,22 @@
</template>

<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 minHeight = computed(() => {
if (useSettingsStore().tagsView) {
return `calc(100vh - ${variables["navbar-height"]} - ${variables["tags-view-height"]})`;
} else {
return `calc(100vh - ${variables["navbar-height"]})`;
}
});
</script>

<style lang="scss" scoped>
.app-main {
position: relative;
width: 100%;
min-height: calc(100vh - $navbar-height);
overflow: hidden;
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>
78 changes: 10 additions & 68 deletions src/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,13 @@ watch(route, () => {
</script>

<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 {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 999;
width: $sidebar-width;
height: 100%;
overflow: hidden;
background-color: $menu-background;
transition: width 0.28s;
Expand All @@ -137,18 +126,22 @@ watch(route, () => {
.main-container {
position: relative;
min-height: 100%;
height: 100%;
margin-left: $sidebar-width;
overflow-y: auto;
transition: margin-left 0.28s;
}
.layout-top {
.fixed-header {
top: $navbar-height;
width: 100%;
position: sticky;
top: 0;
z-index: 9;
transition: width 0.28s;
}
}
.layout-top {
.sidebar-container {
position: sticky;
z-index: 999;
display: flex;
width: 100% !important;
Expand All @@ -172,8 +165,7 @@ watch(route, () => {
}
.main-container {
min-height: calc(100vh - $navbar-height);
padding-top: $navbar-height;
height: calc(100vh - $navbar-height);
margin-left: 0;
}
}
Expand Down Expand Up @@ -240,30 +232,16 @@ watch(route, () => {
flex: 1;
min-width: 0;
margin-left: 0;
.fixed-header {
top: $navbar-height;
}
}
}
}
.hideSidebar {
.fixed-header {
left: $sidebar-width-collapsed;
width: calc(100% - $sidebar-width-collapsed);
}
.main-container {
margin-left: $sidebar-width-collapsed;
}
&.layout-top {
.fixed-header {
left: 0;
width: 100%;
}
.main-container {
margin-left: 0;
}
Expand All @@ -272,7 +250,6 @@ watch(route, () => {
&.layout-mix {
.fixed-header {
left: $sidebar-width-collapsed;
width: calc(100% - $sidebar-width-collapsed);
}
.sidebar-container {
Expand Down Expand Up @@ -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>
1 change: 1 addition & 0 deletions src/styles/variables.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
:export {
sidebar-width: $sidebar-width;
navbar-height: $navbar-height;
tags-view-height: $tags-view-height;
menu-background: $menu-background;
menu-text: $menu-text;
menu-active-text: $menu-active-text;
Expand Down

0 comments on commit 6822a49

Please sign in to comment.