From 0aefe13935990324420bcc5cc857da433dc7fbf2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 11 Oct 2023 10:40:13 +0200 Subject: [PATCH] ref #5417 fix autoload and filters --- src/components/ui/VnFilterPanel.vue | 7 +++++-- src/components/ui/VnPaginate.vue | 11 +---------- src/composables/useArrayData.js | 5 ++--- src/pages/Customer/CustomerPayments.vue | 3 +-- src/pages/Customer/CustomerPaymentsFilter.vue | 1 - 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 045b7c9a3..c7be929fb 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -51,7 +51,9 @@ async function search() { } isLoading.value = true; await arrayData.addFilter({ params }); - if (!props.showAll && !Object.values(params).length) store.data = []; + if (!props.showAll && !Object.values(userParams.value).find((param) => param)) { + store.data = []; + } isLoading.value = false; } @@ -59,7 +61,8 @@ async function reload() { isLoading.value = true; await arrayData.fetch({ append: false }); - if (!props.showAll && !Object.values(userParams.value).length) store.data = []; + if (!props.showAll && !Object.values(userParams.value).find((param) => param)) + store.data = []; isLoading.value = false; emit('refresh'); } diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index 6613f08fd..2475f56e9 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -50,10 +50,6 @@ const props = defineProps({ type: Boolean, default: true, }, - showAll: { - type: Boolean, - default: true, - }, }); const emit = defineEmits(['onFetch', 'onPaginate']); @@ -76,12 +72,7 @@ const arrayData = useArrayData(props.dataKey, { const store = arrayData.store; onMounted(() => { - if (props.autoLoad) { - if (props.showAll) fetch(); - else if (!props.showAll && Object.values(store.userParams).length) fetch(); - else if (!props.showAll && !Object.values(store.userParams).length) - store.data = []; - } + if (props.autoLoad) fetch(); }); watch( diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 7e0a07bb3..9aff0eaa8 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -135,9 +135,8 @@ export function useArrayData(key, userOptions) { await fetch({ append: true }); } - async function refresh(showAll = true) { - if (showAll || Object.values(store.userParams).length) - await fetch({ append: false }); + async function refresh() { + if (Object.values(store.userParams).length) await fetch({ append: false }); } function updateStateParams() { diff --git a/src/pages/Customer/CustomerPayments.vue b/src/pages/Customer/CustomerPayments.vue index 6452a5b55..405348f1b 100644 --- a/src/pages/Customer/CustomerPayments.vue +++ b/src/pages/Customer/CustomerPayments.vue @@ -144,8 +144,7 @@ function stateColor(row) { order="created DESC" :limit="20" :offset="50" - auto-load - :show-all="false" + :auto-load="!!$route?.query.params" >