#
Junjie
7 天以前 ce511a3d55e5f349b1647172e562c1659bbc8172
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <title>Gateway</title>
    <link rel="stylesheet" href="../static/vue/element/element.css">
    <script type="text/javascript" src="../static/js/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="../static/js/common.js"></script>
    <script type="text/javascript" src="../static/vue/js/vue.min.js"></script>
    <script type="text/javascript" src="../static/vue/element/element.js"></script>
    <style>
        .el-table .success-row {
            background: #b6ff8e;
        }
    </style>
</head>
 
<body>
<div id="app" style="display: flex;justify-content: center;flex-wrap: wrap;">
    <div style="width: 40%;">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>模拟设备 - {{ systemInfo.gatewayId }}号网关</span>
<!--                <el-button style="float: right; padding: 3px 0" type="text" @click="addDeviceVisible = true">添加设备</el-button>-->
            </div>
 
            <div style="display: flex;flex-wrap: wrap;justify-content: space-between;">
                <div v-for="item in deviceList" style="width: 49%;margin-top: 20px">
                    <el-card  class="box-card" >
                        <div slot="header" class="clearfix">
                            <span>{{ item.deviceType }} - {{ item.deviceNo }}</span>
<!--                            <el-button style="float: right; padding: 3px 0" type="text" @click="delDevice(item)">删除设备</el-button>-->
                            <el-button style="float: right; padding: 3px 0" type="text" @click="setCurrentDeviceConfig(item)">状态</el-button>
                        </div>
 
                        <div>
                            <div>IP: {{ item.ip }}</div>
                            <div>端口: {{ item.port }}</div>
                            <div>虚拟: {{ item.fake }}</div>
                            <div>实现类: {{ item.threadImpl }}</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </el-card>
    </div>
 
    <div v-if="currentDeviceConfig != null" style="width: 30%;margin-left: 30px;">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>模拟设备状态</span>
            </div>
 
            <div style="display: flex;flex-wrap: wrap;justify-content: space-between;">
                <div v-if="currentDeviceData != null" style="width: 100%;margin-top: 20px">
                    <el-card class="box-card" >
                        <div slot="header" class="clearfix">
                            <span>{{ currentDeviceData.deviceType }} - {{ currentDeviceData.deviceNo }}</span>
                            <el-button v-if="currentDeviceDataForm == null" style="float: right; padding: 3px 0" type="text" @click="updateCurrentDeviceStatus(currentDeviceData)">更新状态</el-button>
                            <el-button v-else style="float: right; padding: 3px 0" type="text" @click="submitUpdateCurrentDeviceStatus(currentDeviceDataForm)">提交更新</el-button>
                        </div>
 
                        <div v-if="currentDeviceDataForm == null">
                            <div>模式: {{ currentDeviceData.data.mode }}</div>
                            <div>状态: {{ currentDeviceData.data.deviceStatus }}</div>
                            <div>顶升: {{ currentDeviceData.data.hasLift }}</div>
                            <div>托盘: {{ currentDeviceData.data.hasPallet }}</div>
                            <div>坐标: {{ currentDeviceData.data.currentCode }}</div>
                            <div>异常: {{ currentDeviceData.data.errorCode }}</div>
                            <div>充电: {{ currentDeviceData.data.hasCharge }}</div>
                            <div>电量: {{ currentDeviceData.data.batteryPower }}</div>
                            <div>电压: {{ currentDeviceData.data.batteryVoltage }}</div>
                            <div>运行方向: {{ currentDeviceData.data.runDirection }}</div>
                            <div>速度: {{ currentDeviceData.data.speed }}</div>
                        </div>
 
                        <div v-else>
                            <div>模式: <el-input v-model="currentDeviceDataForm.data.mode"></el-input></div>
                            <div>状态: <el-input v-model="currentDeviceDataForm.data.deviceStatus"></el-input></div>
                            <div>顶升: <el-input v-model="currentDeviceDataForm.data.hasLift"></el-input></div>
                            <div>托盘: <el-input v-model="currentDeviceDataForm.data.hasPallet"></el-input></div>
                            <div>坐标: <el-input v-model="currentDeviceDataForm.data.currentCode"></el-input></div>
                            <div>异常: <el-input v-model="currentDeviceDataForm.data.errorCode"></el-input></div>
                            <div>充电: <el-input v-model="currentDeviceDataForm.data.hasCharge"></el-input></div>
                            <div>电量: <el-input v-model="currentDeviceDataForm.data.batteryPower"></el-input></div>
                            <div>电压: <el-input v-model="currentDeviceDataForm.data.batteryVoltage"></el-input></div>
                            <div>运行方向: <el-input v-model="currentDeviceDataForm.data.runDirection"></el-input></div>
                            <div>速度: <el-input v-model="currentDeviceDataForm.data.speed"></el-input></div>
                        </div>
 
                        <div>
                            原始数据:
                            {{ currentDeviceData }}
                        </div>
                    </el-card>
                </div>
            </div>
        </el-card>
    </div>
 
    <el-dialog title="添加模拟设备" :visible.sync="addDeviceVisible">
        <el-form :model="addDeviceParam">
            <el-form-item label="设备编号" :label-width="formLabelWidth">
                <el-input v-model="addDeviceParam.deviceNo"></el-input>
            </el-form-item>
            <el-form-item label="IP" :label-width="formLabelWidth">
                <el-input v-model="addDeviceParam.ip"></el-input>
            </el-form-item>
            <el-form-item label="端口" :label-width="formLabelWidth">
                <el-input v-model="addDeviceParam.port"></el-input>
            </el-form-item>
            <el-form-item label="实现类" :label-width="formLabelWidth">
                <el-input v-model="addDeviceParam.threadImpl"></el-input>
            </el-form-item>
            <el-form-item label="设备类型" :label-width="formLabelWidth">
                <el-input v-model="addDeviceParam.deviceType"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="addDeviceVisible = false">取 消</el-button>
            <el-button type="primary" @click="addDevice">确 定</el-button>
        </div>
    </el-dialog>
 
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            addDeviceVisible: false,
            addDeviceParam: {
                deviceNo: '',
                ip: '',
                port: '',
                threadImpl: '',
                deviceType: ''
            },
            systemInfo: {
                gatewayId: 0,
                gatewayPort: 0
            },
            formLabelWidth: '120px',
            deviceList: [],
            currentDeviceConfig: null,
            currentDeviceData: null,
            currentDeviceDataForm: null
        },
        created() {
            this.init()
        },
        methods: {
            init() {
                this.getSystemInfo();
 
                setInterval(() => {
                    this.getDeviceList()
                    this.getFakeThreadStatus()
                }, 1000);
            },
            getSystemInfo() {
                let that = this;
                $.ajax({
                    url: baseUrl + "/open/getSystemInfo",
                    headers: {
                        'token': localStorage.getItem('token')
                    },
                    data: {},
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    method: 'GET',
                    success: function(res) {
                        if (res.code == 200) {
                            let data = res.data;
                            that.systemInfo = data
                        } else {
                            that.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    }
                });
            },
            setCurrentDeviceConfig(deviceConfig) {
                this.currentDeviceConfig = deviceConfig
                this.currentDeviceDataForm = null;
            },
            updateCurrentDeviceStatus(currentDeviceData) {
                if (this.currentDeviceDataForm == null) {
                    this.currentDeviceDataForm = currentDeviceData;
                }else {
                    this.currentDeviceDataForm = null;
                }
            },
            submitUpdateCurrentDeviceStatus(currentDeviceDataForm) {
                let that = this;
                $.ajax({
                    url: baseUrl + "/open/updateFakeThreadStatus",
                    headers: {
                        'token': localStorage.getItem('token')
                    },
                    data: JSON.stringify({
                        deviceType: currentDeviceDataForm.deviceType,
                        deviceNo: currentDeviceDataForm.deviceNo,
                        data: JSON.stringify(currentDeviceDataForm.data)
                    }),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    method: 'POST',
                    success: function (res) {
                        if (res.code == 200) {
                            that.currentDeviceDataForm = null;
                            that.$message({
                                message: res.msg,
                                type: 'success'
                            });
                        } else {
                            that.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    }
                });
            },
            getFakeThreadStatus() {
                let that = this;
                if (this.currentDeviceConfig == null) {
                    return;
                }
 
                $.ajax({
                    url: baseUrl + "/open/getFakeThreadStatus",
                    headers: {
                        'token': localStorage.getItem('token')
                    },
                    data: JSON.stringify({
                        deviceType: this.currentDeviceConfig.deviceType,
                        deviceNo: this.currentDeviceConfig.deviceNo
                    }),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    method: 'POST',
                    success: function (res) {
                        if (res.code == 200) {
                            let data = res.data;
                            let result = {
                                deviceType: that.currentDeviceConfig.deviceType,
                                deviceNo: that.currentDeviceConfig.deviceNo,
                                data: data
                            }
 
                            that.currentDeviceData = result
                        } else {
                            that.currentDeviceConfig = null;
                            that.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    }
                });
            },
            addDevice() {
                //添加设备
                let that = this;
                $.ajax({
                    url: baseUrl + "/open/addFakeDevice",
                    headers: {
                        'token': localStorage.getItem('token')
                    },
                    data: JSON.stringify(this.addDeviceParam),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    method: 'POST',
                    success: function(res) {
                        if (res.code == 200) {
                            console.log(res)
                        } else {
                            that.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    }
                });
            },
            getDeviceList() {
                let that = this;
                $.ajax({
                    url: baseUrl + "/open/getDeviceList",
                    headers: {
                        'token': localStorage.getItem('token')
                    },
                    data: {},
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    method: 'GET',
                    success: function(res) {
                        if (res.code == 200) {
                            let data = res.data;
                            that.deviceList = data
                        } else {
                            that.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    }
                });
            },
            delDevice(config) {
                let that = this;
                $.ajax({
                    url: baseUrl + "/open/deleteFakeDevice",
                    headers: {
                        'token': localStorage.getItem('token')
                    },
                    data: JSON.stringify({
                        deviceNo: config.deviceNo,
                        deviceType: config.deviceType
                    }),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    method: 'POST',
                    success: function(res) {
                        if (res.code == 200) {
                            let data = res.data;
                            that.deviceList = data
                        } else {
                            that.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    }
                });
            }
        },
    })
</script>
</body>
 
</html>