博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NG-ZORRO 使用相关
阅读量:5839 次
发布时间:2019-06-18

本文共 3625 字,大约阅读时间需要 12 分钟。

Upload上传

import { Component, Input, Output, EventEmitter, Inject } from '@angular/core';import { NzMessageService, UploadFile, UploadFilter, UploadXHRArgs } from 'ng-zorro-antd';import {    HttpRequest,    HttpClient,    HttpEventType,    HttpEvent,    HttpResponse} from '@angular/common/http';import { forkJoin } from 'rxjs';import { HttpService } from './httpService';export class File {    uid: '';    name: '';    status: 'done';    url: '';}export class UploadFileType {    'fileId': '';    'fileName': '';    'fileSize': '';    'fileUrl': '';    'sequence': '0';}@Component({    selector: 'UploadPictureCardComponent',    template: `    
Upload
文件上传中{
{progress}}...
`})export class UploadPictureCardComponent {

fileList: File[] = [];

uploadFiles: UploadFileType[] = [];
previewImage = '';
previewVisible = false;
progress = ''; //上传进度
@Input() childIsLoad;
@Input() flieSessionStoragesName; //文件存在sessionStorage中的键值
@Output() private childOuter = new EventEmitter(); //子组件向父组件传值
@Output() private childIsLoadOuter = new EventEmitter(); //告诉父组件是否上传中

constructor(        private msg: NzMessageService,        private httpService: HttpService,        @Inject('urlConfig') public urlConfig    ) {}    ngOnInit() {        //初始化文件    }    //上传限制    filters: UploadFilter[] = [        {            name: 'type',            fn: (fileList: UploadFile[]) => {                const filterFiles = fileList.filter(                    w =>                        ~['image/png', 'image/jpg', 'image/gif', 'image/bmp', 'image/jpeg'].indexOf(                            w.type                        )                );                if (filterFiles.length !== fileList.length) {                    this.msg.create('error', '请上传png、jpg、gif、bmp、jpeg格式的图片!');                    return filterFiles;                }                return fileList;            }        }    ];    //上传之前的操作    beforeUpload = (file: File) => {        let ispass = true; //是否继续往下执行        console.log('上传之前的操作');        //以下操作在        if (window.sessionStorage.getItem(this.flieSessionStoragesName)) {            let list_ = JSON.parse(window.sessionStorage.getItem(this.flieSessionStoragesName));            for (let i in list_) {                if (file.name == list_[i].fileName) {                    ispass = false;                    this.msg.create('warning', '请勿上传同名文件!');                    break;                }            }        }        return ispass; //返回true继续执行,false直接停止    };    //开始、上传进度、完成、失败都会调用这个函数    handleChange(info: any): void {        console.log(info);        if (info.type == 'start') {            this.childIsLoadOuter.emit(true); //告诉父组件上传中            this.progress = '0%';        }        if (info.type == 'progress') {            this.progress = info.event.percent.toFixed(2) + '%';        }        if (info.type === 'success') {            this.progress = '';            console.log(info);            let file = new UploadFileType();            file.fileId = info.file.response['data'].id;            file.fileName = info.file.response['data'].name;            file.fileSize = info.file.response['data'].size;            file.fileUrl = info.file.response['data'].downloadUrl;            file.sequence = '0';            this.childOuter.emit(file); //向父组件传值            this.childIsLoadOuter.emit(false); //告诉父组件上传完成            this.msg.create('success', '上传成功!');        }        if (info.type === 'error') {            this.childIsLoadOuter.emit(false); //告诉父组件上传完成        }    }}

 

转载于:https://www.cnblogs.com/mary-123/p/10057331.html

你可能感兴趣的文章
avcodec_open2()分析
查看>>
何如获取单选框中某一个选中的值
查看>>
paip.输入法编程----删除双字词简拼
查看>>
QQ悬浮返回顶部
查看>>
MySQL建表语句的一些特殊字段
查看>>
《Unix环境高级编程》读书笔记 第8章-进程控制
查看>>
腾讯前端二面题目详解
查看>>
mascara-1
查看>>
Jquery Form表单取值
查看>>
Android API level 与version对应关系
查看>>
Team Name
查看>>
String类
查看>>
西门子_TDC_数据耦合小经验
查看>>
接口测试与postman
查看>>
LINQ To XML的一些方法
查看>>
[LeetCode] Copy List with Random Pointer
查看>>
openstack部署之nova
查看>>
JS组件系列——表格组件神器:bootstrap table
查看>>
存储过程Oracle(一)
查看>>
log4j日志归档
查看>>