feat: 考试和培训可点开明细,考试列表显示是否通过
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user