fix: 文件类型校验
Signed-off-by: NicholasLD <nicholasld505@gmail.com>
This commit is contained in:
parent
e8240021cb
commit
19940201f5
@ -28,7 +28,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
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('删除成功');
|
||||
}
|
||||
</script>
|
||||
@ -261,4 +272,4 @@ async function handleRemove(file: UploadFileInfo) {
|
||||
</NP>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped></style>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user