From da6386c6f038887ac89b952a9379fc75d2936c52 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Fri, 11 Jul 2025 21:44:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=89=8D=E7=AB=AF=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=90=8E=E7=AB=AFapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Alert/index.ts | 21 +++ src/views/User/BoardControl.vue | 186 ++++----------------- src/views/User/BoardManager.ts | 288 ++++++++++++++++++++++++++++++++ 3 files changed, 339 insertions(+), 156 deletions(-) diff --git a/src/components/Alert/index.ts b/src/components/Alert/index.ts index 01879a4..b924eba 100644 --- a/src/components/Alert/index.ts +++ b/src/components/Alert/index.ts @@ -50,10 +50,31 @@ const [useAlertProvider, useAlertStore] = createInjectionState(() => { } } + // Convenience methods for different alert types + function error(message: string, duration = 2000) { + show(message, "error", duration); + } + + function info(message: string, duration = 2000) { + show(message, "info", duration); + } + + function warn(message: string, duration = 2000) { + show(message, "warning", duration); + } + + function success(message: string, duration = 2000) { + show(message, "success", duration); + } + return { alertState, show, hide, + error, + info, + warn, + success, }; }); diff --git a/src/views/User/BoardControl.vue b/src/views/User/BoardControl.vue index 003e159..abc6c9f 100644 --- a/src/views/User/BoardControl.vue +++ b/src/views/User/BoardControl.vue @@ -3,11 +3,7 @@

FPGA 设备管理

@@ -17,7 +13,9 @@

IP 地址列表

