官方凭证档案优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Jiaowu.Api.Contracts;
|
||||||
using Jiaowu.Api.Domain.Academic;
|
using Jiaowu.Api.Domain.Academic;
|
||||||
using Jiaowu.Api.Domain.Identity;
|
using Jiaowu.Api.Domain.Identity;
|
||||||
using Jiaowu.Api.Infrastructure.Auth;
|
using Jiaowu.Api.Infrastructure.Auth;
|
||||||
@@ -32,15 +33,24 @@ public sealed class OfficialDocumentsController(
|
|||||||
OfficialDocumentType? type,
|
OfficialDocumentType? type,
|
||||||
OfficialDocumentStatus? status,
|
OfficialDocumentStatus? status,
|
||||||
Guid? studentId,
|
Guid? studentId,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken,
|
||||||
|
int page = 1,
|
||||||
|
int pageSize = 20)
|
||||||
{
|
{
|
||||||
|
if (page < 1 || pageSize is < 1 or > 100)
|
||||||
|
return ValidationProblem("页码必须大于 0,且每页条数应在 1 至 100 之间。");
|
||||||
|
|
||||||
var source = AccessibleDocuments().AsNoTracking();
|
var source = AccessibleDocuments().AsNoTracking();
|
||||||
if (type.HasValue) source = source.Where(x => x.Type == type);
|
if (type.HasValue) source = source.Where(x => x.Type == type);
|
||||||
if (status.HasValue) source = source.Where(x => x.Status == status);
|
if (status.HasValue) source = source.Where(x => x.Status == status);
|
||||||
if (studentId.HasValue) source = source.Where(x => x.StudentId == studentId);
|
if (studentId.HasValue) source = source.Where(x => x.StudentId == studentId);
|
||||||
|
|
||||||
return Ok(await source
|
var total = await source.CountAsync(cancellationToken);
|
||||||
|
var items = await source
|
||||||
.OrderByDescending(x => x.IssuedAt)
|
.OrderByDescending(x => x.IssuedAt)
|
||||||
|
.ThenByDescending(x => x.Id)
|
||||||
|
.Skip((page - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
x.Id,
|
x.Id,
|
||||||
@@ -62,7 +72,8 @@ public sealed class OfficialDocumentsController(
|
|||||||
DownloadCount = x.Downloads.Count,
|
DownloadCount = x.Downloads.Count,
|
||||||
LastDownloadedAt = x.Downloads.Max(download => (DateTime?)download.CreatedAt)
|
LastDownloadedAt = x.Downloads.Max(download => (DateTime?)download.CreatedAt)
|
||||||
})
|
})
|
||||||
.ToListAsync(cancellationToken));
|
.ToListAsync(cancellationToken);
|
||||||
|
return Ok(new PagedResult<object>(items, total, page, pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("students/options")]
|
[HttpGet("students/options")]
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ const historyLoading = ref(false)
|
|||||||
const downloadHistory = ref<any[]>([])
|
const downloadHistory = ref<any[]>([])
|
||||||
const selectedDocument = ref<OfficialDocumentRow>()
|
const selectedDocument = ref<OfficialDocumentRow>()
|
||||||
const filters = reactive<{ type?: DocumentType; status?: DocumentStatus }>({})
|
const filters = reactive<{ type?: DocumentType; status?: DocumentStatus }>({})
|
||||||
|
const page = ref(1)
|
||||||
|
const total = ref(0)
|
||||||
|
const pageSize = 20
|
||||||
const issueForm = reactive<{ studentId: string; type: DocumentType; purpose: string }>({
|
const issueForm = reactive<{ studentId: string; type: DocumentType; purpose: string }>({
|
||||||
studentId: '',
|
studentId: '',
|
||||||
type: 'Transcript',
|
type: 'Transcript',
|
||||||
@@ -67,11 +70,19 @@ const statusLabels: Record<DocumentStatus, string> = {
|
|||||||
Superseded: '已重签',
|
Superseded: '已重签',
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load() {
|
async function load(resetPage = false) {
|
||||||
|
if (resetPage) page.value = 1
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const { data } = await http.get('/official-documents', { params: filters })
|
const { data } = await http.get('/official-documents', {
|
||||||
documents.value = data
|
params: { ...filters, page: page.value, pageSize },
|
||||||
|
})
|
||||||
|
documents.value = data.items
|
||||||
|
total.value = data.total
|
||||||
|
if (documents.value.length === 0 && page.value > 1) {
|
||||||
|
page.value--
|
||||||
|
await load()
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ElMessage.error(apiErrorMessage(error))
|
ElMessage.error(apiErrorMessage(error))
|
||||||
} finally {
|
} finally {
|
||||||
@@ -224,14 +235,14 @@ onMounted(load)
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="document-toolbar">
|
<section class="document-toolbar">
|
||||||
<el-select v-model="filters.type" clearable placeholder="全部凭证类型" @change="load">
|
<el-select v-model="filters.type" clearable placeholder="全部凭证类型" @change="load(true)">
|
||||||
<el-option v-for="(label, value) in typeLabels" :key="value" :label="label" :value="value" />
|
<el-option v-for="(label, value) in typeLabels" :key="value" :label="label" :value="value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-select v-model="filters.status" clearable placeholder="全部状态" @change="load">
|
<el-select v-model="filters.status" clearable placeholder="全部状态" @change="load(true)">
|
||||||
<el-option v-for="(label, value) in statusLabels" :key="value" :label="label" :value="value" />
|
<el-option v-for="(label, value) in statusLabels" :key="value" :label="label" :value="value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button :icon="Refresh" @click="load">刷新</el-button>
|
<el-button :icon="Refresh" @click="() => load()">刷新</el-button>
|
||||||
<span>共 {{ documents.length }} 份凭证</span>
|
<span>共 {{ total }} 份凭证</span>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="document-list" v-loading="loading">
|
<section class="document-list" v-loading="loading">
|
||||||
@@ -274,6 +285,15 @@ onMounted(load)
|
|||||||
v-if="!documents.length"
|
v-if="!documents.length"
|
||||||
:description="isManager ? '暂无符合条件的官方凭证' : '暂无电子凭证,可点击上方按钮在线申请'"
|
:description="isManager ? '暂无符合条件的官方凭证' : '暂无电子凭证,可点击上方按钮在线申请'"
|
||||||
/>
|
/>
|
||||||
|
<el-pagination
|
||||||
|
v-if="total > pageSize"
|
||||||
|
v-model:current-page="page"
|
||||||
|
:page-size="pageSize"
|
||||||
|
:total="total"
|
||||||
|
layout="total, prev, pager, next"
|
||||||
|
class="document-pagination"
|
||||||
|
@current-change="() => load()"
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<el-dialog v-model="issueDialog" :title="isManager ? '签发官方凭证' : '申请电子凭证'" width="620px">
|
<el-dialog v-model="issueDialog" :title="isManager ? '签发官方凭证' : '申请电子凭证'" width="620px">
|
||||||
|
|||||||
Reference in New Issue
Block a user