diff --git a/src/components/Template/HandleFormItem.vue b/src/components/Template/HandleFormItem.vue index 4486c2c..a1c7d57 100644 --- a/src/components/Template/HandleFormItem.vue +++ b/src/components/Template/HandleFormItem.vue @@ -55,7 +55,6 @@ f !== file && f.status === 'success'); + if (existingFiles.length > 0) { + // 保存待上传的文件信息 + this.pendingUploadFile = file; + + // 从fileList中暂时移除新文件,等待签名验证 + const index = fileList.indexOf(file); + if (index > -1) { + fileList.splice(index, 1); + } + this.fileList = [...fileList]; + + // 触发电子签名弹窗 + EventBus.$emit('showEditSignDialog', { uuid: this.uuid }); + return; + } + + // 没有现有文件或验证通过,手动提交上传 this.$nextTick(() => { // 找到对应的upload组件并提交 const uploadComponent = this.$refs.uploadRef; @@ -338,20 +351,50 @@ export default { }) return list; }, + // 删除前验证电子签名 + beforeRemove(file) { + // 所有删除操作都需要验证电子签名 + // 保存待删除的文件信息 + this.pendingRemoveFile = { file, fileList: this.fileList }; + + // 触发电子签名弹窗 + EventBus.$emit('showEditSignDialog', { uuid: this.uuid }); + + // 返回false阻止默认删除行为,等待签名验证通过后再删除 + return false; + }, handleRemove(file, fileList) { - // 从列表中移除文件 + // on-remove事件在before-remove返回false时不会触发 + // 这个方法在签名验证通过后通过executeRemove调用 + // 这里不需要额外处理,因为executeRemove已经处理了删除逻辑 + }, + // 执行实际的文件删除操作 + executeRemove(file, fileList) { + // 从el-upload的内部uploadFiles中移除文件 + const uploadComponent = this.$refs.uploadRef; + if (uploadComponent && uploadComponent.uploadFiles) { + const uploadFileIndex = uploadComponent.uploadFiles.indexOf(file); + if (uploadFileIndex > -1) { + uploadComponent.uploadFiles.splice(uploadFileIndex, 1); + } + } + + // 从fileList中移除文件 const index = fileList.indexOf(file); if (index > -1) { fileList.splice(index, 1); } - + + // 更新fileList + this.fileList = [...fileList]; + // 更新inputValue为剩余文件路径列表 this.inputValue = JSON.stringify(this.getFileList(fileList)); - this.$emit("change",this.inputValue) - + this.$emit("change", this.inputValue); + // 触发保存记录 this.onCommonHandleSaveRecord(); - + this.$message.success(`文件 ${file.name} 已移除`); }, handlePreview(file) { @@ -456,7 +499,17 @@ export default { // 处理电子签名取消事件 handleEditSignCancel(data) { if (data.uuid === this.uuid) { - this.resetRecord(); + // 如果有待上传的文件,清空它 + if (this.pendingUploadFile) { + this.pendingUploadFile = null; + this.$message.info('已取消文件上传'); + } else if (this.pendingRemoveFile) { + // 如果有待删除的文件,清空它 + this.pendingRemoveFile = null; + this.$message.info('已取消文件删除'); + } else { + this.resetRecord(); + } } }, // 处理电子签名确认回调事件 @@ -466,7 +519,37 @@ export default { } }, onEditSignSave(data) { - this.handleUpdateRecord(data) + // 检查是否有待上传的文件 + if (this.pendingUploadFile) { + // 签名验证通过,将文件添加到列表并上传 + const file = this.pendingUploadFile; + + // 将文件添加到 fileList + this.fileList.push(file); + + // 清空待上传文件标记 + this.pendingUploadFile = null; + + // 手动触发上传 + this.$nextTick(() => { + const uploadComponent = this.$refs.uploadRef; + if (uploadComponent) { + uploadComponent.submit(); + } + }); + } else if (this.pendingRemoveFile) { + // 签名验证通过,执行文件删除 + const { file, fileList } = this.pendingRemoveFile; + + // 清空待删除文件标记 + this.pendingRemoveFile = null; + + // 执行删除操作 + this.executeRemove(file, fileList); + } else { + // 没有待上传/删除文件,执行正常的记录更新 + this.handleUpdateRecord(data); + } }, getChecked() { return !!this.getFieldCheckObj()[this.fieldKey]?.checked;