const parseFilters = (filter: any, defaultListOp: any) => {标签:存在,console,log,57,splitKey,---,拼接,result,operation From: https://blog.51cto.com/u_15460007/6052182
const result: any = {}
console.log(filter,"filter---1")
//{is_delete: 0, name@like: '我是测试'} 'filter---1'
console.log(defaultListOp,"defaultListOp---2")
//eq defaultListOp---2
Object.keys(filter).forEach(function (key) {
// key: the name of the object key
//属性按照@分割
const splitKey = key.split('@');
console.log(splitKey,"splitKey---2")
//['is_delete'] 'splitKey---2' ['name', 'like'] 'splitKey---2'
//如果长度为2 取出数组的属性值
const operation = splitKey.length == 2 ? splitKey[1] : defaultListOp;
console.log(operation,"operation")
let values;
//如果包含like这个属性 拉取到当前的值 拿取到对应的属性的key值
if (operation.includes('like')) {
values = filter[key].trim().split(' ');
} else {
values = [filter[key]];
}
console.log(values,"values")
//[0] 'values' ['我是测试'] 'values'
values.forEach((value: any) => {
//进行拼接
// if operator is intentionally blank, rpc syntax
let op = operation.includes('like') ? `${operation}.*${value}*` : operation.length == 0 ? `${value}` : `${operation}.${value}`;
console.log(op,"oplist---3")
console.log(splitKey,"splitKey")
if (result[splitKey[0]] === undefined) {
// first operator for the key, we add it to the dict
result[splitKey[0]] = op;
console.log(result[splitKey[0]],"result---test1")
}
else {
if (!Array.isArray(result[splitKey[0]])) {
// second operator, we transform to an array
result[splitKey[0]] = [result[splitKey[0]], op]
console.log(result[splitKey[0]],"result---test2")
} else {
// third and subsequent, we add to array
result[splitKey[0]].push(op);
console.log(result[splitKey[0]],"result---test3")
}
}
});
});
console.log(result,"result--zoom")
return result;
}