93 lines
1.7 KiB
TypeScript
93 lines
1.7 KiB
TypeScript
|
import config from '@/config/axios/config'
|
||
|
|
||
|
const { code } = config
|
||
|
|
||
|
const delay = 1000
|
||
|
|
||
|
const List: {
|
||
|
username: string
|
||
|
password: string
|
||
|
role: string
|
||
|
roleId: string
|
||
|
permissions: string | string[]
|
||
|
}[] = [
|
||
|
{
|
||
|
username: 'admin',
|
||
|
password: 'admin',
|
||
|
role: 'admin',
|
||
|
roleId: '1',
|
||
|
permissions: ['*.*.*']
|
||
|
},
|
||
|
{
|
||
|
username: 'test',
|
||
|
password: 'test',
|
||
|
role: 'test',
|
||
|
roleId: '2',
|
||
|
permissions: ['example:dialog:create', 'example:dialog:delete']
|
||
|
}
|
||
|
]
|
||
|
|
||
|
export default [
|
||
|
// 列表接口
|
||
|
{
|
||
|
url: '/mock/user/list',
|
||
|
method: 'GET',
|
||
|
body: ({ 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,
|
||
|
data: {
|
||
|
total: mockList.length,
|
||
|
list: pageList
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
// 登录接口
|
||
|
{
|
||
|
url: '/mock/user/login',
|
||
|
method: 'POST',
|
||
|
delay,
|
||
|
body: ({ 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
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!hasUser) {
|
||
|
return {
|
||
|
code: 500,
|
||
|
message: '账号或密码错误'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
// 退出接口
|
||
|
{
|
||
|
url: '/mock/user/loginOut',
|
||
|
method: 'GET',
|
||
|
delay,
|
||
|
body: () => {
|
||
|
return {
|
||
|
code: code,
|
||
|
data: null
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
]
|