/** * Fullscreen image slideshow for admin feedback / media lists. */ import { useEffect, useCallback } from 'react' import { resolveMediaUrl } from './MediaValue' type Props = { urls: string[] index: number onClose: () => void onIndex: (i: number) => void } export function ImageLightbox({ urls, index, onClose, onIndex }: Props) { const total = urls.length const safeIndex = total ? ((index % total) + total) % total : 0 const src = total ? resolveMediaUrl(urls[safeIndex]) : '' const prev = useCallback(() => { if (!total) return onIndex((safeIndex - 1 + total) % total) }, [onIndex, safeIndex, total]) const next = useCallback(() => { if (!total) return onIndex((safeIndex + 1) % total) }, [onIndex, safeIndex, total]) useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() if (e.key === 'ArrowLeft') prev() if (e.key === 'ArrowRight') next() } window.addEventListener('keydown', onKey) const prevOverflow = document.body.style.overflow document.body.style.overflow = 'hidden' return () => { window.removeEventListener('keydown', onKey) document.body.style.overflow = prevOverflow } }, [onClose, prev, next]) if (!total) return null return (
{total > 1 ? ( <> ) : null}
e.stopPropagation()} >
{safeIndex + 1} / {total} 原图
{total > 1 ? (
e.stopPropagation()} > {urls.map((u, i) => ( ))}
) : null}
) } export function feedbackImageUrls(row: Record): string[] { const raw = row.images if (!Array.isArray(raw)) return [] return raw .filter((u): u is string => typeof u === 'string') .map((u) => u.trim()) .filter((u) => /^https?:\/\//i.test(u)) }