From 3dd2745dde75d1c179b3d6e9f663a0f363321b91 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 5 Jul 2024 15:56:57 +0200 Subject: [PATCH] fix: refs #7197 rollback crudModel --- src/components/CrudModel.vue | 39 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index bd32972da..9fc249380 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -10,7 +10,6 @@ import VnPaginate from 'components/ui/VnPaginate.vue'; import VnConfirm from 'components/ui/VnConfirm.vue'; import SkeletonTable from 'components/ui/SkeletonTable.vue'; import { tMobile } from 'src/composables/tMobile'; -import VnSubToolbar from './ui/VnSubToolbar.vue'; const { push } = useRouter(); const quasar = useQuasar(); @@ -68,7 +67,7 @@ const $props = defineProps({ default: '', description: 'It is used for redirect on click "save and continue"', }, - hasSubToolbar: { + hasSubtoolbar: { type: Boolean, default: true, }, @@ -80,6 +79,7 @@ const originalData = ref(); const vnPaginateRef = ref(); const formData = ref(); const saveButtonRef = ref(null); +const watchChanges = ref(); const formUrl = computed(() => $props.url); const emit = defineEmits(['onFetch', 'update:selected', 'saveChanges']); @@ -94,6 +94,7 @@ defineExpose({ saveChanges, getChanges, formData, + vnPaginateRef, }); onBeforeRouteLeave((to, from, next) => { @@ -115,19 +116,26 @@ async function fetch(data) { data.map((d) => (d.$index = $index++)); } - originalData.value = data && JSON.parse(JSON.stringify(data)); - formData.value = data && JSON.parse(JSON.stringify(data)); - watch(formData, () => (hasChanges.value = true), { deep: true }); + resetData(data); emit('onFetch', data); return data; } +function resetData(data) { + if (!data) return; + originalData.value = JSON.parse(JSON.stringify(data)); + formData.value = JSON.parse(JSON.stringify(data)); + + if (watchChanges.value) watchChanges.value(); //destoy watcher + watchChanges.value = watch(formData, () => (hasChanges.value = true), { deep: true }); +} + async function reset() { await fetch(originalData.value); hasChanges.value = false; } -// eslint-disable-next-line vue/no-dupe-keys + function filter(value, update, filterOptions) { update( () => { @@ -153,7 +161,7 @@ async function onSubmit() { await saveChanges($props.saveFn ? formData.value : null); } -async function onSubmitAndGo() { +async function onSumbitAndGo() { await onSubmit(); push({ path: $props.goTo }); } @@ -289,8 +297,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 () => { @@ -302,10 +311,11 @@ watch(formUrl, async () => { - - + + { />