最近在写一个搜索的接口的入参判断。
参数params固定值有currentPage,pageSize。如果参数中有a条件,那么提示用户“a条件不能与其他条件一并进行搜索”。如果没有a条件,其余条件可以组合性进行搜索
当前我写了一个方法,但觉得并不是太好。希望大家能多多指导一下,提出有更好更稳定的判断方法……
贴码:
`
import { page } from '@/common/constants';
const myFunc = (params) =>{
const { defaultCurrent=1,defaultPageSize=20 } = page
const {currentPage,pageSize} = params
const postData = {
currentPage:currentPage || defaultCurrent,
pageSize:pageSize || defaultPageSize,
...params
}
if(params && Object.getOwnPropertyNames(params).length>3 && params['a']){
message.info('请根据商品标签单独查询')
return
}
console.log('搜索成功!')
}
`
let params = {};
if(a){
params.a = a;
}else{
params = {b:b,c:c,d:d}
}
post(params)