52 lines
947 B
TypeScript
52 lines
947 B
TypeScript
|
import { config } from '@/config/axios'
|
||
|
import { MockMethod } from 'vite-plugin-mock'
|
||
|
|
||
|
const { result_code } = config
|
||
|
|
||
|
const List: {
|
||
|
username: string
|
||
|
password: string
|
||
|
role: string
|
||
|
roleId: string
|
||
|
}[] = [
|
||
|
{
|
||
|
username: 'admin',
|
||
|
password: 'admin',
|
||
|
role: 'admin',
|
||
|
roleId: '1'
|
||
|
},
|
||
|
{
|
||
|
username: 'test',
|
||
|
password: 'test',
|
||
|
role: 'test',
|
||
|
roleId: '2'
|
||
|
}
|
||
|
]
|
||
|
|
||
|
export default [
|
||
|
// 登录接口
|
||
|
{
|
||
|
url: '/user/login',
|
||
|
method: 'post',
|
||
|
response: ({ body }) => {
|
||
|
const data = body
|
||
|
let hasUser = false
|
||
|
for (const user of List) {
|
||
|
if (user.username === data.username && user.password === data.password) {
|
||
|
hasUser = true
|
||
|
return {
|
||
|
code: result_code,
|
||
|
data: user
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!hasUser) {
|
||
|
return {
|
||
|
code: '500',
|
||
|
message: '账号或密码错误'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
] as MockMethod[]
|