fix: empty values after form submission

This commit is contained in:
chenos 2021-10-10 12:50:26 +08:00
parent 8472d9e6b0
commit ccfdb02801
4 changed files with 56 additions and 19 deletions

View File

@ -176,6 +176,7 @@ for (const [key, schema] of interfaces) {
fieldInterfaces.push({
value: key,
label: schema.title,
disabled: schema.disabled,
});
}
@ -592,7 +593,7 @@ function CreateFieldButton() {
option.children.length > 0 && (
<Menu.SubMenu key={groupIndex} title={option.label}>
{option.children.map((item) => (
<Menu.Item style={{ minWidth: 120 }} key={item.name}>
<Menu.Item disabled={item.disabled} style={{ minWidth: 120 }} key={item.name}>
{item.title}
</Menu.Item>
))}
@ -612,12 +613,16 @@ function CreateFieldButton() {
title={'添加字段'}
width={'50%'}
visible={visible}
onClose={() => setVisible(false)}
onClose={() => {
setVisible(false);
form.reset();
}}
footer={
<Space style={{ float: 'right' }}>
<Button
onClick={() => {
onClick={async () => {
setVisible(false);
await form.reset();
}}
>
@ -627,6 +632,7 @@ function CreateFieldButton() {
onClick={async () => {
await resource.save(form.values);
setVisible(false);
await form.reset();
await service.refresh();
await refresh();
}}

View File

@ -217,6 +217,9 @@ Action.Modal = observer((props: any) => {
}
runCancel && (await runCancel());
setVisible(false);
if (isFormDecorator) {
await form.reset();
}
}}
>
@ -229,6 +232,9 @@ Action.Modal = observer((props: any) => {
}
runOk && (await runOk());
setVisible(false);
if (isFormDecorator) {
await form.reset();
}
}}
>
@ -243,6 +249,9 @@ Action.Modal = observer((props: any) => {
}
runCancel && (await runCancel());
setVisible(false);
if (isFormDecorator) {
await form.reset();
}
}}
visible={visible}
>
@ -282,6 +291,9 @@ Action.Drawer = observer((props: any) => {
props.onClose && (await props.onClose(e));
runCancel && (await runCancel());
setVisible(false);
if (isFormDecorator) {
await form.reset();
}
}}
>
@ -292,6 +304,9 @@ Action.Drawer = observer((props: any) => {
props.onOk && (await props.onOk(e));
runOk && (await runOk());
setVisible(false);
if (isFormDecorator) {
await form.reset();
}
}}
type={'primary'}
>
@ -306,6 +321,9 @@ Action.Drawer = observer((props: any) => {
props.onClose && (await props.onClose(e));
runCancel && (await runCancel());
setVisible(false);
if (isFormDecorator) {
await form.reset();
}
}}
>
<FormLayout layout={'vertical'}>{props.children}</FormLayout>

View File

@ -58,10 +58,10 @@ export const SimpleDesignableBar = observer((props) => {
<DragHandle />
<Dropdown
trigger={['hover']}
// visible={visible}
// onVisibleChange={(visible) => {
// setVisible(visible);
// }}
visible={visible}
onVisibleChange={(visible) => {
setVisible(visible);
}}
overlay={
<Menu>
<Menu.Item
@ -172,6 +172,7 @@ export const SimpleDesignableBar = observer((props) => {
defaultFilter;
field.componentProps.defaultFilter = defaultFilter;
await updateSchema(schema);
setVisible(false);
}}
>
@ -190,6 +191,7 @@ export const SimpleDesignableBar = observer((props) => {
field.componentProps.pagination.defaultPageSize = value;
refresh();
updateSchema(schema);
setVisible(false);
}}
defaultValue={defaultPageSize}
>
@ -212,6 +214,7 @@ export const SimpleDesignableBar = observer((props) => {
// console.log({ removed })
const last = removed.pop();
await removeSchema(last);
setVisible(false);
},
});
}}

View File

@ -139,7 +139,7 @@ function useTableCreateAction() {
const form = useForm();
return {
async run() {
console.log('useTableCreateAction', resource);
console.log('refreshRequestOnChange', refreshRequestOnChange);
if (refreshRequestOnChange) {
await resource.create(form.values);
await form.reset();
@ -278,6 +278,9 @@ const useTableRowRecord = () => {
const useTableIndex = () => {
const { pagination, props } = useTable();
const ctx = useContext(TableRowContext);
const { pageSize, page = 1 } = pagination;
console.log({pageSize, page}, ctx.index);
return ctx.index + (page - 1) * pageSize;
if (pagination && !props.clientSidePagination) {
const { pageSize, page = 1 } = pagination;
return ctx.index + (page - 1) * pageSize;
@ -655,12 +658,12 @@ const useDataSource = () => {
props: { clientSidePagination, dataRequest },
} = useTable();
let dataSource = field.value;
if (pagination && (clientSidePagination || !dataRequest)) {
const { page = 1, pageSize } = pagination;
const startIndex = (page - 1) * pageSize;
const endIndex = startIndex + pageSize - 1;
dataSource = field.value?.slice(startIndex, endIndex + 1);
}
// if (pagination && (clientSidePagination || !dataRequest)) {
// const { page = 1, pageSize } = pagination;
// const startIndex = (page - 1) * pageSize;
// const endIndex = startIndex + pageSize - 1;
// dataSource = field.value?.slice(startIndex, endIndex + 1);
// }
return dataSource;
};
@ -860,7 +863,7 @@ const TableProvider = (props: any) => {
const { sortableField } = useCollectionContext();
const dragSort = props.dragSort;
const collectionFields = useCollectionFields(schema);
console.log({ collectionFields });
// console.log({ collectionFields, pagination });
const getDefaultParams = () => {
const defaultParams = { ...pagination };
if (dragSort) {
@ -905,6 +908,7 @@ const TableProvider = (props: any) => {
service.run(getDefaultParams());
}, [
pagination.pageSize,
pagination.page,
props.dragSort,
props.defaultSort,
props.defaultFilter,
@ -2252,10 +2256,10 @@ Table.DesignableBar = observer((props) => {
<DragHandle />
<Dropdown
trigger={['hover']}
// visible={visible}
// onVisibleChange={(visible) => {
// setVisible(visible);
// }}
visible={visible}
onVisibleChange={(visible) => {
setVisible(visible);
}}
overlay={
<Menu>
<Menu.Item
@ -2265,6 +2269,7 @@ Table.DesignableBar = observer((props) => {
schema['x-component-props']['showIndex'] = bool;
field.componentProps.showIndex = bool;
updateSchema(schema);
setVisible(false);
}}
>
<div className={'nb-space-between'}>
@ -2284,6 +2289,7 @@ Table.DesignableBar = observer((props) => {
schema['x-component-props']['dragSort'] = dragSort;
field.componentProps.dragSort = dragSort;
updateSchema(schema);
setVisible(false);
}}
>
<div className={'nb-space-between'}>
@ -2398,6 +2404,7 @@ Table.DesignableBar = observer((props) => {
schema['x-component-props']['defaultSort'] = sort;
field.componentProps.defaultSort = sort;
await updateSchema(schema);
setVisible(false);
console.log('defaultSort', sort);
}}
>
@ -2437,6 +2444,7 @@ Table.DesignableBar = observer((props) => {
defaultFilter;
field.componentProps.defaultFilter = defaultFilter;
await updateSchema(schema);
setVisible(false);
}}
>
@ -2455,6 +2463,7 @@ Table.DesignableBar = observer((props) => {
field.componentProps.pagination.defaultPageSize = value;
refresh();
updateSchema(schema);
setVisible(false);
}}
defaultValue={defaultPageSize}
>
@ -2477,6 +2486,7 @@ Table.DesignableBar = observer((props) => {
// console.log({ removed })
const last = removed.pop();
await removeSchema(last);
setVisible(false);
},
});
}}