Skip to content

Commit

Permalink
feat:ConditionBuilder字段配置支持defaultOp
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm-lv committed Nov 27, 2023
1 parent 9c92c4b commit b2f5916
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/amis-ui/src/components/condition-builder/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ export class ConditionItem extends React.Component<ConditionItemProps> {

@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;
Expand Down
6 changes: 6 additions & 0 deletions packages/amis-ui/src/components/condition-builder/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const defaultConfig: ConditionBuilderConfig = {
]
},
number: {
defaultOp: 'equal',
operators: [
'equal',
'not_equal',
Expand All @@ -75,6 +76,7 @@ const defaultConfig: ConditionBuilderConfig = {
]
},
date: {
defaultOp: 'equal',
operators: [
'equal',
'not_equal',
Expand All @@ -90,6 +92,7 @@ const defaultConfig: ConditionBuilderConfig = {
},

time: {
defaultOp: 'equal',
operators: [
'equal',
'not_equal',
Expand All @@ -105,6 +108,7 @@ const defaultConfig: ConditionBuilderConfig = {
},

datetime: {
defaultOp: 'equal',
operators: [
'equal',
'not_equal',
Expand All @@ -120,6 +124,7 @@ const defaultConfig: ConditionBuilderConfig = {
},

select: {
defaultOp: 'select_equals',
operators: [
'select_equals',
'select_not_equals',
Expand All @@ -130,6 +135,7 @@ const defaultConfig: ConditionBuilderConfig = {
},

boolean: {
defaultOp: 'equal',
operators: ['equal', 'not_equal']
}
}
Expand Down

0 comments on commit b2f5916

Please sign in to comment.