refactor: refs #8207 improve logic
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-11-22 15:37:48 +01:00
parent 0eeb22d40a
commit 661cc0b5ee
2 changed files with 12 additions and 12 deletions

View File

@ -132,8 +132,17 @@ const addFilter = async (filter, params) => {
async function fetch(params, keepRowsNumber = false) { async function fetch(params, keepRowsNumber = false) {
useArrayData(props.dataKey, params); useArrayData(props.dataKey, params);
if (!keepRowsNumber) arrayData.reset(['filter.skip', 'skip', 'page']); const { limit, skip } = arrayData.store;
await arrayData.fetch({ append: false, keepRowsNumber });
if (keepRowsNumber) {
arrayData.store.limit = limit + skip;
arrayData.store.skip = 0;
}
await arrayData.fetch({ append: false });
if (keepRowsNumber) {
arrayData.store.limit = limit;
arrayData.store.skip = skip;
}
if (!store.hasMoreData) isLoading.value = false; if (!store.hasMoreData) isLoading.value = false;
emit('onFetch', store.data); emit('onFetch', store.data);

View File

@ -64,11 +64,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
} }
} }
async function fetch({ async function fetch({ append = false, updateRouter = true }) {
append = false,
updateRouter = true,
keepRowsNumber = false,
}) {
if (!store.url) return; if (!store.url) return;
cancelRequest(); cancelRequest();
@ -111,11 +107,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
if (params.filter.where || exprFilter) if (params.filter.where || exprFilter)
params.filter.where = { ...params.filter.where, ...exprFilter }; params.filter.where = { ...params.filter.where, ...exprFilter };
if (keepRowsNumber) {
const { limit, skip } = store;
params.filter.limit = limit + skip;
params.filter.skip = 0;
}
params.filter = JSON.stringify(params.filter); params.filter = JSON.stringify(params.filter);
store.isLoading = true; store.isLoading = true;