From 12981c5e6eb75238ecd5bb12e797c905d9c65792 Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Thu, 6 Mar 2025 11:40:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=89=93=E5=8C=85=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复文件上传打包报错的问题 --- src/components/Upload/FileUpload.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/Upload/FileUpload.vue b/src/components/Upload/FileUpload.vue index ada73735..8b61aa32 100644 --- a/src/components/Upload/FileUpload.vue +++ b/src/components/Upload/FileUpload.vue @@ -112,7 +112,7 @@ const props = defineProps({ }); const modelValue = defineModel("modelValue", { - type: [Array] as PropType, + type: [Array] as PropType, 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); +}