This commit is contained in:
zc
2026-03-20 11:00:23 +08:00
parent c4303b4d5f
commit 69f97a740d
8 changed files with 112 additions and 51 deletions

View File

@@ -131,7 +131,7 @@
<div class="form-row">
<div class="form-item">
<label>输入数量:</label>
<a-input v-model="inputQuantity" placeholder="请输入数量" @change="calculateWeight" />
<a-input-number :min="1" mode="button" v-model="inputQuantity" placeholder="请输入数量" @change="calculateWeight" />
</div>
</div>
<div class="form-row">
@@ -139,13 +139,17 @@
<label>计算重量(g):</label>
<a-input v-model="calculatedWeight" placeholder="-" disabled />
</div>
</div>
<div class="form-row">
<div class="form-item">
<label>对应重量(g):</label>
<a-input v-model="ahDeviceWeight" placeholder="-" disabled />
</div>
</div>
<div class="form-row">
<div class="form-item">
<label>该物料重量范围:</label>
<a-input v-model="formData.materialName" placeholder="该物料重量范围" disabled />
</div>
</div>
<!-- 这里是摄像头画面 - 替换成FLV播放器 -->
<div class="video-container large-image">
@@ -463,30 +467,30 @@ const checkCameraStatus = () => {
let statusCheckTimer: any = null
// 监听步骤变化
watch(activeStep, (newVal) => {
if (newVal === 2) {
// 进入称重登记页面,启动摄像头
reconnectCount.value = 1 // 重置重连计数
nextTick(() => {
initCamera()
})
// 启动状态检查每30秒检查一次
statusCheckTimer = setInterval(checkCameraStatus, 30000)
} else {
// 离开称重登记页面,停止摄像头和定时器
stopCamera()
if (statusCheckTimer) {
clearInterval(statusCheckTimer)
statusCheckTimer = null
}
if (reconnectTimer.value) {
clearTimeout(reconnectTimer.value)
reconnectTimer.value = null
}
reconnectCount.value = 1
}
})
// watch(activeStep, (newVal) => {
// if (newVal === 2) {
// // 进入称重登记页面,启动摄像头
// reconnectCount.value = 1 // 重置重连计数
// nextTick(() => {
// initCamera()
// })
//
// // 启动状态检查每30秒检查一次
// statusCheckTimer = setInterval(checkCameraStatus, 30000)
// } else {
// // 离开称重登记页面,停止摄像头和定时器
// stopCamera()
// if (statusCheckTimer) {
// clearInterval(statusCheckTimer)
// statusCheckTimer = null
// }
// if (reconnectTimer.value) {
// clearTimeout(reconnectTimer.value)
// reconnectTimer.value = null
// }
// reconnectCount.value = 1
// }
// })
// 组件卸载时清理所有定时器
onBeforeUnmount(() => {
@@ -594,9 +598,9 @@ const workOrderResp = ref<WorkOrderResp>({
})
// 称重登记页面数据
const inputQuantity = ref('')
const inputQuantity = ref()
// todo
const ahDeviceWeight = ref('10.1')
const ahDeviceWeight = ref('100')
const calculatedWeight = ref('')
const weighingCount = ref(1)
@@ -871,7 +875,7 @@ const handleBackToFirst = () => {
// 重置称重登记页面数据
inputQuantity.value = ''
// todo
ahDeviceWeight.value = '10.1'
ahDeviceWeight.value = '100'
calculatedWeight.value = ''
weighingCount.value = 1
// 清空称重列表
@@ -908,8 +912,8 @@ const calculateWeight = () => {
//处理确定
const handleConfirm = async () => {
// 校验输入数量是否为空
if (!inputQuantity.value || inputQuantity.value.trim() === '') {
Message.error('请输入数量')
if (!inputQuantity.value || inputQuantity.value <= 0) {
Message.error('数量需大于0')
return
}
if (!ahDeviceWeight.value || ahDeviceWeight.value.trim() === '') {
@@ -919,15 +923,27 @@ const handleConfirm = async () => {
const data = {
calculatedWeight: calculatedWeight.value,
materialId: formData.id,
inputQuantity: inputQuantity.value,
ahDeviceWeight: ahDeviceWeight.value,
}
const res = await validateWeighing(data);
if (res.code != '0') {
Message.error(res.msg || '系统异常!');
// 然后处理错误信息
if (!res || !res.code) {
return;
}
if (res.data.code !== '200') {
if (res.data.code !== '501') {
playAudio('tooMany')
}
if (res.data.code !== '502') {
playAudio('tooLess')
}
Message.error(res.data.msg || '系统异常!');
return;
}
// 立即创建一个新项的基本数据
const newItem = {
@@ -946,7 +962,7 @@ const handleConfirm = async () => {
// 重置输入(让用户能继续输入)
inputQuantity.value = ''
// todo
ahDeviceWeight.value = '10.1'
ahDeviceWeight.value = '100'
calculatedWeight.value = ''
weighingCount.value = weighingList.value.length + 1
@@ -1098,6 +1114,20 @@ const closeWebSocket = () => {
}
}
// 播放音频文件
const playAudio = (filename: string) => {
console.log(filename)
try {
// 创建音频对象并播放
const audio = new Audio(`/src/assets/wav/${filename}.wav`)
audio.play().catch(error => {
console.error('音频播放失败:', error)
})
} catch (error) {
console.error('播放音频时出错:', error)
}
}
// 组件卸载时关闭WebSocket连接
onUnmounted(() => {
closeWebSocket()