Compare commits

...

3 Commits

Author SHA1 Message Date
2bf7b6872a 抓取优化 2026-03-09 16:22:17 +08:00
zc
a3cb2263fd 优化 2026-03-09 16:06:00 +08:00
zc
d8273464c5 优化 2026-03-09 15:24:02 +08:00
5 changed files with 263 additions and 164 deletions

View File

@@ -12,10 +12,12 @@ export interface WorkOrderResp {
materialSpec: string materialSpec: string
photoUrl: string photoUrl: string
totalWeight: string totalWeight: string
totalCalculatedWeight: string
totalCount: string totalCount: string
createUserString: string createUserString: string
updateUserString: string updateUserString: string
matchResult: string matchResult: string
workOrderInfos: Array<WorkOrderInfoResp>
} }
export interface WorkOrderInfoResp { export interface WorkOrderInfoResp {
@@ -46,9 +48,14 @@ export function listWorkOrder(query: WorkOrderPageQuery) {
return http.get<PageRes<WorkOrderResp[]>>(`${BASE_URL}`, query) return http.get<PageRes<WorkOrderResp[]>>(`${BASE_URL}`, query)
} }
/** @desc 查询工作订单详情 */
export function getWorkOrderInfos(id: string) {
return http.get<Array<WorkOrderInfoResp>>(`${BASE_URL}/info/${id}`)
}
/** @desc 查询工作订单详情 */ /** @desc 查询工作订单详情 */
export function getWorkOrder(id: string) { export function getWorkOrder(id: string) {
return http.get<Array<WorkOrderInfoResp>>(`${BASE_URL}/${id}`) return http.get<WorkOrderResp>(`${BASE_URL}/${id}`)
} }
/** @desc 新增工作订单 */ /** @desc 新增工作订单 */

View File

@@ -9,17 +9,17 @@
<div class="form-grid"> <div class="form-grid">
<div class="form-grid-item"> <div class="form-grid-item">
<a-form-item label="物料名称"> <a-form-item label="物料名称">
<a-input v-model="formData.materialName" placeholder="请输入物料名称" :disabled="isFromWorkOrder" /> <a-input v-model="formData.materialName" placeholder="未获取到物料名称" :disabled="true" />
</a-form-item> </a-form-item>
</div> </div>
<div class="form-grid-item"> <div class="form-grid-item">
<a-form-item label="物料编码"> <a-form-item label="物料编码">
<a-input v-model="formData.encoding" placeholder="请输入物料编码" :disabled="isFromWorkOrder" /> <a-input v-model="formData.encoding" placeholder="未获取到物料编码" :disabled="true" />
</a-form-item> </a-form-item>
</div> </div>
<div class="form-grid-item"> <div class="form-grid-item">
<a-form-item label="工单编号"> <a-form-item label="工单编号">
<a-input v-model="formData.orderNo" placeholder="请输入工单编号" :disabled="isFromWorkOrder" /> <a-input v-model="formData.orderNo" placeholder="未获取到工单编号" :disabled="true" />
</a-form-item> </a-form-item>
</div> </div>
<div class="form-grid-item"> <div class="form-grid-item">
@@ -62,13 +62,13 @@
</td> </td>
<td class="label-cell"> <td class="label-cell">
<div class="label-field">数量</div> <div class="label-field">数量</div>
<div class="label-value">{{ labelData.quantity }}</div> <div class="label-value">{{ labelData.totalCount }}</div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="label-cell"> <td class="label-cell">
<div class="label-field">标重(kg)</div> <div class="label-field">标重(kg)</div>
<div class="label-value">{{ labelData.standardWeight }}</div> <div class="label-value">{{ labelData.totalCalculatedWeight }}</div>
</td> </td>
<td class="label-cell"> <td class="label-cell">
<div class="label-field">包装签字</div> <div class="label-field">包装签字</div>
@@ -78,19 +78,13 @@
<tr> <tr>
<td class="label-cell"> <td class="label-cell">
<div class="label-field">实重(kg)</div> <div class="label-field">实重(kg)</div>
<div class="label-value">{{ labelData.actualWeight || '' }}</div> <div class="label-value">{{ labelData.totalWeight || '' }}</div>
</td> </td>
<td class="label-cell"> <td class="label-cell">
<div class="label-field">检验签字</div> <div class="label-field">检验签字</div>
<div class="label-value">{{ labelData.inspectionSignature || '' }}</div> <div class="label-value">{{ labelData.inspectionSignature || '' }}</div>
</td> </td>
</tr> </tr>
<!-- <tr>-->
<!-- <td class="label-cell" colspan="2"></td>-->
<!-- <td class="label-cell qr-cell">-->
<!-- <div class="serial-number">序号: {{ labelData.serialNumber }}</div>-->
<!-- </td>-->
<!-- </tr>-->
</table> </table>
</div> </div>
</div> </div>
@@ -106,80 +100,71 @@
import { ref, reactive, nextTick, onMounted } from 'vue' import { ref, reactive, nextTick, onMounted } from 'vue'
import { Message } from '@arco-design/web-vue' import { Message } from '@arco-design/web-vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import {getWorkOrder} from "@/apis/workOrder/workOrder";
const route = useRoute() const route = useRoute()
// //
const formData = reactive({ const formData = reactive({
workerOrderId: '',
encoding: '', encoding: '',
materialName: '', materialName: '',
orderNo: '', orderNo: '',
totalCalculatedWeight: '',
totalWeight: '',
totalCount: '',
productionBatch: '' productionBatch: ''
}) })
//
const isFromWorkOrder = ref(false)
// //
const labelData = reactive({ const labelData = reactive({
partName: '', partName: '',
partNumber: '', partNumber: '',
standardWeight: '', totalCalculatedWeight: '',
actualWeight: '', totalWeight: '',
productionDate: '', productionDate: '',
quantity: '', totalCount: '',
packingSignature: '', packingSignature: '',
inspectionSignature: '', inspectionSignature: '',
serialNumber: '',
qrCodeData: '', qrCodeData: '',
}) })
// //
const labelContainer = ref<HTMLElement | null>(null) const labelContainer = ref<HTMLElement | null>(null)
//
const fetchLabelData = async (params: any) => {
//
return new Promise((resolve) => {
setTimeout(() => {
// yyyyMMddHHmm
const now = new Date()
const formattedDate = now.getFullYear().toString() +
String(now.getMonth() + 1).padStart(2, '0') +
String(now.getDate()).padStart(2, '0') +
String(now.getHours()).padStart(2, '0') +
String(now.getMinutes()).padStart(2, '0')
//
const mockData = {
partName: params.materialName || 'PP0449002护套',
partNumber: params.encoding || 'PP0449002',
standardWeight: '0.39500',
actualWeight: '',
productionDate: formattedDate,
quantity: '200',
packingSignature: '',
inspectionSignature: '',
serialNumber: '4',
qrCodeData: `PART:${params.encoding || 'PP0449002'},NAME:${params.materialName || 'PP0449002护套'},DATE:${formattedDate},QTY:200`,
}
resolve(mockData)
}, 500)
})
}
// //
const generateLabel = async () => { const generateLabel = async () => {
if (!formData.productionBatch) { if (!formData.productionBatch) {
Message.error('请输入生产批次') Message.error('请输入生产批次')
return return
} }
if (!formData.materialName) {
Message.error('未获取到物料信息')
return
}
try { try {
// // yyyyMMddHHmm
const result = await fetchLabelData(formData) const now = new Date()
Object.assign(labelData, result) const formattedDate = now.getFullYear().toString() +
String(now.getMonth() + 1).padStart(2, '0') +
String(now.getDate()).padStart(2, '0') +
String(now.getHours()).padStart(2, '0') +
String(now.getMinutes()).padStart(2, '0')
// formData
Object.assign(labelData, {
partName: formData.materialName || '',
partNumber: formData.encoding || '',
totalCalculatedWeight: formData.totalCalculatedWeight || '',
totalWeight: formData.totalWeight || '',
productionDate: formattedDate,
totalCount: formData.totalCount || '',
packingSignature: '',
inspectionSignature: '',
qrCodeData: `PART:${formData.encoding || 'PP0449002'},NAME:${formData.materialName || 'PP0449002护套'},DATE:${formattedDate},QTY:200`,
})
Message.success('标签生成成功') Message.success('标签生成成功')
} catch (error) { } catch (error) {
console.error('生成标签失败:', error) console.error('生成标签失败:', error)
@@ -190,17 +175,24 @@ const generateLabel = async () => {
// //
onMounted(() => { onMounted(() => {
// //
const materialName = route.query.materialName as string const workerOrderId = route.query.workerOrderId as string
const encoding = route.query.encoding as string
const orderNo = route.query.orderNo as string
// //
if (materialName && encoding && orderNo) { if (workerOrderId) {
formData.materialName = materialName formData.workerOrderId = workerOrderId
formData.encoding = encoding getWorkOrder(workerOrderId).then(res => {
formData.orderNo = orderNo if (res.code == '0') {
isFromWorkOrder.value = true formData.encoding = res.data.encoding
formData.materialName = res.data.materialName
formData.orderNo = res.data.orderNo
formData.totalCalculatedWeight = res.data.totalCalculatedWeight
formData.totalWeight = res.data.totalWeight
formData.totalCount = res.data.totalCount
} else {
Message.error('获取详情失败')
}
});
// //
generateLabel() generateLabel()
} }

View File

@@ -20,7 +20,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, onMounted } from 'vue' import { ref, reactive, onMounted, onUnmounted } from 'vue'
import { type FormInstance, Message } from '@arco-design/web-vue' import { type FormInstance, Message } from '@arco-design/web-vue'
import { useTabsStore, useUserStore } from '@/stores' import { useTabsStore, useUserStore } from '@/stores'
@@ -42,12 +42,24 @@ const loading = ref(false)
// 登录 // 登录
const handleLogin = async () => { const handleLogin = async () => {
// 检查用户是否已经登录
if (userStore.token) {
return
}
const isInvalid = await formRef.value?.validate() const isInvalid = await formRef.value?.validate()
if (isInvalid) return if (isInvalid) return
try { try {
loading.value = true loading.value = true
// 调用后端接口校验卡号 // 调用后端接口校验卡号
await userStore.cardLogin(form) await userStore.cardLogin(form)
// 登录成功后移除事件监听器
if (keyDownListener) {
document.removeEventListener('keydown', keyDownListener)
keyDownListener = null
}
tabsStore.reset() tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query const { redirect, ...othersQuery } = router.currentRoute.value.query
await router.push({ await router.push({
@@ -64,24 +76,30 @@ const handleLogin = async () => {
} }
} }
// 键盘事件监听器引用
let keyDownListener: ((e: KeyboardEvent) => void) | null = null
// 监听键盘输入,实现自动识别卡号 // 监听键盘输入,实现自动识别卡号
onMounted(() => { onMounted(() => {
// 监听全局键盘事件,用于识别刷卡输入 // 监听Enter键用于自动登录
document.addEventListener('keydown', (e) => { keyDownListener = (e) => {
// 刷卡器通常会快速输入卡号并以Enter键结束 // 刷卡器通常会快速输入卡号并以Enter键结束
if (e.key === 'Enter') { if (e.key === 'Enter') {
// 遇到Enter键尝试登录 // 遇到Enter键尝试登录
if (form.cardNumber.trim()) { if (form.cardNumber.trim()) {
handleLogin() handleLogin()
} }
} else if (e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey) {
// 只捕获单个字符的按键,忽略控制键和功能键
form.cardNumber += e.key
} else if (e.key === 'Backspace') {
// 处理退格键
form.cardNumber = form.cardNumber.slice(0, -1)
} }
}) }
document.addEventListener('keydown', keyDownListener)
})
// 组件卸载时移除事件监听器
onUnmounted(() => {
if (keyDownListener) {
document.removeEventListener('keydown', keyDownListener)
}
}) })
</script> </script>

View File

@@ -57,7 +57,7 @@
<div class="form-item"> <div class="form-item">
<a-form-item label="物料编码"> <a-form-item label="物料编码">
<a-input <a-input
v-model="formData.inputMaterialCode" v-model="formData.inputMaterialCode"
placeholder="请点击此处确保光标闪烁,并使用扫码枪扫描物料编码" placeholder="请点击此处确保光标闪烁,并使用扫码枪扫描物料编码"
@keydown="handleKeyDown" @keydown="handleKeyDown"
@input="handleMaterialCodeChange" @input="handleMaterialCodeChange"
@@ -74,7 +74,7 @@
<div class="image-placeholder square-image">实时画面 相机1</div> <div class="image-placeholder square-image">实时画面 相机1</div>
<div class="image-placeholder square-image">实时画面 相机2</div> <div class="image-placeholder square-image">实时画面 相机2</div>
</div> </div>
<div class="info-section"> <div class="info-section">
<div class="info-card"> <div class="info-card">
<h4>识别信息</h4> <h4>识别信息</h4>
@@ -92,13 +92,15 @@
<h4>比对结果</h4> <h4>比对结果</h4>
<div class="info-item"> <div class="info-item">
<span class="label">比对结果:</span> <span class="label">比对结果:</span>
<span class="value match-result" :class="{ <span
'match-success': formData.matchResult === 'success', class="value match-result" :class="{
'match-failed': formData.matchResult === 'failed', 'match-success': formData.matchResult === 'success',
'match-pending': !formData.matchResult 'match-failed': formData.matchResult === 'failed',
}"> 'match-pending': !formData.matchResult,
<icon-check-circle-fill v-if="formData.matchResult === 'success'" style="color: #52c41a; margin-right: 8px; font-size: 25px;"/> }"
<icon-close-circle-fill v-else-if="formData.matchResult === 'failed'" style="color: #ff4d4f; margin-right: 8px; font-size: 25px;"/> >
<icon-check-circle-fill v-if="formData.matchResult === 'success'" style="color: #52c41a; margin-right: 8px; font-size: 25px;" />
<icon-close-circle-fill v-else-if="formData.matchResult === 'failed'" style="color: #ff4d4f; margin-right: 8px; font-size: 25px;" />
{{ formData.matchResult === 'success' ? '成功' : formData.matchResult === 'failed' ? '失败' : '-' }} {{ formData.matchResult === 'success' ? '成功' : formData.matchResult === 'failed' ? '失败' : '-' }}
</span> </span>
@@ -135,7 +137,7 @@
<div class="form-row"> <div class="form-row">
<div class="form-item"> <div class="form-item">
<label>对应重量(g):</label> <label>对应重量(g):</label>
<a-input v-model="ahDeviceWeight" placeholder="-" disabled/> <a-input v-model="ahDeviceWeight" placeholder="-" disabled />
</div> </div>
</div> </div>
@@ -246,17 +248,17 @@
<div class="action-buttons"> <div class="action-buttons">
<a-button <a-button
v-if="activeStep > 1 && activeStep < 3" v-if="activeStep > 1 && activeStep < 3"
@click="handlePrevious"
class="previous-button" class="previous-button"
@click="handlePrevious"
> >
上一步 上一步
</a-button> </a-button>
<a-button <a-button
v-if="activeStep < 3" v-if="activeStep < 3"
type="primary" type="primary"
@click="handleNext"
:disabled="activeStep === 1 && formData.matchResult !== 'success'" :disabled="activeStep === 1 && formData.matchResult !== 'success'"
class="next-button" class="next-button"
@click="handleNext"
> >
{{ activeStep === 2 ? '完成' : '下一步' }} {{ activeStep === 2 ? '完成' : '下一步' }}
</a-button> </a-button>
@@ -266,16 +268,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { nextTick, onBeforeUnmount, onMounted, ref, reactive, onUnmounted } from 'vue' import { nextTick, onBeforeUnmount, onMounted, onUnmounted, reactive, ref } from 'vue'
import { Modal, Message } from '@arco-design/web-vue' import { Message, Modal, Notification } from '@arco-design/web-vue'
import { getMaterialDetail } from "@/apis/weightManage/weightManage";
import {addWorkOrder, type WorkOrderResp} from "@/apis/workOrder/workOrder"; import { getMaterialDetail } from '@/apis/weightManage/weightManage'
import { Notification } from "@arco-design/web-vue" import { type WorkOrderResp, addWorkOrder } from '@/apis/workOrder/workOrder'
import { catchPhoto } from '@/apis/material/materialInfo' import { catchPhoto } from '@/apis/material/materialInfo'
defineOptions({ name: 'WeightManage' }) defineOptions({ name: 'WeightManage' })
// 动态导入flv.js // 动态导入flv.js
@@ -554,10 +553,11 @@ const workOrderResp = ref<WorkOrderResp>({
totalCount: '', totalCount: '',
createUserString: '', createUserString: '',
updateUserString: '', updateUserString: '',
matchResult: 'failed' totalCalculatedWeight: '',
workOrderInfos: [],
matchResult: 'failed',
}) })
// 称重登记页面数据 // 称重登记页面数据
const inputQuantity = ref('') const inputQuantity = ref('')
const ahDeviceWeight = ref('10') const ahDeviceWeight = ref('10')
@@ -578,25 +578,25 @@ const columns = [
{ {
title: '称重次数', title: '称重次数',
dataIndex: 'weightTime', dataIndex: 'weightTime',
key: 'weightTime' key: 'weightTime',
}, },
{ {
title: '数量', title: '数量',
dataIndex: 'quantity', dataIndex: 'quantity',
key: 'quantity', key: 'quantity',
className: 'green-bg' className: 'green-bg',
}, },
{ {
title: '重量(g)', title: '重量(g)',
dataIndex: 'weight', dataIndex: 'weight',
key: 'weight', key: 'weight',
className: 'green-bg' className: 'green-bg',
}, },
{ {
title: '计算重量(g)', title: '计算重量(g)',
dataIndex: 'calculatedWeight', dataIndex: 'calculatedWeight',
key: 'calculatedWeight', key: 'calculatedWeight',
className: 'green-bg' className: 'green-bg',
}, },
{ {
title: '抓拍图片', title: '抓拍图片',
@@ -622,33 +622,33 @@ const columns = [
title: '操作', title: '操作',
dataIndex: 'action', dataIndex: 'action',
key: 'action', key: 'action',
slotName: 'action' slotName: 'action',
} },
] ]
// 防抖函数 // 防抖函数
const debounce = <T extends (...args: any[]) => any>(func: T, delay: number): ((...args: Parameters<T>) => void) => { const debounce = <T extends (...args: any[]) => any>(func: T, delay: number): ((...args: Parameters<T>) => void) => {
let timer: ReturnType<typeof setTimeout> | null = null; let timer: ReturnType<typeof setTimeout> | null = null
return function(...args: Parameters<T>) { return function (...args: Parameters<T>) {
if (timer) clearTimeout(timer); if (timer) clearTimeout(timer)
timer = setTimeout(() => { timer = setTimeout(() => {
func(...args); func(...args)
}, delay); }, delay)
}; }
}; }
// 原始的物料编码变化处理函数 // 原始的物料编码变化处理函数
const originalHandleMaterialCodeChange = async () => { const originalHandleMaterialCodeChange = async () => {
// 确保输入框内容是完整的物料编码 // 确保输入框内容是完整的物料编码
const materialCode = formData.inputMaterialCode?.trim(); const materialCode = formData.inputMaterialCode?.trim()
// 无论是否有输入,先重置所有物料相关字段,确保新数据能完全覆盖旧数据 // 无论是否有输入,先重置所有物料相关字段,确保新数据能完全覆盖旧数据
formData.encoding = ""; formData.encoding = ''
formData.materialName = ""; formData.materialName = ''
formData.materialSpec = ""; formData.materialSpec = ''
formData.unitWeight = 0; formData.unitWeight = 0
formData.photoUrl = ""; formData.photoUrl = ''
formData.matchResult = ""; formData.matchResult = ''
// 如果有物料编码输入,获取物料数据 // 如果有物料编码输入,获取物料数据
if (materialCode) { if (materialCode) {
@@ -659,17 +659,17 @@ const originalHandleMaterialCodeChange = async () => {
// 即使获取失败,也保持字段为空,避免显示旧数据 // 即使获取失败,也保持字段为空,避免显示旧数据
} }
} }
}; }
// 记录上次输入时间,用于判断是否是扫码枪输入 // 记录上次输入时间,用于判断是否是扫码枪输入
let lastInputTime = 0; let lastInputTime = 0
// 记录输入内容,用于判断是否是新的扫码 // 记录输入内容,用于判断是否是新的扫码
let previousInput = ''; const previousInput = ''
// 处理键盘按下事件 // 处理键盘按下事件
const handleKeyDown = (event: KeyboardEvent) => { const handleKeyDown = (event: KeyboardEvent) => {
// 获取当前时间 // 获取当前时间
const currentTime = Date.now(); const currentTime = Date.now()
// 如果输入速度非常快小于100ms认为是扫码枪输入 // 如果输入速度非常快小于100ms认为是扫码枪输入
if (currentTime - lastInputTime < 100 && formData.inputMaterialCode) { if (currentTime - lastInputTime < 100 && formData.inputMaterialCode) {
@@ -677,33 +677,33 @@ const handleKeyDown = (event: KeyboardEvent) => {
} else if (event.key.length === 1 && !event.ctrlKey && !event.altKey) { } else if (event.key.length === 1 && !event.ctrlKey && !event.altKey) {
// 如果是新的输入(不是快速连续输入),清空输入框 // 如果是新的输入(不是快速连续输入),清空输入框
// 这样可以确保每次扫码都从空输入框开始 // 这样可以确保每次扫码都从空输入框开始
formData.inputMaterialCode = ''; formData.inputMaterialCode = ''
} }
// 更新上次输入时间 // 更新上次输入时间
lastInputTime = currentTime; lastInputTime = currentTime
}; }
// 带防抖的物料编码变化处理函数 // 带防抖的物料编码变化处理函数
const handleMaterialCodeChange = debounce(originalHandleMaterialCodeChange, 500); // 500ms防抖延迟 const handleMaterialCodeChange = debounce(originalHandleMaterialCodeChange, 500) // 500ms防抖延迟
// 扫码核验获取物料信息 // 扫码核验获取物料信息
const fetchMaterialData = async (code: string) => { const fetchMaterialData = async (code: string) => {
getMaterialDetail(code).then(res => { getMaterialDetail(code).then((res) => {
if (res.code == '0') { if (res.code === '0') {
// 更新表单数据 // 更新表单数据
formData.id = res.data?.id || ""; formData.id = res.data?.id || ''
formData.encoding = res.data?.encoding || ""; formData.encoding = res.data?.encoding || ''
formData.materialName = res.data?.materialName || ""; formData.materialName = res.data?.materialName || ''
formData.materialSpec = res.data?.materialSpec || ""; formData.materialSpec = res.data?.materialSpec || ''
formData.unitWeight = res.data?.unitWeight || 0; formData.unitWeight = res.data?.unitWeight || 0
formData.photoUrl = res.data?.photoUrl || ""; formData.photoUrl = res.data?.photoUrl || ''
// 假设后端返回比对结果 // 假设后端返回比对结果
// formData.matchResult = res.data.matchResult || 'failed' // 这里根据实际接口返回调整 // formData.matchResult = res.data.matchResult || 'failed' // 这里根据实际接口返回调整
formData.matchResult = res.data?.matchResult || 'success' // 这里根据实际接口返回调整 formData.matchResult = res.data?.matchResult || 'success' // 这里根据实际接口返回调整
return true return true
} }
}); })
} }
// 处理下一步 // 处理下一步
@@ -720,20 +720,20 @@ const handleNext = async () => {
const workOrderData = { const workOrderData = {
materialId: formData.id, materialId: formData.id,
materialName: formData.materialName, materialName: formData.materialName,
workOrderInfos: weighingList.value workOrderInfos: weighingList.value,
} }
// 调用后端接口 // 调用后端接口
addWorkOrder(workOrderData).then(res => { addWorkOrder(workOrderData).then((res) => {
if (res.code == '0') { if (res.code === '0') {
Notification.success({ Notification.success({
title: '操作成功', title: '操作成功',
content: `工单创建成功!` content: `工单创建成功!`,
}) })
workOrderResp.value.matchResult = 'success'; workOrderResp.value.matchResult = 'success'
workOrderResp.value.title = res.data?.title || ""; workOrderResp.value.title = res.data?.title || ''
workOrderResp.value.orderNo = res.data?.orderNo || ""; workOrderResp.value.orderNo = res.data?.orderNo || ''
workOrderResp.value.totalWeight = res.data?.totalWeight || ""; workOrderResp.value.totalWeight = res.data?.totalWeight || ''
workOrderResp.value.totalCount = res.data?.totalCount || ""; workOrderResp.value.totalCount = res.data?.totalCount || ''
// 关闭WebSocket连接 // 关闭WebSocket连接
closeWebSocket() closeWebSocket()
@@ -741,12 +741,12 @@ const handleNext = async () => {
activeStep.value++ activeStep.value++
return true return true
} }
}); })
} catch (error) { } catch (error) {
console.error('创建工作订单失败:', error) console.error('创建工作订单失败:', error)
Message.error('创建工作订单失败') Message.error('创建工作订单失败')
} }
} },
}) })
} else { } else {
activeStep.value++ activeStep.value++
@@ -771,7 +771,30 @@ const handlePrevious = () => {
// 返回第一步 // 返回第一步
const handleBackToFirst = () => { const handleBackToFirst = () => {
// 重置所有数据
activeStep.value = 1 activeStep.value = 1
// 重置表单数据
formData.inputMaterialCode = ''
formData.id = ''
formData.encoding = ''
formData.materialName = ''
formData.materialSpec = ''
formData.unitWeight = 0
formData.photoUrl = ''
formData.matchResult = ''
// 重置称重登记页面数据
inputQuantity.value = ''
ahDeviceWeight.value = '10'
calculatedWeight.value = ''
weighingCount.value = 1
// 清空称重列表
weighingList.value = []
// 重置工作订单响应数据
workOrderResp.value = {}
// 离开称重页面时关闭WebSocket连接 // 离开称重页面时关闭WebSocket连接
closeWebSocket() closeWebSocket()
} }
@@ -779,8 +802,8 @@ const handleBackToFirst = () => {
// 计算重量 // 计算重量
const calculateWeight = () => { const calculateWeight = () => {
if (inputQuantity.value && formData.unitWeight) { if (inputQuantity.value && formData.unitWeight) {
const singleWeight = parseFloat(formData.unitWeight.toString()) const singleWeight = Number.parseFloat(formData.unitWeight.toString())
const quantity = parseFloat(inputQuantity.value) const quantity = Number.parseFloat(inputQuantity.value)
if (!isNaN(singleWeight) && !isNaN(quantity)) { if (!isNaN(singleWeight) && !isNaN(quantity)) {
calculatedWeight.value = (singleWeight * quantity).toFixed(2) calculatedWeight.value = (singleWeight * quantity).toFixed(2)
} }
@@ -789,10 +812,8 @@ const calculateWeight = () => {
} }
} }
// 处理确定 // 处理确定
const handleConfirm = () => { /* const handleConfirm = async () => {
// 校验输入数量是否为空 // 校验输入数量是否为空
if (!inputQuantity.value || inputQuantity.value.trim() === '') { if (!inputQuantity.value || inputQuantity.value.trim() === '') {
Message.error('请输入数量') Message.error('请输入数量')
@@ -803,6 +824,12 @@ const handleConfirm = () => {
return return
} }
// 2. 抓拍当前画面
let captureUrl = ''
if (cameraVideo.value && cameraStatus.value === 'connected') {
captureUrl = await capturePhoto()
}
console.log(captureUrl)
// 生成新的列表数据 // 生成新的列表数据
const newItem = { const newItem = {
key: (weighingList.value.length + 1).toString(), key: (weighingList.value.length + 1).toString(),
@@ -821,11 +848,69 @@ const handleConfirm = () => {
calculatedWeight.value = '' calculatedWeight.value = ''
// 称重次数累加 // 称重次数累加
weighingCount.value = weighingList.value.length + 1 weighingCount.value = weighingList.value.length + 1
Message.success('添加成功')
} */
const handleConfirm = () => {
// 校验输入数量是否为空
if (!inputQuantity.value || inputQuantity.value.trim() === '') {
Message.error('请输入数量')
return
}
if (!ahDeviceWeight.value || ahDeviceWeight.value.trim() === '') {
Message.error('电子秤称重结果为空!')
return
}
// 立即创建一个新项的基本数据
const newItem = {
key: (weighingList.value.length + 1).toString(),
weightTime: weighingCount.value,
materialId: formData.id,
quantity: inputQuantity.value,
weight: ahDeviceWeight.value,
calculatedWeight: calculatedWeight.value,
image: '加载中...', // 先显示加载状态
}
// 先添加到列表,让用户能立即看到记录
weighingList.value.push(newItem)
// 重置输入(让用户能继续输入)
inputQuantity.value = ''
ahDeviceWeight.value = '10'
calculatedWeight.value = ''
weighingCount.value = weighingList.value.length + 1
// 异步执行抓拍,不阻塞主流程
if (cameraVideo.value && cameraStatus.value === 'connected') {
// 立即执行异步抓拍
capturePhoto().then((captureUrl) => {
// 找到刚刚添加的项更新图片URL
const addedItem = weighingList.value.find((item) => item.key === newItem.key)
if (addedItem) {
addedItem.image = captureUrl || '抓拍失败'
// 触发视图更新
weighingList.value = [...weighingList.value]
}
Message.success('图片抓拍成功')
}).catch((error) => {
})
} else {
// 摄像头未连接,直接显示未抓拍
const addedItem = weighingList.value.find((item) => item.key === newItem.key)
if (addedItem) {
addedItem.image = '未抓拍'
weighingList.value = [...weighingList.value]
}
}
Message.success('添加成功') Message.success('添加成功')
} }
// 抓拍功能 - 内部方法,不暴露按钮 // 抓拍功能 - 内部方法,不暴露按钮
const capturePhoto = async (): Promise<string> => { const capturePhoto = (): Promise<string> => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const video = cameraVideo.value const video = cameraVideo.value
@@ -852,8 +937,7 @@ const capturePhoto = async (): Promise<string> => {
// 调用后端接口 // 调用后端接口
const response = await catchPhoto(formData) const response = await catchPhoto(formData)
if (!response.code === '200') { if (response.msg !== 'ok') {
reject(new Error('上传失败'))
return return
} }
@@ -892,7 +976,7 @@ const handleReset = () => {
// 处理删除 // 处理删除
const handleDelete = (key) => { const handleDelete = (key) => {
// 过滤掉要删除的项 // 过滤掉要删除的项
weighingList.value = weighingList.value.filter(item => item.key !== key) weighingList.value = weighingList.value.filter((item) => item.key !== key)
// 重新排序称重次数 // 重新排序称重次数
weighingList.value.forEach((item, index) => { weighingList.value.forEach((item, index) => {
item.weightTime = index + 1 item.weightTime = index + 1
@@ -1368,4 +1452,4 @@ onUnmounted(() => {
font-size: 14px; font-size: 14px;
margin-right: 12px; margin-right: 12px;
} }
</style> </style>

View File

@@ -117,7 +117,7 @@ import {Message} from "@arco-design/web-vue";
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { import {
deleteWorkOrder, deleteWorkOrder,
exportWorkOrder, getWorkOrder, exportWorkOrder, getWorkOrderInfos,
listWorkOrder, listWorkOrder,
type WorkOrderQuery, type WorkOrderQuery,
type WorkOrderResp type WorkOrderResp
@@ -172,7 +172,7 @@ const columns = ref<TableInstanceColumns[]>(processColumns([
{ title: '物料编码', dataIndex: 'encoding' }, { title: '物料编码', dataIndex: 'encoding' },
{ title: '单位克重', dataIndex: 'unitWeight' ,slotName: 'unitWeight'}, { title: '单位克重', dataIndex: 'unitWeight' ,slotName: 'unitWeight'},
{ title: '总重量', dataIndex: 'totalWeight' ,slotName: 'totalWeight'}, { title: '总重量', dataIndex: 'totalWeight' ,slotName: 'totalWeight'},
{ title: '称重次数', dataIndex: 'totalCount' }, { title: '总数量', dataIndex: 'totalCount' },
{ title: '创建时间', dataIndex: 'createTime', width: 180 }, { title: '创建时间', dataIndex: 'createTime', width: 180 },
{ {
title: '操作', title: '操作',
@@ -218,7 +218,7 @@ const onDetail = async (record: WorkOrderResp) => {
detailModalVisible.value = true detailModalVisible.value = true
detailData.value = [] detailData.value = []
getWorkOrder(record.id).then(res => { getWorkOrderInfos(record.id).then(res => {
if (res.code == '0') { if (res.code == '0') {
detailData.value = res.data; detailData.value = res.data;
detailLoading.value = false detailLoading.value = false
@@ -258,9 +258,7 @@ const onPrint = (record: WorkOrderResp) => {
router.push({ router.push({
path: '/print', path: '/print',
query: { query: {
materialName: record.materialName, workerOrderId: record.id,
encoding: record.encoding,
orderNo: record.orderNo
} }
}) })
} }