update 表格查询允许更多查询条件
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Button, Table, Tooltip } from 'antd'
|
||||
import { Form, Button, Table, Tooltip, Drawer } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { isEqual } from 'lodash'
|
||||
|
||||
@@ -34,15 +34,15 @@ const rowNoColumn = {
|
||||
* @returns
|
||||
*/
|
||||
function renderQueryBar() {
|
||||
const { query, moreQuery, onQueryChange } = this.props
|
||||
const { query, moreQuery, onQueryChange, queryInitialValues } = this.props
|
||||
|
||||
return (
|
||||
<div className="yo-query-bar">
|
||||
<Form
|
||||
layout="inline"
|
||||
ref={this.form}
|
||||
ref={this.queryForm}
|
||||
onFinish={value => this.onQuery(value)}
|
||||
initialValues={this.props.queryInitialValues}
|
||||
initialValues={queryInitialValues}
|
||||
onValuesChange={(changedValues, allValues) =>
|
||||
onQueryChange && onQueryChange(changedValues, allValues)
|
||||
}
|
||||
@@ -55,18 +55,62 @@ function renderQueryBar() {
|
||||
</Button>
|
||||
<Tooltip placement="bottom" title="重置查询">
|
||||
<Button
|
||||
onClick={() => this.onResetQuery()}
|
||||
onClick={() => this.onResetQuery(this.queryForm)}
|
||||
icon={<AntIcon type="undo" />}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Button.Group>
|
||||
{moreQuery && <Button>更多查询条件</Button>}
|
||||
{moreQuery && (
|
||||
<Button type="text" onClick={() => this.onOpenMoreQuery()}>
|
||||
更多查询条件
|
||||
</Button>
|
||||
)}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function renderMoreQueryBody() {
|
||||
const { moreQueryVisible } = this.state
|
||||
|
||||
const { moreQuery } = this.props
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
width="33%"
|
||||
title="查询"
|
||||
className="yo-drawer-form"
|
||||
visible={moreQueryVisible}
|
||||
onClose={() => this.setState({ moreQueryVisible: false })}
|
||||
>
|
||||
<Form ref={this.moreQueryForm}>
|
||||
<div className="yo-drawer-form--body">{moreQuery}</div>
|
||||
<div className="ant-drawer-footer">
|
||||
<Button.Group>
|
||||
<Button
|
||||
htmlType="submit"
|
||||
type="primary"
|
||||
icon={<AntIcon type="search" />}
|
||||
onClick={() =>
|
||||
this.onQuery(this.moreQueryForm.current.getFieldsValue())
|
||||
}
|
||||
>
|
||||
查询
|
||||
</Button>
|
||||
<Tooltip placement="top" title="重置查询">
|
||||
<Button
|
||||
onClick={() => this.onResetQuery(this.moreQueryForm)}
|
||||
icon={<AntIcon type="undo" />}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Button.Group>
|
||||
</div>
|
||||
</Form>
|
||||
</Drawer>
|
||||
)
|
||||
}
|
||||
|
||||
function renderTable(props, on) {
|
||||
return <Table className="yo-table" {...props} {...on} />
|
||||
}
|
||||
@@ -79,10 +123,14 @@ export default class QueryTable extends Component {
|
||||
type: 'tree',
|
||||
// 数据
|
||||
dataSource: [],
|
||||
|
||||
moreQueryVisible: false,
|
||||
}
|
||||
|
||||
// 查询表单实例
|
||||
form = React.createRef()
|
||||
queryForm = React.createRef()
|
||||
// 更多查询表单实例
|
||||
moreQueryForm = React.createRef()
|
||||
|
||||
// 查询值
|
||||
query = {}
|
||||
@@ -213,7 +261,13 @@ export default class QueryTable extends Component {
|
||||
* @param {*} values
|
||||
*/
|
||||
onQuery = values => {
|
||||
this.query = values
|
||||
const { queryInitialValues } = this.props
|
||||
|
||||
this.query = {
|
||||
...queryInitialValues,
|
||||
...this.query,
|
||||
...values,
|
||||
}
|
||||
this.onReloadData(true)
|
||||
}
|
||||
|
||||
@@ -221,15 +275,23 @@ export default class QueryTable extends Component {
|
||||
* 重置查询
|
||||
* 初始化表单字段值,加载数据,并返回到第一页
|
||||
*/
|
||||
onResetQuery = () => {
|
||||
const { queryInitialValues, onQueryChange } = this.props
|
||||
onResetQuery = from => {
|
||||
const { queryInitialValues, onQueryChange, query, moreQuery } = this.props
|
||||
|
||||
let queryValues = {}
|
||||
if (from === this.queryForm) {
|
||||
from.current.resetFields()
|
||||
queryValues = moreQuery ? this.moreQueryForm.current.getFieldsValue() : {}
|
||||
} else if (from === this.moreQueryForm) {
|
||||
from.current.resetFields()
|
||||
queryValues = query ? this.queryForm.current.getFieldsValue() : {}
|
||||
}
|
||||
|
||||
this.form.current.resetFields()
|
||||
this.query = {
|
||||
...queryInitialValues,
|
||||
...queryValues,
|
||||
}
|
||||
const values = this.form.current.getFieldsValue()
|
||||
onQueryChange && onQueryChange(values, values)
|
||||
onQueryChange && onQueryChange(this.query)
|
||||
this.onReloadData(true)
|
||||
}
|
||||
|
||||
@@ -277,12 +339,16 @@ export default class QueryTable extends Component {
|
||||
return false
|
||||
}
|
||||
|
||||
onOpenMoreQuery = () => {
|
||||
this.setState({ moreQueryVisible: true })
|
||||
}
|
||||
|
||||
render() {
|
||||
const { rowNumber } = this
|
||||
|
||||
const { loading, dataSource, type } = this.state
|
||||
|
||||
const { query, operator, columns, expandable, expandedRowRender } = this.props
|
||||
const { query, moreQuery, operator, columns, expandable, expandedRowRender } = this.props
|
||||
|
||||
const attrs = {}
|
||||
Object.keys(this.props).forEach(key => {
|
||||
@@ -337,6 +403,7 @@ export default class QueryTable extends Component {
|
||||
) : (
|
||||
renderTable.call(this, props, on)
|
||||
)}
|
||||
{moreQuery && renderMoreQueryBody.call(this)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user