生成时间: 2026-08-03 · 数据来源: xnybw平台需求及工作计划.xlsx(南网在线绿能云缺陷跟踪表)· 仅针对 backup730/730backup 分支代码

Row 76 · 附件删除有时成功有时失败但仍提示成功,重新删除报错 2.1.待开发

一级模块项目信息填报
涉及类型全部类型
状态2.1.待开发

问题描述:上传的附件点击删除按钮进行删除,有些时候删除成功,有些时候显示删除成功之后,页面自动刷新但是附件还是存在,重新点击删除之后报错。

旧代码涉及的项目文件名及对应行数

xnybw5f/src/views/projectNew/components/baseInfo/components/batchInfo.vue 第 2720-2751 行 delFile(item, id)

delFile(item, id) {
  this.checkInformation = item
  this.$confirm('此操作将永久删除该文件, 是否继续?', ...).then(() => {
    this.loading = true
    projectGridApi.deleteFile({ fileId: id }).then(async res => {
      this.refreshInformationFlow()
      this.loading = false
      this.$message({ message: '删除成功', type: 'success' })   // ← 未检查 res.code / res.success
    }, () => { this.$message.error('删除失败'); this.loading = false })
    .catch(() => { this.$message.error('删除失败'); this.loading = false })
  })
}

.then(async res => {...}) 是 axios/接口调用 Promise resolve 时的回调——只要 HTTP 请求本身没有网络错误、没有走 .catch,无论后端返回的业务 code 是成功还是失败,前端都会无条件弹"删除成功"并调用 refreshInformationFlow() 刷新列表。如果后端因为文件被其他流程节点占用、并发修改冲突等原因返回了"业务失败"但 HTTP 状态码仍是 200,就会出现"提示删除成功,刷新后文件其实还在"的现象。

"重新点击删除之后报错"则很可能是:第一次删除请求其实部分执行了(比如文件流转记录已更新但物理文件/关联记录没删干净),导致第二次删除时后端命中了一个未预期的状态分支,抛出异常。

修复代码涉及的项目文件名及行数

xnybw5f/src/views/projectNew/components/baseInfo/components/batchInfo.vue 第 2731-2737 行

修复方案

// 建议修改:先判断业务 code,再决定提示内容
projectGridApi.deleteFile({ fileId: id }).then(async res => {
  this.loading = false
  if (res && (res.code === '0' || res.code === 0)) {
    this.refreshInformationFlow()
    this.$message({ message: '删除成功', type: 'success' })
  } else {
    this.$message.error(res && res.msg ? res.msg : '删除失败,请稍后重试')
    // 业务失败时也建议刷新一次,让列表状态和后端保持一致,避免用户带着过期的按钮状态继续操作
    this.refreshInformationFlow()
  }
}, () => { this.$message.error('删除失败'); this.loading = false })
.catch(() => { this.$message.error('删除失败'); this.loading = false })

另外建议排查后端 deleteFile 接口本身在并发/重复调用下是否幂等(同一 fileId 删两次是否会报错而不是静默忽略),这块后端接口具体实现未在本次代码定位范围内确认,建议结合接口返回的具体报错信息进一步排查。