From 522f32aa9a696c4d4fb7dfd8b5c3f215bb373205 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 22 Nov 2024 10:40:49 +0100 Subject: [PATCH] fix: orderCatalogFilter and fix useArrayData --- src/components/ui/VnFilterPanel.vue | 6 +- src/composables/useArrayData.js | 38 +++++---- src/pages/Order/Card/OrderCatalog.vue | 31 +------- src/pages/Order/Card/OrderCatalogFilter.vue | 86 ++++++++------------- 4 files changed, 63 insertions(+), 98 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 1ed1194ea..b9aa5e114 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -57,7 +57,6 @@ const $props = defineProps({ }, }); -defineExpose({ search, sanitizer }); const emit = defineEmits([ 'update:modelValue', 'refresh', @@ -76,6 +75,9 @@ const arrayData = useArrayData($props.dataKey, { const route = useRoute(); const store = arrayData.store; const userParams = ref({}); + +defineExpose({ search, sanitizer, params: userParams }); + onMounted(() => { userParams.value = $props.modelValue ?? {}; emit('init', { params: userParams.value }); @@ -179,7 +181,7 @@ const customTags = computed(() => async function remove(key) { userParams.value[key] = undefined; - search(); + await search(); emit('remove', key); emit('update:modelValue', userParams.value); } diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 7fce714fc..b37fa1377 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -74,18 +74,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { limit: store.limit, }; - let exprFilter; let userParams = { ...store.userParams }; - if (store?.exprBuilder) { - const where = buildFilter(userParams, (param, value) => { - const res = store.exprBuilder(param, value); - if (res) delete userParams[param]; - return res; - }); - exprFilter = where ? { where } : null; - } - Object.assign(filter, store.userFilter, exprFilter); + Object.assign(filter, store.userFilter); + let where; if (filter?.where || store.filter?.where) where = Object.assign(filter?.where ?? {}, store.filter?.where ?? {}); @@ -94,12 +86,29 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const params = { filter }; Object.assign(params, userParams); - params.filter.skip = store.skip; - if (store.order && store.order.length) params.filter.order = store.order; + if (params.filter) params.filter.skip = store.skip; + if (store?.order && typeof store?.order == 'string') store.order = [store.order]; + if (store.order?.length) params.filter.order = [...store.order]; else delete params.filter.order; + store.currentFilter = JSON.parse(JSON.stringify(params)); + delete store.currentFilter.filter.include; + store.currentFilter.filter = JSON.stringify(store.currentFilter.filter); + + let exprFilter; + if (store?.exprBuilder) { + exprFilter = buildFilter(params, (param, value) => { + if (param == 'filter') return; + const res = store.exprBuilder(param, value); + if (res) delete params[param]; + return res; + }); + } + + if (params.filter.where || exprFilter) + params.filter.where = { ...params.filter.where, ...exprFilter }; params.filter = JSON.stringify(params.filter); - store.currentFilter = params; + store.isLoading = true; const response = await axios.get(store.url, { signal: canceller.signal, @@ -249,7 +258,8 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { function updateStateParams() { if (!route?.path) return; const newUrl = { path: route.path, query: { ...(route.query ?? {}) } }; - newUrl.query[store.searchUrl] = JSON.stringify(store.currentFilter); + if (store?.searchUrl) + newUrl.query[store.searchUrl] = JSON.stringify(store.currentFilter); if (store.navigate) { const { customRouteRedirectName, searchText } = store.navigate; diff --git a/src/pages/Order/Card/OrderCatalog.vue b/src/pages/Order/Card/OrderCatalog.vue index 66a1a132d..90bce38fd 100644 --- a/src/pages/Order/Card/OrderCatalog.vue +++ b/src/pages/Order/Card/OrderCatalog.vue @@ -1,14 +1,13 @@