From ba6ec73b84c35e56e32e8dec1d26823d9c2b7420 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Mon, 19 May 2025 15:56:23 +0800 Subject: [PATCH] fix: frontend upload bitstream failed --- src/Common.ts | 2 + src/components/UploadCard.vue | 18 ++- src/components/equipments/MotherBoard.vue | 14 +-- src/components/equipments/MotherBoardCaps.vue | 116 +++++++++--------- src/stores/equipments.ts | 12 +- src/views/TestView.vue | 39 +++--- 6 files changed, 99 insertions(+), 102 deletions(-) diff --git a/src/Common.ts b/src/Common.ts index f658f9d..406186f 100644 --- a/src/Common.ts +++ b/src/Common.ts @@ -3,6 +3,8 @@ import { isNull, isUndefined } from "lodash"; export namespace Common { export function toFileParameter(object: File): FileParameter { + if (isNull(object) || isUndefined(object)) + throw new Error("File is Null or Undefined"); return { data: object, fileName: object.name diff --git a/src/components/UploadCard.vue b/src/components/UploadCard.vue index 4c59ae5..f5899cc 100644 --- a/src/components/UploadCard.vue +++ b/src/components/UploadCard.vue @@ -31,10 +31,9 @@ import { useDialogStore } from "@/stores/dialog"; import { isNull, isUndefined } from "lodash"; interface Props { - uploadEvent?: Function; - downloadEvent?: Function; + uploadEvent?: (file: File) => Promise; + downloadEvent?: () => Promise; maxMemory?: number; - defaultFile?: string; } const props = withDefaults(defineProps(), { @@ -53,7 +52,10 @@ const buttonText = computed(() => { }); const fileInput = useTemplateRef("fileInput"); -const bitstream = defineModel(); +const bitstream = defineModel("bitstreamFile", { + type: File, + default: undefined, +}); onMounted(() => { if (!isUndefined(bitstream.value) && !isNull(fileInput.value)) { let fileList = new DataTransfer(); @@ -94,10 +96,10 @@ async function handleClick(event: Event): Promise { return; } - // Upload - 修改这里,传递bitstream.value而不是bitstream isUploading.value = true; try { - const ret = await props.uploadEvent(event, bitstream.value); + const ret = await props.uploadEvent(bitstream.value); + console.debug(`After upload bistream: ${bitstream.value}, result: ${ret}`); if (isUndefined(props.downloadEvent)) { if (ret) { dialog.info("上传成功"); @@ -105,6 +107,10 @@ async function handleClick(event: Event): Promise { } else dialog.error("上传失败"); return; } + if (!ret) { + isUploading.value = false; + return; + } } catch (e) { dialog.error("上传失败"); console.error(e); diff --git a/src/components/equipments/MotherBoard.vue b/src/components/equipments/MotherBoard.vue index d9f2ca9..3003d0f 100644 --- a/src/components/equipments/MotherBoard.vue +++ b/src/components/equipments/MotherBoard.vue @@ -10,15 +10,15 @@ - +