From bfd067619698292b10a3553912900c811257e6ca Mon Sep 17 00:00:00 2001 From: liqi Date: Wed, 17 Dec 2025 13:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CinematicSlideshow.vue | 33 +++++++++++++++++---------- src/components/SwipeSlideshow.vue | 1 - 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/components/CinematicSlideshow.vue b/src/components/CinematicSlideshow.vue index 1521a0e..9ef99fd 100644 --- a/src/components/CinematicSlideshow.vue +++ b/src/components/CinematicSlideshow.vue @@ -151,6 +151,7 @@ let accumulatedTime = 0 let rafId = null let controlsTimer = null let isSwitching = false +const loadedImageUrls = new Set() // 记录已加载的图片 URL,避免重复加载检测 const currentPhoto = computed(() => props.photos[currentIndex.value]) // 加载期间给个默认背景或黑屏,避免报错 @@ -205,6 +206,7 @@ const preloadAllImages = async () => { const promises = props.photos.map(photo => { const url = getImgUrl(photo.original || photo.compressed) return loadImage(url).then(() => { + loadedImageUrls.add(url) // 记录已加载的 URL loadedCount.value++ loadingProgress.value = Math.floor((loadedCount.value / totalCount.value) * 100) }) @@ -251,15 +253,17 @@ const loop = (timestamp) => { const handleAutoSwitch = async () => { isSwitching = true const nextIdx = (currentIndex.value + 1) % props.photos.length - - // 即使预加载过,也检查一下(通常会立即返回) const nextPhoto = props.photos[nextIdx] const nextUrl = getImgUrl(nextPhoto.original || nextPhoto.compressed) - const bufferTimeout = setTimeout(() => { isBuffering.value = true }, 100) - await loadImage(nextUrl) - clearTimeout(bufferTimeout) - isBuffering.value = false + // 只有未加载过的图片才需要等待加载 + if (!loadedImageUrls.has(nextUrl)) { + const bufferTimeout = setTimeout(() => { isBuffering.value = true }, 100) + await loadImage(nextUrl) + loadedImageUrls.add(nextUrl) + clearTimeout(bufferTimeout) + isBuffering.value = false + } nextSlide(true) isSwitching = false @@ -286,13 +290,18 @@ const prevSlide = async () => { accumulatedTime = 0 progress.value = 0 const prevIdx = (currentIndex.value - 1 + props.photos.length) % props.photos.length - - isSwitching = true - isBuffering.value = true const prevPhoto = props.photos[prevIdx] - await loadImage(getImgUrl(prevPhoto.original || prevPhoto.compressed)) - isBuffering.value = false - isSwitching = false + const prevUrl = getImgUrl(prevPhoto.original || prevPhoto.compressed) + + // 只有未加载过的图片才需要显示 buffering + if (!loadedImageUrls.has(prevUrl)) { + isSwitching = true + isBuffering.value = true + await loadImage(prevUrl) + loadedImageUrls.add(prevUrl) + isBuffering.value = false + isSwitching = false + } currentIndex.value = prevIdx emit('update:index', currentIndex.value) diff --git a/src/components/SwipeSlideshow.vue b/src/components/SwipeSlideshow.vue index 176cf12..53f9418 100644 --- a/src/components/SwipeSlideshow.vue +++ b/src/components/SwipeSlideshow.vue @@ -81,7 +81,6 @@