修改看图功能
This commit is contained in:
parent
068bfaef5d
commit
0e6938f5a4
|
@ -245,7 +245,7 @@ footer{
|
||||||
.adm-floating-panel .adm-floating-panel-content {
|
.adm-floating-panel .adm-floating-panel-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
background: rgb(7 5 10/ var(--tw-bg-opacity));
|
background: rgb(7 5 10/ var(--tw-bg-opacity))!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.adm-list>div>div>div>div{
|
.adm-list>div>div>div>div{
|
||||||
|
|
|
@ -11,45 +11,44 @@ import { Mask, Image } from "antd-mobile";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faAngleLeft, faAngleRight } from "@fortawesome/free-solid-svg-icons";
|
import { faAngleLeft, faAngleRight } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import baseRequest from "@/utils/baseRequest";
|
||||||
const root = createRoot(document?.getElementById("maskDomBox"));
|
const root = createRoot(document?.getElementById("maskDomBox"));
|
||||||
function ImagesMask({}, ref) {
|
function ImagesMask({}, ref) {
|
||||||
const [currentIndex, setCurrentIndex] = useState(0);
|
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [images, setImages] = useState([]);
|
const [images, setImages] = useState([]);
|
||||||
|
const [data, setData] = useState(null);
|
||||||
const scrollRef = useRef(null);
|
const scrollRef = useRef(null);
|
||||||
|
const defaultIndex = useRef(null);
|
||||||
|
const router = useRouter();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
root.render(
|
root.render(
|
||||||
<div>
|
<div>
|
||||||
<ImagesMaskContaint
|
<ImagesMaskContaint
|
||||||
images={images}
|
images={images}
|
||||||
visible={visible}
|
visible={visible}
|
||||||
currentIndex={currentIndex}
|
|
||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
setCurrentIndex={setCurrentIndex}
|
|
||||||
setVisible={setVisible}
|
setVisible={setVisible}
|
||||||
setImages={setImages}
|
setImages={setImages}
|
||||||
|
router={router}
|
||||||
|
data={data}
|
||||||
|
defaultIndex={defaultIndex.current}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
// root.render(<div>xxxx</div>);
|
// root.render(<div>xxxx</div>);
|
||||||
}, [visible]);
|
}, [visible]);
|
||||||
useEffect(() => {
|
|
||||||
if (scrollRef.current) {
|
|
||||||
setTimeout(() => {
|
|
||||||
scrollRef.current.scrollLeft = 414 * currentIndex;
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
}, [currentIndex]);
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
show: (arr, index) => {
|
show: (arr, index, data) => {
|
||||||
setCurrentIndex(index);
|
defaultIndex.current = index;
|
||||||
setImages(arr);
|
setImages(arr);
|
||||||
setVisible(old=>{
|
setData(data);
|
||||||
console.log(arr, index,old)
|
setVisible((old) => {
|
||||||
return !old
|
console.log(arr, index, old);
|
||||||
|
return !old;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mask.show
|
// Mask.show
|
||||||
// const maskDomBox = document.getElementById("maskDomBox");
|
// const maskDomBox = document.getElementById("maskDomBox");
|
||||||
},
|
},
|
||||||
|
@ -60,73 +59,192 @@ function ImagesMask({}, ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImagesMaskContaint = forwardRef(
|
const ImagesMaskContaint = forwardRef(
|
||||||
({ visible, images, currentIndex,setCurrentIndex,setVisible,setImages }, ref) => {
|
(
|
||||||
|
{ visible, images, setVisible, setImages, router, data, defaultIndex = 0 },
|
||||||
|
ref
|
||||||
|
) => {
|
||||||
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
const [distance, setDistance] = useState(0);
|
const [distance, setDistance] = useState(0);
|
||||||
|
const [direction, setDirection] = useState("left");
|
||||||
|
const [initialX, setInitialX] = useState(0);
|
||||||
|
const [currentX, setCurrentX] = useState(0);
|
||||||
|
const [xOffset, setXOffset] = useState(0);
|
||||||
|
const [active, setActive] = useState(false);
|
||||||
|
const base = baseRequest();
|
||||||
const getDistance = (e) => {
|
const getDistance = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const distance = ref.current.scrollLeft;
|
const distance = ref.current.scrollLeft;
|
||||||
setDistance(distance);
|
setDistance(distance);
|
||||||
};
|
};
|
||||||
const handleMoveImages = (e, index) => {
|
useEffect(() => {
|
||||||
e.stopPropagation();
|
setCurrentIndex(defaultIndex);
|
||||||
// console.log("distance",distance)
|
setTimeout(() => {
|
||||||
if (
|
// console.log("ref.current", ref.current);
|
||||||
distance > window.innerWidth * currentIndex &&
|
if (ref.current) {
|
||||||
distance < window.innerWidth + window.innerWidth * currentIndex
|
ref.current.style.transform = `translateX(${
|
||||||
) {
|
-window.innerWidth * defaultIndex
|
||||||
setCurrentIndex(Math.ceil(distance / 414));
|
}px)`;
|
||||||
} else if (distance < window.innerWidth * currentIndex) {
|
}
|
||||||
setCurrentIndex(Math.ceil(distance / 414) - 1);
|
}, 100);
|
||||||
|
}, [defaultIndex]);
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("ref.current", ref.current);
|
||||||
|
if (ref.current) {
|
||||||
|
ref.current.style.transform = `translateX(${
|
||||||
|
-window.innerWidth * currentIndex
|
||||||
|
}px)`;
|
||||||
}
|
}
|
||||||
|
}, [currentIndex]);
|
||||||
|
const test1 = (e) => {
|
||||||
|
console.log(
|
||||||
|
e.touches[0].clientX - (!currentIndex ? 0 : xOffset),
|
||||||
|
e.touches[0].clientX,
|
||||||
|
xOffset
|
||||||
|
);
|
||||||
|
setInitialX(e.touches[0].clientX - (!currentIndex ? 0 : xOffset));
|
||||||
|
if (e.touches.length === 1) {
|
||||||
|
// 单点触摸
|
||||||
|
setActive(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const test2 = (e) => {
|
||||||
|
if (active) {
|
||||||
|
// e.preventDefault();
|
||||||
|
let X =
|
||||||
|
e.touches[0].clientX -
|
||||||
|
window.innerWidth * (currentIndex ? 1 : currentIndex + 1);
|
||||||
|
console.log("-----", e.touches[0].clientX, initialX, currentIndex);
|
||||||
|
setCurrentX((old) => {
|
||||||
|
setDirection(X > old ? "right" : "left");
|
||||||
|
return X;
|
||||||
|
});
|
||||||
|
setXOffset(X);
|
||||||
|
ref.current.style.transform = "translateX(" + X + "px)";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const test3 = (index) => {
|
||||||
|
console.log("index", index);
|
||||||
|
// setInitialX(currentX);
|
||||||
|
setActive(false);
|
||||||
|
let cxOffset = window.innerWidth;
|
||||||
|
console.log(direction, index, images.length - 1);
|
||||||
|
if (direction == "left") {
|
||||||
|
if (index < images.length - 1) {
|
||||||
|
setCurrentIndex(index + 1);
|
||||||
|
console.log(index + 1);
|
||||||
|
} else {
|
||||||
|
ref.current.style.transform = `translateX(${-cxOffset * index}px)`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (index > 0) {
|
||||||
|
setCurrentIndex(index - 1);
|
||||||
|
console.log(index - 1);
|
||||||
|
} else {
|
||||||
|
ref.current.style.transform = `translateX(${-cxOffset * index}px)`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setInitialX(currentX);
|
||||||
|
// setInitialX(-cxOffset * (index + 1));
|
||||||
|
setXOffset(-cxOffset * (index || 1));
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Mask
|
<Mask
|
||||||
visible={visible}
|
visible={visible}
|
||||||
className="z-[1002] h-screen flex justify-center items-center"
|
className="z-[1002] h-screen flex justify-center items-center"
|
||||||
>
|
onMaskClick={() => {
|
||||||
<div className="relative">
|
setVisible(false), setImages([]), setCurrentIndex(0);
|
||||||
<div className="text-center mb-2">
|
// root.unmount();
|
||||||
{currentIndex + 1}/{images.length}
|
}}
|
||||||
</div>
|
>
|
||||||
<div ref={ref} id="imagesScrollBox" className="flex overflow-auto scrollbarBoxX">
|
<div className="relative">
|
||||||
{images.map((item, index) => {
|
<div className="text-center mb-2 leading-[54px]">
|
||||||
return (
|
{currentIndex + 1}/{images.length}
|
||||||
<img
|
|
||||||
key={index}
|
|
||||||
src={item}
|
|
||||||
// onTouchMove={(e) => handleMoveImages(e, index)}
|
|
||||||
onTouchMove={getDistance}
|
|
||||||
onTouchEnd={(e) => handleMoveImages(e, index)}
|
|
||||||
onClick={() => {
|
|
||||||
setVisible(false), setImages([]), setCurrentIndex(0);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-between items-center w-screen absolute top-1/2 px-4 pointer-events-none">
|
|
||||||
<div
|
|
||||||
className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full float-left pointer-events-auto"
|
|
||||||
onClick={() => {
|
|
||||||
setCurrentIndex((old) => (old > 0 ? old - 1 : old));
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faAngleLeft} size="xl" />
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full float-left pointer-events-auto"
|
className="flex justify-start items-center"
|
||||||
|
style={{ height: "calc(100vh - 174px)" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setCurrentIndex((old) =>
|
setVisible(false), setImages([]), setCurrentIndex(0);
|
||||||
old < images.length - 1 ? old + 1 : old
|
// root.unmount();
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faAngleRight} size="xl" />
|
<div
|
||||||
|
ref={ref}
|
||||||
|
id="imagesScrollBox"
|
||||||
|
className="flex justify-center items-center"
|
||||||
|
draggable={true}
|
||||||
|
// onTouchStart={test1}
|
||||||
|
// onTouchMove={test2}
|
||||||
|
// onTouchEnd={() => test3(currentIndex)}
|
||||||
|
>
|
||||||
|
{images.map((item, index) => {
|
||||||
|
return (
|
||||||
|
<div key={index} className="flex-none w-screen relative">
|
||||||
|
<img
|
||||||
|
src={item.url}
|
||||||
|
style={{
|
||||||
|
filter: item.type == "hid" ? "blur(10px)" : "none",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="absolute top-1/2 left-1/2 -ml-[100px] -mt-[14px]">
|
||||||
|
{item.type == "hid" && (
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<div
|
||||||
|
className="rounded-full text-sm h-max w-max px-4 py-1 bg-primary"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
"/webView/" +
|
||||||
|
encodeURIComponent(
|
||||||
|
"/zone/pay/" +
|
||||||
|
data?.zid +
|
||||||
|
"/h5_zone_moment/" +
|
||||||
|
data?.id +
|
||||||
|
"?base=" +
|
||||||
|
encodeURIComponent(JSON.stringify(base))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
此内容暂未解锁,立即解锁
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="flex justify-between items-center w-screen absolute top-1/2 px-4 pointer-events-none"
|
||||||
|
style={{
|
||||||
|
marginTop: "calc(-50vh + 118px)",
|
||||||
|
height: "calc(100vh - 174px)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="w-12 h-full flex items-center justify-center rounded-full float-left pointer-events-auto"
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentIndex((old) => (old > 0 ? old - 1 : old));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faAngleLeft} size="xl" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="w-12 h-full flex items-center justify-center rounded-full float-left pointer-events-auto"
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentIndex((old) =>
|
||||||
|
old < images.length - 1 ? old + 1 : old
|
||||||
|
);
|
||||||
|
setInitialX((currentIndex || 1) * window.innerWidth * 2);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faAngleRight} size="xl" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Mask>
|
||||||
</Mask>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { useRouter } from "next/navigation";
|
||||||
import baseRequest from "@/utils/baseRequest";
|
import baseRequest from "@/utils/baseRequest";
|
||||||
import { handleShowVideo } from "@/utils/tools/handleFuns";
|
import { handleShowVideo } from "@/utils/tools/handleFuns";
|
||||||
// import dynamic from 'next/dynamic'
|
// import dynamic from 'next/dynamic'
|
||||||
// import ImagesMask from "@/components/ImagesMask";
|
import ImagesMask from "@/components/ImagesMask";
|
||||||
// const ImagesMask = dynamic(() =>
|
// const ImagesMask = dynamic(() =>
|
||||||
// import('@/components/ImagesMask'), { ssr: false }
|
// import('@/components/ImagesMask'), { ssr: false }
|
||||||
// )
|
// )
|
||||||
|
@ -84,15 +84,15 @@ export default function Photos({
|
||||||
}, []);
|
}, []);
|
||||||
const showPhotos = (photos, index) => {
|
const showPhotos = (photos, index) => {
|
||||||
currentIndex.current = index;
|
currentIndex.current = index;
|
||||||
const interval = setInterval(() => {
|
// const interval = setInterval(() => {
|
||||||
const bodyBox = document.getElementsByClassName("photos-bodyBox")[0];
|
// const bodyBox = document.getElementsByClassName("photos-bodyBox")[0];
|
||||||
if (bodyBox) {
|
// if (bodyBox) {
|
||||||
bodyBox.firstChild.lastChild.style.transform = `translateX(-${
|
// bodyBox.firstChild.lastChild.style.transform = `translateX(-${
|
||||||
currentIndex.current * (window.innerWidth + 16)
|
// currentIndex.current * (window.innerWidth + 16)
|
||||||
}px)`;
|
// }px)`;
|
||||||
// console.log(bodyBox.firstChild.lastChild.style.transform);
|
// // console.log(bodyBox.firstChild.lastChild.style.transform);
|
||||||
}
|
// }
|
||||||
}, 400);
|
// }, 400);
|
||||||
|
|
||||||
// 添加左右切换按钮
|
// 添加左右切换按钮
|
||||||
// const btns = document.createElement("div");
|
// const btns = document.createElement("div");
|
||||||
|
@ -129,65 +129,62 @@ export default function Photos({
|
||||||
// });
|
// });
|
||||||
// btns.append(btnL, btnR);
|
// btns.append(btnL, btnR);
|
||||||
// handleShowImages(index, photos, btns,interval);
|
// handleShowImages(index, photos, btns,interval);
|
||||||
handleShowImages(index, photos, interval);
|
// handleShowImages(index, photos, interval);
|
||||||
|
|
||||||
// setVisible(true)
|
// setVisible(true)
|
||||||
// console.log(imagesMaskRef.current);
|
console.log(imagesMaskRef.current, photos);
|
||||||
// imagesMaskRef.current.show(
|
imagesMaskRef.current.show(photos, index, data);
|
||||||
// photos.map((item) => item?.url),
|
|
||||||
// index
|
|
||||||
// );
|
|
||||||
};
|
};
|
||||||
const handleShowImages = (index, photos, interval) => {
|
// const handleShowImages = (index, photos, interval) => {
|
||||||
const mediaDom = document.createElement("div");
|
// const mediaDom = document.createElement("div");
|
||||||
mediaDom.style.width = "100vw";
|
// mediaDom.style.width = "100vw";
|
||||||
document.body.appendChild(mediaDom);
|
// document.body.appendChild(mediaDom);
|
||||||
mediaDom.className = `${
|
// mediaDom.className = `${
|
||||||
photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom"
|
// photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom"
|
||||||
}`;
|
// }`;
|
||||||
// mediaDom.appendChild(btns);
|
// // mediaDom.appendChild(btns);
|
||||||
document.body.style.overflow = "hidden";
|
// document.body.style.overflow = "hidden";
|
||||||
ImageViewer.clear();
|
// ImageViewer.clear();
|
||||||
ImageViewer.Multi.show({
|
// ImageViewer.Multi.show({
|
||||||
images: photos.map((item) => item?.url),
|
// images: photos.map((item) => item?.url),
|
||||||
defaultIndex: index,
|
// defaultIndex: index,
|
||||||
renderFooter: (image, index) => {
|
// renderFooter: (image, index) => {
|
||||||
return renderFooter(photos[index]?.type == "hid", mediaDom);
|
// return renderFooter(photos[index]?.type == "hid", mediaDom);
|
||||||
},
|
// },
|
||||||
|
|
||||||
getContainer: mediaDom,
|
// getContainer: mediaDom,
|
||||||
onIndexChange: (index) => {
|
// onIndexChange: (index) => {
|
||||||
currentIndex.current = index;
|
// currentIndex.current = index;
|
||||||
mediaDom.className = `${
|
// mediaDom.className = `${
|
||||||
photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom"
|
// photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom"
|
||||||
}`;
|
// }`;
|
||||||
const leftBtn = document.getElementsByClassName(
|
// const leftBtn = document.getElementsByClassName(
|
||||||
"imagesBtnsControllerLeft"
|
// "imagesBtnsControllerLeft"
|
||||||
)[0];
|
// )[0];
|
||||||
const rightBtn = document.getElementsByClassName(
|
// const rightBtn = document.getElementsByClassName(
|
||||||
"imagesBtnsControllerRight"
|
// "imagesBtnsControllerRight"
|
||||||
)[0];
|
// )[0];
|
||||||
if (leftBtn && rightBtn) {
|
// if (leftBtn && rightBtn) {
|
||||||
if (!index) {
|
// if (!index) {
|
||||||
leftBtn.style.opacity = 0.5;
|
// leftBtn.style.opacity = 0.5;
|
||||||
rightBtn.style.opacity = 1;
|
// rightBtn.style.opacity = 1;
|
||||||
} else if (index == currentPhotos.length - 1) {
|
// } else if (index == currentPhotos.length - 1) {
|
||||||
leftBtn.style.opacity = 1;
|
// leftBtn.style.opacity = 1;
|
||||||
rightBtn.style.opacity = 0.5;
|
// rightBtn.style.opacity = 0.5;
|
||||||
} else {
|
// } else {
|
||||||
leftBtn.style.opacity = 1;
|
// leftBtn.style.opacity = 1;
|
||||||
rightBtn.style.opacity = 1;
|
// rightBtn.style.opacity = 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
afterClose: () => {
|
// afterClose: () => {
|
||||||
mediaDom.remove();
|
// mediaDom.remove();
|
||||||
clearInterval(interval);
|
// clearInterval(interval);
|
||||||
document.body.style.overflow = "auto";
|
// document.body.style.overflow = "auto";
|
||||||
},
|
// },
|
||||||
classNames: { body: "photos-bodyBox" },
|
// classNames: { body: "photos-bodyBox" },
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
const handleSeeAllPhotos = (e) => {
|
const handleSeeAllPhotos = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -343,7 +340,7 @@ export default function Photos({
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
{/* <ImagesMask ref={imagesMaskRef} /> */}
|
<ImagesMask ref={imagesMaskRef} />
|
||||||
{/* <Viewer
|
{/* <Viewer
|
||||||
visible={visible}
|
visible={visible}
|
||||||
onClose={() => { setVisible(false); } }
|
onClose={() => { setVisible(false); } }
|
||||||
|
|
Loading…
Reference in New Issue