Improve upload type definition

This commit is contained in:
Wei Zhu 2017-11-20 16:43:25 +08:00
parent 45135e4ec8
commit 03e4411589
2 changed files with 11 additions and 7 deletions

View File

@ -10,6 +10,8 @@ export interface UploadFile {
uid: number;
size: number;
name: string;
filename?: string;
lastModified?: string;
lastModifiedDate?: Date;
url?: string;
status?: UploadFileStatus;
@ -19,6 +21,7 @@ export interface UploadFile {
response?: any;
error?: any;
linkProps?: any;
type: string;
}
export interface UploadChangeParam {

View File

@ -1,10 +1,12 @@
import { UploadFile } from './interface';
export function T() {
return true;
}
// Fix IE file.status problem
// via coping a new Object
export function fileToObject(file): any {
export function fileToObject(file: UploadFile) {
return {
lastModified: file.lastModified,
lastModifiedDate: file.lastModifiedDate,
@ -15,9 +17,8 @@ export function fileToObject(file): any {
response: file.response,
error: file.error,
percent: 0,
originFileObj: file,
status: null,
};
originFileObj: file as (File | UploadFile),
} as UploadFile;
}
/**
@ -28,7 +29,7 @@ export function genPercentAdd() {
let k = 0.1;
const i = 0.01;
const end = 0.98;
return function (s) {
return function (s: number) {
let start = s;
if (start >= end) {
return start;
@ -43,12 +44,12 @@ export function genPercentAdd() {
};
}
export function getFileItem(file, fileList) {
export function getFileItem(file: UploadFile, fileList: UploadFile[]) {
const matchKey = file.uid !== undefined ? 'uid' : 'name';
return fileList.filter(item => item[matchKey] === file[matchKey])[0];
}
export function removeFileItem(file, fileList) {
export function removeFileItem(file: UploadFile, fileList: UploadFile[]) {
const matchKey = file.uid !== undefined ? 'uid' : 'name';
const removed = fileList.filter(item => item[matchKey] !== file[matchKey]);
if (removed.length === fileList.length) {