fix: 🐛 修复文件上传打包报错的问题

修复文件上传打包报错的问题
This commit is contained in:
Theo
2025-03-06 11:40:01 +08:00
parent 4941d40056
commit 12981c5e6e

View File

@@ -112,7 +112,7 @@ const props = defineProps({
});
const modelValue = defineModel("modelValue", {
type: [Array] as PropType<UploadFile[]>,
type: [Array] as PropType<FileInfo[]>,
required: true,
default: () => [],
});
@@ -131,6 +131,8 @@ watch(
return {
name: name,
url: item.url,
status: "success",
uid: getUid(),
} as UploadFile;
});
},
@@ -191,10 +193,7 @@ const handleProgress = (event: UploadProgressEvent) => {
const handleSuccess = (fileInfo: FileInfo) => {
ElMessage.success("上传成功");
modelValue.value = [
...modelValue.value,
{ name: fileInfo.name, url: fileInfo.url } as UploadFile,
];
modelValue.value = [...modelValue.value, { name: fileInfo.name, url: fileInfo.url } as FileInfo];
};
/**
@@ -224,6 +223,12 @@ function handleDownload(file: UploadUserFile) {
FileAPI.download(url, name);
}
}
/** 获取一个不重复的id */
function getUid(): number {
// 时间戳左移13位相当于乘以8192 + 4位随机数
return (Date.now() << 13) | Math.floor(Math.random() * 8192);
}
</script>
<style lang="scss" scoped>
.el-upload-list__item .el-icon--close {