-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(QueryForm): 增加QueryForm组件,与其他查询结果类组件(例如表格)组合使用
- Loading branch information
Showing
12 changed files
with
312 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { QueryForm } from 'sula'; | ||
|
||
const queryFields = Array(10) | ||
.fill(0) | ||
.map((_, index) => { | ||
return { | ||
name: `input${index}`, | ||
label: `Input${index}`, | ||
field: 'input', | ||
}; | ||
}); | ||
|
||
export default class BasicDemo extends React.Component { | ||
state = {}; | ||
|
||
componentDidMount() {} | ||
|
||
changevisibleFieldsCount = (v) => { | ||
this.setState({ visibleFieldsCount: v }); | ||
}; | ||
|
||
render() { | ||
const { visibleFieldsCount } = this.state; | ||
return ( | ||
<div> | ||
<button onClick={() => this.changevisibleFieldsCount(4)}>4</button> | ||
<button onClick={() => this.changevisibleFieldsCount(3)}>3</button> | ||
<button onClick={() => this.changevisibleFieldsCount(true)}>无</button> | ||
<div style={{ background: 'rgb(241, 242, 246)', padding: 16, marginTop: 16 }}> | ||
<QueryForm | ||
key={visibleFieldsCount || 'all'} | ||
visibleFieldsCount={visibleFieldsCount} | ||
layout="vertical" | ||
fields={queryFields} | ||
actionsRender={[ | ||
{ | ||
type: 'button', | ||
props: { | ||
type: 'primary', | ||
children: '查一下' | ||
}, | ||
action: (ctx) => { | ||
console.log('ctx: ', ctx); | ||
console.log('fieldsValue', ctx.form.getFieldsValue()); | ||
}, | ||
}, | ||
]} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { useForm, QueryForm } from 'sula'; | ||
|
||
const queryFields = Array(10) | ||
.fill(0) | ||
.map((_, index) => { | ||
return { | ||
name: `input${index}`, | ||
label: `Input${index}`, | ||
field: 'input', | ||
}; | ||
}); | ||
|
||
const BasicDemo = () => { | ||
const [form] = useForm(); | ||
return ( | ||
<div> | ||
<button | ||
onClick={() => { | ||
form.setFieldsValue({ | ||
input0: '123123', | ||
}); | ||
}} | ||
> | ||
设置表单值 | ||
</button> | ||
<div style={{ background: 'rgb(241, 242, 246)', padding: 16, marginTop: 16 }}> | ||
<QueryForm | ||
form={form} | ||
layout="horizontal" | ||
labelAlign="left" | ||
onValuesChange={(_, allValues) => { | ||
console.log('allValues: ', allValues); | ||
}} | ||
fields={queryFields} | ||
actionsRender={[ | ||
{ | ||
type: 'button', | ||
props: { | ||
type: 'primary', | ||
children: '查一下', | ||
}, | ||
action: (ctx) => { | ||
console.log('ctx: ', ctx); | ||
console.log('fieldsValue', ctx.form.getFieldsValue()); | ||
}, | ||
}, | ||
]} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BasicDemo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { FormInstance, QueryForm } from 'sula'; | ||
|
||
const queryFields = Array(10) | ||
.fill(0) | ||
.map((_, index) => { | ||
return { | ||
name: `input${index}`, | ||
label: `Input${index}`, | ||
field: 'input', | ||
}; | ||
}); | ||
|
||
export default class BasicDemo extends React.Component { | ||
formRef = React.createRef<FormInstance>(); | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<button onClick={() => { | ||
this.formRef.current?.setFieldsValue({ | ||
input0: '123123', | ||
}) | ||
}}>设置表单值</button> | ||
<div style={{ background: 'rgb(241, 242, 246)', padding: 16, marginTop: 16 }}> | ||
<QueryForm | ||
ref={this.formRef} | ||
layout="horizontal" | ||
labelAlign="left" | ||
onValuesChange={(_, allValues) => { | ||
console.log('allValues: ', allValues); | ||
}} | ||
fields={queryFields} | ||
ctxGetter={() => { | ||
return { | ||
table: { | ||
refreshTable: () => { | ||
console.log('刷新表格') | ||
} | ||
} | ||
} | ||
}} | ||
actionsRender={[ | ||
{ | ||
type: 'button', | ||
props: { | ||
type: 'primary', | ||
children: '查一下' | ||
}, | ||
action: [ | ||
{ type: 'validateQueryFields', resultPropName: '$queryFieldsValue' }, | ||
(ctx) => { | ||
return new Promise((resolve, reject) => { | ||
// mock | ||
setTimeout(() => { | ||
ctx.table?.refreshTable(); | ||
resolve('ok'); | ||
}, 2000); | ||
}) | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: QueryForm | ||
order: 4 | ||
--- | ||
|
||
<code title="基本使用" src="../query-form/basic.jsx" /> | ||
<code title="其他属性" src="../query-form/other.tsx" /> | ||
<code title="hook" src="../query-form/hook.tsx" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { Form, FormInstance, FormProps } from '../form'; | ||
import QueryFields, { QueryFieldsProps } from './QueryFields'; | ||
|
||
export interface QueryFormProps | ||
extends Omit<FormProps, 'fields' | 'actionsPosition' | 'actionsRender'>, | ||
Omit<QueryFieldsProps, 'getFormInstance'> {} | ||
|
||
const QueryForm: React.ForwardRefRenderFunction<FormInstance, QueryFormProps> = (props, ref) => { | ||
const { | ||
layout, | ||
itemLayout = { | ||
cols: 3, | ||
}, | ||
fields, | ||
initialValues, | ||
visibleFieldsCount, | ||
actionsRender, | ||
hasBottomBorder, | ||
...restProps | ||
} = props; | ||
const [form] = Form.useForm(restProps.form); | ||
|
||
React.useImperativeHandle(ref, () => form); | ||
|
||
return ( | ||
<Form | ||
{...restProps} | ||
form={form} | ||
initialValues={initialValues} | ||
itemLayout={itemLayout} | ||
layout={layout} | ||
> | ||
<QueryFields | ||
fields={fields} | ||
visibleFieldsCount={visibleFieldsCount} | ||
getFormInstance={() => form} | ||
hasBottomBorder={hasBottomBorder} | ||
actionsRender={actionsRender} | ||
/> | ||
</Form> | ||
); | ||
}; | ||
|
||
export default React.forwardRef(QueryForm); |
Oops, something went wrong.