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