From 0880a17726e009f1ee5333cdbd453f79211200ef Mon Sep 17 00:00:00 2001 From: manzhenhua Date: Fri, 10 Apr 2020 00:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9searchView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/DataView/index.js | 45 +++++++++++++++++++++++++++++----- components/SearchView/index.js | 1 - 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/components/DataView/index.js b/components/DataView/index.js index 1f95afd..cb30e19 100644 --- a/components/DataView/index.js +++ b/components/DataView/index.js @@ -135,7 +135,7 @@ function changeDateRange(props, changedValues, allValues) { return allValues; } -function formatSelect(val, options) { +export function formatSelect(val, options) { if (Array.isArray(val) && val.length > 0) { return val.map((item) => { return { @@ -557,11 +557,37 @@ export default class DataView extends React.Component { } return data; }; + filterSubComChangeParams = (key) => { + const { searchCols, advancedSearchCols } = this.props; + const sumSearchCols = [...(searchCols || []), ...(advancedSearchCols || [])]; + let fn = null; + if (!Array.isArray(sumSearchCols)) return null; + const filterFun = (data) => { + if (data.key === key && Object.prototype.toString(data) === '[object Object]') { + const componentAttr = data.componentAttr || {}; + const onChangeParams = componentAttr.onChangeParams; + if (onChangeParams && typeof onChangeParams === 'function') { + fn = onChangeParams; + return; + } + } + if (Array.isArray(data)) { + data.map(ls => filterFun(ls)); + } + } + filterFun(sumSearchCols); + return fn; + } // 更改查询条件 - _changeSearchForm = (props, changedValues, allValues) => { - const newData = changeDateRange(props, changedValues, allValues); - this.setState({ + _changeSearchForm = async (props, changedValues, allValues) => { + let newData = changeDateRange(props, changedValues, allValues); + // 回调配置项里面changeParams方法 + const onChangeParams = this.filterSubComChangeParams(Object.keys(changedValues)[0]); + if (onChangeParams) { + newData = await onChangeParams(changedValues, newData) || newData + } + await this.setState({ searchForm: newData, currentSiftNum: 0, }); @@ -596,9 +622,16 @@ export default class DataView extends React.Component { }; // 删除指定搜索条件 - _onRemoveItem = (values) => { + _onRemoveItem = async (values) => { const { searchForm } = this.state; - const formData = removeItem(searchForm, values); + let formData = removeItem(searchForm, values); + // 回调配置项里面changeParams方法 + const onChangeParams = this.filterSubComChangeParams(values.key); + if (onChangeParams) { + const obj = {} + obj[values.key] = undefined; + formData = await onChangeParams(obj, formData) || formData + } this.setState( { searchForm: formData, diff --git a/components/SearchView/index.js b/components/SearchView/index.js index eb4fe3b..7a9ec8c 100644 --- a/components/SearchView/index.js +++ b/components/SearchView/index.js @@ -346,7 +346,6 @@ class SearchView extends React.Component { if (this.props.modal === 'modal') { return this._renderModalForm(col); } - return (
{!!label &&
{label}
} -- 2.21.0