优化条件组合

Change-Id: Ib0dcc208ffbc50a631f657e2faa8df246dc2dd56
This commit is contained in:
2betop 2020-11-02 20:09:17 +08:00
parent f39847315f
commit 2f2d1399d6
5 changed files with 15 additions and 25 deletions

View File

@ -279,7 +279,7 @@
display: block; display: block;
font-size: $fontSizeSm; font-size: $fontSizeSm;
align-self: center; align-self: center;
margin: -5px 0 -5px -8px; margin: -5px 5px -5px -8px;
padding: 5px; padding: 5px;
border-radius: 5px; border-radius: 5px;
user-select: none; user-select: none;

View File

@ -36,7 +36,6 @@ export interface ExpressionProps extends ThemeProps {
valueField?: FieldSimple; valueField?: FieldSimple;
fields?: Field[]; fields?: Field[];
funcs?: Funcs; funcs?: Funcs;
defaultType?: 'value' | 'field' | 'func' | 'formula';
allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>; allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>;
op?: OperatorType; op?: OperatorType;
config: Config; config: Config;
@ -120,12 +119,12 @@ export class Expression extends React.Component<ExpressionProps> {
const { const {
value, value,
valueField, valueField,
defaultType,
allowedTypes, allowedTypes,
funcs, funcs,
fields, fields,
op, op,
classnames: cx classnames: cx,
config
} = this.props; } = this.props;
const inputType = const inputType =
((value as any)?.type === 'field' ((value as any)?.type === 'field'
@ -137,7 +136,6 @@ export class Expression extends React.Component<ExpressionProps> {
: value !== undefined : value !== undefined
? 'value' ? 'value'
: undefined) || : undefined) ||
defaultType ||
allowedTypes?.[0] || allowedTypes?.[0] ||
'value'; 'value';
@ -177,11 +175,11 @@ export class Expression extends React.Component<ExpressionProps> {
{inputType === 'func' ? ( {inputType === 'func' ? (
<ConditionFunc <ConditionFunc
config={config}
value={value as ExpressionFunc} value={value as ExpressionFunc}
onChange={this.handleFuncChange} onChange={this.handleFuncChange}
funcs={funcs} funcs={funcs}
fields={fields} fields={fields}
defaultType={defaultType}
allowedTypes={allowedTypes} allowedTypes={allowedTypes}
/> />
) : null} ) : null}

View File

@ -14,10 +14,10 @@ export class Formula extends React.Component<FormulaProps> {
return ( return (
<div className={cx('CBFormula')}> <div className={cx('CBFormula')}>
<InputBox <InputBox
value={(value as any).value} value={value}
onChange={onChange} onChange={onChange}
placeholder="请输入公式" placeholder="请输入公式"
prefix={<span className={cx('CBFormula-label')}></span>} prefix={<span className={cx('CBFormula-label')}></span>}
/> />
</div> </div>
); );

View File

@ -7,13 +7,14 @@ import {autobind, findTree, noop} from '../../utils/helper';
import ResultBox from '../ResultBox'; import ResultBox from '../ResultBox';
import {Icon} from '../icons'; import {Icon} from '../icons';
import Expression from './Expression'; import Expression from './Expression';
import {Config} from './config';
export interface ConditionFuncProps extends ThemeProps { export interface ConditionFuncProps extends ThemeProps {
value: ExpressionFunc; value: ExpressionFunc;
onChange: (value: ExpressionFunc) => void; onChange: (value: ExpressionFunc) => void;
config: Config;
fields?: Field[]; fields?: Field[];
funcs?: Funcs; funcs?: Funcs;
defaultType?: 'value' | 'field' | 'func' | 'formula';
allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>; allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>;
} }
@ -36,14 +37,7 @@ export class ConditionFunc extends React.Component<ConditionFuncProps> {
} }
renderFunc(func: Func) { renderFunc(func: Func) {
const { const {classnames: cx, fields, value, funcs, config} = this.props;
classnames: cx,
fields,
value,
funcs,
defaultType,
allowedTypes
} = this.props;
return ( return (
<div className={cx('CBFunc-args')}> <div className={cx('CBFunc-args')}>
@ -52,6 +46,7 @@ export class ConditionFunc extends React.Component<ConditionFuncProps> {
<div> <div>
{func.args.map((item, index) => ( {func.args.map((item, index) => (
<Expression <Expression
config={config}
key={index} key={index}
index={index} index={index}
fields={fields} fields={fields}
@ -59,7 +54,6 @@ export class ConditionFunc extends React.Component<ConditionFuncProps> {
valueField={{type: item.type} as any} valueField={{type: item.type} as any}
onChange={this.handleArgChange} onChange={this.handleArgChange}
funcs={funcs} funcs={funcs}
defaultType={defaultType}
// allowedTypes={allowedTypes} // allowedTypes={allowedTypes}
/> />
))} ))}

View File

@ -104,10 +104,11 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
value={value.left} value={value.left}
onChange={this.handleLeftChange} onChange={this.handleLeftChange}
fields={fields} fields={fields}
defaultType="field" allowedTypes={
allowedTypes={(config.valueTypes || ['field', 'func']).filter( ['field', 'func'].filter(
type => type === 'field' || type === 'func' type => type === 'field' || type === 'func'
)} ) as any
}
/> />
); );
} }
@ -251,7 +252,6 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
value={(value.right as Array<ExpressionComplex>)?.[0]} value={(value.right as Array<ExpressionComplex>)?.[0]}
onChange={this.handleRightSubChange.bind(this, 0)} onChange={this.handleRightSubChange.bind(this, 0)}
fields={fields} fields={fields}
defaultType="value"
allowedTypes={ allowedTypes={
field?.valueTypes || field?.valueTypes ||
config.valueTypes || ['value', 'field', 'func', 'formula'] config.valueTypes || ['value', 'field', 'func', 'formula']
@ -267,7 +267,6 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
value={(value.right as Array<ExpressionComplex>)?.[1]} value={(value.right as Array<ExpressionComplex>)?.[1]}
onChange={this.handleRightSubChange.bind(this, 1)} onChange={this.handleRightSubChange.bind(this, 1)}
fields={fields} fields={fields}
defaultType="value"
allowedTypes={ allowedTypes={
field?.valueTypes || field?.valueTypes ||
config.valueTypes || ['value', 'field', 'func', 'formula'] config.valueTypes || ['value', 'field', 'func', 'formula']
@ -286,7 +285,6 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
value={value.right} value={value.right}
onChange={this.handleRightChange} onChange={this.handleRightChange}
fields={fields} fields={fields}
defaultType="value"
allowedTypes={ allowedTypes={
field?.valueTypes || field?.valueTypes ||
config.valueTypes || ['value', 'field', 'func', 'formula'] config.valueTypes || ['value', 'field', 'func', 'formula']