- +
@@ -185,45 +183,20 @@ import { getSortedRowModel, useVueTable, } from "@tanstack/vue-table"; -import { isNull, isUndefined } from "lodash"; -import { h, ref } from "vue"; -import { RemoteUpdateClient } from "@/APIClient"; -import { useDialogStore } from "@/stores/dialog"; -import { Common } from "@/utils/Common"; +import { h, onMounted, ref } from "vue"; +import { useProvideBoardManager, type BoardData } from "./BoardManager"; -const dialog = useDialogStore(); +// 使用 BoardManager +const boardManager = useProvideBoardManager()!; // 编辑状态 const isEditMode = ref(false); - -// 远程升级相关参数 -const devPort = 1234; -const remoteUpdater = new RemoteUpdateClient(); - -// 设备数据接口 -export interface DeviceData { - id: string; - devAddr: string; - version: string; - defaultBitstream: string; - goldBitstreamFile?: File; - appBitstream1File?: File; - appBitstream2File?: File; - appBitstream3File?: File; +function toggleEditMode() { + isEditMode.value = !isEditMode.value; } -// 模拟数据,实际应该从API获取 -const data = ref([ - { - id: "1", - devAddr: "192.168.1.100", - version: "v1.2.3", - defaultBitstream: "黄金位流", - }, -]); - // 表格列定义 -const columns: ColumnDef[] = [ +const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => @@ -258,18 +231,19 @@ const columns: ColumnDef[] = [ ? h("input", { type: "text", class: "input input-sm w-full", - value: device.devAddr, + value: device.ipAddr, onInput: (e: Event) => { - device.devAddr = (e.target as HTMLInputElement).value; + device.ipAddr = (e.target as HTMLInputElement).value; }, }) - : h("span", { class: "font-medium" }, device.devAddr); + : h("span", { class: "font-medium" }, device.ipAddr); }, }, { accessorKey: "version", header: "版本号", - cell: ({ row }) => row.getValue("version"), + cell: ({ row }) => + h("span", { class: "font-mono" }, row.original.firmVersion), }, { accessorKey: "defaultBitstream", @@ -303,7 +277,7 @@ const columns: ColumnDef[] = [ type: "file", class: "file-input file-input-primary file-input-sm", onChange: (e: Event) => - handleFileChange(e, device, "goldBitstreamFile"), + boardManager.handleFileChange(e, device, "goldBitstreamFile"), }); }, }, @@ -316,7 +290,7 @@ const columns: ColumnDef[] = [ type: "file", class: "file-input file-input-secondary file-input-sm", onChange: (e: Event) => - handleFileChange(e, device, "appBitstream1File"), + boardManager.handleFileChange(e, device, "appBitstream1File"), }); }, }, @@ -329,7 +303,7 @@ const columns: ColumnDef[] = [ type: "file", class: "file-input file-input-accent file-input-sm", onChange: (e: Event) => - handleFileChange(e, device, "appBitstream2File"), + boardManager.handleFileChange(e, device, "appBitstream2File"), }); }, }, @@ -342,7 +316,7 @@ const columns: ColumnDef[] = [ type: "file", class: "file-input file-input-info file-input-sm", onChange: (e: Event) => - handleFileChange(e, device, "appBitstream3File"), + boardManager.handleFileChange(e, device, "appBitstream3File"), }); }, }, @@ -357,8 +331,8 @@ const columns: ColumnDef[] = [ { class: "btn btn-warning btn-sm", onClick: () => - uploadAndDownloadBitstreams( - device.devAddr, + boardManager.uploadAndDownloadBitstreams( + device, device.goldBitstreamFile, device.appBitstream1File, device.appBitstream2File, @@ -372,9 +346,9 @@ const columns: ColumnDef[] = [ { class: "btn btn-success btn-sm", onClick: () => - hotresetBitstream( - device.devAddr, - getSelectedBitstreamNum(device.defaultBitstream), + boardManager.hotresetBitstream( + device, + boardManager.getSelectedBitstreamNum(device.defaultBitstream), ), }, "热启动", @@ -395,7 +369,7 @@ const expanded = ref({}); // 创建表格实例 const table = useVueTable({ get data() { - return data.value; + return boardManager.boards.value; }, columns, getCoreRowModel: getCoreRowModel(), @@ -456,110 +430,10 @@ const table = useVueTable({ }, }, }); - -// 处理文件上传 -function handleFileChange( - event: Event, - device: DeviceData, - fileKey: keyof DeviceData, -) { - const target = event.target as HTMLInputElement; - const file = target.files?.[0]; - if (file) { - (device as any)[fileKey] = file; - } -} - -function getSelectedBitstreamNum(bitstreamName: string): number { - if (bitstreamName === "黄金位流") return 0; - if (bitstreamName === "应用位流1") return 1; - if (bitstreamName === "应用位流2") return 2; - if (bitstreamName === "应用位流3") return 3; - return 0; -} - -async function uploadAndDownloadBitstreams( - devAddr: string, - goldBitstream?: File, - appBitstream1?: File, - appBitstream2?: File, - appBitstream3?: File, -) { - let cnt = 0; - if (!isUndefined(goldBitstream)) cnt++; - if (!isUndefined(appBitstream1)) cnt++; - if (!isUndefined(appBitstream2)) cnt++; - if (!isUndefined(appBitstream3)) cnt++; - if (cnt === 0) { - dialog.error("未选择比特流"); - return; - } - - try { - { - const ret = await remoteUpdater.uploadBitstreams( - devAddr, - Common.toFileParameterOrNull(goldBitstream), - Common.toFileParameterOrNull(appBitstream1), - Common.toFileParameterOrNull(appBitstream2), - Common.toFileParameterOrNull(appBitstream3), - ); - if (!ret) { - dialog.warn("上传比特流出错"); - return; - } - } - { - const ret = await remoteUpdater.downloadMultiBitstreams( - devAddr, - devPort, - getSelectedBitstreamNum(data.value[0].defaultBitstream), - ); - if (ret != cnt) { - dialog.warn("固化比特流出错"); - } else { - dialog.info("固化比特流成功"); - } - } - } catch (e) { - dialog.error("比特流上传错误"); - console.error(e); - } -} - -async function hotresetBitstream(devAddr: string, bitstreamNum: number) { - try { - const ret = await remoteUpdater.hotResetBitstream( - devAddr, - devPort, - bitstreamNum, - ); - if (ret) { - dialog.info("切换比特流成功"); - } else { - dialog.error("切换比特流失败"); - } - } catch (e) { - dialog.error("切换比特流失败"); - console.error(e); - } -} - -async function refreshData() { - try { - const ret = await remoteUpdater.getFirmwareVersion( - data.value[0].devAddr, - devPort, - ); - // 更新版本信息 - if (ret) { - data.value[0].version = String(ret); - } - } catch (e) { - dialog.error("获取数据失败"); - console.error(e); - } -} +onMounted(() => { + // 初始化数据 + boardManager.fetchBoardsData(); +});