diff --git a/src/components/custom/file-upload.vue b/src/components/custom/file-upload.vue index e3d02991..d9af02e2 100644 --- a/src/components/custom/file-upload.vue +++ b/src/components/custom/file-upload.vue @@ -28,7 +28,7 @@ const props = withDefaults(defineProps(), { defaultUpload: true, showTip: true, max: 5, - accept: '.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.pdf', + accept: '', fileSize: 5, uploadType: 'file', modelValue: '' @@ -121,6 +121,12 @@ function beforeUpload(options: { file: UploadFileInfo; fileList: UploadFileInfo[ return false; } } + + if (accept.value && !file.name.match(new RegExp(accept.value.replace(/\./g, '\\.').replace(/,/g, '|')))) { + window.$message?.error(`文件格式不正确, 请上传 ${accept.value} 格式文件!`); + return false; + } + // 校检文件名是否包含特殊字符 if (file.name.includes(',')) { window.$message?.error('文件名不正确,不能包含英文逗号!'); @@ -203,8 +209,13 @@ async function handleRemove(file: UploadFileInfo) { if (file.status !== 'finished') { return; } + fileList.value = fileList.value.filter(item => item.id !== file.id); + const fileIds = listToString(fileList.value); + emit('update:modelValue', fileIds); + needRelaodData.value = true; const { error } = await fetchBatchDeleteOss([file.id]); if (error) return; + window.$message?.success('删除成功'); } @@ -261,4 +272,4 @@ async function handleRemove(file: UploadFileInfo) { - \ No newline at end of file +