feat(组织架构): 完成员工与组织节点管理
This commit is contained in:
@@ -20,26 +20,35 @@ function getRecords(data: BackendCollection<OrganizationResponseDto>) {
|
||||
return Array.isArray(data) ? data : (data.records ?? data.items ?? data.content ?? [])
|
||||
}
|
||||
|
||||
export function getCampuses(): Promise<CampusRecord[]> {
|
||||
export async function getCampuses(): Promise<CampusRecord[]> {
|
||||
if (useMockData) {
|
||||
return Promise.resolve([])
|
||||
return []
|
||||
}
|
||||
|
||||
return request
|
||||
.get<ApiResponse<BackendCollection<OrganizationResponseDto>>>('/v1/campuses', {
|
||||
params: { page: 1, size: 200 },
|
||||
})
|
||||
.then(unwrapApiResponse)
|
||||
.then((data) =>
|
||||
getRecords(data).map((item) => ({
|
||||
id: item.id,
|
||||
code: item.code ?? item.id,
|
||||
name: item.name ?? item.campusName ?? item.id,
|
||||
address: item.address ?? undefined,
|
||||
status: item.status ?? 'ENABLED',
|
||||
sortNo: item.sortNo ?? 0,
|
||||
})),
|
||||
)
|
||||
const firstPage = await getCampusPage(1, 200)
|
||||
const pageCount = Math.ceil(firstPage.total / firstPage.pageSize)
|
||||
if (pageCount <= 1) return firstPage.records
|
||||
|
||||
const remainingPages = await Promise.all(
|
||||
Array.from({ length: pageCount - 1 }, (_, index) =>
|
||||
getCampusPage(index + 2, firstPage.pageSize),
|
||||
),
|
||||
)
|
||||
return [firstPage, ...remainingPages].flatMap((page) => page.records)
|
||||
}
|
||||
|
||||
async function getCampusPage(page: number, pageSize: number) {
|
||||
const response = await request.get<ApiResponse<BackendCollection<OrganizationResponseDto>>>(
|
||||
'/v1/campuses',
|
||||
{ params: { page, size: pageSize } },
|
||||
)
|
||||
const data = unwrapApiResponse(response)
|
||||
const records = getRecords(data).map(mapCampus)
|
||||
return {
|
||||
records,
|
||||
total: Array.isArray(data) ? records.length : (data.total ?? records.length),
|
||||
pageSize: Array.isArray(data) ? pageSize : (data.size ?? pageSize),
|
||||
}
|
||||
}
|
||||
|
||||
export function getDepartments(campusId?: string): Promise<DepartmentRecord[]> {
|
||||
@@ -102,6 +111,7 @@ function mapCampus(data: OrganizationResponseDto): CampusRecord {
|
||||
id: data.id,
|
||||
code: data.code ?? data.id,
|
||||
name: data.name ?? data.campusName ?? data.id,
|
||||
institutionName: data.institutionName?.trim() || '新华院区',
|
||||
address: data.address ?? undefined,
|
||||
status: data.status ?? 'ENABLED',
|
||||
sortNo: data.sortNo ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user