feat: 首页两个清单改为并排时间轴,滚动留在各自列表里

This commit is contained in:
2026-10-27 05:23:46 +08:00
parent 41ae8b4f88
commit 060dc60c68
3 changed files with 227 additions and 72 deletions
+57 -51
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from "vue";
import { NAlert, NDataTable } from "naive-ui";
import { NAlert } from "naive-ui";
interface ExamItem {
name: string;
@@ -12,7 +12,6 @@ interface TrainingItem {
name: string;
status: string;
progress: number;
owner: string;
assigned: string;
credits: string;
}
@@ -27,8 +26,6 @@ interface HomeProfile {
month_hours: string;
total_hours: string;
total_score: string;
today_hours: string | number | null;
today_score: string | number | null;
exams: ExamItem[];
trainings: TrainingItem[];
}
@@ -49,31 +46,14 @@ const facts = computed(() => {
{ label: "本月学时", value: current.month_hours },
{ label: "累计学时", value: current.total_hours },
{ label: "累计学分", value: current.total_score },
{ label: "今日学时", value: current.today_hours ?? "—" },
{ label: "今日学分", value: current.today_score ?? "—" },
];
});
const examColumns = [
{ title: "名称", key: "name" },
{ title: "状态", key: "status" },
{ title: "开始", key: "start" },
];
const trainingColumns = [
{ title: "名称", key: "name" },
{ title: "状态", key: "status" },
{ title: "进度", key: "progressText" },
{ title: "学分", key: "credits" },
{ title: "指派", key: "assigned" },
];
const trainingRows = computed(() =>
(profile.value?.trainings || []).map((item) => ({
...item,
progressText: `${item.progress}%`,
})),
);
function trainingMeta(item: TrainingItem) {
const parts = [item.status, `${item.progress}%`];
if (item.credits) parts.push(`${item.credits} 学分`);
return parts.join(" · ");
}
async function load() {
const current = ++requestId;
@@ -104,38 +84,64 @@ onUnmounted(() => window.clearInterval(timer));
</script>
<template>
<section class="page">
<section class="page home-page">
<header class="page-head">
<div>
<h2>首页</h2>
</div>
<h2>首页</h2>
</header>
<n-alert v-if="errorText && !profile" type="error">{{ errorText }}</n-alert>
<p v-else-if="loading" class="home-status">正在获取</p>
<div v-if="profile" class="home">
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
<div class="profile">
<img v-if="profile.avatar" class="avatar" :src="profile.avatar" alt="" referrerpolicy="no-referrer" />
<div v-else class="brand-mark avatar-fallback" aria-hidden="true">{{ profile.name.slice(0, 1) || "E" }}</div>
<div>
<strong>{{ profile.name || props.employeeId }}</strong>
<span>{{ profile.department }}<template v-if="profile.level"> · {{ profile.level }}</template></span>
<n-alert v-if="errorText" type="error">{{ errorText }}</n-alert>
<div class="home-summary">
<div class="profile">
<img v-if="profile.avatar" class="avatar" :src="profile.avatar" alt="" referrerpolicy="no-referrer" />
<div v-else class="brand-mark avatar-fallback" aria-hidden="true">{{ profile.name.slice(0, 1) || "E" }}</div>
<div>
<strong>{{ profile.name || props.employeeId }}</strong>
<span>{{ profile.department }}<template v-if="profile.level"> · {{ profile.level }}</template></span>
</div>
</div>
<dl class="facts">
<div v-for="item in facts" :key="item.label">
<dt>{{ item.label }}</dt>
<dd>{{ item.value }}</dd>
</div>
</dl>
</div>
<div class="boards">
<section class="board" aria-labelledby="exam-heading">
<h3 id="exam-heading">我的考试</h3>
<div class="rail" tabindex="0">
<p v-if="!(profile.exams || []).length" class="rail-empty">没有考试</p>
<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">
<time :datetime="item.start">{{ item.start }}</time>
<strong>{{ item.name }}</strong>
<p class="meta" :class="{ late: item.status === '已过期' }">{{ item.status }}</p>
</div>
</li>
</ol>
</div>
</section>
<section class="board" aria-labelledby="training-heading">
<h3 id="training-heading">线上培训</h3>
<div class="rail" tabindex="0">
<p v-if="!(profile.trainings || []).length" class="rail-empty">没有线上培训</p>
<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">
<time>{{ item.assigned }}</time>
<strong>{{ item.name }}</strong>
<p class="meta">{{ trainingMeta(item) }}</p>
</div>
</li>
</ol>
</div>
</section>
</div>
<dl class="facts">
<div v-for="item in facts" :key="item.label">
<dt>{{ item.label }}</dt>
<dd>{{ item.value }}</dd>
</div>
</dl>
<h3>我的考试</h3>
<n-data-table :columns="examColumns" :data="profile.exams || []" :bordered="false">
<template #empty>没有考试</template>
</n-data-table>
<h3>线上培训</h3>
<n-data-table :columns="trainingColumns" :data="trainingRows" :bordered="false">
<template #empty>没有线上培训</template>
</n-data-table>
</div>
</section>
</template>