Skip to content

Commit

Permalink
feat(Upload): support preview props
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao committed Nov 19, 2024
1 parent d70ff31 commit 2c7dfcc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/upload/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export default {
type: String,
default: 'file',
},
/** 是否支持图片预览,文件没有预览 */
preview: {
type: Boolean,
default: true,
},
/** 自定义上传方法。返回值 `status` 表示上传成功或失败;`error` 或 `response.error` 表示上传失败的原因;<br/>`response` 表示请求上传成功后的返回数据,`response.url` 表示上传成功后的图片/文件地址,`response.files` 表示一个请求上传多个文件/图片后的返回值。<br/>示例一:`{ status: 'fail', error: '上传失败', response }`。<br/>示例二:`{ status: 'success', response: { url: 'https://tdesign.gtimg.com/site/avatar.jpg' } }`。<br/> 示例三:`{ status: 'success', files: [{ url: 'https://xxx.png', name: 'xxx.png' }]}` */
requestMethod: {
type: Function as PropType<TdUploadProps['requestMethod']>,
Expand Down
5 changes: 5 additions & 0 deletions src/upload/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ export interface TdUploadProps<T extends UploadFile = UploadFile> {
*/
mockProgressDuration?: number;
multiple?: boolean;
/**
* 是否支持图片预览,文件没有预览
* @default true
*/
preview?: boolean;
/**
* 自定义上传方法。返回值 `status` 表示上传成功或失败;`error` 或 `response.error` 表示上传失败的原因;<br/>`response` 表示请求上传成功后的返回数据,`response.url` 表示上传成功后的图片/文件地址,`response.files` 表示一个请求上传多个文件/图片后的返回值。<br/>示例一:`{ status: 'fail', error: '上传失败', response }`。<br/>示例二:`{ status: 'success', response: { url: 'https://tdesign.gtimg.com/site/avatar.jpg' } }`。<br/> 示例三:`{ status: 'success', files: [{ url: 'https://xxx.png', name: 'xxx.png' }]}`
*/
Expand Down
1 change: 1 addition & 0 deletions src/upload/upload.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ imageProps | Object | - | Typescript:`ImageProps`,[Image API Documents](./im
max | Number | 0 | max count of files limit | N
method | String | POST | HTTP request method。options: POST/GET/PUT/OPTIONS/PATCH/post/get/put/options/patch | N
multiple | Boolean | false | multiple files uploading | N
preview | Boolean | true | \- | N
requestMethod | Function | - | custom upload request method。Typescript:`(files: UploadFile \| UploadFile[]) => Promise<RequestMethodResponse>` `interface RequestMethodResponse { status: 'success' \| 'fail'; error?: string; response: { url?: string; files?: UploadFile[]; [key: string]: any } }`[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/upload/type.ts) | N
sizeLimit | Number / Object | - | files size limit。Typescript:`number \| SizeLimitObj` `interface SizeLimitObj { size: number; unit: SizeUnit ; message?: string }` `type SizeUnitArray = ['B', 'KB', 'MB', 'GB']` `type SizeUnit = SizeUnitArray[number]`[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/upload/type.ts) | N
useMockProgress | Boolean | true | use mock progress, instead of real progress | N
Expand Down
1 change: 1 addition & 0 deletions src/upload/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ imageProps | Object | - | 透传 Image 组件全部属性。TS 类型:`ImagePr
max | Number | 0 | 用于控制文件上传数量,值为 0 则不限制 | N
method | String | POST | HTTP 请求类型。可选项:POST/GET/PUT/OPTIONS/PATCH/post/get/put/options/patch | N
multiple | Boolean | false | 支持多文件上传 | N
preview | Boolean | true | 是否支持图片预览,文件没有预览 | N
requestMethod | Function | - | 自定义上传方法。返回值 `status` 表示上传成功或失败;`error``response.error` 表示上传失败的原因;<br/>`response` 表示请求上传成功后的返回数据,`response.url` 表示上传成功后的图片/文件地址,`response.files` 表示一个请求上传多个文件/图片后的返回值。<br/>示例一:`{ status: 'fail', error: '上传失败', response }`。<br/>示例二:`{ status: 'success', response: { url: 'https://tdesign.gtimg.com/site/avatar.jpg' } }`。<br/> 示例三:`{ status: 'success', files: [{ url: 'https://xxx.png', name: 'xxx.png' }]}`。TS 类型:`(files: UploadFile \| UploadFile[]) => Promise<RequestMethodResponse>` `interface RequestMethodResponse { status: 'success' \| 'fail'; error?: string; response: { url?: string; files?: UploadFile[]; [key: string]: any } }`[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/upload/type.ts) | N
sizeLimit | Number / Object | - | 图片文件大小限制,默认单位 KB。可选单位有:`'B' \| 'KB' \| 'MB' \| 'GB'`。示例一:`1000`。示例二:`{ size: 2, unit: 'MB', message: '图片大小不超过 {sizeLimit} MB' }`。TS 类型:`number \| SizeLimitObj` `interface SizeLimitObj { size: number; unit: SizeUnit ; message?: string }` `type SizeUnitArray = ['B', 'KB', 'MB', 'GB']` `type SizeUnit = SizeUnitArray[number]`[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/upload/type.ts) | N
useMockProgress | Boolean | true | 是否在请求时间超过 300ms 后显示模拟进度。上传进度有模拟进度和真实进度两种。一般大小的文件上传,真实的上传进度只有 0 和 100,不利于交互呈现,因此组件内置模拟上传进度。真实上传进度一般用于大文件上传 | N
Expand Down
2 changes: 1 addition & 1 deletion src/upload/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default defineComponent({

const handlePreview = (e: MouseEvent, file: UploadFile, index: number) => {
initialIndex.value = index;
showViewer.value = true;
showViewer.value = props.preview;
props.onPreview?.({
e,
file,
Expand Down

0 comments on commit 2c7dfcc

Please sign in to comment.