mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +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) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
onChange(resetValue ?? '');
|
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() {
|
loadMore() {
|
||||||
const {
|
const {
|
||||||
value,
|
value,
|
||||||
@ -157,10 +171,12 @@ export default class ChainedSelectControl extends React.Component<
|
|||||||
arr.splice(idx + 1, value.length - idx - 1);
|
arr.splice(idx + 1, value.length - idx - 1);
|
||||||
arr.push(remoteValue);
|
arr.push(remoteValue);
|
||||||
|
|
||||||
|
const valueRes = this.array2value(arr, true);
|
||||||
|
|
||||||
const rendererEvent = await dispatchEvent(
|
const rendererEvent = await dispatchEvent(
|
||||||
'change',
|
'change',
|
||||||
createObject(data, {
|
createObject(data, {
|
||||||
value: joinValues ? arr.join(delimiter || ',') : arr
|
value: valueRes
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -168,7 +184,7 @@ export default class ChainedSelectControl extends React.Component<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange(joinValues ? arr.join(delimiter || ',') : arr);
|
onChange(valueRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push({
|
stack.push({
|
||||||
@ -203,11 +219,7 @@ export default class ChainedSelectControl extends React.Component<
|
|||||||
arr.splice(index, arr.length - index);
|
arr.splice(index, arr.length - index);
|
||||||
arr.push(joinValues ? currentValue.value : currentValue);
|
arr.push(joinValues ? currentValue.value : currentValue);
|
||||||
|
|
||||||
const valueRes = joinValues
|
const valueRes = this.array2value(arr);
|
||||||
? arr.join(delimiter || ',')
|
|
||||||
: extractValue
|
|
||||||
? arr.map(item => item.value || item)
|
|
||||||
: arr;
|
|
||||||
|
|
||||||
const rendererEvent = await dispatchEvent(
|
const rendererEvent = await dispatchEvent(
|
||||||
'change',
|
'change',
|
||||||
|
@ -55,8 +55,10 @@ export default class CheckboxControl extends React.Component<
|
|||||||
|
|
||||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
onChange(resetValue ?? false);
|
|
||||||
|
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) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
onChange(resetValue ?? '');
|
onChange(resetValue ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,9 @@ export default class MatrixCheckbox extends React.Component<
|
|||||||
|
|
||||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
onChange(resetValue ?? '');
|
onChange(resetValue ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,9 @@ export default class NestedSelectControl extends React.Component<
|
|||||||
|
|
||||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
onChange(resetValue ?? '');
|
onChange(resetValue ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -469,7 +469,9 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||||||
|
|
||||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
onChange(resetValue ?? '');
|
onChange(resetValue ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,9 @@ export default class RadiosControl extends React.Component<RadiosProps, any> {
|
|||||||
|
|
||||||
doAction(action: Action, data: object, throwErrors: boolean) {
|
doAction(action: Action, data: object, throwErrors: boolean) {
|
||||||
const {resetValue, onChange} = this.props;
|
const {resetValue, onChange} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
onChange(resetValue ?? '');
|
onChange(resetValue ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,8 +336,10 @@ export default class SelectControl extends React.Component<SelectProps, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doAction(action: Action, data: object, throwErrors: boolean): any {
|
doAction(action: Action, data: object, throwErrors: boolean): any {
|
||||||
const {simpleValue, resetValue} = this.props;
|
const {resetValue} = this.props;
|
||||||
if (action.actionType === 'clear') {
|
const actionType = action?.actionType as string;
|
||||||
|
|
||||||
|
if (!!~['clear', 'reset'].indexOf(actionType)) {
|
||||||
this.changeValue(resetValue ?? '');
|
this.changeValue(resetValue ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user