feat: 考试和培训可点开明细,考试列表显示是否通过

This commit is contained in:
2026-10-27 05:48:57 +08:00
parent 84772c9f7a
commit d42691aebb
6 changed files with 538 additions and 24 deletions
+160 -7
View File
@@ -1,11 +1,13 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from "vue";
import { NAlert } from "naive-ui";
import { NAlert, NModal } from "naive-ui";
interface ExamItem {
name: string;
status: string;
result: string;
start: string;
detail: string;
}
interface TrainingItem {
@@ -14,6 +16,54 @@ interface TrainingItem {
progress: number;
assigned: string;
credits: string;
detail: string;
}
interface ExamAttempt {
submitted: string;
score: string;
result: string;
}
interface ExamDetail {
total_score: string;
pass_score: string;
questions: string;
window: string;
times: string;
limit: string;
examinee: string;
view_policy: string;
notice: string;
attempts: ExamAttempt[];
}
interface TrainingTask {
name: string;
progress: string;
score: string;
hours: string;
}
interface TrainingPhase {
name: string;
hours: string;
credits: string;
tasks: TrainingTask[];
}
interface TrainingDetail {
owner: string;
earned_hours: string;
actual_hours: string;
reward_hours: string;
earned_credits: string;
actual_credits: string;
reward_credits: string;
rank: string;
progress: string;
deadline: string;
phases: TrainingPhase[];
}
interface HomeProfile {
@@ -35,8 +85,16 @@ const props = defineProps<{ employeeId: string }>();
const profile = ref<HomeProfile | null>(null);
const errorText = ref("");
const loading = ref(false);
const dialogOpen = ref(false);
const dialogTitle = ref("");
const dialogKind = ref<"exam" | "training">("exam");
const examDetail = ref<ExamDetail | null>(null);
const trainingDetail = ref<TrainingDetail | null>(null);
const detailError = ref("");
const detailLoading = ref(false);
let timer = 0;
let requestId = 0;
let detailRequest = 0;
function amount(value: string | number | null | undefined) {
if (value === null || value === undefined || value === "") return "—";
@@ -65,6 +123,38 @@ function trainingMeta(item: TrainingItem) {
return parts.join(" · ");
}
async function openDetail(kind: "exam" | "training", item: { name: string; detail: string }) {
const current = ++detailRequest;
dialogKind.value = kind;
dialogTitle.value = item.name;
examDetail.value = null;
trainingDetail.value = null;
detailError.value = "";
dialogOpen.value = true;
if (!item.detail) {
detailError.value = "明细没有获取到。";
detailLoading.value = false;
return;
}
detailLoading.value = true;
try {
const route = kind === "exam" ? "/api/exam" : "/api/training";
const response = await fetch(`${route}?${new URLSearchParams({ path: item.detail })}`);
const payload = await response.json().catch(() => ({}));
if (current !== detailRequest) return;
if (!response.ok) {
detailError.value = typeof payload.detail === "string" ? payload.detail : "明细没有获取到。";
return;
}
if (kind === "exam") examDetail.value = payload;
else trainingDetail.value = payload;
} catch {
if (current === detailRequest) detailError.value = "明细没有获取到。";
} finally {
if (current === detailRequest) detailLoading.value = false;
}
}
async function load() {
const current = ++requestId;
loading.value = profile.value === null;
@@ -126,11 +216,14 @@ onUnmounted(() => window.clearInterval(timer));
<ol v-else>
<li v-for="item in profile.exams" :key="`${item.start}-${item.name}`" class="event">
<span class="mark" aria-hidden="true"></span>
<div class="event-body">
<button type="button" class="event-hit" @click="openDetail('exam', item)">
<time :datetime="item.start">{{ item.start }}</time>
<strong>{{ item.name }}</strong>
<p class="meta" :class="{ late: item.status === '已过期' }">{{ item.status }}</p>
</div>
<p class="meta">
<span>{{ item.status }}</span>
<span v-if="item.result" :class="item.result === '已通过' ? 'ok' : 'late'">{{ item.result }}</span>
</p>
</button>
</li>
</ol>
</div>
@@ -142,16 +235,76 @@ onUnmounted(() => window.clearInterval(timer));
<ol v-else>
<li v-for="item in profile.trainings" :key="`${item.assigned}-${item.name}`" class="event">
<span class="mark" aria-hidden="true"></span>
<div class="event-body">
<button type="button" class="event-hit" @click="openDetail('training', item)">
<time>{{ item.assigned }}</time>
<strong>{{ item.name }}</strong>
<p class="meta">{{ trainingMeta(item) }}</p>
</div>
<p class="meta"><span>{{ trainingMeta(item) }}</span></p>
</button>
</li>
</ol>
</div>
</section>
</div>
</div>
<n-modal
v-model:show="dialogOpen"
preset="card"
:title="dialogTitle"
:style="{ width: 'min(760px, calc(100vw - 32px))' }"
:content-style="{ maxHeight: '70vh', overflow: 'auto' }"
>
<p v-if="detailLoading" class="home-status">正在获取</p>
<n-alert v-else-if="detailError" type="error">{{ detailError }}</n-alert>
<div v-else-if="dialogKind === 'exam' && examDetail" class="detail">
<p v-if="examDetail.notice" class="detail-notice">{{ examDetail.notice }}</p>
<dl class="detail-facts">
<div><dt>试卷总分</dt><dd>{{ examDetail.total_score }}</dd></div>
<div><dt>合格分数</dt><dd>{{ examDetail.pass_score }}</dd></div>
<div><dt>试卷题数</dt><dd>{{ examDetail.questions }}</dd></div>
<div><dt>考试次数</dt><dd>{{ examDetail.times }}</dd></div>
<div><dt>开考时间</dt><dd>{{ examDetail.window }}</dd></div>
<div><dt>考试时限</dt><dd>{{ examDetail.limit }}</dd></div>
<div><dt>姓名</dt><dd>{{ examDetail.examinee }}</dd></div>
<div><dt>查看答卷</dt><dd>{{ examDetail.view_policy }}</dd></div>
</dl>
<h4>考试历史</h4>
<p v-if="!examDetail.attempts.length" class="home-status">没有考试记录</p>
<table v-else class="detail-table">
<thead>
<tr><th>交卷时间</th><th>考试成绩</th><th>考试结果</th></tr>
</thead>
<tbody>
<tr v-for="attempt in examDetail.attempts" :key="attempt.submitted">
<td>{{ attempt.submitted }}</td>
<td>{{ attempt.score }}</td>
<td :class="attempt.result === '通过' ? 'ok' : 'late'">{{ attempt.result }}</td>
</tr>
</tbody>
</table>
</div>
<div v-else-if="trainingDetail" class="detail">
<dl class="detail-facts">
<div><dt>负责人</dt><dd>{{ trainingDetail.owner || "—" }}</dd></div>
<div><dt>进度</dt><dd>{{ trainingDetail.progress }}</dd></div>
<div><dt>进度排名</dt><dd>{{ trainingDetail.rank }}</dd></div>
<div><dt>要求完成日期</dt><dd>{{ trainingDetail.deadline }}</dd></div>
<div><dt>已获总学时</dt><dd>{{ trainingDetail.earned_hours }}</dd></div>
<div><dt>实际学时</dt><dd>{{ trainingDetail.actual_hours }}</dd></div>
<div><dt>奖励学时</dt><dd>{{ trainingDetail.reward_hours }}</dd></div>
<div><dt>已获总学分</dt><dd>{{ trainingDetail.earned_credits }}</dd></div>
<div><dt>实际学分</dt><dd>{{ trainingDetail.actual_credits }}</dd></div>
<div><dt>奖励学分</dt><dd>{{ trainingDetail.reward_credits }}</dd></div>
</dl>
<section v-for="phase in trainingDetail.phases" :key="phase.name" class="phase">
<h4>{{ phase.name }}<span>{{ phase.hours }} 分钟 · {{ phase.credits }} 学分</span></h4>
<ul>
<li v-for="task in phase.tasks" :key="task.name">
<strong>{{ task.name }}</strong>
<span>{{ task.progress }}<template v-if="task.score"> · {{ task.score }} 学分</template><template v-if="task.hours"> · {{ task.hours }} 分钟</template></span>
</li>
</ul>
</section>
</div>
</n-modal>
</section>
</template>
+119 -8
View File
@@ -532,19 +532,50 @@ select {
background: var(--panel);
}
.event-body {
.event-hit {
min-width: 0;
padding-bottom: 4px;
margin: 0;
padding: 0 0 4px;
border: 0;
background: transparent;
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
}
.event-hit:hover strong {
color: var(--accent);
}
.event time,
.event .meta {
display: block;
.event .meta,
.event .meta span {
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
.event time {
display: block;
}
.event .meta {
display: flex;
gap: 8px;
margin: 2px 0 0;
}
.event .meta span.ok,
.detail-table td.ok {
color: var(--accent);
}
.event .meta span.late,
.detail-table td.late {
color: var(--danger);
}
.event time {
font-variant-numeric: tabular-nums;
}
@@ -558,12 +589,88 @@ select {
overflow-wrap: anywhere;
}
.event .meta {
margin: 2px 0 0;
.detail-notice {
margin: 0 0 12px;
color: var(--danger);
}
.event .meta.late {
color: var(--danger);
.detail-facts {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px 16px;
margin: 0;
}
.detail-facts div {
min-width: 0;
}
.detail-facts dt {
color: var(--muted);
font-size: 12px;
}
.detail-facts dd {
margin: 2px 0 0;
font-variant-numeric: tabular-nums;
overflow-wrap: anywhere;
}
.detail h4 {
margin: 16px 0 8px;
font-size: 14px;
}
.detail-table {
width: 100%;
border-collapse: collapse;
font-variant-numeric: tabular-nums;
}
.detail-table th,
.detail-table td {
padding: 8px 0;
border-bottom: 1px solid var(--line);
text-align: left;
}
.detail-table th {
color: var(--muted);
font-size: 12px;
font-weight: 400;
}
.phase ul {
list-style: none;
margin: 0;
padding: 0;
}
.phase h4 {
display: flex;
justify-content: space-between;
gap: 12px;
}
.phase h4 span,
.phase li span {
color: var(--muted);
font-size: 12px;
font-weight: 400;
}
.phase li {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid var(--line);
}
.phase li strong {
min-width: 0;
font-weight: 650;
overflow-wrap: anywhere;
}
.home-status {
@@ -584,4 +691,8 @@ select {
.facts {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.detail-facts {
grid-template-columns: minmax(0, 1fr);
}
}