优化
This commit is contained in:
@@ -5,6 +5,7 @@ const BASE_URL = '/weighManage/workOrder'
|
|||||||
export interface WorkOrderResp {
|
export interface WorkOrderResp {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
|
orderNo: string
|
||||||
materialName: string
|
materialName: string
|
||||||
encoding: string
|
encoding: string
|
||||||
unitWeight: string
|
unitWeight: string
|
||||||
@@ -14,6 +15,7 @@ export interface WorkOrderResp {
|
|||||||
totalCount: string
|
totalCount: string
|
||||||
createUserString: string
|
createUserString: string
|
||||||
updateUserString: string
|
updateUserString: string
|
||||||
|
matchResult: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WorkOrderInfoResp {
|
export interface WorkOrderInfoResp {
|
||||||
@@ -49,6 +51,11 @@ export function getWorkOrder(id: string) {
|
|||||||
return http.get<Array<WorkOrderInfoResp>>(`${BASE_URL}/${id}`)
|
return http.get<Array<WorkOrderInfoResp>>(`${BASE_URL}/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @desc 新增工作订单 */
|
||||||
|
export function addWorkOrder(data: any) {
|
||||||
|
return http.post(`${BASE_URL}`, data)
|
||||||
|
}
|
||||||
|
|
||||||
/** @desc 删除工作订单 */
|
/** @desc 删除工作订单 */
|
||||||
export function deleteWorkOrder(ids: string | Array<string>) {
|
export function deleteWorkOrder(ids: string | Array<string>) {
|
||||||
return http.del(`${BASE_URL}/${ids}`)
|
return http.del(`${BASE_URL}/${ids}`)
|
||||||
|
|||||||
@@ -135,7 +135,7 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<label>对应重量:</label>
|
<label>对应重量:</label>
|
||||||
<a-input v-model="inputWeight" placeholder="-" disabled/>
|
<a-input v-model="ahDeviceWeight" placeholder="-" disabled/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="image-placeholder large-image">实时画面</div>
|
<div class="image-placeholder large-image">实时画面</div>
|
||||||
@@ -172,28 +172,28 @@
|
|||||||
<div class="completion-icon">
|
<div class="completion-icon">
|
||||||
<a-icon type="check-circle" :size="64" style="color: #52c41a;" />
|
<a-icon type="check-circle" :size="64" style="color: #52c41a;" />
|
||||||
</div>
|
</div>
|
||||||
<h2>创建完成</h2>
|
<h2>{{ workOrderResp.matchResult === '1' ? '创建成功' : '创建失败' }}</h2>
|
||||||
<p>任务已成功创建,以下是任务详情:</p>
|
<p>{{ workOrderResp.matchResult === '1' ? '任务已成功创建' : '任务创建失败' }},以下是任务详情:</p>
|
||||||
<div class="completion-info">
|
<div class="completion-info">
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">任务ID:</span>
|
<span class="label">任务工单号:</span>
|
||||||
<span class="value">{{ taskId }}</span>
|
<span class="value">{{ workOrderResp.orderNo }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">物料名称:</span>
|
<span class="label">物料名称:</span>
|
||||||
<span class="value">{{ formData.materialName }}</span>
|
<span class="value">{{ workOrderResp.materialName }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">物料编码:</span>
|
<span class="label">物料编码:</span>
|
||||||
<span class="value">{{ formData.encoding }}</span>
|
<span class="value">{{ workOrderResp.encoding }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">物料规格:</span>
|
<span class="label">物料规格:</span>
|
||||||
<span class="value">{{ formData.materialSpec }}</span>
|
<span class="value">{{ workOrderResp.materialSpec }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">重量:</span>
|
<span class="label">重量:</span>
|
||||||
<span class="value">{{ formData.unitWeight }}</span>
|
<span class="value">{{ workOrderResp.unitWeight }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="completion-actions">
|
<div class="completion-actions">
|
||||||
@@ -226,9 +226,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, computed } from 'vue'
|
import { ref, reactive, onUnmounted } from 'vue'
|
||||||
import { Modal } from '@arco-design/web-vue'
|
import { Modal, Message } from '@arco-design/web-vue'
|
||||||
import { getMaterialDetail } from "@/apis/weightManage/weightManage";
|
import { getMaterialDetail } from "@/apis/weightManage/weightManage";
|
||||||
|
import {addWorkOrder, type WorkOrderResp} from "@/apis/workOrder/workOrder";
|
||||||
|
import { Notification } from "@arco-design/web-vue"
|
||||||
|
|
||||||
// 当前步骤
|
// 当前步骤
|
||||||
const activeStep = ref(1)
|
const activeStep = ref(1)
|
||||||
@@ -236,6 +238,7 @@ const activeStep = ref(1)
|
|||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
inputMaterialCode: '', // 输入的物料编码
|
inputMaterialCode: '', // 输入的物料编码
|
||||||
|
id: '', // 物料ID
|
||||||
encoding: '', // 物料编码
|
encoding: '', // 物料编码
|
||||||
materialName: '', // 物料名称
|
materialName: '', // 物料名称
|
||||||
materialSpec: '', // 物料规格
|
materialSpec: '', // 物料规格
|
||||||
@@ -244,24 +247,38 @@ const formData = reactive({
|
|||||||
matchResult: '' // 比对结果
|
matchResult: '' // 比对结果
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const workOrderResp = ref<WorkOrderResp>({
|
||||||
|
id: '',
|
||||||
|
title: '',
|
||||||
|
orderNo: '',
|
||||||
|
materialName: '',
|
||||||
|
encoding: '',
|
||||||
|
unitWeight: '',
|
||||||
|
materialSpec: '',
|
||||||
|
photoUrl: '',
|
||||||
|
totalWeight: '',
|
||||||
|
totalCount: '',
|
||||||
|
createUserString: '',
|
||||||
|
updateUserString: '',
|
||||||
|
matchResult: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// 称重登记页面数据
|
// 称重登记页面数据
|
||||||
const inputQuantity = ref('')
|
const inputQuantity = ref('')
|
||||||
const inputWeight = ref('')
|
const ahDeviceWeight = ref('')
|
||||||
const calculatedWeight = ref('')
|
const calculatedWeight = ref('')
|
||||||
const weighingCount = ref(1)
|
const weighingCount = ref(1)
|
||||||
|
|
||||||
|
// WebSocket连接
|
||||||
|
const ws = ref<WebSocket | null>(null)
|
||||||
|
const wsConnected = ref(false)
|
||||||
|
|
||||||
// 称重列表数据
|
// 称重列表数据
|
||||||
const weighingList = ref([
|
const weighingList = ref([
|
||||||
// 初始数据可以在这里添加
|
// 初始数据可以在这里添加
|
||||||
])
|
])
|
||||||
|
|
||||||
// 任务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 columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
@@ -326,11 +343,12 @@ const fetchMaterialData = async (code: string) => {
|
|||||||
getMaterialDetail(code).then(res => {
|
getMaterialDetail(code).then(res => {
|
||||||
if (res.code == '0') {
|
if (res.code == '0') {
|
||||||
// 更新表单数据
|
// 更新表单数据
|
||||||
formData.encoding = res.data.encoding
|
formData.id = res.data?.id || "";
|
||||||
formData.materialName = res.data.materialName
|
formData.encoding = res.data?.encoding || "";
|
||||||
formData.materialSpec = res.data.materialSpec
|
formData.materialName = res.data?.materialName || "";
|
||||||
formData.unitWeight = res.data.unitWeight
|
formData.materialSpec = res.data?.materialSpec || "";
|
||||||
formData.photoUrl = res.data.photoUrl
|
formData.unitWeight = res.data?.unitWeight || 0;
|
||||||
|
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' // 这里根据实际接口返回调整
|
||||||
@@ -340,19 +358,52 @@ const fetchMaterialData = async (code: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理下一步
|
// 处理下一步
|
||||||
const handleNext = () => {
|
const handleNext = async () => {
|
||||||
if (activeStep.value < 3) {
|
if (activeStep.value < 3) {
|
||||||
if (activeStep.value === 2) {
|
if (activeStep.value === 2) {
|
||||||
// 当在称重登记页面点击完成时,显示确认弹框
|
// 当在称重登记页面点击完成时,显示确认弹框
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: '确认完成',
|
title: '确认完成',
|
||||||
content: '确定要完成称重登记吗?',
|
content: '确定要完成称重登记吗?',
|
||||||
onOk: () => {
|
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 = res.data || {}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 关闭WebSocket连接
|
||||||
|
closeWebSocket()
|
||||||
|
|
||||||
|
// 跳转到完成页面
|
||||||
activeStep.value++
|
activeStep.value++
|
||||||
|
|
||||||
|
Message.success('工作订单创建成功')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建工作订单失败:', error)
|
||||||
|
Message.error('创建工作订单失败')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
activeStep.value++
|
activeStep.value++
|
||||||
|
// 进入称重页面时建立WebSocket连接
|
||||||
|
if (activeStep.value === 2) {
|
||||||
|
establishWebSocket()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -361,12 +412,18 @@ const handleNext = () => {
|
|||||||
const handlePrevious = () => {
|
const handlePrevious = () => {
|
||||||
if (activeStep.value > 1) {
|
if (activeStep.value > 1) {
|
||||||
activeStep.value--
|
activeStep.value--
|
||||||
|
// 离开称重页面时关闭WebSocket连接
|
||||||
|
if (activeStep.value !== 2) {
|
||||||
|
closeWebSocket()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回第一步
|
// 返回第一步
|
||||||
const handleBackToFirst = () => {
|
const handleBackToFirst = () => {
|
||||||
activeStep.value = 1
|
activeStep.value = 1
|
||||||
|
// 离开称重页面时关闭WebSocket连接
|
||||||
|
closeWebSocket()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算重量
|
// 计算重量
|
||||||
@@ -392,7 +449,7 @@ const handleConfirm = () => {
|
|||||||
count: weighingCount.value,
|
count: weighingCount.value,
|
||||||
name: formData.materialName,
|
name: formData.materialName,
|
||||||
quantity: inputQuantity.value,
|
quantity: inputQuantity.value,
|
||||||
unitWeight: inputWeight.value,
|
unitWeight: ahDeviceWeight.value,
|
||||||
calculatedWeight: calculatedWeight.value,
|
calculatedWeight: calculatedWeight.value,
|
||||||
image: '图片'
|
image: '图片'
|
||||||
}
|
}
|
||||||
@@ -400,7 +457,7 @@ const handleConfirm = () => {
|
|||||||
weighingList.value.push(newItem)
|
weighingList.value.push(newItem)
|
||||||
// 重置输入
|
// 重置输入
|
||||||
inputQuantity.value = ''
|
inputQuantity.value = ''
|
||||||
inputWeight.value = ''
|
ahDeviceWeight.value = ''
|
||||||
calculatedWeight.value = ''
|
calculatedWeight.value = ''
|
||||||
// 称重次数累加
|
// 称重次数累加
|
||||||
weighingCount.value = weighingList.value.length + 1
|
weighingCount.value = weighingList.value.length + 1
|
||||||
@@ -409,7 +466,7 @@ const handleConfirm = () => {
|
|||||||
// 处理重置
|
// 处理重置
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
inputQuantity.value = ''
|
inputQuantity.value = ''
|
||||||
inputWeight.value = ''
|
ahDeviceWeight.value = ''
|
||||||
calculatedWeight.value = ''
|
calculatedWeight.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,6 +482,58 @@ const handleDelete = (key) => {
|
|||||||
weighingCount.value = weighingList.value.length + 1
|
weighingCount.value = weighingList.value.length + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 建立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 = () => {
|
||||||
|
Message.success('已和电子秤断开连接')
|
||||||
|
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
|
||||||
|
console.log('WebSocket连接已关闭')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件卸载时关闭WebSocket连接
|
||||||
|
onUnmounted(() => {
|
||||||
|
closeWebSocket()
|
||||||
|
})
|
||||||
|
|
||||||
defineOptions({ name: 'WeightManage' })
|
defineOptions({ name: 'WeightManage' })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user