fix: button loading does not disappear when the operation submit failed (#1698)

* fix: button loading does not disappear when the view operation submission failed

* fix: add field button loading

* refactor: code improve
This commit is contained in:
katherinehhh 2023-04-17 17:20:35 +08:00 committed by GitHub
parent 12f95810d0
commit eeb07112c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 38 deletions

View File

@ -201,30 +201,35 @@ const useCreateCollection = (schema?: any) => {
async run() {
field.data = field.data || {};
field.data.loading = true;
await form.submit();
const values = cloneDeep(form.values);
if (schema?.events?.beforeSubmit) {
schema.events.beforeSubmit(values);
try {
await form.submit();
const values = cloneDeep(form.values);
if (schema?.events?.beforeSubmit) {
schema.events.beforeSubmit(values);
}
const fields = values?.template !== 'view' ? useDefaultCollectionFields(values) : values.fields;
if (values.autoCreateReverseField) {
} else {
delete values.reverseField;
}
delete values.id;
delete values.autoCreateReverseField;
await resource.create({
values: {
logging: true,
...values,
fields,
},
});
ctx.setVisible(false);
await form.reset();
field.data.loading = false;
refresh();
await refreshCM();
} catch (error) {
field.data.loading = false;
}
const fields = values?.template !== 'view' ? useDefaultCollectionFields(values) : values.fields;
if (values.autoCreateReverseField) {
} else {
delete values.reverseField;
}
delete values.id;
delete values.autoCreateReverseField;
await resource.create({
values: {
logging: true,
...values,
fields,
},
});
ctx.setVisible(false);
await form.reset();
field.data.loading = false;
refresh();
await refreshCM();
},
};
};

View File

@ -148,12 +148,16 @@ const useCreateCollectionField = () => {
delete values.reverseField;
}
delete values.autoCreateReverseField;
await resource.create({ values });
ctx.setVisible(false);
await form.reset();
field.data.loading = false;
refresh();
await refreshCM();
try {
await resource.create({ values });
ctx.setVisible(false);
await form.reset();
field.data.loading = false;
refresh();
await refreshCM();
} catch (error) {
field.data.loading = false;
}
},
};
};

View File

@ -136,15 +136,19 @@ const useSyncFromDatabase = () => {
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();
try {
await api.resource(`collections`).setFields({
filterByTk,
values: form.values,
});
ctx.setVisible(false);
await form.reset();
field.data.loading = false;
refresh();
await refreshCM();
} catch (error) {
field.data.loading = false;
}
},
};
};