From a54a56865afef90fb5dc2922b86c7c3721cc4ad5 Mon Sep 17 00:00:00 2001 From: zc Date: Tue, 7 Apr 2026 16:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A7=B0=E9=87=8D=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/weightManage/weightManage.ts | 14 +- src/views/weightManage/index.vue | 189 +++++++++++++++++--------- 2 files changed, 134 insertions(+), 69 deletions(-) diff --git a/src/apis/weightManage/weightManage.ts b/src/apis/weightManage/weightManage.ts index 7221fa3..2529925 100644 --- a/src/apis/weightManage/weightManage.ts +++ b/src/apis/weightManage/weightManage.ts @@ -36,10 +36,20 @@ export function vmSend(materialProcess: string) { /** @desc vm定时任务保存图片 */ export function getVmSaveImageTask() { - return http.get(`/vm/start`) + return http.post(`/vm/start`) } /** @desc vm关闭定时任务 */ export function getVmCloseTask() { - return http.get(`/vm/stop`) + return http.post(`/vm/stop`) +} + +/** @desc 启动电子称连接线程 */ +export function weighAHStart() { + return http.post(`/api/weigh/ah/init`) +} + +/** @desc 终止电子称连接线程 */ +export function weighAHStop() { + return http.post(`/api/weigh/ah/destroy`) } diff --git a/src/views/weightManage/index.vue b/src/views/weightManage/index.vue index aad6023..e6227ff 100644 --- a/src/views/weightManage/index.vue +++ b/src/views/weightManage/index.vue @@ -11,6 +11,7 @@
2
称重登记
+
(30分钟有效)
@@ -270,7 +271,7 @@ import { getVmCloseTask, getVmSaveImageTask, validateWeighing, - vmSend + vmSend, weighAHStart, weighAHStop } from '@/apis/weightManage/weightManage' import {type WorkOrderResp, addWorkOrder} from '@/apis/workOrder/workOrder' import {getCaptureImage, getCheckStatus, getEnterWeighPage, getLeaveWeighPage } from "@/apis/weightManage/ys"; @@ -394,6 +395,9 @@ const stopStatusCheck = () => { } } +// 称重登记页面超时定时器 +let weighingTimeoutTimer: number | null = null + // 组件挂载时 onMounted(() => { // 启动图片自动刷新,每秒更新一次 @@ -430,6 +434,11 @@ onMounted(() => { getVmSaveImageTask().catch(error => { console.error('启动vm定时任务保存图片失败:', error) }) + // 清除称重登记页面的超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + weighingTimeoutTimer = null + } } else if (newVal === 2) { // 进入称重登记页面,断开灯光并关闭vm定时任务 disconnect().catch(error => { @@ -441,6 +450,23 @@ onMounted(() => { nextTick(() => { enterWeighPage() }) + // 启动30分钟超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + } + weighingTimeoutTimer = window.setTimeout(() => { + // 超时提示 + Modal.confirm({ + title: '页面超时', + content: '称重登记页面已超过30分钟,请重新加载页面', + onOk: () => { + // 停用电子称 + weighAHStop() + // 重新加载页面 + window.location.reload() + } + }) + }, 30 * 60 * 1000) // 30分钟 } else { // 离开称重页面,断开灯光并关闭vm定时任务 leaveWeighPage() @@ -450,6 +476,11 @@ onMounted(() => { disconnect().catch(error => { console.error('断开灯光失败:', error) }) + // 清除称重登记页面的超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + weighingTimeoutTimer = null + } } }) }) @@ -463,6 +494,11 @@ onBeforeUnmount(() => { } // 停止状态检查 stopStatusCheck() + // 清除称重登记页面的超时定时器 + if (weighingTimeoutTimer) { + clearTimeout(weighingTimeoutTimer) + weighingTimeoutTimer = null + } // 离开称重页面 if (activeStep.value === 2) { leaveWeighPage() @@ -613,81 +649,97 @@ const fetchMaterialData = async (code: string) => { // 处理下一步 const handleNext = async () => { - if (activeStep.value < 3) { - if (activeStep.value === 2) { - // 当在称重登记页面点击完成时,显示确认弹框 - Modal.confirm({ - title: '确认完成', - content: '确定要完成称重登记吗?', - onOk: async () => { - try { - // 准备工作订单数据 - const workOrderData = { - materialId: formData.id, - workOrderInfos: weighingList.value, - } - // 调用后端接口 - addWorkOrder(workOrderData).then((res) => { - if (res.code === '0') { - Notification.success({ - title: '操作成功', - content: `工单创建成功!`, - }) - workOrderResp.value.id = res.data?.id || '' - workOrderResp.value.matchResult = 'success' - workOrderResp.value.title = res.data?.title || '' - workOrderResp.value.orderNo = res.data?.orderNo || '' - workOrderResp.value.totalWeight = res.data?.totalWeight || '' - workOrderResp.value.totalCalculatedWeight = res.data?.totalCalculatedWeight || '' - workOrderResp.value.totalCount = res.data?.totalCount || '' - // 关闭WebSocket连接 - closeWebSocket() - // 跳转到完成页面 - activeStep.value++ - return true - } - }) - } catch (error) { - console.error('创建工作订单失败:', error) - Message.error('创建工作订单失败') + console.log('当前步骤:', activeStep.value) + + // 只处理步骤1和步骤2 + if (activeStep.value >= 3) return; + + // 步骤2:显示确认弹框 + if (activeStep.value === 2) { + Modal.confirm({ + title: '确认完成', + content: '确定要完成称重登记吗?', + onOk: async () => { + try { + // 准备工作订单数据 + const workOrderData = { + materialId: formData.id, + workOrderInfos: weighingList.value, } - }, - }) - } else if (activeStep.value === 1 && compareMatchResult.value !== 'success') { - // 当在扫码核验页面点击开始比对时,调用后端接口获取比对结果 - try { + // 调用后端接口 + addWorkOrder(workOrderData).then((res) => { + if (res.code === '0') { + Notification.success({ + title: '操作成功', + content: `工单创建成功!`, + }) + workOrderResp.value.id = res.data?.id || '' + workOrderResp.value.matchResult = 'success' + workOrderResp.value.title = res.data?.title || '' + workOrderResp.value.orderNo = res.data?.orderNo || '' + workOrderResp.value.totalWeight = res.data?.totalWeight || '' + workOrderResp.value.totalCalculatedWeight = res.data?.totalCalculatedWeight || '' + workOrderResp.value.totalCount = res.data?.totalCount || '' - const materialCode = formData.inputMaterialCode?.trim() - if (!materialCode) { - Message.error('请先扫描物料编码') - } + // 关闭WebSocket连接 + closeWebSocket() + //停用电子称 + weighAHStop() - if (!formData.materialProcess || formData.materialProcess === '') { - Message.error('未找到物料流程,无法对比') - return + // 跳转到完成页面 + activeStep.value++ + return true + } + }) + } catch (error) { + console.error('创建工作订单失败:', error) + Message.error('创建工作订单失败') } + }, + }) + return; + } - // 调用后端接口获取比对结果 // todo - const res = await vmSend(formData.materialProcess); - if (res.data && res.data == materialCode) { - compareMatchResult.value === 'success'; - Message.success('比对成功') - } else { - // 比对失败,提示错误 - Message.error('比对失败') - } - } catch (error) { - console.error('比对失败:', error) - Message.error('比对失败,请重试') + // 步骤1且未成功比对:执行比对操作 + if (activeStep.value === 1 && compareMatchResult.value !== 'success') { + try { + const materialCode = formData.inputMaterialCode?.trim() + if (!materialCode) { + Message.error('请先扫描物料编码') + return; } - } else { - activeStep.value++ - // 进入称重页面时建立WebSocket连接 - if (activeStep.value === 2) { - establishWebSocket() + + if (!formData.materialProcess || formData.materialProcess === '') { + Message.error('未找到物料流程,无法对比') + return; } + + // 调用后端接口获取比对结果 // todo + const res = await vmSend(formData.materialProcess); + if (res.data && res.data == materialCode) { + compareMatchResult.value = 'success' + Message.success('比对成功') + } else { + // 比对失败,提示错误 + Message.error('比对失败') + } + // compareMatchResult.value = 'success' + } catch (error) { + console.error('比对失败:', error) + Message.error('比对失败,请重试') } + return; // 提前返回,避免执行后续代码 + } + + // 其他情况(步骤1且已成功比对,或步骤0):直接进入下一步 + activeStep.value++ + // 进入称重页面时建立WebSocket连接 + if (activeStep.value === 2) { + weighAHStart().catch(error => { + console.error('启动电子称连接线程失败:', error) + }) + establishWebSocket() } } @@ -916,6 +968,9 @@ const playAudio = (filename: string) => { // 组件卸载时关闭WebSocket连接 onUnmounted(() => { + weighAHStop().catch(error => { + console.error('终止电子称连接线程失败:', error) + }) closeWebSocket() })