优化
This commit is contained in:
@@ -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}`)
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
<div class="form-row">
|
||||
<div class="form-item">
|
||||
<label>对应重量:</label>
|
||||
<a-input v-model="inputWeight" placeholder="-" disabled/>
|
||||
<a-input v-model="ahDeviceWeight" placeholder="-" disabled/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-placeholder large-image">实时画面</div>
|
||||
@@ -172,28 +172,28 @@
|
||||
<div class="completion-icon">
|
||||
<a-icon type="check-circle" :size="64" style="color: #52c41a;" />
|
||||
</div>
|
||||
<h2>创建完成</h2>
|
||||
<p>任务已成功创建,以下是任务详情:</p>
|
||||
<h2>{{ workOrderResp.matchResult === '1' ? '创建成功' : '创建失败' }}</h2>
|
||||
<p>{{ workOrderResp.matchResult === '1' ? '任务已成功创建' : '任务创建失败' }},以下是任务详情:</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>
|
||||
<span class="value">{{ formData.materialName }}</span>
|
||||
<span class="value">{{ workOrderResp.materialName }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">物料编码:</span>
|
||||
<span class="value">{{ formData.encoding }}</span>
|
||||
<span class="value">{{ workOrderResp.encoding }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">物料规格:</span>
|
||||
<span class="value">{{ formData.materialSpec }}</span>
|
||||
<span class="value">{{ workOrderResp.materialSpec }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">重量:</span>
|
||||
<span class="value">{{ formData.unitWeight }}</span>
|
||||
<span class="value">{{ workOrderResp.unitWeight }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="completion-actions">
|
||||
@@ -226,9 +226,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { Modal } from '@arco-design/web-vue'
|
||||
import { 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"
|
||||
|
||||
// 当前步骤
|
||||
const activeStep = ref(1)
|
||||
@@ -236,6 +238,7 @@ const activeStep = ref(1)
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
inputMaterialCode: '', // 输入的物料编码
|
||||
id: '', // 物料ID
|
||||
encoding: '', // 物料编码
|
||||
materialName: '', // 物料名称
|
||||
materialSpec: '', // 物料规格
|
||||
@@ -244,24 +247,38 @@ const formData = reactive({
|
||||
matchResult: '' // 比对结果
|
||||
})
|
||||
|
||||
const workOrderResp = ref<WorkOrderResp>({
|
||||
id: '',
|
||||
title: '',
|
||||
orderNo: '',
|
||||
materialName: '',
|
||||
encoding: '',
|
||||
unitWeight: '',
|
||||
materialSpec: '',
|
||||
photoUrl: '',
|
||||
totalWeight: '',
|
||||
totalCount: '',
|
||||
createUserString: '',
|
||||
updateUserString: '',
|
||||
matchResult: ''
|
||||
})
|
||||
|
||||
|
||||
// 称重登记页面数据
|
||||
const inputQuantity = ref('')
|
||||
const inputWeight = ref('')
|
||||
const ahDeviceWeight = ref('')
|
||||
const calculatedWeight = ref('')
|
||||
const weighingCount = ref(1)
|
||||
|
||||
// WebSocket连接
|
||||
const ws = ref<WebSocket | null>(null)
|
||||
const wsConnected = ref(false)
|
||||
|
||||
// 称重列表数据
|
||||
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 = [
|
||||
{
|
||||
@@ -326,11 +343,12 @@ const fetchMaterialData = async (code: string) => {
|
||||
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.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' // 这里根据实际接口返回调整
|
||||
@@ -340,19 +358,52 @@ const fetchMaterialData = async (code: string) => {
|
||||
}
|
||||
|
||||
// 处理下一步
|
||||
const handleNext = () => {
|
||||
const handleNext = async () => {
|
||||
if (activeStep.value < 3) {
|
||||
if (activeStep.value === 2) {
|
||||
// 当在称重登记页面点击完成时,显示确认弹框
|
||||
Modal.confirm({
|
||||
title: '确认完成',
|
||||
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++
|
||||
|
||||
Message.success('工作订单创建成功')
|
||||
} catch (error) {
|
||||
console.error('创建工作订单失败:', error)
|
||||
Message.error('创建工作订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
activeStep.value++
|
||||
// 进入称重页面时建立WebSocket连接
|
||||
if (activeStep.value === 2) {
|
||||
establishWebSocket()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,12 +412,18 @@ const handleNext = () => {
|
||||
const handlePrevious = () => {
|
||||
if (activeStep.value > 1) {
|
||||
activeStep.value--
|
||||
// 离开称重页面时关闭WebSocket连接
|
||||
if (activeStep.value !== 2) {
|
||||
closeWebSocket()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回第一步
|
||||
const handleBackToFirst = () => {
|
||||
activeStep.value = 1
|
||||
// 离开称重页面时关闭WebSocket连接
|
||||
closeWebSocket()
|
||||
}
|
||||
|
||||
// 计算重量
|
||||
@@ -392,7 +449,7 @@ const handleConfirm = () => {
|
||||
count: weighingCount.value,
|
||||
name: formData.materialName,
|
||||
quantity: inputQuantity.value,
|
||||
unitWeight: inputWeight.value,
|
||||
unitWeight: ahDeviceWeight.value,
|
||||
calculatedWeight: calculatedWeight.value,
|
||||
image: '图片'
|
||||
}
|
||||
@@ -400,7 +457,7 @@ const handleConfirm = () => {
|
||||
weighingList.value.push(newItem)
|
||||
// 重置输入
|
||||
inputQuantity.value = ''
|
||||
inputWeight.value = ''
|
||||
ahDeviceWeight.value = ''
|
||||
calculatedWeight.value = ''
|
||||
// 称重次数累加
|
||||
weighingCount.value = weighingList.value.length + 1
|
||||
@@ -409,7 +466,7 @@ const handleConfirm = () => {
|
||||
// 处理重置
|
||||
const handleReset = () => {
|
||||
inputQuantity.value = ''
|
||||
inputWeight.value = ''
|
||||
ahDeviceWeight.value = ''
|
||||
calculatedWeight.value = ''
|
||||
}
|
||||
|
||||
@@ -425,6 +482,58 @@ const handleDelete = (key) => {
|
||||
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' })
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user