Skip to content

Commit

Permalink
fix: 修正DELETE、PUT请求逻辑,新增PATCH请求动词
Browse files Browse the repository at this point in the history
  • Loading branch information
eeve authored and jianbing.chen committed Dec 18, 2024
1 parent 7aff137 commit de706ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const SettingForm = function () {
<Radio.Button value="GET">GET</Radio.Button>
<Radio.Button value="POST">POST</Radio.Button>
<Radio.Button value="PUT">PUT</Radio.Button>
<Radio.Button value="PATCH">PATCH</Radio.Button>
<Radio.Button value="DELETE">DELETE</Radio.Button>
</Radio.Group>
</Form.Item>
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/packages/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export interface ApiType {
stgApi: string;
preApi: string;
prdApi: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
sourceType?: string; //数据源类型,枚举值
// 静态数据源映射
source: any;
Expand Down
8 changes: 7 additions & 1 deletion packages/editor/src/packages/utils/handleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ export const handleApi = async (
return { code: 0, data: response.data, msg: '' };
}
} else {
if (method === 'GET' || method === 'DELETE') {
if (method === 'GET') {
response = (await request.get(config.url, config)) || {};
} else if (method === 'PUT') {
response = (await request.put(config.url, config)) || {};
} else if (method === 'PATCH') {
response = (await request.patch(config.url, config)) || {};
} else if (method === 'DELETE') {
response = (await request.delete(config.url, config)) || {};
} else {
config.headers = {
...config.headers,
Expand Down
7 changes: 5 additions & 2 deletions packages/editor/src/packages/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ export default {
return instance.post(url, params, config);
},
put<R = any>(url: string, params: any = {}, config: any = {}): Promise<R> {
return instance.post(url, params, config);
return instance.put(url, params, config);
},
patch<R = any>(url: string, params: any = {}, config: any = {}): Promise<R> {
return instance.patch(url, params, config);
},
delete<R = any>(url: string, config: any = {}): Promise<R> {
return instance.get(url, config);
return instance.delete(url, config);
},
download(url: string, params: any = {}, config: any = {}) {
return instance.post(url, params, { ...config, responseType: 'blob' }).then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/materials/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export interface ApiType {
stgApi: string;
preApi: string;
prdApi: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
sourceType?: string; //数据源类型,枚举值
// 静态数据源映射
source: any;
Expand Down
8 changes: 7 additions & 1 deletion packages/materials/utils/handleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ export const handleApi = async (
return { code: 0, data: response.data, msg: '' };
}
} else {
if (method === 'GET' || method === 'DELETE') {
if (method === 'GET') {
response = (await request.get(config.url, config)) || {};
} else if (method === 'PUT') {
response = (await request.put(config.url, config)) || {};
} else if (method === 'PATCH') {
response = (await request.patch(config.url, config)) || {};
} else if (method === 'DELETE') {
response = (await request.delete(config.url, config)) || {};
} else {
config.headers = {
...config.headers,
Expand Down
7 changes: 5 additions & 2 deletions packages/materials/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ export default {
return instance.post(url, params, config);
},
put<R = any>(url: string, params: any = {}, config: any = {}): Promise<R> {
return instance.post(url, params, config);
return instance.put(url, params, config);
},
patch<R = any>(url: string, params: any = {}, config: any = {}): Promise<R> {
return instance.patch(url, params, config);
},
delete<R = any>(url: string, config: any = {}): Promise<R> {
return instance.get(url, config);
return instance.delete(url, config);
},
download(url: string, params: any = {}, config: any = {}) {
return instance.post(url, params, { ...config, responseType: 'blob' }).then((response) => {
Expand Down

0 comments on commit de706ed

Please sign in to comment.