提交 bf92d788 编写于 作者: RedPig97's avatar RedPig97

update: 搜索栏条件更新

上级 2731d379
......@@ -139,15 +139,13 @@ import moment from 'moment';
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public getData(): any {
let data: any = {};
<#-- if(!Object.is(this.query, '')) {
Object.assign(data, { query: this.query })
} -->
if(this.filterFields.length > 0) {
let filter: any = this.getFilter();
Object.assign(data, { filter: filter ? JSON.stringify(filter) : null })
return filter;
}
return data;
}
/**
......@@ -160,37 +158,11 @@ import moment from 'moment';
if(this.filterItems.length === 0) {
return null;
}
let ands: any[] = this.transformAnd(this.filterItems);
this.transformResult(ands, '$and');
if(ands.length === 0) {
let params: any = this.transformAnd(this.filterItems);
if(Object.keys(params).length === 0) {
return null;
}
return { '$and': ands };
}
/**
* 处理结果集
*
* @return {*}
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public transformResult(datas: any[], pName: string) {
let items: any[] = [];
for(let i = datas.length - 1; i >= 0; i--) {
let data: any = datas[i];
let field: string = Object.is(pName, '$and') ? '$or' : '$and';
if(data.hasOwnProperty(field)) {
items.push(data);
datas.splice(i, 1);
this.transformResult(data[field], field);
}
}
if(items.length > 0) {
let item: any = {};
item[pName] = items;
datas.push(item);
}
return params;
}
/**
......@@ -200,47 +172,12 @@ import moment from 'moment';
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public transformAnd(datas: any[]): any {
let result: any[] = [];
datas.forEach((data: any) => {
let item: any = {};
if(data.field && data.mode) {
item[data.field] = {};
let valField: string = data.editor ? data.editor : data.field;
item[data.field][data.mode] = (data[valField] == null ? '' : data[valField]);
result.push(item)
} else if(Object.is(data.label, '$and')) {
let items: any[] = this.transformAnd(data.children);
result = [...result, ...items];
} else if(Object.is(data.label, '$or')) {
item[data.label] = this.transformOr(data.children);
result.push(item)
}
})
return result;
}
/**
* 处理或逻辑
*
* @return {*}
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public transformOr(datas: any[]) {
let result: any[] = [];
let result: any = {};
datas.forEach((data: any) => {
let item: any = {};
if(data.field && data.mode) {
item[data.field] = {};
let valField: string = data.editor ? data.editor : data.field;
item[data.field][data.mode] = (data[valField] == null ? '' : data[valField]);
result.push(item);
} else if(Object.is(data.label, '$and')) {
item[data.label] = this.transformAnd(data.children);
result.push(item)
} else if(Object.is(data.label, '$or')) {
item[data.label] = this.transformOr(data.children);
result.push(item);
}
Object.assign(result, {[`n_${data.field}_${data.mode}`]: data[valField]});
}
})
return result;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册