1 |
|
2 |
|
3 | import * as React from 'react';
|
4 | import CommonProps from '../util';
|
5 | import { ProgressProps } from '../progress';
|
6 |
|
7 | interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
|
8 | onError?: any;
|
9 | onSelect?: any;
|
10 | defaultValue?: any;
|
11 | onChange?: any;
|
12 | }
|
13 |
|
14 | export interface CardProps extends HTMLAttributesWeak, CommonProps {
|
15 | |
16 |
|
17 |
|
18 | action?: string;
|
19 |
|
20 | |
21 |
|
22 |
|
23 | multiple?: boolean;
|
24 |
|
25 | |
26 |
|
27 |
|
28 | showDownload?: boolean;
|
29 |
|
30 | |
31 |
|
32 |
|
33 | accept?: string;
|
34 |
|
35 | |
36 |
|
37 |
|
38 | data?: any | (() => void);
|
39 |
|
40 | /**
|
41 | * 设置上传的请求头部
|
42 | */
|
43 | headers?: any;
|
44 |
|
45 | /**
|
46 | * 是否允许请求携带 cookie
|
47 | */
|
48 | withCredentials?: boolean;
|
49 |
|
50 | /**
|
51 | * 可选参数, 详见 [beforeUpload](#beforeUpload)
|
52 | */
|
53 | beforeUpload?: (file: {}, options: {}) => boolean | {} | any;
|
54 |
|
55 | |
56 |
|
57 |
|
58 | onProgress?: () => void;
|
59 |
|
60 | |
61 |
|
62 |
|
63 | onSuccess?: (file: {}, value: Array<any>) => void;
|
64 |
|
65 | |
66 |
|
67 |
|
68 | onError?: (file: {}, value: Array<any>) => void;
|
69 |
|
70 | |
71 |
|
72 |
|
73 | children?: React.ReactNode;
|
74 |
|
75 | |
76 |
|
77 |
|
78 | timeout?: number;
|
79 |
|
80 | |
81 |
|
82 |
|
83 | method?: 'post' | 'put';
|
84 |
|
85 | |
86 |
|
87 |
|
88 | request?: (option: {}) => void;
|
89 |
|
90 | |
91 |
|
92 |
|
93 | name?: string;
|
94 |
|
95 | |
96 |
|
97 |
|
98 | onSelect?: () => void;
|
99 |
|
100 | |
101 |
|
102 |
|
103 | onDrop?: () => void;
|
104 |
|
105 | |
106 |
|
107 |
|
108 | prefix?: string;
|
109 |
|
110 | |
111 |
|
112 |
|
113 | value?: Array<any>;
|
114 |
|
115 | |
116 |
|
117 |
|
118 | defaultValue?: Array<any>;
|
119 |
|
120 | |
121 |
|
122 |
|
123 | shape?: 'card';
|
124 |
|
125 | |
126 |
|
127 |
|
128 | listType?: 'text' | 'image' | 'card';
|
129 |
|
130 | |
131 |
|
132 |
|
133 | formatter?: (response: {}, file: any) => void;
|
134 |
|
135 | |
136 |
|
137 |
|
138 | limit?: number;
|
139 |
|
140 | |
141 |
|
142 |
|
143 | dragable?: boolean;
|
144 |
|
145 | |
146 |
|
147 |
|
148 | useDataURL?: boolean;
|
149 |
|
150 | |
151 |
|
152 |
|
153 | disabled?: boolean;
|
154 |
|
155 | |
156 |
|
157 |
|
158 | onChange?: (value: File[]) => void;
|
159 |
|
160 | |
161 |
|
162 |
|
163 | afterSelect?: (file: {}) => boolean;
|
164 |
|
165 | |
166 |
|
167 |
|
168 | onRemove?: () => void;
|
169 |
|
170 | |
171 |
|
172 |
|
173 | className?: string;
|
174 |
|
175 | |
176 |
|
177 |
|
178 | style?: React.CSSProperties;
|
179 |
|
180 | |
181 |
|
182 |
|
183 | autoUpload?: boolean;
|
184 |
|
185 | |
186 |
|
187 |
|
188 | progressProps?: ProgressProps;
|
189 |
|
190 | |
191 |
|
192 |
|
193 | onPreview?: () => void;
|
194 |
|
195 | |
196 |
|
197 |
|
198 | onCancel?: () => void;
|
199 | |
200 |
|
201 |
|
202 | capture?: string;
|
203 | }
|
204 |
|
205 | export class Card extends React.Component<CardProps, any> {}
|
206 |
|
207 | export class Dragger extends React.Component<UploadProps, any> {}
|
208 |
|
209 | export interface SelecterProps extends HTMLAttributesWeak, CommonProps {
|
210 | |
211 |
|
212 |
|
213 | disabled?: boolean;
|
214 |
|
215 | |
216 |
|
217 |
|
218 | multiple?: boolean;
|
219 |
|
220 | |
221 |
|
222 |
|
223 | dragable?: boolean;
|
224 |
|
225 | |
226 |
|
227 |
|
228 | accept?: string;
|
229 |
|
230 | |
231 |
|
232 |
|
233 | onSelect?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
234 |
|
235 | |
236 |
|
237 |
|
238 | onDragOver?: () => void;
|
239 |
|
240 | |
241 |
|
242 |
|
243 | onDragLeave?: () => void;
|
244 |
|
245 | |
246 |
|
247 |
|
248 | onDrop?: () => void;
|
249 |
|
250 | |
251 |
|
252 |
|
253 | webkitdirectory?: boolean;
|
254 | }
|
255 |
|
256 | export class Selecter extends React.Component<SelecterProps, any> {}
|
257 |
|
258 | export class Uploader {
|
259 | |
260 |
|
261 |
|
262 | constructor(options?: any);
|
263 |
|
264 | /**
|
265 | * 配置选项
|
266 | * @param options 配置
|
267 | */
|
268 | setOptions(options: any): void;
|
269 | /**
|
270 | * 开始上传
|
271 | * @param files 文件列表
|
272 | */
|
273 | startUpload(files: Array<any>): void;
|
274 | /**
|
275 | * 中断某个文件上传
|
276 | * @param file 文件
|
277 | */
|
278 | abort(file: any): void;
|
279 | }
|
280 |
|
281 | export interface UploadProps extends HTMLAttributesWeak, CommonProps {
|
282 | |
283 |
|
284 |
|
285 | action?: string;
|
286 |
|
287 | |
288 |
|
289 |
|
290 | accept?: string;
|
291 |
|
292 | |
293 |
|
294 |
|
295 | data?: any | (() => void);
|
296 |
|
297 | /**
|
298 | * 是否支持多选文件,`ie10+` 支持。开启后按住 ctrl 可选择多个文件
|
299 | */
|
300 | multiple?: boolean;
|
301 |
|
302 | /**
|
303 | * 设置上传的请求头部
|
304 | */
|
305 | headers?: any;
|
306 |
|
307 | /**
|
308 | * 是否允许请求携带 cookie
|
309 | */
|
310 | withCredentials?: boolean;
|
311 |
|
312 | /**
|
313 | * 可选参数, 详见 [beforeUpload](#beforeUpload)
|
314 | */
|
315 | beforeUpload?: (file: any, options: any) => boolean | {} | any;
|
316 |
|
317 | |
318 |
|
319 |
|
320 | onProgress?: () => void;
|
321 |
|
322 | |
323 |
|
324 |
|
325 | onSuccess?: (file: any, value: Array<any>) => void;
|
326 |
|
327 | |
328 |
|
329 |
|
330 | onError?: (file: any, value: Array<any>) => void;
|
331 |
|
332 | |
333 |
|
334 |
|
335 | children?: React.ReactNode;
|
336 |
|
337 | |
338 |
|
339 |
|
340 | timeout?: number;
|
341 |
|
342 | |
343 |
|
344 |
|
345 | method?: 'post' | 'put';
|
346 |
|
347 | |
348 |
|
349 |
|
350 | request?: (option: any) => any;
|
351 |
|
352 | |
353 |
|
354 |
|
355 | name?: string;
|
356 |
|
357 | |
358 |
|
359 |
|
360 | onSelect?: (uploadFiles: Array<any>, value: Array<any>) => void;
|
361 |
|
362 | |
363 |
|
364 |
|
365 | onDrop?: () => void;
|
366 |
|
367 | |
368 |
|
369 |
|
370 | prefix?: string;
|
371 |
|
372 | |
373 |
|
374 |
|
375 | value?: Array<any>;
|
376 |
|
377 | |
378 |
|
379 |
|
380 | defaultValue?: Array<any>;
|
381 |
|
382 | |
383 |
|
384 |
|
385 | shape?: 'card';
|
386 |
|
387 | |
388 |
|
389 |
|
390 | listType?: 'text' | 'image' | 'card';
|
391 |
|
392 | |
393 |
|
394 |
|
395 | formatter?: (response: any, file: any) => void;
|
396 |
|
397 | |
398 |
|
399 |
|
400 | limit?: number;
|
401 |
|
402 | |
403 |
|
404 |
|
405 | dragable?: boolean;
|
406 |
|
407 | |
408 |
|
409 |
|
410 | useDataURL?: boolean;
|
411 |
|
412 | |
413 |
|
414 |
|
415 | disabled?: boolean;
|
416 |
|
417 | |
418 |
|
419 |
|
420 | onChange?: (value: File[]) => void;
|
421 |
|
422 | |
423 |
|
424 |
|
425 | afterSelect?: (file: any) => boolean;
|
426 |
|
427 | |
428 |
|
429 |
|
430 | onRemove?: (file: any) => boolean | any;
|
431 |
|
432 | |
433 |
|
434 |
|
435 | extraRender?: (file: File) => any;
|
436 | |
437 |
|
438 |
|
439 | fileNameRender?: (file: File) => any;
|
440 | |
441 |
|
442 |
|
443 | actionRender?: (file: File) => any;
|
444 | |
445 |
|
446 |
|
447 | className?: string;
|
448 |
|
449 | |
450 |
|
451 |
|
452 | style?: React.CSSProperties;
|
453 |
|
454 | |
455 |
|
456 |
|
457 | autoUpload?: boolean;
|
458 |
|
459 | |
460 |
|
461 |
|
462 | progressProps?: ProgressProps;
|
463 |
|
464 | |
465 |
|
466 |
|
467 | isPreview?: boolean;
|
468 |
|
469 | |
470 |
|
471 |
|
472 | renderPreview?: (value: number) => void;
|
473 |
|
474 | |
475 |
|
476 |
|
477 | fileKeyName?: string;
|
478 | |
479 |
|
480 |
|
481 |
|
482 | previewOnFileName?: boolean,
|
483 | }
|
484 |
|
485 | export default class Upload extends React.Component<UploadProps, any> {
|
486 | static Card: typeof Card;
|
487 | static Dragger: typeof Dragger;
|
488 | static Selecter: typeof Selecter;
|
489 | static Uploader: typeof Uploader;
|
490 | }
|