优化称重连接

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定时任务保存图片 */
export function getVmSaveImageTask() {
return http.get<any>(`/vm/start`)
return http.post<any>(`/vm/start`)
}
/** @desc vm关闭定时任务 */
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-circle">2</div>
<div class="step-title">称重登记</div>
<div class="step-title">30分钟有效</div>
</div>
<div class="step-line"></div>
<div class="step-item" :class="{ active: activeStep >= 3, completed: activeStep > 3 }">
@@ -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,9 +649,14 @@ const fetchMaterialData = async (code: string) => {
// 处理下一步
const handleNext = async () => {
if (activeStep.value < 3) {
console.log('当前步骤:', activeStep.value)
// 只处理步骤1和步骤2
if (activeStep.value >= 3) return;
// 步骤2显示确认弹框
if (activeStep.value === 2) {
// 当在称重登记页面点击完成时,显示确认弹框
Modal.confirm({
title: '确认完成',
content: '确定要完成称重登记吗?',
@@ -643,6 +684,9 @@ const handleNext = async () => {
// 关闭WebSocket连接
closeWebSocket()
//停用电子称
weighAHStop()
// 跳转到完成页面
activeStep.value++
return true
@@ -654,41 +698,49 @@ const handleNext = async () => {
}
},
})
} else if (activeStep.value === 1 && compareMatchResult.value !== 'success') {
// 当在扫码核验页面点击开始比对时,调用后端接口获取比对结果
try {
return;
}
// 步骤1且未成功比对执行比对操作
if (activeStep.value === 1 && compareMatchResult.value !== 'success') {
try {
const materialCode = formData.inputMaterialCode?.trim()
if (!materialCode) {
Message.error('请先扫描物料编码')
return;
}
if (!formData.materialProcess || formData.materialProcess === '') {
Message.error('未找到物料流程,无法对比')
return
return;
}
// 调用后端接口获取比对结果 // todo
const res = await vmSend(formData.materialProcess);
if (res.data && res.data == materialCode) {
compareMatchResult.value === 'success';
compareMatchResult.value = 'success'
Message.success('比对成功')
} else {
// 比对失败,提示错误
Message.error('比对失败')
}
// compareMatchResult.value = 'success'
} catch (error) {
console.error('比对失败:', error)
Message.error('比对失败,请重试')
}
} else {
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()
})
</script>