#
Junjie
2024-10-17 d835d1b51f832889929cdf69010034a30ef44d02
zy-asrs-flow/src/pages/device/lift/index.jsx
@@ -6,18 +6,21 @@
    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 [moveLocType, setMoveLocType] = useState(1);
    const [mapLev, setMapLev] = useState([]);
    const [targetLoc, setTargetLoc] = useState(1);
    const [originLoc, setOriginLoc] = useState(null);
    const [originSite, setOriginSite] = useState(null);
    const [targetSite, setTargetSite] = useState(null);
    useEffect(() => {
        var newWs = new WebSocket("ws://127.0.0.1:9090/wcs/ws/lift/websocket");
        setWs(newWs);
        connect();
        getMapLev();
@@ -55,6 +58,7 @@
            ws.onclose = function (e) {
                console.log("close");
                reconnect();
            }
            ws.onerror = function (e) {
@@ -62,6 +66,18 @@
            }
        }
    }, [ws]);
    const connect = () => {
        var newWs = new WebSocket(WEBSOCKET_BASE_URL + "/ws/lift/websocket");
        setWs(newWs);
    }
    const reconnect = () => {
        setTimeout(() => {
            console.log('WebSocketClient: Attempting to reconnect...');
            connect();
        }, 3000);
    }
    const sendWs = (message) => {
        if (ws.readyState == WebSocket.OPEN) {
@@ -78,7 +94,6 @@
    const showOpera = (data) => {
        setOpenOpera(true);
        console.log(data);
        setCurrentData(data);
    };
@@ -90,13 +105,14 @@
        try {
            const resp = await Http.doPost('api/basLift/getMapLev', {});
            if (resp.code === 200) {
                let arr = [];
                for (let i = 1; i <= resp.data; i++) {
                let arr = []
                let levList = JSON.parse(resp.data);
                levList.forEach((lev) => {
                    arr.push({
                        value: i,
                        label: i
                        value: lev,
                        label: lev
                    })
                }
                })
                setMapLev(arr);
                return true;
            } else {
@@ -109,8 +125,20 @@
        }
    }
    const targetLocChange = (e) => {
        setTargetLoc(e.target.value)
    const targetLocChange = (value) => {
        setTargetLoc(value)
    }
    const originLocChange = (e) => {
        setOriginLoc(e.target.value)
    }
    const targetSiteChange = (e) => {
        setTargetSite(e.target.value)
    }
    const originSiteChange = (e) => {
        setOriginSite(e.target.value)
    }
    const liftOperator = async (type) => {
@@ -118,8 +146,10 @@
            const resp = await Http.doPost('api/basLift/operator/lift', {
                liftNo: currentData.liftNo,
                liftTaskMode: type,
                sourceStaNo: 0,
                staNo: moveLocType
                sourceStaNo: originSite,
                staNo: targetSite,
                sourceLev: originLoc,
                targetLev: targetLoc,
            });
            if (resp.code === 200) {
                message.success("请求成功");
@@ -132,10 +162,6 @@
            message.warning("请求失败");
            return false;
        }
    }
    const moveLocTypeChange = (e) => {
        setMoveLocType(e)
    }
    let codeContent = (<PageContainer
@@ -195,6 +221,21 @@
                        label: '作业标记',
                        children: item.pakMk ? 'Y' : 'N',
                    },
                    {
                        key: '10',
                        label: '当前层',
                        children: item.lev,
                    },
                    {
                        key: '11',
                        label: '已完成任务号',
                        children: item.completeTaskNo,
                    },
                    {
                        key: '12',
                        label: '扩展',
                        children: JSON.stringify(item.extend),
                    },
                ];
                return <div key={item.id} style={{ width: '45%' }}>
                    <div style={{ marginBottom: '10px' }}>
@@ -218,12 +259,23 @@
                            <p>
                                <Select
                                    defaultValue="1"
                                    onChange={moveLocTypeChange}
                                    onChange={targetLocChange}
                                    style={{ width: 120 }}
                                    options={mapLev}
                                />
                                <span><Button onClick={() => liftOperator('move')}>移动</Button></span>
                                <span><Button onClick={() => liftOperator('move')}>升降</Button></span>
                            </p>
                            <p>
                                <Input addonBefore="起始位置" onChange={originSiteChange} />
                            </p>
                            <p>
                                <Input addonBefore="目标位置" onChange={targetSiteChange} />
                            </p>
                            <p>
                            </p>
                            <div className="commandItem">
                                <Button onClick={() => liftOperator('movePallet')}>托盘出入</Button>
                            </div>
                        </Card>
                    </div>
@@ -232,6 +284,12 @@
                            <div className="commandItem">
                                <Button onClick={() => liftOperator('reset')}>复位</Button>
                            </div>
                            <div className="commandItem">
                                <Button onClick={() => liftOperator('lock')}>锁定</Button>
                            </div>
                            <div className="commandItem">
                                <Button onClick={() => liftOperator('unlock')}>解锁</Button>
                            </div>
                        </Card>
                    </div>
                </Drawer>