@@ -44,15 +44,28 @@ export default function StandardTable(): JSX.Element | null {
4444 const async = useAsync ( ) ;
4545 const modelApi = useAPI ( '/device/model' ) ;
4646 const deviceApi = useAPI ( '/device' ) ;
47- const [ initDeviceQuery , saveDeviceQuery ] = useQueryParams < DeviceQueryParams > ( {
47+
48+ const [ deviceQuerySaved , setDeviceQuerySaved ] = useQueryParams < DeviceQueryParams > ( {
4849 keyword : '' ,
4950 sort : '-id' ,
5051 model : [ ] ,
5152 status : [ ] ,
5253 page : 1 ,
5354 pageSize : 10 ,
5455 } ) ;
55- const [ deviceQuery , setDeviceQuery ] = useImmer ( initDeviceQuery ) ;
56+ const [ deviceQuery , setDeviceQuery ] = useImmer ( deviceQuerySaved ) ;
57+ const queryEmptyStatus = ( ( ) => {
58+ const getEmptyStatus = ( query : DeviceQueryParams ) => ( {
59+ keyword : query . keyword . length === 0 ,
60+ model : query . model . length === 0 ,
61+ status : query . status . length === 0 ,
62+ } ) ;
63+ return {
64+ deviceQuerySaved : getEmptyStatus ( deviceQuerySaved ) ,
65+ deviceQuery : getEmptyStatus ( deviceQuery ) ,
66+ } ;
67+ } ) ( ) ;
68+
5669 const [ deviceTable , setDeviceTable ] = useImmer ( {
5770 loading : true ,
5871 list : [ ] as DeviceDoc [ ] ,
@@ -102,7 +115,7 @@ export default function StandardTable(): JSX.Element | null {
102115
103116 const [ updateDeviceTable , setUpdateDeviceTable ] = useState ( 0 ) ;
104117 useEffect ( ( ) => {
105- saveDeviceQuery ( deviceQuery ) ;
118+ setDeviceQuerySaved ( deviceQuery ) ;
106119
107120 const apiQuery : any = {
108121 page : deviceQuery . page ,
@@ -231,7 +244,7 @@ export default function StandardTable(): JSX.Element | null {
231244 } }
232245 />
233246 ) ,
234- isEmpty : deviceQuery . model . length === 0 ,
247+ isEmpty : queryEmptyStatus . deviceQuery . model ,
235248 } ,
236249 {
237250 label : 'Status' ,
@@ -249,7 +262,7 @@ export default function StandardTable(): JSX.Element | null {
249262 } }
250263 />
251264 ) ,
252- isEmpty : deviceQuery . status . length === 0 ,
265+ isEmpty : queryEmptyStatus . deviceQuery . status ,
253266 } ,
254267 ] }
255268 aLabelWidth = { 72 }
@@ -269,6 +282,10 @@ export default function StandardTable(): JSX.Element | null {
269282 draft . model = [ ] ;
270283 draft . status = [ ] ;
271284 } ) ;
285+
286+ if ( Object . values ( queryEmptyStatus . deviceQuerySaved ) . some ( ( isEmpty ) => ! isEmpty ) ) {
287+ setUpdateDeviceTable ( ( n ) => n + 1 ) ;
288+ }
272289 } }
273290 />
274291 < DTable style = { { overflow : 'auto hidden' } } >
0 commit comments