diff --git a/components/upload/demo/picture-card.ts b/components/upload/demo/picture-card.ts index 11c5c190f0b..bde09614238 100644 --- a/components/upload/demo/picture-card.ts +++ b/components/upload/demo/picture-card.ts @@ -14,7 +14,11 @@ import { NzMessageService, UploadFile } from 'ng-zorro-antd';
Upload
- modal待实现:{{ previewVisible | json }} + + + + + `, styles: [ diff --git a/components/upload/interface.ts b/components/upload/interface.ts index a120a8dc20c..01657a50ebd 100644 --- a/components/upload/interface.ts +++ b/components/upload/interface.ts @@ -1,8 +1,7 @@ -// tslint:disable:prefer-method-signature +// tslint:disable:no-any prefer-method-signature import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; -// tslint:disable:no-any /** 状态 */ export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading' | 'removed'; diff --git a/components/upload/nz-upload-btn.component.ts b/components/upload/nz-upload-btn.component.ts index 7cb7f95c5da..1a51e3426d2 100644 --- a/components/upload/nz-upload-btn.component.ts +++ b/components/upload/nz-upload-btn.component.ts @@ -3,7 +3,9 @@ import { HttpClient, HttpEventType, HttpHeaders, HttpRequest, HttpResponse } fro import { ChangeDetectorRef, Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, Optional, SimpleChange, SimpleChanges, ViewChild } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; + import { NzUpdateHostClassService } from '../core/services/update-host-class.service'; + import { UploadFile, UploadXHRArgs, ZipButtonOptions } from './interface'; @Component({ diff --git a/components/upload/nz-upload-list.component.ts b/components/upload/nz-upload-list.component.ts index 8fcbff7c62b..5cac46e7240 100644 --- a/components/upload/nz-upload-list.component.ts +++ b/components/upload/nz-upload-list.component.ts @@ -1,8 +1,10 @@ // tslint:disable: no-any import { animate, state, style, transition, trigger } from '@angular/animations'; import { Component, ElementRef, Input, OnChanges, OnInit, SimpleChange, SimpleChanges } from '@angular/core'; + import { NzUpdateHostClassService } from '../core/services/update-host-class.service'; import { NzI18nService } from '../i18n/nz-i18n.service'; + import { ShowUploadListInterface, UploadFile, UploadListType } from './interface'; @Component({ @@ -64,7 +66,7 @@ import { ShowUploadListInterface, UploadFile, UploadListType } from './interface
- +
`, diff --git a/components/upload/nz-upload.component.ts b/components/upload/nz-upload.component.ts index 44495785671..0914aa37c0a 100644 --- a/components/upload/nz-upload.component.ts +++ b/components/upload/nz-upload.component.ts @@ -4,8 +4,10 @@ import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; import { of } from 'rxjs/observable/of'; import { filter } from 'rxjs/operators'; + import { toBoolean, toNumber } from '../core/util/convert'; import { NzI18nService } from '../i18n/nz-i18n.service'; + import { ShowUploadListInterface, UploadChangeParam, UploadFile, UploadFileStatus, UploadFilter, UploadListType, UploadType, ZipButtonOptions } from './interface'; import { NzUploadBtnComponent } from './nz-upload-btn.component'; @@ -67,7 +69,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy { private _limit: number = 0; @Input() set nzLimit(value: number) { - this._limit = toNumber(value); + this._limit = toNumber(value, null); } get nzLimit(): number { return this._limit; @@ -75,7 +77,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy { private _size: number = 0; @Input() set nzSize(value: number) { - this._size = toNumber(value); + this._size = toNumber(value, null); } get nzSize(): number { return this._size; diff --git a/components/upload/nz-upload.module.ts b/components/upload/nz-upload.module.ts index ec8c6fce622..464808d8fc4 100644 --- a/components/upload/nz-upload.module.ts +++ b/components/upload/nz-upload.module.ts @@ -1,8 +1,10 @@ import { CommonModule } from '@angular/common'; import { ModuleWithProviders, NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; + import { NzI18nModule } from '../i18n'; import { NzToolTipModule } from '../tooltip/nz-tooltip.module'; + import { NzProgressModule } from './../progress/nz-progress.module'; import { NzUploadBtnComponent } from './nz-upload-btn.component'; import { NzUploadListComponent } from './nz-upload-list.component'; diff --git a/components/upload/upload.spec.ts b/components/upload/upload.spec.ts index 989b8a6d8b1..4cc6d85ca60 100644 --- a/components/upload/upload.spec.ts +++ b/components/upload/upload.spec.ts @@ -8,9 +8,11 @@ import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; + import { NzI18nModule, NzI18nService } from '../i18n'; import { NzProgressModule } from '../progress/nz-progress.module'; import { NzToolTipModule } from '../tooltip/nz-tooltip.module'; + import { ShowUploadListInterface, UploadChangeParam, UploadFile, UploadFilter, UploadListType, UploadType, ZipButtonOptions } from './interface'; import { NzUploadBtnComponent } from './nz-upload-btn.component'; import { NzUploadListComponent } from './nz-upload-list.component'; @@ -310,6 +312,53 @@ describe('upload', () => { }); }); }); + + describe('[nzFilter]', () => { + it('shoule be custom limit', () => { + instance.nzMultiple = true; + instance.nzLimit = 1; + instance.nzFilter = [ + { + name: 'limit', + fn: (fileList: UploadFile[]) => fileList.slice(-instance.nzLimit) + } + ]; + fixture.detectChanges(); + expect(instance._beforeUploadList.length).toBe(0); + pageObject.postFile([ + ...PNGSMALL.target.files, + ...PNGSMALL.target.files, + ...PNGSMALL.target.files + ]); + expect(instance._beforeUploadList.length).toBe(instance.nzLimit); + }); + it('shoule be custom size', () => { + instance.nzSize = 1; + instance.nzFilter = [ + { + name: 'size', + fn: (fileList: UploadFile[]) => fileList.filter(w => (w.size / 1024) <= instance.nzSize) + } + ]; + fixture.detectChanges(); + expect(instance._beforeUploadList.length).toBe(0); + pageObject.postLarge(); + expect(instance._beforeUploadList.length).toBe(0); + }); + it('shoule be custom type', () => { + instance.nzFileType = 'image/png'; + instance.nzFilter = [ + { + name: 'type', + fn: (fileList: UploadFile[]) => fileList.filter(w => ~[ instance.nzFileType ].indexOf(w.type)) + } + ]; + fixture.detectChanges(); + expect(instance._beforeUploadList.length).toBe(0); + pageObject.postFile(JPGSMALL.target.files); + expect(instance._beforeUploadList.length).toBe(0); + }); + }); }); describe('CORS', () => {