From 4c8f59caadd7ffb459a17c12b9b63de7009d4dab Mon Sep 17 00:00:00 2001 From: Hakadao Date: Sun, 26 Nov 2023 14:05:26 +0800 Subject: [PATCH] fix: resolve the issue with automatic hiding of top bar --- src/components/Topbar/Topbar.vue | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/Topbar/Topbar.vue b/src/components/Topbar/Topbar.vue index 339bb9a9..a45f2118 100644 --- a/src/components/Topbar/Topbar.vue +++ b/src/components/Topbar/Topbar.vue @@ -3,7 +3,7 @@ import type { Ref, UnwrapNestedRefs } from 'vue' import { onMounted, watch } from 'vue' import type { UnReadDm, UnReadMessage, UserInfo } from './types' import { updateInterval } from './notify' -import { getUserID } from '~/utils/main' +import { getUserID, isHomePage } from '~/utils/main' import { settings } from '~/logic' import emitter from '~/utils/mitt' import type { AppPage } from '~/enums/appEnums' @@ -20,6 +20,7 @@ const props = withDefaults(defineProps(), { }) const activatedPage = inject('activatedPage') as Ref +const scrollbarRef = inject('scrollbarRef') as Ref const mid = getUserID() || '' const userInfo = reactive({}) as UnwrapNestedRefs @@ -110,8 +111,26 @@ async function initData() { }, updateInterval) } +let oldScrollTop = 0 // Function to handle the wheel event with type annotation for the event parameter function handleScroll(event: WheelEvent): void { + let scrollTop = 0 + if (isHomePage()) { + const osInstance = scrollbarRef.value?.osInstance() + scrollTop = osInstance.elements().viewport.scrollTop + } + else { + scrollTop = document.documentElement.scrollTop + } + + if (scrollTop <= 0) + return + + if (scrollTop === oldScrollTop) + return + + oldScrollTop = scrollTop + hideTopbar.value = false if (settings.value.autoHideTopbar && !hovingTopbar.value) {