diff --git a/frontend/src/components/gallery.tsx b/frontend/src/components/gallery.tsx index ea57285..b045c43 100644 --- a/frontend/src/components/gallery.tsx +++ b/frontend/src/components/gallery.tsx @@ -80,10 +80,10 @@ export default function Gallery({ images={images} currentIndex={currentIndex} direction={direction} - isHovered={isHovered} - setIsHovered={setIsHovered} goToPrevious={goToPrevious} goToNext={goToNext} + setDirection={setDirection} + setCurrentIndex={setCurrentIndex} />
; images: number[]; currentIndex: number; direction: number; - isHovered: boolean; - setIsHovered: (hovered: boolean) => void; goToPrevious: () => void; goToNext: () => void; + setDirection: (direction: number) => void; + setCurrentIndex: (index: number) => void; }) { const [width, setWidth] = useState(0); const containerRef = useRef(null); + const thumbnailContainerRef = useRef(null); + const hideTimeoutRef = useRef(null); + const [isHovered, setIsHovered] = useState(true); useEffect(() => { const updateWidth = () => { @@ -221,6 +224,29 @@ function GalleryFullscreen({ }; }, []); + useEffect(() => { + const handleMouseMove = () => { + setIsHovered(true); + if (hideTimeoutRef.current) { + clearTimeout(hideTimeoutRef.current); + } + hideTimeoutRef.current = setTimeout(() => { + setIsHovered(false); + }, 2000); + }; + + if (dialogRef.current?.open) { + window.addEventListener("mousemove", handleMouseMove); + } + + return () => { + window.removeEventListener("mousemove", handleMouseMove); + if (hideTimeoutRef.current) { + clearTimeout(hideTimeoutRef.current); + } + }; + }, [dialogRef.current?.open, setIsHovered]); + useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (dialogRef.current?.open) { @@ -242,6 +268,15 @@ function GalleryFullscreen({ }; }, [dialogRef, goToPrevious, goToNext]); + useEffect(() => { + if (thumbnailContainerRef.current && dialogRef.current?.open) { + const thumbnail = thumbnailContainerRef.current.children[currentIndex] as HTMLElement; + if (thumbnail) { + thumbnail.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" }); + } + } + }, [currentIndex, dialogRef]); + return ( setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} >
- {/* 全屏模式下的指示器 */} + {/* 图片缩略图列表 */}
e.stopPropagation()} > -
- {currentIndex + 1} / {images.length} +
+ {images.map((imageId, index) => ( + + ))}