diff --git a/packages/amis-ui/src/components/condition-builder/Item.tsx b/packages/amis-ui/src/components/condition-builder/Item.tsx index f9b4c7513540..619191e5a496 100644 --- a/packages/amis-ui/src/components/condition-builder/Item.tsx +++ b/packages/amis-ui/src/components/condition-builder/Item.tsx @@ -80,10 +80,16 @@ export class ConditionItem extends React.Component { @autobind handleLeftChange(leftValue: any) { + const {fields, config} = this.props; + // 获取默认Op + const field: any = fields.find( + (f: any) => f.name === leftValue.field + ) as any; + const value = { ...this.props.value, left: leftValue, - op: undefined, + op: field?.defaultOp || config.types[field?.type]?.defaultOp || undefined, right: undefined }; const onChange = this.props.onChange; diff --git a/packages/amis-ui/src/components/condition-builder/config.ts b/packages/amis-ui/src/components/condition-builder/config.ts index 0a4820280955..d9e201217dc1 100644 --- a/packages/amis-ui/src/components/condition-builder/config.ts +++ b/packages/amis-ui/src/components/condition-builder/config.ts @@ -61,6 +61,7 @@ const defaultConfig: ConditionBuilderConfig = { ] }, number: { + defaultOp: 'equal', operators: [ 'equal', 'not_equal', @@ -75,6 +76,7 @@ const defaultConfig: ConditionBuilderConfig = { ] }, date: { + defaultOp: 'equal', operators: [ 'equal', 'not_equal', @@ -90,6 +92,7 @@ const defaultConfig: ConditionBuilderConfig = { }, time: { + defaultOp: 'equal', operators: [ 'equal', 'not_equal', @@ -105,6 +108,7 @@ const defaultConfig: ConditionBuilderConfig = { }, datetime: { + defaultOp: 'equal', operators: [ 'equal', 'not_equal', @@ -120,6 +124,7 @@ const defaultConfig: ConditionBuilderConfig = { }, select: { + defaultOp: 'select_equals', operators: [ 'select_equals', 'select_not_equals', @@ -130,6 +135,7 @@ const defaultConfig: ConditionBuilderConfig = { }, boolean: { + defaultOp: 'equal', operators: ['equal', 'not_equal'] } }