From 45038f548ec20a28a4a1113eef531217fa843158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Fri, 31 Jan 2020 10:23:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(Uploader):=20max-size=E3=80=81max-count=20?= =?UTF-8?q?can=20be=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/uploader/README.md | 4 ++-- src/uploader/README.zh-CN.md | 8 ++++---- src/uploader/index.js | 4 ++-- src/uploader/utils.ts | 5 ++++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/uploader/README.md b/src/uploader/README.md index 8c1f81f47..06bc39b8a 100644 --- a/src/uploader/README.md +++ b/src/uploader/README.md @@ -123,8 +123,8 @@ export default { | after-read | Hook after reading the file | *Function* | - | | before-read | Hook before reading the file, return false to stop reading the file, can return Promise | *Function* | - | | before-delete | Hook before delete the file, return false to stop reading the file, can return Promise | *Function* | - | -| max-size | Max size of file | *number* | - | -| max-count | Max count of image | *number* | - | +| max-size | Max size of file | *number \| string* | - | +| max-count | Max count of image | *number \| string* | - | | result-type `v2.2.7` | Type of file read result, can be set to `file` `text` | *string* | `dataUrl` | | upload-text | Upload text | *string* | - | | image-fit `v2.1.5` | Preview image fit mode | *string* | `cover` | diff --git a/src/uploader/README.zh-CN.md b/src/uploader/README.zh-CN.md index 2b294946b..5a8f542cc 100644 --- a/src/uploader/README.zh-CN.md +++ b/src/uploader/README.zh-CN.md @@ -137,10 +137,10 @@ export default { | deletable `v2.2.12` | 是否展示删除按钮 | *boolean* | `true` | | capture | 图片选取模式,可选值为`camera`(直接调起摄像头) | *string* | - | | after-read | 文件读取完成后的回调函数 | *Function* | - | -| before-read | 文件读取前的回调函数,返回`false`可终止文件读取,支持返回`Promise` | *Function* | - | -| before-delete | 文件删除前的回调函数,返回`false`可终止文件读取,支持返回`Promise` | *Function* | - | -| max-size | 文件大小限制,单位为`byte` | *number* | - | -| max-count | 文件上传数量限制 | *number* | - | +| before-read | 文件读取前的回调函数,返回`false`可终止文件读取,
支持返回`Promise` | *Function* | - | +| before-delete | 文件删除前的回调函数,返回`false`可终止文件读取,
支持返回`Promise` | *Function* | - | +| max-size | 文件大小限制,单位为`byte` | *number \| string* | - | +| max-count | 文件上传数量限制 | *number \| string* | - | | result-type `v2.2.7` | 文件读取结果类型,可选值为`file` `text` | *string* | `dataUrl` | | upload-text | 上传区域文字提示 | *string* | - | | image-fit `v2.1.5` | 预览图裁剪模式,可选值见 [Image](#/zh-CN/image) 组件 | *string* | `cover` | diff --git a/src/uploader/index.js b/src/uploader/index.js index 1e83d6fef..8d965cab3 100644 --- a/src/uploader/index.js +++ b/src/uploader/index.js @@ -36,11 +36,11 @@ export default createComponent({ default: () => [], }, maxSize: { - type: Number, + type: [Number, String], default: Number.MAX_VALUE, }, maxCount: { - type: Number, + type: [Number, String], default: Number.MAX_VALUE, }, deletable: { diff --git a/src/uploader/utils.ts b/src/uploader/utils.ts index 2ce4778eb..03028ca1c 100644 --- a/src/uploader/utils.ts +++ b/src/uploader/utils.ts @@ -29,7 +29,10 @@ export function readFile(file: File, resultType: ResultType) { }); } -export function isOversize(files: File | File[], maxSize: number): boolean { +export function isOversize( + files: File | File[], + maxSize: number | string +): boolean { return toArray(files).some(file => file.size > maxSize); }