传参的时候,
如果拼接的url,
URL 中+号表示空格 %2B
空格 URL中的空格可以用+号或者编码 %20
/ 分隔目录和子目录 %2F
? 分隔实际的URL和参数 %3F
% 指定特殊字符 %25
表示书签 %23
& URL 中指定的参数间的分隔符 %26
= URL 中指定参数的值 %3D
两个解决办法
第一就是js方法里的encodeURIComponent()
第二就是改掉拼接放在params里传值
// 根据查询条件查询书
export function getBookList(params?: TableListParams): Promise<RequestData<TableListItem>> {
const bookname = params && params.bookname ? params.bookname : '';
const ArrTemp=R.join('+',R.split('+', bookname))
delete (params as any).filter;
const created_at = params && params.created_at ? params.created_at.join('|') : '';
const discount = (params && params.discount !== '0|0') ? params.discount : "";
const filter = handleGetfilters({ ...R.dissoc('bookname', R.clone(params)), created_at, discount });
console.log(filter)
// ["?bookname:string","?author:string","?isbn:string","?status:int","?created_at:string","?offset:int","?limit:int"])
return new Promise((resolve, reject) => {
request(
`/admin/book/query_book?${filter}&bookname=${encodeURIComponent(ArrTemp)}&offset=${params?.current}&limit=${params?.pageSize}`,
{
method: 'GET',
},
)
.then((data) => {
const responseData = {
data: data.book_list,
success: true,
total: data.total,
};
resolve(responseData);
})
.catch((err) => {
reject({
success: false,
});
});
});
}
export function getBookList(params?: TableListParams): Promise<RequestData<TableListItem>> {
delete (params as any).filter;
params!.created_at = params && params.created_at ? params.created_at.join('|') : '' as any;
params!.discount = (params && params.discount !== '0|0') ? params.discount : "";
return new Promise((resolve, reject) => {
request
.get(API.getBookList, {
params: sortTableParams(params),
})
.then((data) => {
const responseData = {
data: data.book_list,
success: true,
total: data.total,
};
resolve(responseData);
})
.catch((err:any) => {
reject(new Error(err));
});
});
}
网友评论