gohttpdUi/mock/user/index.ts

94 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-05-04 14:19:31 +08:00
import config from '@/config/axios/config'
2022-01-08 18:38:20 +08:00
import { MockMethod } from 'vite-plugin-mock'
2023-05-04 14:19:31 +08:00
const { code } = config
2022-01-08 18:38:20 +08:00
const timeout = 1000
2022-01-08 18:38:20 +08:00
const List: {
username: string
password: string
role: string
roleId: string
2022-07-13 11:50:45 +08:00
permissions: string | string[]
2022-01-08 18:38:20 +08:00
}[] = [
{
username: 'admin',
password: 'admin',
role: 'admin',
2022-07-13 11:50:45 +08:00
roleId: '1',
2022-07-18 16:02:20 +08:00
permissions: ['*.*.*']
2022-01-08 18:38:20 +08:00
},
{
username: 'test',
password: 'test',
role: 'test',
2022-07-13 11:50:45 +08:00
roleId: '2',
permissions: ['example:dialog:create', 'example:dialog:delete']
2022-01-08 18:38:20 +08:00
}
]
export default [
2022-02-19 20:34:44 +08:00
// 列表接口
{
url: '/user/list',
method: 'get',
response: ({ query }) => {
const { username, pageIndex, pageSize } = query
const mockList = List.filter((item) => {
if (username && item.username.indexOf(username) < 0) return false
return true
})
const pageList = mockList.filter(
(_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
)
return {
code: code,
2022-02-19 20:34:44 +08:00
data: {
total: mockList.length,
list: pageList
2022-02-19 20:34:44 +08:00
}
}
}
},
2022-01-08 18:38:20 +08:00
// 登录接口
{
url: '/user/login',
method: 'post',
timeout,
2022-01-08 18:38:20 +08:00
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: code,
data: user
2022-01-08 18:38:20 +08:00
}
}
}
if (!hasUser) {
return {
code: 500,
message: '账号或密码错误'
2022-01-08 18:38:20 +08:00
}
}
}
},
// 退出接口
{
url: '/user/loginOut',
method: 'get',
timeout,
response: () => {
return {
code: code,
data: null
}
}
2022-01-08 18:38:20 +08:00
}
] as MockMethod[]