upload.d.ts 3.5 KB

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