From 27671920ab21ad57ab1d50c8d35f5368b07184e9 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Wed, 26 Jan 2022 16:26:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=90=AF=20a?= =?UTF-8?q?utoGenerateFilter=20=E5=90=8E=E5=90=8C=E6=97=B6=E6=9C=89?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8F=AF=E6=90=9C=E7=B4=A2=E9=A1=B9=E6=97=B6?= =?UTF-8?q?,=20=E6=8E=A5=E5=8F=A3=E4=B8=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#3500)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/CRUD.tsx | 6 +++++- src/renderers/Table/index.tsx | 23 +++++++++++++++++++++-- src/store/table.ts | 4 +--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/renderers/CRUD.tsx b/src/renderers/CRUD.tsx index 357d73579..20341acd5 100644 --- a/src/renderers/CRUD.tsx +++ b/src/renderers/CRUD.tsx @@ -465,12 +465,16 @@ export default class CRUD extends React.Component { } componentDidMount() { - const {store, autoGenerateFilter} = this.props; + const {store, autoGenerateFilter, columns} = this.props; if (this.props.perPage) { store.changePage(store.page, this.props.perPage); } + // 没有 filter 或者 没有展示 filter 时应该默认初始化一次, + // 否则就应该等待 filter 里面的表单初始化的时候才初始化 + // 另外autoGenerateFilter时,table 里面会单独处理这块逻辑 + // 所以这里应该忽略 autoGenerateFilter 情况 if ( (!this.props.filter || (store.filterTogggable && !store.filterVisible)) && !autoGenerateFilter diff --git a/src/renderers/Table/index.tsx b/src/renderers/Table/index.tsx index 8e4122a98..ab424c955 100644 --- a/src/renderers/Table/index.tsx +++ b/src/renderers/Table/index.tsx @@ -500,7 +500,7 @@ export default class Table extends React.Component { this.handleMouseLeave = this.handleMouseLeave.bind(this); this.subFormRef = this.subFormRef.bind(this); this.handleColumnToggle = this.handleColumnToggle.bind(this); - this.renderAutoFilterForm = this.renderAutoFilterForm.bind(this); + this.updateAutoFillHeight = this.updateAutoFillHeight.bind(this); const { @@ -614,6 +614,19 @@ export default class Table extends React.Component { window.addEventListener('resize', this.affixDetect); this.updateAutoFillHeight(); window.addEventListener('resize', this.updateAutoFillHeight); + + const {store, autoGenerateFilter, onSearchableFromInit} = this.props; + + // autoGenerateFilter 开启后 + // 如果没有一个 searchable 的 column crud 就不会初始化加载 + // 所以这里加个判断默认初始加载一次 + if ( + autoGenerateFilter && + !store.searchableColumns.length && + onSearchableFromInit + ) { + onSearchableFromInit({}); + } } /** @@ -1470,7 +1483,13 @@ export default class Table extends React.Component { activedSearchableColumns.forEach((column, index) => { groupedSearchableColumns[index % 3].body.push({ - ...column.searchable, + ...(column.searchable === true + ? { + type: 'input-text', + name: column.name, + label: column.label + } + : column.searchable), name: column.searchable?.name ?? column.name, label: column.searchable?.label ?? column.label, mode: 'horizontal' diff --git a/src/store/table.ts b/src/store/table.ts index da848c329..15c473ee7 100644 --- a/src/store/table.ts +++ b/src/store/table.ts @@ -518,9 +518,7 @@ export const TableStore = iRendererStore } function getSearchableColumns() { - return self.columns.filter( - column => column.searchable && isObject(column.searchable) - ); + return self.columns.filter(column => column.searchable); } return {