dataease-dm/core/frontend/mock/user.js

85 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-03-03 15:06:52 +08:00
const tokens = {
admin: {
token: 'admin-token'
},
editor: {
token: 'editor-token'
}
}
const users = {
'admin-token': {
roles: ['admin'],
introduction: 'I am a super administrator',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Super Admin'
},
'editor-token': {
roles: ['editor'],
introduction: 'I am an editor',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Normal Editor'
}
}
export default [
// user login
{
2021-11-24 18:49:41 +08:00
url: '/dataease/user/login',
2021-03-03 15:06:52 +08:00
type: 'post',
response: config => {
const { username } = config.body
const token = tokens[username]
// mock error
if (!token) {
return {
code: 60204,
message: 'Account and password are incorrect.'
}
}
return {
code: 20000,
data: token
}
}
},
// get user info
{
2022-06-17 10:55:44 +08:00
url: '/dataease/user/info*',
2021-03-03 15:06:52 +08:00
type: 'get',
response: config => {
const { token } = config.query
const info = users[token]
// mock error
if (!info) {
return {
code: 50008,
message: 'Login failed, unable to get user details.'
}
}
return {
code: 20000,
data: info
}
}
},
// user logout
{
2021-11-24 18:49:41 +08:00
url: '/dataease/user/logout',
2021-03-03 15:06:52 +08:00
type: 'post',
response: _ => {
return {
code: 20000,
data: 'success'
}
}
}
]