vue循环发起请求,等一个请求结束后,进行下一次请求

vue循环发起请求,等一个请求结束后,进行下一次请求
async await new Promise

    async filesSubmitted(files, fileList) {
      if (files.length === 0) {
        return this.$message.error("文件列表存在同名文件,请关闭文件列表后再试。");
      }

      for (let file of files) {
        const path = this.filePath
        const name = file.relativePath
        const size = file.size
        var formData = new FormData();
        formData.append('concurrentType', this.fileType)
        formData.append('fileName', path + name)
        formData.append('partCount', Math.ceil(size / this.chunkSize))
        formData.append('fileSize', size)
        formData.append('userId',this.createUser)
        formData.append('type',1)
        if (this.fileSetCode) {
          formData.append('datasetCode', this.fileSetCode)
        }
        let res = await this.submitFile(formData, file)
      }
      this.isAllCover = -1
    },
    // 文件提交
    submitFile(formData, file) {
      return new Promise((resolve, reject) => {
        this.axios.post(api['distributed'].uploadTestFile, formData
        ).then(response => {
          let res = response.data
          if (res.code === 200) {
            setTimeout(() => {
              file.chunkUrlData = res.data.ulist
              file.chunkUrlData.uploadId = res.data.uploadId
              file.path = res.data.fileName
              var code = res.data.paperCode + '/' 
              if (this.menuItem.length == 0) {
                this.filePath = '论文/' + code
              } else {
                this.filePath = this.menuItem[this.menuItem.length - 1].path
              }
              this.dataSetCode = code
              this.$emit('getCurrentDataSetCode', code)
              // 存在重复文件
              if (res.data.isExist) {
                if (this.isAllCover === 1) { // 已选择全部替换
                  this.startUpload(file, false)
                  resolve()
                } else if (this.isAllCover === -1) { // 询问是否需要全部替换
                  this.$confirm('存在重复文件, 是否全部替换?', '提示', {
                    confirmButtonText: '全部替换',
                    cancelButtonText: '逐一替换',
                    type: 'warning'
                  }).then(() => {
                    this.isAllCover = 1
                    this.startUpload(file, false)
                    resolve()
                  }).catch(() => {
                    this.isAllCover = 0 // 选择逐一替换
                    this.$confirm(file.name + '已存在, 是否选择替换?', '提示', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning'
                    }).then(() => {
                      this.startUpload(file, false)
                      resolve()
                    }).catch(() => {
                      this.startUpload(file, true)
                      resolve()
                    });
                  });
                } else if (this.isAllCover === 0) {
                  this.$confirm(file.name + '已存在, 是否选择替换?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                  }).then(() => {
                    this.startUpload(file, false)
                    resolve()
                  }).catch(() => {
                    this.startUpload(file, true)
                    resolve()
                  });
                }
                // this.startUpload(file, res.data.isExist)
              } else {
                this.startUpload(file, res.data.isExist)
                this.$emit('deletePath', res.data.fileName)
                resolve()
              }

            }, 1000);
          } else {

          }
        })
          .catch(function (error) {
            console.log(error);
          });

      })


    },

相关推荐

  1. POST请求为什么会发送

    2024-04-21 16:54:07       41 阅读
  2. DELETE 请求,如何通过ajax进行发送

    2024-04-21 16:54:07       42 阅读
  3. C++发起Https请求

    2024-04-21 16:54:07       31 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-21 16:54:07       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-21 16:54:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-21 16:54:07       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-21 16:54:07       20 阅读

热门阅读

  1. 科目一笔记

    2024-04-21 16:54:07       19 阅读
  2. iOS知识点---Runloop

    2024-04-21 16:54:07       16 阅读
  3. P1990 覆盖墙壁

    2024-04-21 16:54:07       12 阅读
  4. Spring-Aop源码解析(中)

    2024-04-21 16:54:07       16 阅读
  5. ubuntu 22.04 -- cmake安装

    2024-04-21 16:54:07       13 阅读
  6. centos安装服务及设置自启动

    2024-04-21 16:54:07       13 阅读
  7. 产品经理常用工具汇总

    2024-04-21 16:54:07       14 阅读
  8. 网银快捷支付接口怎么申请!

    2024-04-21 16:54:07       11 阅读