fix: JSON.stringify for filter
This commit is contained in:
		
							parent
							
								
									eb501e3461
								
							
						
					
					
						commit
						2fd4e2fa61
					
				@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import { stringify } from 'querystring';
 | 
				
			||||||
import { request } from 'umi';
 | 
					import { request } from 'umi';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface ActionParams {
 | 
					interface ActionParams {
 | 
				
			||||||
@ -27,9 +28,11 @@ class ApiClient {
 | 
				
			|||||||
    const proxy: any = new Proxy({}, {
 | 
					    const proxy: any = new Proxy({}, {
 | 
				
			||||||
      get(target, method, receiver) {
 | 
					      get(target, method, receiver) {
 | 
				
			||||||
        return (params: ActionParams = {}) => {
 | 
					        return (params: ActionParams = {}) => {
 | 
				
			||||||
          const { associatedKey, resourceKey, ...restParams } = params;
 | 
					          const { associatedKey, resourceKey, filter, ...restParams } = params;
 | 
				
			||||||
          let url = `/${name}`;
 | 
					          let url = `/${name}`;
 | 
				
			||||||
          let options: any = {};
 | 
					          let options: any = {
 | 
				
			||||||
 | 
					            params: {},
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
          if (['list', 'get'].indexOf(method as string) !== -1) {
 | 
					          if (['list', 'get'].indexOf(method as string) !== -1) {
 | 
				
			||||||
            options.method = 'get';
 | 
					            options.method = 'get';
 | 
				
			||||||
            options.params = restParams;
 | 
					            options.params = restParams;
 | 
				
			||||||
@ -45,6 +48,9 @@ class ApiClient {
 | 
				
			|||||||
          if (resourceKey) {
 | 
					          if (resourceKey) {
 | 
				
			||||||
            url += `/${resourceKey}`;
 | 
					            url += `/${resourceKey}`;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					          if (filter) {
 | 
				
			||||||
 | 
					            options.params['filter'] = JSON.stringify(filter);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          console.log({url, params});
 | 
					          console.log({url, params});
 | 
				
			||||||
          return request(url, options);
 | 
					          return request(url, options);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user