71 lines
1.4 KiB
TypeScript
71 lines
1.4 KiB
TypeScript
import { MockMethod } from 'vite-plugin-mock'
|
|
const users = [
|
|
{ name: 'admin', password: '123456', token: 'admin', info: {
|
|
name: '系统管理员'
|
|
}},
|
|
{ name: 'editor', password: '123456', token: 'editor', info: {
|
|
name: '编辑人员'
|
|
}},
|
|
{ name: 'test', password: '123456', token: 'test', info: {
|
|
name: '测试人员'
|
|
}},
|
|
]
|
|
export default [
|
|
{
|
|
url: `/mock/user/login`,
|
|
method: 'post',
|
|
response: ({ body }) => {
|
|
const user = users.find(user => {
|
|
return body.name === user.name && body.password === user.password
|
|
})
|
|
if (user) {
|
|
return {
|
|
code: 200,
|
|
data: {
|
|
token: user.token,
|
|
},
|
|
};
|
|
} else {
|
|
return {
|
|
code: 401,
|
|
data: {},
|
|
msg: '用户名或密码错误'
|
|
};
|
|
}
|
|
|
|
}
|
|
},
|
|
{
|
|
url: `/mock/user/info`,
|
|
method: 'post',
|
|
response: ({ body }) => {
|
|
return {
|
|
code: 200,
|
|
data: users[0],
|
|
}
|
|
|
|
}
|
|
},
|
|
{
|
|
url: `/mock/user/out`,
|
|
method: 'post',
|
|
response: () => {
|
|
return {
|
|
code: 200,
|
|
data: {},
|
|
msg: 'success'
|
|
};
|
|
}
|
|
},
|
|
{
|
|
url: `/mock/user/passwordChange`,
|
|
method: 'post',
|
|
response: () => {
|
|
return {
|
|
code: 200,
|
|
data: {},
|
|
msg: 'success'
|
|
};
|
|
}
|
|
},
|
|
] as MockMethod[] |