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