feat: improve action schema settings

This commit is contained in:
chenos 2022-04-14 09:30:19 +08:00
parent fd493dba9c
commit 6d917d36c2
3 changed files with 58 additions and 25 deletions

View File

@ -38,12 +38,15 @@ export const useCreateActionProps = () => {
const actionSchema = useFieldSchema();
return {
async onClick() {
await form.submit();
const initialValues = actionSchema?.['x-action-params']?.initialValues;
const skipValidator = actionSchema?.['x-action-settings']?.skipValidator;
const overwriteValues = actionSchema?.['x-action-settings']?.overwriteValues;
if (!skipValidator) {
await form.submit();
}
await resource.create({
values: {
...form.values,
...initialValues,
...overwriteValues,
},
});
__parent?.service?.refresh?.();
@ -81,13 +84,16 @@ export const useUpdateActionProps = () => {
const actionSchema = useFieldSchema();
return {
async onClick() {
const initialValues = actionSchema?.['x-action-params']?.initialValues;
await form.submit();
const skipValidator = actionSchema?.['x-action-settings']?.skipValidator;
const overwriteValues = actionSchema?.['x-action-settings']?.overwriteValues;
if (!skipValidator) {
await form.submit();
}
await resource.update({
filterByTk,
values: {
...form.values,
...initialValues,
...overwriteValues,
},
});
__parent?.service?.refresh?.();

View File

@ -77,30 +77,48 @@ export const ActionDesigner = (props) => {
}}
/>
)}
{fieldSchema['x-action-params'] && (
{fieldSchema?.['x-action-settings'] && (
<SchemaSettings.SwitchItem
title={'跳过表单校验'}
checked={!!fieldSchema?.['x-action-settings']?.skipValidator}
onChange={(value) => {
fieldSchema['x-action-settings'].skipValidator = value;
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
'x-action-settings': {
...fieldSchema['x-action-settings'],
},
},
});
}}
/>
)}
{fieldSchema?.['x-action-settings'] && (
<SchemaSettings.ModalItem
title={'表单默认值'}
title={'表单值'}
schema={
{
type: 'object',
properties: {
initialValues: {
overwriteValues: {
title: '以下字段提交时,保存值为',
'x-decorator': 'FormItem',
'x-component': 'Input.TextArea',
default: JSON.stringify(fieldSchema?.['x-action-params']?.initialValues),
default: JSON.stringify(fieldSchema?.['x-action-settings']?.overwriteValues),
},
},
} as ISchema
}
onSubmit={({ initialValues }) => {
onSubmit={({ overwriteValues }) => {
try {
const values = JSON.parse(initialValues);
fieldSchema['x-action-params']['initialValues'] = values;
const values = JSON.parse(overwriteValues);
fieldSchema['x-action-settings'].overwriteValues = values;
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
'x-action-params': {
initialValues: values,
'x-action-settings': {
...fieldSchema['x-action-settings'],
},
},
});

View File

@ -12,13 +12,16 @@ export const FormActionInitializers = {
title: '{{t("Submit")}}',
component: 'CreateSubmitActionInitializer',
schema: {
'x-action-params': {
'x-action-settings': {
initialValues: {},
},
},
},
],
},
{
type: 'divider',
},
{
type: 'subMenu',
title: '{{t("Customize")}}',
@ -31,7 +34,7 @@ export const FormActionInitializers = {
title: '{{ t("Save") }}',
'x-component': 'Action',
'x-designer': 'Action.Designer',
'x-action-params': {
'x-action-settings': {
initialValues: {},
},
'x-component-props': {
@ -57,13 +60,16 @@ export const CreateFormActionInitializers = {
title: '{{t("Submit")}}',
component: 'CreateSubmitActionInitializer',
schema: {
'x-action-params': {
initialValues: {},
'x-action-settings': {
overwriteValues: {},
},
},
},
],
},
{
type: 'divider',
},
{
type: 'subMenu',
title: '{{t("Customize")}}',
@ -76,8 +82,8 @@ export const CreateFormActionInitializers = {
title: '{{ t("Save") }}',
'x-component': 'Action',
'x-designer': 'Action.Designer',
'x-action-params': {
initialValues: {},
'x-action-settings': {
overwriteValues: {},
},
'x-component-props': {
useProps: '{{ useCreateActionProps }}',
@ -102,13 +108,16 @@ export const UpdateFormActionInitializers = {
title: '{{t("Submit")}}',
component: 'UpdateSubmitActionInitializer',
schema: {
'x-action-params': {
initialValues: {},
'x-action-settings': {
overwriteValues: {},
},
},
},
],
},
{
type: 'divider',
},
{
type: 'subMenu',
title: '{{t("Customize")}}',
@ -121,8 +130,8 @@ export const UpdateFormActionInitializers = {
title: '{{ t("Save") }}',
'x-component': 'Action',
'x-designer': 'Action.Designer',
'x-action-params': {
initialValues: {},
'x-action-settings': {
overwriteValues: {},
},
'x-component-props': {
useProps: '{{ useUpdateActionProps }}',