mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 12:29:24 +08:00
condition-builder 部分代码
This commit is contained in:
parent
69bcc57321
commit
a68a9c84d4
23
src/components/condition-builder/ConditionBuilder.tsx
Normal file
23
src/components/condition-builder/ConditionBuilder.tsx
Normal 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'
|
||||
})
|
||||
)
|
||||
);
|
36
src/components/condition-builder/config.ts
Normal file
36
src/components/condition-builder/config.ts
Normal 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;
|
85
src/components/condition-builder/types.ts
Normal file
85
src/components/condition-builder/types.ts
Normal 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>;
|
Loading…
Reference in New Issue
Block a user