|
|
@ -39,6 +39,9 @@ export class Criteria extends Base { |
|
|
|
*/ |
|
|
|
private buildCriteria(value: any, fieldName: string) { |
|
|
|
const queryOperator = this.queryFormFields[fieldName]['queryOperator']; |
|
|
|
if (typeof value === 'string') { |
|
|
|
value = value.trim(); |
|
|
|
} |
|
|
|
if (!Tools.isEmpty(queryOperator)) { |
|
|
|
return { |
|
|
|
fieldName: fieldName, |
|
|
@ -58,11 +61,22 @@ export class Criteria extends Base { |
|
|
|
value: value, |
|
|
|
}; |
|
|
|
} else if (typeof value === 'object' && this.queryFormFields[fieldName]['type'] === 'w-date-range') { |
|
|
|
const endDateStr = value['to']; |
|
|
|
let toValue = value['to']; |
|
|
|
if (!Tools.isEmpty(endDateStr)) { |
|
|
|
toValue = this.strDateAddDay(endDateStr); |
|
|
|
} |
|
|
|
return { |
|
|
|
fieldName: fieldName, |
|
|
|
operator: Constant.CRITERIA_OPERATOR.betweenInclusive, |
|
|
|
start: value['from'], |
|
|
|
end: value['to'], |
|
|
|
end: toValue, |
|
|
|
}; |
|
|
|
} else if (this.queryFormFields[fieldName]['type'] === 'w-select') { |
|
|
|
return { |
|
|
|
fieldName: fieldName, |
|
|
|
operator: Constant.CRITERIA_OPERATOR.equals, |
|
|
|
value: value, |
|
|
|
}; |
|
|
|
} else { |
|
|
|
return { |
|
|
@ -73,6 +87,28 @@ export class Criteria extends Base { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 字符串日期增加天数 |
|
|
|
* @param dateStr 字符串日期 |
|
|
|
* @param dayNum 增加的天数 |
|
|
|
* @returns |
|
|
|
*/ |
|
|
|
private strDateAddDay(dateStr: string, dayNum: number = 1) { |
|
|
|
// 拆分日期并转为数字(月份需减1,因JS月份从0开始)
|
|
|
|
const [year, month, day] = dateStr.split('-').map(Number); |
|
|
|
const date = new Date(year, month - 1, day); |
|
|
|
|
|
|
|
// 核心:增加一天(自动处理跨月/年)
|
|
|
|
date.setDate(date.getDate() + dayNum); |
|
|
|
|
|
|
|
// 格式化为YYYY-MM-DD(自动补零)
|
|
|
|
const newYear = date.getFullYear(); |
|
|
|
const newMonth = String(date.getMonth() + 1).padStart(2, '0'); |
|
|
|
const newDay = String(date.getDate()).padStart(2, '0'); |
|
|
|
|
|
|
|
return `${newYear}-${newMonth}-${newDay}`; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据请求入参拼上查询面板构建 criteria 查询对象,转换成 URLSearchParams 后返回 |
|
|
|
* @param reqParams 请求入参 |
|
|
@ -103,7 +139,8 @@ export class Criteria extends Base { |
|
|
|
(!Tools.isEmpty(queryFormData[item]) && Array.isArray(queryFormData[item]) && queryFormData[item].length > 0) |
|
|
|
) { |
|
|
|
if ( |
|
|
|
(this.queryFormFields[item]['type'] === 'w-date-range' && !Tools.isEmpty(queryFormData[item]['from'])) || |
|
|
|
(this.queryFormFields[item]['type'] === 'w-date-range' && |
|
|
|
(!Tools.isEmpty(queryFormData[item]['from']) || !Tools.isEmpty(queryFormData[item]['to']))) || |
|
|
|
this.queryFormFields[item]['type'] !== 'w-date-range' |
|
|
|
) { |
|
|
|
// 根据数据进行operator处理
|
|
|
|