fix(management): align user permissions with API

This commit is contained in:
yelan
2026-09-01 18:20:04 +08:00
parent dc86ee9149
commit fa42b89136
8 changed files with 226 additions and 34 deletions
+19 -3
View File
@@ -6,6 +6,7 @@ import type {
BackendCollection,
CreateRoleRequest,
RoleRecord,
RoleQuery,
RoleResponseDto,
UpdateRoleRequest,
} from './types'
@@ -21,18 +22,33 @@ function normalizeRole(dto: RoleResponseDto, index: number): RoleRecord {
name: dto.name,
description: dto.description ?? '—',
color: fallbackColors[index % fallbackColors.length],
userCount: dto.userCount ?? 0,
userCount: dto.userCount ?? undefined,
status: dto.status ?? 'ENABLED',
}
}
export function getRoles(): Promise<RoleRecord[]> {
function toBackendQuery(query: RoleQuery) {
const params: Record<string, string | number> = {
page: Math.max(query.page, 1),
size: Math.min(Math.max(query.pageSize, 1), 200),
}
if (query.keyword?.trim()) {
params.keyword = query.keyword.trim()
}
return params
}
export function getRoles(query: RoleQuery = { page: 1, pageSize: 200 }): Promise<RoleRecord[]> {
if (useMockData) {
return Promise.resolve([])
}
return request
.get<ApiResponse<BackendCollection<RoleResponseDto>>>('/v1/roles')
.get<ApiResponse<BackendCollection<RoleResponseDto>>>('/v1/roles', {
params: toBackendQuery(query),
})
.then(unwrapApiResponse)
.then((data) => {
const records = Array.isArray(data)
+5
View File
@@ -126,6 +126,10 @@ export interface RoleRecord {
status: RoleStatus
}
export interface RoleQuery extends PageQuery {
keyword?: string
}
export type RoleStatus = 'ENABLED' | 'DISABLED' | string
export interface RoleResponseDto {
@@ -297,6 +301,7 @@ export interface UserQuery extends PageQuery {
keyword?: string
department?: string
status?: UserStatus | 'all'
campusId?: string
}
export interface UserRecord {
+8 -3
View File
@@ -78,8 +78,8 @@ function mapUser(dto: UserResponseDto): UserRecord {
id: dto.id,
name: dto.displayName,
account: dto.username,
department: dto.departmentId ?? '未指定科室',
role: '未分配角色',
department: dto.departmentId ? '未知科室' : '未指定科室',
role: '未返回角色',
status: normalizeStatus(dto.status),
lastLoginAt: formatDateTime(dto.lastLoginAt),
employeeNo: dto.employeeNo,
@@ -116,6 +116,10 @@ function toBackendQuery(query: UserQuery) {
params.keyword = query.keyword.trim()
}
if (query.campusId) {
params.campusId = query.campusId
}
return params
}
@@ -141,8 +145,9 @@ export function getUsers(query: UserQuery): Promise<UserListResponse> {
!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
const matchesCampus = !query.campusId || record.campusId === query.campusId
return matchesKeyword && matchesDepartment && matchesStatus
return matchesKeyword && matchesDepartment && matchesStatus && matchesCampus
})
const page = Math.max(query.page, 1)
const pageSize = Math.max(query.pageSize, 1)