"use client"; import React, { useEffect, useState, useRef } from "react"; import { Image, ImageViewer, Dialog } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleUp, faClose } from "@fortawesome/free-solid-svg-icons"; import { useRouter } from "next/navigation"; import baseRequest from "@/utils/baseRequest"; import Player from "next-video/player"; // import dynamic from 'next/dynamic' // import ImagesMask from "@/components/ImagesMask"; // const ImagesMask = dynamic(() => // import('@/components/ImagesMask'), { ssr: false } // ) export default function Photos({ isUnlocked, mediaVisibleRange, mediaAmount, media, type, data, }) { const [seeAllPhotos, setSeeAllPhotos] = useState(false); const [currentPhotos, setCurrentPhotos] = useState([]); const [photos, setPhotos] = useState([]); const [visible, setVisible] = useState(false); const currentIndex = useRef(); const swiper = useRef(null); const imagesMaskRef = useRef(null); const router = useRouter(); const base = baseRequest(); useEffect(() => { if (media) { let imgArr = media.images.map((item) => ({ type: "img", url: item.urls?.[0], })); let videoArr = media.videos.map((item) => ({ type: "video", url: item.cover_urls?.[0], mp4: item.urls?.[0], })); let arr = [...imgArr, ...videoArr]; let newPhotos = [...arr]; if (mediaAmount && !isUnlocked) { // console.log("newPhotos", newPhotos); newPhotos = Array(mediaAmount) .fill(null) .map((item, index) => { return newPhotos[index] && mediaVisibleRange ? newPhotos[index] : { mp4: newPhotos[0]?.type === "video", url: newPhotos[0]?.url, type: "hid", }; }); } setPhotos(newPhotos); if (newPhotos.length > 9) { newPhotos = newPhotos.slice(0, 9); } // console.log("newPhotos", newPhotos); setCurrentPhotos(newPhotos); } }, [media]); const showPhotos = (photos, index) => { currentIndex.current = index; const interval = setInterval(() => { console.log("bbbbbb") const bodyBox = document.getElementsByClassName("photos-bodyBox")[0]; if (bodyBox) { bodyBox.firstChild.lastChild.style.transform = `translateX(-${ currentIndex.current * (window.innerWidth + 16) }px)`; // console.log(bodyBox.firstChild.lastChild.style.transform); } }, 400); // 添加左右切换按钮 // const btns = document.createElement("div"); // btns.className = "imagesBtnsControllers"; // const btnL = document.createElement("div"); // btnL.className = "imagesBtnsControllerLeft"; // btnL.addEventListener("click", () => { // if (currentIndex.current > 0) { // currentIndex.current = currentIndex.current - 1; // handleShowImages(currentIndex.current, photos, btns,interval); // if (!currentIndex.current) { // btnL.style.opacity = 0.5; // btnR.style.opacity = 1; // } else { // btnR.style.opacity = 1; // btnL.style.opacity = 1; // } // } // }); // const btnR = document.createElement("div"); // btnR.className = "imagesBtnsControllerRight"; // btnR.addEventListener("click", () => { // if (currentIndex.current < currentPhotos.length - 1) { // currentIndex.current = currentIndex.current + 1; // handleShowImages(currentIndex.current, photos, btns,interval); // if (currentIndex.current == currentPhotos.length - 1) { // btnR.style.opacity = 0.5; // btnL.style.opacity = 1; // } else { // btnR.style.opacity = 1; // btnL.style.opacity = 1; // } // } // }); // btns.append(btnL, btnR); // handleShowImages(index, photos, btns,interval); handleShowImages(index, photos, interval); // setVisible(true) // console.log(imagesMaskRef.current); // imagesMaskRef.current.show( // photos.map((item) => item?.url), // index // ); }; const handleShowImages = (index, photos, interval) => { const mediaDom = document.createElement("div"); mediaDom.style.width = "100vw"; document.body.appendChild(mediaDom); mediaDom.className = `${ photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom" }`; // mediaDom.appendChild(btns); ImageViewer.clear(); ImageViewer.Multi.show({ images: photos.map((item) => item?.url), defaultIndex: index, renderFooter: (image, index) => { return renderFooter(photos[index]?.type == "hid", mediaDom); }, getContainer: mediaDom, onIndexChange: (index) => { currentIndex.current = index; mediaDom.className = `${ photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom" }`; const leftBtn = document.getElementsByClassName("imagesBtnsControllerLeft")[0] const rightBtn = document.getElementsByClassName("imagesBtnsControllerRight")[0] if(leftBtn && rightBtn){ if(!index){ leftBtn.style.opacity=0.5 rightBtn.style.opacity=1 }else if(index==currentPhotos.length-1){ leftBtn.style.opacity=1 rightBtn.style.opacity=0.5 }else{ leftBtn.style.opacity=1 rightBtn.style.opacity=1 } } }, afterClose: () => { mediaDom.remove(); clearInterval(interval); }, classNames: { body: "photos-bodyBox" }, }); }; const handleShowVideo = (video) => { Dialog.className = "videoMask"; Dialog.show({ title: "", content: (