feat: 使用静态arp处理通信

This commit is contained in:
2025-07-18 13:16:07 +08:00
parent e9ad1f0256
commit 9af2d3e87e
6 changed files with 372 additions and 75 deletions

View File

@@ -134,21 +134,29 @@
<h4 class="font-semibold">网络配置信息</h4>
<div class="bg-base-200 p-3 rounded">
<div class="text-sm space-y-1">
<div><span class="font-medium">主机IP:</span> {{ networkConfig.hostIP }}</div>
<div><span class="font-medium">板卡IP:</span> {{ networkConfig.boardIP }}</div>
<div><span class="font-medium">主机MAC:</span> {{ networkConfig.hostMAC }}</div>
<div><span class="font-medium">板卡MAC:</span> {{ networkConfig.boardMAC }}</div>
<div>
<span class="font-medium">主机IP:</span>
{{ networkConfig.hostIP }}
</div>
<div>
<span class="font-medium">板卡IP:</span>
{{ networkConfig.boardIP }}
</div>
<div>
<span class="font-medium">主机MAC:</span>
{{ networkConfig.hostMAC }}
</div>
<div>
<span class="font-medium">板卡MAC:</span>
{{ networkConfig.boardMAC }}
</div>
</div>
</div>
</div>
<!-- 操作按钮 -->
<div class="modal-action">
<button
type="button"
class="btn btn-primary"
@click="handleSuccess"
>
<button type="button" class="btn btn-primary" @click="handleSuccess">
确认
</button>
</div>
@@ -166,7 +174,9 @@
import { ref, reactive, watch } from "vue";
import { AuthManager } from "../../utils/AuthManager";
import { useAlertStore } from "../../components/Alert";
import type { NetworkConfigDto } from "../../APIClient";
import { BoardStatus, type NetworkConfigDto } from "../../APIClient";
import { useRequiredInjection } from "@/utils/Common";
import { useBoardManager } from "@/utils/BoardManager";
// Props 和 Emits
interface Props {
@@ -184,8 +194,12 @@ const emit = defineEmits<Emits>();
// 使用 Alert
const alertStore = useAlertStore();
const boardManager = useRequiredInjection(useBoardManager);
// 当前步骤
const currentStep = ref<'input' | 'pairing' | 'configuring' | 'result'>('input');
const currentStep = ref<"input" | "pairing" | "configuring" | "result">(
"input",
);
// 表单数据
const form = reactive({
@@ -231,7 +245,7 @@ function validateForm(): boolean {
function resetForm() {
form.name = "Board1";
errors.name = "";
currentStep.value = 'input';
currentStep.value = "input";
addedBoardId.value = "";
networkConfig.value = null;
}
@@ -255,13 +269,13 @@ async function handleSubmit() {
try {
// 通过 AuthManager 获取认证的 DataClient
const dataClient = AuthManager.createAuthenticatedDataClient();
// 添加板卡到数据库
const boardId = await dataClient.addBoard(form.name.trim());
if (boardId) {
addedBoardId.value = boardId;
currentStep.value = 'pairing';
currentStep.value = "pairing";
alertStore?.success("板卡添加成功,请开启配对模式");
} else {
alertStore?.error("板卡添加失败");
@@ -281,10 +295,10 @@ async function handleCancelPairing() {
try {
// 通过 AuthManager 获取认证的 DataClient
const dataClient = AuthManager.createAuthenticatedDataClient();
// 删除添加的板卡
await dataClient.deleteBoard(addedBoardId.value);
alertStore?.info("已取消添加实验板");
emit("update:visible", false);
resetForm();
@@ -299,7 +313,7 @@ async function handlePairingConfirm() {
if (!addedBoardId.value) return;
isConfiguring.value = true;
currentStep.value = 'configuring';
currentStep.value = "configuring";
try {
// 通过 AuthManager 获取认证的客户端
@@ -308,7 +322,7 @@ async function handlePairingConfirm() {
// 获取数据库中对应分配的板卡信息
const boardInfo = await dataClient.getBoardByID(addedBoardId.value);
if (!boardInfo) {
throw new Error("无法获取板卡信息");
}
@@ -321,21 +335,34 @@ async function handlePairingConfirm() {
await netConfigClient.setBoardIP(boardInfo.ipAddr);
await netConfigClient.setBoardMAC(boardInfo.macAddr);
// 更新板卡状态为可用
if (
(await dataClient.updateBoardStatus(
boardInfo.id,
BoardStatus.Available,
)) != 1
) {
throw new Error("无法更新板卡状态");
}
if (!(await boardManager.getAllBoards()).success) {
alertStore?.error("无法获取板卡列表");
}
// 获取实验板网络信息
const networkInfo = await netConfigClient.getNetworkConfig();
if (networkInfo) {
networkConfig.value = networkInfo;
currentStep.value = 'result';
currentStep.value = "result";
alertStore?.success("实验板配置成功");
} else {
throw new Error("无法获取网络配置信息");
}
} catch (error) {
console.error("配置实验板失败:", error);
alertStore?.error("配置实验板失败");
// 配置失败,删除数据库中的板卡信息
try {
const dataClient = AuthManager.createAuthenticatedDataClient();
@@ -343,9 +370,9 @@ async function handlePairingConfirm() {
} catch (deleteError) {
console.error("删除板卡失败:", deleteError);
}
// 返回输入步骤
currentStep.value = 'input';
currentStep.value = "input";
} finally {
isConfiguring.value = false;
}