优化称重代码
This commit is contained in:
@@ -244,7 +244,7 @@
|
||||
<!-- 操作按钮 -->
|
||||
<div class="action-buttons">
|
||||
<a-button
|
||||
v-if="activeStep > 1 && activeStep < 3"
|
||||
v-if="activeStep === 2"
|
||||
class="previous-button"
|
||||
@click="handlePrevious"
|
||||
>
|
||||
@@ -398,35 +398,8 @@ const stopStatusCheck = () => {
|
||||
// 称重登记页面超时定时器
|
||||
let weighingTimeoutTimer: number | null = null
|
||||
|
||||
// 组件挂载时
|
||||
onMounted(() => {
|
||||
// 启动图片自动刷新,每秒更新一次
|
||||
imageRefreshTimer = setInterval(() => {
|
||||
// 添加时间戳参数,避免浏览器缓存
|
||||
imgData.imgUrl = `${imgData.baseUrl}?t=${Date.now()}`
|
||||
weighingImgData.imgUrl = `${weighingImgData.baseUrl}?t=${Date.now()}`
|
||||
}, 1500)
|
||||
|
||||
// 页面加载后自动聚焦到物料编码输入框
|
||||
nextTick(() => {
|
||||
if (materialCodeInput.value) {
|
||||
materialCodeInput.value.focus()
|
||||
}
|
||||
})
|
||||
|
||||
// 初始进入扫码验证页面,连接灯光
|
||||
if (activeStep.value === 1) {
|
||||
connect().catch(error => {
|
||||
console.error('连接灯光失败:', error)
|
||||
})
|
||||
getVmSaveImageTask().catch(error => {
|
||||
console.error('启动vm定时任务保存图片失败:', error)
|
||||
})
|
||||
}
|
||||
|
||||
// 监听步骤变化
|
||||
watch(activeStep, (newVal) => {
|
||||
if (newVal === 1) {
|
||||
// 初始化步骤1(扫码验证页面)的操作
|
||||
const initStep1 = () => {
|
||||
// 进入扫码验证页面,连接灯光并启动vm定时任务保存图片
|
||||
connect().catch(error => {
|
||||
console.error('连接灯光失败:', error)
|
||||
@@ -439,7 +412,10 @@ onMounted(() => {
|
||||
clearTimeout(weighingTimeoutTimer)
|
||||
weighingTimeoutTimer = null
|
||||
}
|
||||
} else if (newVal === 2) {
|
||||
}
|
||||
|
||||
// 进入步骤2(称重登记页面)的操作
|
||||
const enterStep2 = () => {
|
||||
// 进入称重登记页面,断开灯光并关闭vm定时任务
|
||||
disconnect().catch(error => {
|
||||
console.error('断开灯光失败:', error)
|
||||
@@ -467,20 +443,62 @@ onMounted(() => {
|
||||
}
|
||||
})
|
||||
}, 30 * 60 * 1000) // 30分钟
|
||||
} else {
|
||||
|
||||
// 启动电子称连接线程并建立WebSocket连接
|
||||
weighAHStart().catch(error => {
|
||||
Message.error('与电子称的连接建立失败')
|
||||
return
|
||||
})
|
||||
establishWebSocket()
|
||||
}
|
||||
|
||||
// 离开称重页面的操作
|
||||
const leaveWeighingPage = () => {
|
||||
// 离开称重页面,断开灯光并关闭vm定时任务
|
||||
leaveWeighPage()
|
||||
getVmCloseTask().catch(error => {
|
||||
console.error('关闭vm定时任务失败:', error)
|
||||
})
|
||||
disconnect().catch(error => {
|
||||
console.error('断开灯光失败:', error)
|
||||
})
|
||||
|
||||
// 清除称重登记页面的超时定时器
|
||||
if (weighingTimeoutTimer) {
|
||||
clearTimeout(weighingTimeoutTimer)
|
||||
weighingTimeoutTimer = null
|
||||
}
|
||||
|
||||
// 停用电子称并关闭WebSocket连接
|
||||
weighAHStop().catch(error => {
|
||||
console.error('停用电子称失败:', error)
|
||||
})
|
||||
closeWebSocket()
|
||||
}
|
||||
|
||||
// 组件挂载时
|
||||
onMounted(() => {
|
||||
// 启动图片自动刷新,每秒更新一次
|
||||
imageRefreshTimer = setInterval(() => {
|
||||
// 添加时间戳参数,避免浏览器缓存
|
||||
imgData.imgUrl = `${imgData.baseUrl}?t=${Date.now()}`
|
||||
weighingImgData.imgUrl = `${weighingImgData.baseUrl}?t=${Date.now()}`
|
||||
}, 1500)
|
||||
|
||||
// 页面加载后自动聚焦到物料编码输入框
|
||||
nextTick(() => {
|
||||
if (materialCodeInput.value) {
|
||||
materialCodeInput.value.focus()
|
||||
}
|
||||
})
|
||||
|
||||
// 初始进入扫码验证页面,连接灯光
|
||||
if (activeStep.value === 1) {
|
||||
initStep1()
|
||||
}
|
||||
|
||||
// 监听步骤变化
|
||||
watch(activeStep, (newVal) => {
|
||||
if (newVal === 1) {
|
||||
initStep1()
|
||||
} else if (newVal === 2) {
|
||||
enterStep2()
|
||||
} else {
|
||||
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,25 +747,17 @@ 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) {
|
||||
weighAHStop()
|
||||
closeWebSocket()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 打印
|
||||
const onPrint = () => {
|
||||
|
||||
Reference in New Issue
Block a user