优化称重连接
This commit is contained in:
@@ -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`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,81 +649,97 @@ const fetchMaterialData = async (code: string) => {
|
|||||||
|
|
||||||
// 处理下一步
|
// 处理下一步
|
||||||
const handleNext = async () => {
|
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连接
|
console.log('当前步骤:', activeStep.value)
|
||||||
closeWebSocket()
|
|
||||||
// 跳转到完成页面
|
// 只处理步骤1和步骤2
|
||||||
activeStep.value++
|
if (activeStep.value >= 3) return;
|
||||||
return true
|
|
||||||
}
|
// 步骤2:显示确认弹框
|
||||||
})
|
if (activeStep.value === 2) {
|
||||||
} catch (error) {
|
Modal.confirm({
|
||||||
console.error('创建工作订单失败:', error)
|
title: '确认完成',
|
||||||
Message.error('创建工作订单失败')
|
content: '确定要完成称重登记吗?',
|
||||||
|
onOk: async () => {
|
||||||
|
try {
|
||||||
|
// 准备工作订单数据
|
||||||
|
const workOrderData = {
|
||||||
|
materialId: formData.id,
|
||||||
|
workOrderInfos: weighingList.value,
|
||||||
}
|
}
|
||||||
},
|
// 调用后端接口
|
||||||
})
|
addWorkOrder(workOrderData).then((res) => {
|
||||||
} else if (activeStep.value === 1 && compareMatchResult.value !== 'success') {
|
if (res.code === '0') {
|
||||||
// 当在扫码核验页面点击开始比对时,调用后端接口获取比对结果
|
Notification.success({
|
||||||
try {
|
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()
|
// 关闭WebSocket连接
|
||||||
if (!materialCode) {
|
closeWebSocket()
|
||||||
Message.error('请先扫描物料编码')
|
//停用电子称
|
||||||
}
|
weighAHStop()
|
||||||
|
|
||||||
if (!formData.materialProcess || formData.materialProcess === '') {
|
// 跳转到完成页面
|
||||||
Message.error('未找到物料流程,无法对比')
|
activeStep.value++
|
||||||
return
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建工作订单失败:', error)
|
||||||
|
Message.error('创建工作订单失败')
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 调用后端接口获取比对结果 // todo
|
// 步骤1且未成功比对:执行比对操作
|
||||||
const res = await vmSend(formData.materialProcess);
|
if (activeStep.value === 1 && compareMatchResult.value !== 'success') {
|
||||||
if (res.data && res.data == materialCode) {
|
try {
|
||||||
compareMatchResult.value === 'success';
|
const materialCode = formData.inputMaterialCode?.trim()
|
||||||
Message.success('比对成功')
|
if (!materialCode) {
|
||||||
} else {
|
Message.error('请先扫描物料编码')
|
||||||
// 比对失败,提示错误
|
return;
|
||||||
Message.error('比对失败')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('比对失败:', error)
|
|
||||||
Message.error('比对失败,请重试')
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
activeStep.value++
|
if (!formData.materialProcess || formData.materialProcess === '') {
|
||||||
// 进入称重页面时建立WebSocket连接
|
Message.error('未找到物料流程,无法对比')
|
||||||
if (activeStep.value === 2) {
|
return;
|
||||||
establishWebSocket()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用后端接口获取比对结果 // 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连接
|
// 组件卸载时关闭WebSocket连接
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
weighAHStop().catch(error => {
|
||||||
|
console.error('终止电子称连接线程失败:', error)
|
||||||
|
})
|
||||||
closeWebSocket()
|
closeWebSocket()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user