// @ts-nocheck export class RequestParameter { constructor (name: string | undefined = undefined, value: any[] | undefined = undefined) { this.parameter = { fieldGroup: { type: 'FieldGroup', group: true, andOr: 'AND', fields: [] }, ordSort: [], pageable: {} } } private setValue (value, oper) { if (Object.prototype.toString.call(value) === '[object Array]') { if (value.length === 0) { throw new Error('数组的值不能为空!!!') } } else { if (oper === 'LIKE') { value = [`%${value}%`] } else { value = [value] } } return value } // AndFields (name, value: any, oper = 'EQUAL', andOr = 'AND', model: any) { AndFields ({ name, value, label, oper = 'EQUAL', andOr = 'AND' }) { const type = ['EQUAL', 'NOT_EQUAL', 'LIKE', 'NOT_LIKE', 'BETWEEN', 'NOT_BETWEEN', 'GREATER_THAN', 'GREATER_THAN_OR_EQUAL', 'LESS_THAN', 'LESS_THAN_OR_EQUAL', 'IS_NULL', 'NOT_NULL', 'IN', 'NOT_IN', 'MATCH'] if (!['AND', 'OR'].includes(andOr)) { throw new Error('andOr 不等于 AND || OR' + '传入的值是: ' + andOr) } if (!type.includes(oper)) { throw new Error('oper 不等于' + type + '传入的值是:' + oper) } // value 值 后端是需要的一个数组 if (!['[object String]', '[object Date]', '[object Array]', '[object Number]'].includes(Object.prototype.toString.call(value))) { throw new Error('value 不是 数组 || 字符串 || 数值, 传入的是:' + Object.prototype.toString.call(value)) } // 处理 value const value1 = this.setValue(value, oper) const label1 = label && label.length > 0 ? this.setValue(label, oper) : '' this.parameter.fieldGroup.fields.push({ type: 'Field', group: false, andOr, name, oper, value: value1, label: label1 }) return this } Sort (name, order) { if (order !== 'ASC' && order !== 'DESC') { throw new Error('排序的 value 不等于 ASC || DESC') } this.parameter.ordSort.push({ name: name, order: order }) return this } Pageable (pageNum = 1, pageSize = 20, pageable = true) { if (pageable === false) { this.parameter.pageable = { pageable: pageable } return this } // 只允许输入整数 const reg = /^\d+$/ if (!(reg.test(pageNum) && reg.test(pageSize))) { throw new Error('只能是整数') } if (Object.prototype.toString.call(pageable) !== '[object Boolean]') { throw new Error('分页的开关必须是 布尔值') } this.parameter.pageable = { pageNum: pageNum, pageSize: pageSize, pageable: pageable } return this } }