feat: restore upload jtag bitstream

This commit is contained in:
2025-05-13 21:52:58 +08:00
parent eea03f5bc8
commit 9657aacf83
7 changed files with 198 additions and 93 deletions

View File

@@ -6,7 +6,7 @@
<!-- Input File -->
<fieldset class="fieldset w-full">
<legend class="fieldset-legend text-sm">选择或拖拽上传文件</legend>
<input type="file" class="file-input w-full" @change="handleFileChange" />
<input type="file" class="file-input w-full" :value="fileInput" @change="handleFileChange" />
<label class="fieldset-label">文件最大容量: {{ maxMemory }}MB</label>
</fieldset>
@@ -20,17 +20,27 @@
</template>
<script lang="ts" setup>
import { computed } from "vue";
import { computed, ref } from "vue";
import { useEquipments } from "@/stores/equipments";
import { useDialogStore } from "@/stores/dialog";
import { isNull, isUndefined } from "lodash";
const emits = defineEmits<{
finishedUpload: [file: File];
}>();
const dialog = useDialogStore();
const eqps = useEquipments();
const buttonText = computed(() => {
return isUndefined(props.downloadEvent) ? "上传" : "上传并下载";
});
var bitstream: File | null = null;
// var bitstream: File | null = null;
const bitstream = defineModel<File | undefined>();
const fileInput = computed(() => {
return !isUndefined(bitstream.value) ? bitstream.value.name : "";
});
function handleFileChange(event: Event): void {
const target = event.target as HTMLInputElement;
@@ -40,15 +50,10 @@ function handleFileChange(event: Event): void {
return;
}
bitstream = file;
bitstream.value = file;
}
function checkFile(file: File | null): boolean {
if (isNull(file)) {
dialog.error(`未选择文件`);
return false;
}
function checkFile(file: File): boolean {
const maxBytes = props.maxMemory! * 1024 * 1024; // 将最大容量从 MB 转换为字节
if (file.size > maxBytes) {
dialog.error(`文件大小超过最大限制: ${props.maxMemory}MB`);
@@ -58,18 +63,25 @@ function checkFile(file: File | null): boolean {
}
async function handleClick(event: Event): Promise<void> {
if (!checkFile(bitstream)) return;
if (isNull(bitstream.value) || isUndefined(bitstream.value)) {
dialog.error(`未选择文件`);
return;
}
if (!checkFile(bitstream.value)) return;
if (isUndefined(props.uploadEvent)) {
dialog.error("无法上传");
return;
}
// Upload
// Upload - 修改这里传递bitstream.value而不是bitstream
try {
const ret = await props.uploadEvent(event, bitstream);
const ret = await props.uploadEvent(event, bitstream.value);
if (isUndefined(props.downloadEvent)) {
if (ret) dialog.info("上传成功");
else dialog.error("上传失败");
if (ret) {
dialog.info("上传成功");
emits("finishedUpload", bitstream.value);
} else dialog.error("上传失败");
return;
}
} catch (e) {
@@ -93,6 +105,7 @@ interface Props {
uploadEvent?: Function;
downloadEvent?: Function;
maxMemory?: number;
defaultFile?: File;
}
const props = withDefaults(defineProps<Props>(), {