From beab50f747568a80438b375d232403534af9c153 Mon Sep 17 00:00:00 2001 From: guoapeng Date: Thu, 20 Mar 2025 22:04:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=96=B7=E6=B6=82=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/system.ts | 2 +- src/components/common/FTButton/index.vue | 10 +++--- src/components/common/FTStream/index.vue | 14 ++++++-- src/components/home/Check/index.vue | 39 +++++++++++++--------- src/libs/socket.ts | 18 ++++++---- src/libs/utils.ts | 1 + src/stores/useSystemStore.ts | 3 +- src/views/debug/index.vue | 48 +++++++++++++-------------- src/views/main/index.vue | 4 +-- src/views/spray/index.vue | 57 +++++++++++++++++++++----------- src/views/spraySet/index.vue | 14 ++++---- vite.config.ts | 4 +-- 12 files changed, 127 insertions(+), 87 deletions(-) diff --git a/src/apis/system.ts b/src/apis/system.ts index 2fde00a..37aee3e 100644 --- a/src/apis/system.ts +++ b/src/apis/system.ts @@ -11,4 +11,4 @@ export const control = (params: any) => http.post('/function', params) export const debugControl = (params: any) => http.post('/function/debug', params) export const getDeviceStatus = () => http.get('/device-status/') -export const getDeviceSelfTest = () => http.get('/device_self_test/') +export const getDeviceSelfTest = () => http.get('/self-test/') diff --git a/src/components/common/FTButton/index.vue b/src/components/common/FTButton/index.vue index b2f8fd1..5ed5162 100644 --- a/src/components/common/FTButton/index.vue +++ b/src/components/common/FTButton/index.vue @@ -14,22 +14,22 @@ const props = defineProps({ type: Boolean, default: false, }, - onClick: { + clickHandle: { type: Function, required: false, - default: () => Promise, }, }) const isLoading = ref(false) async function handleClick() { - if (!props.onClick || isLoading.value) + console.log(props.clickHandle) + if (!props.clickHandle || isLoading.value) return - + console.log(32452353) isLoading.value = true // 进入 loading try { - await props.onClick() // 执行异步操作 + await props.clickHandle() // 执行异步操作 } finally { isLoading.value = false // 结束 loading diff --git a/src/components/common/FTStream/index.vue b/src/components/common/FTStream/index.vue index 6ded1d9..90ffb9e 100644 --- a/src/components/common/FTStream/index.vue +++ b/src/components/common/FTStream/index.vue @@ -12,7 +12,7 @@ defineProps({ const systemStore = useSystemStore() const title = computed(() => { - return cmdNameMap[systemStore.systemList[0]?.cmdCode] || systemStore.systemList[0]?.cmdCode + return cmdNameMap[systemStore.systemList[0]?.cmdCode as keyof typeof cmdNameMap] || systemStore.systemList[0]?.cmdCode }) const maskBodyRef = ref(null) @@ -20,6 +20,7 @@ const maskRef = ref(null) const maskHeaderRef = ref(null) const statusMap = { + fail: 'danger', error: 'danger', success: 'success', finish: 'primary', @@ -90,8 +91,15 @@ const handleMouseUp = () => { -
-
+
+

{{ title }}

diff --git a/src/components/home/Check/index.vue b/src/components/home/Check/index.vue index 617db9e..8ef4da9 100644 --- a/src/components/home/Check/index.vue +++ b/src/components/home/Check/index.vue @@ -20,13 +20,13 @@ const okHandle = () => { } const list = ['x轴是否在原点', 'y轴是否在原点', 'z轴是否在原点'] +const status = ref({}) onMounted(async () => { let num = 0 await nextTick(() => { buttonCloseRef.value.setLoading(true) }) - const res = await getDeviceSelfTest() - console.log(res) + status.value = await getDeviceSelfTest() const interval = async () => { if (num < list.length) { @@ -38,28 +38,38 @@ onMounted(async () => { await interval() buttonCloseRef.value.setLoading(false) closeVisible.value = false + + socket.init(receiveMessage, 'cmd_response') }) +const receiveMessage = (data: any) => { + if (data.cmdId === cmdId && data.status === 'success') { + for (let i = 0; i < checkList.value.length; i++) { + checkList.value[i].result = 'padding' + setTimeout(() => { + checkList.value[i].result = 'success' + }, 500) + } + buttonRef.value.setLoading(false) + closeVisible.value = true + } +} + const cancel = () => { emits('cancel') } +let cmdId = '' const motorXYZOrigin = async () => { buttonRef.value.setLoading(true) - const cmdId = Date.now().toString() + cmdId = Date.now().toString() const params = { cmdCode: 'device_self_test', cmdId, params: {}, } - socket.init((data: any) => { - console.log(data) - if (data.cmdId === cmdId && data.status === 'success') { - buttonRef.value.setLoading(false) - closeVisible.value = true - } - }, 'cmd_response') - await sendControl(params, 'debug') + + await sendControl(params) } const checkList = ref([]) @@ -89,14 +99,13 @@ const addTextToCheckList = async (text: string, id: number) => { // 文字显示完毕后,设置 result 为 'success' 或 'failed' 以显示成功或失败图标 const itemIndex = checkList.value.findIndex(item => item.id === id) if (itemIndex !== -1) { - // 假设通过随机数来决定成功或失败 setTimeout(() => { - checkList.value[itemIndex].result = 'failed' + checkList.value[itemIndex].result = status.value[['xAxisAtOrigin', 'yAxisAtOrigin', 'zAxisAtOrigin'][itemIndex]] ? 'success' : 'failed' resolve() // 解析 Promise,表示当前数据已完全展示 - }, Math.random() * 500) // 修改为随机数延时 + }, Math.random() * 200) // 修改为随机数延时 } } - }, Math.random() * 200) // 修改为随机数延时 + }, Math.random() * 100) // 修改为随机数延时 }) } diff --git a/src/libs/socket.ts b/src/libs/socket.ts index 6885bb4..b976b26 100644 --- a/src/libs/socket.ts +++ b/src/libs/socket.ts @@ -21,7 +21,7 @@ interface socket { reconnect_number: number reconnect_timer: any reconnect_interval: number - receiveMessageCallBackObj: any + receiveMessageCallBackObj: { [key: string]: any[] } initCallBacks: any // eslint-disable-next-line ts/no-unsafe-function-type receiveMessage: Function @@ -76,17 +76,23 @@ export const socket: socket = { // 接收消息的方法 receiveMessage: (e: any) => { const message = JSON.parse(e.data) - const fn = socket.receiveMessageCallBackObj[message.type] - if (fn) { - fn(message.data) + const callbacks = socket.receiveMessageCallBackObj[message.type] + if (callbacks) { + callbacks.forEach((fn) => { + fn(message.data) + }) } else { console.error('请注册当前类型的回调函数', message) } }, + + // 修改 registerCallback 方法 registerCallback: (fn: any, type: any) => { - // 接收消息的回调 - socket.receiveMessageCallBackObj[type] = fn + if (!socket.receiveMessageCallBackObj[type]) { + socket.receiveMessageCallBackObj[type] = [] + } + socket.receiveMessageCallBackObj[type].push(fn) }, init: async ( diff --git a/src/libs/utils.ts b/src/libs/utils.ts index 04569fb..17c707b 100644 --- a/src/libs/utils.ts +++ b/src/libs/utils.ts @@ -64,6 +64,7 @@ export const sendControl = async (params: any, type?: string) => { systemStore.pushSystemList(data) }, 'cmd_debug') socket.init((data: any) => { + console.log('system', data) systemStore.pushSystemList(data) }, 'cmd_response') await (type === 'debug' ? debugControl(params) : control(params)) diff --git a/src/stores/useSystemStore.ts b/src/stores/useSystemStore.ts index 1796ef8..77ee27d 100644 --- a/src/stores/useSystemStore.ts +++ b/src/stores/useSystemStore.ts @@ -16,7 +16,7 @@ export const useSystemStore = defineStore('system', { systemSensor: { humidity: 0, }, - isDebug: false, + isDebug: true, streamVisible: false, systemList: [{ cmdCode: '' }], }), @@ -35,7 +35,6 @@ export const useSystemStore = defineStore('system', { }, pushSystemList(text: any) { this.systemList.push(text) - console.log(this.systemList) }, }, }) diff --git a/src/views/debug/index.vue b/src/views/debug/index.vue index 2613c8c..d756c0d 100644 --- a/src/views/debug/index.vue +++ b/src/views/debug/index.vue @@ -219,13 +219,13 @@ const highVoltageClose = async () => {
- + 执行 - + 停止 - + 回原点
@@ -254,13 +254,13 @@ const highVoltageClose = async () => {
- + 执行 - + 停止 - + 回原点
@@ -289,13 +289,13 @@ const highVoltageClose = async () => { - + 执行 - + 停止 - + 回原点 @@ -318,10 +318,10 @@ const highVoltageClose = async () => { - + 开始 - + 停止 @@ -331,10 +331,10 @@ const highVoltageClose = async () => {
V - + 开启 - + 关闭
@@ -344,20 +344,20 @@ const highVoltageClose = async () => { - + 开启照明灯 - + 关闭照明灯
- + 打开喷嘴管路 - + 打开注射器管路 - + 全部关闭
@@ -365,23 +365,23 @@ const highVoltageClose = async () => {
- + 打开清洗阀 - + 打开喷嘴阀 - + 打开除湿阀
- + 关闭清洗阀 - + 关闭喷嘴阀 - + 关闭除湿阀
diff --git a/src/views/main/index.vue b/src/views/main/index.vue index 26d0417..7509325 100644 --- a/src/views/main/index.vue +++ b/src/views/main/index.vue @@ -130,10 +130,10 @@ const slideTrayOut = async () => {
- + 推入托盘 - + 推出托盘
diff --git a/src/views/spray/index.vue b/src/views/spray/index.vue index 06a3359..6bf959e 100644 --- a/src/views/spray/index.vue +++ b/src/views/spray/index.vue @@ -8,20 +8,14 @@ import route_horizontal from 'assets/images/route_horizontal.png' import route_vertical_active from 'assets/images/route_vertical2.png' import route_vertical from 'assets/images/route_vertical.png' import Edit from 'components/martixCraft/Edit/index.vue' -import startSpray from 'components/spray/startSpray/index.vue' import TrayGraph from 'components/spray/trayGraph/index.vue' import { FtMessage } from 'libs/message' import { socket } from 'libs/socket' import { sendControl } from 'libs/utils' -import { useSystemStore } from 'stores/useSystemStore' import { nextTick, onMounted, ref } from 'vue' -const systemStore = useSystemStore() - const sprayRefs = ref([]) -const wsList = ref([]) - const updateParam = () => { updateForm.value = { motorZHeight: form.value.motorZHeight, // 高度 @@ -84,8 +78,6 @@ const updateForm = ref({ movingSpeed: undefined, // 移动速度 }) -const visible = ref(false) - const formRef = ref() const checkPosition = () => { @@ -134,16 +126,44 @@ const startWork = async () => { }, } console.log(params) - sendControl(params) - visible.value = true - wsList.value = [] - socket.init(sprayTskReceiveMessage, 'spray_tsk') socket.init(sprayPointReceiveMessage, 'spray_point') + await sendControl(params) + currentSpeed = Number(form.value.movingSpeed) }) } +let currentSpeed = 0 +let poll: ReturnType + const sprayPointReceiveMessage = (data: any) => { - drawLine(data.index, data.point) + if (poll) { + clearInterval(poll) + } + const { currentPoint, nextPoint, index } = data + // 计算累加的mm + const moveDistance = currentSpeed / 2 + // y轴移动 + if (currentPoint.x === nextPoint.x) { + let currentY = currentPoint.y + poll = setInterval(() => { + currentY += moveDistance + if (currentY >= nextPoint.y) { + clearInterval(poll) + } + drawLine(index, { x: currentPoint.x * 5, y: currentY * 5 }) + }, 500) + } + else if (currentPoint.y === nextPoint.y) { + // x轴移动 + let currentX = currentPoint.x + poll = setInterval(() => { + currentX += moveDistance + if (currentX >= nextPoint.x) { + clearInterval(poll) + } + drawLine(index, { x: currentX * 5, y: currentPoint.y * 5 }) + }, 500) + } } const drawLine = async (index: number, point: { x: number, y: number }) => { @@ -152,14 +172,10 @@ const drawLine = async (index: number, point: { x: number, y: number }) => { sprayRefs.value[index].addLine() } }) + console.log('drawLine', point) sprayRefs.value[index].updateLine(point) } -const sprayTskReceiveMessage = (data: any) => { - console.log(data) - wsList.value.push(data) -} - const pauseWork = async () => { const params = { cmdCode: 'matrix_spray_pause', @@ -182,6 +198,7 @@ const continueWork = async () => { }, } await sendControl(params) + currentSpeed = Number(form.value.movingSpeed) } const stopWork = async () => { @@ -289,7 +306,7 @@ const addCraft = () => { 继续喷涂 - + 结束喷涂 @@ -421,7 +438,7 @@ const addCraft = () => { - + diff --git a/src/views/spraySet/index.vue b/src/views/spraySet/index.vue index 227a226..6592e03 100644 --- a/src/views/spraySet/index.vue +++ b/src/views/spraySet/index.vue @@ -205,13 +205,13 @@ const dehumidifierStop = async () => { uL/min - + 清洗注射器管路 - + 清洗喷嘴管路 - + 停止清洗 @@ -231,10 +231,10 @@ const dehumidifierStop = async () => { uL/min - + 开始预充 - + 结束预充 @@ -260,10 +260,10 @@ const dehumidifierStop = async () => { %RH - + 开始除湿 - + 停止除湿 diff --git a/vite.config.ts b/vite.config.ts index 6cd72a9..3488468 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -76,8 +76,8 @@ export default defineConfig({ host: '0.0.0.0', proxy: { '/api': { - target: 'http://192.168.1.199:8080', - // target: 'http://192.168.1.200:8080', + // target: 'http://192.168.1.199:8080', + target: 'http://192.168.1.200:8080', // secure: false, changeOrigin: true, // 是否跨域 rewrite: path => path.replace(/^\/api/, 'api'),