From 51a599f7df8c4965bb949ab807657ea950886577 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 18 十月 2024 13:46:28 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/map/JsonShow.jsx               |    8 +++++++-
 zy-acs-flow/src/map/insight/agv/AgvControl.jsx |    6 +++++-
 zy-acs-flow/src/map/insight/agv/AgvMain.jsx    |   13 ++++++-------
 zy-acs-flow/src/map/insight/agv/index.jsx      |   17 +++++++++++------
 4 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/zy-acs-flow/src/map/JsonShow.jsx b/zy-acs-flow/src/map/JsonShow.jsx
index 977fed5..fd70475 100644
--- a/zy-acs-flow/src/map/JsonShow.jsx
+++ b/zy-acs-flow/src/map/JsonShow.jsx
@@ -23,7 +23,13 @@
     const theme = useTheme();
     const themeMode = theme.palette.mode;
 
-    let json = parseJson(data);
+    const [json, setJson] = useState(null);
+
+    useEffect(() => {
+        if (data) {
+            setJson(parseJson(data));
+        }
+    }, [data]);
 
     return (
         <Paper
diff --git a/zy-acs-flow/src/map/insight/agv/AgvControl.jsx b/zy-acs-flow/src/map/insight/agv/AgvControl.jsx
index 6b98bdd..5551377 100644
--- a/zy-acs-flow/src/map/insight/agv/AgvControl.jsx
+++ b/zy-acs-flow/src/map/insight/agv/AgvControl.jsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect } from 'react';
 import { useTranslate } from "react-admin";
 import { useForm, Controller } from 'react-hook-form';
 import {
@@ -47,6 +47,10 @@
         { value: 'STA_TO_STA', label: translate('page.map.insight.control.type.STA_TO_STA') },
     ];
 
+    useEffect(() => {
+        reset();
+    }, [curAgvNo]);
+
     const onSubmit = (data) => {
         if (curAgvNo) {
             console.log(data);
diff --git a/zy-acs-flow/src/map/insight/agv/AgvMain.jsx b/zy-acs-flow/src/map/insight/agv/AgvMain.jsx
index f507cd5..efa722f 100644
--- a/zy-acs-flow/src/map/insight/agv/AgvMain.jsx
+++ b/zy-acs-flow/src/map/insight/agv/AgvMain.jsx
@@ -67,7 +67,7 @@
 
                 addObject(agvGroup);
 
-                three.rePerspective(350, 450);
+                three?.rePerspective(350, 450);
 
             }).catch((error) => {
                 console.error(error);
@@ -77,7 +77,7 @@
 }
 
 const AgvMain = (props) => {
-    const { data, curAgvNo, setCurAgvNo } = props;
+    const { curAgvNo, setCurAgvNo, setJsonData } = props;
     const theme = useTheme();
     const translate = useTranslate();
     const containerRef = useRef();
@@ -85,17 +85,16 @@
     const [info, setInfo] = useState(null);
 
     useEffect(() => {
-        if (data) {
-            getAgvInfo(data.no, (response) => {
+        if (curAgvNo) {
+            getAgvInfo(curAgvNo, (response) => {
                 setInfo(response);
-                setCurAgvNo(data.no);
             });
         }
-    }, [data]);
+    }, [curAgvNo]);
 
     useEffect(() => {
         if (info) {
-            // console.log(info);
+            setJsonData(info);
             endThree();
             setLoading(true);
             setTimeout(() => {
diff --git a/zy-acs-flow/src/map/insight/agv/index.jsx b/zy-acs-flow/src/map/insight/agv/index.jsx
index 2351c85..bfe531e 100644
--- a/zy-acs-flow/src/map/insight/agv/index.jsx
+++ b/zy-acs-flow/src/map/insight/agv/index.jsx
@@ -13,20 +13,26 @@
 
     const [activeTab, setActiveTab] = useState(0);
     const [curAgvNo, setCurAgvNo] = useState(null);
+    const [jsonData, setJsonData] = useState(null);
 
     const handleTabChange = (event, newValue) => {
         setActiveTab(newValue);
     };
 
     useEffect(() => {
-        if (curAgvNo) {
-            setTitle(translate('page.map.devices.agv') + ' - ' + curAgvNo);
+        if (sprite) {
+            const agvNo = sprite.data.no;
+            if (agvNo) {
+                setCurAgvNo(agvNo);
+                setTitle(translate('page.map.devices.agv') + ' - ' + agvNo);
+            }
         }
 
         return () => {
             setTitle(null);
+            setJsonData(null);
         }
-    }, [curAgvNo])
+    }, [sprite])
 
     return (
         <Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
@@ -46,20 +52,19 @@
             <Box flex={1} pt={2}>
                 {activeTab === 0 && (
                     <AgvMain
-                        data={sprite?.data}
                         curAgvNo={curAgvNo}
                         setCurAgvNo={setCurAgvNo}
+                        setJsonData={setJsonData}
                     />
                 )}
                 {activeTab === 1 && (
                     <AgvControl
-                        data={sprite?.data}
                         curAgvNo={curAgvNo}
                     />
                 )}
                 {activeTab === 2 && (
                     <JsonShow
-                        data={sprite?.data}
+                        data={jsonData || sprite?.data}
                         height={550}
                     />
                 )}

--
Gitblit v1.9.1