92 lines
2.0 KiB
TypeScript
92 lines
2.0 KiB
TypeScript
import { MockMethod, Recordable } from 'vite-plugin-mock'
|
|
import { resultSuccess } from './_util'
|
|
|
|
export default [
|
|
{
|
|
url: /api\/v1\/users\/\d+/,
|
|
method: 'get',
|
|
response: (opt: { url: Recordable; query: Recordable }) => {
|
|
const userId = opt.url.split('/')[4]
|
|
return resultSuccess({
|
|
id: userId,
|
|
'userId|+1': '@/name',
|
|
'name|+1': '@/cname',
|
|
mobile: /1[0-9]{10}/,
|
|
'gender|1-2': 0,
|
|
avatar: "@image('100x100', '@/color', '#FFF', 'png', '')",
|
|
position: '操作员',
|
|
mainDepartment: 2,
|
|
roles: [
|
|
{
|
|
id: 1,
|
|
name: '管理员'
|
|
}
|
|
],
|
|
departments: [
|
|
{
|
|
id: 1,
|
|
name: '研发'
|
|
}
|
|
],
|
|
lastLoginAt: 0,
|
|
lastLoginIp: '[::1]:6994',
|
|
disabledAt: 0,
|
|
createdAt: 1680884142,
|
|
updatedAt: 1682327867,
|
|
status: 1,
|
|
department: '研发'
|
|
})
|
|
}
|
|
},
|
|
{
|
|
url: '/api/v1/users',
|
|
method: 'get',
|
|
response: () => {
|
|
return resultSuccess({
|
|
page: 1,
|
|
limit: 10,
|
|
total: 12,
|
|
'data|10': [
|
|
{
|
|
'id|+1': 1,
|
|
'userId|1': '@/name',
|
|
'name|1': '@/cname',
|
|
mobile: /1[0-9]{10}/,
|
|
'gender|1-2': 0,
|
|
avatar: "@image('100x100', '@/color', '#FFF', 'png', '')",
|
|
position: '@/title',
|
|
mainDepartment: 2,
|
|
lastLoginAt: 1682327867,
|
|
lastLoginIp: '[::1]:6994',
|
|
disabledAt: 0,
|
|
createdAt: 1680884142,
|
|
updatedAt: 1682327867
|
|
}
|
|
]
|
|
})
|
|
}
|
|
},
|
|
{
|
|
url: /\/api\/v1\/users\/\d+\/roles\/\d+/,
|
|
method: 'post',
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
},
|
|
{
|
|
url: '/api/v1/users',
|
|
method: 'post',
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
},
|
|
// 删除用户
|
|
{
|
|
url: /\/api\/v1\/users\/\d+/,
|
|
method: 'delete',
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
}
|
|
] as MockMethod[]
|