mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:39:05 +08:00
优化条件组合
Change-Id: Ib0dcc208ffbc50a631f657e2faa8df246dc2dd56
This commit is contained in:
parent
f39847315f
commit
2f2d1399d6
@ -279,7 +279,7 @@
|
||||
display: block;
|
||||
font-size: $fontSizeSm;
|
||||
align-self: center;
|
||||
margin: -5px 0 -5px -8px;
|
||||
margin: -5px 5px -5px -8px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
user-select: none;
|
||||
|
@ -36,7 +36,6 @@ export interface ExpressionProps extends ThemeProps {
|
||||
valueField?: FieldSimple;
|
||||
fields?: Field[];
|
||||
funcs?: Funcs;
|
||||
defaultType?: 'value' | 'field' | 'func' | 'formula';
|
||||
allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>;
|
||||
op?: OperatorType;
|
||||
config: Config;
|
||||
@ -120,12 +119,12 @@ export class Expression extends React.Component<ExpressionProps> {
|
||||
const {
|
||||
value,
|
||||
valueField,
|
||||
defaultType,
|
||||
allowedTypes,
|
||||
funcs,
|
||||
fields,
|
||||
op,
|
||||
classnames: cx
|
||||
classnames: cx,
|
||||
config
|
||||
} = this.props;
|
||||
const inputType =
|
||||
((value as any)?.type === 'field'
|
||||
@ -137,7 +136,6 @@ export class Expression extends React.Component<ExpressionProps> {
|
||||
: value !== undefined
|
||||
? 'value'
|
||||
: undefined) ||
|
||||
defaultType ||
|
||||
allowedTypes?.[0] ||
|
||||
'value';
|
||||
|
||||
@ -177,11 +175,11 @@ export class Expression extends React.Component<ExpressionProps> {
|
||||
|
||||
{inputType === 'func' ? (
|
||||
<ConditionFunc
|
||||
config={config}
|
||||
value={value as ExpressionFunc}
|
||||
onChange={this.handleFuncChange}
|
||||
funcs={funcs}
|
||||
fields={fields}
|
||||
defaultType={defaultType}
|
||||
allowedTypes={allowedTypes}
|
||||
/>
|
||||
) : null}
|
||||
|
@ -14,10 +14,10 @@ export class Formula extends React.Component<FormulaProps> {
|
||||
return (
|
||||
<div className={cx('CBFormula')}>
|
||||
<InputBox
|
||||
value={(value as any).value}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
placeholder="请输入公式"
|
||||
prefix={<span className={cx('CBFormula-label')}>公式</span>}
|
||||
prefix={<span className={cx('CBFormula-label')}>表达式</span>}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@ -7,13 +7,14 @@ import {autobind, findTree, noop} from '../../utils/helper';
|
||||
import ResultBox from '../ResultBox';
|
||||
import {Icon} from '../icons';
|
||||
import Expression from './Expression';
|
||||
import {Config} from './config';
|
||||
|
||||
export interface ConditionFuncProps extends ThemeProps {
|
||||
value: ExpressionFunc;
|
||||
onChange: (value: ExpressionFunc) => void;
|
||||
config: Config;
|
||||
fields?: Field[];
|
||||
funcs?: Funcs;
|
||||
defaultType?: 'value' | 'field' | 'func' | 'formula';
|
||||
allowedTypes?: Array<'value' | 'field' | 'func' | 'formula'>;
|
||||
}
|
||||
|
||||
@ -36,14 +37,7 @@ export class ConditionFunc extends React.Component<ConditionFuncProps> {
|
||||
}
|
||||
|
||||
renderFunc(func: Func) {
|
||||
const {
|
||||
classnames: cx,
|
||||
fields,
|
||||
value,
|
||||
funcs,
|
||||
defaultType,
|
||||
allowedTypes
|
||||
} = this.props;
|
||||
const {classnames: cx, fields, value, funcs, config} = this.props;
|
||||
|
||||
return (
|
||||
<div className={cx('CBFunc-args')}>
|
||||
@ -52,6 +46,7 @@ export class ConditionFunc extends React.Component<ConditionFuncProps> {
|
||||
<div>
|
||||
{func.args.map((item, index) => (
|
||||
<Expression
|
||||
config={config}
|
||||
key={index}
|
||||
index={index}
|
||||
fields={fields}
|
||||
@ -59,7 +54,6 @@ export class ConditionFunc extends React.Component<ConditionFuncProps> {
|
||||
valueField={{type: item.type} as any}
|
||||
onChange={this.handleArgChange}
|
||||
funcs={funcs}
|
||||
defaultType={defaultType}
|
||||
// allowedTypes={allowedTypes}
|
||||
/>
|
||||
))}
|
||||
|
@ -104,10 +104,11 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
|
||||
value={value.left}
|
||||
onChange={this.handleLeftChange}
|
||||
fields={fields}
|
||||
defaultType="field"
|
||||
allowedTypes={(config.valueTypes || ['field', 'func']).filter(
|
||||
type => type === 'field' || type === 'func'
|
||||
)}
|
||||
allowedTypes={
|
||||
['field', 'func'].filter(
|
||||
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]}
|
||||
onChange={this.handleRightSubChange.bind(this, 0)}
|
||||
fields={fields}
|
||||
defaultType="value"
|
||||
allowedTypes={
|
||||
field?.valueTypes ||
|
||||
config.valueTypes || ['value', 'field', 'func', 'formula']
|
||||
@ -267,7 +267,6 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
|
||||
value={(value.right as Array<ExpressionComplex>)?.[1]}
|
||||
onChange={this.handleRightSubChange.bind(this, 1)}
|
||||
fields={fields}
|
||||
defaultType="value"
|
||||
allowedTypes={
|
||||
field?.valueTypes ||
|
||||
config.valueTypes || ['value', 'field', 'func', 'formula']
|
||||
@ -286,7 +285,6 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
|
||||
value={value.right}
|
||||
onChange={this.handleRightChange}
|
||||
fields={fields}
|
||||
defaultType="value"
|
||||
allowedTypes={
|
||||
field?.valueTypes ||
|
||||
config.valueTypes || ['value', 'field', 'func', 'formula']
|
||||
|
Loading…
Reference in New Issue
Block a user