导入去重

This commit is contained in:
NiSen
2023-07-20 10:31:37 +08:00
parent 0bfc219e0d
commit 543235673e

View File

@@ -347,6 +347,23 @@ const closeModal = () => {
state.importId = '',
state.AMvisible = false
}
// 根据数组id去重
const deduplicateArrayById = (arr) => {
// 使用 Set 数据结构保存不重复的 id
const idSet = new Set();
// 使用 map 方法遍历数组,检查并去重对象
const deduplicatedArray = arr.filter(obj => {
const id = obj.id;
if (!idSet.has(id)) {
idSet.add(id);
return true;
}
return false;
});
return deduplicatedArray;
}
//上传文件
const handleChange = (info) => {
@@ -389,9 +406,7 @@ const handleChange = (info) => {
state.caseTitleList = caseList
state.selectedRowKeys = [...new Set([...caseIdList, ...state.selectedRowKeys])]
state.selectedRow = [...new Set([...state.selectedRow, ...caseList].map(t => JSON.stringify(t)))].map(s => JSON.parse(s))
// state.selectedRow.push(...caseList)
// state.selectedRow = Array.from(new Set(state.selectedRow.map(JSON.stringify))).map(JSON.parse);
state.selectedRow = deduplicateArrayById([...state.selectedRow, ...caseList]);
console.log(caseList, state.selectedRow);
//发请求看失败的数据