Browse Source

命令重命名

feature/layout_0214
zhangjiming 6 months ago
parent
commit
cc59dc159d
  1. 6
      src/services/globalCmd/globalCmd.ts
  2. 1
      src/services/socket.ts
  3. 28
      src/services/txn.ts
  4. 4
      src/views/debug/debug.vue

6
src/services/debug/debugApi.ts → 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<string, any> }) {
export function debugCmd(params: { command: OperationCmd; params: Record<string, any> }) {
const commandId = addTxnRecord({ ...params, category: "debug" });
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/", params: { ...params, commandId }, method: "POST" });
}

1
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";

28
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<string, any>
}
category: "debug";
command: OperationCmd;
params: Record<string, any>;
};
type TxnRecord = DebugCmdRecord // | xxxRecord
type TxnRecord = DebugCmdRecord; // | xxxRecord
const txnCmdMap: Record<string, TxnRecord> = {};
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;
}

4
src/views/debug/debug.vue

@ -169,7 +169,7 @@
</div>
</template>
<script setup lang="ts">
import { CmdDescMap, debugCmd, type DebugCmd } from "@/services/debug/debugApi";
import { CmdDescMap, debugCmd, type OperationCmd } from "@/services/globalCmd/globalCmd";
import { createWebSocket, sharedWsUrl } from "@/services/socket";
import { updateConfig } from "@/services/sysConfig/sysConfig";
import { useSettingStore } from "@/stores/setting";
@ -231,7 +231,7 @@ onMounted(() => {
});
});
function onCmdClick(command: DebugCmd) {
function onCmdClick(command: OperationCmd) {
let params: Record<string, any> = {};
if (command === "upTray") {
params = { areaId: selectedAreaForTray.value, height: trayHeight.value };

Loading…
Cancel
Save