Skip to content

Commit

Permalink
fix: 修正DELETE、PUT、PATCH请求参数问题
Browse files Browse the repository at this point in the history
  • Loading branch information
eeve committed Nov 11, 2024
1 parent f9913ee commit b1693f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
23 changes: 14 additions & 9 deletions packages/editor/src/packages/utils/handleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@ export const handleApi = async (
} else {
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 {
const data = contentType === 'application/x-www-form-urlencoded'
? qs.stringify(config.data)
: config.data;

config.headers = {
...config.headers,
'Content-Type': contentType,
};
response =
(await request.post(config.url, contentType === 'application/x-www-form-urlencoded' ? qs.stringify(config.data) : config.data, config)) ||
{};

if (method === 'PUT') {
response = (await request.put(config.url, data, config)) || {};
} else if (method === 'PATCH') {
response = (await request.patch(config.url, data, config)) || {};
} else if (method === 'DELETE') {
response = (await request.delete(config.url, { ...config, data })) || {};
} else {
response = (await request.post(config.url, data, config)) || {};
}
}
}
} catch (error: any) {
Expand Down
23 changes: 14 additions & 9 deletions packages/materials/utils/handleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@ export const handleApi = async (
} else {
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 {
const data = contentType === 'application/x-www-form-urlencoded'
? qs.stringify(config.data)
: config.data;

config.headers = {
...config.headers,
'Content-Type': contentType,
};
response =
(await request.post(config.url, contentType === 'application/x-www-form-urlencoded' ? qs.stringify(config.data) : config.data, config)) ||
{};

if (method === 'PUT') {
response = (await request.put(config.url, data, config)) || {};
} else if (method === 'PATCH') {
response = (await request.patch(config.url, data, config)) || {};
} else if (method === 'DELETE') {
response = (await request.delete(config.url, { ...config, data })) || {};
} else {
response = (await request.post(config.url, data, config)) || {};
}
}
}
} catch (error: any) {
Expand Down

0 comments on commit b1693f2

Please sign in to comment.