9 changed files with 549 additions and 155 deletions
-
6.env
-
29src/services/globalCmd/cmdTypes.ts
-
48src/services/globalCmd/globalCmd.ts
-
64src/services/httpRequest.ts
-
43src/services/txn.ts
-
458src/views/debug/index.vue
-
15src/views/debug/type.ts
-
39src/views/spurtPrint/index.vue
-
2vite.config.ts
@ -1,3 +1,3 @@ |
|||
VITE_API_HOST=window.location.hostname |
|||
VITE_API_PORT=80 |
|||
VITE_WS_PATH=/api/v1/app/ws/state |
|||
VITE_API_HOST=192.168.1.199 |
|||
VITE_API_PORT=8090 |
|||
VITE_WS_PATH=/ws |
@ -0,0 +1,29 @@ |
|||
export type OperationCmd = |
|||
| "moveMotorToPosition" // 移动电机
|
|||
|
|||
export type ControlType = { |
|||
valveType: string, |
|||
isOpen: Boolean |
|||
} |
|||
|
|||
export type SyringeType = { |
|||
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 |
|||
} |
@ -0,0 +1,48 @@ |
|||
import httpRequest, { type BaseResponse } from "../httpRequest"; |
|||
import { addTxnRecord } from "../txn"; |
|||
import type { OperationCmd, ControlType, SyringeType, workType } from "./cmdTypes"; |
|||
|
|||
//移动电机
|
|||
export function moveMotorToPosition(params: { commandName: string; params: Record<string, any> }) { |
|||
const commandId = addTxnRecord({ ...params, category: "debug" }); |
|||
return httpRequest<BaseResponse<string>>({ url: "api/cmd/moveMotorToPosition", params: { ...params, commandId }, method: "POST" }); |
|||
} |
|||
|
|||
//切换清洗管路
|
|||
export function switchThreeWayValve(params: { type: string }) { |
|||
const commandId = addTxnRecord({ ...params, category: "debug" }); |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/switchThreeWayValve", params: { ...params, commandId }, method: "POST" }); |
|||
} |
|||
|
|||
//氮气三路
|
|||
export function controlValve(params:ControlType) { |
|||
const commandId = addTxnRecord({ ...params, category: "debug" }); |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/controlValve", params: { ...params, commandId }, method: "POST" }); |
|||
} |
|||
|
|||
//电压控制 开启
|
|||
export function turnOnHighVoltage(params:{voltage: string | number}) { |
|||
const commandId = addTxnRecord({ ...params, category: "debug" }); |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/turnOnHighVoltage", params: { ...params, commandId }, method: "POST" }); |
|||
} |
|||
|
|||
//电压控制 关闭
|
|||
export function turnOffHighVoltage() { |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/turnOffHighVoltage", params: {}, method: "POST" }); |
|||
} |
|||
|
|||
//注射泵开启
|
|||
export function turnOnSyringePump(params:SyringeType) { |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/turnOnSyringePump", params: {...params}, method: "POST" }); |
|||
} |
|||
|
|||
//注射泵关闭
|
|||
export function turnOffSyringePump() { |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/turnOffSyringePump", params: {}, method: "POST" }); |
|||
} |
|||
|
|||
//开始喷涂
|
|||
export function startWork(params:workType) { |
|||
return httpRequest<BaseResponse<string>>({ url: "/cmd/startWork", params, method: "POST" }); |
|||
} |
|||
|
@ -0,0 +1,64 @@ |
|||
import { Subject } from "rxjs"; |
|||
|
|||
export interface BaseResponse<T = unknown> { |
|||
success: boolean; |
|||
code: string; |
|||
msg: string; |
|||
data: T; |
|||
} |
|||
|
|||
type HttpReqParam = { |
|||
url: string; |
|||
method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE"; |
|||
params?: Record<string, any>; |
|||
encode?: "form" | "json"; // 入参编码类型
|
|||
headers?: Record<string, any>; |
|||
}; |
|||
|
|||
export type ApiException = "invalidToken" | "serverError"; |
|||
|
|||
const exceptionSub = new Subject<ApiException>(); |
|||
export const exceptionOb = exceptionSub.asObservable(); |
|||
|
|||
function extHandle(res: BaseResponse) { |
|||
if (res.code === "A0230") { |
|||
// 访问令牌无效或已过期
|
|||
exceptionSub.next("invalidToken"); |
|||
} |
|||
return { |
|||
...res, |
|||
success: res.code === "00000", |
|||
}; |
|||
} |
|||
|
|||
export default async function httpRequest<T>({ url, method = "GET", params = {}, encode = "json", headers = {} }: HttpReqParam) { |
|||
const token = sessionStorage.getItem("token"); |
|||
if (token) { |
|||
headers = { Authorization: token, ...headers }; |
|||
} |
|||
if (method === "GET") { |
|||
const query = urlEncode(params); |
|||
const _url = query ? url + "?" + query : url; |
|||
const res = await fetch(_url, { headers }); |
|||
return res.json().then(res => extHandle(res) as T); |
|||
} else { |
|||
const body = encode === "json" ? JSON.stringify(params) : urlEncode(params); |
|||
const _headers = |
|||
encode === "json" |
|||
? { "Content-Type": "application/json; charset=utf-8", ...headers } |
|||
: { "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", ...headers }; |
|||
const res = await fetch(url, { method, headers: _headers, body }); |
|||
return res.json().then(res => extHandle(res) as T); |
|||
} |
|||
} |
|||
export function urlEncode(params?: Record<string, any>) { |
|||
let query = ""; |
|||
if (params && Object.keys(params).length > 0) { |
|||
const qs = []; |
|||
for (let attr in params) { |
|||
qs.push(`${attr}=${encodeURIComponent(params[attr])}`); |
|||
} |
|||
query = qs.join("&"); |
|||
} |
|||
return query; |
|||
} |
@ -0,0 +1,43 @@ |
|||
import type { OperationCmd } from "./globalCmd/cmdTypes"; |
|||
|
|||
let _lastTimestamp = 0; |
|||
export function generateTxnNo() { |
|||
const txnNo = Date.now(); |
|||
// 确保前后两条指令的txn 不一样
|
|||
if (txnNo !== _lastTimestamp) { |
|||
if (txnNo < _lastTimestamp) { |
|||
_lastTimestamp++; |
|||
} else { |
|||
_lastTimestamp = txnNo; |
|||
} |
|||
} else { |
|||
_lastTimestamp = txnNo + 1; |
|||
} |
|||
return _lastTimestamp; |
|||
} |
|||
|
|||
type DebugCmdRecord = { |
|||
category: "debug"; |
|||
commandName: string; |
|||
params: Record<string, any>; |
|||
}; |
|||
|
|||
type TxnRecord = Partial<DebugCmdRecord>; |
|||
|
|||
const txnCmdMap: Record<string, TxnRecord> = {}; |
|||
|
|||
export function addTxnRecord(val: TxnRecord) { |
|||
const txn = generateTxnNo().toString(); |
|||
txnCmdMap[txn] = val; |
|||
return txn; |
|||
} |
|||
|
|||
export function getTxnRecord(txn: string, category: TxnRecord["category"]) { |
|||
const record = txnCmdMap[txn]; |
|||
// 只有属于指定category时,才返回,且返回后删除记录,节约内存
|
|||
if (record && record.category === category) { |
|||
delete txnCmdMap[txn]; |
|||
return record; |
|||
} |
|||
return undefined; |
|||
} |
@ -1,5 +1,12 @@ |
|||
export type MachineryType = { |
|||
x: string | number |
|||
y: string | number |
|||
z: string | number |
|||
} |
|||
axis: string, |
|||
position: string | number |
|||
} |
|||
|
|||
export type ControlNitrogen = 'Dehumidification' | 'Cleaning' | 'Nozzle' |
|||
|
|||
export type SyringeType = { |
|||
rotationSpeed: string | number, |
|||
direction: string | number, |
|||
time: string | number, |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue