入伍和外宿申请-已办任务的详情表单数据哦

This commit is contained in:
2025-12-16 10:49:40 +08:00
parent 0ffbd2d804
commit 6ee21d3d98
4 changed files with 235 additions and 46 deletions

View File

@@ -112,7 +112,7 @@
<!-- 佐证附件 -->
<el-descriptions-item label="佐证附件" required>
<el-form-item prop="affixId" class="no-label-form-item">
<AffixIndex ref="affixComponent" v-model="form.affixId" @input="handleAffix" @fileUploaded="handleAffix"
<AffixIndex ref="affixComponent" v-model="form.affixId" @input="getffix" @fileUploaded="handleAffix"
@delete-file="handleDeleteFile" />
<div class="el-upload__tip">
支持上传jpg/png/pdf格式文件单个文件不超过10MB如病例住房证明等
@@ -408,7 +408,7 @@ export default {
promiseDate: [{ required: true, message: '请选择签署日期', trigger: 'change' }],
studentSignature: [{ required: true, message: '请完成电子签名', trigger: 'change' }],
studentPromiseSign: [{ required: true, message: '请完成承诺签名', trigger: 'change' }],
// affixId: [{ required: true, message: '请上传佐证材料', trigger: 'change' }],
affixId: [{ required: true, message: '请上传佐证材料', trigger: 'change' }],
parentSignAttachment: [
{
required: true,
@@ -771,28 +771,35 @@ export default {
this.clearStudentCanvas()
this.clearPromiseCanvas()
},
// 处理 AffixIndex 组件回传:既支持 v-model 返回的 affixId也支持文件信息对象
getffix(affixId) {
this.form.affixId = affixId
},
// 处理 AffixIndex 组件回传:支持文件信息对象
handleAffix(payload) {
if (typeof payload === 'string' || typeof payload === 'number') {
this.form.affixId = payload
return
}
// if (typeof payload === 'string' || typeof payload === 'number') {
// this.form.affixId = payload
// return
// }
const fileInfo = payload
if (!fileInfo || !fileInfo.fileName || !fileInfo.filePath) {
this.$message.warning('附件标识异常或文件信息缺失,请重新上传')
return
}
// 构建与后端实体匹配的data对象
const data = {
applyId: this.form.id || null,
attachmentName: fileInfo.fileName,
attachmentUrl: fileInfo.filePath,
filePath: fileInfo.filePath,
fileSize: fileInfo.originalFile?.size || 0,
fileSuffix: fileInfo.fileType,
processInstanceId: this.form.processInstanceId || '',
studentName: this.form.studentName || '',
studentNo: this.form.studentNo || ''
}
// id: null, // 主键(后端自增)
applyId: this.form.id || null, // 关联申请表ID从主表单获取
attachmentName: fileInfo.fileName, // 文件名(从组件传递的信息中获取)
attachmentUrl: fileInfo.filePath, // 文件路径相对路径关联sys_file表
filePath: fileInfo.filePath, // 文件路径相对路径关联sys_file表
fileSize: fileInfo.originalFile?.size || 0, // 若需要可从fileInfo.originalFile.size获取单位字节
fileSuffix: fileInfo.fileType, // 文件类型如docx、pdf
processInstanceId: this.form.processInstanceId || '', // 申请编号(从主表单获取)
studentName: this.form.studentName || '', // 学生姓名(从主表单获取)
studentNo: this.form.studentNo || '' // 学号(从主表单获取)
}
// 避免重复添加根据filePath去重
const isDuplicate = this.reasonFileList.some((item) => item.filePath === data.filePath)
if (isDuplicate) {
this.$message.warning('该文件已添加,请勿重复上传')

View File

@@ -104,6 +104,22 @@ export default {
this.loadData(newVal)
}
}
},
// 关键监听affixId变化确保外部能捕获
affixId: {
immediate: true,
handler(newVal, oldVal) {
if (newVal !== oldVal || newVal) {
// 使用$nextTick确保DOM更新后再emit
this.$nextTick(() => {
this.$emit('input', newVal)
// 额外触发change事件方便外部监听
this.$emit('affixId-change', newVal)
// 更新v-model绑定兼容不同Vue版本
this.$emit('update:value', newVal)
})
}
}
}
},
beforeUnmount() {
@@ -119,22 +135,29 @@ export default {
},
isImageURL(url) {
// 修复正则:原正则会匹配以这些字符结尾,但写法有问题(少了\.
// 正则:原正则会匹配以这些字符结尾
const regex = /(\.jpg|\.jpeg|\.png|\.gif|\.webp)$/i
return regex.test(url)
},
// 处理上传请求(改为加入队列
// 处理上传请求(修复队列立即执行逻辑
handleUpload(file) {
// 生成统一的UID确保和beforeUpload中的UID一致
const fileUid = file.file.uid || Date.now() + Math.random()
file.file.uid = fileUid
// 将文件加入上传队列
this.uploadQueue.push(file)
// 若未在上传,则执行队列
if (!this.isUploading) {
this.processUploadQueue()
}
// 立即执行队列(修复第一次上传不触发的问题)
this.$nextTick(() => {
if (!this.isUploading) {
this.processUploadQueue()
}
})
},
// 串行处理上传队列(核心修复并发问题)
// 串行处理上传队列(核心修复第一次上传问题)
async processUploadQueue() {
// 队列为空则结束
if (this.uploadQueue.length === 0) {
@@ -146,17 +169,12 @@ export default {
this.isUploading = true
// 取出队列第一个文件
const file = this.uploadQueue.shift()
const currentFileUid = file.file.uid || Date.now() + Math.random()
// 使用文件自带的UID和beforeUpload中保持一致
const currentFileUid = file.file.uid
// 确保affixId存在
if (!this.affixId) {
this.affixId = this.$tool.uuid()
// 若后端需要先创建affix主记录取消注释并调整根据实际情况
// await this.createAffixRecord(this.affixId)
this.$nextTick(() => {
this.$emit('input', this.affixId)
this.$emit('change', this.affixId)
})
}
try {
@@ -165,7 +183,7 @@ export default {
this.uploadCnt--
if (res.code === 200) {
// 通过uid匹配文件解决同名文件问题)
// 通过uid匹配文件修复匹配不到的问题)
const fileIndex = this.fileList.findIndex(item =>
item.uid === currentFileUid && item.status === 1
)
@@ -173,13 +191,13 @@ export default {
if (fileIndex > -1) {
const savePath = this.baseurl + res.savePath
// 更新文件信息
this.fileList[fileIndex] = {
this.fileList.splice(fileIndex, 1, {
...this.fileList[fileIndex],
id: res.id,
status: 2,
savePath: savePath,
trueName: res.trueName
}
})
// 预览列表去重添加
if (this.isImageURL(savePath) && !this.previewList.includes(savePath)) {
@@ -201,6 +219,9 @@ export default {
fileList: JSON.parse(JSON.stringify(this.fileList)),
previewList: JSON.parse(JSON.stringify(this.previewList))
}
// 强制更新视图
this.$forceUpdate()
}
} else {
this.$message.error(res.message || '上传失败')
@@ -236,7 +257,7 @@ export default {
}
}
// 处理下一个文件
// 立即处理下一个文件(移除异步延迟)
this.processUploadQueue()
},
@@ -247,6 +268,7 @@ export default {
)
if (fileIndex > -1) {
this.fileList.splice(fileIndex, 1)
this.$forceUpdate() // 确保视图更新
}
},
@@ -254,6 +276,7 @@ export default {
async createAffixRecord(affixId) {
try {
// await createAffix({ affixId: affixId })
// 创建成功后自动触发watch
} catch (err) {
this.$message.error('创建附件记录失败:' + err.message)
}
@@ -269,10 +292,6 @@ export default {
// 生成affixId若不存在
if (!this.affixId) {
this.affixId = this.$tool.uuid()
// 若后端需要先创建affix主记录取消注释
// this.createAffixRecord(this.affixId).then(() => {
// this.$emit('input', this.affixId)
// })
}
// 校验文件大小
@@ -281,15 +300,26 @@ export default {
this.$message.error(`上传大小不能超过 ${this.maxSize}MB!`)
return false // 显式阻止上传
} else {
// 为文件添加唯一标识uid解决同名文件匹配问题
// 生成统一的UID确保和handleUpload中一致
const fileUid = file.uid || Date.now() + Math.random()
this.fileList.push({
file.uid = fileUid
// 立即添加文件到列表(确保视图能及时显示)
const newFile = {
name: file.name,
status: 1,
uid: fileUid,
rawFile: file
})
}
// 先清空同名未上传文件(避免重复)
this.fileList = this.fileList.filter(item => !(item.name === file.name && item.status === 1))
this.fileList.push(newFile)
// 立即更新视图
this.$forceUpdate()
this.uploadCnt++
return true
}
},
@@ -355,7 +385,6 @@ export default {
if (this.fileList.length === 0) {
delete this.cacheData[this.affixId]
this.affixId = ''
this.$emit('input', '')
} else {
// 更新缓存(深拷贝)
this.cacheData[this.affixId] = {
@@ -365,6 +394,7 @@ export default {
}
// 触发删除事件
this.$emit('delete-file', file.name)
this.$forceUpdate()
} else {
this.$message.error(res.message || '删除失败')
}
@@ -455,7 +485,23 @@ export default {
this.isUploading = false
// 清空缓存
delete this.cacheData[this.affixId]
this.$emit('input', '')
},
// 手动获取affixId的方法供外部调用
getAffixId() {
return new Promise((resolve) => {
if (this.affixId) {
resolve(this.affixId)
} else {
// 监听affixId变化直到有值
const unwatch = this.$watch('affixId', (newVal) => {
if (newVal) {
resolve(newVal)
unwatch() // 取消监听
}
}, { immediate: true })
}
})
}
}
}