智能控制页面添加WebSocket
This commit is contained in:
parent
ea06d2d1d4
commit
e81c342acd
@ -5,7 +5,7 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, nextTick } from "vue";
|
import { ref, onMounted, nextTick, onBeforeUnmount } from "vue";
|
||||||
import { getTreeList } from "@/api/linksignal";
|
import { getTreeList } from "@/api/linksignal";
|
||||||
import { countDeviceTypeStatus, queryYxData, sendCommand } from "@/api/intelligentcontrol";
|
import { countDeviceTypeStatus, queryYxData, sendCommand } from "@/api/intelligentcontrol";
|
||||||
import { getDeviceByType } from '@/api/device'
|
import { getDeviceByType } from '@/api/device'
|
||||||
@ -138,7 +138,8 @@ function openchange(row: any) {
|
|||||||
value: row.yxValue,
|
value: row.yxValue,
|
||||||
}
|
}
|
||||||
sendCommand(params).then((res: any) => {
|
sendCommand(params).then((res: any) => {
|
||||||
getdataone()
|
setupWebSocket(row.signalId)
|
||||||
|
// getdataone()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@ -190,7 +191,38 @@ function getDeviceImage1(deviceType: any, yxValue: any, status: any) {
|
|||||||
return ''; // 或者返回一个默认图片路径
|
return ''; // 或者返回一个默认图片路径
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let indexarr: any = ref([])
|
||||||
|
// = new WebSocket(userStore.wsApiBaseUrl + ''+'');
|
||||||
|
function setupWebSocket(id: any) {
|
||||||
|
if (indexarr.value.length > 4) {
|
||||||
|
ElMessage.warning('当前设备打开过多,请稍后再试!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let ws2 = new WebSocket(userStore.wsApiBaseUrl + '/websocket/auxcontrol_' + id);
|
||||||
|
indexarr.value.push(ws2)
|
||||||
|
ws2.onopen = () => {
|
||||||
|
console.log('WebSocket连接已打开');
|
||||||
|
};
|
||||||
|
ws2.onerror = (error: any) => {
|
||||||
|
};
|
||||||
|
ws2.onmessage = (e: any) => {
|
||||||
|
getdataone()
|
||||||
|
ws2.close()
|
||||||
|
indexarr.value = indexarr.value.filter((item: any) => item !== ws2);
|
||||||
|
}
|
||||||
|
ws2.onclose = () => {
|
||||||
|
console.log('WebSocket连接已关闭');
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (indexarr.value.length > 0) {
|
||||||
|
indexarr.value.forEach((item: any) => {
|
||||||
|
item.close()
|
||||||
|
});
|
||||||
|
indexarr.value.length = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getSelect();
|
getSelect();
|
||||||
getType()
|
getType()
|
||||||
|
@ -96,11 +96,16 @@ const tableDataList: any = ref([])
|
|||||||
const tableTempDataList: any = ref([])
|
const tableTempDataList: any = ref([])
|
||||||
// 搜索_时间赋值
|
// 搜索_时间赋值
|
||||||
function dataChange() {
|
function dataChange() {
|
||||||
if (tableData.value.length == 2) {
|
if (tableData.value&&tableData.value.length == 2) {
|
||||||
SearchBox.value.startDate = tableData.value[0]
|
SearchBox.value.startDate = tableData.value[0]
|
||||||
SearchBox.value.endDate = tableData.value[1]
|
SearchBox.value.endDate = tableData.value[1]
|
||||||
|
}else{
|
||||||
|
SearchBox.value.startDate = ''
|
||||||
|
SearchBox.value.endDate = ''
|
||||||
}
|
}
|
||||||
|
getData()
|
||||||
}
|
}
|
||||||
|
|
||||||
const treeloading = ref(false)
|
const treeloading = ref(false)
|
||||||
//获取机器人-无人机
|
//获取机器人-无人机
|
||||||
const robotUAV: any = ref([])
|
const robotUAV: any = ref([])
|
||||||
|
Loading…
Reference in New Issue
Block a user