继续优化了官方凭证的学生选择器:
管理员签发弹窗不再全量加载可见学生。 首屏与每次远程搜索最多返回 30 位匹配学生。 搜索范围仍严格遵循学院/校级数据权限。
This commit is contained in:
@@ -80,8 +80,13 @@ public sealed class OfficialDocumentsController(
|
|||||||
[Authorize(Roles = Managers)]
|
[Authorize(Roles = Managers)]
|
||||||
public async Task<ActionResult> StudentOptions(
|
public async Task<ActionResult> StudentOptions(
|
||||||
string? keyword,
|
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();
|
var source = AccessibleStudents().AsNoTracking();
|
||||||
if (!string.IsNullOrWhiteSpace(keyword))
|
if (!string.IsNullOrWhiteSpace(keyword))
|
||||||
{
|
{
|
||||||
@@ -90,7 +95,10 @@ public sealed class OfficialDocumentsController(
|
|||||||
x.StudentNumber.Contains(value) || x.Name.Contains(value));
|
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
|
.Select(x => new
|
||||||
{
|
{
|
||||||
x.Id,
|
x.Id,
|
||||||
@@ -101,7 +109,8 @@ public sealed class OfficialDocumentsController(
|
|||||||
MajorName = x.AdministrativeClass.Major!.Name,
|
MajorName = x.AdministrativeClass.Major!.Name,
|
||||||
CollegeName = x.AdministrativeClass.Major.College!.Name
|
CollegeName = x.AdministrativeClass.Major.College!.Name
|
||||||
})
|
})
|
||||||
.ToListAsync(cancellationToken));
|
.ToListAsync(cancellationToken);
|
||||||
|
return Ok(new PagedResult<object>(items, total, page, pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|||||||
@@ -94,9 +94,9 @@ async function loadStudents(keyword = '') {
|
|||||||
if (!isManager.value) return
|
if (!isManager.value) return
|
||||||
try {
|
try {
|
||||||
const { data } = await http.get('/official-documents/students/options', {
|
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) {
|
} catch (error) {
|
||||||
ElMessage.error(apiErrorMessage(error))
|
ElMessage.error(apiErrorMessage(error))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user