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

View File

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

View File

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