fix: frontend upload bitstream failed

This commit is contained in:
2025-05-19 15:56:23 +08:00
parent 5042bf8ce5
commit ba6ec73b84
6 changed files with 99 additions and 102 deletions

View File

@@ -31,10 +31,9 @@ import { useDialogStore } from "@/stores/dialog";
import { isNull, isUndefined } from "lodash";
interface Props {
uploadEvent?: Function;
downloadEvent?: Function;
uploadEvent?: (file: File) => Promise<boolean>;
downloadEvent?: () => Promise<boolean>;
maxMemory?: number;
defaultFile?: string;
}
const props = withDefaults(defineProps<Props>(), {
@@ -53,7 +52,10 @@ const buttonText = computed(() => {
});
const fileInput = useTemplateRef("fileInput");
const bitstream = defineModel<File | undefined>();
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<void> {
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<void> {
} else dialog.error("上传失败");
return;
}
if (!ret) {
isUploading.value = false;
return;
}
} catch (e) {
dialog.error("上传失败");
console.error(e);