refs #5673 feat(crudModel): add saveFn prop
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ea8a7de6d2
commit
52fcbdb689
|
@ -53,6 +53,10 @@ const $props = defineProps({
|
|||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
saveFn: {
|
||||
type: Function,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const isLoading = ref(false);
|
||||
|
@ -83,6 +87,7 @@ onUnmounted(() => {
|
|||
function tMobile(...args) {
|
||||
if (!quasar.platform.is.mobile) return t(...args);
|
||||
}
|
||||
|
||||
async function fetch(data) {
|
||||
if (data && Array.isArray(data)) {
|
||||
let $index = 0;
|
||||
|
@ -128,17 +133,18 @@ async function onSubmit() {
|
|||
}
|
||||
|
||||
async function saveChanges(data) {
|
||||
if ($props.saveFn) return $props.saveFn(data, getChanges);
|
||||
const changes = data || getChanges();
|
||||
try {
|
||||
await axios.post($props.saveUrl || $props.url + '/crud', changes);
|
||||
} catch (e) {
|
||||
return (isLoading.value = false);
|
||||
}
|
||||
|
||||
originalData.value = JSON.parse(JSON.stringify(formData.value));
|
||||
if (changes.creates?.length) await vnPaginateRef.value.fetch();
|
||||
|
||||
hasChanges.value = false;
|
||||
isLoading.value = false;
|
||||
if (changes.creates?.length) await vnPaginateRef.value.fetch();
|
||||
}
|
||||
|
||||
async function insert() {
|
||||
|
@ -249,12 +255,9 @@ watch(formUrl, async () => {
|
|||
</script>
|
||||
<template>
|
||||
<VnPaginate
|
||||
@submit="onSubmit"
|
||||
@reset="reset"
|
||||
:url="url"
|
||||
v-bind="$attrs"
|
||||
@on-fetch="fetch"
|
||||
class="q-pa-md"
|
||||
:skeleton="false"
|
||||
ref="vnPaginateRef"
|
||||
>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<script setup>
|
||||
import axios from 'axios';
|
||||
import { ref, onMounted, computed, onUpdated } from 'vue';
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import CardSummary from 'components/ui/CardSummary.vue';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||
import { createWrapper } from 'app/test/vitest/helper';
|
||||
import CrudModel from 'components/CrudModel.vue';
|
||||
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
|
||||
|
||||
|
@ -95,28 +95,6 @@ describe('CrudModel', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// TODO: test .onOk()
|
||||
describe('remove()', () => {
|
||||
it('should remove', async () => {
|
||||
vi.spyOn(vm.quasar, 'dialog');
|
||||
|
||||
vm.originalData = [
|
||||
{ id: 1, name: 'Tony Starks', $index: 1 },
|
||||
{ id: 2, name: 'Jessica Jones', $index: 2 },
|
||||
{ id: 3, name: 'Bruce Wayne', $index: 3 },
|
||||
];
|
||||
vm.state.set('crudModel', [
|
||||
{ id: 1, name: 'New name one', $index: 1 },
|
||||
{ id: 2, name: 'New name two', $index: 2 },
|
||||
{ id: 3, name: 'Bruce Wayne', $index: 3 },
|
||||
]);
|
||||
|
||||
await vm.remove([{ id: 1 }]);
|
||||
|
||||
expect(vm.quasar.dialog).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDifferences()', () => {
|
||||
it('should return the differences between two objects', async () => {
|
||||
const obj1 = {
|
||||
|
|
Loading…
Reference in New Issue