diff --git a/src/Jiaowu.Api/Controllers/OfficialDocumentsController.cs b/src/Jiaowu.Api/Controllers/OfficialDocumentsController.cs index 42b80c7..e913d16 100644 --- a/src/Jiaowu.Api/Controllers/OfficialDocumentsController.cs +++ b/src/Jiaowu.Api/Controllers/OfficialDocumentsController.cs @@ -80,8 +80,13 @@ public sealed class OfficialDocumentsController( [Authorize(Roles = Managers)] public async Task StudentOptions( string? keyword, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + int page = 1, + int pageSize = 30) { + if (page < 1 || pageSize is < 1 or > 100) + return ValidationProblem("页码必须大于 0,且每页条数应在 1 至 100 之间。"); + var source = AccessibleStudents().AsNoTracking(); if (!string.IsNullOrWhiteSpace(keyword)) { @@ -90,7 +95,10 @@ public sealed class OfficialDocumentsController( x.StudentNumber.Contains(value) || x.Name.Contains(value)); } - return Ok(await source.OrderBy(x => x.StudentNumber) + var total = await source.CountAsync(cancellationToken); + var items = await source.OrderBy(x => x.StudentNumber) + .Skip((page - 1) * pageSize) + .Take(pageSize) .Select(x => new { x.Id, @@ -101,7 +109,8 @@ public sealed class OfficialDocumentsController( MajorName = x.AdministrativeClass.Major!.Name, CollegeName = x.AdministrativeClass.Major.College!.Name }) - .ToListAsync(cancellationToken)); + .ToListAsync(cancellationToken); + return Ok(new PagedResult(items, total, page, pageSize)); } [HttpPost] diff --git a/web/src/views/OfficialDocumentsView.vue b/web/src/views/OfficialDocumentsView.vue index 601d374..c1feb3f 100644 --- a/web/src/views/OfficialDocumentsView.vue +++ b/web/src/views/OfficialDocumentsView.vue @@ -94,9 +94,9 @@ async function loadStudents(keyword = '') { if (!isManager.value) return try { const { data } = await http.get('/official-documents/students/options', { - params: { keyword: keyword || undefined }, + params: { keyword: keyword || undefined, page: 1, pageSize: 30 }, }) - students.value = data + students.value = data.items } catch (error) { ElMessage.error(apiErrorMessage(error)) }