@@ -6,6 +6,8 @@ import ProForm, {
66 ProFormText ,
77 ProFormDatePicker ,
88 ProFormDateRangePicker ,
9+ ProFormDateTimePicker ,
10+ ProFormDateTimeRangePicker ,
911 ProFormSelect
1012} from '@ant-design/pro-form' ;
1113
@@ -17,6 +19,7 @@ export interface Action {
1719const QueryFilter : React . FC < Action > = ( props ) => {
1820 const onFinish = ( values : any ) => {
1921 let query = { } ;
22+
2023 query [ 'api' ] = history . location . query . api ;
2124 query [ 'page' ] = history . location . query . page ;
2225 query [ 'pageSize' ] = history . location . query . pageSize ;
@@ -30,6 +33,34 @@ const QueryFilter: React.FC<Action> = (props) => {
3033 query [ 'filter' ] = history . location . query . filter ;
3134 }
3235
36+ // hack random
37+ query [ 'random' ] = Math . random ( ) ;
38+
39+ history . push ( { pathname : history . location . pathname , query : query } ) ;
40+
41+ if ( props . current ) {
42+ props . current . reload ( ) ;
43+ }
44+ } ;
45+
46+ const onReset = ( ) => {
47+ let query = { } ;
48+
49+ query [ 'api' ] = history . location . query . api ;
50+ query [ 'page' ] = history . location . query . page ;
51+ query [ 'pageSize' ] = history . location . query . pageSize ;
52+
53+ if ( history . location . query . sorter ) {
54+ query [ 'sorter' ] = history . location . query . sorter ;
55+ }
56+
57+ if ( history . location . query . filter ) {
58+ query [ 'filter' ] = history . location . query . filter ;
59+ }
60+
61+ // hack random
62+ query [ 'random' ] = Math . random ( ) ;
63+
3364 history . push ( { pathname : history . location . pathname , query : query } ) ;
3465
3566 if ( props . current ) {
@@ -38,10 +69,11 @@ const QueryFilter: React.FC<Action> = (props) => {
3869 } ;
3970
4071 const searchComponent = ( item :any ) => {
72+ let component = null ;
4173 switch ( item . component ) {
4274 case 'input' :
4375 if ( item . operator == 'between' ) {
44- return (
76+ component =
4577 < ProForm . Group title = { item . label } >
4678 < ProFormText
4779 key = { item . name + '_start' }
@@ -56,98 +88,113 @@ const QueryFilter: React.FC<Action> = (props) => {
5688 style = { item . style ? item . style : [ ] }
5789 />
5890 </ ProForm . Group >
59- )
6091 } else {
61- return (
62- < ProFormText
63- key = { item . name }
64- name = { item . name }
65- label = { item . label }
66- placeholder = { item . placeholder }
67- style = { item . style ? item . style : [ ] }
68- />
69- )
92+ component =
93+ < ProFormText
94+ key = { item . name }
95+ name = { item . name }
96+ label = { item . label }
97+ placeholder = { item . placeholder }
98+ style = { item . style ? item . style : [ ] }
99+ />
70100 }
71101
72102 break ;
73103 case 'select' :
74- return (
75- < ProFormSelect
104+ component =
105+ < ProFormSelect
106+ key = { item . name }
107+ label = { item . label }
108+ name = { item . name }
109+ options = { item . options }
110+ style = { item . style ? item . style : [ ] }
111+ placeholder = { item . placeholder }
112+ />
113+ break ;
114+ case 'multipleSelect' :
115+ component =
116+ < ProFormSelect
117+ mode = "multiple"
118+ key = { item . name }
119+ label = { item . label }
120+ name = { item . name }
121+ options = { item . options }
122+ style = { item . style ? item . style : [ ] }
123+ placeholder = { item . placeholder }
124+ />
125+ break ;
126+
127+ case 'datetime' :
128+ if ( item . operator == 'between' ) {
129+ component =
130+ < ProFormDateTimeRangePicker
76131 key = { item . name }
77132 label = { item . label }
78133 name = { item . name }
79- options = { item . options }
80134 style = { item . style ? item . style : [ ] }
81- placeholder = { item . placeholder }
82135 />
83- )
84-
85- break ;
86- case 'multipleSelect' :
87- return (
88- < ProFormSelect
89- mode = "multiple"
136+ } else {
137+ component =
138+ < ProFormDateTimePicker
90139 key = { item . name }
91- label = { item . label }
92140 name = { item . name }
93- options = { item . options }
94- style = { item . style ? item . style : [ ] }
141+ label = { item . label }
95142 placeholder = { item . placeholder }
143+ style = { item . style ? item . style : [ ] }
96144 />
97- )
98-
145+ }
99146 break ;
100147
101- case 'datetime ' :
148+ case 'date ' :
102149 if ( item . operator == 'between' ) {
103- return (
104- < ProFormDateRangePicker
105- key = { item . name }
106- label = { item . label }
107- name = { item . name }
108- style = { item . style ? item . style : [ ] }
109- />
110- )
150+ component =
151+ < ProFormDateRangePicker
152+ key = { item . name }
153+ label = { item . label }
154+ name = { item . name }
155+ style = { item . style ? item . style : [ ] }
156+ />
111157 } else {
112- return (
113- < ProFormDatePicker
114- key = { item . name }
115- name = { item . name }
116- label = { item . label }
117- placeholder = { item . placeholder }
118- style = { item . style ? item . style : [ ] }
119- />
120- )
158+ component =
159+ < ProFormDatePicker
160+ key = { item . name }
161+ name = { item . name }
162+ label = { item . label }
163+ placeholder = { item . placeholder }
164+ style = { item . style ? item . style : [ ] }
165+ />
121166 }
122167 break ;
123168
124169 case 'inputGroup' :
125- return (
126- < ProForm . Group title = { item . label } >
127- < ProFormSelect
128- key = { item . name + '_start' }
129- name = { item . name + '_start' }
130- options = { item . options }
131- style = { { width : ( item . style . width [ 0 ] ? item . style . width [ 0 ] : null ) } }
132- />
133- < ProFormText
134- key = { item . name + '_end' }
135- name = { item . name + '_end' }
136- style = { { width : ( item . style . width [ 1 ] ? item . style . width [ 1 ] : null ) } }
137- placeholder = { item . placeholder }
138- />
139- </ ProForm . Group >
140- )
170+ component =
171+ < ProForm . Group title = { item . label } >
172+ < ProFormSelect
173+ key = { item . name + '_start' }
174+ name = { item . name + '_start' }
175+ options = { item . options }
176+ style = { { width : ( item . style . width [ 0 ] ? item . style . width [ 0 ] : null ) } }
177+ />
178+ < ProFormText
179+ key = { item . name + '_end' }
180+ name = { item . name + '_end' }
181+ style = { { width : ( item . style . width [ 1 ] ? item . style . width [ 1 ] : null ) } }
182+ placeholder = { item . placeholder }
183+ />
184+ </ ProForm . Group >
141185 break ;
142186
143187 default :
144- return null ;
188+ component = null ;
145189 }
190+
191+ return component ;
146192 } ;
147193
148194 return (
149195 < ProQueryFilter
150- onFinish = { onFinish }
196+ onFinish = { async ( values ) => { onFinish ( values ) } }
197+ onReset = { async ( ) => { onReset ( ) } }
151198 labelAlign = { props . search . labelAlign }
152199 size = { props . search . size }
153200 defaultCollapsed = { props . search . defaultCollapsed }
0 commit comments