From 0bc59bd64e2fb998535b6cec4920d2048c4560e6 Mon Sep 17 00:00:00 2001 From: biss Date: Tue, 11 Aug 2026 11:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E5=87=AD=E8=AF=81=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=EF=BC=9A=20=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=AD=BE=E5=8F=91=E5=BC=B9=E7=AA=97=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=85=A8=E9=87=8F=E5=8A=A0=E8=BD=BD=E5=8F=AF=E8=A7=81=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E3=80=82=20=E9=A6=96=E5=B1=8F=E4=B8=8E=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E8=BF=9C=E7=A8=8B=E6=90=9C=E7=B4=A2=E6=9C=80=E5=A4=9A?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=2030=20=E4=BD=8D=E5=8C=B9=E9=85=8D=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E3=80=82=20=E6=90=9C=E7=B4=A2=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E4=BB=8D=E4=B8=A5=E6=A0=BC=E9=81=B5=E5=BE=AA=E5=AD=A6=E9=99=A2?= =?UTF-8?q?/=E6=A0=A1=E7=BA=A7=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/OfficialDocumentsController.cs | 15 ++++++++++++--- web/src/views/OfficialDocumentsView.vue | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) 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)) }