mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
9e5e630987
* refactor(api): remove unnecessary userId param 移除getUserInfo、getPermCode、getMenuList接口的userId参数。 这些接口应当始终与当前登录用户相关而无需传递userId。 * fix: fix auth header key case error
99 lines
2.5 KiB
TypeScript
99 lines
2.5 KiB
TypeScript
import { MockMethod } from 'vite-plugin-mock';
|
||
import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util';
|
||
|
||
export function createFakeUserList() {
|
||
return [
|
||
{
|
||
userId: '1',
|
||
username: 'vben',
|
||
realName: 'Vben Admin',
|
||
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
|
||
desc: 'manager',
|
||
password: '123456',
|
||
token: 'fakeToken1',
|
||
roles: [
|
||
{
|
||
roleName: 'Super Admin',
|
||
value: 'super',
|
||
},
|
||
],
|
||
},
|
||
{
|
||
userId: '2',
|
||
username: 'test',
|
||
password: '123456',
|
||
realName: 'test user',
|
||
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=339449197&s=640',
|
||
desc: 'tester',
|
||
token: 'fakeToken2',
|
||
roles: [
|
||
{
|
||
roleName: 'Tester',
|
||
value: 'test',
|
||
},
|
||
],
|
||
},
|
||
];
|
||
}
|
||
|
||
const fakeCodeList: any = {
|
||
'1': ['1000', '3000', '5000'],
|
||
|
||
'2': ['2000', '4000', '6000'],
|
||
};
|
||
export default [
|
||
// mock user login
|
||
{
|
||
url: '/basic-api/login',
|
||
timeout: 200,
|
||
method: 'post',
|
||
response: ({ body }) => {
|
||
const { username, password } = body;
|
||
const checkUser = createFakeUserList().find(
|
||
(item) => item.username === username && password === item.password
|
||
);
|
||
if (!checkUser) {
|
||
return resultError('Incorrect account or password!');
|
||
}
|
||
const { userId, username: _username, token, realName, desc, roles } = checkUser;
|
||
return resultSuccess({
|
||
roles,
|
||
userId,
|
||
username: _username,
|
||
token,
|
||
realName,
|
||
desc,
|
||
});
|
||
},
|
||
},
|
||
{
|
||
url: '/basic-api/getUserInfo',
|
||
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('The corresponding user information was not obtained!');
|
||
}
|
||
return resultSuccess(checkUser);
|
||
},
|
||
},
|
||
{
|
||
url: '/basic-api/getPermCode',
|
||
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!');
|
||
}
|
||
const codeList = fakeCodeList[checkUser.userId];
|
||
|
||
return resultSuccess(codeList);
|
||
},
|
||
},
|
||
] as MockMethod[];
|