fix: 修复开启 autoGenerateFilter 后同时有没有可搜索项时, 接口不初始化的问题 (#3500)

This commit is contained in:
liaoxuezhi 2022-01-26 16:26:43 +08:00 committed by GitHub
parent c79b40c426
commit 27671920ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View File

@ -465,12 +465,16 @@ export default class CRUD extends React.Component<CRUDProps, any> {
}
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

View File

@ -500,7 +500,7 @@ export default class Table extends React.Component<TableProps, object> {
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<TableProps, object> {
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<TableProps, object> {
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'

View File

@ -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 {