Skip to content

Commit 8e52248

Browse files
committed
fix api
1 parent a249aa7 commit 8e52248

File tree

7 files changed

+69
-139
lines changed

7 files changed

+69
-139
lines changed

antd-pro/src/services/api/account.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// @ts-ignore
22
/* eslint-disable */
3-
import { request, history } from '@umijs/max';
4-
import { stringify } from 'querystring';
3+
import {history} from '@umijs/max';
4+
import {stringify} from 'querystring';
5+
import {post} from "./index";
56

67

78
export function logout() {
@@ -10,12 +11,12 @@ export function logout() {
1011
localStorage.removeItem('authorities');
1112
localStorage.removeItem('avatar');
1213

13-
const { search, pathname } = window.location;
14+
const {search, pathname} = window.location;
1415
const urlParams = new URL(window.location.href).searchParams;
1516
/** 此方法会跳转到 redirect 参数所在的位置 */
1617
const redirect = urlParams.get('redirect');
1718
// Note: There may be security issues, please note
18-
if (window.location.pathname !== '/user/login' && !redirect) {
19+
if (window.location.pathname !== '/login' && !redirect) {
1920
history.replace({
2021
pathname: '/login',
2122
search: stringify({
@@ -27,14 +28,7 @@ export function logout() {
2728

2829

2930
/** 登录接口 POST /api/login/account */
30-
export async function login(body: Account.LoginRequest, options?: { [key: string]: any }) {
31-
return request<API.Response<Account.LoginResponse>>('/user/login', {
32-
method: 'POST',
33-
headers: {
34-
'Content-Type': 'application/json',
35-
},
36-
data: body,
37-
...(options || {}),
38-
});
31+
export async function login(body: Account.LoginRequest) {
32+
return post('/user/login', body);
3933
}
4034

antd-pro/src/services/api/api.ts

+9-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-ignore
22
/* eslint-disable */
3-
import {request} from '@umijs/max';
3+
import {get, post} from "@/services/api/index";
44

55

66
export async function list(
@@ -11,51 +11,23 @@ export async function list(
1111
/** 页面的容量 */
1212
pageSize?: number;
1313
},
14-
options?: { [key: string]: any },
1514
) {
16-
return request<API.Response<any>>('/api/api/list', {
17-
method: 'GET',
18-
params: {
19-
...params,
20-
},
21-
...(options || {}),
22-
});
15+
return get('/api/api/list', params);
2316
}
2417

2518

26-
export async function test(body: any, options?: { [key: string]: any }) {
27-
return request<API.Response<any>>('/api/api/test', {
28-
method: 'POST',
29-
headers: {
30-
'Content-Type': 'application/json',
31-
},
32-
data: body,
33-
...(options || {}),
34-
});
19+
export async function test(body: any) {
20+
return post('/api/api/test', body)
3521
}
3622

3723

38-
export async function save(body: any, options?: { [key: string]: any }) {
39-
return request<API.Response<any>>('/api/api/save', {
40-
method: 'POST',
41-
headers: {
42-
'Content-Type': 'application/json',
43-
},
44-
data: body,
45-
...(options || {}),
46-
});
24+
export async function save(body: any) {
25+
return post('/api/api/save', body)
4726
}
4827

4928

5029
export async function del(body: {
51-
id:string,
52-
}, options?: { [key: string]: any }) {
53-
return request<API.Response<any>>('/api/api/delete', {
54-
method: 'POST',
55-
headers: {
56-
'Content-Type': 'application/json',
57-
},
58-
data: body,
59-
...(options || {}),
60-
});
30+
id: string,
31+
}) {
32+
return post('/api/api/delete', body)
6133
}

antd-pro/src/services/api/index.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @ts-ignore
2+
/* eslint-disable */
3+
import {request} from '@umijs/max';
4+
5+
6+
export async function get(url:string,params?:any,options?: { [key: string]: any }) {
7+
return request<API.Response<any>>(url, {
8+
method: 'GET',
9+
params: {
10+
...params,
11+
},
12+
...(options || {}),
13+
});
14+
}
15+
16+
export async function post(url:string,body?: any,options?: { [key: string]: any }) {
17+
return request<API.Response<any>>(url, {
18+
method: 'POST',
19+
headers: {
20+
'Content-Type': 'application/json',
21+
},
22+
data: body,
23+
...(options || {}),
24+
});
25+
}
26+
27+
28+
export async function postFile(url:string,file:File) {
29+
const formData = new FormData();
30+
formData.append('files', file);
31+
32+
return request<API.Response<any>>(url, {
33+
method: 'POST',
34+
data: formData,
35+
});
36+
}

antd-pro/src/services/api/oss.ts

+4-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-ignore
22
/* eslint-disable */
3-
import {request} from '@umijs/max';
3+
import {get, post, postFile} from "@/services/api/index";
44

55

66
export async function list(
@@ -11,39 +11,18 @@ export async function list(
1111
/** 页面的容量 */
1212
pageSize?: number;
1313
},
14-
options?: { [key: string]: any },
1514
) {
16-
return request<API.Response<any>>('/api/oss/list', {
17-
method: 'GET',
18-
params: {
19-
...params,
20-
},
21-
...(options || {}),
22-
});
15+
return get('/api/oss/list', params);
2316
}
2417

2518

26-
2719
export async function upload(file: File) {
28-
const formData = new FormData();
29-
formData.append('files', file);
30-
31-
return request<API.Response<any>>('/api/oss/upload', {
32-
method: 'POST',
33-
data: formData,
34-
});
20+
return postFile('/api/oss/upload', file);
3521
}
3622

3723

3824
export async function del(body: {
3925
id:string,
4026
}, options?: { [key: string]: any }) {
41-
return request<API.Response<any>>('/api/oss/delete', {
42-
method: 'POST',
43-
headers: {
44-
'Content-Type': 'application/json',
45-
},
46-
data: body,
47-
...(options || {}),
48-
});
27+
return post('/api/oss/delete', body);
4928
}
+6-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-ignore
22
/* eslint-disable */
3-
import {request} from '@umijs/max';
4-
3+
import {get, post} from "@/services/api/index";
54

65
export async function list(
76
params: {
@@ -13,37 +12,17 @@ export async function list(
1312
},
1413
options?: { [key: string]: any },
1514
) {
16-
return request<API.Response<any>>('/api/parameter/list', {
17-
method: 'GET',
18-
params: {
19-
...params,
20-
},
21-
...(options || {}),
22-
});
15+
return get('/api/parameter/list', params);
2316
}
2417

2518

26-
export async function save(body: Table.SaveCommand, options?: { [key: string]: any }) {
27-
return request<API.Response<any>>('/api/parameter/save', {
28-
method: 'POST',
29-
headers: {
30-
'Content-Type': 'application/json',
31-
},
32-
data: body,
33-
...(options || {}),
34-
});
19+
export async function save(body: any) {
20+
return post('/api/parameter/save', body);
3521
}
3622

3723

3824
export async function del(body: {
3925
id:string,
40-
}, options?: { [key: string]: any }) {
41-
return request<API.Response<any>>('/api/parameter/delete', {
42-
method: 'POST',
43-
headers: {
44-
'Content-Type': 'application/json',
45-
},
46-
data: body,
47-
...(options || {}),
48-
});
26+
}) {
27+
return post('/api/parameter/delete', body);
4928
}

antd-pro/src/services/api/table.ts

+7-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-ignore
22
/* eslint-disable */
3-
import {request} from '@umijs/max';
3+
import {get, post} from "@/services/api/index";
44

55

66
export async function list(
@@ -10,40 +10,19 @@ export async function list(
1010
current?: number;
1111
/** 页面的容量 */
1212
pageSize?: number;
13-
},
14-
options?: { [key: string]: any },
13+
}
1514
) {
16-
return request<API.Response<any>>('/api/server/list', {
17-
method: 'GET',
18-
params: {
19-
...params,
20-
},
21-
...(options || {}),
22-
});
15+
return get('/api/server/list', params);
2316
}
2417

2518

26-
export async function save(body: Table.SaveCommand, options?: { [key: string]: any }) {
27-
return request<API.Response<any>>('/api/server/save', {
28-
method: 'POST',
29-
headers: {
30-
'Content-Type': 'application/json',
31-
},
32-
data: body,
33-
...(options || {}),
34-
});
19+
export async function save(body: any) {
20+
return post('/api/server/save', body);
3521
}
3622

3723

3824
export async function del(body: {
3925
id:string,
40-
}, options?: { [key: string]: any }) {
41-
return request<API.Response<any>>('/api/server/del', {
42-
method: 'POST',
43-
headers: {
44-
'Content-Type': 'application/json',
45-
},
46-
data: body,
47-
...(options || {}),
48-
});
26+
}) {
27+
return post('/api/server/delete', body);
4928
}

antd-pro/src/services/api/typings.d.ts

-9
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,3 @@ declare namespace Account {
3535
};
3636
}
3737

38-
39-
declare namespace Table {
40-
41-
type SaveCommand = {
42-
name: string;
43-
url: string;
44-
};
45-
46-
}

0 commit comments

Comments
 (0)