condition-builder 部分代码

This commit is contained in:
liaoxuezhi 2020-08-13 00:16:32 +08:00
parent 69bcc57321
commit a68a9c84d4
3 changed files with 144 additions and 0 deletions

View File

@ -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<FieldItem>;
}
export class QueryBuilder extends React.Component<QueryBuilderProps> {
render() {
return <p>this is querybuilder component</p>;
}
}
export default themeable(
localeable(
uncontrollable(QueryBuilder, {
value: 'onChange'
})
)
);

View File

@ -0,0 +1,36 @@
import {FieldTypes, OperatorType, Funcs} from './types';
export interface BaseFieldConfig {
operations: Array<OperatorType>;
}
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;

View File

@ -0,0 +1,85 @@
type TypedMap<T> = {
[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<OperatorType>;
};
export type ConditionRightValueLiteral = string | number | object | undefined;
export type ConditionRightValue =
| ConditionRightValueLiteral
| {
type: 'raw';
value: ConditionRightValueLiteral;
}
| {
type: 'func';
func: string;
args: Array<ConditionRightValue>;
}
| {
type: 'field';
field: string;
}
| {
type: 'expression';
field: string;
};
export interface ConditionRule {
left: string;
op: OperatorType;
right: ConditionRightValue | Array<ConditionRightValue>;
}
export interface ConditionGroup {
conjunction: 'and' | 'or';
not?: boolean;
children?: Array<ConditionRule | ConditionGroup>;
}
export interface ConditionValue extends ConditionGroup {}
interface BaseField {
type: FieldTypes;
label: string;
valueTypes?: Array<'raw' | 'field' | 'func' | 'expression'>;
// valueTypes 里面配置 func 才有效。
funcs?: Array<string>;
defaultValue?: any;
}
interface TextField extends BaseField {
type: 'text';
}
type Field = TextField;
interface FuncGroup {
label: string;
children: Array<Func>;
}
export interface Func {
type: string;
returnType: FieldTypes;
args: Array<FuncArg>;
label: string;
}
export interface FuncArg extends BaseField {
isOptional?: boolean;
}
export type Funcs = Array<Func | FuncGroup>;
export type Fields = Array<Field>;