fix: serialize params with qs

This commit is contained in:
chenos 2022-02-25 23:41:33 +08:00
parent bcc42a9455
commit f06a4497f0
3 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import { observable } from '@formily/reactive';
import { Result } from 'ahooks/lib/useRequest/src/types';
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import qs from 'qs';
export interface ActionParams {
filterByTk?: any;
@ -37,9 +38,22 @@ export class APIClient {
} else {
this.axios = axios.create(instance);
}
this.qsMiddleware();
this.authMiddleware();
}
qsMiddleware() {
this.axios.interceptors.request.use((config) => {
config.paramsSerializer = (params) => {
return qs.stringify(params, {
strictNullHandling: true,
arrayFormat: 'brackets',
});
};
return config;
});
}
authMiddleware() {
this.axios.interceptors.request.use((config) => {
const token = localStorage.getItem(this.tokenKey);

View File

@ -79,11 +79,7 @@ export const useBulkDestroyAction = () => {
return {
async run() {
await resource.destroy({
filter: {
[targetKey]: {
$in: state?.selectedRowKeys || [],
},
},
filterByTk: state?.selectedRowKeys || [],
});
setState?.({ selectedRowKeys: [] });
refresh();

View File

@ -198,7 +198,7 @@ export function parseQuery(input: string): any {
// 原始 query string 中如果一个键连等号“=”都没有可以被认为是 null 类型
strictNullHandling: true,
// 逗号分隔转换为数组
comma: true,
// comma: true,
});
// filter 支持 json string
if (typeof query.filter === 'string') {