From 18d258c246cb9e4812964968769eb32fa990065a Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期四, 11 七月 2024 16:44:00 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/device/shuttle/index.jsx |  143 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 132 insertions(+), 11 deletions(-)

diff --git a/zy-asrs-flow/src/pages/device/shuttle/index.jsx b/zy-asrs-flow/src/pages/device/shuttle/index.jsx
index 11d4f34..b6c1609 100644
--- a/zy-asrs-flow/src/pages/device/shuttle/index.jsx
+++ b/zy-asrs-flow/src/pages/device/shuttle/index.jsx
@@ -6,17 +6,23 @@
     PageContainer,
 } from '@ant-design/pro-components';
 import './index.less'
+import { WEBSOCKET_BASE_URL } from '@/config/setting';
 
 const Main = () => {
     const [deviceInfos, setDeviceInfos] = useState([]);
     const [ws, setWs] = useState(null);
     const [openOpera, setOpenOpera] = useState(false);
     const [currentData, setCurrentData] = useState(null);
+    const [sourceLoc, setSourceLoc] = useState("");
     const [targetLoc, setTargetLoc] = useState("");
+    const [xStart, setXStart] = useState(1);
+    const [xTarget, setXTarget] = useState(1);
+    const [yStart, setYStart] = useState(1);
+    const [yTarget, setYTarget] = useState(1);
+    const [moveLocType, setMoveLocType] = useState(1);
 
     useEffect(() => {
-        var newWs = new WebSocket("ws://127.0.0.1:9090/wcs/ws/shuttle/websocket");
-        setWs(newWs);
+        connect();
 
         return () => {
             if (ws) {
@@ -52,6 +58,7 @@
 
             ws.onclose = function (e) {
                 console.log("close");
+                reconnect();
             }
 
             ws.onerror = function (e) {
@@ -59,6 +66,18 @@
             }
         }
     }, [ws]);
+
+    const connect = () => {
+        var newWs = new WebSocket(WEBSOCKET_BASE_URL + "/ws/shuttle/websocket");
+        setWs(newWs);
+    }
+
+    const reconnect = () => {
+        setTimeout(() => {
+            console.log('WebSocketClient: Attempting to reconnect...');
+            connect();
+        }, 3000);
+    }
 
     const sendWs = (message) => {
         if (ws.readyState == WebSocket.OPEN) {
@@ -83,6 +102,10 @@
         setOpenOpera(false);
     };
 
+    const sourceLocChange = (e) => {
+        setSourceLoc(e.target.value)
+    }
+
     const targetLocChange = (e) => {
         setTargetLoc(e.target.value)
     }
@@ -93,12 +116,23 @@
                 message.warning('璇疯緭鍏ョ洰鏍囦綅缃�');
                 return;
             }
+        }else if(type == 'takeMove') {
+            if (targetLoc == '') {
+                message.warning('璇疯緭鍏ョ洰鏍囦綅缃�');
+                return;
+            }
+
+            if (sourceLoc == '') {
+                message.warning('璇疯緭鍏ヨ捣濮嬩綅缃�');
+                return;
+            }
         }
 
         try {
             const resp = await Http.doPost('api/basShuttle/operator/shuttle', {
                 shuttleNo: currentData.shuttleNo,
                 shuttleTaskMode: type,
+                sourceLocNo: sourceLoc,
                 targetLocNo: targetLoc
             });
             if (resp.code === 200) {
@@ -112,6 +146,73 @@
             message.warning("璇锋眰澶辫触");
             return false;
         }
+    }
+
+    const shuttleMoveLoc = async () => {
+        if (xStart == '' || xTarget == '' || yStart == '' || yTarget == '') {
+            message.warning('璇疯緭鍏ュ弬鏁�');
+            return;
+        }
+
+        try {
+            const resp = await Http.doPost('api/basShuttle/moveLoc', {
+                shuttleNo: currentData.shuttleNo,
+                moveType: moveLocType,
+                startX: xStart,
+                targetX: xTarget,
+                startY: yStart,
+                targetY: yTarget,
+            });
+            if (resp.code === 200) {
+                message.success("璇锋眰鎴愬姛");
+                return true;
+            } else {
+                message.warning(resp.msg);
+                return false;
+            }
+        } catch (error) {
+            message.warning("璇锋眰澶辫触");
+            return false;
+        }
+    }
+
+    const shuttleMoveLocClose = async () => {
+        try {
+            const resp = await Http.doPost('api/basShuttle/moveLocClose', {
+                shuttleNo: currentData.shuttleNo,
+            });
+            if (resp.code === 200) {
+                message.success("璇锋眰鎴愬姛");
+                return true;
+            } else {
+                message.warning(resp.msg);
+                return false;
+            }
+        } catch (error) {
+            message.warning("璇锋眰澶辫触");
+            return false;
+        }
+    }
+
+
+    const xStartChange = (e) => {
+        setXStart(e.target.value)
+    }
+
+    const xTargetChange = (e) => {
+        setXTarget(e.target.value)
+    }
+
+    const yStartChange = (e) => {
+        setYStart(e.target.value)
+    }
+
+    const yTargetChange = (e) => {
+        setYTarget(e.target.value)
+    }
+
+    const moveLocTypeChange = (e) => {
+        setMoveLocType(e)
     }
 
     let codeContent = (<PageContainer
@@ -154,7 +255,7 @@
                     {
                         key: '6',
                         label: '閿欒鐮�',
-                        children: '0',
+                        children: item.errorCode$,
                     },
                     {
                         key: '7',
@@ -186,6 +287,16 @@
                         label: '鏄惁鏈夋墭鐩�',
                         children: item.hasPallet ? 'Y' : 'N',
                     },
+                    {
+                        key: '13',
+                        label: '鑷姩',
+                        children: item.mode ? 'Y' : 'N',
+                    },
+                    {
+                        key: '14',
+                        label: '搴撲綅鍙�',
+                        children: item.currentLocNo,
+                    },
                 ];
                 return <div key={item.id} style={{ width: '45%' }}>
                     <div style={{ marginBottom: '10px' }}>
@@ -207,11 +318,19 @@
                     <div style={{ marginBottom: '15px' }}>
                         <Card title="绉诲姩鎸囦护" style={{ width: 300 }}>
                             <p>
-                                <Input addonBefore="鐩爣浣嶇疆" defaultValue="1-1-1" onChange={targetLocChange} />
+                                <Input addonBefore="璧峰浣嶇疆" onChange={sourceLocChange} />
                             </p>
                             <p>
-                                <Button onClick={() => shuttleOperator('moveLoc')}>绉诲姩鍒扮洰鏍囦綅缃�</Button>
+                                <Input addonBefore="鐩爣浣嶇疆" onChange={targetLocChange} />
                             </p>
+                            <p>
+                            </p>
+                            <p>
+                            </p>
+                            <div className="commandItem">
+                                <Button onClick={() => shuttleOperator('moveLoc')}>绉诲姩鍒扮洰鏍囦綅缃�</Button>
+                                <Button onClick={() => shuttleOperator('takeMove')}>鍙栨斁璐т綔涓�</Button>
+                            </div>
                         </Card>
                     </div>
 
@@ -230,18 +349,20 @@
                     <div style={{ marginBottom: '15px' }}>
                         <Card title="璺戝簱绯荤粺" style={{ width: 300 }}>
                             <div className="commandItem">
-                                <div><Input addonBefore="X璧风偣" defaultValue="1" /></div>
-                                <div><Input addonBefore="X缁堢偣" defaultValue="1" /></div>
-                                <div><Input addonBefore="Y璧风偣" defaultValue="1" /></div>
-                                <div><Input addonBefore="Y缁堢偣" defaultValue="1" /></div>
+                                <div><Input addonBefore="X璧风偣" defaultValue="1" onChange={xStartChange} /></div>
+                                <div><Input addonBefore="X缁堢偣" defaultValue="1" onChange={xTargetChange} /></div>
+                                <div><Input addonBefore="Y璧风偣" defaultValue="1" onChange={yStartChange} /></div>
+                                <div><Input addonBefore="Y缁堢偣" defaultValue="1" onChange={yTargetChange} /></div>
                                 <div>
                                     <Select
                                         defaultValue="0"
+                                        onChange={moveLocTypeChange}
                                         style={{ width: 120 }}
-                                        options={[{ value: '0', label: '璺戣建閬�' }, { value: '1', label: '璺戝簱浣�' }, { value: '2', label: '姣嶈建閬撳惊鐜窇' }, { value: '3', label: '瀛愯建閬撳惊鐜窇' }]}
+                                        options={[{ value: '0', label: '璺戣建閬�' }, { value: '1', label: '璺戝簱浣�' }, { value: '2', label: '姣嶈建閬撳惊鐜窇' }, { value: '3', label: '瀛愯建閬撳惊鐜窇' }, { value: '4', label: '鍙栨斁璐�' }]}
                                     />
                                 </div>
-                                <Button>璺戝簱</Button>
+                                <Button onClick={() => shuttleMoveLoc()}>璺戝簱</Button>
+                                <Button onClick={() => shuttleMoveLocClose()}>璺戝簱鍏抽棴</Button>
                             </div>
                         </Card>
                     </div>

--
Gitblit v1.9.1