fix:crud filter combo模式不能清空查询条件 (#1990)

Co-authored-by: dqc <qianchuan.deng@gmail.com>
This commit is contained in:
qianchuan 2021-05-24 10:23:56 +08:00 committed by GitHub
parent 3e9df63fad
commit f0a22ffba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -784,8 +784,18 @@ export default class CRUD extends React.Component<CRUDProps, any> {
perPageField,
loadDataOnceFetchOnFilter
} = this.props;
values = syncLocation ? qs.parse(qsstringify(values)) : values;
values = syncLocation
? qs.parse(
qsstringify(
values,
{
arrayFormat: 'indices',
encodeValuesOnly: true
},
true
)
)
: values;
store.updateQuery(
{
...values,

View File

@ -1282,8 +1282,14 @@ export function qsstringify(
options: any = {
arrayFormat: 'indices',
encodeValuesOnly: true
}
},
keepEmptyArray?: boolean
) {
// qs会保留空字符串。fix: Combo模式的空数组无法清空。改为存为空字符串只转换一层
keepEmptyArray &&
Object.keys(data).forEach((key: any) => {
Array.isArray(data[key]) && !data[key].length && (data[key] = '');
});
return qs.stringify(data, options);
}