diff --git a/src/components/condition-builder/ConditionBuilder.tsx b/src/components/condition-builder/ConditionBuilder.tsx new file mode 100644 index 000000000..96f977f0b --- /dev/null +++ b/src/components/condition-builder/ConditionBuilder.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import {ThemeProps, themeable} from '../../theme'; +import {LocaleProps, localeable} from '../../locale'; +import {uncontrollable} from 'uncontrollable'; +import {FieldTypes, FieldItem} from './types'; + +export interface QueryBuilderProps extends ThemeProps, LocaleProps { + fields: Array; +} + +export class QueryBuilder extends React.Component { + render() { + return

this is querybuilder component

; + } +} + +export default themeable( + localeable( + uncontrollable(QueryBuilder, { + value: 'onChange' + }) + ) +); diff --git a/src/components/condition-builder/config.ts b/src/components/condition-builder/config.ts new file mode 100644 index 000000000..ad707e809 --- /dev/null +++ b/src/components/condition-builder/config.ts @@ -0,0 +1,36 @@ +import {FieldTypes, OperatorType, Funcs} from './types'; + +export interface BaseFieldConfig { + operations: Array; +} + +export interface Config { + funcs?: Funcs; + maxLevel?: number; +} + +const defaultConfig: Config = { + // fields: [], + + // 函数配置示例 + funcs: [ + // { + // label: '文本', + // children: [ + // { + // type: 'LOWERCASE', + // label: '转小写', + // returnType: 'text', + // args: [ + // { + // type: 'text', + // label: '文本', + // valueTypes: ['raw', 'field'] + // } + // ] + // } + // ] + // } + ] +}; +export default defaultConfig; diff --git a/src/components/condition-builder/types.ts b/src/components/condition-builder/types.ts new file mode 100644 index 000000000..da3f74bb6 --- /dev/null +++ b/src/components/condition-builder/types.ts @@ -0,0 +1,85 @@ +type TypedMap = { + [key: string]: T; +}; + +export type FieldTypes = 'text' | 'number' | 'boolean' | 'date' | 'datetime'; + +export type OperatorType = + | 'equals' + | 'not_equals' + | 'less_than' + | 'less_than_or_equals'; + +export type FieldItem = { + type: 'text'; + operators: Array; +}; + +export type ConditionRightValueLiteral = string | number | object | undefined; +export type ConditionRightValue = + | ConditionRightValueLiteral + | { + type: 'raw'; + value: ConditionRightValueLiteral; + } + | { + type: 'func'; + func: string; + args: Array; + } + | { + type: 'field'; + field: string; + } + | { + type: 'expression'; + field: string; + }; + +export interface ConditionRule { + left: string; + op: OperatorType; + right: ConditionRightValue | Array; +} + +export interface ConditionGroup { + conjunction: 'and' | 'or'; + not?: boolean; + children?: Array; +} + +export interface ConditionValue extends ConditionGroup {} + +interface BaseField { + type: FieldTypes; + label: string; + valueTypes?: Array<'raw' | 'field' | 'func' | 'expression'>; + + // valueTypes 里面配置 func 才有效。 + funcs?: Array; + + defaultValue?: any; +} + +interface TextField extends BaseField { + type: 'text'; +} + +type Field = TextField; + +interface FuncGroup { + label: string; + children: Array; +} + +export interface Func { + type: string; + returnType: FieldTypes; + args: Array; + label: string; +} +export interface FuncArg extends BaseField { + isOptional?: boolean; +} +export type Funcs = Array; +export type Fields = Array;