zoukankan      html  css  js  c++  java
  • Angular2 判断上传的.txt文件内容是不是对象 如果上传文件列表有一个了 则替代之前的文件 如果上传文件不是.txt文件 则清空上传文件列表

         if(this.documentUpload.substr(0,1) == '{' && this.documentUpload.substr(-1,1) == '}'){}
     
       if(this.fileList.length > 1){
           this.fileList = this.fileList.slice(-1);
         }
       this.fileList = [];
    ---------------------------------------------------------------------------------------------
    const filterFiles = fileLists.filter(w => ~['text/plain'].indexOf(w.type));
    ---------------------------------------------------------------------------------------------
      filterPic: UploadFilter[] = [           //过滤器  上传列表数量的限制
        {
          name: 'type',
          fn: (fileListPic: UploadFile[]) => {
            // var filetypes =[".jpg",".png",".rar",".txt",".zip",".doc",".ppt",".xls",".pdf",".docx",".xlsx"];
            const filterFiles = fileListPic.filter(w => ~['image/png','image/jpeg','image/gif','image/bmp'].indexOf(w.type));
            // const filterFiles = fileLists.filter(w => ~["/txt","/doc"].indexOf(w.type));
            if (filterFiles.length !== fileListPic.length) {
              this.msg.error(`包含文件格式不正确,只支持image/png,image/jpeg,image/gif,image/bmp格式`);
              return filterFiles;
            }
            return fileListPic;
          }
        },
        {
          name: 'async',
          fn: (fileListsPic: UploadFile[]) => {
            return new Observable((observer: Observer<UploadFile[]>) => {
              // doing
              observer.next(fileListsPic);
              observer.complete();
            });
          }
        }
      ];
    ---------------------------------------------------------------------------------------------
      <div nz-row class="serveKey">
        <div nz-col nzSpan="1"></div>
        <div nz-col nzSpan="18">
          <nz-upload
            [nzFileType]="'image/png,image/jpeg,image/gif,image/bmp'"
            [nzAction]="url + '/publish/upload/pic'"
            [nzFileList]="fileListPic"
            [nzFilter]="filterPic"
            nzMultiple
            [nzLimit]="2"
            (nzChange)="picChange($event)"
          >
            <button nz-button style="margin: 0;"><i nz-icon nzType="upload"></i><span>图片上传</span></button>
          </nz-upload>
          <span *ngIf="ngText&&publish.imagePath == ''" style="margin-top:5px;display: block;color: #f5707a;">不能为空</span>
    
        </div>
        <div nz-col nzSpan="1">
          <div *ngIf="publish.imagePath !== ''" style="display:inline-block;vertical-align:middle;margin-left: 6px;">
            <i nz-icon  [nzType]="'check-circle'" [nzTheme]="'twotone'" [nzTwotoneColor]="'#52c41a'"></i>
          </div>
        </div>
      </div>
    

      

     
  • 相关阅读:
    delphi7 projectoptions打开出错
    file not found frmaddBdsuo.dcu
    session 不活动是因为未注册 WebSessionActivator,或试图在 IHttpHandler 的构造函数中 访问session
    oracle导出指定的表,并将指定的表追加到其他dmp文件中(不影响dmp中其他的表)
    父类指针转换成子类指针
    为什么会是这样的输出结果
    字符数组
    变量的声明和定义
    const对象默认为文件的局部变量
    输出结果
  • 原文地址:https://www.cnblogs.com/zhanglanzuopin/p/12603359.html
Copyright © 2011-2022 走看看