#8113 create arrayDataStore map #979

Closed
jorgep wants to merge 17 commits from 8113-preventDuplicateRecords into dev
1 changed files with 14 additions and 10 deletions
Showing only changes of commit 683940cc24 - Show all commits

View File

@ -124,24 +124,28 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
store.data = [];
store.map = new Map();
}
response.data.forEach((row) => {
const totalRows = store.data.length;
response.data.forEach((row, position) => {
const key = row.id;
const val = { ...row, key };
if (!store.map.has(key)) store.data.push({ ...row, key });
else {
const dataIndex = store.data.findIndex((item) => item.key === key);
store.data[dataIndex] = { ...row, key };
if (!store.map.has(key)) {
store.data.push({ ...val, position: totalRows + position });
} else {
const record = store.map.get(key);
const curPosition = record.position;
store.data[curPosition] = { ...val, position: curPosition };
}
store.map.set(key, row);
store.map.set(key, val);
});
} else {
store.data = [];
response.data.forEach((row) => {
response.data.forEach((row, position) => {
const key = row.id;
store.data.push({ ...row, key });
store.map.set(key, row);
const val = { ...row, key, position };
store.data.push(val);
store.map.set(key, val);
});
if (!isDialogOpened()) updateRouter && updateStateParams();
}