ant-design-vue icon indicating copy to clipboard operation
ant-design-vue copied to clipboard

The upload control settings limit the number of uploaded files, but after multiple selection, the files that exceed the limit will still request the api to upload, although it is not displayed on the page

Open WormGirl opened this issue 2 years ago • 6 comments

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.

Version

3.2.3

Environment

not need

Reproduction link

https://www.github.com

Steps to reproduce

官方upload 限制文件个数那个demo就能复现

What is expected?

超出后的文件拦截下来 不要请求接口上传

What is actually happening?

超出后的文件依然请求接口上传了 只是页面上没显示

WormGirl avatar May 12 '22 06:05 WormGirl

有办法限制超出后的文件不要上传么 现在超出的文件也会请求接口上传 这是不正常的, 官方文档里的demo能复现这个问题

WormGirl avatar May 12 '22 06:05 WormGirl

需要自己处理 感觉可以内置处理下

   const leftCount = computed(() => attrs.maxCount as number - fileList.value.length);
    
    // 上传之前校验
    const beforeUpload = (file: FileList[number], files: FileList) => {
      // 校验文件数是否超出,超出部分直接丢弃
      const index = files.findIndex(elem => elem === file);
      if (index >= leftCount.value) {
        return false
      }
      const size = file.size || 0;
      if (!unref(accept).includes(file.type || '')) {
        message.error(
          t('page.upload_img_tip_type', {
            name: file.name
          })
        );
        return CUpload.LIST_IGNORE;
      }
      // 文件大小校验
      const maxSize: number = (attrs.maxSize as number) || 200;
      if (size > maxSize * UNIT) {
        message.error(
          t('page.upload_img_tip_size', {
            size: (size / 1024).toFixed(0),
            maxSize
          })
        );
        return CUpload.LIST_IGNORE;
      }
      return true;
    };

WormGirl avatar May 12 '22 06:05 WormGirl

CUpload.LIST_IGNORE 这个怎么来的

PoliWen avatar Jul 03 '22 13:07 PoliWen

import { message, Upload } from 'ant-design-vue'

CUpload.LIST_IGNORE 应该是Upload.LIST_IGNORE吧

PoliWen avatar Jul 03 '22 15:07 PoliWen

import { message, Upload } from 'ant-design-vue'

CUpload.LIST_IGNORE 应该是Upload.LIST_IGNORE吧

yes

WormGirl avatar Aug 08 '22 05:08 WormGirl

这是来自QQ邮箱的假期自动回复邮件。   您好,邮件已收到。记得常联系哦

PoliWen avatar Aug 08 '22 05:08 PoliWen

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Oct 08 '22 03:10 github-actions[bot]

这是来自QQ邮箱的假期自动回复邮件。   您好,邮件已收到。记得常联系哦

PoliWen avatar Oct 08 '22 03:10 PoliWen

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Dec 09 '22 02:12 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 18 '23 00:12 github-actions[bot]