|
@@ -0,0 +1,234 @@
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import { useLocation } from "react-router-dom";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import KrpanoCom from "@/components/KrpanoCom";
|
|
|
+import { baseUrl } from "@/index";
|
|
|
+import classNames from "classnames";
|
|
|
+import history from "@/utils/history";
|
|
|
+import btnImg from "@/assets/img/tab2/btn_m.png";
|
|
|
+import { SwapRightOutlined } from "@ant-design/icons";
|
|
|
+
|
|
|
+function B1VillageM() {
|
|
|
+ const location = useLocation();
|
|
|
+
|
|
|
+ const [uId, setUid] = useState("");
|
|
|
+
|
|
|
+ const villageData = useSelector(
|
|
|
+ (state: RootState) => state.A0Layout.dataAll.village
|
|
|
+ );
|
|
|
+
|
|
|
+ const curScene = useMemo(() => {
|
|
|
+ return (
|
|
|
+ villageData.find((v) => v.id === Number(uId))?.scene ||
|
|
|
+ villageData[0].scene
|
|
|
+ );
|
|
|
+ }, [uId, villageData]);
|
|
|
+
|
|
|
+ //当前村落的 信息
|
|
|
+ const curVillage = useMemo(
|
|
|
+ () =>
|
|
|
+ villageData.find((i) => i.id === Number(uId))?.info ||
|
|
|
+ villageData[0].info,
|
|
|
+ [uId, villageData]
|
|
|
+ );
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const query = new URLSearchParams(location.search);
|
|
|
+ const param = query.get("id");
|
|
|
+ // console.log("村落页面获取id", param);
|
|
|
+ setUid(param!);
|
|
|
+ }, [location.search]);
|
|
|
+
|
|
|
+ // 详情 索引
|
|
|
+ const [infoInd, setInfoInd] = useState(-1);
|
|
|
+
|
|
|
+ // 每次索引变化的时候 动态加载 序列帧样式
|
|
|
+ const setFullFu = useCallback(() => {
|
|
|
+ // 看看是否已经插入的 script
|
|
|
+ const ruDom = document.querySelector("#myStyle");
|
|
|
+ if (ruDom) ruDom.remove();
|
|
|
+
|
|
|
+ clearTimeout(time.current);
|
|
|
+ time.current = window.setTimeout(() => {
|
|
|
+ if (infoInd === -1) return;
|
|
|
+
|
|
|
+ const num = curVillage[infoInd].zhen;
|
|
|
+ // 获取序列帧 外层 盒子的 宽度
|
|
|
+ const dom = document.querySelector(".B1imgMove") as HTMLDivElement;
|
|
|
+ if (dom) {
|
|
|
+ const width = dom.getBoundingClientRect().width;
|
|
|
+ const leftNum = "-" + width * num + "px";
|
|
|
+ const styleStr = `.B1VinfoAc .B1imgMoveMain {
|
|
|
+ animation: tab2MoveImg 2.4s steps(${num}) infinite;
|
|
|
+ }
|
|
|
+ @keyframes tab2MoveImg {
|
|
|
+
|
|
|
+ 100% {
|
|
|
+ left: ${leftNum};
|
|
|
+ }
|
|
|
+ }`;
|
|
|
+
|
|
|
+ const styletDom = document.createElement("style");
|
|
|
+ styletDom.type = "text/css";
|
|
|
+ styletDom.id = "myStyle";
|
|
|
+ styletDom.innerHTML = styleStr;
|
|
|
+ document.querySelector("html")?.appendChild(styletDom);
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
+ }, [curVillage, infoInd]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (infoInd !== -1) setFullFu();
|
|
|
+ }, [infoInd, setFullFu]);
|
|
|
+
|
|
|
+ const time = useRef(-1);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ window.addEventListener("resize", setFullFu, true);
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ window.removeEventListener("resize", setFullFu);
|
|
|
+ };
|
|
|
+ }, [setFullFu]);
|
|
|
+
|
|
|
+ // 点击右侧的 场景 或者 构件
|
|
|
+ const rightClickFu = useCallback((id: string, name: string) => {
|
|
|
+ if (name === "室内场景") history.push(`/scene?id=${id}`);
|
|
|
+ else history.push(`/buildInfo?id=${id}`);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ className={styles.B1VillageM}
|
|
|
+ style={{ zIndex: infoInd !== -1 ? "40" : "" }}
|
|
|
+ >
|
|
|
+ {/* 全景相关 */}
|
|
|
+ {curScene ? (
|
|
|
+ <KrpanoCom
|
|
|
+ scale={0.5}
|
|
|
+ curScene={curScene}
|
|
|
+ curVillage={curVillage}
|
|
|
+ infoInd={infoInd}
|
|
|
+ setInfoInd={(ind) => setInfoInd(ind)}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {/* 详情页面 */}
|
|
|
+ <div className={classNames("B1Vinfo", infoInd !== -1 ? "B1VinfoAc" : "")}>
|
|
|
+ {/* 右上角的关闭按钮 */}
|
|
|
+ <div className="B1Vback" onClick={() => setInfoInd(-1)}>
|
|
|
+ <img src={`${baseUrl}/A1Home/mobile/icon_cancel.png`} alt="" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {curVillage.map((v, i) => (
|
|
|
+ <div
|
|
|
+ className={classNames("B1info", infoInd === i ? "B1infoAc" : "")}
|
|
|
+ key={v.id}
|
|
|
+ >
|
|
|
+ {/* 大名字 */}
|
|
|
+ {uId ? (
|
|
|
+ <div className="B1infoMainName">
|
|
|
+ <img
|
|
|
+ src={`${baseUrl}/B1Village/pc/${uId}/name${v.id}.png`}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+ {/* 上面的 序列帧 和 左右箭头 */}
|
|
|
+ <div className="B1imgMove">
|
|
|
+ {/* 图片的序列帧 */}
|
|
|
+ {uId ? (
|
|
|
+ <img
|
|
|
+ className={classNames("B1imgMoveMain")}
|
|
|
+ style={{
|
|
|
+ width: v.zhen * 100 + "%",
|
|
|
+ maxWidth: v.zhen * 100 + "%",
|
|
|
+ }}
|
|
|
+ src={`${baseUrl}/B1Village/pc/${uId}/move${v.id}.png`}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {/* 左右箭头 */}
|
|
|
+ <div
|
|
|
+ onClick={() => setInfoInd(infoInd - 1)}
|
|
|
+ className={classNames(
|
|
|
+ "B1infoAr B1infoAr1",
|
|
|
+ infoInd === 0 ? "B1infoArNone" : ""
|
|
|
+ )}
|
|
|
+ hidden={curVillage.length <= 1}
|
|
|
+ ></div>
|
|
|
+ <div
|
|
|
+ onClick={() => setInfoInd(infoInd + 1)}
|
|
|
+ className={classNames(
|
|
|
+ "B1infoAr B1infoAr2",
|
|
|
+ infoInd >= curVillage.length - 1 ? "B1infoArNone" : ""
|
|
|
+ )}
|
|
|
+ hidden={curVillage.length <= 1}
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
+ {/* 下面的信息 */}
|
|
|
+ <div className="B1infoTxt">
|
|
|
+ {/* 场景和构件的选择 */}
|
|
|
+ <div className="B1infoTxt1">
|
|
|
+ {v.buildArr.map((v2) => (
|
|
|
+ <div
|
|
|
+ onClick={() => rightClickFu(v2.id, v2.name)}
|
|
|
+ className="B1infoTxt1Row"
|
|
|
+ key={v2.id}
|
|
|
+ >
|
|
|
+ {uId ? (
|
|
|
+ <div className="B1infoTxt1RowIn">
|
|
|
+ <img
|
|
|
+ src={`${baseUrl}/B1Village/pc/${uId}/${v2.id}.png`}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ <div>{v2.name}</div>
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 文字介绍 */}
|
|
|
+ <div className="B1infoTxt2">
|
|
|
+ <div
|
|
|
+ className="mySorrl"
|
|
|
+ dangerouslySetInnerHTML={{
|
|
|
+ __html: v.txt ? v.txt : `暂无介绍`,
|
|
|
+ }}
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 底部的按钮 */}
|
|
|
+ <div
|
|
|
+ className="B1infoTxt3"
|
|
|
+ onClick={() => history.push(`/architec?id=${uId}`)}
|
|
|
+ >
|
|
|
+ <img src={btnImg} alt="" />
|
|
|
+ <div>
|
|
|
+ 建筑模型
|
|
|
+ <p>
|
|
|
+ <SwapRightOutlined />
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoB1VillageM = React.memo(B1VillageM);
|
|
|
+
|
|
|
+export default MemoB1VillageM;
|