Browse Source

单文件上传优化

wangwei 3 years ago
parent
commit
8bf1ab6dab

+ 6 - 1
src/components/Upload/src/BasicUpload.vue

@@ -89,7 +89,12 @@
 
       // 上传modal保存操作
       function handleChange(urls: string[]) {
-        fileList.value = [...unref(fileList), ...(urls || [])];
+        // 如果最大限制上传为1, 只获取最新上传的一个文件。。。
+        if (props.maxNumber === 1) {
+          fileList.value = [...(urls || [])];
+        } else {
+          fileList.value = [...unref(fileList), ...(urls || [])];
+        }
         emit('update:value', fileList.value);
         emit('change', fileList.value);
       }

+ 2 - 2
src/components/Upload/src/UploadModal.vue

@@ -212,7 +212,8 @@
       // 点击开始上传
       async function handleStartUpload() {
         const { maxNumber } = props;
-        if ((fileListRef.value.length + props.previewFileList?.length ?? 0) > maxNumber) {
+        // if ((fileListRef.value.length + props.previewFileList?.length ?? 0) > maxNumber) { 下面做了修改
+        if ((fileListRef.value.length ?? 0) > maxNumber) {
           return createMessage.warning(t('component.upload.maxNumber', [maxNumber]));
         }
         try {
@@ -250,7 +251,6 @@
         for (const item of fileListRef.value) {
           const { status, responseData } = item;
           if (status === UploadResultStatus.SUCCESS && responseData) {
-            console.log(`responseData`, responseData);
             fileList.push(responseData.result.url);
           }
         }