mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +08:00
Combo 条件没命中显式数据错误
This commit is contained in:
parent
c75d89cf7a
commit
8d92802de8
@ -5,13 +5,22 @@ import {Schema, Action, Api} from '../../types';
|
||||
import {ComboStore, IComboStore} from '../../store/combo';
|
||||
import {default as CTabs, Tab} from '../../components/Tabs';
|
||||
|
||||
import {guid, anyChanged, isObject, createObject, extendObject, autobind} from '../../utils/helper';
|
||||
import {
|
||||
guid,
|
||||
anyChanged,
|
||||
isObject,
|
||||
createObject,
|
||||
extendObject,
|
||||
autobind,
|
||||
isObjectShallowModified
|
||||
} from '../../utils/helper';
|
||||
import Sortable = require('sortablejs');
|
||||
import {evalExpression, filter} from '../../utils/tpl';
|
||||
import find = require('lodash/find');
|
||||
import Select from '../../components/Select';
|
||||
import {dataMapping} from '../../utils/tpl-builtin';
|
||||
import {isEffectiveApi} from '../../utils/api';
|
||||
import {Alert2} from '../../components';
|
||||
|
||||
export interface Condition {
|
||||
test: string;
|
||||
@ -291,6 +300,11 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
}
|
||||
|
||||
let value = this.getValueAsArray();
|
||||
const newValue = flat ? values.flat : {...values};
|
||||
|
||||
if (!isObjectShallowModified(value[index], newValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
value[index] = flat ? values.flat : {...values};
|
||||
|
||||
@ -415,9 +429,9 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
return createObject(extendObject(data, {index, __index: index, ...data}), value);
|
||||
}
|
||||
|
||||
pickCondition(value: any): Condition {
|
||||
const conditions: Array<Condition> = this.props.conditions as Array<Condition>;
|
||||
return (find(conditions, item => item.test && evalExpression(item.test, value)) || conditions[0]) as Condition;
|
||||
pickCondition(value: any): Condition | null {
|
||||
const conditions: Array<Condition> = this.props.conditions!;
|
||||
return find(conditions, item => item.test && evalExpression(item.test, value)) as Condition | null;
|
||||
}
|
||||
|
||||
handleComboTypeChange(index: number, selection: any) {
|
||||
@ -541,22 +555,7 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
>
|
||||
{value.map((value, index) => {
|
||||
const data = this.formatValue(value, index);
|
||||
let condition: Condition | null = null;
|
||||
|
||||
if (Array.isArray(conditions) && conditions.length) {
|
||||
condition = this.pickCondition(data);
|
||||
controls = condition.controls;
|
||||
}
|
||||
|
||||
let finnalControls = flat
|
||||
? [
|
||||
{
|
||||
...(controls && controls[0]),
|
||||
name: 'flat'
|
||||
}
|
||||
]
|
||||
: controls;
|
||||
|
||||
let condition: Condition | null | undefined = null;
|
||||
let toolbar = undefined;
|
||||
if (
|
||||
finnalRemovable && // 表达式判断单条是否可删除
|
||||
@ -575,6 +574,21 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
);
|
||||
}
|
||||
|
||||
if (Array.isArray(conditions) && conditions.length) {
|
||||
condition = this.pickCondition(data);
|
||||
controls = condition ? condition.controls : undefined;
|
||||
}
|
||||
|
||||
let finnalControls =
|
||||
flat && controls
|
||||
? [
|
||||
{
|
||||
...(controls && controls[0]),
|
||||
name: 'flat'
|
||||
}
|
||||
]
|
||||
: controls;
|
||||
|
||||
return (
|
||||
<Tab
|
||||
title={filter(tabsLabelTpl || '成员${index|plus}', data)}
|
||||
@ -598,7 +612,8 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
</div>
|
||||
) : null}
|
||||
<div className={cx(`Combo-itemInner`)}>
|
||||
{render(
|
||||
{finnalControls ? (
|
||||
render(
|
||||
`multiple/${index}`,
|
||||
{
|
||||
type: 'form',
|
||||
@ -618,6 +633,11 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
ref: (ref: any) => this.formRef(ref, index),
|
||||
canAccessSuperData
|
||||
}
|
||||
)
|
||||
) : (
|
||||
<Alert2 level="warning" className="m-b-none">
|
||||
数据非法,或者数据已失效,请移除
|
||||
</Alert2>
|
||||
)}
|
||||
</div>
|
||||
</Tab>
|
||||
@ -719,10 +739,11 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
|
||||
if (Array.isArray(conditions) && conditions.length) {
|
||||
condition = this.pickCondition(data);
|
||||
controls = condition.controls;
|
||||
controls = condition ? condition.controls : undefined;
|
||||
}
|
||||
|
||||
let finnalControls = flat
|
||||
let finnalControls =
|
||||
flat && controls
|
||||
? [
|
||||
{
|
||||
...(controls && controls[0]),
|
||||
@ -750,7 +771,8 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
</div>
|
||||
) : null}
|
||||
<div className={cx(`Combo-itemInner`)}>
|
||||
{render(
|
||||
{finnalControls ? (
|
||||
render(
|
||||
`multiple/${index}`,
|
||||
{
|
||||
type: 'form',
|
||||
@ -770,6 +792,11 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
ref: (ref: any) => this.formRef(ref, index),
|
||||
canAccessSuperData
|
||||
}
|
||||
)
|
||||
) : (
|
||||
<Alert2 level="warning" className="m-b-none">
|
||||
数据非法,或者数据已失效,请移除
|
||||
</Alert2>
|
||||
)}
|
||||
</div>
|
||||
{toolbar.length ? <div className={cx(`Combo-itemToolbar`)}>{toolbar}</div> : null}
|
||||
@ -845,7 +872,7 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
|
||||
if (Array.isArray(conditions) && conditions.length) {
|
||||
condition = this.pickCondition(data);
|
||||
controls = condition.controls;
|
||||
controls = condition ? condition.controls : undefined;
|
||||
}
|
||||
|
||||
return (
|
||||
@ -872,7 +899,8 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
) : null}
|
||||
|
||||
<div className={cx(`Combo-itemInner`)}>
|
||||
{render(
|
||||
{controls ? (
|
||||
render(
|
||||
'single',
|
||||
{
|
||||
type: 'form',
|
||||
@ -890,6 +918,11 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
onInit: this.handleSingleFormInit,
|
||||
canAccessSuperData
|
||||
}
|
||||
)
|
||||
) : (
|
||||
<Alert2 level="warning" className="m-b-none">
|
||||
数据非法,或者数据已失效,请移除
|
||||
</Alert2>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -245,7 +245,7 @@ export function isObjectShallowModified(
|
||||
strictMode: boolean = true,
|
||||
ignoreUndefined: boolean = false
|
||||
) {
|
||||
if (null == prev || null == next || typeof prev !== 'object' || typeof next !== 'object') {
|
||||
if (null == prev || null == next || !isObject(prev) || !isObject(next)) {
|
||||
return strictMode ? prev !== next : prev != next;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user