diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index fe15d2db1..078c95b2a 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -89,6 +89,7 @@ defineExpose({ saveChanges, getChanges, formData, + vnPaginateRef, }); async function fetch(data) { @@ -271,8 +272,9 @@ function isEmpty(obj) { if (obj.length > 0) return false; } -async function reload() { - vnPaginateRef.value.fetch(); +async function reload(params) { + const data = await vnPaginateRef.value.fetch(params); + fetch(data); } watch(formUrl, async () => { @@ -284,10 +286,10 @@ watch(formUrl, async () => { - @@ -231,7 +232,9 @@ defineExpose({ :style="mode == 'table' && 'max-height: 92vh'" virtual-scroll @virtual-scroll=" - (event) => event.index > rows.length - 2 && VnPaginateRef.paginate() + (event) => + event.index > rows.length - 2 && + CrudModelRef.vnPaginateRef.paginate() " @row-click="(_, row) => rowClickFunction(row)" > @@ -421,7 +424,7 @@ defineExpose({ - + diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index c3b556e23..a188a5059 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -100,6 +100,11 @@ watch( } ); +watch( + () => store.data, + (data) => emit('onFetch', data) +); + const addFilter = async (filter, params) => { await arrayData.addFilter({ filter, params }); }; @@ -113,6 +118,7 @@ async function fetch(params) { isLoading.value = false; } emit('onFetch', store.data); + return store.data; } async function paginate() { @@ -144,6 +150,7 @@ function endPagination() { emit('onPaginate'); } async function onLoad(index, done) { + console.log('onLoad?'); if (!store.data) return done(); if (store.data.length === 0 || !props.url) return done(false); diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index c20260c59..6db4251e1 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -34,7 +34,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { delete params.filter; store.userParams = { ...params, ...store.userParams }; store.userFilter = { ...JSON.parse(filter), ...store.userFilter }; - console.log('store.userParams', store.userParams, store.userFilter); } }); @@ -126,7 +125,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { } function destroy() { - console.log('DESTROY', key); if (arrayDataStore.get(key)) { arrayDataStore.clear(key); } @@ -223,13 +221,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { ? path.replace(/\/(list|:id)|-list/, `/${store.data[0].id}`) : path.replace(/:id.*/, ''); - console.log('to: ', to, store.userParams, store.userFilter, route.query); if (route.path != to) { destroy(); const pushUrl = { path: to }; if (to.endsWith('/list') || to.endsWith('/')) pushUrl.query = newUrl.query; - console.log('pushUrl: ', to, pushUrl.query); return router.push(pushUrl); } }