From 68141f9c0620c93dc64870763fee3f8874ad12be Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Mon, 3 Mar 2025 09:40:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=96=B7=E6=B6=82=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Spray.vue | 2 +- src/services/globalCmd/cmdTypes.ts | 2 +- src/services/matrix/craft.ts | 17 ++++++ src/views/SprayView.vue | 114 +++++++++++++++++++++++++------------ 4 files changed, 97 insertions(+), 38 deletions(-) diff --git a/src/components/Spray.vue b/src/components/Spray.vue index 4c0e660..134879a 100644 --- a/src/components/Spray.vue +++ b/src/components/Spray.vue @@ -60,7 +60,7 @@ const yEndPx = props.height - props.bottomPadding; const yStepPx = (props.height - props.topPadding - props.bottomPadding) / props.rows; const yUnitPx = yStepPx / props.cellNum; -let selectArea: GridArea = { xStart: 5, xEnd: 15, yStart: 5, yEnd: 15 }; +let selectArea: GridArea = { xStart: 8, xEnd: 16, yStart: 8, yEnd: 16 }; const touchPoint: Point2D = { x: 0, y: 0 }; let touchedElem: TouchElem = "None"; diff --git a/src/services/globalCmd/cmdTypes.ts b/src/services/globalCmd/cmdTypes.ts index 9b36621..3141212 100644 --- a/src/services/globalCmd/cmdTypes.ts +++ b/src/services/globalCmd/cmdTypes.ts @@ -12,7 +12,7 @@ export type SyringeType = { time: number; }; }; -type PositionType = { +export type PositionType = { x1: number; y1: number; x2: number; diff --git a/src/services/matrix/craft.ts b/src/services/matrix/craft.ts index e329b93..7686294 100644 --- a/src/services/matrix/craft.ts +++ b/src/services/matrix/craft.ts @@ -1,3 +1,4 @@ +import type { WorkType } from "../globalCmd/cmdTypes"; import httpRequest, { type BaseResponse } from "../httpRequest"; import type { CraftItem } from "./type"; @@ -16,3 +17,19 @@ export function getListByMatrixId(params: { matrixId: number }) { method: "GET", }); } + +export function createCraft(params: CraftItem) { + return httpRequest>({ + url: "/api/matrixCraft/add", + params, + method: "POST", + }); +} + +export function updateCraft(params: CraftItem) { + return httpRequest>({ + url: "/api/matrixCraft", + params, + method: "PUT", + }); +} diff --git a/src/views/SprayView.vue b/src/views/SprayView.vue index 04d9823..2474a0f 100644 --- a/src/views/SprayView.vue +++ b/src/views/SprayView.vue @@ -7,7 +7,7 @@
选择基质 - + 工艺 @@ -52,7 +52,7 @@ :columns="1" :rows="3" :cell-num="25" - @select-area="onSelectArea" /> + @select-area="area => onSelectArea(area, 0)" /> + @select-area="area => onSelectArea(area, 1)" /> + @select-area="area => onSelectArea(area, 2)" /> + @select-area="area => onSelectArea(area, 3)" />
- - - - + + + + - @@ -110,12 +109,11 @@ import Spray, { type GridArea } from "@/components/Spray.vue"; import { onMounted, ref } from "vue"; import { startSpray, stopWork } from "@/services/globalCmd/globalCmd"; -import type { WorkType } from "@/services/globalCmd/cmdTypes"; +import { checkSprayParamValid, type PositionType, type WorkType } from "@/services/globalCmd/cmdTypes"; import { ElMessage } from "element-plus"; -import type { MatrixItem } from "./matrixManage/type"; import { useSettingStore } from "@/stores/setting"; import type { CraftItem } from "@/services/matrix/type"; -import { getListByMatrixId } from "@/services/matrix/craft"; +import { createCraft, getListByMatrixId, updateCraft } from "@/services/matrix/craft"; import SprayParam from "@/components/SprayParam.vue"; const defaultCraft: Partial = { @@ -136,15 +134,21 @@ const defaultCraft: Partial = { const settingStore = useSettingStore(); -const selectMatrix = ref( - settingStore.matrixList.length > 0 ? settingStore.matrixList[0] : ({ id: 0, name: "未知" } as MatrixItem) -); +const selectMatrixId = ref(settingStore.matrixList.length > 0 ? settingStore.matrixList[0].id : 0); const craftList = ref([]); + +const selectCraftId = ref(1); const selectCraft = ref>(defaultCraft); -const selectedArea = ref(); -const checked = ref(["a", "b"]); +const selectedArea = ref([ + { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 }, + { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 }, + { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 }, + { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 }, +]); + +const checked = ref(["0"]); onMounted(() => { if (settingStore.matrixList.length > 0) { @@ -152,17 +156,20 @@ onMounted(() => { } }); -function onSelectArea(area: GridArea) { - selectedArea.value = area; +function onSelectArea(area: GridArea, index: number) { + selectedArea.value[index] = area; } function onMatrixChange(val: number) { + selectMatrixId.value = val; getListByMatrixId({ matrixId: val }).then(res => { if (res.success) { craftList.value = res.data || []; if (res.data.length > 0) { + selectCraftId.value = res.data[0].id; selectCraft.value = { ...res.data[0], needPower: res.data[0].voltage > 0 }; } else { + selectCraftId.value = 0; selectCraft.value = defaultCraft; } } else { @@ -173,25 +180,40 @@ function onMatrixChange(val: number) { function onCraftChange(val: number) { const craft = craftList.value.find(item => item.id === val); - selectCraft.value = craft || defaultCraft; + selectCraft.value = { ...craft, needPower: craft!.voltage > 0 }; } +function mapAreaToPosition() { + return checked.value.map(index => { + const idx = +index; + const pos: PositionType = { + x1: selectedArea.value[idx].xStart, + y1: selectedArea.value[idx].yStart, + x2: selectedArea.value[idx].xEnd, + y2: selectedArea.value[idx].yEnd, + index: idx, + }; + return pos; + }); +} function onStartSpray() { - selectCraft.value.position = [ - { - x1: selectedArea.value?.xStart || 10, - y1: selectedArea.value?.yStart || 10, - x2: selectedArea.value?.xEnd || 20, - y2: selectedArea.value?.yEnd || 20, - index: 0, - }, - ]; - const params = selectCraft.value.needPower ? selectCraft : { ...selectCraft, voltage: 0 }; + if (checked.value.length === 0) { + ElMessage.error("请至少选择一个玻片"); + return; + } + selectCraft.value.position = mapAreaToPosition(); + const params = selectCraft.value.needPower ? selectCraft.value : { ...selectCraft.value, voltage: 0 }; console.log(params); - //TODO 检查参数合法性 + + const check = checkSprayParamValid(params); + if (!check[0]) { + ElMessage.error(check[1]); + return; + } + startSpray({ - ...(selectCraft.value as CraftItem), - matrixId: selectMatrix.value.id, + ...(params as CraftItem), + matrixId: selectMatrixId.value, matrixCraftId: selectCraft.value.id || 0, }).then(res => { if (res.success) { @@ -212,7 +234,27 @@ function onStopSpray() { function updateSprayParam(p: WorkType) { console.log(p); - selectCraft.value = p as CraftItem; + const params = !!p.needPower ? p : { ...p, voltage: 0 }; + if ((params as CraftItem).id === 0) { + // 创建 + const p = { ...(params as CraftItem), matrixId: selectMatrixId.value }; + createCraft(p).then(res => { + if (res.success) { + onMatrixChange(selectMatrixId.value); + } else { + ElMessage.error(res.msg); + } + }); + } else { + // 更新 + updateCraft(params as CraftItem).then(res => { + if (res.success) { + selectCraft.value = params as CraftItem; + } else { + ElMessage.error(res.msg); + } + }); + } }