mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-04 04:48:32 +08:00
下拉选择类组件doAction修改&链式下拉框抽离逻辑
This commit is contained in:
parent
d0e9c3af70
commit
41cb86a187
@ -84,11 +84,25 @@ export default class ChainedSelectControl extends React.Component<
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
array2value(arr: Array<any>, isExtracted: boolean = false) {
|
||||
const {delimiter, joinValues, extractValue} = this.props;
|
||||
// 判断arr的项是否已抽取
|
||||
return isExtracted
|
||||
? (joinValues ? arr.join(delimiter || ',') : arr)
|
||||
: (joinValues
|
||||
? arr.join(delimiter || ',')
|
||||
: extractValue
|
||||
? arr.map(item => item.value || item)
|
||||
: arr)
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
const {
|
||||
value,
|
||||
@ -157,10 +171,12 @@ export default class ChainedSelectControl extends React.Component<
|
||||
arr.splice(idx + 1, value.length - idx - 1);
|
||||
arr.push(remoteValue);
|
||||
|
||||
const valueRes = this.array2value(arr, true);
|
||||
|
||||
const rendererEvent = await dispatchEvent(
|
||||
'change',
|
||||
createObject(data, {
|
||||
value: joinValues ? arr.join(delimiter || ',') : arr
|
||||
value: valueRes
|
||||
})
|
||||
);
|
||||
|
||||
@ -168,7 +184,7 @@ export default class ChainedSelectControl extends React.Component<
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(joinValues ? arr.join(delimiter || ',') : arr);
|
||||
onChange(valueRes);
|
||||
}
|
||||
|
||||
stack.push({
|
||||
@ -203,11 +219,7 @@ export default class ChainedSelectControl extends React.Component<
|
||||
arr.splice(index, arr.length - index);
|
||||
arr.push(joinValues ? currentValue.value : currentValue);
|
||||
|
||||
const valueRes = joinValues
|
||||
? arr.join(delimiter || ',')
|
||||
: extractValue
|
||||
? arr.map(item => item.value || item)
|
||||
: arr;
|
||||
const valueRes = this.array2value(arr);
|
||||
|
||||
const rendererEvent = await dispatchEvent(
|
||||
'change',
|
||||
|
@ -55,8 +55,10 @@ export default class CheckboxControl extends React.Component<
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
onChange(resetValue ?? false);
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,9 @@ export default class TagControl extends React.PureComponent<
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,9 @@ export default class MatrixCheckbox extends React.Component<
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,9 @@ export default class NestedSelectControl extends React.Component<
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -469,7 +469,9 @@ export function registerOptionsControl(config: OptionsConfig) {
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,9 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||
const {resetValue, onChange} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -336,8 +336,10 @@ export default class SelectControl extends React.Component<SelectProps, any> {
|
||||
}
|
||||
|
||||
doAction(action: Action, data: object, throwErrors: boolean): any {
|
||||
const {simpleValue, resetValue} = this.props;
|
||||
if (action.actionType === 'clear') {
|
||||
const {resetValue} = this.props;
|
||||
const actionType = action?.actionType as string;
|
||||
|
||||
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||
this.changeValue(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user