#
zjj
2024-06-22 dcc528dae89242366a86e8b3709479621b95b0c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import React, { useEffect, useRef, useState } from "react";
import { getToken } from '@/utils/token-util'
import Http from '@/utils/http';
import { Badge, Button, Descriptions, Drawer, Input, Card, Select, message } from 'antd';
import {
    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 [taskNo, setTaskNo] = useState(null);
    const [staNo, setStaNo] = useState(null);
 
    useEffect(() => {
        connect();
 
        return () => {
            if (ws) {
                ws.close();
            }
        }
    }, [])
 
    useEffect(() => {
        if (ws) {
            ws.onopen = function () {
                console.log("open");
 
                sendWs(JSON.stringify({
                    "url": "login",
                    "data": {
                        "token": getToken()
                    }
                }))
            }
 
            ws.onmessage = function (e) {
                const result = JSON.parse(e.data);
                if (result.url == "login") {
                    setInterval(function () {
                        getDeviceInfo();
                    }, 1000)
                } else if (result.url == "/conveyor/list") {
                    const data = JSON.parse(result.data);
                    setDeviceInfos(data);
                }
            }
 
            ws.onclose = function (e) {
                console.log("close");
                reconnect();
            }
 
            ws.onerror = function (e) {
                console.log(e);
            }
        }
    }, [ws]);
 
    const connect = () => {
        var newWs = new WebSocket(WEBSOCKET_BASE_URL + "/ws/conveyor/websocket");
        setWs(newWs);
    }
 
    const reconnect = () => {
        setTimeout(() => {
            console.log('WebSocketClient: Attempting to reconnect...');
            connect();
        }, 3000);
    }
 
    const sendWs = (message) => {
        if (ws.readyState == WebSocket.OPEN) {
            ws.send(message)
        }
    }
 
    const getDeviceInfo = () => {
        sendWs(JSON.stringify({
            "url": "/conveyor/list",
            "data": {}
        }))
    }
 
    const showOpera = (data) => {
        setOpenOpera(true);
        setCurrentData(data);
 
        setTaskNo(data.taskNo);
        setStaNo(data.staNo);
    };
 
    const closeOpera = () => {
        setOpenOpera(false);
    };
 
    const taskNoChange = (e) => {
        setTaskNo(e.target.value)
    }
 
    const staNoChange = (e) => {
        setStaNo(e.target.value)
    }
 
    const conveyorOperator = async (type) => {
        try {
            const resp = await Http.doPost('api/basConveyor/operator/sta', {
                conveyorNo: currentData.conveyorNo,
                siteNo: currentData.siteNo,
                taskMode: type,
                taskNo: taskNo,
                staNo: staNo
            });
            if (resp.code === 200) {
                message.success("请求成功");
                return true;
            } else {
                message.warning(resp.msg);
                return false;
            }
        } catch (error) {
            message.warning("请求失败");
            return false;
        }
    }
 
    let codeContent = (<PageContainer
        header={{
            breadcrumb: {},
        }}
    >
        <div style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'space-around' }}>
            {deviceInfos.map(item => {
                if (item == null) {
                    return;
                }
                let tmpTitle = item.siteNo + "站"
                let tmpData = [
                    {
                        key: '1',
                        label: '任务号',
                        children: item.taskNo,
                    },
                    {
                        key: '2',
                        label: '自动',
                        children: item.autoing,
                    },
                    {
                        key: '3',
                        label: '有物',
                        children: item.loading,
                    },
                    {
                        key: '4',
                        label: '可入',
                        children: item.inEnable,
                    },
                    {
                        key: '5',
                        label: '可出',
                        children: item.outEnable,
                    },
                    {
                        key: '6',
                        label: '能入',
                        children: item.canining,
                    },
                    {
                        key: '7',
                        label: '能出',
                        children: item.canouting,
                    },
                    {
                        key: '8',
                        label: '高低类型',
                        children: item.locType1$,
                    },
                    {
                        key: '9',
                        label: '宽窄类型',
                        children: item.locType2$,
                    },
                    {
                        key: '10',
                        label: '轻重类型',
                        children: item.locType3$,
                    },
                    {
                        key: '11',
                        label: '工作模式',
                        children: item.workMode$,
                    },
                    {
                        key: '12',
                        label: '目标站',
                        children: item.staNo,
                    },
                ];
                return <div key={item.id} style={{ width: '45%', marginBottom: '30px' }}>
                    <div style={{ marginBottom: '10px' }}>
                        <span style={{ marginRight: '10px' }}>{tmpTitle}</span>
                        <Button type="primary" onClick={() => showOpera(item)}>操作</Button>
                    </div>
                    <Descriptions size="small" bordered items={tmpData} />
                </div>
            })}
        </div>
    </PageContainer>);
 
    if (currentData) {
        codeContent = (
            <>
                {codeContent}
                <Drawer title="操作面板" onClose={closeOpera} open={openOpera}>
                    <h2 style={{ marginBottom: '15px' }}>{currentData.siteNo}站</h2>
 
                    <div style={{ marginBottom: '15px' }}>
                        <Card title="相关指令" style={{ width: 300 }}>
                            <div className="commandItem">
                                <Input value={taskNo} addonBefore="工作号" onChange={taskNoChange} />
                                <Input value={staNo} addonBefore="目标站" onChange={staNoChange} />
                                <Button type="primary" onClick={() => conveyorOperator('taskNoAndStaNo')}>保存</Button>
                            </div>
                        </Card>
                    </div>
                </Drawer>
            </>
        )
    }
 
    return (codeContent);
}
 
export default Main;