diff --git a/.env.development b/.env.development index 08bbd6f..662a41e 100644 --- a/.env.development +++ b/.env.development @@ -8,5 +8,5 @@ VITE_APP_ENV = 'development' VITE_APP_BASE_API = '/dev-api' VITE_API_URL = http://192.168.28.10:13080 -VITE_WS_URL = ws://192.168.28.10:13080/ws +VITE_WS_URL = ws://192.168.0.201:13080/ws diff --git a/.env.production b/.env.production index 45f5456..dd9f27c 100644 --- a/.env.production +++ b/.env.production @@ -14,4 +14,4 @@ VITE_BUILD_COMPRESS = gzip VITE_NODE_RED_URL = 'http://10.148.108.59:13080' VITE_API_URL = http://192.168.28.10:13080 -VITE_WS_URL = ws://192.168.28.10:13080/ws +VITE_WS_URL = ws://192.168.0.201:13080/ws diff --git a/.env.staging b/.env.staging index 61d4957..66d8d56 100644 --- a/.env.staging +++ b/.env.staging @@ -10,4 +10,4 @@ VITE_APP_BASE_API = '/stage-api' # 是否在打包时开启压缩,支持 gzip 和 brotli VITE_BUILD_COMPRESS = gzip VITE_API_URL = http://10.148.121.100:13080 -VITE_WS_URL = ws://10.148.121.100:13080/ws \ No newline at end of file +VITE_WS_URL = ws://192.168.0.201:13080/ws \ No newline at end of file diff --git a/src/main.js b/src/main.js index eb71c52..8be21ea 100644 --- a/src/main.js +++ b/src/main.js @@ -87,9 +87,8 @@ app.use(ElementPlus, { app.use(WebSocketPlugin, { - // url: import.meta.env.VITE_WS_URL, - url: 'ws://192.168.0.201:13080/ws', - // url: 'ws://10.148.209.5:13080/ws', + url: import.meta.env.VITE_WS_URL, + // url: 'ws://192.168.0.201:13080/ws', userId: 'your_user_id' }); diff --git a/src/views/inspection/runTask/index.vue b/src/views/inspection/runTask/index.vue index c64ab82..283a069 100644 --- a/src/views/inspection/runTask/index.vue +++ b/src/views/inspection/runTask/index.vue @@ -10,43 +10,55 @@
{{ task.taskName }}
- - - - + + + +
机器人:{{ task.robotName }}
- + -
+
当前任务
历史记录
-
+
-
+
-
-
厂区巡检
-
ID: 123456
+
+
+
{{ runTask.taskName }}
+
ID: {{ runTask.taskId }}
+
+
+
机器人:{{ runTask.robotName }}
+
开始时间: {{ formatDate(runTask.startTime) }}
+
+
+
+ + {{ taskStatusMap[runTask.status] || '未知状态' }} +
-
执行中
-
-
-
机器人:xxxx
-
IP: 192.168.1.100
-
开始时间: 2026-06-01 10:00:00
+
执行进度
- - + +
执行日志
@@ -98,7 +110,7 @@ + v-model:page="queryParams.pageNum" :total="total" @pagination="getHistoryList" />
@@ -109,7 +121,8 @@ - + @@ -133,15 +146,17 @@ import SvgIcon from "@/components/SvgIcon"; import taskSteps from "./task-steps.vue"; import { useContainerHeight } from "@/hooks/tableHeight"; -import { getTaskList } from "@/api/inspection/task"; +import { getTaskList, getWaypointByTaskId } from "@/api/inspection/task"; import { getRobotList } from "@/api/inspection/robot"; -import { onMounted } from "vue"; +import { onMounted, onUnmounted } from "vue"; import { addRunTask, getRunTaskList, startRunTask, pauseRunTask, stopRunTask, resumeRunTask, deleteRunTask } from "@/api/inspection/runTask"; import { ElMessage, ElMessageBox } from "element-plus"; import { formatDate } from "@/utils/index"; +import { debounce } from 'lodash'; // 引入 lodash 的防抖函数 const topContainerRef = ref(); const containerHeight = useContainerHeight(topContainerRef); +const socket = inject('ws'); const taskStatusMap = { '0': '已完成', @@ -176,10 +191,11 @@ const getTaskData = () => { }) } -const getRobotData = () => { +const getRobotData = (mapId = null) => { getRobotList({ pageNum: 1, pageSize: 10000, + currentMapId: mapId }).then((res) => { robotList.value = res.rows; }) @@ -190,6 +206,15 @@ const open = ref(false); const addTask = () => { open.value = true; } + +const taskChange = (value) => { + const task = taskList.value.find(item => item.id === value) + const mapId = task.mapId + form.robotId = null; + robotList.value = [] + getRobotData(mapId) +} + const runTaskRef = ref(); const confirmTaskDialog = () => { runTaskRef.value.validate((valid) => { @@ -210,18 +235,31 @@ const cancelTaskDialog = () => { open.value = false; } + +const runingTaskList = ref([]) +/** + * 获取任务队列 + */ const getList = () => { - loading.value = true; getRunTaskList({ statusList: ['1', '3', '5'], }).then((res) => { if (res.code === 200) { runTaskList.value = res.rows; + runingTaskList.value = res.rows.filter(item => item.status !== '5') + for (let i = 0; i < runTaskList.value.length; i++) { + getPointByTaskId(runTaskList.value[i].taskId) + } } - loading.value = false; - }).catch(() => { - loading.value = false; - }); + }) +} + +const pointList_runintTask = ref({}) +const getPointByTaskId = async (taskId) => { + const res = await getWaypointByTaskId(taskId) + if (res.code === 200) { + pointList_runintTask.value[taskId] = res.data + } } const customColorMethod = (percentage) => { @@ -293,6 +331,9 @@ const removeTask = async (task) => { }); } +/** + * 获取历史执行任务 + */ const getHistoryList = () => { loading.value = true; getRunTaskList({ @@ -310,11 +351,73 @@ const getHistoryList = () => { }); } +const taskRunningInfo = ref({}) + +const socketChannelCallbacks = ref({}) +const channel = 'InspectionTaskInstance'; + +const subscribeDebounced = debounce(async (sub) => { + if (!socket) { + console.warn(`执行任务订阅失败: socket=${!!socket}`); + return; + } + + socket.send({ + type: 'channel_subscription', + action: sub ? 'subscribe' : 'unsubscribe', + channel, + }); + + if (sub) { + await nextTick(); + // 清理旧回调 + if (socketChannelCallbacks.value[channel]) { + socket.off(channel, socketChannelCallbacks.value[channel]); + console.log('清理旧回调:', channel); + } + + const callback = (data) => { + if (data !== '500') { + if (data.status !== 0) { + let activeStep = pointList_runintTask.value[data.taskId].findIndex(item => item.detectItemId === data.itemId) || 0 + if (data.progress == 100) { + activeStep += 1 + } + taskRunningInfo.value[data.insId] = { + ...data, + activeStep + } + } else { + delete taskRunningInfo.value[data.insId] + getList() + } + console.log('taskRunningInfo', taskRunningInfo.value) + } else { + // 错误处理:取消订阅后重新订阅 + subscribeDebounced(false); + subscribeDebounced(true); + } + }; + socket.on(channel, callback); + socketChannelCallbacks.value[channel] = callback; + } else { + if (socketChannelCallbacks.value[channel]) { + socket.off(channel, socketChannelCallbacks.value[channel]); + delete socketChannelCallbacks.value[channel]; + } + } +}, 300); + onMounted(() => { getTaskData(); getRobotData(); getList(); getHistoryList(); + subscribeDebounced(true) +}) + +onUnmounted(() => { + subscribeDebounced(false) })