<script setup lang="ts">
const videoStore = useVideoStore()
const currentVideo = computed(() => videoStore.videos[videoStore.currentIndex])
// 移动端上下滑动切换(防抖)
const handleScroll = useThrottleFn(() => {
if (process.client) {
const scrollTop = window.scrollY
const windowHeight = window.innerHeight
const newIndex = Math.round(scrollTop / windowHeight)
if (newIndex !== videoStore.currentIndex) {
videoStore.currentIndex = newIndex % videoStore.videos.length
}
}
}, 100)
onMounted(() => {
window.addEventListener('scroll', handleScroll, { passive: true })
})
onUnmounted(() => {
window.removeEventListener('scroll', handleScroll)
})
</script>
<template>
<div class="min-h-screen bg-black text-white">
<!-- 移动端布局 -->
<div class="md:hidden">
<div class="fixed inset-0 snap-y snap-mandatory overflow-y-scroll scrollbar-hide">
<div v-for="(video, index) in videoStore.videos" :key="video.id" class="snap-center h-screen relative">
<VideoPlayer :video="video" :is-active="index === videoStore.currentIndex" />
</div>
</div>
<!-- 移动端顶部搜索 + 底部导航 -->
<MobileHeader />
<MobileBottomNav />
</div>
<!-- PC/平板布局 -->
<div class="hidden md:flex h-screen">
<!-- 左侧导航 -->
<PcSidebar />
<!-- 中间视频列表 -->
<div class="w-full lg:w-2/3 xl:w-3/5 overflow-y-auto">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4 p-4">
<VideoCard v-for="video in videoStore.videos" :key="video.id" :video="video" />
</div>
</div>
<!-- 右侧推荐 -->
<PcRightSidebar class="hidden xl:block" />
</div>
</div>
</template>