优化称重连接

This commit is contained in:
zc
2026-04-07 16:37:51 +08:00
parent 45bd3bc8f5
commit a54a56865a
2 changed files with 134 additions and 69 deletions

View File

@@ -36,10 +36,20 @@ export function vmSend(materialProcess: string) {
/** @desc vm定时任务保存图片 */ /** @desc vm定时任务保存图片 */
export function getVmSaveImageTask() { export function getVmSaveImageTask() {
return http.get<any>(`/vm/start`) return http.post<any>(`/vm/start`)
} }
/** @desc vm关闭定时任务 */ /** @desc vm关闭定时任务 */
export function getVmCloseTask() { export function getVmCloseTask() {
return http.get<any>(`/vm/stop`) return http.post<any>(`/vm/stop`)
}
/** @desc 启动电子称连接线程 */
export function weighAHStart() {
return http.post<any>(`/api/weigh/ah/init`)
}
/** @desc 终止电子称连接线程 */
export function weighAHStop() {
return http.post<any>(`/api/weigh/ah/destroy`)
} }

View File

@@ -11,6 +11,7 @@
<div class="step-item" :class="{ active: activeStep >= 2, completed: activeStep > 2 }"> <div class="step-item" :class="{ active: activeStep >= 2, completed: activeStep > 2 }">
<div class="step-circle">2</div> <div class="step-circle">2</div>
<div class="step-title">称重登记</div> <div class="step-title">称重登记</div>
<div class="step-title">30分钟有效</div>
</div> </div>
<div class="step-line"></div> <div class="step-line"></div>
<div class="step-item" :class="{ active: activeStep >= 3, completed: activeStep > 3 }"> <div class="step-item" :class="{ active: activeStep >= 3, completed: activeStep > 3 }">
@@ -270,7 +271,7 @@ import {
getVmCloseTask, getVmCloseTask,
getVmSaveImageTask, getVmSaveImageTask,
validateWeighing, validateWeighing,
vmSend vmSend, weighAHStart, weighAHStop
} from '@/apis/weightManage/weightManage' } from '@/apis/weightManage/weightManage'
import {type WorkOrderResp, addWorkOrder} from '@/apis/workOrder/workOrder' import {type WorkOrderResp, addWorkOrder} from '@/apis/workOrder/workOrder'
import {getCaptureImage, getCheckStatus, getEnterWeighPage, getLeaveWeighPage } from "@/apis/weightManage/ys"; import {getCaptureImage, getCheckStatus, getEnterWeighPage, getLeaveWeighPage } from "@/apis/weightManage/ys";
@@ -394,6 +395,9 @@ const stopStatusCheck = () => {
} }
} }
// 称重登记页面超时定时器
let weighingTimeoutTimer: number | null = null
// 组件挂载时 // 组件挂载时
onMounted(() => { onMounted(() => {
// 启动图片自动刷新,每秒更新一次 // 启动图片自动刷新,每秒更新一次
@@ -430,6 +434,11 @@ onMounted(() => {
getVmSaveImageTask().catch(error => { getVmSaveImageTask().catch(error => {
console.error('启动vm定时任务保存图片失败:', error) console.error('启动vm定时任务保存图片失败:', error)
}) })
// 清除称重登记页面的超时定时器
if (weighingTimeoutTimer) {
clearTimeout(weighingTimeoutTimer)
weighingTimeoutTimer = null
}
} else if (newVal === 2) { } else if (newVal === 2) {
// 进入称重登记页面断开灯光并关闭vm定时任务 // 进入称重登记页面断开灯光并关闭vm定时任务
disconnect().catch(error => { disconnect().catch(error => {
@@ -441,6 +450,23 @@ onMounted(() => {
nextTick(() => { nextTick(() => {
enterWeighPage() enterWeighPage()
}) })
// 启动30分钟超时定时器
if (weighingTimeoutTimer) {
clearTimeout(weighingTimeoutTimer)
}
weighingTimeoutTimer = window.setTimeout(() => {
// 超时提示
Modal.confirm({
title: '页面超时',
content: '称重登记页面已超过30分钟请重新加载页面',
onOk: () => {
// 停用电子称
weighAHStop()
// 重新加载页面
window.location.reload()
}
})
}, 30 * 60 * 1000) // 30分钟
} else { } else {
// 离开称重页面断开灯光并关闭vm定时任务 // 离开称重页面断开灯光并关闭vm定时任务
leaveWeighPage() leaveWeighPage()
@@ -450,6 +476,11 @@ onMounted(() => {
disconnect().catch(error => { disconnect().catch(error => {
console.error('断开灯光失败:', error) console.error('断开灯光失败:', error)
}) })
// 清除称重登记页面的超时定时器
if (weighingTimeoutTimer) {
clearTimeout(weighingTimeoutTimer)
weighingTimeoutTimer = null
}
} }
}) })
}) })
@@ -463,6 +494,11 @@ onBeforeUnmount(() => {
} }
// 停止状态检查 // 停止状态检查
stopStatusCheck() stopStatusCheck()
// 清除称重登记页面的超时定时器
if (weighingTimeoutTimer) {
clearTimeout(weighingTimeoutTimer)
weighingTimeoutTimer = null
}
// 离开称重页面 // 离开称重页面
if (activeStep.value === 2) { if (activeStep.value === 2) {
leaveWeighPage() leaveWeighPage()
@@ -613,9 +649,14 @@ const fetchMaterialData = async (code: string) => {
// 处理下一步 // 处理下一步
const handleNext = async () => { const handleNext = async () => {
if (activeStep.value < 3) {
console.log('当前步骤:', activeStep.value)
// 只处理步骤1和步骤2
if (activeStep.value >= 3) return;
// 步骤2显示确认弹框
if (activeStep.value === 2) { if (activeStep.value === 2) {
// 当在称重登记页面点击完成时,显示确认弹框
Modal.confirm({ Modal.confirm({
title: '确认完成', title: '确认完成',
content: '确定要完成称重登记吗?', content: '确定要完成称重登记吗?',
@@ -643,6 +684,9 @@ const handleNext = async () => {
// 关闭WebSocket连接 // 关闭WebSocket连接
closeWebSocket() closeWebSocket()
//停用电子称
weighAHStop()
// 跳转到完成页面 // 跳转到完成页面
activeStep.value++ activeStep.value++
return true return true
@@ -654,42 +698,50 @@ const handleNext = async () => {
} }
}, },
}) })
} else if (activeStep.value === 1 && compareMatchResult.value !== 'success') { return;
// 当在扫码核验页面点击开始比对时,调用后端接口获取比对结果 }
try {
// 步骤1且未成功比对执行比对操作
if (activeStep.value === 1 && compareMatchResult.value !== 'success') {
try {
const materialCode = formData.inputMaterialCode?.trim() const materialCode = formData.inputMaterialCode?.trim()
if (!materialCode) { if (!materialCode) {
Message.error('请先扫描物料编码') Message.error('请先扫描物料编码')
return;
} }
if (!formData.materialProcess || formData.materialProcess === '') { if (!formData.materialProcess || formData.materialProcess === '') {
Message.error('未找到物料流程,无法对比') Message.error('未找到物料流程,无法对比')
return return;
} }
// 调用后端接口获取比对结果 // todo // 调用后端接口获取比对结果 // todo
const res = await vmSend(formData.materialProcess); const res = await vmSend(formData.materialProcess);
if (res.data && res.data == materialCode) { if (res.data && res.data == materialCode) {
compareMatchResult.value === 'success'; compareMatchResult.value = 'success'
Message.success('比对成功') Message.success('比对成功')
} else { } else {
// 比对失败,提示错误 // 比对失败,提示错误
Message.error('比对失败') Message.error('比对失败')
} }
// compareMatchResult.value = 'success'
} catch (error) { } catch (error) {
console.error('比对失败:', error) console.error('比对失败:', error)
Message.error('比对失败,请重试') Message.error('比对失败,请重试')
} }
} else { return; // 提前返回,避免执行后续代码
}
// 其他情况步骤1且已成功比对或步骤0直接进入下一步
activeStep.value++ activeStep.value++
// 进入称重页面时建立WebSocket连接 // 进入称重页面时建立WebSocket连接
if (activeStep.value === 2) { if (activeStep.value === 2) {
weighAHStart().catch(error => {
console.error('启动电子称连接线程失败:', error)
})
establishWebSocket() establishWebSocket()
} }
} }
}
}
// 处理上一步 // 处理上一步
const handlePrevious = () => { const handlePrevious = () => {
@@ -916,6 +968,9 @@ const playAudio = (filename: string) => {
// 组件卸载时关闭WebSocket连接 // 组件卸载时关闭WebSocket连接
onUnmounted(() => { onUnmounted(() => {
weighAHStop().catch(error => {
console.error('终止电子称连接线程失败:', error)
})
closeWebSocket() closeWebSocket()
}) })
</script> </script>