From 6efa44c11bf77f884d55fa075464979945debb58 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Wed, 19 Aug 2020 14:25:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=A1=E4=BB=B6=E7=BB=84?= =?UTF-8?q?=E5=90=88=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/components/Example.tsx | 6 ++ examples/components/Form/ConditionBuilder.jsx | 99 +++++++++++++++++++ scss/components/_condition-builder.scss | 4 + src/components/condition-builder/Group.tsx | 24 +++-- src/components/condition-builder/Item.tsx | 6 +- src/components/condition-builder/config.ts | 40 +------- src/components/condition-builder/index.tsx | 38 +++++-- src/index.tsx | 1 + src/renderers/Form/ConditionBuilder.tsx | 31 ++++++ src/utils/Animation.ts | 6 +- 10 files changed, 196 insertions(+), 59 deletions(-) create mode 100644 examples/components/Form/ConditionBuilder.jsx create mode 100644 src/renderers/Form/ConditionBuilder.tsx diff --git a/examples/components/Example.tsx b/examples/components/Example.tsx index 6e463595c..d4bab5718 100644 --- a/examples/components/Example.tsx +++ b/examples/components/Example.tsx @@ -15,6 +15,7 @@ import StaticFormSchema from './Form/Static'; import HintFormSchema from './Form/Hint'; import FieldSetInTabsFormSchema from './Form/FieldSetInTabs'; import ComboFormSchema from './Form/Combo'; +import ConditionBuilderSchema from './Form/ConditionBuilder'; import SubFormSchema from './Form/SubForm'; import RichTextSchema from './Form/RichText'; import EditorSchema from './Form/Editor'; @@ -226,6 +227,11 @@ export const examples = [ path: '/examples/form/formula', component: makeSchemaRenderer(FormulaFormSchema) }, + { + label: '条件组合', + path: '/examples/form/condition-builder', + component: makeSchemaRenderer(ConditionBuilderSchema) + }, { label: '引用', diff --git a/examples/components/Form/ConditionBuilder.jsx b/examples/components/Form/ConditionBuilder.jsx new file mode 100644 index 000000000..28e69fb38 --- /dev/null +++ b/examples/components/Form/ConditionBuilder.jsx @@ -0,0 +1,99 @@ +export default { + $schema: 'https://houtai.baidu.com/v2/schemas/page.json#', + title: '条件生成器', + body: [ + { + type: 'form', + api: '/api/mock2/saveForm?waitSeconds=2', + title: '', + mode: 'horizontal', + horizontal: { + leftFixed: true + }, + actions: [ + { + label: '查看数据', + type: 'button', + actionType: 'dialog', + dialog: { + title: '数据', + body: '
${conditions|json:2}
' + } + } + ], + controls: [ + { + type: 'condition-builder', + label: '条件组件', + name: 'conditions', + description: + '适合让用户自己拼查询条件,然后后端根据数据生成 query where', + fields: [ + { + label: '文本', + type: 'text', + name: 'text' + }, + { + label: '数字', + type: 'number', + name: 'number' + }, + { + label: '布尔', + type: 'boolean', + name: 'boolean' + }, + { + label: '选项', + type: 'select', + name: 'select', + options: [ + { + label: 'A', + value: 'a' + }, + { + label: 'B', + value: 'b' + }, + { + label: 'C', + value: 'c' + }, + { + label: 'D', + value: 'd' + }, + { + label: 'E', + value: 'e' + } + ] + }, + { + label: '日期', + children: [ + { + label: '日期', + type: 'date', + name: 'date' + }, + { + label: '时间', + type: 'time', + name: 'time' + }, + { + label: '日期时间', + type: 'datetime', + name: 'datetime' + } + ] + } + ] + } + ] + } + ] +}; diff --git a/scss/components/_condition-builder.scss b/scss/components/_condition-builder.scss index 8d1bad73e..40084124e 100644 --- a/scss/components/_condition-builder.scss +++ b/scss/components/_condition-builder.scss @@ -137,6 +137,10 @@ background: rgba(0, 0, 0, 0.03); transition: all 0.3s ease-out; + + > .#{$ns}CBGroup { + margin: 3px; + } } &-body:not(:hover) .#{$ns}CBDelete { diff --git a/src/components/condition-builder/Group.tsx b/src/components/condition-builder/Group.tsx index 9ebeec579..75039fc85 100644 --- a/src/components/condition-builder/Group.tsx +++ b/src/components/condition-builder/Group.tsx @@ -14,6 +14,7 @@ export interface ConditionGroupProps extends ThemeProps { value?: ConditionGroupValue; fields: Fields; funcs?: Funcs; + showNot?: boolean; onChange: (value: ConditionGroupValue) => void; removeable?: boolean; onRemove?: (e: React.MouseEvent) => void; @@ -117,22 +118,25 @@ export class ConditionGroup extends React.Component { config, removeable, onRemove, - onDragStart + onDragStart, + showNot } = this.props; return (
- + {showNot ? ( + + ) : null}