66 */
77
88import type { PanelRenderContext , Segment , SelectPanelData , SelectSearchField } from '../types'
9+ import type { ProSearchLocale } from '@idux/pro/locales'
910
1011import { isNil , toString } from 'lodash-es'
1112
@@ -19,6 +20,7 @@ const defaultSeparator = '|'
1920export function createSelectSegment (
2021 prefixCls : string ,
2122 config : SelectSearchField [ 'fieldConfig' ] ,
23+ locale : ProSearchLocale ,
2224) : Segment < VKey | VKey [ ] | undefined > {
2325 const { dataSource, separator, searchable, showSelectAll, searchFn, multiple, virtual, onSearch } = config
2426
@@ -64,27 +66,44 @@ export function createSelectSegment(
6466 name : 'select' ,
6567 inputClassName : [ `${ prefixCls } -select-segment-input` ] ,
6668 containerClassName : [ `${ prefixCls } -select-segment-container` ] ,
67- parse : input => parseInput ( input , config ) ,
68- format : value => formatValue ( value , config ) ,
69+ parse : input => parseInput ( input , config , locale . allSelected ) ,
70+ format : value => formatValue ( value , config , locale . allSelected ) ,
6971 panelRenderer,
7072 }
7173}
7274
73- function parseInput ( input : string , config : SelectSearchField [ 'fieldConfig' ] ) : VKey | VKey [ ] | undefined {
74- const { separator, dataSource, multiple } = config
75+ function parseInput (
76+ input : string ,
77+ config : SelectSearchField [ 'fieldConfig' ] ,
78+ allSelected : string ,
79+ ) : VKey | VKey [ ] | undefined {
80+ const { concludeAllSelected, separator, dataSource, multiple } = config
7581 const trimedInput = input . trim ( )
7682
77- const keys = getKeyByLabels ( dataSource , trimedInput . split ( separator ?? defaultSeparator ) )
83+ const keys =
84+ concludeAllSelected && trimedInput === allSelected
85+ ? dataSource . map ( data => data . key )
86+ : getKeyByLabels ( dataSource , trimedInput . split ( separator ?? defaultSeparator ) )
7887
7988 return multiple ? ( keys . length > 0 ? keys : undefined ) : keys [ 0 ]
8089}
8190
82- function formatValue ( value : VKey | VKey [ ] | undefined , config : SelectSearchField [ 'fieldConfig' ] ) : string {
83- const { dataSource, separator } = config
91+ function formatValue (
92+ value : VKey | VKey [ ] | undefined ,
93+ config : SelectSearchField [ 'fieldConfig' ] ,
94+ allSelected : string ,
95+ ) : string {
96+ const { concludeAllSelected, dataSource, separator } = config
8497 if ( isNil ( value ) ) {
8598 return ''
8699 }
87100
101+ const values = convertArray ( value )
102+
103+ if ( concludeAllSelected && values . length > 0 && values . length >= dataSource . length ) {
104+ return allSelected
105+ }
106+
88107 return getLabelByKeys ( dataSource , convertArray ( value ) ) . join ( ` ${ separator ?? defaultSeparator } ` )
89108}
90109
0 commit comments