vben-admin-thin-next/mock/sys/user.ts
Netfan 7519a00ada
fix(avatar): show current user's avatar (#640)
在显示头像的地方正确显示当前登录用户的头像,已补充mock接口返回的avatar字段。
2021-05-23 09:02:47 +08:00

96 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { MockMethod } from 'vite-plugin-mock';
import { resultError, resultSuccess } from '../_util';
function createFakeUserList() {
return [
{
userId: '1',
username: 'vben',
realName: 'Vben Admin',
avatar: 'http://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: 'http://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/getUserInfoById',
method: 'get',
response: ({ query }) => {
const { userId } = query;
const checkUser = createFakeUserList().find((item) => item.userId === userId);
if (!checkUser) {
return resultError('The corresponding user information was not obtained!');
}
return resultSuccess(checkUser);
},
},
{
url: '/basic-api/getPermCodeByUserId',
timeout: 200,
method: 'get',
response: ({ query }) => {
const { userId } = query;
if (!userId) {
return resultError('userId is not null!');
}
const codeList = fakeCodeList[userId];
return resultSuccess(codeList);
},
},
] as MockMethod[];