diff --git a/src/apis/weightManage/light.ts b/src/apis/weightManage/light.ts new file mode 100644 index 0000000..3a80dc1 --- /dev/null +++ b/src/apis/weightManage/light.ts @@ -0,0 +1,23 @@ +import http from '@/utils/http' + +const BASE_URL = '/api/light' + +/** @desc 连接灯光 */ +export function connect() { + return http.post(`${BASE_URL}/connect`) +} + +/** @desc 断开灯光连接 */ +export function disconnect() { + return http.post(`${BASE_URL}/disconnect`) +} + +/** @desc 设置灯光亮度 */ +export function brightness(materialId: string) { + return http.post(`${BASE_URL}/brightness`, { materialId: Number(materialId) }) +} + +/** @desc 检查灯光状态 */ +export function status() { + return http.get(`${BASE_URL}/status`) +} diff --git a/src/views/weightManage/index.vue b/src/views/weightManage/index.vue index 5f624f9..3edf8cc 100644 --- a/src/views/weightManage/index.vue +++ b/src/views/weightManage/index.vue @@ -268,6 +268,7 @@ import { Message, Modal, Notification } from '@arco-design/web-vue' import { getMaterialDetail, validateWeighing, vmSend } from '@/apis/weightManage/weightManage' import {type WorkOrderResp, addWorkOrder} from '@/apis/workOrder/workOrder' import {getCaptureImage, getCheckStatus, getEnterWeighPage, getLeaveWeighPage} from "@/apis/weightManage/ys"; +import {brightness, connect, disconnect} from "@/apis/weightManage/light"; import router from "@/router"; import type {TableInstanceColumns} from "@/components/GiTable/type"; @@ -402,16 +403,34 @@ onMounted(() => { } }) + // 初始进入扫码验证页面,连接灯光 + if (activeStep.value === 1) { + connect().catch(error => { + console.error('连接灯光失败:', error) + }) + } + // 监听步骤变化 watch(activeStep, (newVal) => { - if (newVal === 2) { - // 进入称重登记页面 + if (newVal === 1) { + // 进入扫码验证页面,连接灯光 + connect().catch(error => { + console.error('连接灯光失败:', error) + }) + } else if (newVal === 2) { + // 进入称重登记页面,断开灯光 + disconnect().catch(error => { + console.error('断开灯光失败:', error) + }) nextTick(() => { enterWeighPage() }) } else { - // 离开称重页面 + // 离开称重页面,断开灯光 leaveWeighPage() + disconnect().catch(error => { + console.error('断开灯光失败:', error) + }) } }) }) @@ -429,6 +448,10 @@ onBeforeUnmount(() => { if (activeStep.value === 2) { leaveWeighPage() } + // 断开灯光连接 + disconnect().catch(error => { + console.error('断开灯光失败:', error) + }) }) const workOrderResp = ref({ @@ -549,7 +572,7 @@ const handleMaterialCodeChange = debounce(originalHandleMaterialCodeChange, 500) // 扫码核验获取物料信息 const fetchMaterialData = async (code: string) => { - getMaterialDetail(code).then((res) => { + const res = await getMaterialDetail(code); if (res.code === '0') { // 更新表单数据 formData.id = res.data?.id || '' @@ -559,9 +582,10 @@ const fetchMaterialData = async (code: string) => { formData.unitWeight = res.data?.unitWeight || 0 formData.photoUrl = res.data?.photoUrl || '' formData.weightRange = (res.data?.downFloatRatio || '-') + '% ~ ' + (res.data?.upFloatRatio || '-') + '%' - return true } - }) + if(res.data && res.data.id) { + await brightness(res.data.id); + } } // 处理下一步