智能控制页面添加WebSocket

This commit is contained in:
wangxk 2025-06-16 09:08:50 +08:00
parent ea06d2d1d4
commit e81c342acd
2 changed files with 43 additions and 6 deletions

View File

@ -5,7 +5,7 @@ export default {
</script>
<script setup lang="ts">
import { ref, onMounted, nextTick } from "vue";
import { ref, onMounted, nextTick, onBeforeUnmount } from "vue";
import { getTreeList } from "@/api/linksignal";
import { countDeviceTypeStatus, queryYxData, sendCommand } from "@/api/intelligentcontrol";
import { getDeviceByType } from '@/api/device'
@ -138,7 +138,8 @@ function openchange(row: any) {
value: row.yxValue,
}
sendCommand(params).then((res: any) => {
getdataone()
setupWebSocket(row.signalId)
// getdataone()
})
})
.catch(() => {
@ -190,7 +191,38 @@ function getDeviceImage1(deviceType: any, yxValue: any, status: any) {
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(() => {
getSelect();
getType()

View File

@ -96,11 +96,16 @@ const tableDataList: any = ref([])
const tableTempDataList: any = ref([])
// _
function dataChange() {
if (tableData.value.length == 2) {
if (tableData.value&&tableData.value.length == 2) {
SearchBox.value.startDate = tableData.value[0]
SearchBox.value.endDate = tableData.value[1]
}else{
SearchBox.value.startDate = ''
SearchBox.value.endDate = ''
}
getData()
}
const treeloading = ref(false)
//-
const robotUAV: any = ref([])