feat: 首页两个清单改为并排时间轴,滚动留在各自列表里
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -82,7 +82,7 @@ function onLogout(key: string) {
|
||||
</div>
|
||||
</div>
|
||||
</n-layout-sider>
|
||||
<n-layout class="content">
|
||||
<n-layout class="content" :native-scrollbar="false" content-style="height: 100%; min-height: 0; overflow: hidden; display: flex; flex-direction: column;">
|
||||
<HomeView v-if="page === 'home'" :employee-id="props.employeeId" />
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
|
||||
+169
-20
@@ -344,24 +344,46 @@ select {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.page .n-data-table {
|
||||
font-variant-numeric: tabular-nums;
|
||||
.content > .n-layout-scroll-container,
|
||||
.content > .n-scrollbar,
|
||||
.content > .n-scrollbar > .n-scrollbar-container {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.page .n-data-table td {
|
||||
white-space: nowrap;
|
||||
.home-page {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.home-page .page-head {
|
||||
flex: none;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.home-page .page-head h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.home {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.home-summary {
|
||||
flex: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.profile {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin-bottom: 16px;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.profile strong,
|
||||
@@ -392,16 +414,17 @@ select {
|
||||
|
||||
.facts {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
margin: 0 0 20px;
|
||||
border-top: 1px solid var(--line);
|
||||
border-left: 1px solid var(--line);
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
gap: 8px 16px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.facts div {
|
||||
padding: 12px 16px;
|
||||
border-right: 1px solid var(--line);
|
||||
border-bottom: 1px solid var(--line);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.facts dt {
|
||||
@@ -410,16 +433,137 @@ select {
|
||||
}
|
||||
|
||||
.facts dd {
|
||||
margin: 6px 0 0;
|
||||
font-size: 22px;
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.03em;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.home h3 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 16px;
|
||||
.boards {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.board {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.board h3 {
|
||||
flex: none;
|
||||
margin: 0;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
font-size: 14px;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.rail {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
padding: 4px 16px 12px;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--line) transparent;
|
||||
}
|
||||
|
||||
.rail:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.rail ol {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.rail-empty {
|
||||
margin: 16px 0 0;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.event {
|
||||
display: grid;
|
||||
grid-template-columns: 12px minmax(0, 1fr);
|
||||
column-gap: 12px;
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.mark {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.mark::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 3px;
|
||||
top: 8px;
|
||||
bottom: -20px;
|
||||
width: 1px;
|
||||
background: var(--muted);
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.event:last-child .mark::before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mark::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 5px;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: 50%;
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.event-body {
|
||||
min-width: 0;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.event time,
|
||||
.event .meta {
|
||||
display: block;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.event time {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.event strong {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-size: 14px;
|
||||
font-weight: 650;
|
||||
line-height: 1.45;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.event .meta {
|
||||
margin: 2px 0 0;
|
||||
}
|
||||
|
||||
.event .meta.late {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.home-status {
|
||||
@@ -432,7 +576,12 @@ select {
|
||||
padding: 16px 12px;
|
||||
}
|
||||
|
||||
.boards {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.facts {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user