@@ -130,6 +130,14 @@ export class JigsawPagination extends AbstractJigsawComponent implements OnInit,
130130 @Input ( )
131131 public placeholder : string = '' ;
132132
133+ /**
134+ * 设置了此属性会给搜索增加一个防抖功能,并增加enter回车立刻搜索
135+ * 设为'none'、NaN、小于0,或者不设置则表示不设置防抖
136+ */
137+ @RequireMarkForCheck ( )
138+ @Input ( )
139+ public searchDebounce : number | 'none' = NaN ;
140+
133141 @Output ( )
134142 public search = new EventEmitter < string > ( ) ;
135143 /**
@@ -149,6 +157,55 @@ export class JigsawPagination extends AbstractJigsawComponent implements OnInit,
149157 @ViewChildren ( JigsawInput )
150158 public inputs : QueryList < JigsawInput > ;
151159
160+ /**
161+ * @internal
162+ */
163+ public _$searchKeyChange ( $event ) {
164+ if ( this . _isValidSearchDebounce ( ) ) {
165+ // 输入3000ms没有回车也会发一次事件
166+ this . _debounceSearch ( $event ) ;
167+ } else {
168+ this . search . emit ( $event )
169+ }
170+ }
171+
172+ private _isValidSearchDebounce ( ) {
173+ return this . searchDebounce && this . searchDebounce != 'none' && ! isNaN ( this . searchDebounce ) && Number ( this . searchDebounce ) > 0
174+ }
175+
176+ /**
177+ * @internal
178+ */
179+ public _$searchKey : string ;
180+
181+ /**
182+ * @internal
183+ */
184+ public _$enterSearch ( $event ) {
185+ $event . preventDefault ( ) ;
186+ $event . stopPropagation ( ) ;
187+ if ( this . _isValidSearchDebounce ( ) ) {
188+ this . _clearSearchTimer ( ) ;
189+ this . search . emit ( this . _$searchKey ) ;
190+ }
191+ }
192+
193+ private _searchTimer : number ;
194+
195+ private _debounceSearch ( key : string ) {
196+ this . _clearSearchTimer ( ) ;
197+ this . _searchTimer = this . callLater ( ( ) => {
198+ this . search . emit ( key ) ;
199+ } , this . searchDebounce )
200+ }
201+
202+ private _clearSearchTimer ( ) {
203+ if ( this . _searchTimer ) {
204+ clearTimeout ( this . _searchTimer ) ;
205+ this . _searchTimer = null ;
206+ }
207+ }
208+
152209 private _current : number ;
153210
154211 /**
0 commit comments