From 5d5996b915a42a5fb5d6256a5eba0dc7797b7ef0 Mon Sep 17 00:00:00 2001 From: zc Date: Tue, 7 Apr 2026 17:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A7=B0=E9=87=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/weightManage/index.vue | 157 ++++++++++++++++--------------- 1 file changed, 81 insertions(+), 76 deletions(-) diff --git a/src/views/weightManage/index.vue b/src/views/weightManage/index.vue index e6227ff..beaba6f 100644 --- a/src/views/weightManage/index.vue +++ b/src/views/weightManage/index.vue @@ -244,7 +244,7 @@
@@ -398,6 +398,78 @@ const stopStatusCheck = () => { // 称重登记页面超时定时器 let weighingTimeoutTimer: number | null = null +// 初始化步骤1(扫码验证页面)的操作 +const initStep1 = () => { + // 进入扫码验证页面,连接灯光并启动vm定时任务保存图片 + connect().catch(error => { + console.error('连接灯光失败:', error) + }) + getVmSaveImageTask().catch(error => { + console.error('启动vm定时任务保存图片失败:', error) + }) + // 清除称重登记页面的超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + weighingTimeoutTimer = null + } +} + +// 进入步骤2(称重登记页面)的操作 +const enterStep2 = () => { + // 进入称重登记页面,断开灯光并关闭vm定时任务 + disconnect().catch(error => { + console.error('断开灯光失败:', error) + }) + getVmCloseTask().catch(error => { + console.error('关闭vm定时任务失败:', error) + }) + nextTick(() => { + enterWeighPage() + }) + // 启动30分钟超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + } + weighingTimeoutTimer = window.setTimeout(() => { + // 超时提示 + Modal.confirm({ + title: '页面超时', + content: '称重登记页面已超过30分钟,请重新加载页面', + onOk: () => { + // 停用电子称 + weighAHStop() + // 重新加载页面 + window.location.reload() + } + }) + }, 30 * 60 * 1000) // 30分钟 + + // 启动电子称连接线程并建立WebSocket连接 + weighAHStart().catch(error => { + Message.error('与电子称的连接建立失败') + return + }) + establishWebSocket() +} + +// 离开称重页面的操作 +const leaveWeighingPage = () => { + // 离开称重页面,断开灯光并关闭vm定时任务 + leaveWeighPage() + + // 清除称重登记页面的超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + weighingTimeoutTimer = null + } + + // 停用电子称并关闭WebSocket连接 + weighAHStop().catch(error => { + console.error('停用电子称失败:', error) + }) + closeWebSocket() +} + // 组件挂载时 onMounted(() => { // 启动图片自动刷新,每秒更新一次 @@ -416,71 +488,17 @@ onMounted(() => { // 初始进入扫码验证页面,连接灯光 if (activeStep.value === 1) { - connect().catch(error => { - console.error('连接灯光失败:', error) - }) - getVmSaveImageTask().catch(error => { - console.error('启动vm定时任务保存图片失败:', error) - }) + initStep1() } // 监听步骤变化 watch(activeStep, (newVal) => { if (newVal === 1) { - // 进入扫码验证页面,连接灯光并启动vm定时任务保存图片 - connect().catch(error => { - console.error('连接灯光失败:', error) - }) - getVmSaveImageTask().catch(error => { - console.error('启动vm定时任务保存图片失败:', error) - }) - // 清除称重登记页面的超时定时器 - if (weighingTimeoutTimer) { - clearTimeout(weighingTimeoutTimer) - weighingTimeoutTimer = null - } + initStep1() } else if (newVal === 2) { - // 进入称重登记页面,断开灯光并关闭vm定时任务 - disconnect().catch(error => { - console.error('断开灯光失败:', error) - }) - getVmCloseTask().catch(error => { - console.error('关闭vm定时任务失败:', error) - }) - nextTick(() => { - enterWeighPage() - }) - // 启动30分钟超时定时器 - if (weighingTimeoutTimer) { - clearTimeout(weighingTimeoutTimer) - } - weighingTimeoutTimer = window.setTimeout(() => { - // 超时提示 - Modal.confirm({ - title: '页面超时', - content: '称重登记页面已超过30分钟,请重新加载页面', - onOk: () => { - // 停用电子称 - weighAHStop() - // 重新加载页面 - window.location.reload() - } - }) - }, 30 * 60 * 1000) // 30分钟 + enterStep2() } else { - // 离开称重页面,断开灯光并关闭vm定时任务 - leaveWeighPage() - getVmCloseTask().catch(error => { - console.error('关闭vm定时任务失败:', error) - }) - disconnect().catch(error => { - console.error('断开灯光失败:', error) - }) - // 清除称重登记页面的超时定时器 - if (weighingTimeoutTimer) { - clearTimeout(weighingTimeoutTimer) - weighingTimeoutTimer = null - } + leaveWeighingPage() } }) }) @@ -682,11 +700,6 @@ const handleNext = async () => { workOrderResp.value.totalCalculatedWeight = res.data?.totalCalculatedWeight || '' workOrderResp.value.totalCount = res.data?.totalCount || '' - // 关闭WebSocket连接 - closeWebSocket() - //停用电子称 - weighAHStop() - // 跳转到完成页面 activeStep.value++ return true @@ -717,7 +730,7 @@ const handleNext = async () => { // 调用后端接口获取比对结果 // todo const res = await vmSend(formData.materialProcess); - if (res.data && res.data == materialCode) { + if (res.data && res.data === materialCode) { compareMatchResult.value = 'success' Message.success('比对成功') } else { @@ -734,23 +747,15 @@ const handleNext = async () => { // 其他情况(步骤1且已成功比对,或步骤0):直接进入下一步 activeStep.value++ - // 进入称重页面时建立WebSocket连接 - if (activeStep.value === 2) { - weighAHStart().catch(error => { - console.error('启动电子称连接线程失败:', error) - }) - establishWebSocket() - } + // 进入称重页面的操作已在watch监听器中处理 } // 处理上一步 const handlePrevious = () => { if (activeStep.value > 1) { activeStep.value-- - // 离开称重页面时关闭WebSocket连接 - if (activeStep.value !== 2) { - closeWebSocket() - } + weighAHStop() + closeWebSocket() } }