|
1
|
import { MockMethod } from 'vite-plugin-mock';
|
|
2
|
import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util';
|
|
3
|
|
|
4
|
export function createFakeUserList() {
|
|
5
6
7
8
|
return [
{
userId: '1',
username: 'vben',
|
vben
authored
|
9
|
realName: 'Vben Admin',
|
|
10
|
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
|
|
11
12
13
|
desc: 'manager',
password: '123456',
token: 'fakeToken1',
|
|
14
|
homePath: '/dashboard/analysis',
|
vben
authored
|
15
16
17
18
19
20
|
roles: [
{
roleName: 'Super Admin',
value: 'super',
},
],
|
|
21
22
23
24
25
26
|
},
{
userId: '2',
username: 'test',
password: '123456',
realName: 'test user',
|
|
27
|
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=339449197&s=640',
|
|
28
29
|
desc: 'tester',
token: 'fakeToken2',
|
|
30
|
homePath: '/dashboard/workbench',
|
vben
authored
|
31
32
33
34
35
36
|
roles: [
{
roleName: 'Tester',
value: 'test',
},
],
|
|
37
38
39
40
41
42
43
44
45
46
47
48
|
},
];
}
const fakeCodeList: any = {
'1': ['1000', '3000', '5000'],
'2': ['2000', '4000', '6000'],
};
export default [
// mock user login
{
|
Vben
authored
|
49
|
url: '/basic-api/login',
|
vben
authored
|
50
|
timeout: 200,
|
|
51
52
53
54
|
method: 'post',
response: ({ body }) => {
const { username, password } = body;
const checkUser = createFakeUserList().find(
|
vben
authored
|
55
|
(item) => item.username === username && password === item.password,
|
|
56
57
58
59
|
);
if (!checkUser) {
return resultError('Incorrect account or password!');
}
|
vben
authored
|
60
|
const { userId, username: _username, token, realName, desc, roles } = checkUser;
|
|
61
|
return resultSuccess({
|
vben
authored
|
62
|
roles,
|
|
63
64
65
66
67
68
69
70
71
|
userId,
username: _username,
token,
realName,
desc,
});
},
},
{
|
|
72
|
url: '/basic-api/getUserInfo',
|
|
73
|
method: 'get',
|
|
74
75
76
77
|
response: (request: requestParams) => {
const token = getRequestToken(request);
if (!token) return resultError('Invalid token');
const checkUser = createFakeUserList().find((item) => item.token === token);
|
|
78
79
80
81
82
83
84
|
if (!checkUser) {
return resultError('The corresponding user information was not obtained!');
}
return resultSuccess(checkUser);
},
},
{
|
|
85
|
url: '/basic-api/getPermCode',
|
|
86
87
|
timeout: 200,
method: 'get',
|
|
88
89
90
91
92
93
|
response: (request: requestParams) => {
const token = getRequestToken(request);
if (!token) return resultError('Invalid token');
const checkUser = createFakeUserList().find((item) => item.token === token);
if (!checkUser) {
return resultError('Invalid token!');
|
|
94
|
}
|
|
95
|
const codeList = fakeCodeList[checkUser.userId];
|
|
96
97
98
99
|
return resultSuccess(codeList);
},
},
|
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
{
url: '/basic-api/logout',
timeout: 200,
method: 'get',
response: (request: requestParams) => {
const token = getRequestToken(request);
if (!token) return resultError('Invalid token');
const checkUser = createFakeUserList().find((item) => item.token === token);
if (!checkUser) {
return resultError('Invalid token!');
}
return resultSuccess(undefined, { message: 'Token has been destroyed' });
},
},
|
|
114
115
116
117
118
119
120
121
|
{
url: '/basic-api/testRetry',
statusCode: 405,
method: 'get',
response: () => {
return resultError('Error!');
},
},
|
|
122
|
] as MockMethod[];
|