refactor(高级搜索): 优化自定义字段到搜索项对象的转化

This commit is contained in:
shiziyuan9527 2022-06-27 15:15:59 +08:00 committed by shiziyuan9527
parent d18ed3d200
commit bf8c39cee3
1 changed files with 44 additions and 27 deletions

View File

@ -5,43 +5,54 @@ 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;
}
const componentType = getComponentName(field.type);
let component = {
key: field.id,
name: componentType,
label: field.name,
operator: getComponentOperator(componentType, field.type, false), // 自定义字段可以异步获取选项?
options: getComponentOptions(field),
custom: !field.system,
type: field.type
}
// 自定义字段中有"系统字段"属性为否的,记录为含有自定义字段
if (!field.system && !condition.custom) {
condition.custom = true;
}
// 作为搜索条件时,可以多选
if (componentType === 'MsTableSearchSelect') {
component['props'] = {
multiple: true
}
}
//
if (component.type === 'member' || component.type === 'multipleMember') {
component['isShow']= operator => {
return operator !== OPERATORS.CURRENT_USER.value;
}
}
components.push(component);
components.push(_createComponent(field));
}
return components;
}
function _createComponent(field) {
const componentType = getComponentName(field.type);
let component = {
key: field.id,
name: componentType,
label: field.name,
operator: getComponentOperator(componentType, field.type, false), // 自定义字段可以异步获取选项?
options: getComponentOptions(field),
custom: !field.system,
type: field.type
}
_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;
}
}
}
function getComponentOptions(field) {
return Array.isArray(field.options) ? (field.options.length > 0 ? field.options : []) : [];
}
@ -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;
}