diff --git a/src/services/globalCmd/cmdTypes.ts b/src/services/globalCmd/cmdTypes.ts index b92167d..2d6b87c 100644 --- a/src/services/globalCmd/cmdTypes.ts +++ b/src/services/globalCmd/cmdTypes.ts @@ -1,29 +1,29 @@ -export type OperationCmd = - | "moveMotorToPosition" // 移动电机 +export type OperationCmd = "moveMotorToPosition"; // 移动电机 export type ControlType = { - valveType: string, - isOpen: Boolean -} + valveType: string; + isOpen: Boolean; +}; export type SyringeType = { - rotationSpeed: string | number, - direction: string | number, - time: string | number, -} + rotationSpeed: string | number; + direction: string | number; + time: string | number; +}; type PositionType = { - x:string | number - y:string | number -} -type PositionListType = [PositionType] -export type workType = { - direction: string - space: string | number - nitrogenFlowVelocity : string | number - nitrogenAirPressure : string | number - matrixFlowVelocity : string | number - voltage : string | number - height : string | number - movementSpeed : string | number - position: PositionListType -} \ No newline at end of file + x: number; + y: number; +}; +type PositionListType = PositionType[]; +export type WorkType = { + direction: 1 | 2; + space: number; + nitrogenFlowVelocity: number; + nitrogenAirPressure: number; + matrixFlowVelocity: number; + voltage: number; + needPower?: boolean; + height: number; + movementSpeed: number; + position: PositionListType; +}; diff --git a/src/services/globalCmd/globalCmd.ts b/src/services/globalCmd/globalCmd.ts index 6cac6a0..aae1d2a 100644 --- a/src/services/globalCmd/globalCmd.ts +++ b/src/services/globalCmd/globalCmd.ts @@ -1,48 +1,62 @@ import httpRequest, { type BaseResponse } from "../httpRequest"; import { addTxnRecord } from "../txn"; -import type { OperationCmd, ControlType, SyringeType, workType } from "./cmdTypes"; +import type { OperationCmd, ControlType, SyringeType, WorkType } from "./cmdTypes"; //移动电机 export function moveMotorToPosition(params: { commandName: string; params: Record }) { const commandId = addTxnRecord({ ...params, category: "debug" }); - return httpRequest>({ url: "api/cmd/moveMotorToPosition", params: { ...params, commandId }, method: "POST" }); + return httpRequest>({ + url: "/api/cmd/moveMotorToPosition", + params: { ...params, commandId }, + method: "POST", + }); } //切换清洗管路 export function switchThreeWayValve(params: { type: string }) { const commandId = addTxnRecord({ ...params, category: "debug" }); - return httpRequest>({ url: "/cmd/switchThreeWayValve", params: { ...params, commandId }, method: "POST" }); + return httpRequest>({ + url: "/api/cmd/switchThreeWayValve", + params: { ...params, commandId }, + method: "POST", + }); } //氮气三路 -export function controlValve(params:ControlType) { +export function controlValve(params: ControlType) { const commandId = addTxnRecord({ ...params, category: "debug" }); - return httpRequest>({ url: "/cmd/controlValve", params: { ...params, commandId }, method: "POST" }); + return httpRequest>({ url: "/api/cmd/controlValve", params: { ...params, commandId }, method: "POST" }); } //电压控制 开启 -export function turnOnHighVoltage(params:{voltage: string | number}) { +export function turnOnHighVoltage(params: { voltage: string | number }) { const commandId = addTxnRecord({ ...params, category: "debug" }); - return httpRequest>({ url: "/cmd/turnOnHighVoltage", params: { ...params, commandId }, method: "POST" }); + return httpRequest>({ + url: "/api/cmd/turnOnHighVoltage", + params: { ...params, commandId }, + method: "POST", + }); } //电压控制 关闭 export function turnOffHighVoltage() { - return httpRequest>({ url: "/cmd/turnOffHighVoltage", params: {}, method: "POST" }); + return httpRequest>({ url: "/api/cmd/turnOffHighVoltage", params: {}, method: "POST" }); } //注射泵开启 -export function turnOnSyringePump(params:SyringeType) { - return httpRequest>({ url: "/cmd/turnOnSyringePump", params: {...params}, method: "POST" }); +export function turnOnSyringePump(params: SyringeType) { + return httpRequest>({ url: "/api/cmd/turnOnSyringePump", params: { ...params }, method: "POST" }); } //注射泵关闭 export function turnOffSyringePump() { - return httpRequest>({ url: "/cmd/turnOffSyringePump", params: {}, method: "POST" }); + return httpRequest>({ url: "/api/cmd/turnOffSyringePump", params: {}, method: "POST" }); } //开始喷涂 -export function startWork(params:workType) { - return httpRequest>({ url: "/cmd/startWork", params, method: "POST" }); +export function startWork(params: WorkType) { + return httpRequest>({ url: "/api/cmd/startWork", params, method: "POST" }); +} +export function stopWork() { + return httpRequest>({ url: "/api/cmd/stopWork", method: "POST" }); } - diff --git a/src/views/SprayView.vue b/src/views/SprayView.vue index 3f3357d..c6c93cd 100644 --- a/src/views/SprayView.vue +++ b/src/views/SprayView.vue @@ -120,6 +120,9 @@ import route_h from "@/assets/route_horizontal.png"; import route_h2 from "@/assets/route_horizontal2.png"; import Spray, { type GridArea } from "@/components/Spray.vue"; import { reactive, ref } from "vue"; +import { startWork, stopWork } from "@/services/globalCmd/globalCmd"; +import type { WorkType } from "@/services/globalCmd/cmdTypes"; +import { ElMessage } from "element-plus"; type DTO = { direction: 1 | 2; @@ -136,7 +139,7 @@ type DTO = { y: number; }>; }; -const dto = reactive({ +const dto = reactive({ direction: 1, space: 20, nitrogenFlowVelocity: 20, @@ -171,11 +174,22 @@ function startSpray() { ]; const params = dto.needPower ? dto : { ...dto, voltage: 0 }; console.log(params); - // 调用方法 + + startWork(dto).then(res => { + if (res.success) { + } else { + ElMessage.error(res.msg); + } + }); } function stopSpray() { - // 调用方法 + stopWork().then(res => { + if (res.success) { + } else { + ElMessage.error(res.msg); + } + }); }