feat: 添加文件上传数量限制,优化禁用状态逻辑并显示上传文件信息
All checks were successful
/ build-and-deploy-to-vercel (push) Successful in 1m44s
/ playwright (push) Successful in 1m56s
/ depcheck (push) Successful in 1m35s

This commit is contained in:
严浩
2024-12-16 01:09:34 +08:00
parent 511f07f778
commit 86943c1e58

View File

@ -81,10 +81,14 @@ const showUploadButton = computed(() => {
return false;
});
const fileLimit = 2;
const disabled = computed(() => {
if (fileUploadRef.value?.uploadedFiles?.some((f) => f.status === 'failed')) {
return true;
}
if ((fileUploadRef.value?.uploadedFileCount || 0) >= fileLimit) {
return true;
}
return false;
});
</script>
@ -102,7 +106,7 @@ const disabled = computed(() => {
accept="image/*"
:maxFileSize="1000000 * 1"
invalidFileSizeMessage="文件 {0} 大小超过限制 {1}"
:fileLimit="2"
:fileLimit="fileLimit"
invalidFileLimitMessage="最多只能上传 {0} 个文件,请移除多余文件后点击上传"
@uploader="onUploader"
:chooseButtonProps="{ size: 'small' }"
@ -113,11 +117,6 @@ const disabled = computed(() => {
<Message size="small" severity="info">请上传图片</Message>
</template>
<template #content="{ messages, removeFileCallback, removeUploadedFileCallback }">
<!-- slotProps.removeFileCallback -->
<!-- slotProps.removeUploadedFileCallback -->
<!-- <div>files.length: {{ files.length }}</div> -->
<!-- <div>uploadedFiles.length: {{ uploadedFiles.length }}</div> -->
<!-- <div>uploadedFileCount: {{ fileUploadRef?.uploadedFileCount }}</div> -->
<Message
size="small"
v-for="msg of messages"
@ -164,6 +163,10 @@ const disabled = computed(() => {
<ProgressBar v-if="file.status === 'uploading'" :value="file.progress" />
</div>
</template>
<div>files.length: {{ files.length }}</div>
<div>uploadedFiles.length: {{ uploadedFiles.length }}</div>
<div>uploadedFileCount: {{ fileUploadRef?.uploadedFileCount }}</div>
</template>
</FileUpload>
</template>