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>
|
||||
)
|
||||
}
|
||||
|
||||
267
web-react/src/pages/business/house/query/index.jsx
Normal file
267
web-react/src/pages/business/house/query/index.jsx
Normal file
@@ -0,0 +1,267 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm, Radio, Select, Tag } from 'antd'
|
||||
import { AntIcon, Auth, Container, QueryTable } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import { toCamelCase } from 'util/format'
|
||||
|
||||
/**
|
||||
* 注释段[\/**\/]为必须要改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 配置页面所需接口函数
|
||||
*/
|
||||
const apiAction = {
|
||||
page: api.houseTaskPage,
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于弹窗标题
|
||||
* [必要]
|
||||
*/
|
||||
const name = '/**/'
|
||||
|
||||
/**
|
||||
* 统一配置权限标识
|
||||
* [必要]
|
||||
*/
|
||||
const authName = 'houseTask'
|
||||
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
codes: {
|
||||
houseType: [],
|
||||
houseIndustry: [],
|
||||
},
|
||||
|
||||
type: '',
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
// 新增窗口实例
|
||||
addForm = React.createRef()
|
||||
// 编辑窗口实例
|
||||
editForm = React.createRef()
|
||||
|
||||
columns = [
|
||||
{
|
||||
title: '房屋编码',
|
||||
dataIndex: 'houseCode',
|
||||
sorter: true,
|
||||
width: 300,
|
||||
render: (text, record) => (
|
||||
<>
|
||||
{`${record.areaName}-${record.roadName}-${record.commName}-${
|
||||
record.note
|
||||
}-${record.no.toString().padStart(3, '0')}`}
|
||||
<br />
|
||||
<Tag color="purple">{text}</Tag>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '房屋性质及行业',
|
||||
dataIndex: 'type',
|
||||
sorter: true,
|
||||
width: 150,
|
||||
render: text => this.bindCodeValue(text, 'house_type'),
|
||||
},
|
||||
{
|
||||
title: '地址',
|
||||
dataIndex: 'address',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '任务截止时间',
|
||||
dataIndex: 'endTime',
|
||||
sorter: true,
|
||||
width: 150,
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const flag = auth({ [authName]: [['edit'], ['delete']] })
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字典数据,之后开始加载表格数据
|
||||
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
|
||||
*/
|
||||
componentDidMount() {
|
||||
const { onLoading, onLoadData } = this.table.current
|
||||
onLoading()
|
||||
getDictData('house_type', 'house_industry').then(codes => {
|
||||
this.setState({ codes }, () => {
|
||||
onLoadData()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
...query,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} id
|
||||
*/
|
||||
onOpen(modal, id) {
|
||||
modal.current.open({ id })
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
const { onLoading, onLoaded, onReloadData } = this.table.current
|
||||
onLoading()
|
||||
try {
|
||||
if (action) {
|
||||
await action
|
||||
}
|
||||
if (successMessage) {
|
||||
Message.success(successMessage)
|
||||
}
|
||||
onReloadData()
|
||||
} catch {
|
||||
onLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} id
|
||||
*/
|
||||
onDelete(id) {
|
||||
this.onAction(apiAction.delete({ id }), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
const { codes, type } = this.state
|
||||
|
||||
return (
|
||||
<Container mode="fluid">
|
||||
<br />
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
ref={this.table}
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
query={
|
||||
<Auth auth={{ [authName]: 'page' }}>
|
||||
<Form.Item label="房屋性质" name="type">
|
||||
<Radio.Group buttonStyle="solid">
|
||||
<Radio.Button value="">全部</Radio.Button>
|
||||
{codes.houseType.map(item => (
|
||||
<Radio.Button key={item.code} value={item.code}>
|
||||
{item.value}
|
||||
</Radio.Button>
|
||||
))}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
{type == 2 && (
|
||||
<Form.Item label="行业" name="industry">
|
||||
<Select
|
||||
allowClear
|
||||
className="w-150"
|
||||
placeholder="请选择行业"
|
||||
>
|
||||
{codes.houseIndustry.map(item => (
|
||||
<Select.Option key={item.code} value={item.code}>
|
||||
{item.value}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
<Form.Item label="地址" name="address">
|
||||
<Input autoComplete="off" placeholder="请输入地址" />
|
||||
</Form.Item>
|
||||
<Form.Item label="房屋唯一编码" name="houseCode">
|
||||
<Input autoComplete="off" placeholder="请输入房屋唯一编码" />
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
moreQuery={
|
||||
<Auth auth={{ [authName]: 'page' }}>
|
||||
<Form.Item label="地址" name="addresstest">
|
||||
<Input autoComplete="off" placeholder="请输入地址" />
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
operator={
|
||||
<Auth auth={{ [authName]: 'add' }}>
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user