Compare commits

...

8 Commits

Author SHA1 Message Date
zc
630a98af65 优化 2026-03-06 18:25:24 +08:00
zc
31178da436 Merge remote-tracking branch 'refs/remotes/origin/master' into dev
# Conflicts:
#	src/views/weightManage/index.vue
2026-03-06 18:15:58 +08:00
zc
323a641fa3 Merge branch 'refs/heads/master' into dev
# Conflicts:
#	src/views/system/user/index.vue
2026-03-06 18:06:34 +08:00
zc
c858ace541 优化 2026-03-06 18:04:40 +08:00
zc
006130b4b7 优化 2026-03-06 16:29:31 +08:00
zc
b4ebebe2a8 优化 2026-03-06 15:54:36 +08:00
zc
60933ee1a6 优化 2026-03-06 14:17:19 +08:00
zc
d014699b95 优化 2026-03-05 18:14:25 +08:00
6 changed files with 679 additions and 128 deletions

1
package-lock.json generated
View File

@@ -766,7 +766,6 @@
},
"node_modules/@clack/prompts/node_modules/is-unicode-supported": {
"version": "1.3.0",
"extraneous": true,
"inBundle": true,
"license": "MIT",
"engines": {

View File

@@ -5,6 +5,7 @@ const BASE_URL = '/weighManage/workOrder'
export interface WorkOrderResp {
id: string
title: string
orderNo: string
materialName: string
encoding: string
unitWeight: string
@@ -14,6 +15,7 @@ export interface WorkOrderResp {
totalCount: string
createUserString: string
updateUserString: string
matchResult: string
}
export interface WorkOrderInfoResp {
@@ -49,6 +51,11 @@ export function getWorkOrder(id: string) {
return http.get<Array<WorkOrderInfoResp>>(`${BASE_URL}/${id}`)
}
/** @desc 新增工作订单 */
export function addWorkOrder(data: any) {
return http.post(`${BASE_URL}`, data)
}
/** @desc 删除工作订单 */
export function deleteWorkOrder(ids: string | Array<string>) {
return http.del(`${BASE_URL}/${ids}`)

View File

@@ -13,11 +13,10 @@ declare module 'vue' {
ABreadcrumb: typeof import('@arco-design/web-vue')['Breadcrumb']
ABreadcrumbItem: typeof import('@arco-design/web-vue')['BreadcrumbItem']
AButton: typeof import('@arco-design/web-vue')['Button']
ACard: typeof import('@arco-design/web-vue')['Card']
ACheckbox: typeof import('@arco-design/web-vue')['Checkbox']
ACheckboxGroup: typeof import('@arco-design/web-vue')['CheckboxGroup']
ACol: typeof import('@arco-design/web-vue')['Col']
AConfigProvider: typeof import('@arco-design/web-vue')['ConfigProvider']
ADatePicker: typeof import('@arco-design/web-vue')['DatePicker']
ADescriptions: typeof import('@arco-design/web-vue')['Descriptions']
ADescriptionsItem: typeof import('@arco-design/web-vue')['DescriptionsItem']
ADivider: typeof import('@arco-design/web-vue')['Divider']
@@ -27,8 +26,6 @@ declare module 'vue' {
AEmpty: typeof import('@arco-design/web-vue')['Empty']
AForm: typeof import('@arco-design/web-vue')['Form']
AFormItem: typeof import('@arco-design/web-vue')['FormItem']
AGrid: typeof import('@arco-design/web-vue')['Grid']
AGridItem: typeof import('@arco-design/web-vue')['GridItem']
AIcon: typeof import('@arco-design/web-vue')['Icon']
AImage: typeof import('@arco-design/web-vue')['Image']
AInput: typeof import('@arco-design/web-vue')['Input']
@@ -42,31 +39,23 @@ declare module 'vue' {
AMenu: typeof import('@arco-design/web-vue')['Menu']
AMenuItem: typeof import('@arco-design/web-vue')['MenuItem']
AModal: typeof import('@arco-design/web-vue')['Modal']
AOverflowList: typeof import('@arco-design/web-vue')['OverflowList']
APagination: typeof import('@arco-design/web-vue')['Pagination']
APopover: typeof import('@arco-design/web-vue')['Popover']
AProgress: typeof import('@arco-design/web-vue')['Progress']
ARadio: typeof import('@arco-design/web-vue')['Radio']
ARadioGroup: typeof import('@arco-design/web-vue')['RadioGroup']
ARangePicker: typeof import('@arco-design/web-vue')['RangePicker']
ARow: typeof import('@arco-design/web-vue')['Row']
AScrollbar: typeof import('@arco-design/web-vue')['Scrollbar']
ASelect: typeof import('@arco-design/web-vue')['Select']
ASpace: typeof import('@arco-design/web-vue')['Space']
ASpin: typeof import('@arco-design/web-vue')['Spin']
AStatistic: typeof import('@arco-design/web-vue')['Statistic']
ASubMenu: typeof import('@arco-design/web-vue')['SubMenu']
ASwitch: typeof import('@arco-design/web-vue')['Switch']
ATable: typeof import('@arco-design/web-vue')['Table']
ATabPane: typeof import('@arco-design/web-vue')['TabPane']
ATabs: typeof import('@arco-design/web-vue')['Tabs']
ATag: typeof import('@arco-design/web-vue')['Tag']
ATextarea: typeof import('@arco-design/web-vue')['Textarea']
ATooltip: typeof import('@arco-design/web-vue')['Tooltip']
ATree: typeof import('@arco-design/web-vue')['Tree']
ATreeSelect: typeof import('@arco-design/web-vue')['TreeSelect']
ATrigger: typeof import('@arco-design/web-vue')['Trigger']
ATypographyParagraph: typeof import('@arco-design/web-vue')['TypographyParagraph']
AUpload: typeof import('@arco-design/web-vue')['Upload']
Avatar: typeof import('./../components/Avatar/index.vue')['default']
AWatermark: typeof import('@arco-design/web-vue')['Watermark']
Breadcrumb: typeof import('./../components/Breadcrumb/index.vue')['default']

View File

@@ -0,0 +1,377 @@
<template>
<div class="gi_page">
<div class="container">
<h2 class="page-title">标签打印</h2>
<!-- 标签参数设置 -->
<div class="form-section">
<a-form :model="formData" layout="vertical">
<div class="form-grid">
<div class="form-grid-item">
<a-form-item label="物料名称">
<a-input v-model="formData.materialName" placeholder="请输入物料名称" :disabled="isFromWorkOrder" />
</a-form-item>
</div>
<div class="form-grid-item">
<a-form-item label="物料编码">
<a-input v-model="formData.encoding" placeholder="请输入物料编码" :disabled="isFromWorkOrder" />
</a-form-item>
</div>
<div class="form-grid-item">
<a-form-item label="工单编号">
<a-input v-model="formData.orderNo" placeholder="请输入工单编号" :disabled="isFromWorkOrder" />
</a-form-item>
</div>
<div class="form-grid-item">
<a-form-item label="生产批次" required>
<a-input v-model="formData.productionBatch" placeholder="请输入生产批次" />
</a-form-item>
</div>
</div>
<div class="form-actions">
<a-button type="primary" @click="generateLabel" :disabled="!formData.productionBatch">生成标签</a-button>
</div>
</a-form>
</div>
<!-- 标签预览 -->
<div v-if="labelData.partName" class="label-preview-section">
<h3>标签预览</h3>
<div class="label-container" ref="labelContainer">
<div class="label" v-for="index in 1" :key="index">
<table class="label-table">
<tr>
<td class="label-cell">
<div class="label-field">零件名称</div>
<div class="label-value">{{ labelData.partName }}</div>
</td>
<td class="label-cell">
<div class="label-field">生产日期</div>
<div class="label-value">{{ labelData.productionDate }}</div>
</td>
<td class="label-cell qr-cell" rowspan="4">
<div class="qr-code">
<img :src="`https://api.qrserver.com/v1/create-qr-code/?size=120x120&data=${encodeURIComponent(labelData.qrCodeData)}`" alt="QR Code" />
</div>
</td>
</tr>
<tr>
<td class="label-cell">
<div class="label-field">零件号</div>
<div class="label-value">{{ labelData.partNumber }}</div>
</td>
<td class="label-cell">
<div class="label-field">数量</div>
<div class="label-value">{{ labelData.quantity }}</div>
</td>
</tr>
<tr>
<td class="label-cell">
<div class="label-field">标重(kg)</div>
<div class="label-value">{{ labelData.standardWeight }}</div>
</td>
<td class="label-cell">
<div class="label-field">包装签字</div>
<div class="label-value">{{ labelData.packingSignature || '' }}</div>
</td>
</tr>
<tr>
<td class="label-cell">
<div class="label-field">实重(kg)</div>
<div class="label-value">{{ labelData.actualWeight || '' }}</div>
</td>
<td class="label-cell">
<div class="label-field">检验签字</div>
<div class="label-value">{{ labelData.inspectionSignature || '' }}</div>
</td>
</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>
</div>
</div>
<div class="label-actions">
<a-button type="primary" @click="printLabel">打印标签</a-button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, nextTick, onMounted } from 'vue'
import { Message } from '@arco-design/web-vue'
import { useRoute } from 'vue-router'
const route = useRoute()
// 表单数据
const formData = reactive({
encoding: '',
materialName: '',
orderNo: '',
productionBatch: ''
})
// 是否是从工单页面跳转过来的
const isFromWorkOrder = ref(false)
// 标签数据
const labelData = reactive({
partName: '',
partNumber: '',
standardWeight: '',
actualWeight: '',
productionDate: '',
quantity: '',
packingSignature: '',
inspectionSignature: '',
serialNumber: '',
qrCodeData: '',
})
// 标签容器引用
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 () => {
if (!formData.productionBatch) {
Message.error('请输入生产批次')
return
}
try {
// 获取标签数据
const result = await fetchLabelData(formData)
Object.assign(labelData, result)
Message.success('标签生成成功')
} catch (error) {
console.error('生成标签失败:', error)
Message.error('生成标签失败')
}
}
// 组件挂载时,检查是否有参数传递
onMounted(() => {
// 从路由参数中获取数据
const materialName = route.query.materialName as string
const encoding = route.query.encoding as string
const orderNo = route.query.orderNo as string
// 如果有参数传递,设置表单数据并标记为不可修改
if (materialName && encoding && orderNo) {
formData.materialName = materialName
formData.encoding = encoding
formData.orderNo = orderNo
isFromWorkOrder.value = true
// 自动生成标签
generateLabel()
}
})
// 打印标签
const printLabel = async () => {
await nextTick()
if (labelContainer.value) {
// 克隆标签容器内容用于打印
const printContent = labelContainer.value.cloneNode(true) as HTMLElement
// 创建打印窗口
const printWindow = window.open('', '_blank')
if (printWindow) {
printWindow.document.write(`
<html>
<head>
<title>标签打印</title>
<style>
body { margin: 0; padding: 10mm; font-family: Arial, sans-serif; }
.label-container { display: flex; flex-wrap: wrap; gap: 10mm; justify-content: center; }
.label { width: 90mm; height: 36mm; border: 1px solid #000; padding: 0; box-sizing: border-box; page-break-inside: avoid; }
.label-table { width: 100%; height: 100%; border-collapse: collapse; }
.label-cell { border: 1px solid #000; padding: 1mm; vertical-align: top; }
.qr-cell { width: 24mm; text-align: center; vertical-align: middle; }
.label-field { font-size: 7pt; font-weight: bold; margin-bottom: 0.5mm; }
.label-value { font-size: 7pt; }
.qr-code img { width: 20mm; height: 20mm; margin: 1mm 0; }
.serial-number { font-size: 7pt; margin-top: 1mm; }
</style>
</head>
<body>
${printContent.innerHTML}
</body>
</html>
`)
printWindow.document.close()
printWindow.focus()
printWindow.print()
printWindow.close()
}
}
}
defineOptions({ name: 'BarcodePrint' })
</script>
<style scoped lang="scss">
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.page-title {
margin-bottom: 30px;
text-align: center;
color: #333;
}
/* 表单区域 */
.form-section {
background-color: var(--color-bg-2);
padding: 20px;
border-radius: 4px;
margin-bottom: 30px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.form-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 16px;
margin-bottom: 20px;
}
.form-grid-item {
width: 100%;
}
.form-actions {
margin-top: 20px;
display: flex;
justify-content: center;
}
/* 标签预览 */
.label-preview-section {
margin-top: 30px;
padding: 20px;
background-color: var(--color-bg-2);
border-radius: 4px;
}
.label-preview-section h3 {
margin: 0 0 20px 0;
font-size: 16px;
font-weight: bold;
text-align: center;
}
.label-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
margin-bottom: 20px;
}
.label {
width: 450px;
height: 180px;
border: 1px solid #000;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
.label-table {
width: 100%;
height: 100%;
border-collapse: collapse;
}
.label-cell {
border: 1px solid #000;
padding: 5px;
vertical-align: top;
}
.qr-cell {
width: 120px;
text-align: center;
vertical-align: middle;
}
.label-field {
font-size: 12px;
font-weight: bold;
margin-bottom: 2px;
}
.label-value {
font-size: 12px;
}
.qr-code img {
width: 100px;
height: 100px;
margin: 5px 0;
}
.serial-number {
font-size: 12px;
margin-top: 5px;
}
.label-actions {
display: flex;
justify-content: center;
margin-top: 20px;
}
/* 确保输入框宽度一致 */
:deep(.arco-input-wrapper) {
width: 100%;
height: 35px;
}
:deep(.arco-input) {
font-size: 16px;
}
</style>

View File

@@ -48,7 +48,7 @@
</a-form-item>
</div>
<div class="form-item">
<a-form-item label="重量">
<a-form-item label="重量(g)">
<a-input v-model="formData.unitWeight" placeholder="Kg" disabled />
</a-form-item>
</div>
@@ -57,9 +57,10 @@
<div class="form-item">
<a-form-item label="物料编码">
<a-input
v-model="formData.inputMaterialCode"
placeholder="请使用扫码枪扫描物料编码"
@change="handleMaterialCodeChange"
v-model="formData.inputMaterialCode"
placeholder="请点击此处确保光标闪烁,并使用扫码枪扫描物料编码"
@keydown="handleKeyDown"
@input="handleMaterialCodeChange"
/>
</a-form-item>
</div>
@@ -73,7 +74,7 @@
<div class="image-placeholder square-image">实时画面 相机1</div>
<div class="image-placeholder square-image">实时画面 相机2</div>
</div>
<div class="info-section">
<div class="info-card">
<h4>识别信息</h4>
@@ -91,15 +92,13 @@
<h4>比对结果</h4>
<div class="info-item">
<span class="label">比对结果:</span>
<span
class="value match-result" :class="{
'match-success': formData.matchResult === 'success',
'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;" />
<span class="value match-result" :class="{
'match-success': formData.matchResult === 'success',
'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;"/>
{{ formData.matchResult === 'success' ? '成功' : formData.matchResult === 'failed' ? '失败' : '-' }}
</span>
@@ -129,14 +128,14 @@
</div>
<div class="form-row">
<div class="form-item">
<label>计算重量:</label>
<label>计算重量(g):</label>
<a-input v-model="calculatedWeight" placeholder="-" disabled />
</div>
</div>
<div class="form-row">
<div class="form-item">
<label>对应重量:</label>
<a-input v-model="inputWeight" placeholder="-" disabled />
<label>对应重量(g):</label>
<a-input v-model="ahDeviceWeight" placeholder="-" disabled/>
</div>
</div>
@@ -207,14 +206,14 @@
<div v-else-if="activeStep === 3" class="step-content">
<div class="completion-content">
<div class="completion-icon">
<icon-check-circle-fill :size="64" style="color: #52c41a;" />
<a-icon type="check-circle" :size="64" style="color: #52c41a;" />
</div>
<h2>创建完成</h2>
<p>任务已成功创建以下是任务详情</p>
<h2>{{ workOrderResp.matchResult === 'success' ? '创建成功' : '创建失败' }}</h2>
<p>{{ workOrderResp.matchResult === 'success' ? '任务创建成功' : '任务创建失败' }}以下是任务详情</p>
<div class="completion-info">
<div class="info-item">
<span class="label">任务ID:</span>
<span class="value">{{ taskId }}</span>
<span class="label">任务工单号:</span>
<span class="value">{{ workOrderResp.orderNo }}</span>
</div>
<div class="info-item">
<span class="label">物料名称:</span>
@@ -229,8 +228,12 @@
<span class="value">{{ formData.materialSpec }}</span>
</div>
<div class="info-item">
<span class="label">重量:</span>
<span class="value">{{ formData.unitWeight }}</span>
<span class="label">物料总个数:</span>
<span class="value">{{ workOrderResp.totalCount }}</span>
</div>
<div class="info-item">
<span class="label">物料总重量(g):</span>
<span class="value">{{ workOrderResp.totalWeight }}</span>
</div>
</div>
<div class="completion-actions">
@@ -243,17 +246,17 @@
<div class="action-buttons">
<a-button
v-if="activeStep > 1 && activeStep < 3"
class="previous-button"
@click="handlePrevious"
class="previous-button"
>
上一步
</a-button>
<a-button
v-if="activeStep < 3"
type="primary"
<a-button
v-if="activeStep < 3"
type="primary"
@click="handleNext"
:disabled="activeStep === 1 && formData.matchResult !== 'success'"
class="next-button"
@click="handleNext"
>
{{ activeStep === 2 ? '完成' : '下一步' }}
</a-button>
@@ -263,10 +266,15 @@
</template>
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
import { Message, Modal } from '@arco-design/web-vue'
import { nextTick, onBeforeUnmount, onMounted, ref, reactive, onUnmounted } from 'vue'
import { Modal, Message } from '@arco-design/web-vue'
import { getMaterialDetail } from "@/apis/weightManage/weightManage";
import {addWorkOrder, type WorkOrderResp} from "@/apis/workOrder/workOrder";
import { Notification } from "@arco-design/web-vue"
import { catchPhoto } from '@/apis/material/materialInfo'
import { getMaterialDetail } from '@/apis/weightManage/weightManage'
defineOptions({ name: 'WeightManage' })
@@ -279,6 +287,7 @@ const activeStep = ref(1)
// 表单数据
const formData = reactive({
inputMaterialCode: '', // 输入的物料编码
id: '', // 物料ID
encoding: '', // 物料编码
materialName: '', // 物料名称
materialSpec: '', // 物料规格
@@ -532,46 +541,62 @@ onBeforeUnmount(() => {
stopCamera()
})
const workOrderResp = ref<WorkOrderResp>({
id: '',
title: '',
orderNo: '',
materialName: '',
encoding: '',
unitWeight: '',
materialSpec: '',
photoUrl: '',
totalWeight: '',
totalCount: '',
createUserString: '',
updateUserString: '',
matchResult: 'failed'
})
// 称重登记页面数据
const inputQuantity = ref('')
const inputWeight = ref('')
const ahDeviceWeight = ref('10')
const calculatedWeight = ref('')
const weighingCount = ref(1)
// 称重列表数据
const weighingList = ref<any[]>([])
// WebSocket连接
const ws = ref<WebSocket | null>(null)
const wsConnected = ref(false)
// 任务ID
const taskId = computed(() => {
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '')
const random = Math.floor(1000 + Math.random() * 9000)
return `${date}${formData.encoding}${random}`
})
// 称重列表数据
const weighingList = ref([
// 初始数据可以在这里添加
])
// 称重表格列
const columns = [
{
title: '称重次数',
dataIndex: 'count',
key: 'count',
dataIndex: 'weightTime',
key: 'weightTime'
},
{
title: '数量',
dataIndex: 'quantity',
key: 'quantity',
className: 'green-bg',
className: 'green-bg'
},
{
title: '重量',
title: '重量(g)',
dataIndex: 'weight',
key: 'weight',
className: 'green-bg',
className: 'green-bg'
},
{
title: '计算重量',
title: '计算重量(g)',
dataIndex: 'calculatedWeight',
key: 'calculatedWeight',
className: 'green-bg',
className: 'green-bg'
},
{
title: '抓拍图片',
@@ -597,57 +622,138 @@ const columns = [
title: '操作',
dataIndex: 'action',
key: 'action',
slotName: 'action',
},
slotName: 'action'
}
]
// 处理物料编码变化
const handleMaterialCodeChange = async () => {
if (formData.inputMaterialCode) {
// 防抖函数
const debounce = <T extends (...args: any[]) => any>(func: T, delay: number): ((...args: Parameters<T>) => void) => {
let timer: ReturnType<typeof setTimeout> | null = null;
return function(...args: Parameters<T>) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
func(...args);
}, delay);
};
};
// 原始的物料编码变化处理函数
const originalHandleMaterialCodeChange = async () => {
// 确保输入框内容是完整的物料编码
const materialCode = formData.inputMaterialCode?.trim();
// 无论是否有输入,先重置所有物料相关字段,确保新数据能完全覆盖旧数据
formData.encoding = "";
formData.materialName = "";
formData.materialSpec = "";
formData.unitWeight = 0;
formData.photoUrl = "";
formData.matchResult = "";
// 如果有物料编码输入,获取物料数据
if (materialCode) {
try {
await fetchMaterialData(formData.inputMaterialCode)
await fetchMaterialData(materialCode)
} catch (error) {
console.error('获取物料数据失败:', error)
// 即使获取失败,也保持字段为空,避免显示旧数据
}
} else {
formData.encoding = ''
formData.materialName = ''
formData.materialSpec = ''
formData.unitWeight = 0
formData.photoUrl = ''
formData.matchResult = ''
}
}
};
// 调用后端接口
// 记录上次输入时间,用于判断是否是扫码枪输入
let lastInputTime = 0;
// 记录输入内容,用于判断是否是新的扫码
let previousInput = '';
// 处理键盘按下事件
const handleKeyDown = (event: KeyboardEvent) => {
// 获取当前时间
const currentTime = Date.now();
// 如果输入速度非常快小于100ms认为是扫码枪输入
if (currentTime - lastInputTime < 100 && formData.inputMaterialCode) {
// 扫码枪通常会以回车键结束,这里不做处理
} else if (event.key.length === 1 && !event.ctrlKey && !event.altKey) {
// 如果是新的输入(不是快速连续输入),清空输入框
// 这样可以确保每次扫码都从空输入框开始
formData.inputMaterialCode = '';
}
// 更新上次输入时间
lastInputTime = currentTime;
};
// 带防抖的物料编码变化处理函数
const handleMaterialCodeChange = debounce(originalHandleMaterialCodeChange, 500); // 500ms防抖延迟
// 扫码核验获取物料信息
const fetchMaterialData = async (code: string) => {
getMaterialDetail(code).then((res) => {
getMaterialDetail(code).then(res => {
if (res.code == '0') {
// 更新表单数据
formData.encoding = res.data.encoding
formData.materialName = res.data.materialName
formData.materialSpec = res.data.materialSpec
formData.unitWeight = res.data.unitWeight
formData.photoUrl = res.data.photoUrl
formData.matchResult = res.data.matchResult || 'success'
formData.id = res.data?.id || "";
formData.encoding = res.data?.encoding || "";
formData.materialName = res.data?.materialName || "";
formData.materialSpec = res.data?.materialSpec || "";
formData.unitWeight = res.data?.unitWeight || 0;
formData.photoUrl = res.data?.photoUrl || "";
// 假设后端返回比对结果
// formData.matchResult = res.data.matchResult || 'failed' // 这里根据实际接口返回调整
formData.matchResult = res.data?.matchResult || 'success' // 这里根据实际接口返回调整
return true
}
})
});
}
// 处理下一步
const handleNext = () => {
const handleNext = async () => {
if (activeStep.value < 3) {
if (activeStep.value === 2) {
// 当在称重登记页面点击完成时,显示确认弹框
Modal.confirm({
title: '确认完成',
content: '确定要完成称重登记吗?',
onOk: () => {
activeStep.value++
},
onOk: async () => {
try {
// 准备工作订单数据
const workOrderData = {
materialId: formData.id,
materialName: formData.materialName,
workOrderInfos: weighingList.value
}
// 调用后端接口
addWorkOrder(workOrderData).then(res => {
if (res.code == '0') {
Notification.success({
title: '操作成功',
content: `工单创建成功!`
})
workOrderResp.value.matchResult = 'success';
workOrderResp.value.title = res.data?.title || "";
workOrderResp.value.orderNo = res.data?.orderNo || "";
workOrderResp.value.totalWeight = res.data?.totalWeight || "";
workOrderResp.value.totalCount = res.data?.totalCount || "";
// 关闭WebSocket连接
closeWebSocket()
// 跳转到完成页面
activeStep.value++
return true
}
});
} catch (error) {
console.error('创建工作订单失败:', error)
Message.error('创建工作订单失败')
}
}
})
} else {
activeStep.value++
// 进入称重页面时建立WebSocket连接
if (activeStep.value === 2) {
establishWebSocket()
}
}
}
}
@@ -656,56 +762,64 @@ const handleNext = () => {
const handlePrevious = () => {
if (activeStep.value > 1) {
activeStep.value--
// 离开称重页面时关闭WebSocket连接
if (activeStep.value !== 2) {
closeWebSocket()
}
}
}
// 返回第一步
const handleBackToFirst = () => {
activeStep.value = 1
// 离开称重页面时关闭WebSocket连接
closeWebSocket()
}
// 计算重量
const calculateWeight = () => {
if (inputQuantity.value && formData.unitWeight) {
const singleWeight = Number.parseFloat(formData.unitWeight.toString())
const quantity = Number.parseFloat(inputQuantity.value)
if (!Number.isNaN(singleWeight) && !Number.isNaN(quantity)) {
calculatedWeight.value = `${(singleWeight * quantity).toFixed(2)}g`
const singleWeight = parseFloat(formData.unitWeight.toString())
const quantity = parseFloat(inputQuantity.value)
if (!isNaN(singleWeight) && !isNaN(quantity)) {
calculatedWeight.value = (singleWeight * quantity).toFixed(2)
}
} else {
calculatedWeight.value = ''
}
}
// 处理确定
const handleConfirm = async () => {
if (!inputQuantity.value) {
Message.warning('请输入数量')
const handleConfirm = () => {
// 校验输入数量是否为空
if (!inputQuantity.value || inputQuantity.value.trim() === '') {
Message.error('请输入数量')
return
}
if (!ahDeviceWeight.value || ahDeviceWeight.value.trim() === '') {
Message.error('电子秤称重结果为空!')
return
}
// 1. 显示加载状态
Message.loading('正在处理...')
// 2. 抓拍当前画面
let captureUrl = ''
if (cameraVideo.value && cameraStatus.value === 'connected') {
captureUrl = await capturePhoto()
}
// 生成新的列表数据
const newItem = {
key: (weighingList.value.length + 1).toString(),
count: weighingCount.value,
name: formData.materialName,
weightTime: weighingCount.value,
materialId: formData.id,
quantity: inputQuantity.value,
weight: inputWeight.value,
weight: ahDeviceWeight.value,
calculatedWeight: calculatedWeight.value,
image: captureUrl || '未抓拍',
}
// 添加到列表
weighingList.value.push(newItem)
// 重置输入
inputQuantity.value = ''
inputWeight.value = ''
ahDeviceWeight.value = '10'
calculatedWeight.value = ''
// 称重次数累加
weighingCount.value = weighingList.value.length + 1
Message.success('添加成功')
}
@@ -771,19 +885,71 @@ const previewImage = (url: string) => {
// 处理重置
const handleReset = () => {
inputQuantity.value = ''
inputWeight.value = ''
ahDeviceWeight.value = ''
calculatedWeight.value = ''
}
// 处理删除
const handleDelete = (key: string) => {
weighingList.value = weighingList.value.filter((item) => item.key !== key)
const handleDelete = (key) => {
// 过滤掉要删除的项
weighingList.value = weighingList.value.filter(item => item.key !== key)
// 重新排序称重次数
weighingList.value.forEach((item, index) => {
item.count = index + 1
item.weightTime = index + 1
})
// 更新当前称重次数
weighingCount.value = weighingList.value.length + 1
Message.success('删除成功')
}
// 建立WebSocket连接
const establishWebSocket = () => {
try {
// 这里替换为实际的WebSocket服务器地址
const wsUrl = 'ws://localhost:6609/ws/scale'
ws.value = new WebSocket(wsUrl)
ws.value.onopen = () => {
Message.success('已和电子秤建立连接')
}
ws.value.onmessage = (event) => {
try {
if (event.data) {
ahDeviceWeight.value = event.data
}
} catch (error) {
console.error('WebSocket消息解析失败:', error)
}
}
ws.value.onclose = () => {
wsConnected.value = false
}
ws.value.onerror = (error) => {
console.error('WebSocket错误:', error)
wsConnected.value = false
Message.error('称重连接失败')
}
} catch (error) {
console.error('建立WebSocket连接失败:', error)
Message.error('无法建立称重连接')
}
}
// 关闭WebSocket连接
const closeWebSocket = () => {
if (ws.value) {
ws.value.close()
ws.value = null
wsConnected.value = false
}
}
// 组件卸载时关闭WebSocket连接
onUnmounted(() => {
closeWebSocket()
})
</script>
<style scoped lang="scss">
@@ -882,12 +1048,12 @@ const handleDelete = (key: string) => {
/* 称重登记页面 */
.weighing-content {
display: flex;
gap: 30px;
margin-bottom: 30px;
}
.left-weighing-section {
width: 450px;
width: 400px;
margin-right: 30px;
}
.right-weighing-section {
@@ -1045,7 +1211,7 @@ const handleDelete = (key: string) => {
margin-top: 40px;
}
/* 图片占位符(保留用于扫码核验页面) */
/* 图片占位符 */
.image-placeholder {
width: 100%;
height: 150px;
@@ -1070,7 +1236,7 @@ const handleDelete = (key: string) => {
border-radius: 4px;
}
/* 相机区域(保留用于扫码核验页面) */
/* 相机区域 */
.camera-section {
display: flex;
justify-content: space-between;
@@ -1088,16 +1254,17 @@ const handleDelete = (key: string) => {
.form-row {
display: flex;
gap: 20px;
margin-bottom: 16px;
}
.form-item {
flex: 1;
margin-right: 20px;
}
.form-item.full-width {
flex: 1;
margin-right: 0;
}
/* 确保输入框宽度一致 */
@@ -1115,7 +1282,6 @@ const handleDelete = (key: string) => {
margin-bottom: 8px;
font-size: 16px;
color: #666;
font-weight: 500;
}
.form-actions {
@@ -1132,7 +1298,6 @@ const handleDelete = (key: string) => {
border-radius: 4px;
padding: 20px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
margin-bottom: 16px;
}
.info-card h4 {
@@ -1140,8 +1305,6 @@ const handleDelete = (key: string) => {
font-size: 16px;
font-weight: bold;
color: #333;
border-bottom: 1px solid #e8e8e8;
padding-bottom: 8px;
}
.info-item {
@@ -1191,7 +1354,6 @@ const handleDelete = (key: string) => {
.action-buttons {
display: flex;
justify-content: flex-end;
margin-top: 30px;
}
.next-button {
@@ -1206,4 +1368,4 @@ const handleDelete = (key: string) => {
font-size: 14px;
margin-right: 12px;
}
</style>
</style>

View File

@@ -18,7 +18,7 @@
<template #toolbar-left>
<a-input-search v-model="queryForm.userName" placeholder="请输入姓名" allow-clear @search="search" />
<a-input-search v-model="queryForm.carNo" placeholder="请输入人员卡号" allow-clear @search="search" />
<a-input-search v-model="queryForm.orderNo" placeholder="请输入单号" allow-clear @search="search" />
<a-input-search v-model="queryForm.orderNo" placeholder="请输入任务工单号" allow-clear @search="search" />
<a-input-search v-model="queryForm.materialName" placeholder="请输入物料名称" allow-clear @search="search" />
<a-input-search v-model="queryForm.encoding" placeholder="请输入物料编码" allow-clear @search="search" />
<a-date-picker
@@ -67,6 +67,7 @@
<template #action="{ record }">
<a-space>
<a-link v-permission="['workOrder:record:detail']" title="详情" @click="onDetail(record)">详情</a-link>
<a-link v-permission="['workOrder:record:print']" title="打印" @click="onPrint(record)">打印</a-link>
<a-link v-permission="['workOrder:record:delete']" status="danger" :title="'删除'" @click="onDeleteOne(record.id)">删除</a-link>
</a-space>
</template>
@@ -113,6 +114,7 @@ import has from '@/utils/has'
import type GiTable from "@/components/GiTable/index.vue";
import {ref, reactive} from "vue";
import {Message} from "@arco-design/web-vue";
import { useRouter } from 'vue-router';
import {
deleteWorkOrder,
exportWorkOrder, getWorkOrder,
@@ -123,6 +125,7 @@ import {
defineOptions({ name: 'Record' })
const router = useRouter()
const queryForm = reactive<WorkOrderQuery>({
@@ -160,9 +163,10 @@ const processColumns = (columns: TableInstanceColumns[]): TableInstanceColumns[]
// 定义列配置,使用工具函数处理
const columns = ref<TableInstanceColumns[]>(processColumns([
{ title: '创建人', dataIndex: 'createUserString' },
{ title: '卡号', dataIndex: 'cardNo' },
{ title: '标题', dataIndex: 'title', width: 180 },
{ title: '创建人', dataIndex: 'createUserString' },
{ title: '人员卡号', dataIndex: 'cardNo' },
{ title: '任务工单号', dataIndex: 'orderNo' },
{ title: '物料图片', dataIndex: 'photoUrl', slotName: 'photoUrl', minWidth: 180, ellipsis: true, tooltip: true },
{ title: '物料名称', dataIndex: 'materialName' },
{ title: '物料编码', dataIndex: 'encoding' },
@@ -248,6 +252,19 @@ const onExport = () => {
useDownload(() => exportWorkOrder(queryForm))
}
// 打印
const onPrint = (record: WorkOrderResp) => {
// 跳转到标签打印页面,并传递数据
router.push({
path: '/print',
query: {
materialName: record.materialName,
encoding: record.encoding,
orderNo: record.orderNo
}
})
}
</script>
<style scoped lang="scss">