-
+`;
+
+exports[`renders ./components/upload/demo/fileList.vue correctly 1`] = `
+
+
+`;
+
+exports[`renders ./components/upload/demo/max-count.vue correctly 1`] = `
+
+`;
+
+exports[`renders ./components/upload/demo/picture-card.vue correctly 1`] = `
+
`;
exports[`renders ./components/upload/demo/picture-style.vue correctly 1`] = `
-
`;
exports[`renders ./components/upload/demo/preview-file.vue correctly 1`] = `
-
+
`;
exports[`renders ./components/upload/demo/transform-file.vue correctly 1`] = `
-
+
+`;
+
+exports[`renders ./components/upload/demo/upload-custom-action-icon.vue correctly 1`] = `
+
+
+`;
+
+exports[`renders ./components/upload/demo/upload-png-only.vue correctly 1`] = `
+
+
`;
diff --git a/components/upload/__tests__/__snapshots__/uploadlist.test.js.snap b/components/upload/__tests__/__snapshots__/uploadlist.test.js.snap
index 9ec7b50d1..5a2aa53b8 100644
--- a/components/upload/__tests__/__snapshots__/uploadlist.test.js.snap
+++ b/components/upload/__tests__/__snapshots__/uploadlist.test.js.snap
@@ -35,41 +35,71 @@ exports[`Upload List handle error 2`] = `
exports[`Upload List should be uploading when upload a file 1`] = `
upload
`;
exports[`Upload List should non-image format file preview 1`] = `
-
-
-
-
-
-
-
-
-
+
upload
+
`;
diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js
index e82a8907e..d6e9da8ea 100644
--- a/components/upload/__tests__/upload.test.js
+++ b/components/upload/__tests__/upload.test.js
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import Upload from '..';
-import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from '../utils';
+import { getFileItem, removeFileItem } from '../utils';
import PropsTypes from '../../_util/vue-types';
import { uploadListProps } from '../interface';
import { setup, teardown } from './mock';
@@ -199,36 +199,6 @@ describe('Upload', () => {
});
describe('util', () => {
- // https://github.com/react-component/upload/issues/36
- it('should T() return true', () => {
- const res = T();
- expect(res).toBe(true);
- });
- it('should be able to copy file instance', () => {
- const file = new File([], 'aaa.zip');
- const copiedFile = fileToObject(file);
- ['uid', 'lastModified', 'lastModifiedDate', 'name', 'size', 'type'].forEach(key => {
- expect(key in copiedFile).toBe(true);
- });
- });
- it('should be able to progress from 0.1 ', () => {
- // 0.1 -> 0.98
- const getPercent = genPercentAdd();
- let curPercent = 0;
- curPercent = getPercent(curPercent);
- expect(curPercent).toBe(0.1);
- });
-
- it('should be able to progress to 0.98 ', () => {
- // 0.1 -> 0.98
- const getPercent = genPercentAdd();
- let curPercent = 0;
- for (let i = 0; i < 500; i += 1) {
- curPercent = getPercent(curPercent);
- }
- expect(parseFloat(curPercent.toFixed(2))).toBe(0.98);
- });
-
it('should be able to get fileItem', () => {
const file = { uid: '-1', name: 'item.jpg' };
const fileList = [
diff --git a/components/upload/__tests__/uploadlist.test.js b/components/upload/__tests__/uploadlist.test.js
index 6fe88fca9..52cd2fff1 100644
--- a/components/upload/__tests__/uploadlist.test.js
+++ b/components/upload/__tests__/uploadlist.test.js
@@ -300,7 +300,7 @@ describe('Upload List', () => {
defaultFileList: fileList,
listType: 'picture-card',
action: '',
- remove: handleRemove,
+ onRemove: handleRemove,
onChange: handleChange,
},
diff --git a/components/upload/demo/avatar.vue b/components/upload/demo/avatar.vue
index cd68f1a22..66e14fc15 100644
--- a/components/upload/demo/avatar.vue
+++ b/components/upload/demo/avatar.vue
@@ -10,7 +10,7 @@ title:
点击上传用户头像,并使用 `beforeUpload` 限制用户上传的图片格式和大小。
-> `beforeUpload` 的返回值可以是一个 Promise 以支持异步处理,如服务端校验等:[示例](http://react-component.github.io/upload/examples/beforeUpload.html)。
+> `beforeUpload` 的返回值可以是一个 Promise 以支持异步处理,如服务端校验等:可参考react版本[示例](http://react-component.github.io/upload/examples/beforeUpload.html)。
## en-US
diff --git a/components/upload/demo/custom-render.vue b/components/upload/demo/custom-render.vue
new file mode 100644
index 000000000..0a77bf336
--- /dev/null
+++ b/components/upload/demo/custom-render.vue
@@ -0,0 +1,93 @@
+
+---
+order: 0
+title:
+ zh-CN: 自定义上传列表
+ en-US: Custom Render
+---
+
+## zh-CN
+
+使用 `itemRender` 插槽进行完全自定义列表
+
+## en-US
+
+Custom render by using `itemRender` slot.
+
+
+
+
+
+
+ Click to Upload
+
+
+
+ {{ file.name }}
+ download
+ delete
+
+
+
+
+
diff --git a/components/upload old/demo/basic.vue b/components/upload/demo/customize-progress-bar.vue
similarity index 69%
rename from components/upload old/demo/basic.vue
rename to components/upload/demo/customize-progress-bar.vue
index 3c9862438..c3afe5dbe 100644
--- a/components/upload old/demo/basic.vue
+++ b/components/upload/demo/customize-progress-bar.vue
@@ -1,27 +1,28 @@
---
-order: 0
+order: 15
title:
- zh-CN: 点击上传
- en-US: Upload by clicking
+ zh-CN: 自定义进度条样式
+ en-US: Customize Progress Bar
---
## zh-CN
-经典款式,用户点击按钮弹出文件选择框。
+使用 `progress` 属性自定义进度条样式。
## en-US
-Classic mode. File selection dialog pops up when upload button is clicked.
+Use `progress` for customize progress bar.
+
@@ -34,7 +35,7 @@ Classic mode. File selection dialog pops up when upload button is clicked.
import { message } from 'ant-design-vue';
import { UploadOutlined } from '@ant-design/icons-vue';
import { defineComponent, ref } from 'vue';
-import type { UploadChangeParam } from 'ant-design-vue';
+import type { UploadChangeParam, UploadProps } from 'ant-design-vue';
export default defineComponent({
components: {
@@ -53,12 +54,22 @@ export default defineComponent({
};
const fileList = ref([]);
+ const progress: UploadProps['progress'] = {
+ strokeColor: {
+ '0%': '#108ee9',
+ '100%': '#87d068',
+ },
+ strokeWidth: 3,
+ format: percent => `${parseFloat(percent.toFixed(2))}%`,
+ class: 'test',
+ };
return {
fileList,
headers: {
authorization: 'authorization-text',
},
handleChange,
+ progress,
};
},
});
diff --git a/components/upload/demo/defaultFileList.vue b/components/upload/demo/defaultFileList.vue
index 0cb1fab90..c37bc7de0 100644
--- a/components/upload/demo/defaultFileList.vue
+++ b/components/upload/demo/defaultFileList.vue
@@ -8,11 +8,11 @@ title:
## zh-CN
-使用 `defaultFileList` 设置已上传的内容。
+使用 `fileList` 设置已上传的内容。
## en-US
-Use `defaultFileList` for uploaded files when page init.
+Use `fileList` for uploaded files when page init.
diff --git a/components/upload/demo/drag.vue b/components/upload/demo/drag.vue
index 6bf30241a..8fe4543ba 100644
--- a/components/upload/demo/drag.vue
+++ b/components/upload/demo/drag.vue
@@ -10,13 +10,13 @@ title:
把文件拖入指定区域,完成上传,同样支持点击上传。
-设置 `multiple` 后,在 `IE10+` 可以一次上传多个文件。
+设置 `multiple` 后,可以一次上传多个文件。
## en-US
You can drag files to a specific area, to upload. Alternatively, you can also upload by selecting.
-We can upload serveral files at once in modern browsers by giving the input the `multiple` attribute.
+We can upload serveral files at once by giving the input the `multiple` attribute.
@@ -26,6 +26,7 @@ We can upload serveral files at once in modern browsers by giving the input the
:multiple="true"
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
@change="handleChange"
+ @drop="handleDrop"
>
@@ -62,6 +63,9 @@ export default defineComponent({
return {
handleChange,
fileList: ref([]),
+ handleDrop: (e: DragEvent) => {
+ console.log(e);
+ },
};
},
});
diff --git a/components/upload/demo/index.vue b/components/upload/demo/index.vue
index b1ae4e92e..8796c28b1 100644
--- a/components/upload/demo/index.vue
+++ b/components/upload/demo/index.vue
@@ -11,6 +11,11 @@
+
+
+
+
+
diff --git a/components/upload/demo/picture-style.vue b/components/upload/demo/picture-style.vue
index 1782f0e75..0ba3bca06 100644
--- a/components/upload/demo/picture-style.vue
+++ b/components/upload/demo/picture-style.vue
@@ -8,11 +8,11 @@ title:
## zh-CN
-上传文件为图片,可展示本地缩略图。`IE8/9` 不支持浏览器本地缩略图展示([Ref](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL)),可以写 `thumbUrl` 属性来代替。
+上传文件为图片,可展示本地缩略图。
## en-US
-If uploaded file is a picture, the thumbnail can be shown. `IE8/9` do not support local thumbnail show. Please use `thumbUrl` instead.
+If uploaded file is a picture, the thumbnail can be shown.
diff --git a/components/upload/demo/preview-file.vue b/components/upload/demo/preview-file.vue
index 9f2ceb2fb..0907c6f53 100644
--- a/components/upload/demo/preview-file.vue
+++ b/components/upload/demo/preview-file.vue
@@ -33,13 +33,14 @@ Customize local preview. Can handle with non-image format files such as video.
diff --git a/components/upload/index.en-US.md b/components/upload/index.en-US.md
index 84500cf84..f73639458 100644
--- a/components/upload/index.en-US.md
+++ b/components/upload/index.en-US.md
@@ -18,12 +18,12 @@ Uploading is the process of publishing information (web pages, text, pictures, v
## API
| Property | Description | Type | Default | Version |
-| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
+| --- | --- | --- | --- | --- | --- |
| accept | File types that can be accepted. See [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) | string | - | |
| action | Uploading URL | string\|(file) => `Promise` | - | |
| method | http method of upload request | string | `post` | 1.5.0 |
| directory | support upload whole directory ([caniuse](https://caniuse.com/#feat=input-file-directory)) | boolean | false | |
-| beforeUpload | Hook function which will be executed before uploading. Uploading will be stopped with `false` or a rejected Promise returned. **Warning:this function is not supported in IE9**。 | (file, fileList) => `boolean | Promise` | - | |
+| beforeUpload | Hook function which will be executed before uploading. Uploading will be stopped with `false` or a rejected Promise returned. | (file, fileList) => `boolean | Promise` | - | |
| customRequest | override for the default xhr behavior allowing for additional customization and ability to implement your own XMLHttpRequest | Function | - | |
| data | Uploading params or function which can return uploading params. | object\|function(file) | - | |
| disabled | disable upload button | boolean | false | |
@@ -33,12 +33,20 @@ Uploading is the process of publishing information (web pages, text, pictures, v
| multiple | Whether to support selected multiple file. `IE10+` supported. You can select multiple files with CTRL holding down while multiple is set to be true | boolean | false | |
| name | The name of uploading file | string | `file` | |
| previewFile | Customize preview file logic | (file: File \| Blob) => Promise | - | 1.5.0 |
-| showUploadList | Whether to show default upload list, could be an object to specify `showPreviewIcon` and `showRemoveIcon` individually | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean } | true | |
+| showUploadList | Whether to show default upload list, could be an object to specify `showPreviewIcon` and `showRemoveIcon` individually | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: booleanshowDownloadIcon?: boolean } | true | showDownloadIcon(3.0) |
| supportServerRender | Need to be turned on while the server side is rendering. | boolean | false | |
| withCredentials | ajax upload with cookie sent | boolean | false | |
| openFileDialogOnClick | click open file dialog | boolean | true | |
-| remove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when return value is `false` or a Promise which resolve(false) or reject. | Function(file): `boolean | Promise` | - | |
-| transformFile | Customize transform file before request | Function(file): `string | Blob | File | Promise` | - | 1.5.0 |
+| directory | Support upload whole directory([caniuse](https://caniuse.com/#feat=input-file-directory)) | boolean | false | 3.0 |
+| iconRender | Custom show icon | v-slot:iconRender="{file: UploadFile, listType?: UploadListType}" | - | 3.0 |
+| isImageUrl | Customize if render <img /> in thumbnail | (file: UploadFile) => boolean | - | 3.0 |
+| itemRender | Custom item of uploadList | v-slot:itemRender="{originNode: ReactElement, file: UploadFile, fileList: object\[], actions: { download: function, preview: function, remove: function }" | - | 3.0 |
+| maxCount | Limit the number of uploaded files. Will replace current one when `maxCount` is `1` | number | - | 3.0 |
+| openFileDialogOnClick | Click open file dialog | boolean | true | 3.0 |
+| progress | Custom progress bar | [ProgressProps](/components/progress/#API) (support `type="line"` only) | { strokeWidth: 2, showInfo: false } | 3.0 |
+| previewIcon | custom preview icon | v-slot:iconRender="{file: UploadFile}" | - | 3.0 |
+| removeIcon | custom remove icon | v-slot:iconRender="{file: UploadFile}" | - | 3.0 |
+| downloadIcon | custom download icon | v-slot:iconRender="{file: UploadFile}" | - | 3.0 |
### events
@@ -48,6 +56,21 @@ Uploading is the process of publishing information (web pages, text, pictures, v
| preview | A callback function, will be executed when file link or preview icon is clicked. | Function(file) | - | |
| download | Click the method to download the file, pass the method to perform the method logic, do not pass the default jump to the new TAB. | Function(file): void | Jump to new TAB | 1.5.0 |
| reject | A callback function, will be executed when drop files is not accept. | Function(fileList) | - | |
+| drop | A callback function executed when files are dragged and dropped into upload area | (event: DragEvent) => void | - | 3.0 |
+| remove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when return value is false or a Promise which resolve(false) or reject | function(file): boolean \| Promise | - | 3.0 |
+
+### UploadFile
+
+Extends File with additional props.
+
+| Property | Description | Type | Default |
+| --- | --- | --- | --- |
+| name | File name | string | - |
+| percent | Upload progress percent | number | - |
+| status | Upload status. Show different style when configured | `error` \| `success` \| `done` \| `uploading` \| `removed` | - |
+| thumbUrl | Thumb image url | string | - |
+| uid | unique id. Will auto generate when not provided | string | - |
+| url | Download url | string | - |
### change
@@ -78,3 +101,26 @@ When uploading state change, it returns:
2. `fileList` current list of files
3. `event` response from server, including uploading progress, supported by advanced browsers.
+
+## FAQ
+
+### How to implement upload server side?
+
+- You can consult [jQuery-File-Upload](https://github.com/blueimp/jQuery-File-Upload/wiki#server-side) about how to implement server side upload interface.
+- There is a mock example of [express](https://github.com/react-component/upload/blob/master/server.js) in rc-upload.
+
+### I want to display download links.
+
+Please set property `url` of each item in `fileList` to control content of link.
+
+### How to use `customRequest`?
+
+See .
+
+### Why `fileList` in control will not trigger `change` `status` update when file not in the list?
+
+`change` only trigger when file in the list, it will ignore left events when removed from the list. Please note that there exist bug which makes event still trigger even the file is not in the list before `3.0.0-beta.10`.
+
+### Why sometime `change` return File object and sometime return { originFileObj: File }?
+
+For compatible case, we return File object when `beforeUpload` return `false`. It will merge to `{ originFileObj: File }` in next major version. Current version is compatible to get origin file by `info.file.originFileObj`. You can change this before major release.
diff --git a/components/upload/index.zh-CN.md b/components/upload/index.zh-CN.md
index 73db3ef2c..8abd3c853 100644
--- a/components/upload/index.zh-CN.md
+++ b/components/upload/index.zh-CN.md
@@ -19,12 +19,12 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
## API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
-| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
+| --- | --- | --- | --- | --- | --- |
| accept | 接受上传的文件类型, 详见 [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) | string | 无 | |
| action | 上传的地址 | string\|(file) => `Promise` | 无 | |
| method | 上传请求的 http method | string | `post` | 1.5.0 |
| directory | 支持上传文件夹([caniuse](https://caniuse.com/#feat=input-file-directory)) | boolean | false | |
-| beforeUpload | 上传文件之前的钩子,参数为上传的文件,若返回 `false` 则停止上传。支持返回一个 Promise 对象,Promise 对象 reject 时则停止上传,resolve 时开始上传( resolve 传入 `File` 或 `Blob` 对象则上传 resolve 传入对象)。**注意:IE9 不支持该方法**。 | (file, fileList) => `boolean | Promise` | 无 | |
+| beforeUpload | 上传文件之前的钩子,参数为上传的文件,若返回 `false` 则停止上传。支持返回一个 Promise 对象,Promise 对象 reject 时则停止上传,resolve 时开始上传( resolve 传入 `File` 或 `Blob` 对象则上传 resolve 传入对象)。 | (file, fileList) => `boolean | Promise` | 无 | |
| customRequest | 通过覆盖默认的上传行为,可以自定义自己的上传实现 | Function | 无 | |
| data | 上传所需参数或返回上传参数的方法 | object\|(file) => object | 无 | |
| disabled | 是否禁用 | boolean | false | |
@@ -34,12 +34,20 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
| multiple | 是否支持多选文件,`ie10+` 支持。开启后按住 ctrl 可选择多个文件。 | boolean | false | |
| name | 发到后台的文件参数名 | string | `file` | |
| previewFile | 自定义文件预览逻辑 | (file: File \| Blob) => Promise | 无 | 1.5.0 |
-| showUploadList | 是否展示 uploadList, 可设为一个对象,用于单独设定 showPreviewIcon 和 showRemoveIcon | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean } | true | |
+| showUploadList | 是否展示 uploadList, 可设为一个对象,用于单独设定 showPreviewIcon 和 showRemoveIcon | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean, showDownloadIcon?: boolean } | true | showDownloadIcon(3.0) |
| supportServerRender | 服务端渲染时需要打开这个 | boolean | false | |
| withCredentials | 上传请求时是否携带 cookie | boolean | false | |
| openFileDialogOnClick | 点击打开文件对话框 | boolean | true | |
-| remove | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除。 | Function(file): `boolean | Promise` | 无 | |
-| transformFile | 在上传之前转换文件。支持返回一个 Promise 对象 | Function(file): `string | Blob | File | Promise` | 无 | 1.5.0 |
+| directory | 支持上传文件夹([caniuse](https://caniuse.com/#feat=input-file-directory)) | boolean | false | 3.0 |
+| iconRender | 自定义显示 icon | v-slot:iconRender="{file: UploadFile, listType?: UploadListType}" | - | 3.0 |
+| isImageUrl | 自定义缩略图是否使用 <img /> 标签进行显示 | (file: UploadFile) => boolean | - | 3.0 |
+| itemRender | 自定义上传列表项 | v-slot:itemRender="{originNode: ReactElement, file: UploadFile, fileList: object\[], actions: { download: function, preview: function, remove: function }" | - | 3.0 |
+| maxCount | 限制上传数量。当为 1 时,始终用最新上传的文件代替当前文件 | number | - | 3.0 |
+| openFileDialogOnClick | 点击打开文件对话框 | boolean | true | 3.0 |
+| progress | 自定义进度条样式 | [ProgressProps](/components/progress/#API)(仅支持 `type="line"`) | { strokeWidth: 2, showInfo: false } | 3.0 |
+| previewIcon | 自定义预览 icon | v-slot:iconRender="{file: UploadFile}" | - | 3.0 |
+| removeIcon | 自定义删除 icon | v-slot:iconRender="{file: UploadFile}" | - | 3.0 |
+| downloadIcon | 自定义下载 icon | v-slot:iconRender="{file: UploadFile}" | - | 3.0 |
### 事件
@@ -49,6 +57,21 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
| preview | 点击文件链接或预览图标时的回调 | Function(file) | 无 | |
| download | 点击下载文件时的回调,如果没有指定,则默认跳转到文件 url 对应的标签页。 | Function(file): void | 跳转新标签页 | 1.5.0 |
| reject | 拖拽文件不符合 accept 类型时的回调 | Function(fileList) | 无 | |
+| drop | 当文件被拖入上传区域时执行的回调功能 | (event: DragEvent) => void | - | 3.0 |
+| remove | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除 | function(file): boolean \| Promise | - | 3.0 |
+
+### UploadFile
+
+继承自 File,附带额外属性用于渲染。
+
+| 参数 | 说明 | 类型 | 默认值 |
+| --- | --- | --- | --- |
+| name | 文件名 | string | - |
+| percent | 上传进度 | number | - |
+| status | 上传状态,不同状态展示颜色也会有所不同 | `error` \| `success` \| `done` \| `uploading` \| `removed` | - |
+| thumbUrl | 缩略图地址 | string | - |
+| uid | 唯一标识符,不设置时会自动生成 | string | - |
+| url | 下载地址 | string | - |
### change
@@ -79,3 +102,26 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
2. `fileList` 当前的文件列表。
3. `event` 上传中的服务端响应内容,包含了上传进度等信息,高级浏览器支持。
+
+## FAQ
+
+### 服务端如何实现?
+
+- 服务端上传接口实现可以参考 [jQuery-File-Upload](https://github.com/blueimp/jQuery-File-Upload/wiki#server-side)。
+- 如果要做本地 mock 可以参考这个 [express 的例子](https://github.com/react-component/upload/blob/master/server.js)。
+
+### 如何显示下载链接?
+
+请使用 fileList 属性设置数组项的 url 属性进行展示控制。
+
+### `customRequest` 怎么使用?
+
+请参考 。
+
+### 为何 `fileList` 受控时,上传不在列表中的文件不会触发 `onChange` 后续的 `status` 更新事件?
+
+`onChange` 事件仅会作用于在列表中的文件,因而 `fileList` 不存在对应文件时后续事件会被忽略。请注意,在 `3.0.0-beta.10` 版本之前受控状态存在 bug 导致不在列表中的文件也会触发。
+
+### `onChange` 为什么有时候返回 File 有时候返回 { originFileObj: File }?
+
+历史原因,在 `beforeUpload` 返回 `false` 时,会返回 File 对象。在下个大版本我们会统一返回 `{ originFileObj: File }` 对象。当前版本已经兼容所有场景下 `info.file.originFileObj` 获取原 File 写法。你可以提前切换。
diff --git a/components/upload/interface.tsx b/components/upload/interface.tsx
index 9bcc77040..b7898c31d 100755
--- a/components/upload/interface.tsx
+++ b/components/upload/interface.tsx
@@ -4,9 +4,9 @@ import type {
} from '../vc-upload/interface';
import type { ProgressProps } from '../progress';
import type { VueNode } from '../_util/type';
-import type { ExtractPropTypes, PropType } from 'vue';
+import type { ExtractPropTypes, PropType, CSSProperties } from 'vue';
-export interface RcFile extends OriRcFile {
+export interface FileType extends OriRcFile {
readonly lastModifiedDate: Date;
}
@@ -27,7 +27,7 @@ export interface UploadFile {
status?: UploadFileStatus;
percent?: number;
thumbUrl?: string;
- originFileObj?: RcFile;
+ originFileObj?: FileType;
response?: T;
error?: any;
linkProps?: any;
@@ -37,7 +37,7 @@ export interface UploadFile {
}
export interface InternalUploadFile extends UploadFile {
- originFileObj: RcFile;
+ originFileObj: FileType;
}
export interface ShowUploadListInterface {
@@ -63,7 +63,10 @@ export interface UploadLocale {
export type UploadType = 'drag' | 'select';
export type UploadListType = 'text' | 'picture' | 'picture-card';
-export type UploadListProgressProps = Omit;
+export type UploadListProgressProps = Omit & {
+ class?: string;
+ style?: CSSProperties;
+};
export type ItemRender = (opt: {
originNode: VueNode;
@@ -76,11 +79,11 @@ export type ItemRender = (opt: {
};
}) => VueNode;
-type PreviewFileHandler = (file: File | Blob) => PromiseLike;
+type PreviewFileHandler = (file: FileType | Blob) => PromiseLike;
type TransformFileHandler = (
- file: RcFile,
-) => string | Blob | File | PromiseLike;
-type BeforeUploadValueType = void | boolean | string | Blob | File;
+ file: FileType,
+) => string | Blob | FileType | PromiseLike;
+type BeforeUploadValueType = void | boolean | string | Blob | FileType;
function uploadProps() {
return {
@@ -90,7 +93,7 @@ function uploadProps() {
defaultFileList: Array as PropType>>,
fileList: Array as PropType>>,
action: [String, Function] as PropType<
- string | ((file: RcFile) => string) | ((file: RcFile) => PromiseLike)
+ string | ((file: FileType) => string) | ((file: FileType) => PromiseLike)
>,
directory: { type: Boolean, default: undefined },
data: [Object, Function] as PropType<
@@ -106,7 +109,10 @@ function uploadProps() {
multiple: { type: Boolean, default: undefined },
accept: String,
beforeUpload: Function as PropType<
- (file: RcFile, FileList: RcFile[]) => BeforeUploadValueType | Promise
+ (
+ file: FileType,
+ FileList: FileType[],
+ ) => BeforeUploadValueType | Promise
>,
onChange: Function as PropType<(info: UploadChangeParam) => void>,
'onUpdate:fileList': Function as PropType<(fileList: UploadChangeParam['fileList']) => void>,
@@ -114,9 +120,12 @@ function uploadProps() {
listType: String as PropType,
onPreview: Function as PropType<(file: UploadFile) => void>,
onDownload: Function as PropType<(file: UploadFile) => void>,
+ onReject: Function as PropType<(fileList: FileType[]) => void>,
onRemove: Function as PropType<
(file: UploadFile) => void | boolean | Promise
>,
+ /** @deprecated Please use `onRemove` directly */
+ remove: Function as PropType<(file: UploadFile) => void | boolean | Promise>,
supportServerRender: { type: Boolean, default: undefined },
disabled: { type: Boolean, default: undefined },
prefixCls: String,
diff --git a/components/upload/utils.tsx b/components/upload/utils.tsx
index 3f605723a..8e18d5f7a 100644
--- a/components/upload/utils.tsx
+++ b/components/upload/utils.tsx
@@ -1,6 +1,6 @@
-import type { RcFile, UploadFile, InternalUploadFile } from './interface';
+import type { FileType, UploadFile, InternalUploadFile } from './interface';
-export function file2Obj(file: RcFile): InternalUploadFile {
+export function file2Obj(file: FileType): InternalUploadFile {
return {
...file,
lastModified: file.lastModified,
@@ -26,7 +26,7 @@ export function updateFileList(file: UploadFile, fileList: UploadFile[
return nextFileList;
}
-export function getFileItem(file: RcFile, fileList: UploadFile[]) {
+export function getFileItem(file: FileType, fileList: UploadFile[]) {
const matchKey = file.uid !== undefined ? 'uid' : 'name';
return fileList.filter(item => item[matchKey] === file[matchKey])[0];
}
diff --git a/components/vc-upload/AjaxUploader.tsx b/components/vc-upload/AjaxUploader.tsx
index f97cad70f..bb5c1d3f9 100644
--- a/components/vc-upload/AjaxUploader.tsx
+++ b/components/vc-upload/AjaxUploader.tsx
@@ -12,6 +12,7 @@ import { uploadProps } from './interface';
import { defineComponent, onBeforeUnmount, onMounted, ref } from 'vue';
import type { ChangeEvent } from '../_util/EventInterface';
import pickAttrs from '../_util/pickAttrs';
+import partition from 'lodash-es/partition';
interface ParsedFileInfo {
origin: RcFile;
@@ -240,15 +241,18 @@ export default defineComponent({
(_file: RcFile) => attrAccept(_file, props.accept),
);
} else {
- let files = [...e.dataTransfer.files].filter((file: RcFile) =>
- attrAccept(file, props.accept),
+ const files: [RcFile[], RcFile[]] = partition(
+ Array.prototype.slice.call(e.dataTransfer.files),
+ (file: RcFile) => attrAccept(file, props.accept),
);
-
+ let successFiles = files[0];
+ const errorFiles = files[1];
if (multiple === false) {
- files = files.slice(0, 1);
+ successFiles = successFiles.slice(0, 1);
}
- uploadFiles(files);
+ uploadFiles(successFiles);
+ if (errorFiles.length && props.onReject) props.onReject(errorFiles);
}
};
expose({
diff --git a/components/vc-upload/interface.tsx b/components/vc-upload/interface.tsx
index 16389d50e..46609a482 100644
--- a/components/vc-upload/interface.tsx
+++ b/components/vc-upload/interface.tsx
@@ -23,6 +23,7 @@ export const uploadProps = () => {
onBatchStart: Function as PropType<
(fileList: { file: RcFile; parsedFile: Exclude }[]) => void
>,
+ onReject: Function as PropType<(fileList: RcFile[]) => void>,
onStart: Function as PropType<(file: RcFile) => void>,
onError: Function as PropType<
(error: Error, ret: Record, file: RcFile) => void
diff --git a/package.json b/package.json
index 373cc3e3e..ef2585da0 100644
--- a/package.json
+++ b/package.json
@@ -222,7 +222,6 @@
"vue-antd-md-loader": "^1.2.1-beta.1",
"vue-clipboard2": "0.3.3",
"vue-drag-resize": "^2.0.3",
- "vue-draggable-resizable": "^2.1.0",
"vue-eslint-parser": "^8.0.0",
"vue-i18n": "^9.1.7",
"vue-infinite-scroll": "^2.0.2",