refactor: refs #8113 fine tunning processData
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-11-25 16:48:49 +01:00
parent d1684b4ae6
commit e4bac3edab
2 changed files with 26 additions and 28 deletions

View File

@ -120,21 +120,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
const { limit } = filter;
store.hasMoreData = limit && response.data.length >= limit;
if (append) {
if (!store.data) {
store.data = [];
store.map = new Map();
}
mapData(response.data);
} else {
store.data = [];
mapData(response.data);
if (!isDialogOpened()) updateRouter && updateStateParams();
}
processData(response.data, { map: !!store.mapKey, append });
if (!append && !isDialogOpened()) updateRouter && updateStateParams();
store.isLoading = false;
canceller = null;
return response;
}
@ -293,22 +283,29 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
router.replace(newUrl);
}
function mapData(data) {
data.forEach((row) => {
const key = row[store.mapKey];
const val = { ...row, key };
function processData(data, { map = true, append = true }) {
if (!store.data) {
store.data = [];
store.map = new Map();
}
if (store.map.has(key)) {
const { position } = store.map.get(key);
val.position = position;
store.map.set(key, val);
store.data[position] = val;
} else {
val.position = store.map.size;
store.map.set(key, val);
store.data.push(val);
}
});
if (!map && !append) store.data = data;
else if (!map && append) store.data.push(...data);
else
data.forEach((row) => {
const key = row[store.mapKey];
const val = { ...row, key };
if (store.map.has(key)) {
const { position } = store.map.get(key);
val.position = position;
store.map.set(key, val);
store.data[position] = val;
} else {
val.position = store.map.size;
store.map.set(key, val);
store.data.push(val);
}
});
}
const totalRows = computed(() => (store.data && store.data.length) || 0);

View File

@ -441,6 +441,7 @@ watch(
<QPage class="column items-center q-pa-md">
<VnTable
data-key="advanceTickets"
:map-key="false"
ref="vnTableRef"
url="Tickets/getTicketsAdvance"
search-url="advanceTickets"