import { Fragment, useRef, useState } from 'react' import { Dialog, Transition } from '@headlessui/react' import { usePlogGlobal } from '..' import { ArrowPath, ChevronLeft, ChevronRight } from '@/components/HeroIcons' import Link from 'next/link' import { siteConfig } from '@/lib/config' import LazyImage from '@/components/LazyImage' import { compressImage } from '@/lib/notion/mapImage' /** * 弹出框 */ export default function Modal(props) { const { showModal, setShowModal, modalContent, setModalContent } = usePlogGlobal() const { siteInfo, posts } = props const cancelButtonRef = useRef(null) const img = compressImage(modalContent?.pageCover || siteInfo?.pageCover, 1200, 85, 'webp') const imgRef = useRef(null) // 添加loading状态 const [loading, setLoading] = useState(true) // 在图片加载完成时设置loading为false function handleImageLoad() { setLoading(false) } // 关闭弹窗 function handleClose() { setShowModal(false) setLoading(true) } // 修改当前显示的遮罩内容 function prev() { setLoading(true) const index = posts?.findIndex(post => post.slug === modalContent.slug) if (index === 0) { setModalContent(posts[posts.length - 1]) } else { setModalContent(posts[index - 1]) } } // 下一个 const next = () => { setLoading(true) const index = posts.findIndex(post => post.slug === modalContent.slug) if (index === posts.length - 1) { setModalContent(posts[0]) } else { setModalContent(posts[index + 1]) } } return ( {/* 遮罩 */}
{/* 添加loading状态 */}
{/* 添加onLoad事件处理函数 */} {!loading && (<>

{modalContent?.title}

{modalContent?.summary}
{modalContent?.category && (
{modalContent?.category}
)}
)}
) }