upload.d.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { ElementUIComponent } from './component'
  2. export type ListType = 'text' | 'picture' | 'picture-card'
  3. export type FileUploadStatus = 'ready' | 'uploading' | 'success' | 'fail'
  4. export interface FileListItem {
  5. name: string,
  6. url: string,
  7. status?: FileUploadStatus
  8. }
  9. export interface ElUploadInternalFileDetail {
  10. status: FileUploadStatus,
  11. name: string,
  12. size: number,
  13. percentage: number,
  14. uid: number,
  15. raw: File
  16. }
  17. export interface ElUploadProgressEvent extends ProgressEvent {
  18. percent: number
  19. }
  20. export interface HttpRequestOptions {
  21. headers: object,
  22. withCredentials: boolean,
  23. file: ElUploadInternalFileDetail,
  24. data: object,
  25. filename: string,
  26. action: string,
  27. onProgress: (e: ElUploadProgressEvent) => void,
  28. onSuccess: (response: any) => void,
  29. onError: (err: ErrorEvent) => void
  30. }
  31. /** Upload Component */
  32. export declare class ElUpload extends ElementUIComponent {
  33. /** Request URL (required) */
  34. action: string
  35. /** Request headers */
  36. headers: object
  37. /** Whether uploading multiple files is permitted */
  38. multiple: boolean
  39. /** Additions options of request */
  40. data: object
  41. /** Key name for uploaded file */
  42. name: string
  43. /** Whether cookies are sent */
  44. withCredentials: boolean
  45. /** Whether to show the uploaded file list */
  46. showFileList: boolean
  47. /** Whether to activate drag and drop mode */
  48. drag: boolean
  49. /** Accepted file types, will not work when thumbnail-mode is true */
  50. accept: string
  51. /** Hook function when clicking the uploaded files */
  52. onPreview: (file: ElUploadInternalFileDetail) => void
  53. /** Hook function when files are removed */
  54. onRemove: (file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail[]) => void
  55. /** Hook function when uploaded successfully */
  56. onSuccess: (response: any, file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail) => void
  57. /** Hook function when some errors occurs */
  58. onError: (err: ErrorEvent, file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail) => void
  59. /** Hook function when some progress occurs */
  60. onProgress: (event: ElUploadProgressEvent, file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail) => void
  61. /** Hook function when file status change */
  62. onChange: (file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail[]) => void
  63. /** Hook function before uploading with the file to be uploaded as its parameter. If false or a Promise is returned, uploading will be aborted */
  64. beforeUpload: (file: ElUploadInternalFileDetail) => boolean | Promise<File | boolean>
  65. /** Whether thumbnail is displayed */
  66. thumbnailMode: boolean
  67. /** Default uploaded files */
  68. fileList: FileListItem[]
  69. /** Type of fileList */
  70. listType: ListType
  71. /** Whether to auto upload file */
  72. autoUpload: boolean
  73. /** Override default xhr behavior, allowing you to implement your own upload-file's request */
  74. httpRequest: (options: HttpRequestOptions) => void
  75. /** Whether to disable upload */
  76. disabled: boolean
  77. /** Maximum number of uploads allowed */
  78. limit: number
  79. /** Hook function when limit is exceeded */
  80. onExceed: (file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail[]) => void
  81. }