fix: CRUD2 中form组件reset不生效问题 (#6405)

This commit is contained in:
sansiro 2023-03-23 11:14:10 +08:00 committed by GitHub
parent 183431c3b9
commit 0291fdc7d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -388,7 +388,7 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
} }
initQuery(values: object) { initQuery(values: object) {
const {store, orderBy, orderDir} = this.props; const {store, orderBy, orderDir, loadType} = this.props;
const params: any = {}; const params: any = {};
if (orderBy) { if (orderBy) {
@ -402,7 +402,8 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
...values, ...values,
...store.query ...store.query
}, },
replaceQuery: this.props.initFetch !== false replaceQuery: this.props.initFetch !== false,
loadMore: loadType === 'more'
}); });
// 保留一次用于重置查询条件 // 保留一次用于重置查询条件
@ -426,9 +427,10 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
query?: object; // 查询条件,没有将使用当前的 query?: object; // 查询条件,没有将使用当前的
resetQuery?: boolean; resetQuery?: boolean;
replaceQuery?: boolean; replaceQuery?: boolean;
loadMore?: boolean;
}) { }) {
const {store, syncLocation, env, pageField, perPageField} = this.props; const {store, syncLocation, env, pageField, perPageField} = this.props;
let {query, resetQuery, replaceQuery} = data || {}; let {query, resetQuery, replaceQuery, loadMore} = data || {};
query = query =
syncLocation && query syncLocation && query
@ -444,9 +446,10 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
perPageField, perPageField,
replaceQuery replaceQuery
); );
store.changePage(1);
this.lastQuery = store.query; this.lastQuery = store.query;
this.getData(undefined, undefined, undefined); this.getData(undefined, undefined, undefined, loadMore ?? false);
} }
handleStopAutoRefresh() { handleStopAutoRefresh() {
@ -1015,15 +1018,15 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
}; };
return render(region, schema, { return render(region, schema, {
...props,
// 包两层,主要是为了处理以下 case // 包两层,主要是为了处理以下 case
// 里面放了个 formform 提交过来的时候不希望把 items 这些发送过来。 // 里面放了个 formform 提交过来的时候不希望把 items 这些发送过来。
// 因为会把数据呈现在地址栏上。 // 因为会把数据呈现在地址栏上。
/** data 可以被覆盖,因为 filter 中不需要额外的 data */
data: createObject( data: createObject(
createObject(store.filterData, store.getData(this.props.data)), createObject(store.filterData, store.getData(this.props.data)),
{} {}
), ),
render: this.renderChild, ...props,
...childProps ...childProps
}); });
} }
@ -1049,8 +1052,14 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
return filter.map((item, index) => return filter.map((item, index) =>
this.renderChild(`filter/${index}`, item, { this.renderChild(`filter/${index}`, item, {
key: index + '', key: index + 'filter',
onSubmit: (data: any) => this.handleSearch({query: data}) data: this.props.store.filterData,
onSubmit: (data: any) => this.handleSearch({query: data}),
onReset: () =>
this.handleSearch({
resetQuery: true,
replaceQuery: true
})
}) })
); );
} }