upload.d.ts 3.3 KB

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