@@ -143,11 +143,66 @@ export class JigsawPagination extends AbstractJigsawComponent implements OnInit,
143143 @Input ( ) public mode : 'complex' | 'simple' = 'complex' ; // 当为「small」时,是小尺寸分页
144144 @Input ( ) public placeholder : string = '' ;
145145
146+ /**
147+ * 设置了此属性会给搜索增加一个防抖功能,并增加enter回车立刻搜索
148+ * 设为'none'、NaN、小于0,或者不设置则表示不设置防抖
149+ */
150+ @Input ( )
151+ public searchDebounce : number | 'none' = NaN ;
152+
146153 @ViewChildren ( forwardRef ( ( ) => JigsawPagingItem ) )
147154 private _pages : QueryList < JigsawPagingItem > = null ;
148155
149156 @ViewChildren ( JigsawInput ) inputs : QueryList < JigsawInput > ;
150157
158+ /**
159+ * @internal
160+ */
161+ public _$searchKeyChange ( $event ) {
162+ if ( this . _isValidSearchDebounce ( ) ) {
163+ this . _debounceSearch ( $event ) ;
164+ } else {
165+ this . search . emit ( $event )
166+ }
167+ }
168+
169+ private _isValidSearchDebounce ( ) {
170+ return this . searchDebounce && this . searchDebounce != 'none' && ! isNaN ( this . searchDebounce ) && Number ( this . searchDebounce ) > 0
171+ }
172+
173+ /**
174+ * @internal
175+ */
176+ public _$searchKey : string ;
177+
178+ /**
179+ * @internal
180+ */
181+ public _$enterSearch ( $event ) {
182+ $event . preventDefault ( ) ;
183+ $event . stopPropagation ( ) ;
184+ if ( this . _isValidSearchDebounce ( ) ) {
185+ this . _clearSearchTimer ( ) ;
186+ this . search . emit ( this . _$searchKey ) ;
187+ }
188+ }
189+
190+ private _searchTimer : number ;
191+
192+ private _debounceSearch ( key : string ) {
193+ this . _clearSearchTimer ( ) ;
194+ this . _searchTimer = this . callLater ( ( ) => {
195+ this . search . emit ( key ) ;
196+ } , this . searchDebounce )
197+ }
198+
199+ private _clearSearchTimer ( ) {
200+ if ( this . _searchTimer ) {
201+ clearTimeout ( this . _searchTimer ) ;
202+ this . _searchTimer = null ;
203+ }
204+ }
205+
151206 /*
152207 * 根据current设置page按钮的显示,上一页,下一页,上五页,下五页的显示
153208 * */
0 commit comments