|
@@ -1,4 +1,10 @@
|
|
|
-import React, { useEffect, useMemo, useState } from "react";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
import { useLocation } from "react-router-dom";
|
|
|
import history from "@/utils/history";
|
|
@@ -11,12 +17,20 @@ function B1Village() {
|
|
|
const location = useLocation();
|
|
|
|
|
|
const [uId, setUid] = useState("");
|
|
|
- const [curScene, setCurScene] = useState("scene_zlc");
|
|
|
+
|
|
|
const [hotspotHoverName, setHotspotHoverName] = 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(
|
|
|
() =>
|
|
@@ -35,13 +49,67 @@ function B1Village() {
|
|
|
// 详情 索引
|
|
|
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(() => {
|
|
|
+ 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 = `.B1infoRowAc .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.B1Village}>
|
|
|
{/* 全景相关 */}
|
|
|
<Krpano
|
|
|
className={styles.villageKrpano}
|
|
|
xml="/scene.xml"
|
|
|
- currentScene={curScene}
|
|
|
+ currentScene={"scene_zlc"}
|
|
|
>
|
|
|
{curVillage.map((item, index) => {
|
|
|
const name = `hotspot${item.id}`;
|
|
@@ -53,7 +121,7 @@ function B1Village() {
|
|
|
type="text"
|
|
|
atv={item.atv}
|
|
|
ath={item.ath}
|
|
|
- scale={0.5}
|
|
|
+ scale={0.3}
|
|
|
edge="top"
|
|
|
bg={false}
|
|
|
distorted={true}
|
|
@@ -89,18 +157,25 @@ function B1Village() {
|
|
|
key={v.id}
|
|
|
>
|
|
|
{/* 大名字 */}
|
|
|
- <div className="B1infoMainName">
|
|
|
- <img
|
|
|
- src={`${baseUrl}/B1Village/pc/${uId}/name${v.id}.png`}
|
|
|
- alt=""
|
|
|
- />
|
|
|
- </div>
|
|
|
+ {uId ? (
|
|
|
+ <div className="B1infoMainName">
|
|
|
+ <img
|
|
|
+ src={`${baseUrl}/B1Village/pc/${uId}/name${v.id}.png`}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+
|
|
|
{/* 底部介绍 */}
|
|
|
<div className="B1infoFloo">
|
|
|
- <div
|
|
|
- className="B1infoFloo1 mySorrl"
|
|
|
- dangerouslySetInnerHTML={{ __html: v.txt }}
|
|
|
- ></div>
|
|
|
+ <div className="B1infoFloo1">
|
|
|
+ <div
|
|
|
+ className="mySorrl"
|
|
|
+ dangerouslySetInnerHTML={{
|
|
|
+ __html: v.txt ? v.txt : "暂无介绍",
|
|
|
+ }}
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
{/* 左右箭头 */}
|
|
|
<div
|
|
|
onClick={() => setInfoInd(infoInd - 1)}
|
|
@@ -127,11 +202,50 @@ function B1Village() {
|
|
|
查看
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
{/* 右侧的打点定位 */}
|
|
|
- <div className="B1infoRloc"></div>
|
|
|
- {v.buildArr.map((v2) => (
|
|
|
- <div className={classNames("B1infoRloc",)} key={v2.id}></div>
|
|
|
- ))}
|
|
|
+ <div
|
|
|
+ className={classNames(
|
|
|
+ "B1infoRlocBox",
|
|
|
+ `B1infoRlocBox${v.buildArr.length}`
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ {v.buildArr.map((v2) => (
|
|
|
+ <div
|
|
|
+ className={classNames("B1infoRloc")}
|
|
|
+ key={v2.id}
|
|
|
+ onClick={() => rightClickFu(v2.id, v2.name)}
|
|
|
+ >
|
|
|
+ <div className="B1infoRlocMain">
|
|
|
+ {uId ? (
|
|
|
+ <img
|
|
|
+ src={`${baseUrl}/B1Village/pc/${uId}/${v2.id}.png`}
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+ <div>{v2.name}</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ {/* 图片的序列帧 */}
|
|
|
+ <div
|
|
|
+ className="B1imgMove"
|
|
|
+ // onMouseEnter={() => setImgHover(false)}
|
|
|
+ // onMouseLeave={() => setImgHover(true)}
|
|
|
+ >
|
|
|
+ {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>
|
|
|
</div>
|
|
|
))}
|
|
|
</div>
|