refactor(高级搜索): 优化自定义字段到搜索项对象的转化
This commit is contained in:
parent
d18ed3d200
commit
bf8c39cee3
|
@ -5,12 +5,19 @@ export function getAdvSearchCustomField(condition, fields) {
|
|||
const components = [];
|
||||
for (let field of fields) {
|
||||
let index = componentArr.findIndex(a => a.key === field.id);
|
||||
if (index > -1) {
|
||||
if (index > -1 || field.id === 'platformStatus') {
|
||||
continue;
|
||||
}
|
||||
if (field.id === 'platformStatus') {
|
||||
continue;
|
||||
// 自定义字段中有"系统字段"属性为否的,记录为含有自定义字段
|
||||
if (!field.system && !condition.custom) {
|
||||
condition.custom = true;
|
||||
}
|
||||
components.push(_createComponent(field));
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
function _createComponent(field) {
|
||||
const componentType = getComponentName(field.type);
|
||||
let component = {
|
||||
key: field.id,
|
||||
|
@ -21,25 +28,29 @@ export function getAdvSearchCustomField(condition, fields) {
|
|||
custom: !field.system,
|
||||
type: field.type
|
||||
}
|
||||
// 自定义字段中有"系统字段"属性为否的,记录为含有自定义字段
|
||||
if (!field.system && !condition.custom) {
|
||||
condition.custom = true;
|
||||
_handleComponentAttributes(component, componentType);
|
||||
return component;
|
||||
}
|
||||
|
||||
function _handleComponentAttributes(component, componentType) {
|
||||
// 作为搜索条件时,可以多选
|
||||
if (componentType === 'MsTableSearchSelect') {
|
||||
component['props'] = {
|
||||
multiple: true
|
||||
}
|
||||
}
|
||||
// 浮点数精度
|
||||
if (componentType === 'MsTableSearchInputNumber' && component.type === 'float') {
|
||||
component['props'] = {
|
||||
precision: 2
|
||||
}
|
||||
}
|
||||
//
|
||||
if (component.type === 'member' || component.type === 'multipleMember') {
|
||||
component['isShow']= operator => {
|
||||
return operator !== OPERATORS.CURRENT_USER.value;
|
||||
}
|
||||
}
|
||||
components.push(component);
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
function getComponentOptions(field) {
|
||||
|
@ -65,6 +76,7 @@ function getComponentName(type) {
|
|||
return 'MsTableSearchDateTimePicker';
|
||||
case 'int':
|
||||
case 'float':
|
||||
return 'MsTableSearchInputNumber';
|
||||
case 'multipleInput':
|
||||
return 'MsTableSearchInput'; // todo 创建对应组件
|
||||
default:
|
||||
|
@ -104,6 +116,11 @@ function getComponentOperator(componentType, fieldType, async) {
|
|||
options: [OPERATORS.BETWEEN, OPERATORS.GT, OPERATORS.GE, OPERATORS.LT, OPERATORS.LE, OPERATORS.EQ]
|
||||
}
|
||||
break;
|
||||
case 'MsTableSearchInputNumber':
|
||||
operator = {
|
||||
options: [OPERATORS.GT, OPERATORS.GE, OPERATORS.LT, OPERATORS.LE, OPERATORS.EQ]
|
||||
}
|
||||
break;
|
||||
}
|
||||
return operator;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue