fix 81119

This commit is contained in:
danshihao
2024-01-22 18:46:20 +08:00
parent f834860c6c
commit 1b7720f487
2 changed files with 32 additions and 17 deletions
@@ -339,7 +339,7 @@ export default {
}
// 发起节点:通过表格中的员获取所属部门人稽查征求意见对象
if (this.isInitiate) {
const userList = this.$refs.inspectionPlanTable.dataSource.map(item => item.objectOfConsultation.split(',')).flat(Infinity)
const userList = this.$refs.inspectionPlanTable.getData().map(item => item.objectOfConsultation.split(',')).flat(Infinity)
personnelObj.opinionFillList = Array.from(new Set(userList)).filter(item => item)
}
}
@@ -382,10 +382,7 @@ export default {
}
const params = {}
// 业务表信息
params.processEsInspectPlanList = this.$refs.inspectionPlanTable.dataSource.map(item => {
delete item.createTime
return item
})
params.processEsInspectPlanList = this.$refs.inspectionPlanTable.getData()
// 获取删除业务信息的ids列表
params.processAllDelIds = this.$refs.inspectionPlanTable.getDelIds()
// 收集所有表单信息
@@ -18,7 +18,7 @@
:columns="columns"
:dataSource="dataSource"
:can-drag="true"
:rowKey="(_, index) => index"
rowKey="id"
:loading="loading"
:pagination="false"
:row-selection="hasTableOperator ? { selectedRowKeys: selectedRowKeys, onChange: onSelectChange, getCheckboxProps } : null"
@@ -76,6 +76,8 @@ import { EsInspectionPlan } from '@/enums/commonEnums'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import store from '@/store'
// 临时id前缀
const tempIdPrefix = 'tempId_'
let importModalLoading
export default {
name: 'InspectionPlanTable',
@@ -295,13 +297,9 @@ export default {
title: this.$t('confirmBatchDeletion'),
content: this.$t('deleteAData'),
onOk: () => {
// 将删除的id进行收集,提交节点的时候后端进行删除
this.selectedRowKeys.forEach(key => {
if (this.dataSource[key].id) {
this.delIds.push(this.dataSource[key].id)
}
})
this.dataSource = this.dataSource.filter((item, index) => !this.selectedRowKeys.includes(index))
// 收集除了前端生成的id
this.delIds.push(...this.selectedRowKeys.filter(item => !item.includes(tempIdPrefix)))
this.dataSource = this.dataSource.filter((item) => !this.selectedRowKeys.includes(item.id))
this.onClearSelected()
}
})
@@ -313,11 +311,13 @@ export default {
title: this.$t('confirmDeletion'),
content: this.$t('areYouSure'),
onOk: () => {
// 将删除的id进行收集,提交节点的时候后端进行删除
if (this.dataSource[index].id) {
// 将删除的id进行收集,提交节点的时候后端进行删除(非前端临时id)
const id = this.dataSource[index].id
if (id && !id.includes(tempIdPrefix)) {
this.delIds.push(this.dataSource[index].id)
}
this.dataSource.splice(index, 1)
this.onClearSelected()
}
})
},
@@ -332,12 +332,19 @@ export default {
this.$refs.modalForm.title = this.$t('edit')
this.$refs.modalForm.disableSubmit = false
},
// 临时生成前端id,提交后端前删除,作用是给rowKey唯一值,因为禁用选择使用下标会出错
generateTempId (index) {
// 用时间戳加行号,防止导入时同一个时间戳重复
return tempIdPrefix + +new Date() + '_' + index
},
// 添加或编辑回调
handleAddOrEditCallback (row, index) {
this.$message.success(this.$t('operationSuccessful'))
console.log('添加或编辑回调', row, index)
// index -1就是添加
if (index === undefined || index === -1) {
// 新增时手动添加前端id
row.id = this.generateTempId(this.dataSource.length)
this.dataSource.push(row)
} else {
this.dataSource.splice(index, 1, row)
@@ -361,7 +368,14 @@ export default {
return obj
},
getData () {
return this.dataSource
return this.dataSource.map(item => {
// 如果有前端生成的id,就把id去掉不给后端提交
if ((item.id + '').includes(tempIdPrefix)) {
delete item.id
}
delete item.createTime
return item
})
},
// 更新表格数据
updateData (list) {
@@ -440,7 +454,11 @@ export default {
}
// 前端存储
const data = info.file.response.result || []
this.dataSource.push(...data)
this.dataSource.push(...data.map((item, index) => {
// 导入的时候生成前端id,不用索引防止禁用出错
item.id = this.generateTempId(this.dataSource.length + index)
return item
}))
} else {
if (Array.isArray(info.file.response.result) && info.file.response.result.length > 0) {
this.messageLineFeed(this.$t('fileImportError'), info.file.response.result)