diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 2e580257c..3842ff947 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -97,7 +97,7 @@ const $props = defineProps({ }); const emit = defineEmits(['onFetch', 'onDataSaved']); const modelValue = computed( - () => $props.model ?? `formModel_${route?.meta?.title ?? route.name}` + () => $props.model ?? `formModel_${route?.meta?.title ?? route.name}`, ).value; const componentIsRendered = ref(false); const arrayData = useArrayData(modelValue); @@ -136,7 +136,8 @@ onMounted(async () => { if (!$props.formInitialData) { if ($props.autoLoad && $props.url) await fetch(); - else if (arrayData.store.data) updateAndEmit('onFetch', arrayData.store.data); + else if (arrayData.store.data) + updateAndEmit('onFetch', { val: arrayData.store.data }); } if ($props.observeFormChanges) { watch( @@ -148,7 +149,7 @@ onMounted(async () => { JSON.stringify(newVal) !== JSON.stringify(originalData.value); isResetting.value = false; }, - { deep: true } + { deep: true }, ); } }); @@ -156,7 +157,7 @@ onMounted(async () => { if (!$props.url) watch( () => arrayData.store.data, - (val) => updateAndEmit('onFetch', val) + (val) => updateAndEmit('onFetch', { val }), ); watch( @@ -165,7 +166,7 @@ watch( originalData.value = null; reset(); await fetch(); - } + }, ); onBeforeRouteLeave((to, from, next) => { @@ -194,7 +195,7 @@ async function fetch() { }); if (Array.isArray(data)) data = data[0] ?? {}; - updateAndEmit('onFetch', data); + updateAndEmit('onFetch', { val: data }); } catch (e) { state.set(modelValue, {}); originalData.value = {}; @@ -222,7 +223,11 @@ async function save() { if ($props.urlCreate) notify('globals.dataCreated', 'positive'); - updateAndEmit('onDataSaved', formData.value, response?.data); + updateAndEmit('onDataSaved', { + val: formData.value, + res: response?.data, + old: originalData.value, + }); if ($props.reload) await arrayData.fetch({}); hasChanges.value = false; } finally { @@ -236,7 +241,7 @@ async function saveAndGo() { } function reset() { - updateAndEmit('onFetch', originalData.value); + updateAndEmit('onFetch', { val: originalData.value }); if ($props.observeFormChanges) { hasChanges.value = false; isResetting.value = true; @@ -254,16 +259,16 @@ function filter(value, update, filterOptions) { (ref) => { ref.setOptionIndex(-1); ref.moveOptionSelection(1, true); - } + }, ); } -function updateAndEmit(evt, val, res) { +function updateAndEmit(evt, { val, res, old } = { val: null, res: null, old: null }) { state.set(modelValue, val); originalData.value = val && JSON.parse(JSON.stringify(val)); if (!$props.url) arrayData.store.data = val; - emit(evt, state.get(modelValue), res); + emit(evt, state.get(modelValue), res, old); } function trimData(data) { diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index 6e5f9fef4..96b2c7ca2 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -485,7 +485,7 @@ function cardClick(_, row) { flat dense :class=" - btn.isPrimary ? 'text-primary-light' : 'color-vn-text ' + btn.isPrimary ? 'text-primary-light' : 'color-vn-label' " :style="`visibility: ${ ((btn.show && btn.show(row)) ?? true) @@ -510,7 +510,7 @@ function cardClick(_, row) {