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