From 1d14ade6b5b75b7f7e37958d95f8bb6a6dcc036d Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 10 四月 2023 18:33:40 +0800 Subject: [PATCH] 优化避免鼠标移出时无法隐藏滚动条的问题 --- src/layout/index.vue | 63 +++++++++++++++++++++---------- 1 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/layout/index.vue b/src/layout/index.vue index 50fda30..b81b4b3 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -1,15 +1,17 @@ <template> <div :class="classObj" class="app-wrapper" :style="{ '--current-color': theme }"> <div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside"/> - <sidebar class="sidebar-container" /> - <div :class="{ hasTagsView: needTagsView }" class="main-container"> - <div :class="{ 'fixed-header': fixedHeader }"> - <navbar @setLayout="setLayout" /> - <tags-view v-if="needTagsView" /> - </div> - <app-main /> - <settings ref="settingRef" /> - </div> + <sidebar v-if="!sidebar.hide" class="sidebar-container" /> + <div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container"> + <el-scrollbar> + <div :class="{ 'fixed-header': fixedHeader }"> + <navbar @setLayout="setLayout" /> + <tags-view v-if="needTagsView" /> + </div> + <app-main /> + <settings ref="settingRef" /> + </el-scrollbar> + </div> </div> </template> @@ -19,13 +21,16 @@ import { AppMain, Navbar, Settings, TagsView } from './components' import defaultSettings from '@/settings' -const store = useStore(); -const theme = computed(() => store.state.settings.theme); -const sideTheme = computed(() => store.state.settings.sideTheme); -const sidebar = computed(() => store.state.app.sidebar); -const device = computed(() => store.state.app.device); -const needTagsView = computed(() => store.state.settings.tagsView); -const fixedHeader = computed(() => store.state.settings.fixedHeader); +import useAppStore from '@/store/modules/app' +import useSettingsStore from '@/store/modules/settings' + +const settingsStore = useSettingsStore() +const theme = computed(() => settingsStore.theme); +const sideTheme = computed(() => settingsStore.sideTheme); +const sidebar = computed(() => useAppStore().sidebar); +const device = computed(() => useAppStore().device); +const needTagsView = computed(() => settingsStore.tagsView); +const fixedHeader = computed(() => settingsStore.fixedHeader); const classObj = computed(() => ({ hideSidebar: !sidebar.value.opened, @@ -39,18 +44,18 @@ watchEffect(() => { if (device.value === 'mobile' && sidebar.value.opened) { - store.dispatch('app/closeSideBar', { withoutAnimation: false }) + useAppStore().closeSideBar({ withoutAnimation: false }) } if (width.value - 1 < WIDTH) { - store.dispatch('app/toggleDevice', 'mobile') - store.dispatch('app/closeSideBar', { withoutAnimation: true }) + useAppStore().toggleDevice('mobile') + useAppStore().closeSideBar({ withoutAnimation: true }) } else { - store.dispatch('app/toggleDevice', 'desktop') + useAppStore().toggleDevice('desktop') } }) function handleClickOutside() { - store.dispatch('app/closeSideBar', { withoutAnimation: false }) + useAppStore().closeSideBar({ withoutAnimation: false }) } const settingRef = ref(null); @@ -68,6 +73,18 @@ position: relative; height: 100%; width: 100%; + + .el-scrollbar { + height: 100%; + } + + :deep(.el-scrollbar__bar).is-vertical { + z-index: 10; + } + + :deep(.el-scrollbar__wrap) { + overflow-x: hidden; + } &.mobile.openSidebar { position: fixed; @@ -98,6 +115,10 @@ width: calc(100% - 54px); } +.sidebarHide .fixed-header { + width: 100%; +} + .mobile .fixed-header { width: 100%; } -- Gitblit v1.9.3