From ddcc7bfca547f94d4b51f202eb344a43caa28d40 Mon Sep 17 00:00:00 2001 From: zhangxulong Date: Mon, 12 Jun 2023 14:07:18 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=E7=A7=BB=E5=8A=A8=E7=AB=AF=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/src/components/UserSelect.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/amis-ui/src/components/UserSelect.tsx b/packages/amis-ui/src/components/UserSelect.tsx index 0792ede9a..77c4aeb94 100644 --- a/packages/amis-ui/src/components/UserSelect.tsx +++ b/packages/amis-ui/src/components/UserSelect.tsx @@ -439,6 +439,16 @@ export class UserSelect extends React.Component< options = [] } = this.props; const _selection = this.props.selection?.slice() || []; + if (Array.isArray(options?.[0]?.leftOptions)) { + eachTree(options?.[0].leftOptions, (item: Option) => { + const res = _selection.find( + (item2: Option) => item2[valueField] === item[valueField] + ); + if (res) { + res.label = item[labelField]; + } + }); + } eachTree(options, (item: Option) => { const res = _selection.find( From 83d847b90b9a4509cf820ccb25e188ef5237bf76 Mon Sep 17 00:00:00 2001 From: zhangxulong Date: Mon, 12 Jun 2023 15:42:54 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8=E7=AB=AF=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/src/components/UserSelect.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/amis-ui/src/components/UserSelect.tsx b/packages/amis-ui/src/components/UserSelect.tsx index 77c4aeb94..81256dbce 100644 --- a/packages/amis-ui/src/components/UserSelect.tsx +++ b/packages/amis-ui/src/components/UserSelect.tsx @@ -20,6 +20,7 @@ import Spinner, {SpinnerExtraProps} from './Spinner'; import flatten from 'lodash/flatten'; import {findDOMNode} from 'react-dom'; import {Api, PlainObject} from 'amis-core'; +import cloneDeep from 'lodash/cloneDeep'; export interface UserSelectProps extends ThemeProps, @@ -438,7 +439,7 @@ export class UserSelect extends React.Component< labelField = 'label', options = [] } = this.props; - const _selection = this.props.selection?.slice() || []; + const _selection = cloneDeep(this.props.selection) || []; if (Array.isArray(options?.[0]?.leftOptions)) { eachTree(options?.[0].leftOptions, (item: Option) => { const res = _selection.find( @@ -714,8 +715,6 @@ export class UserSelect extends React.Component< ) : null} - {} - {!option.isRef ? ( labelField === 'avatar' ? ( option[labelField] ? ( From 4f0642f120a9eea078a074ac1f75a0a081d6d6f2 Mon Sep 17 00:00:00 2001 From: zhangxulong Date: Mon, 12 Jun 2023 16:41:57 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8=E7=AB=AF=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-ui/src/components/UserSelect.tsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/amis-ui/src/components/UserSelect.tsx b/packages/amis-ui/src/components/UserSelect.tsx index 81256dbce..7a769a5fe 100644 --- a/packages/amis-ui/src/components/UserSelect.tsx +++ b/packages/amis-ui/src/components/UserSelect.tsx @@ -20,7 +20,6 @@ import Spinner, {SpinnerExtraProps} from './Spinner'; import flatten from 'lodash/flatten'; import {findDOMNode} from 'react-dom'; import {Api, PlainObject} from 'amis-core'; -import cloneDeep from 'lodash/cloneDeep'; export interface UserSelectProps extends ThemeProps, @@ -439,24 +438,30 @@ export class UserSelect extends React.Component< labelField = 'label', options = [] } = this.props; - const _selection = cloneDeep(this.props.selection) || []; + const _selection = this.props.selection?.concat() || []; if (Array.isArray(options?.[0]?.leftOptions)) { eachTree(options?.[0].leftOptions, (item: Option) => { - const res = _selection.find( + const index = _selection.findIndex( (item2: Option) => item2[valueField] === item[valueField] ); - if (res) { - res.label = item[labelField]; + if (!!~index) { + _selection.splice(index, 1, { + ..._selection[index], + label: item[labelField] + }); } }); } eachTree(options, (item: Option) => { - const res = _selection.find( + const index = _selection.findIndex( (item2: Option) => item2[valueField] === item[valueField] ); - if (res) { - res.label = item[labelField]; + if (!!~index) { + _selection.splice(index, 1, { + ..._selection[index], + label: item[labelField] + }); } }); return _selection; From 70626bd0f46c997025e3858af34ff9543b310527 Mon Sep 17 00:00:00 2001 From: ls <1769057083@qq.com> Date: Mon, 12 Jun 2023 16:43:33 +0800 Subject: [PATCH 4/4] Update UserSelect.tsx --- packages/amis-ui/src/components/UserSelect.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amis-ui/src/components/UserSelect.tsx b/packages/amis-ui/src/components/UserSelect.tsx index 7a769a5fe..20c07ebe7 100644 --- a/packages/amis-ui/src/components/UserSelect.tsx +++ b/packages/amis-ui/src/components/UserSelect.tsx @@ -440,7 +440,7 @@ export class UserSelect extends React.Component< } = this.props; const _selection = this.props.selection?.concat() || []; if (Array.isArray(options?.[0]?.leftOptions)) { - eachTree(options?.[0].leftOptions, (item: Option) => { + eachTree(options[0].leftOptions, (item: Option) => { const index = _selection.findIndex( (item2: Option) => item2[valueField] === item[valueField] );