feat(clinical-web): 添加管理端与工作台 API 模块及类型定义
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { request } from '@/utils/request'
|
||||
|
||||
import type { UserListResponse, UserQuery, UserRecord } from './types'
|
||||
|
||||
const useMockData = import.meta.env.VITE_USE_MOCK !== 'false'
|
||||
|
||||
const mockRecords: UserRecord[] = [
|
||||
{
|
||||
id: 'user-001',
|
||||
name: '张文静',
|
||||
account: 'zhangwenjing',
|
||||
department: '医务管理',
|
||||
role: '系统管理员',
|
||||
status: 'enabled',
|
||||
lastLoginAt: '2026-08-27 08:12',
|
||||
},
|
||||
{
|
||||
id: 'user-002',
|
||||
name: '王医生',
|
||||
account: 'wangdoctor',
|
||||
department: '消化内科',
|
||||
role: '医生',
|
||||
status: 'enabled',
|
||||
lastLoginAt: '2026-08-27 08:35',
|
||||
},
|
||||
{
|
||||
id: 'user-003',
|
||||
name: '李护士',
|
||||
account: 'linurse',
|
||||
department: '儿科急诊',
|
||||
role: '护士',
|
||||
status: 'disabled',
|
||||
lastLoginAt: '2026-08-20 14:26',
|
||||
},
|
||||
]
|
||||
|
||||
export function getUsers(query: UserQuery): Promise<UserListResponse> {
|
||||
if (!useMockData) {
|
||||
return request.get<UserListResponse>('/management/users', {
|
||||
params: query,
|
||||
})
|
||||
}
|
||||
|
||||
const keyword = query.keyword?.trim().toLowerCase()
|
||||
const filteredRecords = mockRecords.filter((record) => {
|
||||
const matchesKeyword =
|
||||
!keyword || [record.name, record.account].join(' ').toLowerCase().includes(keyword)
|
||||
const matchesDepartment = !query.department || record.department === query.department
|
||||
const matchesStatus = !query.status || query.status === 'all' || record.status === query.status
|
||||
|
||||
return matchesKeyword && matchesDepartment && matchesStatus
|
||||
})
|
||||
const page = Math.max(query.page, 1)
|
||||
const pageSize = Math.max(query.pageSize, 1)
|
||||
const start = (page - 1) * pageSize
|
||||
|
||||
return Promise.resolve({
|
||||
records: filteredRecords.slice(start, start + pageSize),
|
||||
total: filteredRecords.length,
|
||||
page,
|
||||
pageSize,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user