@@ -3,11 +3,16 @@ import { useRequestParamsStore } from '@/stores/params'
33export const useRequestParamsChange = ( ) => {
44 const { params } = useRequestParamsStore ( )
55
6+ const onArrayChange = < Value extends number | string > ( array : Value [ ] , value : Value ) => {
7+ return array . includes ( value ) ? array . filter ( el => el !== value ) : [ ...array , value ]
8+ }
9+
610 const onTermChange = ( value : string ) => {
711 if ( value === '' ) {
812 params . term = ''
13+ } else {
14+ params . term = Number ( value )
915 }
10- params . term = Number ( value )
1116 }
1217 const onTitleChange = ( value : string ) => {
1318 params . title = value
@@ -16,27 +21,13 @@ export const useRequestParamsChange = () => {
1621 params . nickName = value
1722 }
1823 const onMainChange = ( value : number ) => {
19- if ( params . mainCategoryId . includes ( value ) ) {
20- params . mainCategoryId = [ ...params . mainCategoryId ] . filter ( el => el !== value )
21- } else {
22- params . mainCategoryId . push ( value )
23- }
24+ params . mainCategoryId = onArrayChange ( params . mainCategoryId , value )
2425 }
2526 const onSubChange = ( value : number ) => {
26- if ( params . categoryId . includes ( value ) ) {
27- params . categoryId = [ ...params . categoryId ] . filter ( el => el !== value )
28- } else {
29- params . categoryId . push ( value )
30- }
27+ params . categoryId = onArrayChange ( params . categoryId , value )
3128 }
3229 const onTaskStatusChange = ( value : string ) => {
33- if ( params . taskStatus ) {
34- if ( params . taskStatus . includes ( value ) ) {
35- params . taskStatus = [ ...params . taskStatus ] . filter ( el => el !== value )
36- } else {
37- params . taskStatus . push ( value )
38- }
39- }
30+ params . taskStatus = onArrayChange ( params . taskStatus ! , value )
4031 }
4132 const onPageSizeChange = ( value : string ) => {
4233 params . pageSize = Number ( value )
0 commit comments