feat 搭建架构骨架

This commit is contained in:
Ironsp
2026-09-24 09:09:47 +08:00
parent dd9f6b77a4
commit 7a2efa3fea
180 changed files with 18967 additions and 9 deletions

View File

@@ -0,0 +1,26 @@
import { computed, onMounted, onUnmounted, ref, type ComputedRef, type Ref } from 'vue'
/** 滚动监听/吸顶/回到顶部 */
export function useScroll(threshold = 200): {
scrollY: Ref<number>
isAtTop: ComputedRef<boolean>
showBackTop: ComputedRef<boolean>
scrollToTop: (smooth?: boolean) => void
} {
const scrollY = ref(0)
const isAtTop = computed(() => scrollY.value <= 0)
const showBackTop = computed(() => scrollY.value > threshold)
function onScroll(): void {
scrollY.value = window.scrollY
}
function scrollToTop(smooth = true): void {
window.scrollTo({ top: 0, behavior: smooth ? 'smooth' : 'auto' })
}
onMounted(() => window.addEventListener('scroll', onScroll, { passive: true }))
onUnmounted(() => window.removeEventListener('scroll', onScroll))
return { scrollY, isAtTop, showBackTop, scrollToTop }
}