From 41cb86a187962af1291e5748f475f6d4f29bf0ee Mon Sep 17 00:00:00 2001 From: xujiahao01 Date: Wed, 23 Feb 2022 13:17:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E6=8B=89=E9=80=89=E6=8B=A9=E7=B1=BB?= =?UTF-8?q?=E7=BB=84=E4=BB=B6doAction=E4=BF=AE=E6=94=B9&=E9=93=BE=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E6=A1=86=E6=8A=BD=E7=A6=BB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/ChainedSelect.tsx | 28 ++++++++++++++++++------- src/renderers/Form/Checkbox.tsx | 6 ++++-- src/renderers/Form/InputTag.tsx | 4 +++- src/renderers/Form/MatrixCheckboxes.tsx | 4 +++- src/renderers/Form/NestedSelect.tsx | 4 +++- src/renderers/Form/Options.tsx | 4 +++- src/renderers/Form/Radios.tsx | 4 +++- src/renderers/Form/Select.tsx | 6 ++++-- 8 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/renderers/Form/ChainedSelect.tsx b/src/renderers/Form/ChainedSelect.tsx index 2b9e7ea7d..530cde8da 100644 --- a/src/renderers/Form/ChainedSelect.tsx +++ b/src/renderers/Form/ChainedSelect.tsx @@ -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, 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', diff --git a/src/renderers/Form/Checkbox.tsx b/src/renderers/Form/Checkbox.tsx index dac23b34b..16a76e5f4 100644 --- a/src/renderers/Form/Checkbox.tsx +++ b/src/renderers/Form/Checkbox.tsx @@ -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 ?? ''); } } diff --git a/src/renderers/Form/InputTag.tsx b/src/renderers/Form/InputTag.tsx index 6bc93aec5..b9ad75a96 100644 --- a/src/renderers/Form/InputTag.tsx +++ b/src/renderers/Form/InputTag.tsx @@ -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 ?? ''); } } diff --git a/src/renderers/Form/MatrixCheckboxes.tsx b/src/renderers/Form/MatrixCheckboxes.tsx index a7c3bba10..9e0a36ebb 100644 --- a/src/renderers/Form/MatrixCheckboxes.tsx +++ b/src/renderers/Form/MatrixCheckboxes.tsx @@ -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 ?? ''); } } diff --git a/src/renderers/Form/NestedSelect.tsx b/src/renderers/Form/NestedSelect.tsx index a4246ebfb..59d450db0 100644 --- a/src/renderers/Form/NestedSelect.tsx +++ b/src/renderers/Form/NestedSelect.tsx @@ -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 ?? ''); } } diff --git a/src/renderers/Form/Options.tsx b/src/renderers/Form/Options.tsx index 7bd081286..b2666d54a 100644 --- a/src/renderers/Form/Options.tsx +++ b/src/renderers/Form/Options.tsx @@ -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 ?? ''); } } diff --git a/src/renderers/Form/Radios.tsx b/src/renderers/Form/Radios.tsx index f964973b4..1a383c25c 100644 --- a/src/renderers/Form/Radios.tsx +++ b/src/renderers/Form/Radios.tsx @@ -39,7 +39,9 @@ export default class RadiosControl 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 ?? ''); } } diff --git a/src/renderers/Form/Select.tsx b/src/renderers/Form/Select.tsx index 2648120ef..050995412 100644 --- a/src/renderers/Form/Select.tsx +++ b/src/renderers/Form/Select.tsx @@ -336,8 +336,10 @@ export default class SelectControl extends React.Component { } 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 ?? ''); } }