diff --git a/src/services/debug/debugApi.ts b/src/services/globalCmd/globalCmd.ts similarity index 88% rename from src/services/debug/debugApi.ts rename to src/services/globalCmd/globalCmd.ts index c4d4ee5..19bb440 100644 --- a/src/services/debug/debugApi.ts +++ b/src/services/globalCmd/globalCmd.ts @@ -1,7 +1,7 @@ import httpRequest, { type BaseResponse } from "../httpRequest"; import { addTxnRecord } from "../txn"; -export const CmdDescMap: { [k in DebugCmd]: string } = { +export const CmdDescMap: { [k in OperationCmd]: string } = { upTray: "抬起托盘", downTray: "降下托盘", injectFluid: "注入溶液", @@ -22,7 +22,7 @@ export const CmdDescMap: { [k in DebugCmd]: string } = { moveTube: "移动试管", }; -export type DebugCmd = +export type OperationCmd = | "upTray" // 抬起托盘 | "downTray" // 降下托盘 | "injectFluid" // 注入溶液 @@ -42,7 +42,7 @@ export type DebugCmd = | "moveMachineArm" // 移动机械臂 | "moveTube"; // 移动试管 -export function debugCmd(params: { command: DebugCmd; params: Record }) { +export function debugCmd(params: { command: OperationCmd; params: Record }) { const commandId = addTxnRecord({ ...params, category: "debug" }); return httpRequest>({ url: "/api/cmd/", params: { ...params, commandId }, method: "POST" }); } diff --git a/src/services/socket.ts b/src/services/socket.ts index 9a2c4a4..9daeadb 100644 --- a/src/services/socket.ts +++ b/src/services/socket.ts @@ -1,5 +1,4 @@ import { Subject } from "rxjs"; -import type { DebugCmd } from "./debug/debugApi"; export type CmdSuccess = "D0000"; export type CmdFailure = "D1111"; diff --git a/src/services/txn.ts b/src/services/txn.ts index 5286065..c6f9f73 100644 --- a/src/services/txn.ts +++ b/src/services/txn.ts @@ -1,4 +1,4 @@ -import type { DebugCmd } from "./debug/debugApi"; +import type { OperationCmd } from "./globalCmd/globalCmd"; let _lastTimestamp = 0; export function generateTxnNo() { @@ -17,27 +17,27 @@ export function generateTxnNo() { } type DebugCmdRecord = { - category: 'debug'; - command: DebugCmd; - params: Record -} + category: "debug"; + command: OperationCmd; + params: Record; +}; -type TxnRecord = DebugCmdRecord // | xxxRecord +type TxnRecord = DebugCmdRecord; // | xxxRecord const txnCmdMap: Record = {}; export function addTxnRecord(val: TxnRecord) { const txn = generateTxnNo().toString(); txnCmdMap[txn] = val; - return txn + return txn; } -export function getTxnRecord(txn: string, category: TxnRecord['category']) { +export function getTxnRecord(txn: string, category: TxnRecord["category"]) { const record = txnCmdMap[txn]; - // 只有属于指定category时,才返回,且返回后删除记录,节约内存 - if (record.category === category) { - delete txnCmdMap[txn]; - return record - } - return undefined + // 只有属于指定category时,才返回,且返回后删除记录,节约内存 + if (record.category === category) { + delete txnCmdMap[txn]; + return record; + } + return undefined; } diff --git a/src/views/debug/debug.vue b/src/views/debug/debug.vue index 2729deb..7b960b3 100644 --- a/src/views/debug/debug.vue +++ b/src/views/debug/debug.vue @@ -169,7 +169,7 @@