index.tsx
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { useEffect } from 'react';
import {
QxBaseCondition,
QxBaseConditionValueType,
} from '../qx-base-condition';
import { QxConditionSql, SqlType } from '../qx-condition-sql';
import { INode } from '../qx-flow-node-selector';
export const QxCondition: React.FC<QxConditionProps> = ({
value,
className,
style,
enabled = true,
showAssignment = true,
onChange,
node,
nodes
}) => {
const handleChange = (opt: Partial<QxConditionValueType>) => {
onChange?.(Object.assign({}, value, opt, { enabled }));
};
return (
<div className={`qx-condition ${className}`} style={style}>
<QxBaseCondition
mode="condition"
nodes={nodes}
node={node}
showAssignment={showAssignment}
value={value?.operators}
onChange={(condition) => {
handleChange({
operators: condition,
});
}}
/>
{(value?.operators?.length || 0) >= 2 ? (
<QxConditionSql value={value} onChange={handleChange} />
) : null}
</div>
);
};
export interface QxConditionValueType {
/**
* 是否启用条件
*/
enabled?: boolean;
/**
* 条件组合类型
*/
sqlType: SqlType;
/**
* 自定义条件表达式
*/
expression: string;
/**
* 算子
*/
operators: OperatorsType[];
}
export type OperatorsType = QxBaseConditionValueType;
export interface QxConditionProps {
[key: string]: any;
value?: QxConditionValueType;
onChange?: (value: QxConditionValueType) => void;
className?: string;
style?: React.CSSProperties;
node?: INode
nodes?: INode[]
showAssignment?: boolean
}