/* eslint-disable jsx-a11y/iframe-has-title */ import React, { useEffect, useRef, useState } from "react"; import styles from "./index.module.scss"; import { baseUrl } from "@/index"; import history, { modelUrl } from "@/utils/history"; import classNames from "classnames"; import { InfoRowType } from "@/types"; import { getUrlHashFu } from "@/utils/data"; import { useLocation } from "react-router-dom"; const iconArr = [ { id: 2, name: "放大" }, { id: 3, name: "缩小" }, { id: 4, name: "复位" }, ]; type Props = { info: InfoRowType; type: "C2ArchitecInfo" | "D2BuildInfo"; }; function ArcOrBuildInfo({ info, type }: Props) { // 嵌套 四维看看 iframe 返回的问题 const location = useLocation(); const [back2, setBack2] = useState(""); useEffect(() => { const query = new URLSearchParams(location.search); const back2 = query.get("back2"); setBack2(back2!); setBack2(back2!); }, [location.search]); // 模型的ref const ifrRefNew = useRef(null); const modelChangeFu = (val: number) => { const dom = ifrRefNew.current; if (dom && dom.contentWindow && dom.contentWindow.webview) { if (val === 2) dom.contentWindow.webview.zoomIn(); // 放大 else if (val === 3) dom.contentWindow.webview.zoomOut(); // 缩小 else dom.contentWindow.webview.resetView(); // 复位 } }; // 点击对比 const [oldShow, setOldShow] = useState(false); useEffect(() => { if (oldShow) setOldFlag(true); }, [oldShow]); const [oldFlag, setOldFlag] = useState(false); // 点击全屏 const [full, setFull] = useState(false); return (
{/* 左下方的按钮 */}
(back2 ? history.push(back2) : history.go(-1))} > 返回
{info.isBuild ? ( <> {info.isBuild.map((v) => (
history.push(`/buildInfo?id=${v.id}`)} > {v.name}
))} ) : null}
{/* 左边信息 */}
{info.name}
{/* 右边模型 */}
{/* VR漫游按钮 */} {type === "C2ArchitecInfo" && info.code ? ( ) : null} {/* 右侧的功能按钮 */}
{/* 是否有对比 */} {info.isOld ? ( ) : null} {iconArr.map((v) => (
modelChangeFu(v.id)} className={classNames("C2rBtnRow", "C2rBtnRow" + v.id)} key={v.id} title={v.name} >
))} {/* 全屏 */}
{ const dom = ifrRefNew.current; if (dom && dom.contentWindow && dom.contentWindow.modelLoding) setFull(!full); }} className={classNames( "C2rBtnRow", "C2rBtnRow5", full ? "C2rBtnRow5Ac" : "" )} title={full ? "退出全屏" : "全屏"} >
{/* 点击对比打开的元素 */} {oldFlag ? (
{info.isOld ? ( <>
{info.isOld.name}
{/* 线 */}
{/* 模型或者图片 */} {info.isOld.type === "model" ? ( ) : ( )} ) : null}
setOldShow(false)}>
) : null}
); } const MemoArcOrBuildInfo = React.memo(ArcOrBuildInfo); export default MemoArcOrBuildInfo;