浏览代码

嵌套 iframe history.go(-1) 返回的问题

shaogen1995 1 年之前
父节点
当前提交
5ccc317690

+ 3 - 2
code/src/components/ArcOrBuildInfo/index.tsx

@@ -5,6 +5,7 @@ import { baseUrl } from "@/index";
 import history, { modelUrl } from "@/utils/history";
 import classNames from "classnames";
 import { InfoRowType } from "@/types";
+import { getUrlHashFu } from "@/utils/data";
 
 const iconArr = [
   { id: 2, name: "放大" },
@@ -92,11 +93,11 @@ function ArcOrBuildInfo({ info, type }: Props) {
           frameBorder="0"
         ></iframe>
         {/* 进入室内按钮 */}
-        {type === "C2ArchitecInfo"&&info.code ? (
+        {type === "C2ArchitecInfo" && info.code ? (
           <div
             hidden={full}
             className="C2rToScene"
-            onClick={() => history.push(`/scene?id=${info.code}`)}
+            onClick={() => getUrlHashFu(info.code)}
           >
             进入室内
           </div>

+ 2 - 4
code/src/components/ArcOrBuildInfoM/index.tsx

@@ -7,6 +7,7 @@ import { InfoRowType } from "@/types";
 import history, { modelUrl } from "@/utils/history";
 import { SwapRightOutlined } from "@ant-design/icons";
 import classNames from "classnames";
+import { getUrlHashFu } from "@/utils/data";
 
 const iconArr = [
   { id: 2, name: "放大" },
@@ -131,10 +132,7 @@ function ArcOrBuildInfoM({ info, type }: Props) {
 
         {/* 去大场景 */}
         {type === "C2ArchitecInfo" && info.code ? (
-          <div
-            className="AMtoVr"
-            onClick={() => history.push(`/scene?id=${info.code}`)}
-          >
+          <div className="AMtoVr" onClick={() => getUrlHashFu(info.code)}>
             室内VR
             <p>
               <SwapRightOutlined />

+ 2 - 1
code/src/pages/B1Village/index.tsx

@@ -14,6 +14,7 @@ import { RootState } from "@/store";
 import classNames from "classnames";
 import { baseUrl } from "@/index";
 import KrpanoCom from "@/components/KrpanoCom";
+import { getUrlHashFu } from "@/utils/data";
 function B1Village() {
   const location = useLocation();
 
@@ -147,7 +148,7 @@ function B1Village() {
 
   // 点击右侧的 场景 或者 构件
   const rightClickFu = useCallback((id: string, name: string) => {
-    if (name === "VR场景") history.push(`/scene?id=${id}`);
+    if (name === "VR场景") getUrlHashFu(id)
     else history.push(`/buildInfo?id=${id}`);
   }, []);
 

+ 2 - 1
code/src/pages/B1VillageM/index.tsx

@@ -15,6 +15,7 @@ import classNames from "classnames";
 import history from "@/utils/history";
 import btnImg from "@/assets/img/tab2/btn_m.png";
 import { SwapRightOutlined } from "@ant-design/icons";
+import { getUrlHashFu } from "@/utils/data";
 
 function B1VillageM() {
   const location = useLocation();
@@ -146,7 +147,7 @@ function B1VillageM() {
 
   // 点击右侧的 场景 或者 构件
   const rightClickFu = useCallback((id: string, name: string) => {
-    if (name === "VR场景") history.push(`/scene?id=${id}`);
+    if (name === "VR场景") getUrlHashFu(id);
     else history.push(`/buildInfo?id=${id}`);
   }, []);
 

+ 8 - 1
code/src/pages/Z2Scene/index.tsx

@@ -8,10 +8,15 @@ function Z2Scene() {
 
   const [uid, setUid] = useState("");
 
+  const [back, setBack] = useState("");
+
   useEffect(() => {
     const query = new URLSearchParams(location.search);
     const id = query.get("id");
     setUid(id!);
+
+    const back = query.get("back");
+    setBack(back!);
   }, [location.search]);
 
   return (
@@ -25,7 +30,9 @@ function Z2Scene() {
       ) : null}
 
       {/* 返回按钮 */}
-      <div className="Z2back" onClick={() => history.go(-1)}></div>
+      {back ? (
+        <div className="Z2back" onClick={() => history.push(back)}></div>
+      ) : null}
     </div>
   );
 }

+ 11 - 0
code/src/utils/data.ts

@@ -1,6 +1,17 @@
+import history from "./history";
+
 export const AppTabList = [
   { id: 1, name: "总览", pathUrl: "/", path: "/" },
   { id: 2, name: "村落", pathUrl: "/village", path: "/village" },
   { id: 3, name: "建筑", pathUrl: "/architec?id=1", path: "/architec" },
   { id: 4, name: "构件", pathUrl: "/build", path: "/build" },
 ];
+
+// 嵌套 iframe history.go(-1) 返回的问题
+export const getUrlHashFu = (id: string) => {
+  const url = window.location.hash;
+  if (url && url.includes("#/")) {
+    const path = url.replace("#", "");
+    history.push(`/scene?id=${id}&back=${path}`);
+  }
+};

文件差异内容过多而无法显示
+ 355 - 278
静态资源/web/staticData/dataTemp.js