refactor: loading wthen action submit

This commit is contained in:
katherinehhh 2023-04-04 11:00:42 +08:00 committed by chenos
parent 83daf55741
commit 28ef3b6952

View File

@ -1,6 +1,6 @@
import { PlusOutlined } from '@ant-design/icons';
import { ArrayTable } from '@formily/antd';
import { useForm } from '@formily/react';
import { useForm, useField } from '@formily/react';
import { uid } from '@formily/shared';
import { Button } from 'antd';
import { cloneDeep } from 'lodash';
@ -130,15 +130,19 @@ const useSyncFromDatabase = () => {
const { targetKey } = useResourceContext();
const { [targetKey]: filterByTk } = useRecord();
const api = useAPIClient();
const field = useField();
return {
async run() {
await form.submit();
field.data = field.data || {};
field.data.loading = true;
await api.resource(`collections`).setFields({
filterByTk,
values: form.values,
});
ctx.setVisible(false);
await form.reset();
field.data.loading = false;
refresh();
await refreshCM();
},