import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faClose } from "@fortawesome/free-solid-svg-icons"; import { Dialog, Toast } from "antd-mobile"; import html2canvas from "html2canvas"; import { checkRole } from "../auth"; import VideoPlayer from "@/components/VideoPlayer"; // export const handleShowVideos = (video) => { // Dialog.className = "videoMask"; // Dialog.show({ // title: "", // closeOnMaskClick: true, // content: ( //
//
//
Dialog.clear()} // > // //
//
//
// //
// {/*
// //
*/} //
// ), // bodyStyle: { // background: "none", // maxHeight: "none", // height: "100%", // }, // }); // }; export const handleShowVideo = (video) => { document.body.style.overflow = "hidden"; const scrollY = window.scrollY; Dialog.className = "videoMask"; Dialog.show({ title: "", bodyClassName: "!p-0", content: (
{ if (scrollY !== 0) { window.scrollTo(0, scrollY); } Dialog.clear(); }} >
{/* */} {/*
{/*
saveFile(video.mp4)} >
*/}
), bodyStyle: { background: "none", maxHeight: "none", height: "100%", }, closeOnMaskClick: true, onClose: () => { document.body.style.overflow = "visible"; }, }); }; //保存div内容为图片 export const saveDivImage = async (divId) => { if (typeof window == "undefined") return; const div = document.getElementById(divId); html2canvas(div, { useCORS: true }).then(function (canvas) { // 创建一个图片元素 var img = canvas.toDataURL("image/jpg"); // 创建一个链接元素 var link = document.createElement("a"); link.href = img; // 设置下载的文件名 link.download = "SAVE_IMAGE.jpg"; // 触发点击 link.click(); }); }; //保存图片 export const saveImage = async (url) => { if (typeof window == "undefined") return; fetch(url) .then((res) => res.blob()) .then((blob) => { const url = URL.createObjectURL(blob); // 创建一个链接元素 var link = document.createElement("a"); link.href = url; // 设置下载的文件名 link.download = "SAVE_IMAGE.jpg"; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); }) .catch((error) => console.log(error)); }; export const saveFile = async (href) => { const isVip = await checkRole(); if (!isVip) { // setIsVipModalVisible(true); Toast.show({ icon: "fail", content: "仅会员支持下载", position: "top", }); return; } if (typeof window == "undefined") return; var link = document.createElement("a"); link.href = href; link.target = "_blank"; // 设置下载的文件名 link.download = "newfile.mp4"; // 触发点击 // link.click(); link.style.display = "none"; // 设置为隐藏元素 document.body.appendChild(link); link.click(); // 模拟点击以开始下载 document.body.removeChild(link); // 下载后移除元素 }; export const toggleFullScreen = (videoEleId, controllerId, getState) => { const video = document.getElementById(videoEleId); const controller = document.getElementById(controllerId); const videoHeight = window.getComputedStyle(video).height; const videoWidth = window.getComputedStyle(video).width; if (!document.fullscreenElement) { if (video.requestFullscreen) { video.requestFullscreen(); } else if (video.mozRequestFullScreen) { // Firefox video.mozRequestFullScreen(); } else if (video.webkitRequestFullscreen) { // Chrome, Safari and Opera video.webkitRequestFullscreen(); } else if (video.msRequestFullscreen) { // IE/Edge video.msRequestFullscreen(); } // console.log("toggleFullScreen", video); if (!video || !controller) return; // video.style.transform = // "translateX(50vw) translateY(-24.4vh) rotate(90deg) !important"; // video.firstChild.className = "h-[100vw] w-[100vh] origin-left"; // video.firstChild.style = { // transform: "translateX(50vw) translateY(-24.4vh) rotate(90deg) !important", // width: "100vh", // height: "100vw", // transformOrigin: "left", // }; if (videoWidth < videoHeight) { video.firstChild.style.width = "100vw"; video.firstChild.style.height = "100vh"; controller.style.width = "100vw"; controller.style.height = "100vh"; // controller.firstChild.style.marginLeft = "10px"; // controller.firstChild.style.transform = "rotate(180deg)"; // controller.firstChild.style.transformOrigin = "center center"; } else { video.firstChild.style.transform = "translateX(50vw) translateY(-24.4vh) rotate(90deg)"; video.firstChild.style.width = "100vh"; video.firstChild.style.height = "100vw"; video.firstChild.style.transformOrigin = "left"; controller.style.width = "100vw"; controller.style.height = "100vh"; controller.firstChild.style.marginLeft = "10px"; // controller.firstChild.style.transform = "rotate(180deg)"; // controller.firstChild.style.transformOrigin = "center center"; } getState((old) => !old); } else { // console.log("toggleFullScreen", video); if (!video || !controller) return; // video.style.transform = // "translateX(50vw) translateY(-24.4vh) rotate(90deg) !important"; // video.firstChild.className = "h-[100vw] w-[100vh] origin-left"; // video.firstChild.style = { // transform: "translateX(50vw) translateY(-24.4vh) rotate(90deg) !important", // width: "100vh", // height: "100vw", // transformOrigin: "left", // }; video.firstChild.style.transform = "none"; video.firstChild.style.width = "auto"; video.firstChild.style.height = "auto"; video.firstChild.style.transformOrigin = ""; controller.style.width = "100%"; controller.style.height = "100%"; controller.firstChild.style.marginLeft = "0"; // controller.firstChild.style.transform = "rotate(180deg)"; // controller.firstChild.style.transformOrigin = "center center"; if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.mozCancelFullScreen) { // Firefox document.mozCancelFullScreen(); } else if (document.webkitExitFullscreen) { // Chrome, Safari and Opera document.webkitExitFullscreen(); } else if (document.msExitFullscreen) { // IE/Edge document.msExitFullscreen(); } getState((old) => !old); } };