From bf8c39cee33c7d851f379d31a1d2e3191ae12f64 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 27 Jun 2022 15:15:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=AB=98=E7=BA=A7=E6=90=9C=E7=B4=A2):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=88=B0=E6=90=9C=E7=B4=A2=E9=A1=B9=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=9A=84=E8=BD=AC=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/search/custom-component.js | 71 ++++++++++++------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/frontend/src/business/components/common/components/search/custom-component.js b/frontend/src/business/components/common/components/search/custom-component.js index db0d28d963..d9fed1af2f 100644 --- a/frontend/src/business/components/common/components/search/custom-component.js +++ b/frontend/src/business/components/common/components/search/custom-component.js @@ -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; }