fix: missing request params
This commit is contained in:
parent
11bbec7fd4
commit
31340f4773
@ -32,6 +32,7 @@ export class APIClient {
|
||||
|
||||
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D> | ResourceActionOptions): Promise<R> {
|
||||
const { resource, resourceOf, action, params } = config as any;
|
||||
console.log('config', config);
|
||||
if (resource) {
|
||||
return this.resource(resource, resourceOf)[action](params);
|
||||
}
|
||||
@ -51,8 +52,11 @@ export class APIClient {
|
||||
config['method'] = 'post';
|
||||
}
|
||||
return (params?: ActionParams) => {
|
||||
config[config.method === 'get' ? 'params' : 'data'] = { __params__: params };
|
||||
console.log({ config });
|
||||
const { values, ...others } = params || {};
|
||||
config['params'] = others;
|
||||
if (config.method !== 'get') {
|
||||
config['data'] = values || {};
|
||||
}
|
||||
return this.request(config);
|
||||
};
|
||||
},
|
||||
|
@ -21,16 +21,14 @@ export function useRequest<P>(
|
||||
if (typeof service === 'function') {
|
||||
return useReq(service, options);
|
||||
}
|
||||
return useReq(async () => {
|
||||
const { url, resource, resourceOf, action, params } = service as any;
|
||||
if (url) {
|
||||
const response = await api.request(service);
|
||||
return response?.data;
|
||||
}
|
||||
return useReq(async (params) => {
|
||||
const { resource } = service as ResourceActionOptions;
|
||||
if (resource) {
|
||||
const response = await api.resource(resource, resourceOf)[action](params);
|
||||
return response?.data?.data;
|
||||
Object.assign(service, { params });
|
||||
} else {
|
||||
Object.assign(service, params);
|
||||
}
|
||||
return;
|
||||
const response = await api.request(service);
|
||||
return response?.data;
|
||||
}, options);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user