From cc4295e7223c19be0891e3a8343a55ccad015b51 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 3 Jan 2025 15:40:19 +0100 Subject: [PATCH] feat: refs #8197 keepData in VnSection --- src/components/common/VnSection.vue | 5 +++++ src/components/ui/VnPaginate.vue | 9 ++------- src/composables/useArrayData.js | 1 + src/stores/useArrayDataStore.js | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/common/VnSection.vue b/src/components/common/VnSection.vue index 76856ef94..846717dc8 100644 --- a/src/components/common/VnSection.vue +++ b/src/components/common/VnSection.vue @@ -38,6 +38,10 @@ const $props = defineProps({ type: Boolean, default: true, }, + keepData: { + type: Boolean, + default: true, + }, }); const sectionValue = computed(() => $props.section ?? $props.dataKey); @@ -46,6 +50,7 @@ onBeforeMount(() => { if ($props.dataKey) arrayData = useArrayData($props.dataKey, { searchUrl: 'table', + keepData: $props.keepData, ...$props.arrayDataProps, navigate: $props.redirect, }); diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index ee6937add..5abb0d96c 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -111,14 +111,9 @@ onMounted(async () => { mounted.value = true; }); -// onBeforeRouteUpdate((to, from, next) => { -// if (to.name === from.name && to.path !== from.path) { -// arrayData.reset(['data']); -// } -// next(); -// }); - onBeforeUnmount(() => { + console.log('store.keepData: ', store.keepData); + if (!store.keepData) arrayData.reset(['data']); arrayData.resetPagination(); }); diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 1a91cc50b..720a1ec88 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -53,6 +53,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { 'searchUrl', 'navigate', 'mapKey', + 'keepData', ]; if (typeof userOptions === 'object') { for (const option in userOptions) { diff --git a/src/stores/useArrayDataStore.js b/src/stores/useArrayDataStore.js index e0d8b7929..8d62fdb4a 100644 --- a/src/stores/useArrayDataStore.js +++ b/src/stores/useArrayDataStore.js @@ -18,6 +18,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => { navigate: null, page: 1, mapKey: 'id', + keepData: false, }; function get(key) {