From e0fe34e65f8f1f051cf848fc7e8f099815747417 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 21 九月 2024 16:26:32 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/page/agv/AgvShow.jsx            |   13 ++++++++++---
 zy-acs-flow/src/page/agv/show/AgvShowDetail.jsx |   23 ++++++++++++++---------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/zy-acs-flow/src/page/agv/AgvShow.jsx b/zy-acs-flow/src/page/agv/AgvShow.jsx
index 3b25088..bca624a 100644
--- a/zy-acs-flow/src/page/agv/AgvShow.jsx
+++ b/zy-acs-flow/src/page/agv/AgvShow.jsx
@@ -34,6 +34,14 @@
 const AgvShowContent = (props) => {
     const { record, isPending } = useShowContext();
     const theme = useTheme();
+    const [online, setOnline] = useState(false);
+
+    useEffect(() => {
+        if (record) {
+            setOnline(record.online)
+        }
+    }, [record])
+
     if (isPending || !record) return null;
 
     return (
@@ -51,9 +59,8 @@
                                     <Stack direction='row'>
                                         <Box mt={.8} mr={2}>
                                             <PulseSignal
-                                                flag={record.online}
+                                                flag={online}
                                                 width={10}
-                                                negative={!record.online}
                                             />
                                         </Box>
                                         <Typography
@@ -76,7 +83,7 @@
                                 }}
                             >
                                 <TabbedShowLayout.Tab label="page.agv.show.tabs.detail">
-                                    <AgvShowDetail agvId={record.id} />
+                                    <AgvShowDetail agvId={record.id} setOnline={setOnline} />
                                 </TabbedShowLayout.Tab>
                                 <TabbedShowLayout.Tab label="page.agv.show.tabs.task" path="tasks">
                                     <AgvShowTask agvId={record.id} />
diff --git a/zy-acs-flow/src/page/agv/show/AgvShowDetail.jsx b/zy-acs-flow/src/page/agv/show/AgvShowDetail.jsx
index e507917..6df36d8 100644
--- a/zy-acs-flow/src/page/agv/show/AgvShowDetail.jsx
+++ b/zy-acs-flow/src/page/agv/show/AgvShowDetail.jsx
@@ -25,23 +25,28 @@
 const GRID_CONTAINER_MAX_WIDTH = '100%';
 
 export const AgvShowDetail = (props) => {
-    const { agvId } = props;
+    const { agvId, setOnline } = props;
     const [record, setRecord] = useState(null);
     const resource = useResourceContext();
 
     useEffect(() => {
         const http = async (agvId) => {
-            const res = await request.get(resource + '/' + agvId);
-            const { code, msg, data } = res.data;
-            if (code === 200) {
-                setRecord(data);
-            } else {
-                setRecord(null);
+            if (agvId) {
+                const res = await request.get(resource + '/' + agvId);
+                const { code, msg, data } = res.data;
+                if (code === 200) {
+                    setOnline(data.online);
+                    setRecord(data);
+                } else {
+                    setRecord(null);
+                }
             }
         }
-        if (agvId) {
+        const intervalId = setInterval(() => {
             http(agvId);
-        }
+        }, 1000);
+        http(agvId);
+        return () => clearInterval(intervalId);
     }, [agvId]);
 
     if (!record) {

--
Gitblit v1.9.1