Skip to content

Commit

Permalink
Merge pull request #640 from brianzhang/fix/upload-brian
Browse files Browse the repository at this point in the history
【Upload】 fix: 修复handleProgress file状态判断
  • Loading branch information
chaishi committed Mar 28, 2022
2 parents 79bc95b + 19588c4 commit 78f3e97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
16 changes: 9 additions & 7 deletions src/upload/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { renderContent } from '../utils/render-tnode';
import props from './props';
import { ClassName } from '../common';
import { emitEvent } from '../utils/event';
import { dedupeFile } from './util';
import {
HTMLInputEvent,
SuccessContext,
Expand Down Expand Up @@ -257,7 +256,8 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload')).exte

let tmpFiles = [...files];
if (this.max) {
tmpFiles = tmpFiles.slice(0, this.max - this.files.length);
// 判断当前待上传列表长度
tmpFiles = tmpFiles.slice(0, this.max - this.toUploadFiles.length - this.files.length);
if (tmpFiles.length !== files.length) {
console.warn(`TDesign Upload Warn: you can only upload ${this.max} files`);
}
Expand Down Expand Up @@ -285,10 +285,11 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload')).exte
this.handleBeforeUpload(file).then((canUpload) => {
if (!canUpload) return;
const newFiles = this.toUploadFiles.concat();
newFiles.push(uploadFile);
this.toUploadFiles = !this.allowUploadDuplicateFile
? dedupeFile([...new Set(newFiles)])
: [...new Set(newFiles)];
// 判断是否为重复文件条件,已选是否存在检验
if (this.allowUploadDuplicateFile || !this.toUploadFiles.find((file) => file.name === uploadFile.name)) {
newFiles.push(uploadFile);
}
this.toUploadFiles = newFiles;
this.loadingFile = uploadFile;
if (this.autoUpload) {
this.upload(uploadFile);
Expand Down Expand Up @@ -445,7 +446,8 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload')).exte

innerFiles.forEach((file) => {
file.percent = Math.min(percent, 100);
this.loadingFile = file;
// 判断文件状态是否上传完成
this.loadingFile = file.status === 'success' ? null : file;
});
const progressCtx = {
percent,
Expand Down
11 changes: 0 additions & 11 deletions src/upload/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import uniqWith from 'lodash/uniqWith';
import { prefix } from '../config';
import { UploadFile } from './type';

export const UPLOAD_NAME = `${prefix}-upload`;

Expand Down Expand Up @@ -44,12 +42,3 @@ export function abridgeName(inputName: string, leftCount = 5, rightcount = 7): s
}
return name.replace(new RegExp(`^(.{${leftLength}})(.+)(.{${rightLength}})$`), '$1…$3');
}
/**
* 重复数组检查
* @param files Array
* @param key string default name
* @returns Array of files
*/
export function dedupeFile(files: Array<UploadFile>, key = 'name'): any {
return uniqWith(files, (val1, val2) => val1[key] === val2[key]);
}

0 comments on commit 78f3e97

Please sign in to comment.