vue-simple-uploader如何防止选中了重复的文件上传

有这样一个需求,把一个文件复制一份然后改个名称,同时上传这两个相同的文件,这样后端就会报错,所以需要做一下校验,不允许重复

<uploader
      ref="uploader"
      :options="options"
      :autoStart="false"
      @file-added="onFileAdded"
      @files-added="onFilesAdded"
      @file-success="onFileSuccess"
      @file-progress="onFileProgress"
      @file-error="onFileError"
      class="uploader-app"

  

onFilesAdded(files, fileList, event){

      for (var i=0; i<fileList.length; i++) {

              for (var j=i+1; j<fileList.length; j++) {

                  if (fileList[i].uniqueIdentifier.split('-')[0] == fileList[j].uniqueIdentifier.split('-')[0]) {


                      files.ignored = true
                      if (this.$i18n.locale == "zh") {
                        this.$modal.msgSuccess("请勿上传重复的文件");
                      } else if (this.$i18n.locale == "en") {
                        this.$modal.msgSuccess("Please do not upload duplicate files");
                      }
                      return false;

                  }


              }
          }
           console.log("多个文件上传每一个",files)
          for(let file of files){
            this.computeMD5(file);
            this.panelShow = true;
            Bus.$emit('fileAdded');
          }


    },
    onFileAdded(file) {
      // this.panelShow = true;
      // this.computeMD5(file);

      // Bus.$emit("fileAdded");
    },

参考大佬的代码改的

https://www.cnblogs.com/xiahj/p/15950975.html

posted @ 2022-11-30 18:35  sgj191024  阅读(994)  评论(0)    收藏  举报