diff --git a/app/hosts/[hostname]/page.tsx b/app/hosts/[hostname]/page.tsx index 45fb721..a53f752 100644 --- a/app/hosts/[hostname]/page.tsx +++ b/app/hosts/[hostname]/page.tsx @@ -124,6 +124,7 @@ export default function HostDetail() { const [imagesLoadedCount, setImagesLoadedCount] = useState(0); const [imageAspectRatio, setImageAspectRatio] = useState(16 / 9); const autoPlayTimer = useRef(null); + const wheelDeltaAccumulator = useRef(0); // 格式化内存大小 const formatMemory = (bytes: number | string) => { @@ -516,28 +517,20 @@ export default function HostDetail() { // 播放控制 const nextFrame = () => { - setCurrentFrameIndex(prevIndex => { - if (prevIndex < records.length - 1) { - const newIndex = prevIndex + 1; - setSelectedRecord(records[newIndex]); - return newIndex; - } else { - setAutoPlay(false); - return prevIndex; - } - }); + if (currentFrameIndex < records.length - 1) { + setCurrentFrameIndex(currentFrameIndex + 1); + setSelectedRecord(records[currentFrameIndex + 1]); + } else { + setAutoPlay(false); + } stopAutoPlayTimer(); }; const prevFrame = () => { - setCurrentFrameIndex(prevIndex => { - if (prevIndex > 0) { - const newIndex = prevIndex - 1; - setSelectedRecord(records[newIndex]); - return newIndex; - } - return prevIndex; - }); + if (currentFrameIndex > 0) { + setCurrentFrameIndex(currentFrameIndex - 1); + setSelectedRecord(records[currentFrameIndex - 1]); + } stopAutoPlayTimer(); }; @@ -607,22 +600,37 @@ export default function HostDetail() { // 滚轮事件处理 useEffect(() => { + const WHEEL_THRESHOLD = 20; // 累计多少像素后才切换(可调整) + const handleWheel = (event: WheelEvent) => { - if (event.deltaX < 0) { - // 向左滚动,上一帧 - prevFrame(); - } else if (event.deltaX > 0) { - // 向右滚动,下一帧 - nextFrame(); + // 累计水平滚动距离 + wheelDeltaAccumulator.current += event.deltaX; + + // 检查是否超过阈值 + if (Math.abs(wheelDeltaAccumulator.current) >= WHEEL_THRESHOLD) { + if (wheelDeltaAccumulator.current < 0) { + // 向左滚动,上一帧 + prevFrame(); + } else { + // 向右滚动,下一帧 + nextFrame(); + } + // 重置累计器 + wheelDeltaAccumulator.current = 0; } }; document.addEventListener('wheel', handleWheel, { passive: true }); return () => { document.removeEventListener('wheel', handleWheel); + // 清理累计器 + wheelDeltaAccumulator.current = 0; }; }, [prevFrame, nextFrame]); + + + // Effects useEffect(() => { fetchTimeDistribution(); @@ -810,7 +818,12 @@ export default function HostDetail() { {/* 图片预览区域及控制按钮 */} {selectedRecord && (
- + { + !(navigator as any).connection?.saveData && + records.map(record => record.screenshots).flat() + .filter((_, index) => Math.abs(index - currentFrameIndex) <= 20) + .map(screenshot => ) + } {/* 图片预览区域 */} {selectedRecord.screenshots.map((screenshot, sIndex) => (
@@ -875,8 +888,8 @@ export default function HostDetail() {