From cd9ab746e41dce5410158b3f9b88894d80dbe209 Mon Sep 17 00:00:00 2001 From: manzhenhua Date: Fri, 10 Apr 2020 13:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=90=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/DataView/index.js | 31 +++++++++++++++++++++---------- components/SearchView/index.js | 3 +++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/components/DataView/index.js b/components/DataView/index.js index cb30e19..477baaf 100644 --- a/components/DataView/index.js +++ b/components/DataView/index.js @@ -24,6 +24,10 @@ import { getOptionName, replacePageNum } from '@/utils/utils'; import { SIFT_TYPE } from '@/utils/enum'; import storage from '@/utils/storage'; /* eslint-disable react/sort-comp */ // 关闭下划线变量检测 // 关闭方法排序检测 // 多维数组降维成一维数组 +/** + * + * @param {initView} fun 用于数据初始化之后的数据处理,每个自控可单独处理回调 + */ /* eslint-disable no-underscore-dangle */ function reduceDimension(arr) { return Array.prototype.concat.apply([], arr); @@ -118,7 +122,7 @@ function formarRange(data) { // 日期区间格式化(时间部分为00:00:00-23:59:59) function changeDateRange(props, changedValues, allValues) { const key = Object.keys(changedValues)[0]; - const cols = reduceDimension([...props.searchCols, ...props.advancedSearchCols]); + const cols = reduceDimension([...(props.searchCols || []), ...(props.advancedSearchCols || [])]); const col = cols.find((item) => { return item.key === key; }); @@ -149,12 +153,10 @@ export function formatSelect(val, options) { if (Array.isArray(val) && val.length === 0) { return []; } - return { - id: val, - name: options.find((item) => { - return item.id === val; - }).name, - }; + const selectObj = options.find((item) => { + return item.id === val; + }) || {} + return selectObj; } function formatForm(formData, searchCols) { @@ -295,8 +297,9 @@ export default class DataView extends React.Component { // this.getDefaultSift(); } - componentDidMount() { - this.getSiftData(); + async componentDidMount() { + await this.getSiftData(); + await this.initView(); replacePageNum('pageNum', this.state.current, this.fetchPage); // 当url里面有pageNum参数时,获取url里面的参数进行请求 } @@ -381,6 +384,14 @@ export default class DataView extends React.Component { message.error(res && res.message); } } + initView = () => { // 该方法用于回调子空间的initView方法,只会执行一次 + const { initView } = this.props; + const { searchForm } = this.state; + if (initView) { + initView({ searchForm, instance: this, form: this.props.form }); + } + + } // eslint-disable-next-line react/sort-comp _beforeFetch() { @@ -651,7 +662,7 @@ export default class DataView extends React.Component { // 渲染查询条件按钮组件 _renderFilterBtn = () => { let { searchCols, advancedSearchCols } = this.props; - searchCols = [...searchCols, ...advancedSearchCols]; + searchCols = [...(searchCols || []), ...(advancedSearchCols || [])]; const { searchForm, siftDataArr, currentSiftNum } = this.state; if (searchCols === null || searchCols.length <= 0) return null; const chooseItems = formatForm(searchForm, searchCols); diff --git a/components/SearchView/index.js b/components/SearchView/index.js index 7a9ec8c..98f31b5 100644 --- a/components/SearchView/index.js +++ b/components/SearchView/index.js @@ -23,6 +23,9 @@ import styles from './index.less'; /* eslint-disable no-underscore-dangle */ // 基础搜索组件 // mode分为page 为页面模式下的搜索框, modal 弹框模式下搜索组件 +/** + * select 拓展参数,将options 设置成function,用于基于业务处理options回调 + */ const formItemLayout = { -- 2.21.0