2018-07-16 22:22:55 +08:00
|
|
|
import Mock from 'mockjs'
|
|
|
|
|
|
|
|
|
|
const userDB = [
|
|
|
|
|
{
|
|
|
|
|
username: 'admin',
|
|
|
|
|
password: 'admin',
|
2018-07-23 20:16:56 +08:00
|
|
|
uuid: 'admin-uuid',
|
2018-07-16 22:22:55 +08:00
|
|
|
name: '管理员'
|
2018-07-18 13:57:52 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
username: 'editor',
|
|
|
|
|
password: 'editor',
|
|
|
|
|
uuid: 'editor-uuid',
|
|
|
|
|
name: '编辑'
|
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-19 17:00:45 +08:00
|
|
|
username: 'user1',
|
|
|
|
|
password: 'user1',
|
|
|
|
|
uuid: 'user1-uuid',
|
|
|
|
|
name: '用户1'
|
2018-07-16 22:22:55 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2018-08-24 17:05:32 +08:00
|
|
|
Mock.mock('/api/login', 'post', ({url, type, body}) => {
|
2018-07-16 22:22:55 +08:00
|
|
|
const bodyObj = JSON.parse(body)
|
|
|
|
|
const user = userDB.find(e => e.username === bodyObj.username && e.password === bodyObj.password)
|
|
|
|
|
if (user) {
|
|
|
|
|
return {
|
|
|
|
|
code: 0,
|
2018-08-31 16:23:47 +08:00
|
|
|
msg: '登录成功',
|
2018-07-16 22:22:55 +08:00
|
|
|
data: {
|
|
|
|
|
...user,
|
|
|
|
|
token: 'd787syv8dys8cas80d9s0a0d8f79ads56f7s4d56f879a8as89fd980s7dg'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
code: 401,
|
2018-08-27 09:10:30 +08:00
|
|
|
msg: '用户名或密码错误',
|
|
|
|
|
data: {}
|
2018-07-16 22:22:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|