From a1284cefc2b62a53c634be9bf9b233a1ce9c8d42 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 25 Nov 2024 12:01:28 +0100 Subject: [PATCH] refactor: refs #8207 add update fn --- src/components/ui/VnPaginate.vue | 29 ++++++++++++--------- src/pages/Monitor/Ticket/MonitorTickets.vue | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index cc15ddb28..19c98e0cf 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -130,21 +130,26 @@ const addFilter = async (filter, params) => { await arrayData.addFilter({ filter, params }); }; -async function fetch(params, keepPagination = false) { +async function fetch(params) { useArrayData(props.dataKey, params); + arrayData.reset(['filter.skip', 'skip']); + await arrayData.fetch({ append: false }); + return emitStoreData(); +} - if (!keepPagination) await arrayData.fetch({ append: false }); - else { - const { limit, skip } = store; - store.limit = limit + skip; - store.skip = 0; - await arrayData.fetch({ append: false }); - store.limit = limit; - store.skip = skip; - } +async function update(params) { + useArrayData(props.dataKey, params); + const { limit, skip } = store; + store.limit = limit + skip; + store.skip = 0; + await arrayData.fetch({ append: false }); + store.limit = limit; + store.skip = skip; + return emitStoreData(); +} +function emitStoreData() { if (!store.hasMoreData) isLoading.value = false; - emit('onFetch', store.data); return store.data; } @@ -190,7 +195,7 @@ async function onLoad(index, done) { done(isDone); } -defineExpose({ fetch, addFilter, paginate }); +defineExpose({ fetch, update, addFilter, paginate });