feat: crud filter 支持深层数组的清除 Close: #7083

This commit is contained in:
2betop 2023-06-16 16:05:20 +08:00
parent 796db753fb
commit ff8051fb0f
2 changed files with 74 additions and 5 deletions

View File

@ -1310,11 +1310,12 @@ export function qsstringify(
},
keepEmptyArray?: boolean
) {
// qs会保留空字符串。fix: Combo模式的空数组无法清空。改为存为空字符串只转换一层
keepEmptyArray &&
Object.keys(data).forEach((key: any) => {
Array.isArray(data[key]) && !data[key].length && (data[key] = '');
});
// qs会保留空字符串。fix: Combo模式的空数组无法清空。改为存为空字符串
if (keepEmptyArray) {
data = JSONValueMap(data, value =>
Array.isArray(value) && !value.length ? '' : value
);
}
return qs.stringify(data, options);
}
@ -1741,6 +1742,73 @@ export function JSONTraverse(
});
}
/**
*
* @param json
* @param mapper
* @returns
*/
export function JSONValueMap(
json: any,
mapper: (
value: any,
key: string | number,
host: Object,
stack: Array<Object>
) => any,
stack: Array<Object> = []
) {
if (!isPlainObject(json) && !Array.isArray(json)) {
return json;
}
const iterator = (
origin: any,
key: number | string,
host: any,
stack: Array<any> = []
) => {
let maped: any = mapper(origin, key, host, stack);
if (maped === origin && (isPlainObject(origin) || Array.isArray(origin))) {
return JSONValueMap(origin, mapper, stack);
}
return maped;
};
if (Array.isArray(json)) {
let flag = false;
let mapped = json.map((value, index) => {
let result: any = iterator(value, index, json, [json].concat(stack));
if (result !== value) {
flag = true;
return result;
}
return value;
});
return flag ? mapped : json;
}
let flag = false;
const toUpdate: any = {};
Object.keys(json).forEach(key => {
const value: any = json[key];
let result: any = iterator(value, key, json, [json].concat(stack));
if (result !== value) {
flag = true;
toUpdate[key] = result;
return;
}
});
return flag
? {
...json,
...toUpdate
}
: json;
}
export function convertArrayValueToMoment(
value: number[],
types: string[],

View File

@ -251,6 +251,7 @@ export class ResultBox extends React.Component<ResultBoxProps> {
maxTagCount,
overflowTagPopover,
showArrow,
popOverContainer,
...rest
} = this.props;
const isFocused = this.state.isFocused;