2018-04-19 11:54:28 +08:00
|
|
|
import { RcFile, UploadFile } from './interface';
|
2017-11-20 16:43:25 +08:00
|
|
|
|
2017-03-17 11:47:05 +08:00
|
|
|
export function T() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix IE file.status problem
|
|
|
|
// via coping a new Object
|
2018-04-19 11:54:28 +08:00
|
|
|
export function fileToObject(file: RcFile): UploadFile {
|
2017-03-17 11:47:05 +08:00
|
|
|
return {
|
2018-04-28 11:06:32 +08:00
|
|
|
...file,
|
2018-05-02 13:56:54 +08:00
|
|
|
lastModified: file.lastModified,
|
|
|
|
lastModifiedDate: file.lastModifiedDate,
|
|
|
|
name: file.name,
|
|
|
|
size: file.size,
|
|
|
|
type: file.type,
|
|
|
|
uid: file.uid,
|
2017-03-17 11:47:05 +08:00
|
|
|
percent: 0,
|
2018-04-19 11:54:28 +08:00
|
|
|
originFileObj: file,
|
2017-11-20 16:43:25 +08:00
|
|
|
} as UploadFile;
|
2017-03-17 11:47:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成Progress percent: 0.1 -> 0.98
|
|
|
|
* - for ie
|
|
|
|
*/
|
|
|
|
export function genPercentAdd() {
|
|
|
|
let k = 0.1;
|
|
|
|
const i = 0.01;
|
|
|
|
const end = 0.98;
|
2018-12-07 20:02:01 +08:00
|
|
|
return function(s: number) {
|
2017-03-17 11:47:05 +08:00
|
|
|
let start = s;
|
|
|
|
if (start >= end) {
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
start += k;
|
|
|
|
k = k - i;
|
|
|
|
if (k < 0.001) {
|
|
|
|
k = 0.001;
|
|
|
|
}
|
2018-05-22 15:36:25 +08:00
|
|
|
return start;
|
2017-03-17 11:47:05 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:43:25 +08:00
|
|
|
export function getFileItem(file: UploadFile, fileList: UploadFile[]) {
|
2017-08-20 15:39:02 +08:00
|
|
|
const matchKey = file.uid !== undefined ? 'uid' : 'name';
|
2017-03-17 11:47:05 +08:00
|
|
|
return fileList.filter(item => item[matchKey] === file[matchKey])[0];
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:43:25 +08:00
|
|
|
export function removeFileItem(file: UploadFile, fileList: UploadFile[]) {
|
2017-08-20 15:39:02 +08:00
|
|
|
const matchKey = file.uid !== undefined ? 'uid' : 'name';
|
2017-03-17 11:47:05 +08:00
|
|
|
const removed = fileList.filter(item => item[matchKey] !== file[matchKey]);
|
|
|
|
if (removed.length === fileList.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|