/* eslint-disable jsx-a11y/iframe-has-title */ import { useEffect, useRef, useState } from "react"; import musicImg from "@/assets/img/music.png"; import musicImgAc from "@/assets/img/musicAc.png"; import styles from "./index.module.scss"; import { baseURL } from "@/utils/http"; import { useLocation } from "react-router-dom"; import { useDispatch, useSelector } from "react-redux"; import { getModelInfo } from "@/store/action/home"; import { RootState } from "@/store"; export default function Model() { const location = useLocation(); const dispatch = useDispatch(); // 发送请求获取信息,存到仓库 useEffect(() => { const arr = location.search.split("="); const id = arr[1]; dispatch(getModelInfo(id)); }, [dispatch, location.search]); // 从仓库获取信息 const info = useSelector((state: RootState) => state.homeStore.qrModel); // 控制模型放大缩小和复位 const ifrBoxRef = useRef(null); const modelChangeFu = (val: number) => { const dom = ifrBoxRef.current; if (dom && dom.contentWindow && dom.contentWindow.webview) { if (val === 1) dom.contentWindow.webview.zoomIn(); // 放大 else if (val === 2) dom.contentWindow.webview.zoomOut(); // 缩小 else dom.contentWindow.webview.resetView(); // 复位 } }; // 控制音乐播放暂停 const musicRef = useRef(null); const [music, setMusic] = useState(false); const musicPlayFu = (flag: boolean) => { const dom = musicRef.current; if (dom) { if (flag) { // 打开音乐 setMusic(true); dom.play(); dom.addEventListener( "ended", function () { setMusic(false); }, false ); } else { // 关闭音乐 setMusic(false); dom.pause(); } } }; return (
{/* 音频 */} {info.audioPath ? ( ) : null} {/* 模型盒子 */}
{info.fileName ? ( ) : null}
{/* 右边介绍 */}
{info.name}
{info.description ? (
) : (
暂无信息
)}
类别:

{info.dictTextureName ? info.dictTextureName : "(空)"}

年代:

{info.dictAgeName ? info.dictAgeName : "(空)"}

{
尺寸:

{info.sizeLength ? info.sizeLength : "(空)"}

}
{/* 底部按钮 */}
modelChangeFu(1)} >
modelChangeFu(2)} >
{info.audioPath ? (
{music ? ( musicPlayFu(false)} /> ) : ( musicPlayFu(true)} /> )}
) : null}
modelChangeFu(3)} >
); }