Files
Academic-Affairs-System/web/src/views/GraduationAuditsView.vue
T

325 lines
19 KiB
Vue

<script setup lang="ts">
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { Check, DocumentChecked, Download, Plus, Refresh, Stamp } from '@element-plus/icons-vue'
import http, { apiErrorMessage } from '../api/http'
import { downloadApiFile } from '../api/excel'
import { useAuthStore } from '../stores/auth'
const auth = useAuthStore()
const { locale, t } = useI18n()
const isStudent = computed(() => auth.user?.roles.includes('Student') ?? false)
const isPublisher = computed(() =>
auth.user?.roles.some((role) => ['SuperAdmin', 'AcademicAdmin'].includes(role)) ?? false)
const batches = ref<any[]>([])
const selected = ref<any | null>(null)
const myResult = ref<any | null>(null)
const loading = ref(false)
const createDialog = ref(false)
const decisionDialog = ref(false)
const decisionTarget = ref<any | null>(null)
const keyword = ref('')
const conclusionFilter = ref('')
const grade = ref<number>()
const collegeId = ref('')
const majorId = ref('')
const administrativeClassId = ref('')
const colleges = ref<any[]>([])
const majors = ref<any[]>([])
const classes = ref<any[]>([])
const grades = computed(() => [...new Set(classes.value.map((item: any) => item.grade))].sort((a, b) => b - a))
const filteredMajors = computed(() => majors.value.filter((item: any) => !collegeId.value || item.collegeId === collegeId.value))
const filteredClasses = computed(() => classes.value.filter((item: any) =>
(!grade.value || item.grade === grade.value) &&
(!collegeId.value || filteredMajors.value.some((major: any) => major.id === item.majorId)) &&
(!majorId.value || item.majorId === majorId.value)))
const resultPage = ref(1)
const resultPageSize = 20
const resultRequestId = ref(0)
let filterTimer: ReturnType<typeof setTimeout> | undefined
const batchForm = reactive({
name: '2030届本科生毕业资格审核',
graduationYear: 2030,
enrollmentYear: 2026,
notes: '',
})
const decisionForm = reactive({ conclusion: 'Ineligible', comment: '' })
const statusLabel = (value: string) => t(`graduationAudits.statuses.${value}`)
const conclusionLabel = (value: string) => t(`graduationAudits.conclusions.${value}`)
const resultItems = computed(() => selected.value?.results?.items ?? [])
const resultTotal = computed(() => selected.value?.results?.total ?? 0)
function percent(earned: number, required: number) {
if (!required) return 0
return Math.min(100, Math.round((earned / required) * 100))
}
function dateText(value?: string) {
if (!value) return '—'
return new Intl.DateTimeFormat(locale.value, {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', hour12: false,
}).format(new Date(value))
}
async function load() {
loading.value = true
try {
if (isStudent.value) {
myResult.value = (await http.get('/graduation-audits/my-result')).data
return
}
const [batchResponse, collegeResponse, majorResponse, classResponse] = await Promise.all([
http.get('/graduation-audits/batches'), http.get('/base-data/colleges'), http.get('/base-data/majors'), http.get('/base-data/classes'),
])
batches.value = batchResponse.data; colleges.value = collegeResponse.data; majors.value = majorResponse.data; classes.value = classResponse.data
const batch = batches.value.find((x) => x.id === selected.value?.id) ?? batches.value[0]
if (batch) await selectBatch(batch.id)
else selected.value = null
} catch (error) {
ElMessage.error(apiErrorMessage(error))
} finally {
loading.value = false
}
}
async function selectBatch(id: string) {
resultPage.value = 1
await loadBatch(id)
}
async function loadBatch(id = selected.value?.id) {
if (!id) return
const requestId = ++resultRequestId.value
loading.value = true
try {
const response = await http.get(`/graduation-audits/batches/${id}`, {
params: {
page: resultPage.value,
pageSize: resultPageSize,
keyword: keyword.value.trim() || undefined,
conclusion: conclusionFilter.value || undefined,
grade: grade.value || undefined,
collegeId: collegeId.value || undefined,
majorId: majorId.value || undefined,
administrativeClassId: administrativeClassId.value || undefined,
},
})
if (requestId === resultRequestId.value) selected.value = response.data
} catch (error) {
if (requestId === resultRequestId.value) ElMessage.error(apiErrorMessage(error))
} finally {
if (requestId === resultRequestId.value) loading.value = false
}
}
async function exportRows() { try { await downloadApiFile(`/graduation-audits/batches/${selected.value.id}/export.xlsx`, t('graduationAudits.exportFile'), { params: { keyword: keyword.value.trim() || undefined, conclusion: conclusionFilter.value || undefined, grade: grade.value || undefined, collegeId: collegeId.value || undefined, majorId: majorId.value || undefined, administrativeClassId: administrativeClassId.value || undefined } }); ElMessage.success(t('graduationAudits.messages.exported')) } catch (error) { ElMessage.error(apiErrorMessage(error)) } }
function onCollegeChange() { majorId.value = ''; administrativeClassId.value = '' }
function onMajorChange() { administrativeClassId.value = '' }
async function removeBatch() { try { await ElMessageBox.confirm(t('graduationAudits.messages.deleteConfirm', { name: selected.value.name }), t('graduationAudits.deleteBatch'), { type: 'warning', confirmButtonText: t('graduationAudits.delete') }); await http.delete(`/graduation-audits/batches/${selected.value.id}`); ElMessage.success(t('graduationAudits.messages.deleted')); await load() } catch (error: any) { if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error)) } }
async function createBatch() {
if (!batchForm.name.trim()) return
try {
const response = await http.post('/graduation-audits/batches', batchForm)
createDialog.value = false
await http.post(`/graduation-audits/batches/${response.data.id}/calculate`)
ElMessage.success(t('graduationAudits.messages.created'))
await load()
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function calculate() {
try {
await ElMessageBox.confirm(t('graduationAudits.messages.recalculateConfirm'), t('graduationAudits.recalculateTitle'), {
type: 'warning', confirmButtonText: t('graduationAudits.recalculate'),
})
await http.post(`/graduation-audits/batches/${selected.value.id}/calculate`)
ElMessage.success(t('graduationAudits.messages.recalculationQueued'))
await load()
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
function openDecision(row: any) {
decisionTarget.value = row
decisionForm.conclusion = row.conclusion
decisionForm.comment = row.reviewComment ?? ''
decisionDialog.value = true
}
async function saveDecision() {
if (decisionForm.comment.trim().length < 5) {
ElMessage.warning(t('graduationAudits.messages.commentRequired'))
return
}
try {
await http.put(`/graduation-audits/results/${decisionTarget.value.id}`, decisionForm)
decisionDialog.value = false
ElMessage.success(t('graduationAudits.messages.reviewSaved'))
await loadBatch()
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function publish() {
try {
await ElMessageBox.confirm(
t('graduationAudits.messages.publishConfirm'),
t('graduationAudits.publishTitle'),
{ type: 'warning', confirmButtonText: t('graduationAudits.confirmPublish') },
)
await http.post(`/graduation-audits/batches/${selected.value.id}/publish`)
ElMessage.success(t('graduationAudits.messages.published'))
await load()
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
watch([keyword, conclusionFilter, grade, collegeId, majorId, administrativeClassId], () => {
resultPage.value = 1
if (filterTimer) clearTimeout(filterTimer)
filterTimer = setTimeout(() => loadBatch(), 300)
})
onUnmounted(() => {
if (filterTimer) clearTimeout(filterTimer)
resultRequestId.value++
})
onMounted(load)
</script>
<template>
<div class="page-stack graduation-page">
<section class="page-intro">
<div>
<span class="section-kicker">DEGREE CLEARANCE</span>
<h2>{{ t(isStudent ? 'graduationAudits.studentTitle' : 'graduationAudits.managerTitle') }}</h2>
<p>{{ t(isStudent ? 'graduationAudits.studentDescription' : 'graduationAudits.managerDescription') }}</p>
</div>
<el-button v-if="isPublisher && !isStudent" type="primary" :icon="Plus" @click="createDialog = true">{{ t('graduationAudits.newBatch') }}</el-button>
<el-button v-else :icon="Refresh" @click="load">{{ t('graduationAudits.refresh') }}</el-button>
</section>
<template v-if="isStudent">
<section v-if="myResult" class="graduation-certificate" v-loading="loading">
<header>
<span>OFFICIAL DEGREE CLEARANCE</span>
<i>{{ myResult.graduationYear }}</i>
</header>
<div class="certificate-person">
<div><span>{{ t('graduationAudits.studentName') }}</span><b>{{ myResult.name }}</b></div>
<div><span>{{ t('graduationAudits.studentNumber') }}</span><b>{{ myResult.studentNumber }}</b></div>
<div><span>{{ t('graduationAudits.major') }}</span><b>{{ myResult.majorName }}</b></div>
</div>
<div class="certificate-conclusion" :class="{ eligible: myResult.conclusion === 'Eligible' }">
<el-icon><DocumentChecked /></el-icon>
<div><span>{{ t('graduationAudits.conclusion') }}</span><h3>{{ conclusionLabel(myResult.conclusion) }}</h3><p>{{ myResult.batchName }} · {{ t('graduationAudits.publishedAt', { date: dateText(myResult.publishedAt) }) }}</p></div>
</div>
<div class="certificate-metrics">
<div><span>{{ t('graduationAudits.creditsComplete') }}</span><b>{{ myResult.earnedCredits }} / {{ myResult.requiredCredits }}</b><el-progress :percentage="percent(myResult.earnedCredits, myResult.requiredCredits)" :show-text="false" /></div>
<div><span>{{ t('graduationAudits.requiredCourses') }}</span><b>{{ myResult.passedRequiredCourseCount }} / {{ myResult.requiredCourseCount }}</b><p>{{ t('graduationAudits.completedRequired') }}</p></div>
<div><span>{{ t('graduationAudits.unresolvedFailures') }}</span><b>{{ myResult.failedCourseCount }}</b><p>{{ t('graduationAudits.courses') }}</p></div>
</div>
<footer>
<div><span>{{ t('graduationAudits.missingCourses') }}</span><b>{{ myResult.missingCourseNames || t('graduationAudits.none') }}</b></div>
<div v-if="myResult.reviewComment"><span>{{ t('graduationAudits.reviewComment') }}</span><b>{{ myResult.reviewComment }}</b></div>
</footer>
</section>
<el-empty v-else v-loading="loading" :description="t('graduationAudits.emptyStudent')" />
</template>
<template v-else>
<section class="graduation-batch-strip">
<button v-for="batch in batches" :key="batch.id" :class="{ active: selected?.id === batch.id }" @click="selectBatch(batch.id)">
<span>{{ t('graduationAudits.batchYears', { graduation: batch.graduationYear, enrollment: batch.enrollmentYear }) }}</span>
<b>{{ batch.name }}</b>
<small>{{ t('graduationAudits.batchCounts', { total: batch.resultCount, eligible: batch.eligibleCount }) }}</small>
<i>{{ statusLabel(batch.status) }}</i>
</button>
</section>
<section v-if="selected" class="graduation-workbench" v-loading="loading">
<header>
<div><span>AUDIT REGISTER</span><h3>{{ selected.name }}</h3><p>{{ t(selected.calculationStatus === 'Queued' ? 'graduationAudits.queued' : selected.calculationStatus === 'Running' ? 'graduationAudits.running' : 'graduationAudits.calculatedAt', { date: dateText(selected.calculatedAt) }) }} · {{ t('graduationAudits.ruleBasis') }}</p></div>
<div>
<el-button :icon="Download" @click="exportRows">{{ t('graduationAudits.export') }}</el-button>
<template v-if="selected.status === 'Draft' && isPublisher">
<el-button :icon="Refresh" @click="calculate">{{ t('graduationAudits.recalculate') }}</el-button>
<el-button type="danger" plain @click="removeBatch">{{ t('graduationAudits.deleteBatch') }}</el-button>
<el-button type="primary" :icon="Stamp" @click="publish">{{ t('graduationAudits.publish') }}</el-button>
</template>
<el-tag v-else type="success" effect="plain">{{ t('graduationAudits.locked') }}</el-tag>
</div>
</header>
<div class="graduation-summary">
<div><span>{{ t('graduationAudits.reviewedStudents') }}</span><b>{{ selected.resultCount }}</b><small>{{ t('graduationAudits.people') }}</small></div>
<div><span>{{ t('graduationAudits.eligible') }}</span><b>{{ selected.eligibleCount }}</b><small>{{ t('graduationAudits.people') }}</small></div>
<div><span>{{ t('graduationAudits.ineligible') }}</span><b>{{ selected.ineligibleCount }}</b><small>{{ t('graduationAudits.people') }}</small></div>
<div><span>{{ t('graduationAudits.overrides') }}</span><b>{{ selected.overrideCount }}</b><small>{{ t('graduationAudits.people') }}</small></div>
</div>
<div class="graduation-filter">
<el-input v-model="keyword" clearable :placeholder="t('graduationAudits.searchPlaceholder')" />
<el-select v-model="conclusionFilter" clearable :placeholder="t('graduationAudits.allConclusions')">
<el-option :label="conclusionLabel('Eligible')" value="Eligible" />
<el-option :label="conclusionLabel('Ineligible')" value="Ineligible" />
</el-select>
<el-select v-model="grade" clearable :placeholder="t('graduationAudits.allGrades')"><el-option v-for="item in grades" :key="item" :label="t('graduationAudits.grade', { value: item })" :value="item" /></el-select>
<el-select v-model="collegeId" clearable filterable :placeholder="t('graduationAudits.allColleges')" @change="onCollegeChange"><el-option v-for="item in colleges" :key="item.id" :label="item.name" :value="item.id" /></el-select>
<el-select v-model="majorId" clearable filterable :placeholder="t('graduationAudits.allMajors')" @change="onMajorChange"><el-option v-for="item in filteredMajors" :key="item.id" :label="item.name" :value="item.id" /></el-select>
<el-select v-model="administrativeClassId" clearable filterable :placeholder="t('graduationAudits.allClasses')"><el-option v-for="item in filteredClasses" :key="item.id" :label="`${item.majorName} · ${item.name}`" :value="item.id" /></el-select>
<span>{{ t('graduationAudits.totalRecords', { count: resultTotal }) }}</span>
</div>
<div class="graduation-result-list">
<article v-for="row in resultItems" :key="row.id">
<div class="graduation-student"><span>{{ row.studentNumber }} · {{ row.className }}</span><h4>{{ row.name }}</h4><p>{{ row.majorName }} · {{ row.planName || t('graduationAudits.noPlan') }}</p></div>
<div class="credit-progress"><span>{{ t('graduationAudits.creditProgress') }}</span><b>{{ row.earnedCredits }} / {{ row.requiredCredits }}</b><el-progress :percentage="percent(row.earnedCredits, row.requiredCredits)" :show-text="false" /></div>
<div class="course-clearance"><span>{{ t('graduationAudits.requiredCourses') }}</span><b>{{ row.passedRequiredCourseCount }} / {{ row.requiredCourseCount }}</b><small v-if="row.missingCourseNames">{{ t('graduationAudits.missing', { courses: row.missingCourseNames }) }}</small><small v-else>{{ t('graduationAudits.requirementsComplete') }}</small></div>
<div class="graduation-conclusion" :class="{ eligible: row.conclusion === 'Eligible' }"><el-icon><Check /></el-icon><span>{{ conclusionLabel(row.conclusion) }}</span><small>{{ t(row.isOverridden ? 'graduationAudits.manualReview' : 'graduationAudits.ruleCalculation') }}</small></div>
<el-button v-if="selected.status === 'Draft'" link type="primary" @click="openDecision(row)">{{ t('graduationAudits.manualReview') }}</el-button>
</article>
<el-empty v-if="!resultItems.length" :description="t('graduationAudits.emptyFiltered')" />
<el-pagination
v-if="resultTotal > resultPageSize"
v-model:current-page="resultPage"
:page-size="resultPageSize"
:total="resultTotal"
layout="total, prev, pager, next"
@current-change="loadBatch()"
/>
</div>
</section>
<el-empty v-else v-loading="loading" :description="t('graduationAudits.emptyBatches')" />
</template>
<el-dialog v-model="createDialog" :title="t('graduationAudits.newBatch')" width="620px">
<el-form label-position="top">
<el-form-item :label="t('graduationAudits.batchName')"><el-input v-model="batchForm.name" /></el-form-item>
<div class="form-grid">
<el-form-item :label="t('graduationAudits.graduationYear')"><el-input-number v-model="batchForm.graduationYear" :min="2000" :max="2200" /></el-form-item>
<el-form-item :label="t('graduationAudits.enrollmentYear')"><el-input-number v-model="batchForm.enrollmentYear" :min="2000" :max="2200" /></el-form-item>
</div>
<el-form-item :label="t('graduationAudits.notes')"><el-input v-model="batchForm.notes" type="textarea" :rows="3" /></el-form-item>
</el-form>
<template #footer><el-button @click="createDialog = false">{{ t('graduationAudits.cancel') }}</el-button><el-button type="primary" @click="createBatch">{{ t('graduationAudits.createAndCalculate') }}</el-button></template>
</el-dialog>
<el-dialog v-model="decisionDialog" :title="t('graduationAudits.reviewTitle')" width="620px">
<div v-if="decisionTarget" class="review-target">
<span>{{ decisionTarget.studentNumber }}</span><b>{{ decisionTarget.name }} · {{ decisionTarget.majorName }}</b>
<p>{{ t('graduationAudits.ruleConclusion', { conclusion: conclusionLabel(decisionTarget.calculatedConclusion), earned: decisionTarget.earnedCredits, required: decisionTarget.requiredCredits }) }}</p>
</div>
<el-form label-position="top">
<el-form-item :label="t('graduationAudits.reviewConclusion')">
<el-radio-group v-model="decisionForm.conclusion">
<el-radio-button value="Eligible">{{ conclusionLabel('Eligible') }}</el-radio-button>
<el-radio-button value="Ineligible">{{ conclusionLabel('Ineligible') }}</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item :label="t('graduationAudits.reviewComment')"><el-input v-model="decisionForm.comment" type="textarea" :rows="4" maxlength="500" show-word-limit /></el-form-item>
</el-form>
<template #footer><el-button @click="decisionDialog = false">{{ t('graduationAudits.cancel') }}</el-button><el-button type="primary" @click="saveDecision">{{ t('graduationAudits.saveReview') }}</el-button></template>
</el-dialog>
</div>
</template>