fix: empty values after form submission
This commit is contained in:
		
							parent
							
								
									8472d9e6b0
								
							
						
					
					
						commit
						ccfdb02801
					
				@ -176,6 +176,7 @@ for (const [key, schema] of interfaces) {
 | 
				
			|||||||
  fieldInterfaces.push({
 | 
					  fieldInterfaces.push({
 | 
				
			||||||
    value: key,
 | 
					    value: key,
 | 
				
			||||||
    label: schema.title,
 | 
					    label: schema.title,
 | 
				
			||||||
 | 
					    disabled: schema.disabled,
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -592,7 +593,7 @@ function CreateFieldButton() {
 | 
				
			|||||||
          option.children.length > 0 && (
 | 
					          option.children.length > 0 && (
 | 
				
			||||||
            <Menu.SubMenu key={groupIndex} title={option.label}>
 | 
					            <Menu.SubMenu key={groupIndex} title={option.label}>
 | 
				
			||||||
              {option.children.map((item) => (
 | 
					              {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}
 | 
					                  {item.title}
 | 
				
			||||||
                </Menu.Item>
 | 
					                </Menu.Item>
 | 
				
			||||||
              ))}
 | 
					              ))}
 | 
				
			||||||
@ -612,12 +613,16 @@ function CreateFieldButton() {
 | 
				
			|||||||
        title={'添加字段'}
 | 
					        title={'添加字段'}
 | 
				
			||||||
        width={'50%'}
 | 
					        width={'50%'}
 | 
				
			||||||
        visible={visible}
 | 
					        visible={visible}
 | 
				
			||||||
        onClose={() => setVisible(false)}
 | 
					        onClose={() => {
 | 
				
			||||||
 | 
					          setVisible(false);
 | 
				
			||||||
 | 
					          form.reset();
 | 
				
			||||||
 | 
					        }}
 | 
				
			||||||
        footer={
 | 
					        footer={
 | 
				
			||||||
          <Space style={{ float: 'right' }}>
 | 
					          <Space style={{ float: 'right' }}>
 | 
				
			||||||
            <Button
 | 
					            <Button
 | 
				
			||||||
              onClick={() => {
 | 
					              onClick={async () => {
 | 
				
			||||||
                setVisible(false);
 | 
					                setVisible(false);
 | 
				
			||||||
 | 
					                await form.reset();
 | 
				
			||||||
              }}
 | 
					              }}
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
              取消
 | 
					              取消
 | 
				
			||||||
@ -627,6 +632,7 @@ function CreateFieldButton() {
 | 
				
			|||||||
              onClick={async () => {
 | 
					              onClick={async () => {
 | 
				
			||||||
                await resource.save(form.values);
 | 
					                await resource.save(form.values);
 | 
				
			||||||
                setVisible(false);
 | 
					                setVisible(false);
 | 
				
			||||||
 | 
					                await form.reset();
 | 
				
			||||||
                await service.refresh();
 | 
					                await service.refresh();
 | 
				
			||||||
                await refresh();
 | 
					                await refresh();
 | 
				
			||||||
              }}
 | 
					              }}
 | 
				
			||||||
 | 
				
			|||||||
@ -217,6 +217,9 @@ Action.Modal = observer((props: any) => {
 | 
				
			|||||||
                  }
 | 
					                  }
 | 
				
			||||||
                  runCancel && (await runCancel());
 | 
					                  runCancel && (await runCancel());
 | 
				
			||||||
                  setVisible(false);
 | 
					                  setVisible(false);
 | 
				
			||||||
 | 
					                  if (isFormDecorator) {
 | 
				
			||||||
 | 
					                    await form.reset();
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
                }}
 | 
					                }}
 | 
				
			||||||
              >
 | 
					              >
 | 
				
			||||||
                取消
 | 
					                取消
 | 
				
			||||||
@ -229,6 +232,9 @@ Action.Modal = observer((props: any) => {
 | 
				
			|||||||
                  }
 | 
					                  }
 | 
				
			||||||
                  runOk && (await runOk());
 | 
					                  runOk && (await runOk());
 | 
				
			||||||
                  setVisible(false);
 | 
					                  setVisible(false);
 | 
				
			||||||
 | 
					                  if (isFormDecorator) {
 | 
				
			||||||
 | 
					                    await form.reset();
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
                }}
 | 
					                }}
 | 
				
			||||||
              >
 | 
					              >
 | 
				
			||||||
                确定
 | 
					                确定
 | 
				
			||||||
@ -243,6 +249,9 @@ Action.Modal = observer((props: any) => {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        runCancel && (await runCancel());
 | 
					        runCancel && (await runCancel());
 | 
				
			||||||
        setVisible(false);
 | 
					        setVisible(false);
 | 
				
			||||||
 | 
					        if (isFormDecorator) {
 | 
				
			||||||
 | 
					          await form.reset();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }}
 | 
					      }}
 | 
				
			||||||
      visible={visible}
 | 
					      visible={visible}
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
@ -282,6 +291,9 @@ Action.Drawer = observer((props: any) => {
 | 
				
			|||||||
                    props.onClose && (await props.onClose(e));
 | 
					                    props.onClose && (await props.onClose(e));
 | 
				
			||||||
                    runCancel && (await runCancel());
 | 
					                    runCancel && (await runCancel());
 | 
				
			||||||
                    setVisible(false);
 | 
					                    setVisible(false);
 | 
				
			||||||
 | 
					                    if (isFormDecorator) {
 | 
				
			||||||
 | 
					                      await form.reset();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  取消
 | 
					                  取消
 | 
				
			||||||
@ -292,6 +304,9 @@ Action.Drawer = observer((props: any) => {
 | 
				
			|||||||
                    props.onOk && (await props.onOk(e));
 | 
					                    props.onOk && (await props.onOk(e));
 | 
				
			||||||
                    runOk && (await runOk());
 | 
					                    runOk && (await runOk());
 | 
				
			||||||
                    setVisible(false);
 | 
					                    setVisible(false);
 | 
				
			||||||
 | 
					                    if (isFormDecorator) {
 | 
				
			||||||
 | 
					                      await form.reset();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
                  type={'primary'}
 | 
					                  type={'primary'}
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
@ -306,6 +321,9 @@ Action.Drawer = observer((props: any) => {
 | 
				
			|||||||
            props.onClose && (await props.onClose(e));
 | 
					            props.onClose && (await props.onClose(e));
 | 
				
			||||||
            runCancel && (await runCancel());
 | 
					            runCancel && (await runCancel());
 | 
				
			||||||
            setVisible(false);
 | 
					            setVisible(false);
 | 
				
			||||||
 | 
					            if (isFormDecorator) {
 | 
				
			||||||
 | 
					              await form.reset();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
          }}
 | 
					          }}
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
          <FormLayout layout={'vertical'}>{props.children}</FormLayout>
 | 
					          <FormLayout layout={'vertical'}>{props.children}</FormLayout>
 | 
				
			||||||
 | 
				
			|||||||
@ -58,10 +58,10 @@ export const SimpleDesignableBar = observer((props) => {
 | 
				
			|||||||
          <DragHandle />
 | 
					          <DragHandle />
 | 
				
			||||||
          <Dropdown
 | 
					          <Dropdown
 | 
				
			||||||
            trigger={['hover']}
 | 
					            trigger={['hover']}
 | 
				
			||||||
            // visible={visible}
 | 
					            visible={visible}
 | 
				
			||||||
            // onVisibleChange={(visible) => {
 | 
					            onVisibleChange={(visible) => {
 | 
				
			||||||
            //   setVisible(visible);
 | 
					              setVisible(visible);
 | 
				
			||||||
            // }}
 | 
					            }}
 | 
				
			||||||
            overlay={
 | 
					            overlay={
 | 
				
			||||||
              <Menu>
 | 
					              <Menu>
 | 
				
			||||||
                <Menu.Item
 | 
					                <Menu.Item
 | 
				
			||||||
@ -172,6 +172,7 @@ export const SimpleDesignableBar = observer((props) => {
 | 
				
			|||||||
                      defaultFilter;
 | 
					                      defaultFilter;
 | 
				
			||||||
                    field.componentProps.defaultFilter = defaultFilter;
 | 
					                    field.componentProps.defaultFilter = defaultFilter;
 | 
				
			||||||
                    await updateSchema(schema);
 | 
					                    await updateSchema(schema);
 | 
				
			||||||
 | 
					                    setVisible(false);
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  设置数据范围
 | 
					                  设置数据范围
 | 
				
			||||||
@ -190,6 +191,7 @@ export const SimpleDesignableBar = observer((props) => {
 | 
				
			|||||||
                      field.componentProps.pagination.defaultPageSize = value;
 | 
					                      field.componentProps.pagination.defaultPageSize = value;
 | 
				
			||||||
                      refresh();
 | 
					                      refresh();
 | 
				
			||||||
                      updateSchema(schema);
 | 
					                      updateSchema(schema);
 | 
				
			||||||
 | 
					                      setVisible(false);
 | 
				
			||||||
                    }}
 | 
					                    }}
 | 
				
			||||||
                    defaultValue={defaultPageSize}
 | 
					                    defaultValue={defaultPageSize}
 | 
				
			||||||
                  >
 | 
					                  >
 | 
				
			||||||
@ -212,6 +214,7 @@ export const SimpleDesignableBar = observer((props) => {
 | 
				
			|||||||
                        // console.log({ removed })
 | 
					                        // console.log({ removed })
 | 
				
			||||||
                        const last = removed.pop();
 | 
					                        const last = removed.pop();
 | 
				
			||||||
                        await removeSchema(last);
 | 
					                        await removeSchema(last);
 | 
				
			||||||
 | 
					                        setVisible(false);
 | 
				
			||||||
                      },
 | 
					                      },
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
 | 
				
			|||||||
@ -139,7 +139,7 @@ function useTableCreateAction() {
 | 
				
			|||||||
  const form = useForm();
 | 
					  const form = useForm();
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    async run() {
 | 
					    async run() {
 | 
				
			||||||
      console.log('useTableCreateAction', resource);
 | 
					      console.log('refreshRequestOnChange', refreshRequestOnChange);
 | 
				
			||||||
      if (refreshRequestOnChange) {
 | 
					      if (refreshRequestOnChange) {
 | 
				
			||||||
        await resource.create(form.values);
 | 
					        await resource.create(form.values);
 | 
				
			||||||
        await form.reset();
 | 
					        await form.reset();
 | 
				
			||||||
@ -278,6 +278,9 @@ const useTableRowRecord = () => {
 | 
				
			|||||||
const useTableIndex = () => {
 | 
					const useTableIndex = () => {
 | 
				
			||||||
  const { pagination, props } = useTable();
 | 
					  const { pagination, props } = useTable();
 | 
				
			||||||
  const ctx = useContext(TableRowContext);
 | 
					  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) {
 | 
					  if (pagination && !props.clientSidePagination) {
 | 
				
			||||||
    const { pageSize, page = 1 } = pagination;
 | 
					    const { pageSize, page = 1 } = pagination;
 | 
				
			||||||
    return ctx.index + (page - 1) * pageSize;
 | 
					    return ctx.index + (page - 1) * pageSize;
 | 
				
			||||||
@ -655,12 +658,12 @@ const useDataSource = () => {
 | 
				
			|||||||
    props: { clientSidePagination, dataRequest },
 | 
					    props: { clientSidePagination, dataRequest },
 | 
				
			||||||
  } = useTable();
 | 
					  } = useTable();
 | 
				
			||||||
  let dataSource = field.value;
 | 
					  let dataSource = field.value;
 | 
				
			||||||
  if (pagination && (clientSidePagination || !dataRequest)) {
 | 
					  // if (pagination && (clientSidePagination || !dataRequest)) {
 | 
				
			||||||
    const { page = 1, pageSize } = pagination;
 | 
					  //   const { page = 1, pageSize } = pagination;
 | 
				
			||||||
    const startIndex = (page - 1) * pageSize;
 | 
					  //   const startIndex = (page - 1) * pageSize;
 | 
				
			||||||
    const endIndex = startIndex + pageSize - 1;
 | 
					  //   const endIndex = startIndex + pageSize - 1;
 | 
				
			||||||
    dataSource = field.value?.slice(startIndex, endIndex + 1);
 | 
					  //   dataSource = field.value?.slice(startIndex, endIndex + 1);
 | 
				
			||||||
  }
 | 
					  // }
 | 
				
			||||||
  return dataSource;
 | 
					  return dataSource;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -860,7 +863,7 @@ const TableProvider = (props: any) => {
 | 
				
			|||||||
  const { sortableField } = useCollectionContext();
 | 
					  const { sortableField } = useCollectionContext();
 | 
				
			||||||
  const dragSort = props.dragSort;
 | 
					  const dragSort = props.dragSort;
 | 
				
			||||||
  const collectionFields = useCollectionFields(schema);
 | 
					  const collectionFields = useCollectionFields(schema);
 | 
				
			||||||
  console.log({ collectionFields });
 | 
					  // console.log({ collectionFields, pagination });
 | 
				
			||||||
  const getDefaultParams = () => {
 | 
					  const getDefaultParams = () => {
 | 
				
			||||||
    const defaultParams = { ...pagination };
 | 
					    const defaultParams = { ...pagination };
 | 
				
			||||||
    if (dragSort) {
 | 
					    if (dragSort) {
 | 
				
			||||||
@ -905,6 +908,7 @@ const TableProvider = (props: any) => {
 | 
				
			|||||||
    service.run(getDefaultParams());
 | 
					    service.run(getDefaultParams());
 | 
				
			||||||
  }, [
 | 
					  }, [
 | 
				
			||||||
    pagination.pageSize,
 | 
					    pagination.pageSize,
 | 
				
			||||||
 | 
					    pagination.page,
 | 
				
			||||||
    props.dragSort,
 | 
					    props.dragSort,
 | 
				
			||||||
    props.defaultSort,
 | 
					    props.defaultSort,
 | 
				
			||||||
    props.defaultFilter,
 | 
					    props.defaultFilter,
 | 
				
			||||||
@ -2252,10 +2256,10 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
          <DragHandle />
 | 
					          <DragHandle />
 | 
				
			||||||
          <Dropdown
 | 
					          <Dropdown
 | 
				
			||||||
            trigger={['hover']}
 | 
					            trigger={['hover']}
 | 
				
			||||||
            // visible={visible}
 | 
					            visible={visible}
 | 
				
			||||||
            // onVisibleChange={(visible) => {
 | 
					            onVisibleChange={(visible) => {
 | 
				
			||||||
            //   setVisible(visible);
 | 
					              setVisible(visible);
 | 
				
			||||||
            // }}
 | 
					            }}
 | 
				
			||||||
            overlay={
 | 
					            overlay={
 | 
				
			||||||
              <Menu>
 | 
					              <Menu>
 | 
				
			||||||
                <Menu.Item
 | 
					                <Menu.Item
 | 
				
			||||||
@ -2265,6 +2269,7 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
                    schema['x-component-props']['showIndex'] = bool;
 | 
					                    schema['x-component-props']['showIndex'] = bool;
 | 
				
			||||||
                    field.componentProps.showIndex = bool;
 | 
					                    field.componentProps.showIndex = bool;
 | 
				
			||||||
                    updateSchema(schema);
 | 
					                    updateSchema(schema);
 | 
				
			||||||
 | 
					                    setVisible(false);
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  <div className={'nb-space-between'}>
 | 
					                  <div className={'nb-space-between'}>
 | 
				
			||||||
@ -2284,6 +2289,7 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
                    schema['x-component-props']['dragSort'] = dragSort;
 | 
					                    schema['x-component-props']['dragSort'] = dragSort;
 | 
				
			||||||
                    field.componentProps.dragSort = dragSort;
 | 
					                    field.componentProps.dragSort = dragSort;
 | 
				
			||||||
                    updateSchema(schema);
 | 
					                    updateSchema(schema);
 | 
				
			||||||
 | 
					                    setVisible(false);
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  <div className={'nb-space-between'}>
 | 
					                  <div className={'nb-space-between'}>
 | 
				
			||||||
@ -2398,6 +2404,7 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
                      schema['x-component-props']['defaultSort'] = sort;
 | 
					                      schema['x-component-props']['defaultSort'] = sort;
 | 
				
			||||||
                      field.componentProps.defaultSort = sort;
 | 
					                      field.componentProps.defaultSort = sort;
 | 
				
			||||||
                      await updateSchema(schema);
 | 
					                      await updateSchema(schema);
 | 
				
			||||||
 | 
					                      setVisible(false);
 | 
				
			||||||
                      console.log('defaultSort', sort);
 | 
					                      console.log('defaultSort', sort);
 | 
				
			||||||
                    }}
 | 
					                    }}
 | 
				
			||||||
                  >
 | 
					                  >
 | 
				
			||||||
@ -2437,6 +2444,7 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
                      defaultFilter;
 | 
					                      defaultFilter;
 | 
				
			||||||
                    field.componentProps.defaultFilter = defaultFilter;
 | 
					                    field.componentProps.defaultFilter = defaultFilter;
 | 
				
			||||||
                    await updateSchema(schema);
 | 
					                    await updateSchema(schema);
 | 
				
			||||||
 | 
					                    setVisible(false);
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  设置数据范围
 | 
					                  设置数据范围
 | 
				
			||||||
@ -2455,6 +2463,7 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
                      field.componentProps.pagination.defaultPageSize = value;
 | 
					                      field.componentProps.pagination.defaultPageSize = value;
 | 
				
			||||||
                      refresh();
 | 
					                      refresh();
 | 
				
			||||||
                      updateSchema(schema);
 | 
					                      updateSchema(schema);
 | 
				
			||||||
 | 
					                      setVisible(false);
 | 
				
			||||||
                    }}
 | 
					                    }}
 | 
				
			||||||
                    defaultValue={defaultPageSize}
 | 
					                    defaultValue={defaultPageSize}
 | 
				
			||||||
                  >
 | 
					                  >
 | 
				
			||||||
@ -2477,6 +2486,7 @@ Table.DesignableBar = observer((props) => {
 | 
				
			|||||||
                        // console.log({ removed })
 | 
					                        // console.log({ removed })
 | 
				
			||||||
                        const last = removed.pop();
 | 
					                        const last = removed.pop();
 | 
				
			||||||
                        await removeSchema(last);
 | 
					                        await removeSchema(last);
 | 
				
			||||||
 | 
					                        setVisible(false);
 | 
				
			||||||
                      },
 | 
					                      },
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                  }}
 | 
					                  }}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user