chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,687 @@
|
||||
<template>
|
||||
<div class="course-detail">
|
||||
<!-- 页头:返回 + 课程信息 + 我的学习状态 -->
|
||||
<header class="detail-header">
|
||||
<div class="detail-title-row">
|
||||
<t-button variant="text" shape="square" class="detail-back" @click="goBack">
|
||||
<template #icon>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m15 18-6-6 6-6"/></svg>
|
||||
</template>
|
||||
</t-button>
|
||||
<t-tag v-if="course" :theme="course.mode === 'online' ? 'primary' : 'success'" variant="light" size="small" :class="{ 'course-tag-offline': course.mode !== 'online' }">
|
||||
{{ course.mode === 'online' ? '线上课程' : '线下课程' }}
|
||||
</t-tag>
|
||||
<h2 class="detail-name">{{ course?.name || '课程详情' }}</h2>
|
||||
<t-tag v-if="course" theme="default" variant="outline" size="small">{{ typeText }}</t-tag>
|
||||
</div>
|
||||
<div class="detail-meta">
|
||||
<span v-if="course">学时 {{ course.hours }}<template v-if="course.credits"> · 学分 {{ course.credits }}</template></span>
|
||||
<span v-if="myTask?.deadline">学习期限:{{ fmtDate(myTask.deadline) }}</span>
|
||||
<t-tag v-if="taskState" :theme="taskTheme" variant="light" size="small">{{ taskState }}</t-tag>
|
||||
<span v-if="progressPercent > 0" class="detail-progress-text">学习进度 {{ progressPercent }}%</span>
|
||||
</div>
|
||||
<div v-if="materials.length" class="detail-bar" :class="progressPercent >= 95 ? 'is-done' : ''">
|
||||
<i :style="{ width: `${progressPercent}%` }"></i>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="detail-body">
|
||||
<!-- 课件列表 -->
|
||||
<aside class="material-list">
|
||||
<div class="material-list__title">课件 ({{ materials.length }})</div>
|
||||
<button
|
||||
v-for="m in materials"
|
||||
:key="m.id"
|
||||
type="button"
|
||||
class="material-item"
|
||||
:class="{ 'is-active': current?.id === m.id }"
|
||||
@click="openMaterial(m)"
|
||||
>
|
||||
<span class="material-item__icon" :class="`kind-${previewKind(m)}`">{{ kindIcon(m) }}</span>
|
||||
<span class="material-item__name" :title="m.name">{{ m.name }}</span>
|
||||
<span class="material-item__percent" :class="{ 'is-done': (progressMap[m.id]?.percent || 0) >= 95 }">
|
||||
{{ progressMap[m.id]?.percent ? `${progressMap[m.id].percent}%` : '' }}
|
||||
</span>
|
||||
</button>
|
||||
<t-empty v-if="!loading && !materials.length" description="暂无课件" class="material-empty" />
|
||||
</aside>
|
||||
|
||||
<!-- 预览区 -->
|
||||
<main class="preview-pane">
|
||||
<t-loading :loading="previewLoading" class="preview-pane__inner" :fullscreen="false">
|
||||
<DocumentPreview
|
||||
v-if="current && docBlob"
|
||||
:source-blob="docBlob"
|
||||
:file-type="previewKind(current)"
|
||||
:file-name="current.name"
|
||||
active
|
||||
fill-height
|
||||
/>
|
||||
<DocumentPreview
|
||||
v-else-if="current && isDoc(current)"
|
||||
:knowledge-id="current.knowledge_id"
|
||||
:file-type="previewKind(current)"
|
||||
:file-name="current.name"
|
||||
active
|
||||
fill-height
|
||||
/>
|
||||
<t-empty
|
||||
v-else-if="current"
|
||||
class="preview-empty"
|
||||
description="该课件未上传文件,请联系培训管理员补传"
|
||||
/>
|
||||
<t-empty v-else class="preview-empty" description="从左侧选择课件开始学习" />
|
||||
</t-loading>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- 随堂考试(开启随堂考试或绑定题库即可考) -->
|
||||
<div v-if="course?.exam_enabled || course?.exam_ready" class="panel-box exam-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">随堂考试</span>
|
||||
<div class="panel-box__actions">
|
||||
<template v-if="examRecord">
|
||||
<span class="exam-score" :class="examPassed ? 'is-good' : 'is-bad'">
|
||||
{{ examRecord.score ?? '—' }} 分
|
||||
<t-tag :theme="examPassed ? 'success' : 'warning'" variant="light" size="small">
|
||||
{{ examPassed ? '已通过' : '未通过' }}
|
||||
</t-tag>
|
||||
</span>
|
||||
<t-button v-if="!examPassed" theme="primary" variant="outline" :loading="examLoading" @click="startExam">
|
||||
重新考试
|
||||
</t-button>
|
||||
</template>
|
||||
<t-button v-else theme="primary" :loading="examLoading" @click="startExam">开始考试</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="exam-hint">考试题目来自课程绑定的题库,及格后完成本课;未通过可反复重考巩固学习。</p>
|
||||
</div>
|
||||
|
||||
<!-- 在线答题(逐题作答:实时统计/题号导航/作答后揭示答案) -->
|
||||
<QuestionExamDialog
|
||||
:visible="takeVisible"
|
||||
:paper="takePaper"
|
||||
:questions="takeQuestions"
|
||||
:submitting="submitting"
|
||||
@update:visible="takeVisible = $event"
|
||||
@submit="onSubmitExam"
|
||||
/>
|
||||
|
||||
<!-- 交卷结果 -->
|
||||
<t-dialog v-model:visible="resultVisible" header="考试结果" width="420">
|
||||
<div class="exam-result">
|
||||
<div class="exam-result__score" :class="resultPassed ? 'is-good' : 'is-bad'">{{ resultScore }}<span>分</span></div>
|
||||
<div class="exam-result__line">
|
||||
及格线 {{ takePaper?.pass_score }} 分 ·
|
||||
<t-tag :theme="resultPassed ? 'success' : 'warning'" variant="light" size="small">
|
||||
{{ resultPassed ? '恭喜通过!' : '未通过,可重新考试' }}
|
||||
</t-tag>
|
||||
</div>
|
||||
<div v-if="wrongCount > 0" class="exam-result__wrong">答错 {{ wrongCount }} 题,已计入错题本,可在「学习与错题」中复习</div>
|
||||
<div class="exam-result__synced">成绩已记录:可在「学习考试 → 我的考试成绩」查看,并计入课程考试状态</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button theme="primary" @click="resultVisible = false">知道了</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import DocumentPreview from '@/components/document-preview.vue'
|
||||
import QuestionExamDialog from './components/QuestionExamDialog.vue'
|
||||
import {
|
||||
downloadMaterialFile,
|
||||
getCourse,
|
||||
getCourseExamPaper,
|
||||
getMyCourseExamRecord,
|
||||
listCourseProgress,
|
||||
listMaterials,
|
||||
listMyLearningTasks,
|
||||
saveLearningProgress,
|
||||
submitExam,
|
||||
unwrap,
|
||||
type LearningTask,
|
||||
type MaterialProgress,
|
||||
type TrainingCourse,
|
||||
type TrainingExamRecord,
|
||||
type TrainingMaterial,
|
||||
type TrainingPaper,
|
||||
type TrainingQuestion,
|
||||
} from '@/api/training'
|
||||
import { resolvePreviewKind } from '@/utils/filePreview'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const courseId = String(route.params.courseId || '')
|
||||
|
||||
const loading = ref(false)
|
||||
const course = ref<TrainingCourse | null>(null)
|
||||
const materials = ref<TrainingMaterial[]>([])
|
||||
const myTask = ref<LearningTask | null>(null)
|
||||
const progressMap = ref<Record<string, MaterialProgress>>({})
|
||||
|
||||
// 预览区状态
|
||||
const current = ref<TrainingMaterial | null>(null)
|
||||
const previewLoading = ref(false)
|
||||
const docBlob = ref<Blob | null>(null)
|
||||
|
||||
// 考试状态
|
||||
const examLoading = ref(false)
|
||||
const examRecord = ref<TrainingExamRecord | null>(null)
|
||||
const examPassed = ref(false)
|
||||
const takeVisible = ref(false)
|
||||
const takePaper = ref<TrainingPaper | null>(null)
|
||||
const takeQuestions = ref<TrainingQuestion[]>([])
|
||||
const submitting = ref(false)
|
||||
const resultVisible = ref(false)
|
||||
const resultScore = ref(0)
|
||||
const resultPassed = ref(false)
|
||||
const wrongCount = ref(0)
|
||||
|
||||
// ---- 课程信息 / 学习状态 ----
|
||||
|
||||
const typeText = computed(() => (course.value?.type === 'elective' ? '选修' : '必修'))
|
||||
|
||||
const taskState = computed(() => {
|
||||
const map: Record<string, string> = { done: '已完成', doing: '学习中', overdue: '已逾期', pending: '待学习' }
|
||||
return myTask.value ? map[myTask.value.status] || '' : ''
|
||||
})
|
||||
const taskTheme = computed(() =>
|
||||
myTask.value?.status === 'done' ? 'success' : myTask.value?.status === 'overdue' ? 'danger' : 'primary')
|
||||
|
||||
// 课程整体进度 = 各课件 percent 的平均(有课件才计算)。
|
||||
const progressPercent = computed(() => {
|
||||
const list = Object.values(progressMap.value)
|
||||
if (!list.length) return 0
|
||||
const sum = list.reduce((n, p) => n + (p.percent || 0), 0)
|
||||
return Math.round(sum / list.length)
|
||||
})
|
||||
|
||||
// ---- 课件预览 ----
|
||||
|
||||
const ext = (name: string) => name.split('.').pop()?.toLowerCase() || ''
|
||||
const previewKind = (m: TrainingMaterial) => {
|
||||
if (m.knowledge_id || m.file_key) return String(resolvePreviewKind(ext(m.name)))
|
||||
return 'unsupported'
|
||||
}
|
||||
const isVideo = (m: TrainingMaterial) => previewKind(m) === 'video' || (!m.knowledge_id && !!m.file_key)
|
||||
const isDoc = (m: TrainingMaterial) => !isVideo(m) && (m.knowledge_id || m.file_key)
|
||||
|
||||
const kindIcon = (m: TrainingMaterial) => {
|
||||
const kind = previewKind(m)
|
||||
if (isVideo(m)) return '▶'
|
||||
const map: Record<string, string> = { pdf: 'PDF', docx: 'DOC', pptx: 'PPT', image: 'IMG', excel: 'XLS', text: 'TXT', markdown: 'MD' }
|
||||
return map[kind] || 'DOC'
|
||||
}
|
||||
|
||||
const stopHeartbeat = () => {
|
||||
if (docTimer) { clearInterval(docTimer); docTimer = null }
|
||||
if (videoTimer) { clearInterval(videoTimer); videoTimer = null }
|
||||
docSeconds = 0
|
||||
docPercentStep = 0
|
||||
}
|
||||
|
||||
// 打开课件:文档带 knowledge_id 时走知识库流(DocumentPreview 自带拉取);
|
||||
// 视频/仅 file_key 的课件统一走课件文件流(blob 播放/渲染)。
|
||||
const openMaterial = async (m: TrainingMaterial) => {
|
||||
if (current.value?.id === m.id) return
|
||||
stopHeartbeat()
|
||||
current.value = m
|
||||
docBlob.value = null
|
||||
if (!m.knowledge_id && !m.file_key) return
|
||||
if (isVideo(m) || !m.knowledge_id) {
|
||||
previewLoading.value = true
|
||||
try {
|
||||
docBlob.value = await downloadMaterialFile(m.id)
|
||||
if (isVideo(m)) bindVideoHeartbeat()
|
||||
} catch {
|
||||
MessagePlugin.error('课件文件加载失败,请稍后重试')
|
||||
current.value = null
|
||||
} finally {
|
||||
previewLoading.value = false
|
||||
}
|
||||
return
|
||||
}
|
||||
startDocHeartbeat(m)
|
||||
}
|
||||
|
||||
// ---- 学习进度心跳 ----
|
||||
// 文档:每 30s 按停留档位上报(30→60→95);视频:每 15s 按播放位置上报。
|
||||
// percent≥95 后端自动完成任务并计积分(SaveLearningProgress)。
|
||||
|
||||
let docTimer: ReturnType<typeof setInterval> | null = null
|
||||
let videoTimer: ReturnType<typeof setInterval> | null = null
|
||||
let docSeconds = 0
|
||||
let docPercentStep = 0
|
||||
const DOC_STEP_SECONDS = 30
|
||||
const DOC_STEP_PERCENTS = [30, 60, 95]
|
||||
|
||||
const reportProgress = async (m: TrainingMaterial, positionSec: number, percent: number) => {
|
||||
if (!myTask.value || !m) return
|
||||
try {
|
||||
await saveLearningProgress(myTask.value.id, m.id, Math.floor(positionSec), Math.min(100, Math.max(0, Math.round(percent))))
|
||||
const prev = progressMap.value[m.id]
|
||||
const merged: MaterialProgress = {
|
||||
material_id: m.id,
|
||||
position_sec: Math.max(positionSec, prev?.position_sec || 0),
|
||||
percent: Math.max(Math.round(percent), prev?.percent || 0),
|
||||
}
|
||||
progressMap.value = { ...progressMap.value, [m.id]: merged }
|
||||
} catch {
|
||||
// 进度上报失败不打断学习,下个心跳再试。
|
||||
}
|
||||
}
|
||||
|
||||
const startDocHeartbeat = (m: TrainingMaterial) => {
|
||||
if (!myTask.value) return
|
||||
docTimer = setInterval(() => {
|
||||
docSeconds += DOC_STEP_SECONDS
|
||||
const step = DOC_STEP_PERCENTS[Math.min(docPercentStep, DOC_STEP_PERCENTS.length - 1)]
|
||||
docPercentStep += 1
|
||||
void reportProgress(m, docSeconds, step)
|
||||
}, DOC_STEP_SECONDS * 1000)
|
||||
}
|
||||
|
||||
const startVideoHeartbeat = (m: TrainingMaterial, videoEl: HTMLVideoElement) => {
|
||||
if (!myTask.value) return
|
||||
videoTimer = setInterval(() => {
|
||||
const pct = videoEl.duration > 0 ? (videoEl.currentTime / videoEl.duration) * 100 : 0
|
||||
void reportProgress(m, videoEl.currentTime, Math.max(pct, 5))
|
||||
}, 15 * 1000)
|
||||
}
|
||||
|
||||
// DocumentPreview 渲染出的 video 元素挂载后接心跳(video 在预览容器内部)。
|
||||
const bindVideoHeartbeat = () => {
|
||||
if (!current.value || !isVideo(current.value)) return
|
||||
const material = current.value
|
||||
const tryBind = (retries: number) => {
|
||||
const el = document.querySelector('.preview-pane video') as HTMLVideoElement | null
|
||||
if (el) {
|
||||
startVideoHeartbeat(material, el)
|
||||
} else if (retries > 0) {
|
||||
setTimeout(() => tryBind(retries - 1), 500)
|
||||
}
|
||||
}
|
||||
tryBind(10)
|
||||
}
|
||||
|
||||
// ---- 随堂考试 ----
|
||||
|
||||
const startExam = async () => {
|
||||
examLoading.value = true
|
||||
try {
|
||||
const data = unwrap<{ paper: TrainingPaper; questions: TrainingQuestion[] }>(await getCourseExamPaper(courseId))
|
||||
if (!data?.paper) throw new Error('no paper')
|
||||
takePaper.value = data.paper
|
||||
takeQuestions.value = data.questions || []
|
||||
takeVisible.value = true
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.data?.message || e?.message
|
||||
MessagePlugin.warning(msg || '取卷失败,该课程可能未绑定题库')
|
||||
} finally {
|
||||
examLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmitExam = async ({ answers }: { answers: Record<string, string> }) => {
|
||||
if (!takePaper.value) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const record = unwrap<TrainingExamRecord>(await submitExam(takePaper.value.id, answers))
|
||||
if (!record) throw new Error('submit failed')
|
||||
const score = record.score ?? 0
|
||||
const passed = takePaper.value.pass_score > 0 ? score >= takePaper.value.pass_score : score >= (takePaper.value.total_score * 0.6)
|
||||
resultScore.value = Math.round(score * 100) / 100
|
||||
resultPassed.value = passed
|
||||
wrongCount.value = record.wrong_question_ids?.length || 0
|
||||
takeVisible.value = false
|
||||
resultVisible.value = true
|
||||
examRecord.value = record
|
||||
examPassed.value = passed
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.data?.message || e?.message
|
||||
MessagePlugin.warning(msg || '交卷失败,请稍后重试')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 加载与生命周期 ----
|
||||
|
||||
const fmtDate = (raw: string | null) => (raw ? new Date(raw).toLocaleDateString() : '')
|
||||
const goBack = () => {
|
||||
if (window.history.length > 1) router.back()
|
||||
else router.push('/platform/training/dashboard')
|
||||
}
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [c, m, t, p, r] = await Promise.all([
|
||||
getCourse(courseId),
|
||||
listMaterials(courseId),
|
||||
listMyLearningTasks().catch(() => null),
|
||||
listCourseProgress(courseId).catch(() => null),
|
||||
getMyCourseExamRecord(courseId).catch(() => null),
|
||||
])
|
||||
course.value = unwrap<TrainingCourse>(c) || null
|
||||
materials.value = unwrap<TrainingMaterial[]>(m) || []
|
||||
const tasks = (t && unwrap<LearningTask[]>(t)) || []
|
||||
myTask.value = tasks.find((task) => task.course_id === courseId) || null
|
||||
const progress = (p && unwrap<MaterialProgress[]>(p)) || []
|
||||
progressMap.value = Object.fromEntries(progress.map((item) => [item.material_id, item]))
|
||||
const exam = r && unwrap<{ record: TrainingExamRecord | null; passed: boolean }>(r)
|
||||
examRecord.value = exam?.record || null
|
||||
examPassed.value = !!exam?.passed
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 切走/关闭页面停心跳,防泄漏。
|
||||
onBeforeUnmount(stopHeartbeat)
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) './training.less';
|
||||
|
||||
.course-detail {
|
||||
.training-page-frame();
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
padding: 4px 0 0;
|
||||
}
|
||||
|
||||
.detail-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.detail-back {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.detail-name {
|
||||
margin: 0;
|
||||
font-size: var(--app-text-xl, 20px);
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.detail-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin: 8px 0 6px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
.detail-progress-text {
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.detail-bar {
|
||||
height: 6px;
|
||||
border-radius: var(--app-radius-pill);
|
||||
background: var(--td-bg-color-component);
|
||||
overflow: hidden;
|
||||
max-width: 480px;
|
||||
|
||||
i {
|
||||
display: block;
|
||||
height: 100%;
|
||||
border-radius: var(--app-radius-pill);
|
||||
background: var(--td-brand-color);
|
||||
transition: width 0.4s ease;
|
||||
}
|
||||
|
||||
&.is-done i {
|
||||
background: var(--td-success-color);
|
||||
}
|
||||
}
|
||||
|
||||
.detail-body {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
// ---- 课件列表 ----
|
||||
|
||||
.material-list {
|
||||
width: 260px;
|
||||
flex-shrink: 0;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 10px;
|
||||
overflow-y: auto;
|
||||
|
||||
&__title {
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
padding: 2px 6px 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.material-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: background var(--app-motion-fast) ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
background: var(--td-brand-color-1, rgba(7, 192, 95, 0.08));
|
||||
|
||||
.material-item__name {
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
&__icon {
|
||||
flex-shrink: 0;
|
||||
min-width: 34px;
|
||||
height: 22px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
|
||||
&.kind-video {
|
||||
color: #fff;
|
||||
background: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
&__name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
&__percent {
|
||||
flex-shrink: 0;
|
||||
font-size: var(--app-text-sm);
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
&.is-done {
|
||||
color: var(--td-success-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.material-empty {
|
||||
padding: 32px 0;
|
||||
}
|
||||
|
||||
// ---- 预览区 ----
|
||||
|
||||
.preview-pane {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 460px;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
overflow: hidden;
|
||||
|
||||
&__inner {
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-empty {
|
||||
padding: 96px 0;
|
||||
}
|
||||
|
||||
// ---- 随堂考试 ----
|
||||
|
||||
.exam-box {
|
||||
.training-panel-box();
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.exam-hint {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
.exam-score {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 600;
|
||||
font-size: var(--app-text-lg);
|
||||
|
||||
&.is-good {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.is-bad {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
}
|
||||
|
||||
.exam-meta {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.take-question {
|
||||
padding: 10px 0;
|
||||
border-top: 1px solid var(--td-component-stroke);
|
||||
|
||||
&__stem {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
&__score {
|
||||
color: var(--td-text-color-placeholder);
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
&__options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
&__opt {
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 交卷结果 ----
|
||||
|
||||
.exam-result {
|
||||
text-align: center;
|
||||
padding: 12px 0;
|
||||
|
||||
&__score {
|
||||
font-size: 44px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
|
||||
span {
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 400;
|
||||
margin-left: 4px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&.is-good {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.is-bad {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
}
|
||||
|
||||
&__line {
|
||||
margin: 10px 0 6px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&__wrong {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
&__synced {
|
||||
margin-top: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,260 @@
|
||||
<template>
|
||||
<div class="training-page">
|
||||
<!-- 页头与知识库/工具箱同构:资源图标 + 当前页签名称 + 角色标签 + 副标题 -->
|
||||
<header class="training-header">
|
||||
<div class="training-title-row">
|
||||
<div class="training-title-group">
|
||||
<h2>
|
||||
<ResourceIcon type="training" :size="24" />
|
||||
{{ activeTabMeta.title }}
|
||||
</h2>
|
||||
<t-tag v-if="myRoleLabel" theme="primary" variant="light">{{ myRoleLabel }}</t-tag>
|
||||
</div>
|
||||
<!-- 工作台视图切换:课程 / 个人成长 / 数据驾驶舱(驾驶舱仅培训管理角色可见) -->
|
||||
<nav v-if="isWorkbench" class="workbench-switch" aria-label="工作台视图切换">
|
||||
<button
|
||||
v-for="t in workbenchSwitchTabs"
|
||||
:key="t.key"
|
||||
type="button"
|
||||
class="workbench-switch__tab"
|
||||
:class="{ 'is-active': workbenchTab === t.key }"
|
||||
:aria-pressed="workbenchTab === t.key"
|
||||
@click="workbenchTab = t.key"
|
||||
>{{ t.label }}</button>
|
||||
</nav>
|
||||
</div>
|
||||
<p class="training-subtitle">{{ activeTabMeta.desc }}</p>
|
||||
</header>
|
||||
|
||||
<!-- 子页(工作台/培训计划/…/配置中心)由侧栏「企业培训」分组导航,此处按路由 tab 参数渲染 -->
|
||||
<t-alert
|
||||
v-if="sessionExpired"
|
||||
class="training-session-alert"
|
||||
theme="warning"
|
||||
message="登录态已失效"
|
||||
description="培训数据未丢失。请重新登录后刷新本页即可查看。"
|
||||
/>
|
||||
<div class="training-body">
|
||||
<!-- 工作台:课程(默认)/个人成长/数据驾驶舱 三视图自由切换 -->
|
||||
<WorkbenchPanel v-if="activeTab === 'dashboard'" :roles="myRoles" :admin="isAdmin" :tab="workbenchTab" />
|
||||
<template v-else-if="activeTab === 'plan'">
|
||||
<PlanPanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
|
||||
<t-empty v-else class="training-empty" description="培训计划仅课长/经理/人事可见" />
|
||||
</template>
|
||||
<template v-else-if="activeTab === 'course'">
|
||||
<CoursePanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
|
||||
<t-empty v-else class="training-empty" description="课程维护仅课长/经理/人事/讲师可见,学员请前往工作台课程目录" />
|
||||
</template>
|
||||
<template v-else-if="activeTab === 'sign'">
|
||||
<SignPanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
|
||||
<t-empty v-else class="training-empty" description="课堂签到仅课长/经理/人事/讲师可见" />
|
||||
</template>
|
||||
<StudyPanel v-else-if="activeTab === 'study'" :roles="myRoles" :admin="isAdmin" />
|
||||
<template v-else-if="activeTab === 'members'">
|
||||
<MemberPanel v-if="isAdmin" />
|
||||
<t-empty v-else class="training-empty" description="职称角色维护仅人事可见" />
|
||||
</template>
|
||||
<template v-else-if="activeTab === 'rules'">
|
||||
<RulePanel v-if="isAdmin" />
|
||||
<t-empty v-else class="training-empty" description="配置中心仅人事可见" />
|
||||
</template>
|
||||
<WorkbenchPanel v-else :roles="myRoles" :admin="isAdmin" :tab="workbenchTab" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import ResourceIcon from '@/components/icons/ResourceIcon.vue'
|
||||
import WorkbenchPanel from './components/WorkbenchPanel.vue'
|
||||
import PlanPanel from './components/PlanPanel.vue'
|
||||
import CoursePanel from './components/CoursePanel.vue'
|
||||
import SignPanel from './components/SignPanel.vue'
|
||||
import MemberPanel from './components/MemberPanel.vue'
|
||||
import StudyPanel from './components/StudyPanel.vue'
|
||||
import RulePanel from './components/RulePanel.vue'
|
||||
import { expandRoles, fetchRoleDict, getMyProfile, roleLabelOf, type TrainingMember, type TrainingRoleDef } from '@/api/training'
|
||||
|
||||
// 与侧栏「企业培训」分组文案一致;title 同时用于页头显示当前页签名
|
||||
const TRAINING_TABS_META: Record<string, { title: string; desc: string }> = {
|
||||
dashboard: { title: '工作台', desc: '培训运营总览、待办与达成率一览' },
|
||||
plan: { title: '培训计划', desc: '年度培训需求收集与汇总(可切换年度)' },
|
||||
course: { title: '培训课程', desc: '课程资产库、场次安排与学员名单;课件自动同步知识库' },
|
||||
sign: { title: '课堂签到', desc: '签到码生成、签到明细复核与佐证导出' },
|
||||
study: { title: '学习考试', desc: '我的课程学习、课程学习情况、课程考试情况与 AI 课程分析' },
|
||||
members: { title: '职称角色', desc: '名册来自「组织架构」,此处维护员工职称角色' },
|
||||
rules: { title: '配置中心', desc: '培训业务规则在线配置,改配置不改代码' },
|
||||
}
|
||||
|
||||
const TRAINING_TAB_KEYS = Object.keys(TRAINING_TABS_META)
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const rawRoles = ref<string[]>([])
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// 职称角色字典(配置中心可配);myRoles = 实际分配角色按「权限分配」传递展开后的
|
||||
// 权限并集 —— 各子页既有 canXxx 判断因此对自定义角色自动生效,无需逐一修改。
|
||||
const roleDict = ref<TrainingRoleDef[]>([])
|
||||
const myRoles = computed(() => expandRoles(rawRoles.value, roleDict.value))
|
||||
fetchRoleDict().then((d) => {
|
||||
roleDict.value = d
|
||||
})
|
||||
|
||||
// 空间 Admin/Owner 视同培训管理角色(与后端 requireRoles 的 bypass 一致),
|
||||
// 保证冷启动时管理员即可进入职称角色/配置中心子页完成首批授权。
|
||||
// 职称角色/配置中心为人事专属(角色体系 v2)。
|
||||
const isAdmin = computed(() =>
|
||||
myRoles.value.some((r) => r === 'hr') ||
|
||||
authStore.hasRole('admin'))
|
||||
|
||||
// 培训管理页签(培训计划/培训课程/课堂签到)门槛:课长/经理/人事/讲师
|
||||
// (myRoles 已按权限组展开,自定义角色继承系统角色后自动生效)。
|
||||
const canManageTabs = computed(() =>
|
||||
isAdmin.value ||
|
||||
myRoles.value.some((r) => ['hr', 'supervisor', 'exec', 'lecturer'].includes(r)))
|
||||
|
||||
// 页头角色标签:展示实际分配的角色(非权限展开),文案取自配置中心字典
|
||||
const myRoleLabel = computed(() =>
|
||||
rawRoles.value.map((r) => roleLabelOf(r, roleDict.value)).join(' / '))
|
||||
|
||||
// 当前子页:取路由 tab 参数;非法值回退工作台(不动路由,避免与侧栏高亮脱节)
|
||||
const activeTab = computed(() => {
|
||||
const tab = String(route.params.tab || 'dashboard')
|
||||
// 旧页签合并兼容:exam/learning → study
|
||||
if (tab === 'exam' || tab === 'learning') return 'study'
|
||||
return TRAINING_TAB_KEYS.includes(tab) ? tab : 'dashboard'
|
||||
})
|
||||
|
||||
const activeTabMeta = computed(() => {
|
||||
// 工作台三视图:页头标题/副标题跟随当前视图(课程视图与设计稿一致使用「培训课程」)
|
||||
if (activeTab.value === 'dashboard') {
|
||||
if (workbenchTab.value === 'course') return { title: '培训课程', desc: '课件/题库上传后自动同步知识库,可对话问答' }
|
||||
if (workbenchTab.value === 'growth') return { title: '工作台', desc: '个人成长进阶 · 能力模型与成就任务总览' }
|
||||
return TRAINING_TABS_META.dashboard
|
||||
}
|
||||
return TRAINING_TABS_META[activeTab.value]
|
||||
})
|
||||
|
||||
// ---- 工作台三视图切换 ----
|
||||
// 课程 / 个人成长全员可见;数据驾驶舱仅培训管理角色可见(普通员工隐藏入口)。
|
||||
type WorkbenchView = 'course' | 'growth' | 'dashboard'
|
||||
const workbenchTab = ref<WorkbenchView>('course')
|
||||
|
||||
const canSeeWorkbenchDashboard = computed(
|
||||
() => isAdmin.value || myRoles.value.some((r) => r === 'hr' || r === 'supervisor' || r === 'exec'),
|
||||
)
|
||||
|
||||
const workbenchSwitchTabs = computed(() => {
|
||||
const list: { key: WorkbenchView; label: string }[] = [
|
||||
{ key: 'course', label: '课程' },
|
||||
{ key: 'growth', label: '个人成长' },
|
||||
]
|
||||
if (canSeeWorkbenchDashboard.value) list.push({ key: 'dashboard', label: '数据驾驶舱' })
|
||||
return list
|
||||
})
|
||||
|
||||
const isWorkbench = computed(() => activeTab.value === 'dashboard')
|
||||
|
||||
// 角色异步加载后若驾驶舱入口被收回,视图回落课程目录
|
||||
watch(canSeeWorkbenchDashboard, (ok) => {
|
||||
if (!ok && workbenchTab.value === 'dashboard') workbenchTab.value = 'course'
|
||||
})
|
||||
|
||||
// 会话失效标记:401 时组件层不再静默降级为「学员」空态(会被误读成数据丢失),
|
||||
// 而是明确提示重新登录;跳转由 request.ts 的 401 拦截器统一负责。
|
||||
const sessionExpired = ref(false)
|
||||
|
||||
const loadProfile = async () => {
|
||||
try {
|
||||
const res = await getMyProfile() as any
|
||||
sessionExpired.value = false
|
||||
// 兼容两种封包:拦截器解包后 {success, data}(res.data 即 member)
|
||||
const member: TrainingMember | undefined = res?.data?.data || res?.data
|
||||
if (member) {
|
||||
rawRoles.value = (member.roles as unknown as string[]) || ['trainee']
|
||||
}
|
||||
} catch (e: any) {
|
||||
const status = e?.response?.status || e?.data?.status
|
||||
if (status === 401) {
|
||||
sessionExpired.value = true
|
||||
rawRoles.value = []
|
||||
MessagePlugin.warning('登录态已失效,请重新登录后查看培训数据')
|
||||
} else {
|
||||
rawRoles.value = ['trainee']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadProfile()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) './training.less';
|
||||
|
||||
.training-page {
|
||||
.training-page-frame();
|
||||
}
|
||||
|
||||
.training-header {
|
||||
.training-header();
|
||||
}
|
||||
|
||||
// 工作台视图切换页签:右对齐文本页签,激活态品牌色加粗
|
||||
.workbench-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 28px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&__tab {
|
||||
position: relative;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
padding: 4px 2px;
|
||||
font: inherit;
|
||||
font-size: var(--app-text-lg);
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-secondary);
|
||||
cursor: pointer;
|
||||
transition: color var(--app-motion-fast) ease;
|
||||
|
||||
&:hover {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: 2px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.training-session-alert {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.training-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: var(--app-space-3) 0 var(--app-space-6);
|
||||
}
|
||||
|
||||
.training-empty {
|
||||
padding: 64px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,347 @@
|
||||
<template>
|
||||
<div class="ai-analysis-panel">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">AI课程分析</span>
|
||||
<div class="panel-box__actions">
|
||||
<t-select
|
||||
v-if="canAggregate"
|
||||
v-model="courseId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="全部课程(汇总)"
|
||||
style="width: 280px"
|
||||
:loading="courseLoading"
|
||||
>
|
||||
<t-option label="全部课程(汇总)" value="" />
|
||||
<t-option v-for="c in courses" :key="c.id" :value="c.id" :label="c.name" />
|
||||
</t-select>
|
||||
<t-button theme="primary" :loading="generating" @click="generate">
|
||||
{{ generating ? 'AI 分析中…' : (result ? '重新分析' : '生成 AI 分析') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="ai-hint">
|
||||
汇总{{ scopeHint }}的课程学习、考试成绩、课堂签到与错题情况,由大模型生成本次分析报告与指导建议。
|
||||
分析约需数十秒,请耐心等待。
|
||||
</p>
|
||||
|
||||
<!-- 统计指标卡(与报告同源,来自后端聚合) -->
|
||||
<div v-if="result" class="metric-grid">
|
||||
<div class="metric-card">
|
||||
<div class="metric-card__label">学习完成率</div>
|
||||
<div class="metric-card__value" :class="metricTone(result.stats.learning.completion_rate)">
|
||||
{{ Math.round(result.stats.learning.completion_rate) }}%
|
||||
</div>
|
||||
<div class="metric-card__sub">已完成 {{ result.stats.learning.done }}/{{ result.stats.learning.total }}<template v-if="result.stats.learning.overdue"> · 逾期 {{ result.stats.learning.overdue }}</template></div>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<div class="metric-card__label">考试及格率</div>
|
||||
<div class="metric-card__value" :class="metricTone(result.stats.exam.pass_rate)">
|
||||
{{ Math.round(result.stats.exam.pass_rate) }}%
|
||||
</div>
|
||||
<div class="metric-card__sub">及格 {{ result.stats.exam.passed }}/已考 {{ result.stats.exam.taken }} · 均分 {{ result.stats.exam.avg_score }}</div>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<div class="metric-card__label">签到出勤率</div>
|
||||
<div class="metric-card__value" :class="metricTone(signRate)">
|
||||
{{ Math.round(signRate) }}%
|
||||
</div>
|
||||
<div class="metric-card__sub">实到 {{ result.stats.sign.signed }}/应到 {{ result.stats.sign.expected }}<template v-if="result.stats.sign.late"> · 迟到 {{ result.stats.sign.late }}</template></div>
|
||||
</div>
|
||||
<div class="metric-card metric-card--wide">
|
||||
<div class="metric-card__label">薄弱知识点 Top{{ result.stats.wrong_questions.length || '—' }}</div>
|
||||
<div v-if="result.stats.wrong_questions.length" class="metric-card__weak-list">
|
||||
<t-tag v-for="w in result.stats.wrong_questions" :key="w.knowledge_point" theme="danger" variant="light" size="small">
|
||||
{{ w.knowledge_point }} · 错 {{ w.wrong_count }} 次
|
||||
</t-tag>
|
||||
</div>
|
||||
<div v-else class="metric-card__sub">暂无错题数据</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 分析报告 -->
|
||||
<div v-if="result" class="report">
|
||||
<div class="report__meta">
|
||||
<t-tag theme="primary" variant="light">{{ scopeLabel }}</t-tag>
|
||||
<t-tag v-if="result.model_name === 'rule-fallback'" theme="warning" variant="light">规则引擎版</t-tag>
|
||||
<span v-if="result.model_name === 'rule-fallback' && result.fallback_reason" class="report__fallback">{{ result.fallback_reason }}</span>
|
||||
<span v-else-if="result.model_name" class="report__model">{{ result.model_name }}</span>
|
||||
<span class="report__time">生成于 {{ fmtTime(result.generated_at) }}</span>
|
||||
<t-button variant="text" size="small" class="report__copy" @click="copyReport">复制报告</t-button>
|
||||
</div>
|
||||
<!-- eslint-disable-next-line vue/no-v-html -- sanitizeHTML 已消毒 -->
|
||||
<div class="report__body" v-html="analysisHtml"></div>
|
||||
</div>
|
||||
|
||||
<div v-if="generating" class="generating">
|
||||
<t-loading size="small" text="正在聚合学习/考试/签到/错题数据并调用大模型分析…" show-overlay />
|
||||
</div>
|
||||
<t-empty v-else-if="!result" description="点击「生成 AI 分析」获取汇总分析与指导建议" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { marked } from 'marked'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { sanitizeHTML } from '@/utils/security'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import {
|
||||
getCourseAIAnalysis,
|
||||
listCourses,
|
||||
type TrainingAIAnalysis,
|
||||
type TrainingCourse,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
|
||||
// AI课程分析:后端聚合学习/考试/签到/错题统计,交租户默认对话模型出
|
||||
// markdown 报告;管理角色为全员维度(全部课程/按课程聚焦),学员为个人维度。
|
||||
// 未配置模型时后端回退规则引擎摘要(model_name=rule-fallback)。
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
// 全员维度分析:人事/课长/讲师(roles 已按权限组展开,经理自动命中)
|
||||
const canAggregate = computed(() => props.admin || props.roles.some((r) => ['hr', 'supervisor', 'lecturer'].includes(r)))
|
||||
|
||||
const courses = ref<TrainingCourse[]>([])
|
||||
const courseLoading = ref(false)
|
||||
const courseId = ref('')
|
||||
const generating = ref(false)
|
||||
const result = ref<TrainingAIAnalysis | null>(null)
|
||||
|
||||
const scopeHint = computed(() =>
|
||||
canAggregate.value ? '(选择课程可聚焦分析,默认汇总全部课程)' : '个人',
|
||||
)
|
||||
const scopeLabel = computed(() => {
|
||||
if (!result.value) return ''
|
||||
if (result.value.scope === 'personal') return '个人维度'
|
||||
return result.value.scope === 'course' ? `课程:${result.value.course_name}` : '全部课程'
|
||||
})
|
||||
|
||||
const analysisHtml = computed(() => {
|
||||
if (!result.value?.analysis) return ''
|
||||
try {
|
||||
return sanitizeHTML(marked.parse(result.value.analysis, { async: false }) as string)
|
||||
} catch {
|
||||
return `<pre>${result.value.analysis}</pre>`
|
||||
}
|
||||
})
|
||||
|
||||
const signRate = computed(() => {
|
||||
const s = result.value?.stats.sign
|
||||
if (!s || s.expected <= 0) return 0
|
||||
return Math.min((s.signed / s.expected) * 100, 100)
|
||||
})
|
||||
|
||||
const metricTone = (rate: number) => (rate >= 80 ? 'tone-good' : rate >= 60 ? 'tone-warn' : 'tone-bad')
|
||||
|
||||
const fmtTime = (raw: string) => fmtBeijingTime(raw) || raw
|
||||
|
||||
// 区分失败原因给出可行动提示:超时(大模型长耗时)/接口不存在(后端未更新)/后端具体错误
|
||||
const aiErrorMessage = (e: any): string => {
|
||||
if (e?.code === 'ECONNABORTED' || /timeout/i.test(e?.message || '')) {
|
||||
return '生成超时:大模型响应较慢,请重试,或改选单门课程聚焦分析'
|
||||
}
|
||||
if (e?.response?.status === 404) {
|
||||
return 'AI 分析接口不存在,请确认后端服务已更新并重启'
|
||||
}
|
||||
return e?.response?.data?.message || 'AI 分析失败,请稍后重试'
|
||||
}
|
||||
|
||||
const generate = async () => {
|
||||
generating.value = true
|
||||
try {
|
||||
const res = await getCourseAIAnalysis(courseId.value || undefined)
|
||||
const data = unwrap(res)
|
||||
if (data) {
|
||||
result.value = data
|
||||
if (data.model_name !== 'rule-fallback') {
|
||||
MessagePlugin.success('AI 分析报告已生成')
|
||||
} else if (data.fallback_reason && !data.fallback_reason.includes('未配置')) {
|
||||
// 模型存在但调用失败(网络/鉴权/超时等),给出后端带回的具体原因
|
||||
MessagePlugin.error(`大模型调用失败:${data.fallback_reason.replace(/^大模型调用失败:/, '')}。本次为规则引擎版摘要,请检查模型服务的网络与配置`)
|
||||
} else {
|
||||
MessagePlugin.warning('未配置可用大模型,本次为规则引擎版摘要;请在「模型管理」配置后重试')
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(aiErrorMessage(e))
|
||||
} finally {
|
||||
generating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const copyReport = async () => {
|
||||
if (!result.value?.analysis) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(result.value.analysis)
|
||||
MessagePlugin.success('报告已复制到剪贴板')
|
||||
} catch {
|
||||
MessagePlugin.error('复制失败,请手动选择文本复制')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!canAggregate.value) return
|
||||
courseLoading.value = true
|
||||
try {
|
||||
const res = await listCourses({ page_size: 100 })
|
||||
courses.value = (unwrap(res)?.items || []).filter((c: TrainingCourse) => c.status === 'published')
|
||||
} catch {
|
||||
courses.value = []
|
||||
} finally {
|
||||
courseLoading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
}
|
||||
|
||||
.ai-hint {
|
||||
margin: 0 0 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
// 统计指标卡
|
||||
.metric-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.metric-card {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 12px 14px;
|
||||
|
||||
&--wide {
|
||||
grid-column: span 3;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-column: span 1;
|
||||
}
|
||||
}
|
||||
|
||||
&__label {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
&__value {
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
&__sub {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
&__weak-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
// 报告区
|
||||
.report {
|
||||
border-top: 1px solid var(--td-component-stroke);
|
||||
padding-top: 12px;
|
||||
|
||||
&__meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
&__model {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&__fallback {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
|
||||
&__time {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
// markdown 报告排版(紧凑版式,标题/列表/段落层级清晰)
|
||||
&__body {
|
||||
:deep(h1),
|
||||
:deep(h2),
|
||||
:deep(h3) {
|
||||
margin: 14px 0 8px;
|
||||
font-size: var(--app-text-lg);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(h1:first-child),
|
||||
:deep(h2:first-child),
|
||||
:deep(h3:first-child) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
:deep(p) {
|
||||
margin: 6px 0;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
:deep(ul),
|
||||
:deep(ol) {
|
||||
margin: 6px 0;
|
||||
padding-left: 22px;
|
||||
|
||||
li {
|
||||
margin: 4px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(strong) {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(table) {
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
|
||||
th,
|
||||
td {
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
padding: 4px 10px;
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.generating {
|
||||
padding: 32px 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.tone-good { color: var(--td-success-color); }
|
||||
.tone-warn { color: var(--td-warning-color); }
|
||||
.tone-bad { color: var(--td-error-color); }
|
||||
</style>
|
||||
@@ -0,0 +1,242 @@
|
||||
<template>
|
||||
<div class="cls-panel">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">课程学习情况</span>
|
||||
<t-select
|
||||
v-model="courseId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择课程查看全员学习进度"
|
||||
style="width: 320px"
|
||||
:loading="courseLoading"
|
||||
@change="loadTasks"
|
||||
>
|
||||
<t-option v-for="c in courses" :key="c.id" :value="c.id" :label="c.name" />
|
||||
</t-select>
|
||||
</div>
|
||||
|
||||
<!-- 状态汇总(列表唯一口径:课程+学员一条任务行) -->
|
||||
<div v-if="rows.length" class="learn-stats">
|
||||
<div class="learn-stat">
|
||||
<span class="learn-stat__num">{{ rows.length }}</span>
|
||||
<span class="learn-stat__label">总人数</span>
|
||||
</div>
|
||||
<div class="learn-stat">
|
||||
<span class="learn-stat__num tone-good">{{ stats.done }}</span>
|
||||
<span class="learn-stat__label">已完成</span>
|
||||
</div>
|
||||
<div class="learn-stat">
|
||||
<span class="learn-stat__num">{{ stats.doing }}</span>
|
||||
<span class="learn-stat__label">学习中</span>
|
||||
</div>
|
||||
<div class="learn-stat">
|
||||
<span class="learn-stat__num">{{ stats.pending }}</span>
|
||||
<span class="learn-stat__label">待学习</span>
|
||||
</div>
|
||||
<div class="learn-stat">
|
||||
<span class="learn-stat__num tone-bad">{{ stats.overdue }}</span>
|
||||
<span class="learn-stat__label">已逾期</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 条件查询:部门 / 关键词(工号·岗位) / 状态 -->
|
||||
<div v-if="rows.length" class="query-bar">
|
||||
<t-select v-model="filters.dept" clearable placeholder="部门" style="width: 150px">
|
||||
<t-option v-for="d in deptOptions" :key="d" :value="d" :label="d" />
|
||||
</t-select>
|
||||
<t-input v-model="filters.keyword" clearable placeholder="工号 / 岗位" style="width: 180px">
|
||||
<template #searchIcon><SearchIcon /></template>
|
||||
</t-input>
|
||||
<t-select v-model="filters.status" clearable placeholder="状态" style="width: 120px">
|
||||
<t-option label="待学习" value="pending" />
|
||||
<t-option label="学习中" value="doing" />
|
||||
<t-option label="已完成" value="done" />
|
||||
<t-option label="已逾期" value="overdue" />
|
||||
</t-select>
|
||||
<t-button variant="text" theme="primary" :disabled="!hasFilter" @click="resetFilters">重置</t-button>
|
||||
<span class="query-bar__hit">共 {{ filteredRows.length }} 条</span>
|
||||
</div>
|
||||
|
||||
<t-table
|
||||
:data="filteredRows"
|
||||
:columns="learnColumns"
|
||||
row-key="id"
|
||||
size="small"
|
||||
:loading="taskLoading"
|
||||
>
|
||||
<template #member="{ row }">
|
||||
{{ [row.employee_no, row.post].filter(Boolean).join(' ') || row.member_id.slice(0, 8) }}
|
||||
</template>
|
||||
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
|
||||
<template #deadline="{ row }">{{ fmtTime(row.deadline) }}</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="taskTheme(row.status)" variant="light" size="small">{{ taskText(row.status) }}</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!courseId" description="选择课程后查看该课程全员学习进度" />
|
||||
<t-empty v-else-if="!taskLoading && !rows.length" description="该课程暂无学习任务" />
|
||||
<t-empty v-else-if="rows.length && !filteredRows.length" description="没有符合查询条件的记录" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { SearchIcon } from 'tdesign-icons-vue-next'
|
||||
import {
|
||||
listCourses,
|
||||
listCourseLearningTasks,
|
||||
type CourseLearningTask,
|
||||
type TrainingCourse,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
|
||||
// 课程学习情况(管理端):列表按课程+学员唯一(后端 tr_learning_tasks
|
||||
// 以 tenant+course+member 唯一索引约束),上方为各状态汇总,支持条件查询。
|
||||
// initialCourseId:培训课程页「学习状态」列跳转时预选的课程。
|
||||
const props = defineProps<{ initialCourseId?: string }>()
|
||||
|
||||
const courses = ref<TrainingCourse[]>([])
|
||||
const courseLoading = ref(false)
|
||||
const courseId = ref('')
|
||||
const taskLoading = ref(false)
|
||||
const rows = ref<CourseLearningTask[]>([])
|
||||
|
||||
watch(
|
||||
() => props.initialCourseId,
|
||||
(id) => {
|
||||
if (id && id !== courseId.value && courses.value.some((c) => c.id === id)) {
|
||||
courseId.value = id
|
||||
loadTasks()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const filters = reactive({ dept: '', keyword: '', status: '' })
|
||||
const hasFilter = computed(() => Boolean(filters.dept || filters.keyword || filters.status))
|
||||
|
||||
const learnColumns = [
|
||||
{ colKey: 'member', title: '员工' },
|
||||
{ colKey: 'dept_name', title: '部门', width: 110 },
|
||||
{ colKey: 'deadline', title: '完成期限', width: 150 },
|
||||
{ colKey: 'status', title: '状态', width: 90 },
|
||||
]
|
||||
|
||||
const taskText = (s: string) => ({ pending: '待学习', doing: '学习中', done: '已完成', overdue: '已逾期' }[s] || s)
|
||||
const taskTheme = (s: string) => ({ pending: 'default', doing: 'primary', done: 'success', overdue: 'danger' }[s] || 'default')
|
||||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
|
||||
|
||||
const stats = computed(() => {
|
||||
const count = (s: string) => rows.value.filter((t) => t.status === s).length
|
||||
return { done: count('done'), doing: count('doing'), pending: count('pending'), overdue: count('overdue') }
|
||||
})
|
||||
|
||||
// 部门下拉从当前课程名单去重生成(行上带的是联查展示字段 dept_name)
|
||||
const deptOptions = computed(() =>
|
||||
[...new Set(rows.value.map((r) => r.dept_name).filter(Boolean))].sort(),
|
||||
)
|
||||
|
||||
const filteredRows = computed(() => {
|
||||
const kw = filters.keyword.trim().toLowerCase()
|
||||
return rows.value.filter((r) => {
|
||||
if (filters.dept && (r.dept_name || '') !== filters.dept) return false
|
||||
if (filters.status && r.status !== filters.status) return false
|
||||
if (kw) {
|
||||
const text = `${r.employee_no || ''} ${r.post || ''}`.toLowerCase()
|
||||
if (!text.includes(kw)) return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.dept = ''
|
||||
filters.keyword = ''
|
||||
filters.status = ''
|
||||
}
|
||||
|
||||
const loadTasks = async () => {
|
||||
resetFilters()
|
||||
if (!courseId.value) {
|
||||
rows.value = []
|
||||
return
|
||||
}
|
||||
taskLoading.value = true
|
||||
try {
|
||||
const res = await listCourseLearningTasks(courseId.value)
|
||||
rows.value = unwrap(res) || []
|
||||
} catch {
|
||||
rows.value = []
|
||||
} finally {
|
||||
taskLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
courseLoading.value = true
|
||||
try {
|
||||
const res = await listCourses({ page_size: 100 })
|
||||
courses.value = (unwrap(res)?.items || []).filter((c: TrainingCourse) => c.status === 'published')
|
||||
// 优先聚焦培训课程页跳转指定的课程,否则默认第一个课程(进页即可看数据)
|
||||
const preset = props.initialCourseId
|
||||
const target = (preset && courses.value.find((c) => c.id === preset)) || courses.value[0]
|
||||
if (target) {
|
||||
courseId.value = target.id
|
||||
loadTasks()
|
||||
}
|
||||
} finally {
|
||||
courseLoading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
}
|
||||
|
||||
// 状态汇总:大数字 + 配色(已完成绿/已逾期红,同原型)
|
||||
.learn-stats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 24px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.learn-stat {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
|
||||
&__num {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
&__label {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
// 条件查询栏(同培训计划页 demand-search 模式)
|
||||
.query-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
&__hit {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.tone-good { color: var(--td-success-color); }
|
||||
.tone-bad { color: var(--td-error-color); }
|
||||
</style>
|
||||
@@ -0,0 +1,230 @@
|
||||
<template>
|
||||
<div class="dash-panel">
|
||||
<!-- 人事工作台 -->
|
||||
<template v-if="showHr">
|
||||
<div class="stat-cards">
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">年度需求收集</div>
|
||||
<div class="stat-card__value">{{ hrData.demand_progress?.length || 0 }} 部门</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">年度课程总数</div>
|
||||
<div class="stat-card__value">{{ hrData.course_total ?? 0 }} 门</div>
|
||||
<div class="stat-card__sub">线上 {{ hrData.course_online ?? 0 }} · 线下 {{ hrData.course_offline ?? 0 }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">本月完成率</div>
|
||||
<div class="stat-card__value" :class="percentTone(hrData.month_completion?.percent)">
|
||||
{{ hrData.month_completion?.percent ?? 0 }}%
|
||||
</div>
|
||||
<div class="stat-card__sub">已完成 {{ hrData.month_completion?.completed ?? 0 }}/{{ hrData.month_completion?.total ?? 0 }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">本月排期场次</div>
|
||||
<div class="stat-card__value">{{ hrData.month_sessions?.length ?? 0 }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-grid">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__title">年度需求收集进度(各部门)</div>
|
||||
<div v-for="row in hrData.demand_progress || []" :key="row.dept_id" class="progress-row">
|
||||
<span class="progress-row__name">{{ row.dept_name || '未分组' }}</span>
|
||||
<t-progress class="progress-row__bar" :percentage="row.percent" />
|
||||
<span class="progress-row__meta">{{ row.done }}/{{ row.total }} 门</span>
|
||||
</div>
|
||||
<t-empty v-if="!(hrData.demand_progress || []).length" description="暂无需求数据" />
|
||||
</div>
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__title">人事待办(待确认需求)</div>
|
||||
<div v-for="d in (hrData.pending_demands || []).slice(0, 8)" :key="d.id" class="list-row">
|
||||
<span>{{ d.course_name }}</span>
|
||||
<t-tag v-if="d.check_status === 'pending'" theme="warning" variant="light" size="small">待校验</t-tag>
|
||||
<t-tag v-else theme="success" variant="light" size="small">已确认</t-tag>
|
||||
</div>
|
||||
<t-empty v-if="!(hrData.pending_demands || []).length" description="暂无待办" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 课长工作台(本部门) -->
|
||||
<template v-if="showDept">
|
||||
<div class="stat-cards">
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">本月部门排期</div>
|
||||
<div class="stat-card__value">{{ deptData.month_plans?.length ?? 0 }} 项</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">待审批</div>
|
||||
<div class="stat-card__value" :class="deptData.pending_approvals ? 'tone-warn' : ''">
|
||||
{{ deptData.pending_approvals ?? 0 }} 项
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">部门完成率</div>
|
||||
<div class="stat-card__value">{{ deptData.month_completion?.percent ?? 0 }}%</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">未完成预警</div>
|
||||
<div class="stat-card__value" :class="deptData.unfinished_count ? 'tone-bad' : ''">
|
||||
{{ deptData.unfinished_count ?? 0 }} 人次
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 管理驾驶舱 -->
|
||||
<template v-if="showExec">
|
||||
<div class="stat-cards">
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">月度达成率</div>
|
||||
<div class="stat-card__value">{{ execData.month_completion?.percent ?? 0 }}%</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">累计积分发放</div>
|
||||
<div class="stat-card__value">{{ execData.points_total ?? 0 }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-card__label">活跃讲师</div>
|
||||
<div class="stat-card__value">{{ execData.lecturer_ranking?.length ?? 0 }} 人</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-grid">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__title">部门培训达成率排名(年度累计)</div>
|
||||
<div v-for="row in execData.dept_ranking || []" :key="row.dept_id" class="progress-row">
|
||||
<span class="progress-row__name">{{ row.dept_name || '未分组' }}</span>
|
||||
<t-progress class="progress-row__bar" :percentage="row.percent" />
|
||||
<span class="progress-row__meta">{{ row.percent }}%</span>
|
||||
</div>
|
||||
<t-empty v-if="!(execData.dept_ranking || []).length" description="暂无数据" />
|
||||
</div>
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__title">讲师积分榜 TOP 5<t-button v-if="admin" variant="text" theme="primary" size="small" :loading="settleLoading" @click="onSettle">结算本月</t-button></div>
|
||||
<div v-for="(row, idx) in lecturerRanking.slice(0, 5)" :key="row.lecturer_id" class="list-row">
|
||||
<span>
|
||||
<t-tag :theme="idx === 0 ? 'warning' : 'default'" variant="light" size="small">{{ idx + 1 }}</t-tag>
|
||||
{{ row.name }}
|
||||
<span v-if="row.dept_name" class="muted">{{ row.dept_name }}</span>
|
||||
</span>
|
||||
<span class="rank-score">{{ row.total }} 分</span>
|
||||
</div>
|
||||
<t-empty v-if="!(execData.lecturer_ranking || []).length" description="暂无讲师积分" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-box ai-summary">
|
||||
<div class="panel-box__title">AI · 月度盘点摘要</div>
|
||||
<div>{{ execData.ai_summary || '—' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 无驾驶舱角色兜底:个人成长已由工作台「个人成长」页签承载 -->
|
||||
<t-empty v-if="!showHr && !showDept && !showExec" description="当前角色暂无驾驶舱数据" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { getDeptDashboard, getExecDashboard, getHRDashboard, settleLecturerScores, unwrap, type DashboardData } from '@/api/training'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
|
||||
const hrData = ref<DashboardData>({})
|
||||
const deptData = ref<DashboardData>({})
|
||||
const execData = ref<DashboardData>({})
|
||||
|
||||
// 人事工作台仅人事;部门看板=课长(roles 已展开,经理自动命中);管理驾驶舱=经理
|
||||
const showHr = computed(() => props.roles.includes('hr'))
|
||||
const showDept = computed(() => props.roles.includes('supervisor'))
|
||||
const showExec = computed(() => props.roles.includes('exec'))
|
||||
|
||||
// 讲师积分榜(驾驶舱 exec 视图),显式类型避免 v-for 索引被推断为 string | number
|
||||
const lecturerRanking = computed(
|
||||
() => (execData.value.lecturer_ranking || []) as { lecturer_id: string; name: string; dept_name?: string; total: number }[],
|
||||
)
|
||||
|
||||
const percentTone = (p?: number) => {
|
||||
if (p == null) return ''
|
||||
if (p >= 90) return 'tone-good'
|
||||
if (p >= 70) return ''
|
||||
return 'tone-bad'
|
||||
}
|
||||
|
||||
const loadAll = async () => {
|
||||
const now = new Date()
|
||||
if (showHr.value) {
|
||||
try {
|
||||
const res = await getHRDashboard(now.getFullYear(), now.getMonth() + 1)
|
||||
hrData.value = unwrap(res) || {}
|
||||
} catch { /* keep empty */ }
|
||||
}
|
||||
if (showDept.value) {
|
||||
try {
|
||||
const res = await getDeptDashboard(now.getFullYear(), now.getMonth() + 1)
|
||||
deptData.value = unwrap(res) || {}
|
||||
} catch { /* keep empty */ }
|
||||
}
|
||||
if (showExec.value) {
|
||||
try {
|
||||
const res = await getExecDashboard(now.getFullYear())
|
||||
execData.value = unwrap(res) || {}
|
||||
} catch { /* keep empty */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const settleLoading = ref(false)
|
||||
const onSettle = async () => {
|
||||
const now = new Date()
|
||||
try {
|
||||
const res = await settleLecturerScores(now.getFullYear(), now.getMonth() + 1)
|
||||
MessagePlugin.success(`讲师月度综合分已结算 ${unwrap(res)?.settled ?? 0} 人`)
|
||||
loadAll()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.response?.data?.message || '结算失败(本月需有授课场次与评分数据)')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.stat-cards {
|
||||
.training-stat-cards();
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
.training-stat-card();
|
||||
}
|
||||
|
||||
.tone-good { color: var(--td-success-color); }
|
||||
.tone-warn { color: var(--td-warning-color); }
|
||||
.tone-bad { color: var(--td-error-color); }
|
||||
|
||||
.panel-grid {
|
||||
.training-panel-grid();
|
||||
}
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
|
||||
&__title {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.ai-summary { margin-top: 0; }
|
||||
|
||||
.progress-row {
|
||||
.training-progress-row();
|
||||
}
|
||||
|
||||
.list-row {
|
||||
.training-list-row();
|
||||
}
|
||||
|
||||
.rank-score { font-weight: 600; color: var(--td-warning-color); }
|
||||
.muted { color: var(--td-text-color-placeholder); margin-left: 6px; }
|
||||
</style>
|
||||
@@ -0,0 +1,607 @@
|
||||
<template>
|
||||
<div class="exam-panel">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">班级薄弱点视图</span>
|
||||
</div>
|
||||
<div v-for="row in analysis" :key="row.knowledge_point" class="progress-row">
|
||||
<span class="progress-row__name">{{ row.knowledge_point || '未分类' }}</span>
|
||||
<t-progress
|
||||
class="progress-row__bar"
|
||||
:percentage="Math.round(row.error_rate * 100)"
|
||||
:color="row.error_rate > 0.3 ? 'var(--td-error-color)' : 'var(--td-brand-color)'"
|
||||
/>
|
||||
<span class="progress-row__meta">错误 {{ row.wrong_count }} 次</span>
|
||||
</div>
|
||||
<t-empty v-if="!analysis.length" description="选择场次后查看知识点错误率" />
|
||||
<div v-if="analysisTop" class="ai-tip">AI 建议:「{{ analysisTop.knowledge_point }}」错误率最高,建议安排集中补训。</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">考试成绩</span>
|
||||
<div class="exam-query-group">
|
||||
<t-select v-model="recordCourseId" filterable clearable placeholder="选择课程" style="width: 220px" @change="onCoursePicked">
|
||||
<t-option v-for="c in courses" :key="c.id" :value="c.id" :label="c.name" />
|
||||
</t-select>
|
||||
<t-select
|
||||
v-model="recordPaperId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择试卷/试题"
|
||||
style="width: 240px"
|
||||
:loading="papersLoading"
|
||||
@change="loadRecords"
|
||||
>
|
||||
<t-option v-for="p in papers" :key="p.id" :value="p.id" :label="p.name" />
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 试卷列表与答题(按课程查询:场次卷 + 线上自学卷) -->
|
||||
<template v-if="recordCourseId">
|
||||
<div class="records-header">
|
||||
<span class="records-header__title">试卷</span>
|
||||
<span class="muted">学员可在企微内答题;此处支持本人在线答题与监考代录</span>
|
||||
</div>
|
||||
<t-table :data="papers" :columns="paperColumns" row-key="id" size="small" :loading="papersLoading">
|
||||
<template #course="{ row }">{{ paperCourseName(row) }}</template>
|
||||
<template #op="{ row }">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onTakeExam(row)">答题</t-button>
|
||||
<t-button v-if="canProctor" variant="text" size="small" @click="openProctor(row)">代交卷</t-button>
|
||||
<t-button variant="text" size="small" @click="recordPaperId = row.id">考试情况</t-button>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!papersLoading && !papers.length" description="该课程暂无试卷(组卷/AI 生成/答题后自动生成)" />
|
||||
</template>
|
||||
|
||||
<!-- 状态汇总(列表按学员去重:同一学员多次交卷取最新) -->
|
||||
<div v-if="recordPaperId" class="exam-stats">
|
||||
<div class="exam-stat">
|
||||
<span class="exam-stat__num">{{ examStats.expected }}</span>
|
||||
<span class="exam-stat__label">应考</span>
|
||||
</div>
|
||||
<div class="exam-stat">
|
||||
<span class="exam-stat__num">{{ examStats.taken }}</span>
|
||||
<span class="exam-stat__label">已考</span>
|
||||
</div>
|
||||
<div class="exam-stat">
|
||||
<span class="exam-stat__num tone-good">{{ examStats.passed }}</span>
|
||||
<span class="exam-stat__label">及格</span>
|
||||
</div>
|
||||
<div class="exam-stat">
|
||||
<span class="exam-stat__num tone-bad">{{ examStats.failed }}</span>
|
||||
<span class="exam-stat__label">不及格</span>
|
||||
</div>
|
||||
<div class="exam-stat">
|
||||
<span class="exam-stat__num">{{ examStats.missing }}</span>
|
||||
<span class="exam-stat__label">未考</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 条件查询:部门 / 关键词(工号·岗位) / 状态 -->
|
||||
<div v-if="recordPaperId && dedupedRecords.length" class="query-bar">
|
||||
<t-select v-model="recordFilters.dept" clearable placeholder="部门" style="width: 150px">
|
||||
<t-option v-for="d in recordDeptOptions" :key="d" :value="d" :label="d" />
|
||||
</t-select>
|
||||
<t-input v-model="recordFilters.keyword" clearable placeholder="工号 / 岗位" style="width: 180px" />
|
||||
<t-select v-model="recordFilters.status" clearable placeholder="状态" style="width: 110px">
|
||||
<t-option label="及格" value="passed" />
|
||||
<t-option label="不及格" value="failed" />
|
||||
</t-select>
|
||||
<t-button variant="text" theme="primary" :disabled="!hasRecordFilter" @click="resetRecordFilters">重置</t-button>
|
||||
<span class="query-bar__hit">共 {{ filteredRecords.length }} 条</span>
|
||||
</div>
|
||||
|
||||
<t-table :data="filteredRecords" :columns="recordColumns" row-key="id" size="small" class="records-table" :loading="recordLoading">
|
||||
<template #member="{ row }">{{ memberLabel(row.member_id) }}</template>
|
||||
<template #dept="{ row }">{{ memberDept(row.member_id) }}</template>
|
||||
<template #score="{ row }">
|
||||
<span :class="scoreClass(row)">{{ row.score ?? '—' }}</span>
|
||||
</template>
|
||||
<template #submitted_at="{ row }">{{ fmtTime(row.submitted_at) }}</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!recordPaperId" description="选择课程与试卷后查看考试情况与答题记录" />
|
||||
<t-empty v-else-if="!recordLoading && !records.length" description="该试卷暂无答题记录" />
|
||||
<t-empty v-else-if="records.length && !filteredRecords.length" description="没有符合查询条件的记录" />
|
||||
</div>
|
||||
|
||||
<!-- 在线答题(逐题作答:实时统计/题号导航/作答后揭示答案) -->
|
||||
<QuestionExamDialog
|
||||
:visible="takeVisible"
|
||||
:paper="takePaper"
|
||||
:questions="takeQuestions"
|
||||
:submitting="saving"
|
||||
@update:visible="takeVisible = $event"
|
||||
@submit="onSubmitExam"
|
||||
/>
|
||||
|
||||
<!-- 代交卷 -->
|
||||
<t-dialog v-model:visible="proctorVisible" :header="`监考代交卷 · ${proctorPaper?.name || ''}`" width="460">
|
||||
<t-form label-width="90">
|
||||
<t-form-item label="学员" required>
|
||||
<t-select v-model="proctorMemberId" filterable style="width: 100%">
|
||||
<t-option v-for="m in members" :key="m.id" :value="m.id" :label="`${m.employee_no || ''} ${m.post || ''}`" />
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
<t-form-item label="答卷录入">
|
||||
<t-button variant="outline" size="small" @click="loadPaperForProctor">载入试卷题目(线下答题快速录入)</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<div v-if="proctorQuestions.length" class="take-question">
|
||||
<div v-for="q in proctorQuestions" :key="q.id" class="take-question__stem">
|
||||
{{ q.stem }}
|
||||
<t-input v-model="proctorAnswers[q.id]" size="small" class="proctor-input" placeholder="答案(如 A / ABD / 对)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-hint">代交卷与本人交卷同一判分;成绩达标自动置该场次课程完成。</div>
|
||||
<template #footer>
|
||||
<t-button theme="primary" :loading="saving" :disabled="!proctorMemberId" @click="onSubmitFor">提交成绩</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
getExamAnalysis,
|
||||
getPaperForExam,
|
||||
listCourses,
|
||||
listCoursePapers,
|
||||
listDepts,
|
||||
listEnrollments,
|
||||
listMembers,
|
||||
listPaperRecords,
|
||||
listSessions,
|
||||
submitExam,
|
||||
submitExamFor,
|
||||
type ExamAnalysisItem,
|
||||
type TrainingCourse,
|
||||
type TrainingCourseSession,
|
||||
type TrainingDept,
|
||||
type TrainingExamRecord,
|
||||
type TrainingMember,
|
||||
type TrainingPaper,
|
||||
type TrainingQuestion,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import { apiErrorMessage } from '@/utils/request'
|
||||
import QuestionExamDialog from './QuestionExamDialog.vue'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean; initialCourseId?: string }>()
|
||||
// 监考/代交卷:人事/课长/讲师(roles 已按权限组展开,经理自动命中)
|
||||
const canProctor = computed(() => props.admin || props.roles.some((r) => ['hr', 'supervisor', 'lecturer'].includes(r)))
|
||||
|
||||
const saving = ref(false)
|
||||
const recordLoading = ref(false)
|
||||
const courses = ref<TrainingCourse[]>([])
|
||||
const sessions = ref<TrainingCourseSession[]>([])
|
||||
const analysis = ref<ExamAnalysisItem[]>([])
|
||||
const records = ref<TrainingExamRecord[]>([])
|
||||
const papers = ref<TrainingPaper[]>([])
|
||||
const members = ref<TrainingMember[]>([])
|
||||
const memberLabels = ref<Record<string, string>>({})
|
||||
const deptNames = ref<Record<string, string>>({})
|
||||
const expectedCount = ref(0)
|
||||
const analysisSessionId = ref('')
|
||||
// 考试成绩按 课程 + 试卷(试题) 查询;记录按试卷(覆盖 session 为空的线上自学卷)
|
||||
const recordCourseId = ref('')
|
||||
const recordPaperId = ref('')
|
||||
const papersLoading = ref(false)
|
||||
const selectedPaper = computed(() => papers.value.find((p) => p.id === recordPaperId.value) || null)
|
||||
|
||||
// 在线答题状态
|
||||
const takeVisible = ref(false)
|
||||
const takePaper = ref<TrainingPaper | null>(null)
|
||||
const takeQuestions = ref<TrainingQuestion[]>([])
|
||||
|
||||
// 代交卷状态
|
||||
const proctorVisible = ref(false)
|
||||
const proctorPaper = ref<TrainingPaper | null>(null)
|
||||
const proctorMemberId = ref('')
|
||||
const proctorQuestions = ref<TrainingQuestion[]>([])
|
||||
const proctorAnswers = ref<Record<string, string>>({})
|
||||
|
||||
const analysisTop = computed(() => analysis.value[0] || null)
|
||||
|
||||
const recordColumns = [
|
||||
{ colKey: 'member', title: '学员' },
|
||||
{ colKey: 'dept', title: '部门', width: 110 },
|
||||
{ colKey: 'score', title: '成绩', width: 80 },
|
||||
{ colKey: 'submitted_at', title: '交卷时间', width: 180 },
|
||||
]
|
||||
|
||||
const paperColumns = [
|
||||
{ colKey: 'name', title: '试卷' },
|
||||
{ colKey: 'course', title: '课程' },
|
||||
{ colKey: 'total_score', title: '总分', width: 80 },
|
||||
{ colKey: 'pass_score', title: '及格线', width: 80 },
|
||||
{ colKey: 'version', title: '版本', width: 70 },
|
||||
{ colKey: 'op', title: '操作', width: 160 },
|
||||
]
|
||||
|
||||
// 试卷所属课程名:场次→课程(线上自学卷不入场次列表,按所属场次回显即可)
|
||||
const paperCourseName = (paper: TrainingPaper) => {
|
||||
const session = sessions.value.find((s) => s.id === paper.session_id)
|
||||
const course = session && courses.value.find((c) => c.id === session.course_id)
|
||||
return course?.name || '-'
|
||||
}
|
||||
|
||||
const memberLabel = (memberId: string) => memberLabels.value[memberId] || memberId
|
||||
// 学员部门展示(部门名映射自 listDepts,未导入部门的档案回退 '-')
|
||||
const memberDept = (memberId: string) => {
|
||||
const m = members.value.find((x) => x.id === memberId)
|
||||
return (m && deptNames.value[m.dept_id]) || '-'
|
||||
}
|
||||
|
||||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
|
||||
|
||||
// ---- 考试成绩:课程+学员唯一去重 + 状态汇总 + 条件查询 ----
|
||||
// 同一学员多份卷/多次交卷取最新一次,保证列表按学员唯一。
|
||||
const dedupedRecords = computed<TrainingExamRecord[]>(() => {
|
||||
const latest = new Map<string, TrainingExamRecord>()
|
||||
for (const r of records.value) {
|
||||
const old = latest.get(r.member_id)
|
||||
const t = r.submitted_at ? new Date(r.submitted_at).getTime() : 0
|
||||
const oldT = old?.submitted_at ? new Date(old.submitted_at).getTime() : 0
|
||||
if (!old || t >= oldT) latest.set(r.member_id, r)
|
||||
}
|
||||
return [...latest.values()].sort((a, b) => {
|
||||
const ta = a.submitted_at ? new Date(a.submitted_at).getTime() : 0
|
||||
const tb = b.submitted_at ? new Date(b.submitted_at).getTime() : 0
|
||||
return ta - tb
|
||||
})
|
||||
})
|
||||
|
||||
// 及格线按答卷所属试卷取(未组卷代录等场景回退 60 分)
|
||||
const passLineOf = (row: TrainingExamRecord) => {
|
||||
const paper = papers.value.find((p) => p.id === row.paper_id)
|
||||
return paper?.pass_score && paper.pass_score > 0 ? paper.pass_score : 60
|
||||
}
|
||||
|
||||
const isPassed = (row: TrainingExamRecord) => row.score != null && row.score >= passLineOf(row)
|
||||
|
||||
const examStats = computed(() => {
|
||||
const taken = dedupedRecords.value.length
|
||||
const passed = dedupedRecords.value.filter((r) => isPassed(r)).length
|
||||
return {
|
||||
expected: Math.max(expectedCount.value, taken),
|
||||
taken,
|
||||
passed,
|
||||
failed: taken - passed,
|
||||
missing: Math.max(expectedCount.value - taken, 0),
|
||||
}
|
||||
})
|
||||
|
||||
const scoreClass = (row: TrainingExamRecord) => (isPassed(row) ? 'tone-good' : 'tone-bad')
|
||||
|
||||
const recordFilters = reactive({ dept: '', keyword: '', status: '' })
|
||||
const hasRecordFilter = computed(() => Boolean(recordFilters.dept || recordFilters.keyword || recordFilters.status))
|
||||
const resetRecordFilters = () => {
|
||||
recordFilters.dept = ''
|
||||
recordFilters.keyword = ''
|
||||
recordFilters.status = ''
|
||||
}
|
||||
|
||||
const recordDeptOptions = computed(() => {
|
||||
const names = new Set<string>()
|
||||
for (const r of dedupedRecords.value) {
|
||||
const d = memberDept(r.member_id)
|
||||
if (d && d !== '-') names.add(d)
|
||||
}
|
||||
return [...names].sort()
|
||||
})
|
||||
|
||||
const filteredRecords = computed(() => {
|
||||
const kw = recordFilters.keyword.trim().toLowerCase()
|
||||
return dedupedRecords.value.filter((r) => {
|
||||
if (recordFilters.dept && memberDept(r.member_id) !== recordFilters.dept) return false
|
||||
if (recordFilters.status === 'passed' && !isPassed(r)) return false
|
||||
if (recordFilters.status === 'failed' && isPassed(r)) return false
|
||||
if (kw) {
|
||||
const m = members.value.find((x) => x.id === r.member_id)
|
||||
const text = `${memberLabel(r.member_id)} ${m?.user_name || ''}`.toLowerCase()
|
||||
if (!text.includes(kw)) return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
const loadAll = async () => {
|
||||
const [s, m, c, d] = await Promise.all([
|
||||
listSessions({ page_size: 200 }),
|
||||
listMembers({ page_size: 500 }).catch(() => null),
|
||||
listCourses({ page_size: 100 }).catch(() => null),
|
||||
listDepts().catch(() => null),
|
||||
])
|
||||
sessions.value = unwrap(s) || []
|
||||
courses.value = (c && unwrap(c)?.items) || []
|
||||
deptNames.value = Object.fromEntries(
|
||||
((d && unwrap(d) || []) as TrainingDept[]).map((dep) => [dep.id, dep.name]),
|
||||
)
|
||||
const memberItems = (m && unwrap(m)?.items) || []
|
||||
if (memberItems.length) {
|
||||
members.value = memberItems
|
||||
const labels: Record<string, string> = {}
|
||||
for (const mem of members.value) {
|
||||
labels[mem.id] = `${mem.employee_no || '-'} ${mem.post || ''}`.trim() || mem.id.slice(0, 8)
|
||||
}
|
||||
memberLabels.value = labels
|
||||
}
|
||||
// 优先聚焦培训课程页「考试状态」列跳转指定的课程,否则默认第一门有试卷的课程
|
||||
const presetCourse = props.initialCourseId
|
||||
const target = presetCourse || courses.value[0]?.id || ''
|
||||
if (target) {
|
||||
recordCourseId.value = target
|
||||
const firstSession = sessions.value.find((x) => x.course_id === target)
|
||||
if (firstSession) {
|
||||
analysisSessionId.value = firstSession.id
|
||||
loadAnalysis()
|
||||
}
|
||||
await loadPapers()
|
||||
}
|
||||
}
|
||||
|
||||
// 培训课程页「考试状态」列再次跳转时切换到对应课程
|
||||
watch(
|
||||
() => props.initialCourseId,
|
||||
async (courseId) => {
|
||||
if (!courseId || courseId === recordCourseId.value) return
|
||||
recordCourseId.value = courseId
|
||||
const firstSession = sessions.value.find((x) => x.course_id === courseId)
|
||||
if (firstSession) {
|
||||
analysisSessionId.value = firstSession.id
|
||||
loadAnalysis()
|
||||
}
|
||||
await loadPapers()
|
||||
},
|
||||
)
|
||||
|
||||
const loadAnalysis = async () => {
|
||||
if (!analysisSessionId.value) return
|
||||
try {
|
||||
const res = await getExamAnalysis(analysisSessionId.value)
|
||||
analysis.value = unwrap(res) || []
|
||||
} catch {
|
||||
analysis.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 课程维度的试卷列表(场次卷 + 线上自学卷归并);默认选中第一张
|
||||
const loadPapers = async () => {
|
||||
recordPaperId.value = ''
|
||||
records.value = []
|
||||
expectedCount.value = 0
|
||||
if (!recordCourseId.value) {
|
||||
papers.value = []
|
||||
return
|
||||
}
|
||||
papersLoading.value = true
|
||||
try {
|
||||
const res = await listCoursePapers(recordCourseId.value)
|
||||
papers.value = unwrap(res) || []
|
||||
if (papers.value.length) {
|
||||
recordPaperId.value = papers.value[0].id
|
||||
loadRecords()
|
||||
}
|
||||
} catch {
|
||||
papers.value = []
|
||||
} finally {
|
||||
papersLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onCoursePicked = () => {
|
||||
void loadPapers()
|
||||
}
|
||||
|
||||
const loadRecords = async () => {
|
||||
resetRecordFilters()
|
||||
if (!recordPaperId.value) {
|
||||
records.value = []
|
||||
expectedCount.value = 0
|
||||
return
|
||||
}
|
||||
recordLoading.value = true
|
||||
try {
|
||||
// 记录按试卷查询(覆盖 session 为空的线上自学卷);应考口径 = 试卷所属场次名单人数
|
||||
const [recs, roster] = await Promise.all([
|
||||
listPaperRecords(recordPaperId.value),
|
||||
(async () => {
|
||||
const session = sessions.value.find((x) => x.id === selectedPaper.value?.session_id)
|
||||
if (!session) return null
|
||||
return listEnrollments(session.id).catch(() => null)
|
||||
})(),
|
||||
])
|
||||
records.value = unwrap(recs) || []
|
||||
expectedCount.value = (roster && unwrap(roster) || []).length
|
||||
} catch {
|
||||
records.value = []
|
||||
expectedCount.value = 0
|
||||
} finally {
|
||||
recordLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 在线答题 ----
|
||||
const onTakeExam = async (paper: TrainingPaper) => {
|
||||
try {
|
||||
const res = await getPaperForExam(paper.id)
|
||||
takePaper.value = unwrap(res)?.paper || paper
|
||||
takeQuestions.value = unwrap(res)?.questions || []
|
||||
takeVisible.value = true
|
||||
} catch {
|
||||
MessagePlugin.error('取卷失败')
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmitExam = async ({ answers }: { answers: Record<string, string> }) => {
|
||||
if (!takePaper.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
const res = await submitExam(takePaper.value.id, answers)
|
||||
const score = unwrap(res)?.score
|
||||
MessagePlugin.success(`答卷已提交,得分 ${score ?? '—'} 分;成绩已记录并计入课程考试状态`)
|
||||
takeVisible.value = false
|
||||
loadRecords()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(apiErrorMessage(e, '交卷失败'))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 监考代交卷 ----
|
||||
const openProctor = (paper: TrainingPaper) => {
|
||||
proctorPaper.value = paper
|
||||
proctorMemberId.value = ''
|
||||
proctorQuestions.value = []
|
||||
proctorAnswers.value = {}
|
||||
proctorVisible.value = true
|
||||
}
|
||||
|
||||
const loadPaperForProctor = async () => {
|
||||
if (!proctorPaper.value) return
|
||||
try {
|
||||
const res = await getPaperForExam(proctorPaper.value.id)
|
||||
proctorQuestions.value = unwrap(res)?.questions || []
|
||||
} catch {
|
||||
proctorQuestions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmitFor = async () => {
|
||||
if (!proctorPaper.value || !proctorMemberId.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
const res = await submitExamFor(proctorPaper.value.id, proctorMemberId.value, proctorAnswers.value)
|
||||
const score = unwrap(res)?.score
|
||||
MessagePlugin.success(`已录入成绩 ${score ?? '—'} 分`)
|
||||
proctorVisible.value = false
|
||||
loadRecords()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.response?.data?.message || '录入失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.progress-row {
|
||||
.training-progress-row();
|
||||
|
||||
.progress-row__name { width: 130px; }
|
||||
}
|
||||
|
||||
.ai-tip {
|
||||
margin-top: 10px;
|
||||
background: var(--td-brand-color-1, rgba(0, 82, 217, 0.06));
|
||||
border-radius: var(--app-radius-sm);
|
||||
padding: 8px 10px;
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
margin-top: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.records-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin: 4px 0 8px;
|
||||
|
||||
&__title { font-weight: 600; }
|
||||
}
|
||||
|
||||
// 考试成绩查询组:课程 + 试卷 双下拉
|
||||
.exam-query-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.records-table { margin-top: 10px; }
|
||||
|
||||
// 考试成绩状态汇总(应考/已考/及格/不及格/未考)
|
||||
.exam-stats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 24px;
|
||||
margin: 4px 0 10px;
|
||||
}
|
||||
|
||||
.exam-stat {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
|
||||
&__num {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
&__label {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
// 条件查询栏(与课程学习情况页同款)
|
||||
.query-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
|
||||
&__hit {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.muted { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); }
|
||||
|
||||
.tone-good { color: var(--td-success-color); font-weight: 600; }
|
||||
.tone-bad { color: var(--td-error-color); font-weight: 600; }
|
||||
|
||||
.exam-meta {
|
||||
margin-bottom: 10px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.take-question {
|
||||
padding: 10px 4px;
|
||||
border-bottom: 1px solid var(--td-component-border);
|
||||
|
||||
&__stem { font-weight: 600; }
|
||||
&__score { color: var(--td-text-color-placeholder); font-weight: 400; margin-left: 6px; }
|
||||
&__options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.proctor-input { margin-top: 4px; width: 220px; }
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,150 @@
|
||||
<template>
|
||||
<div class="learning-panel">
|
||||
<div class="panel-grid">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的线上学习任务</span>
|
||||
</div>
|
||||
<t-table :data="tasks" :columns="taskColumns" row-key="id" size="small">
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="taskTheme(row.status)" variant="light" size="small">{{ taskText(row.status) }}</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<t-button variant="text" theme="primary" size="small" @click="goLearn(row.course_id)">去学习</t-button>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!tasks.length" description="暂无学习任务" />
|
||||
</div>
|
||||
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的错题本</span>
|
||||
</div>
|
||||
<t-table :data="wrongBook" :columns="wrongColumns" row-key="id" size="small">
|
||||
<template #knowledge_point="{ row }">
|
||||
<t-tag v-if="row.knowledge_point" variant="light" size="small">{{ row.knowledge_point }}</t-tag>
|
||||
<span v-else>—</span>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!wrongBook.length" description="错题本为空,继续保持" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的能力画像</span>
|
||||
</div>
|
||||
<div v-if="profile" class="profile-grid">
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">岗位胜任度</div>
|
||||
<div class="profile-item__value" :class="profile.competency >= profile.pass_line ? 'tone-good' : 'tone-bad'">
|
||||
{{ profile.competency }} 分
|
||||
</div>
|
||||
<div class="profile-item__sub">达标线 {{ profile.pass_line }} 分</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">累计积分</div>
|
||||
<div class="profile-item__value">{{ profile.points }}</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">平均成绩</div>
|
||||
<div class="profile-item__value">{{ profile.avg_score }}</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">学习时长</div>
|
||||
<div class="profile-item__value">{{ profile.study_hours }} h</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">课程数</div>
|
||||
<div class="profile-item__value">{{ profile.course_count }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<t-empty v-else description="暂无画像数据" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
getMyAbilityProfile,
|
||||
listMyLearningTasks,
|
||||
listWrongBook,
|
||||
type LearningTask,
|
||||
type TrainingProfile,
|
||||
type WrongBookItem,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
|
||||
const router = useRouter()
|
||||
// 任务行「去学习」→ 课程学习详情页。
|
||||
const goLearn = (courseId: string) => router.push(`/platform/training/course/${courseId}`)
|
||||
|
||||
const tasks = ref<LearningTask[]>([])
|
||||
const wrongBook = ref<WrongBookItem[]>([])
|
||||
const profile = ref<TrainingProfile | null>(null)
|
||||
|
||||
const taskColumns = [
|
||||
{ colKey: 'course_name', title: '课程' },
|
||||
{ colKey: 'deadline', title: '完成期限', width: 180 },
|
||||
{ colKey: 'status', title: '状态', width: 90 },
|
||||
{ colKey: 'op', title: '操作', width: 90 },
|
||||
]
|
||||
|
||||
const wrongColumns = [
|
||||
{ colKey: 'stem', title: '题干' },
|
||||
{ colKey: 'knowledge_point', title: '知识点', width: 140 },
|
||||
{ colKey: 'wrong_count', title: '错误次数', width: 90 },
|
||||
]
|
||||
|
||||
const taskText = (s: string) => ({ pending: '待学习', doing: '学习中', done: '已完成', overdue: '已逾期' }[s] || s)
|
||||
const taskTheme = (s: string) => ({ pending: 'default', doing: 'primary', done: 'success', overdue: 'danger' }[s] || 'default')
|
||||
|
||||
const loadAll = async () => {
|
||||
try {
|
||||
const [t, w, p] = await Promise.all([
|
||||
listMyLearningTasks(),
|
||||
listWrongBook(),
|
||||
getMyAbilityProfile(),
|
||||
])
|
||||
tasks.value = unwrap(t) || []
|
||||
wrongBook.value = unwrap(w) || []
|
||||
profile.value = unwrap(p) || null
|
||||
} catch { /* keep empty */ }
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.panel-grid {
|
||||
.training-panel-grid();
|
||||
}
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
}
|
||||
|
||||
.profile-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.profile-item {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 12px 14px;
|
||||
text-align: center;
|
||||
|
||||
&__label { color: var(--td-text-color-secondary); font-size: var(--app-text-md); }
|
||||
&__value { font-size: 22px; font-weight: 700; margin-top: 4px; }
|
||||
&__sub { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); margin-top: 2px; }
|
||||
}
|
||||
|
||||
.tone-good { color: var(--td-success-color); }
|
||||
.tone-bad { color: var(--td-error-color); }
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<!-- 题库 Excel 导入弹窗:「题库与考试」与知识库「企业培训(题库)」页共用 -->
|
||||
<t-dialog :visible="visible" header="题库 Excel 导入" width="560" @close="close">
|
||||
<t-form label-width="90">
|
||||
<t-form-item label="题库名称" required>
|
||||
<t-input v-model="form.name" placeholder="如:TPM 设备保全题库" />
|
||||
</t-form-item>
|
||||
<t-form-item label="关联课程">
|
||||
<t-select v-model="form.courseId" filterable clearable placeholder="选择题库归属课程(可选)" style="width: 100%">
|
||||
<t-option v-for="c in courses" :key="c.id" :value="c.id" :label="c.name" />
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
<t-form-item label="Excel 文件" required>
|
||||
<input type="file" accept=".xlsx,.xls" @change="onFileChange" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<div class="form-hint">
|
||||
推荐使用<a class="template-link" href="javascript:void(0)" @click.prevent="downloadTemplate">《部门培训课程试题(题库导入版)》模板</a>:
|
||||
工作表「单选题/多选题/判断题」,列:题目/课程名称/难度/正确答案/答案A..L,题型按工作表名识别,难度支持高/中/低。
|
||||
</div>
|
||||
<div class="form-hint">也支持简表格式:题型 | 题干 | 选项(A. xx|B. xx) | 答案 | 分值 | 难度(1-5) | 知识点 | 解析</div>
|
||||
<div class="form-hint">导入成功后,题库 Excel 将自动同步至知识库「企业培训(题库)」,可在 AI 对话中问答。</div>
|
||||
<template #footer>
|
||||
<t-button variant="outline" @click="downloadTemplate">下载试题模板</t-button>
|
||||
<t-button theme="primary" :loading="saving" @click="onImport">导入</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
importQuestionBankExcel,
|
||||
listCourses,
|
||||
type TrainingCourse,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { QUESTION_TEMPLATE_KEY, downloadTrainingTemplate } from '../trainingTemplates'
|
||||
|
||||
const props = defineProps<{ visible: boolean }>()
|
||||
const emit = defineEmits<{ 'update:visible': [v: boolean]; imported: [name: string, count: number] }>()
|
||||
|
||||
const saving = ref(false)
|
||||
const courses = ref<TrainingCourse[]>([])
|
||||
const form = ref({ name: '', courseId: '' })
|
||||
const importFile = ref<File | null>(null)
|
||||
|
||||
const close = () => emit('update:visible', false)
|
||||
|
||||
const onFileChange = (e: Event) => {
|
||||
const input = e.target as HTMLInputElement
|
||||
importFile.value = input.files?.[0] || null
|
||||
}
|
||||
|
||||
const downloadTemplate = () => downloadTrainingTemplate(QUESTION_TEMPLATE_KEY)
|
||||
|
||||
const loadCourses = async () => {
|
||||
try {
|
||||
const res = await listCourses({ page_size: 100 })
|
||||
courses.value = unwrap(res)?.items || []
|
||||
} catch {
|
||||
courses.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const onImport = async () => {
|
||||
if (!importFile.value || !form.value.name) {
|
||||
MessagePlugin.warning('请填写题库名称并选择 Excel 文件')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const fd = new FormData()
|
||||
fd.append('file', importFile.value)
|
||||
fd.append('name', form.value.name)
|
||||
if (form.value.courseId) fd.append('course_id', form.value.courseId)
|
||||
const res = await importQuestionBankExcel(fd)
|
||||
const synced = !!unwrap(res)?.knowledge_id
|
||||
const count = unwrap(res)?.question_count ?? 0
|
||||
MessagePlugin.success(
|
||||
synced
|
||||
? `题库已导入,共 ${count} 题;Excel 已同步知识库「企业培训(题库)」,支持对话问答`
|
||||
: `题库已导入,共 ${count} 题`,
|
||||
)
|
||||
emit('imported', form.value.name, count)
|
||||
form.value = { name: '', courseId: '' }
|
||||
importFile.value = null
|
||||
close()
|
||||
} catch {
|
||||
MessagePlugin.error('导入失败,请检查 Excel 格式')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadCourses)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.form-hint {
|
||||
margin-top: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.template-link {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,371 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
:visible="visible"
|
||||
:header="`在线答题 · ${paper?.name || ''}`"
|
||||
width="760"
|
||||
@close="emit('update:visible', false)"
|
||||
>
|
||||
<!-- 实时统计:答题数/对错/得分 -->
|
||||
<div class="take-stats">
|
||||
<span class="take-stats__item">第 {{ index + 1 }}/{{ questions.length }} 题</span>
|
||||
<span class="take-stats__item">已答 {{ answeredCount }}/{{ questions.length }}</span>
|
||||
<span class="take-stats__item is-good">答对 {{ correctCount }}</span>
|
||||
<span class="take-stats__item is-bad">答错 {{ wrongCount }}</span>
|
||||
<span class="take-stats__item">得分 {{ fmtScore(earnedScore) }}/{{ paper?.total_score ?? 100 }} 分</span>
|
||||
</div>
|
||||
|
||||
<!-- 题号导航:点击跳转任意一题(绿=答对 红=答错 蓝=已答) -->
|
||||
<div v-if="questions.length" class="take-nav" role="tablist" aria-label="题号导航">
|
||||
<button
|
||||
v-for="(q, i) in questions"
|
||||
:key="q.id"
|
||||
type="button"
|
||||
class="take-nav__item"
|
||||
:class="navClass(q)"
|
||||
:aria-label="`第${i + 1}题`"
|
||||
@click="index = i"
|
||||
>{{ i + 1 }}</button>
|
||||
</div>
|
||||
|
||||
<!-- 当前题(逐题作答,作答确认后揭示答案并锁定) -->
|
||||
<div v-if="current" class="take-question">
|
||||
<div class="take-question__stem">
|
||||
{{ index + 1 }}. 【{{ qTypeText(current.type) }}】{{ current.stem }}<span class="take-question__score">({{ current.score }}分)</span>
|
||||
</div>
|
||||
<t-radio-group
|
||||
v-if="current.type !== 'multiple'"
|
||||
v-model="currentAnswer"
|
||||
class="take-question__options"
|
||||
:disabled="isConfirmed"
|
||||
>
|
||||
<t-radio
|
||||
v-for="opt in current.options || []"
|
||||
:key="opt"
|
||||
:value="optLetter(opt)"
|
||||
class="take-question__opt"
|
||||
:class="feedbackOptionClass(opt)"
|
||||
>{{ opt }}</t-radio>
|
||||
</t-radio-group>
|
||||
<t-checkbox-group
|
||||
v-else
|
||||
v-model="currentMulti"
|
||||
class="take-question__options"
|
||||
:disabled="isConfirmed"
|
||||
@change="(v: any) => (currentMulti = v as string[])"
|
||||
>
|
||||
<t-checkbox
|
||||
v-for="opt in current.options || []"
|
||||
:key="opt"
|
||||
:value="optLetter(opt)"
|
||||
class="take-question__opt"
|
||||
:class="feedbackOptionClass(opt)"
|
||||
>{{ opt }}</t-checkbox>
|
||||
</t-checkbox-group>
|
||||
<div v-if="feedback" class="take-feedback" :class="feedback.correct ? 'is-good' : 'is-bad'">
|
||||
<span class="take-feedback__verdict">{{ feedback.correct ? '回答正确' : '回答错误' }} · 得 {{ fmtScore(feedback.score) }} 分</span>
|
||||
<span v-if="!feedback.correct" class="take-feedback__answer">正确答案:{{ feedback.correct_answer }}</span>
|
||||
<div v-if="feedback.analysis" class="take-feedback__analysis">解析:{{ feedback.analysis }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<t-empty v-if="!questions.length" description="该试卷暂无题目" />
|
||||
|
||||
<!-- 翻页与确认 -->
|
||||
<div class="take-pager">
|
||||
<t-button variant="outline" size="small" :disabled="index <= 0" @click="index--">上一题</t-button>
|
||||
<t-button
|
||||
v-if="!isConfirmed"
|
||||
theme="primary"
|
||||
size="small"
|
||||
:loading="confirming"
|
||||
:disabled="!draftAnswer"
|
||||
@click="confirmAnswer"
|
||||
>确认答案</t-button>
|
||||
<span v-else class="take-pager__locked">已确认作答</span>
|
||||
<t-button variant="outline" size="small" :disabled="index >= questions.length - 1" @click="index++">下一题</t-button>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<span class="take-submit-hint">已答 {{ answeredCount }}/{{ questions.length }};未答题目交卷后按错题计</span>
|
||||
<t-button theme="primary" :loading="submitting" :disabled="!questions.length" @click="onSubmitClick">提交答卷</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
answerQuestion,
|
||||
type TrainingPaper,
|
||||
type TrainingQuestion,
|
||||
type TrainingQuestionFeedback,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { apiErrorMessage } from '@/utils/request'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
paper: TrainingPaper | null
|
||||
questions: TrainingQuestion[]
|
||||
submitting?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'submit', payload: { answers: Record<string, string> }): void
|
||||
}>()
|
||||
|
||||
// 作答状态:确认后的答案与判分反馈(逐题锁定,不可回改)
|
||||
const index = ref(0)
|
||||
const answers = ref<Record<string, string>>({})
|
||||
const feedbackMap = ref<Record<string, TrainingQuestionFeedback>>({})
|
||||
const feedback = ref<TrainingQuestionFeedback | null>(null)
|
||||
const currentAnswer = ref('')
|
||||
const currentMulti = ref<string[]>([])
|
||||
const confirming = ref(false)
|
||||
|
||||
const current = computed(() => props.questions[index.value] || null)
|
||||
const isConfirmed = computed(() => !!(current.value && feedbackMap.value[current.value.id]))
|
||||
const draftAnswer = computed(() =>
|
||||
current.value?.type === 'multiple' ? currentMulti.value.slice().sort().join('') : currentAnswer.value.trim(),
|
||||
)
|
||||
|
||||
const answeredCount = computed(() => props.questions.filter((q) => answers.value[q.id]).length)
|
||||
const correctCount = computed(() => Object.values(feedbackMap.value).filter((f) => f.correct).length)
|
||||
const wrongCount = computed(() => Object.values(feedbackMap.value).filter((f) => !f.correct).length)
|
||||
const earnedScore = computed(() => Object.values(feedbackMap.value).reduce((sum, f) => sum + (f.score || 0), 0))
|
||||
|
||||
const qTypeText = (t: string) => ({ single: '单选', multiple: '多选', judge: '判断' }[t] || t)
|
||||
const optLetter = (opt: string) => (opt.match(/^([A-Za-z])[..、::]/)?.[1] || opt)
|
||||
const fmtScore = (v: number) => `${Math.round(v * 100) / 100}`
|
||||
|
||||
const navClass = (q: TrainingQuestion) => {
|
||||
const fb = feedbackMap.value[q.id]
|
||||
return {
|
||||
'is-current': current.value?.id === q.id,
|
||||
'is-answered': !!answers.value[q.id] && !fb,
|
||||
'is-good': !!fb?.correct,
|
||||
'is-bad': !!fb && !fb.correct,
|
||||
}
|
||||
}
|
||||
|
||||
// 反馈揭示后的选项着色:正确项绿、误选项红
|
||||
const feedbackOptionClass = (opt: string) => {
|
||||
if (!feedback.value) return ''
|
||||
const letter = optLetter(opt).toUpperCase()
|
||||
const correctLetters = (feedback.value.correct_answer || '').toUpperCase().split('')
|
||||
const given = current.value?.type === 'multiple' ? currentMulti.value : [currentAnswer.value]
|
||||
if (correctLetters.includes(letter)) return 'is-correct'
|
||||
if (given.map((g) => g.toUpperCase()).includes(letter)) return 'is-wrong'
|
||||
return ''
|
||||
}
|
||||
|
||||
// 切题:恢复该题的已确认答案与反馈
|
||||
watch(
|
||||
() => index.value,
|
||||
() => {
|
||||
feedback.value = (current.value && feedbackMap.value[current.value.id]) || null
|
||||
currentAnswer.value = (current.value && answers.value[current.value.id]) || ''
|
||||
currentMulti.value =
|
||||
current.value && current.value.type === 'multiple' ? (answers.value[current.value.id]?.split('') || []) : []
|
||||
},
|
||||
)
|
||||
|
||||
// 打开弹窗即重置作答状态
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
index.value = 0
|
||||
answers.value = {}
|
||||
feedbackMap.value = {}
|
||||
feedback.value = null
|
||||
currentAnswer.value = ''
|
||||
currentMulti.value = []
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const confirmAnswer = async () => {
|
||||
const q = current.value
|
||||
const given = draftAnswer.value
|
||||
if (!q || !given) {
|
||||
MessagePlugin.warning('请先选择答案')
|
||||
return
|
||||
}
|
||||
confirming.value = true
|
||||
try {
|
||||
const res = await answerQuestion(props.paper!.id, { question_id: q.id, answer: given })
|
||||
const fb = unwrap<TrainingQuestionFeedback>(res)
|
||||
if (!fb) throw new Error('no feedback')
|
||||
answers.value = { ...answers.value, [q.id]: given }
|
||||
feedbackMap.value = { ...feedbackMap.value, [q.id]: fb }
|
||||
feedback.value = fb
|
||||
} catch (e) {
|
||||
MessagePlugin.error(apiErrorMessage(e, '判分失败,请稍后重试'))
|
||||
} finally {
|
||||
confirming.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const emitSubmit = () => {
|
||||
emit('submit', { answers: answers.value })
|
||||
}
|
||||
|
||||
// 提交答卷:未答完时应用内确认(嵌入式环境下原生 confirm 可能被吞),确认后向上提交
|
||||
const onSubmitClick = () => {
|
||||
const unanswered = props.questions.length - answeredCount.value
|
||||
if (unanswered <= 0) {
|
||||
emitSubmit()
|
||||
return
|
||||
}
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: '确认提交答卷',
|
||||
body: `还有 ${unanswered} 题未作答,未答题目按错题计。确定提交答卷?提交后将记录本次答题成绩并同步课程考试状态。`,
|
||||
confirmBtn: { content: '提交答卷', theme: 'primary' },
|
||||
cancelBtn: '继续作答',
|
||||
onConfirm: () => {
|
||||
dialog.destroy()
|
||||
emitSubmit()
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
// 实时统计条
|
||||
.take-stats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
font-size: var(--app-text-sm);
|
||||
|
||||
&__item {
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
&.is-good { color: var(--td-success-color); font-weight: 600; }
|
||||
&.is-bad { color: var(--td-error-color); font-weight: 600; }
|
||||
}
|
||||
}
|
||||
|
||||
// 题号导航(可跳转任意一题)
|
||||
.take-nav {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin: 10px 0 4px;
|
||||
max-height: 108px;
|
||||
overflow-y: auto;
|
||||
|
||||
&__item {
|
||||
min-width: 30px;
|
||||
height: 26px;
|
||||
padding: 0 6px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: var(--td-bg-color-container);
|
||||
color: var(--td-text-color-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-sm);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { border-color: var(--td-brand-color); color: var(--td-brand-color); }
|
||||
|
||||
&.is-answered {
|
||||
background: var(--td-brand-color-1, rgba(0, 82, 217, 0.08));
|
||||
border-color: var(--td-brand-color);
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&.is-good {
|
||||
background: var(--td-success-color-1, rgba(0, 168, 112, 0.1));
|
||||
border-color: var(--td-success-color);
|
||||
color: var(--td-success-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.is-bad {
|
||||
background: var(--td-error-color-1, rgba(227, 77, 89, 0.1));
|
||||
border-color: var(--td-error-color);
|
||||
color: var(--td-error-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.is-current {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.take-question {
|
||||
margin-top: 10px;
|
||||
padding: 10px 4px;
|
||||
border-bottom: 1px solid var(--td-component-border);
|
||||
|
||||
&__stem { font-weight: 600; }
|
||||
&__score { color: var(--td-text-color-placeholder); font-weight: 400; margin-left: 6px; }
|
||||
&__options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
&__opt {
|
||||
align-items: flex-start;
|
||||
|
||||
&.is-correct :deep(.t-radio__label),
|
||||
&.is-correct :deep(.t-checkbox__label) { color: var(--td-success-color); font-weight: 600; }
|
||||
&.is-wrong :deep(.t-radio__label),
|
||||
&.is-wrong :deep(.t-checkbox__label) { color: var(--td-error-color); }
|
||||
}
|
||||
}
|
||||
|
||||
// 即时反馈:作答确认后展示对错/正确答案/解析
|
||||
.take-feedback {
|
||||
margin-top: 10px;
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
font-size: var(--app-text-md);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
|
||||
&.is-good {
|
||||
background: var(--td-success-color-1, rgba(0, 168, 112, 0.08));
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.is-bad {
|
||||
background: var(--td-error-color-1, rgba(227, 77, 89, 0.08));
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
|
||||
&__verdict { font-weight: 600; }
|
||||
&__answer { color: var(--td-text-color-primary); }
|
||||
&__analysis { color: var(--td-text-color-secondary); }
|
||||
}
|
||||
|
||||
// 翻页与交卷
|
||||
.take-pager {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
margin-top: 14px;
|
||||
|
||||
&__locked {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.take-submit-hint {
|
||||
margin-right: auto;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,636 @@
|
||||
<template>
|
||||
<div class="sign-panel">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">课堂签到与佐证</span>
|
||||
<t-select
|
||||
v-model="selectedSessionId"
|
||||
filterable
|
||||
placeholder="选择课程场次"
|
||||
style="width: 360px"
|
||||
@change="loadSessionData"
|
||||
>
|
||||
<t-option
|
||||
v-for="s in sessions"
|
||||
:key="s.id"
|
||||
:value="s.id"
|
||||
:label="`${courseName(s.course_id)} · ${fmtTime(s.start_at)}`"
|
||||
/>
|
||||
</t-select>
|
||||
</div>
|
||||
|
||||
<template v-if="selectedSessionId">
|
||||
<!-- 签到码 + 统计卡片 -->
|
||||
<div class="sign-top">
|
||||
<div class="sign-code-box">
|
||||
<div class="sign-code-box__title">课堂签到码</div>
|
||||
<div class="sign-code-box__token">{{ signCode?.token || '尚未生成' }}</div>
|
||||
<div class="sign-code-box__meta" v-if="signCode">
|
||||
有效期至 {{ fmtTime(signCode.expire_at) }}
|
||||
<template v-if="signCode.geo_radius"> · 定位半径 {{ signCode.geo_radius }}m</template>
|
||||
</div>
|
||||
<t-button v-if="canReview" theme="primary" variant="outline" :loading="genLoading" @click="onGenCode">
|
||||
{{ signCode ? '刷新签到码' : '生成签到码' }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="stat-cards">
|
||||
<div class="stat-card"><div class="stat-card__label">应到(人)</div><div class="stat-card__value">{{ summary?.expected ?? '—' }}</div></div>
|
||||
<div class="stat-card"><div class="stat-card__label">已签到</div><div class="stat-card__value tone-good">{{ summary?.signed ?? '—' }}</div></div>
|
||||
<div class="stat-card"><div class="stat-card__label">迟到</div><div class="stat-card__value tone-warn">{{ summary?.late ?? '—' }}</div></div>
|
||||
<div class="stat-card"><div class="stat-card__label">异常待复核</div><div class="stat-card__value tone-bad">{{ summary?.abnormal ?? '—' }}</div></div>
|
||||
<!-- 培训佐证上传:签到照(可多选)/培训视频,点击卡片选择文件 -->
|
||||
<template v-if="canUpload">
|
||||
<div class="stat-card upload-card" :class="{ 'is-uploading': uploading }" role="button" tabindex="0" @click="!uploading && photoInput?.click()" @keydown.enter="!uploading && photoInput?.click()">
|
||||
<div class="stat-card__label">上传签到照</div>
|
||||
<div class="upload-card__main">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="9" cy="10" r="1.6"/><path d="m5 19 5.2-5.2a1.4 1.4 0 0 1 2 0L17 18.5"/><path d="M14.5 15.5 16 14a1.4 1.4 0 0 1 2 0l3 3"/><path d="M12 2v4M10 4h4"/></svg>
|
||||
<span>已归档 {{ evidenceCount('sign_photo') }} 张</span>
|
||||
</div>
|
||||
<div class="upload-card__hint">{{ uploading ? '上传中…' : '现场拍照上传 · 每张 ≤ ' + PHOTO_MAX_MB + 'MB' }}</div>
|
||||
</div>
|
||||
<div class="stat-card upload-card" :class="{ 'is-uploading': uploading }" role="button" tabindex="0" @click="!uploading && videoInput?.click()" @keydown.enter="!uploading && videoInput?.click()">
|
||||
<div class="stat-card__label">上传培训视频</div>
|
||||
<div class="upload-card__main">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="12" rx="2"/><path d="m10 8.6 4 2.4-4 2.4z"/><path d="M8 21h8M12 17v4"/><path d="M12 1v2"/></svg>
|
||||
<span>已归档 {{ evidenceCount('training_video') }} 个</span>
|
||||
</div>
|
||||
<div class="upload-card__hint">{{ uploading ? '上传中…' : '课程实录留证 · 每个 ≤ ' + VIDEO_MAX_MB + 'MB' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<input ref="photoInput" type="file" accept="image/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'sign_photo')" />
|
||||
<input ref="videoInput" type="file" accept="video/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'training_video')" />
|
||||
</div>
|
||||
|
||||
<!-- 佐证文件列表:在线预览(照片/视频)与删除 -->
|
||||
<div v-if="evidences.length" class="evidence-files">
|
||||
<div class="records-header">
|
||||
<span class="records-header__title">培训佐证文件</span>
|
||||
</div>
|
||||
<div class="evidence-files__list">
|
||||
<div v-for="ev in evidences" :key="ev.id" class="evidence-file">
|
||||
<span class="evidence-file__icon" :class="`is-${ev.kind}`">
|
||||
<svg v-if="ev.kind === 'sign_photo'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="9" cy="10" r="1.6"/><path d="m5 19 5.2-5.2a1.4 1.4 0 0 1 2 0L17 18.5"/><path d="M14.5 15.5 16 14a1.4 1.4 0 0 1 2 0l3 3"/></svg>
|
||||
<svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="12" rx="2"/><path d="m10 8.6 4 2.4-4 2.4z"/><path d="M8 21h8M12 17v4"/></svg>
|
||||
</span>
|
||||
<div class="evidence-file__meta">
|
||||
<span class="evidence-file__name" :title="ev.name">{{ ev.name }}</span>
|
||||
<span class="evidence-file__sub">{{ ev.kind === 'sign_photo' ? '签到照' : '培训视频' }} · {{ fmtSize(ev.size) }} · {{ fmtTime(ev.created_at) }}</span>
|
||||
</div>
|
||||
<t-button variant="text" theme="primary" size="small" @click="onPreviewEvidence(ev)">预览</t-button>
|
||||
<t-popconfirm v-if="canUpload" content="确定删除该佐证文件?" theme="danger" @confirm="onDeleteEvidence(ev)">
|
||||
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 签到明细 -->
|
||||
<div class="records-header">
|
||||
<span class="records-header__title">签到明细</span>
|
||||
<t-button v-if="canReview && signCode" variant="outline" size="small" @click="proxyVisible = true">代扫码 / 补录</t-button>
|
||||
</div>
|
||||
<t-table :data="records" :columns="recordColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #member="{ row }">{{ memberLabel(row.member_id) }}</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="statusTheme(row.status)" variant="light" size="small">{{ statusText(row.status) }}</t-tag>
|
||||
<t-tag v-for="f in row.abnormal_flags || []" :key="f" theme="danger" variant="outline" size="small" class="flag-tag">{{ flagText(f) }}</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<template v-if="canReview && row.status !== 'normal'">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onReview(row, 'confirm')">确认</t-button>
|
||||
<t-button variant="text" theme="danger" size="small" @click="onReview(row, 'reject')">驳回</t-button>
|
||||
</template>
|
||||
</template>
|
||||
</t-table>
|
||||
|
||||
<!-- 代扫码 / 补录:走同一防伪规则引擎,proxy 标记留痕 -->
|
||||
<t-dialog v-model:visible="proxyVisible" header="代扫码 / 现场补录" width="460">
|
||||
<t-form label-width="90">
|
||||
<t-form-item label="学员" required>
|
||||
<t-select v-model="proxyMemberId" filterable placeholder="选择要补录的学员" style="width: 100%">
|
||||
<t-option v-for="m in members" :key="m.id" :value="m.id" :label="memberLabelText(m)" />
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<div class="form-hint">代录与本人扫码走同一校验(有效期/名单/定位/迟到),记录带 proxy 标记可追溯。</div>
|
||||
<template #footer>
|
||||
<t-button theme="primary" :loading="proxyLoading" :disabled="!proxyMemberId" @click="onProxyCheckin">完成签到</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 佐证预览:照片直接展示,视频 blob 播放 -->
|
||||
<t-dialog v-model:visible="previewVisible" :header="previewEvidence?.name || '佐证预览'" width="720">
|
||||
<div class="preview-box">
|
||||
<t-loading :loading="previewLoading" class="preview-box__wrap">
|
||||
<img v-if="previewEvidence?.kind === 'sign_photo' && previewUrl" :src="previewUrl" class="preview-box__img" alt="签到照" />
|
||||
<video v-else-if="previewEvidence?.kind === 'training_video' && previewUrl" :src="previewUrl" class="preview-box__video" controls playsinline />
|
||||
<t-empty v-else-if="!previewLoading" description="文件加载失败" />
|
||||
</t-loading>
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button variant="outline" @click="previewVisible = false">关闭</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 佐证导出 -->
|
||||
<div class="evidence-bar">
|
||||
<div>
|
||||
<div class="evidence-bar__title">一键导出 · 请款佐证包</div>
|
||||
<div class="muted">导出字段:部门 · 工号 · 姓名 · 签到时间 · 讲师姓名 · 课程名称 · 上课时间 · 学员考试成绩</div>
|
||||
</div>
|
||||
<t-button theme="primary" :loading="exportLoading" @click="onExport">导出佐证包(Excel)</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<t-empty v-else description="请选择课程场次查看签到情况" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
checkin,
|
||||
createSignCode,
|
||||
deleteSessionEvidence,
|
||||
downloadSessionEvidenceFile,
|
||||
exportEvidence,
|
||||
getSignCode,
|
||||
getSignSummary,
|
||||
listCourses,
|
||||
listMembers,
|
||||
listSessions,
|
||||
listSessionEvidence,
|
||||
listSignRecords,
|
||||
reviewSignRecord,
|
||||
uploadSessionEvidence,
|
||||
type SignSummary,
|
||||
type TrainingCourse,
|
||||
type TrainingCourseSession,
|
||||
type TrainingMember,
|
||||
type TrainingSessionEvidence,
|
||||
type TrainingSignCode,
|
||||
type TrainingSignRecord,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
// 签到复核/代签:人事/课长(roles 已按权限组展开,经理自动命中)
|
||||
const canReview = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor'))
|
||||
// 佐证上传/删除:人事/课长/讲师(与课件上传同口径)
|
||||
const canUpload = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'lecturer'))
|
||||
|
||||
// 客户端预检上限提示(服务端同口径硬限制:文档 50MB/视频 200MB)
|
||||
const PHOTO_MAX_MB = 50
|
||||
const VIDEO_MAX_MB = 200
|
||||
|
||||
const loading = ref(false)
|
||||
const genLoading = ref(false)
|
||||
const exportLoading = ref(false)
|
||||
const sessions = ref<TrainingCourseSession[]>([])
|
||||
const courses = ref<TrainingCourse[]>([])
|
||||
const selectedSessionId = ref('')
|
||||
const signCode = ref<TrainingSignCode | null>(null)
|
||||
const summary = ref<SignSummary | null>(null)
|
||||
const records = ref<TrainingSignRecord[]>([])
|
||||
|
||||
const recordColumns = [
|
||||
{ colKey: 'member', title: '学员', width: 220 },
|
||||
{ colKey: 'signed_at', title: '签到时间', width: 170 },
|
||||
{ colKey: 'channel', title: '方式', width: 110 },
|
||||
{ colKey: 'distance_m', title: '定位距离(m)', width: 110 },
|
||||
{ colKey: 'status', title: '状态' },
|
||||
{ colKey: 'op', title: '操作', width: 140 },
|
||||
]
|
||||
|
||||
const statusText = (s: string) => ({
|
||||
normal: '已签到', late: '迟到', abnormal: '待复核', outside: '定位异常', duplicate: '重复扫码', missing: '未签到',
|
||||
}[s] || s)
|
||||
|
||||
const statusTheme = (s: string) => ({
|
||||
normal: 'success', late: 'warning', abnormal: 'danger', outside: 'danger', duplicate: 'danger', missing: 'default',
|
||||
}[s] || 'default')
|
||||
|
||||
const flagText = (f: string) => ({ late: '迟到', outside: '定位异常', not_in_roster: '名单外' }[f] || f)
|
||||
|
||||
const courseName = (courseId: string) => courses.value.find((c) => c.id === courseId)?.name || '课程'
|
||||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
|
||||
|
||||
const memberLabels = ref<Record<string, string>>({})
|
||||
const members = ref<TrainingMember[]>([])
|
||||
const proxyVisible = ref(false)
|
||||
const proxyMemberId = ref('')
|
||||
const proxyLoading = ref(false)
|
||||
|
||||
const memberLabel = (memberId: string) => memberLabels.value[memberId] || memberId
|
||||
const memberLabelText = (m: TrainingMember) => {
|
||||
const role = (m.post || '').trim()
|
||||
return `${m.employee_no || '-'} ${role ? ` · ${role}` : ''}`
|
||||
}
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [s, c, m] = await Promise.all([
|
||||
listSessions({ page_size: 200 }),
|
||||
listCourses({ page_size: 200 }),
|
||||
listMembers({ page_size: 500 }).catch(() => null),
|
||||
])
|
||||
sessions.value = unwrap(s) || []
|
||||
courses.value = unwrap(c)?.items || []
|
||||
const memberItems = (m && unwrap(m)?.items) || []
|
||||
if (memberItems.length) {
|
||||
members.value = memberItems
|
||||
const labels: Record<string, string> = {}
|
||||
const deptNames: Record<string, string> = {}
|
||||
for (const mem of members.value) {
|
||||
labels[mem.id] = `${mem.employee_no || '-'} ${mem.post || ''}`.trim() || mem.id.slice(0, 8)
|
||||
if (mem.dept_id) deptNames[mem.dept_id] = deptNames[mem.dept_id] || ''
|
||||
}
|
||||
memberLabels.value = labels
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadSessionData = async () => {
|
||||
if (!selectedSessionId.value) return
|
||||
const sid = selectedSessionId.value
|
||||
try {
|
||||
const [code, sum, recs, evs] = await Promise.all([
|
||||
getSignCode(sid).catch(() => null),
|
||||
getSignSummary(sid).catch(() => null),
|
||||
listSignRecords(sid),
|
||||
listSessionEvidence(sid).catch(() => null),
|
||||
])
|
||||
signCode.value = unwrap(code) || null
|
||||
summary.value = unwrap(sum) || null
|
||||
records.value = unwrap(recs) || []
|
||||
evidences.value = (evs && unwrap(evs)) || []
|
||||
} catch {
|
||||
records.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 培训佐证文件(签到照/培训视频) ----
|
||||
const evidences = ref<TrainingSessionEvidence[]>([])
|
||||
const photoInput = ref<HTMLInputElement | null>(null)
|
||||
const videoInput = ref<HTMLInputElement | null>(null)
|
||||
const uploading = ref(false)
|
||||
|
||||
const evidenceCount = (kind: TrainingSessionEvidence['kind']) =>
|
||||
evidences.value.filter((e) => e.kind === kind).length
|
||||
|
||||
const fmtSize = (size: number) => {
|
||||
if (!size) return '-'
|
||||
return size >= 1024 * 1024 ? `${(size / 1024 / 1024).toFixed(1)}MB` : `${Math.ceil(size / 1024)}KB`
|
||||
}
|
||||
|
||||
const onEvidenceFiles = async (e: Event, kind: TrainingSessionEvidence['kind']) => {
|
||||
const input = e.target as HTMLInputElement
|
||||
const files = Array.from(input.files || [])
|
||||
input.value = ''
|
||||
if (!files.length || !selectedSessionId.value) return
|
||||
const limitMB = kind === 'sign_photo' ? PHOTO_MAX_MB : VIDEO_MAX_MB
|
||||
const oversize = files.filter((f) => f.size > limitMB * 1024 * 1024)
|
||||
if (oversize.length) {
|
||||
MessagePlugin.warning(`文件大小不能超过${limitMB}MB:${oversize.map((f) => f.name).join('、')}`)
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
let ok = 0
|
||||
let fail = 0
|
||||
try {
|
||||
for (const file of files) {
|
||||
try {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
fd.append('kind', kind)
|
||||
fd.append('name', file.name)
|
||||
await uploadSessionEvidence(selectedSessionId.value, fd)
|
||||
ok += 1
|
||||
} catch {
|
||||
fail += 1
|
||||
}
|
||||
}
|
||||
if (ok) MessagePlugin.success(`已上传 ${ok} 个${kind === 'sign_photo' ? '签到照' : '培训视频'}并归档到场次佐证`)
|
||||
if (fail) MessagePlugin.error(`${fail} 个文件上传失败,请稍后重试`)
|
||||
await loadSessionData()
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const previewVisible = ref(false)
|
||||
const previewLoading = ref(false)
|
||||
const previewEvidence = ref<TrainingSessionEvidence | null>(null)
|
||||
const previewUrl = ref('')
|
||||
let previewObjectUrl = ''
|
||||
|
||||
const onPreviewEvidence = async (ev: TrainingSessionEvidence) => {
|
||||
previewEvidence.value = ev
|
||||
previewUrl.value = ''
|
||||
previewVisible.value = true
|
||||
previewLoading.value = true
|
||||
try {
|
||||
const blob = await downloadSessionEvidenceFile(ev.id)
|
||||
previewObjectUrl = URL.createObjectURL(blob)
|
||||
previewUrl.value = previewObjectUrl
|
||||
} catch {
|
||||
previewUrl.value = ''
|
||||
} finally {
|
||||
previewLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onDeleteEvidence = async (ev: TrainingSessionEvidence) => {
|
||||
try {
|
||||
await deleteSessionEvidence(ev.id)
|
||||
MessagePlugin.success('佐证文件已删除')
|
||||
loadSessionData()
|
||||
} catch {
|
||||
MessagePlugin.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
const onGenCode = async () => {
|
||||
genLoading.value = true
|
||||
try {
|
||||
const res = await createSignCode(selectedSessionId.value)
|
||||
signCode.value = unwrap(res) || null
|
||||
MessagePlugin.success('签到码已生成,学员企微扫码/点击链接即可签到')
|
||||
} catch {
|
||||
MessagePlugin.error('生成失败')
|
||||
} finally {
|
||||
genLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onReview = async (row: TrainingSignRecord, decision: 'confirm' | 'reject') => {
|
||||
try {
|
||||
await reviewSignRecord(row.id, decision)
|
||||
MessagePlugin.success(decision === 'confirm' ? '已确认签到有效' : '已维持异常标记')
|
||||
loadSessionData()
|
||||
} catch {
|
||||
MessagePlugin.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const onProxyCheckin = async () => {
|
||||
if (!signCode.value || !proxyMemberId.value) return
|
||||
proxyLoading.value = true
|
||||
try {
|
||||
await checkin(signCode.value.token, 0, 0, 'proxy', proxyMemberId.value)
|
||||
MessagePlugin.success('代录签到完成')
|
||||
proxyVisible.value = false
|
||||
proxyMemberId.value = ''
|
||||
loadSessionData()
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.response?.data?.message || '代录失败')
|
||||
} finally {
|
||||
proxyLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onExport = async () => {
|
||||
exportLoading.value = true
|
||||
try {
|
||||
const res = await exportEvidence([selectedSessionId.value])
|
||||
const blob = new Blob([res.data as unknown as BlobPart], {
|
||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
})
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `training_evidence_${new Date().toISOString().slice(0, 10)}.xlsx`
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
MessagePlugin.success('佐证包已导出')
|
||||
} catch {
|
||||
MessagePlugin.error('导出失败')
|
||||
} finally {
|
||||
exportLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
|
||||
&__header {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.sign-top {
|
||||
display: grid;
|
||||
grid-template-columns: 280px 1fr;
|
||||
gap: 12px;
|
||||
margin-bottom: 14px;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.sign-code-box {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border: 1px dashed var(--td-component-border);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 14px;
|
||||
text-align: center;
|
||||
|
||||
&__title { font-weight: 600; }
|
||||
&__token {
|
||||
margin: 10px 0;
|
||||
font-family: monospace;
|
||||
font-size: var(--app-text-md);
|
||||
word-break: break-all;
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: var(--app-radius-sm);
|
||||
padding: 8px;
|
||||
}
|
||||
&__meta { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); margin-bottom: 10px; }
|
||||
}
|
||||
|
||||
.stat-cards {
|
||||
.training-stat-cards();
|
||||
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
.training-stat-card();
|
||||
}
|
||||
|
||||
// 佐证上传卡片:点击选择文件,与统计卡片同区栅格
|
||||
.upload-card {
|
||||
cursor: pointer;
|
||||
transition: box-shadow var(--app-motion-fast) ease, transform var(--app-motion-fast) ease;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--app-shadow-1, 0 6px 16px rgba(0, 0, 0, 0.08));
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
&.is-uploading {
|
||||
opacity: 0.6;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&__main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 10px 0 6px;
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 600;
|
||||
|
||||
svg {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
}
|
||||
|
||||
&__hint {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
// 隐藏的文件选择 input(卡片点击触发)
|
||||
.visually-hidden-input {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
// 佐证文件列表
|
||||
.evidence-files {
|
||||
margin-bottom: 14px;
|
||||
|
||||
&__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.evidence-file {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
|
||||
&__icon {
|
||||
display: inline-flex;
|
||||
color: var(--td-brand-color);
|
||||
|
||||
svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
&.is-training_video {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
}
|
||||
|
||||
&__meta {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
&__name {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__sub {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
// 佐证预览弹窗
|
||||
.preview-box {
|
||||
&__wrap {
|
||||
display: block;
|
||||
min-height: 160px;
|
||||
}
|
||||
|
||||
&__img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
max-height: 60vh;
|
||||
margin: 0 auto;
|
||||
border-radius: var(--app-radius-md);
|
||||
}
|
||||
|
||||
&__video {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-height: 60vh;
|
||||
border-radius: var(--app-radius-md);
|
||||
background: #000;
|
||||
}
|
||||
}
|
||||
|
||||
.tone-good { color: var(--td-success-color); }
|
||||
.tone-warn { color: var(--td-warning-color); }
|
||||
.tone-bad { color: var(--td-error-color); }
|
||||
|
||||
.flag-tag { margin-left: 4px; }
|
||||
|
||||
.evidence-bar {
|
||||
margin-top: 14px;
|
||||
background: var(--td-brand-color-1, rgba(0, 82, 217, 0.06));
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 14px 16px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
&__title { font-weight: 600; margin-bottom: 2px; }
|
||||
}
|
||||
|
||||
.muted { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); }
|
||||
|
||||
.records-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
|
||||
&__title { font-weight: 600; }
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
margin-top: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,322 @@
|
||||
<template>
|
||||
<div class="study-panel">
|
||||
<!-- 顶部页签:我的课程学习 / 课程学习情况 / 课程考试情况 / AI课程分析 -->
|
||||
<div class="study-tabbar">
|
||||
<div class="study-tabs" role="tablist" aria-label="学习考试分区">
|
||||
<button
|
||||
v-for="tab in visibleTabs"
|
||||
:key="tab.key"
|
||||
type="button"
|
||||
role="tab"
|
||||
class="study-tab"
|
||||
:aria-selected="activeSection === tab.key"
|
||||
@click="activeSection = tab.key"
|
||||
>{{ tab.title }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- A. 我的课程学习:我的学习/考试/错题/画像 四宫格(所有人可见) -->
|
||||
<div v-if="isVisited('mine')" v-show="activeSection === 'mine'" class="panel-grid">
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的学习任务</span>
|
||||
<span class="panel-box__sub">点击课程名进入学习,进度 ≥95% 自动完成</span>
|
||||
</div>
|
||||
<t-table :data="tasks" :columns="taskColumns" row-key="id" size="small">
|
||||
<template #course_name="{ row }">
|
||||
<a class="task-course-link" @click="goCourse(row.course_id)">{{ row.course_name }}</a>
|
||||
</template>
|
||||
<template #deadline="{ row }">{{ fmtTime(row.deadline) }}</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="taskTheme(row.status)" variant="light" size="small">{{ taskText(row.status) }}</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!tasks.length" description="暂无学习任务,课程发布后将自动生成" />
|
||||
</div>
|
||||
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的考试成绩</span>
|
||||
</div>
|
||||
<t-table :data="myRecords" :columns="myRecordColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #course_name="{ row }">{{ row.course_name || row.paper_name || '-' }}</template>
|
||||
<template #score="{ row }">
|
||||
<span :class="passClass(row)">{{ row.score ?? '—' }}</span>
|
||||
</template>
|
||||
<template #pass_line="{ row }">{{ row.pass_score || '-' }} / {{ row.total_score || '-' }}</template>
|
||||
<template #submitted_at="{ row }">{{ fmtTime(row.submitted_at) }}</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!myRecords.length" description="暂无考试记录,参加随堂考试后此处展示成绩" />
|
||||
</div>
|
||||
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的错题本</span>
|
||||
</div>
|
||||
<t-table :data="wrongBook" :columns="wrongColumns" row-key="id" size="small">
|
||||
<template #knowledge_point="{ row }">
|
||||
<t-tag v-if="row.knowledge_point" variant="light" size="small">{{ row.knowledge_point }}</t-tag>
|
||||
<span v-else>—</span>
|
||||
</template>
|
||||
<template #mastered="{ row }">
|
||||
<t-tag :theme="row.mastered ? 'success' : 'warning'" variant="light" size="small">
|
||||
{{ row.mastered ? '已掌握' : '待巩固' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-empty v-if="!wrongBook.length" description="错题本为空,继续保持" />
|
||||
</div>
|
||||
|
||||
<div class="panel-box">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的能力画像</span>
|
||||
</div>
|
||||
<div v-if="profile" class="profile-grid">
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">岗位胜任度</div>
|
||||
<div class="profile-item__value" :class="profile.competency >= profile.pass_line ? 'tone-good' : 'tone-bad'">
|
||||
{{ profile.competency }} 分
|
||||
</div>
|
||||
<div class="profile-item__sub">达标线 {{ profile.pass_line }} 分</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">累计积分</div>
|
||||
<div class="profile-item__value">{{ profile.points }}</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">平均成绩</div>
|
||||
<div class="profile-item__value">{{ profile.avg_score }}</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">学习时长</div>
|
||||
<div class="profile-item__value">{{ profile.study_hours }} h</div>
|
||||
</div>
|
||||
<div class="profile-item">
|
||||
<div class="profile-item__label">课程数</div>
|
||||
<div class="profile-item__value">{{ profile.course_count }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<t-empty v-else description="暂无画像数据" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- B. 课程学习情况(人事/文员/讲师):课程选择 + 状态汇总 + 条件查询 -->
|
||||
<CourseLearningStatus
|
||||
v-if="canManage && isVisited('learning')"
|
||||
v-show="activeSection === 'learning'"
|
||||
:initial-course-id="initialCourseId"
|
||||
/>
|
||||
|
||||
<!-- C. 课程考试情况(人事/文员/讲师):成绩汇总查询 + 班级薄弱点 -->
|
||||
<ExamPanel
|
||||
v-if="canManage && isVisited('exam')"
|
||||
v-show="activeSection === 'exam'"
|
||||
:roles="roles"
|
||||
:admin="admin"
|
||||
:initial-course-id="initialCourseId"
|
||||
/>
|
||||
|
||||
<!-- D. AI课程分析:学习/考试/签到/错题汇总分析(全员可见,维度随角色) -->
|
||||
<CourseAIAnalysis
|
||||
v-if="isVisited('ai')"
|
||||
v-show="activeSection === 'ai'"
|
||||
:roles="roles"
|
||||
:admin="admin"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
getMyAbilityProfile,
|
||||
listMyExamRecords,
|
||||
listMyLearningTasks,
|
||||
listWrongBook,
|
||||
type LearningTask,
|
||||
type MyExamRecord,
|
||||
type TrainingProfile,
|
||||
type WrongBookItem,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import CourseLearningStatus from './CourseLearningStatus.vue'
|
||||
import ExamPanel from './ExamPanel.vue'
|
||||
import CourseAIAnalysis from './CourseAIAnalysis.vue'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
// 课程学习/考试情况管理端:人事/课长/讲师(roles 已按权限组展开,经理自动命中)
|
||||
const canManage = computed(() => props.admin || props.roles.some((r) => ['hr', 'supervisor', 'lecturer'].includes(r)))
|
||||
const router = useRouter()
|
||||
|
||||
// ---- 顶部页签(管理页签对纯学员隐藏,与工作台按角色显隐口径一致) ----
|
||||
type StudySection = 'mine' | 'learning' | 'exam' | 'ai'
|
||||
const STUDY_TABS: { key: StudySection; title: string; manageOnly?: boolean }[] = [
|
||||
{ key: 'mine', title: '我的课程学习' },
|
||||
{ key: 'learning', title: '课程学习情况', manageOnly: true },
|
||||
{ key: 'exam', title: '课程考试情况', manageOnly: true },
|
||||
{ key: 'ai', title: 'AI课程分析' },
|
||||
]
|
||||
|
||||
const activeSection = ref<StudySection>('mine')
|
||||
// 首访才挂载页签组件(懒加载),挂载后保活切换不丢状态
|
||||
const visitedSections = ref(new Set<StudySection>(['mine']))
|
||||
const isVisited = (key: StudySection) => visitedSections.value.has(key)
|
||||
|
||||
const visibleTabs = computed(() => STUDY_TABS.filter((t) => !t.manageOnly || canManage.value))
|
||||
|
||||
// 培训课程页状态列跳转:携带 section(learning/exam)与 courseId 查询参数,
|
||||
// 用于直达「课程学习情况/课程考试情况」页签并预选对应课程。
|
||||
const route = useRoute()
|
||||
const initialCourseId = computed(() => String(route.query.courseId || ''))
|
||||
|
||||
const applyRouteSection = () => {
|
||||
const section = String(route.query.section || '')
|
||||
if (!canManage.value || (section !== 'learning' && section !== 'exam')) return
|
||||
activeSection.value = section
|
||||
visitedSections.value.add(section)
|
||||
}
|
||||
|
||||
watch(activeSection, (key) => {
|
||||
visitedSections.value.add(key)
|
||||
})
|
||||
|
||||
// 角色异步加载后若管理页签被收回,视图回落「我的课程学习」;
|
||||
// 角色就绪时再按路由参数重放一次页签定位(培训课程页跳转场景)。
|
||||
watch(canManage, (ok) => {
|
||||
if (!ok) {
|
||||
if (activeSection.value === 'learning' || activeSection.value === 'exam') {
|
||||
activeSection.value = 'mine'
|
||||
}
|
||||
return
|
||||
}
|
||||
applyRouteSection()
|
||||
})
|
||||
|
||||
// 已挂载状态下再次携参跳转(如从培训课程页二次点击)同步页签
|
||||
watch(() => route.query.section, applyRouteSection)
|
||||
|
||||
// ---- A. 我的课程学习数据 ----
|
||||
const loading = ref(false)
|
||||
const tasks = ref<LearningTask[]>([])
|
||||
const myRecords = ref<MyExamRecord[]>([])
|
||||
const wrongBook = ref<WrongBookItem[]>([])
|
||||
const profile = ref<TrainingProfile | null>(null)
|
||||
|
||||
const taskColumns = [
|
||||
{ colKey: 'course_name', title: '课程' },
|
||||
{ colKey: 'deadline', title: '完成期限', width: 160 },
|
||||
{ colKey: 'status', title: '状态', width: 90 },
|
||||
]
|
||||
|
||||
const myRecordColumns = [
|
||||
{ colKey: 'course_name', title: '课程/试卷' },
|
||||
{ colKey: 'score', title: '成绩', width: 70 },
|
||||
{ colKey: 'pass_line', title: '及格/总分', width: 90 },
|
||||
{ colKey: 'submitted_at', title: '交卷时间', width: 160 },
|
||||
]
|
||||
|
||||
const wrongColumns = [
|
||||
{ colKey: 'stem', title: '题干' },
|
||||
{ colKey: 'knowledge_point', title: '知识点', width: 130 },
|
||||
{ colKey: 'wrong_count', title: '错误次数', width: 90 },
|
||||
{ colKey: 'mastered', title: '掌握状态', width: 90 },
|
||||
]
|
||||
|
||||
const taskText = (s: string) => ({ pending: '待学习', doing: '学习中', done: '已完成', overdue: '已逾期' }[s] || s)
|
||||
const taskTheme = (s: string) => ({ pending: 'default', doing: 'primary', done: 'success', overdue: 'danger' }[s] || 'default')
|
||||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
|
||||
|
||||
const passClass = (row: MyExamRecord) => {
|
||||
if (row.score == null) return ''
|
||||
return row.pass_score ? (row.score >= row.pass_score ? 'tone-good' : 'tone-bad') : ''
|
||||
}
|
||||
|
||||
const goCourse = (courseId: string) => {
|
||||
if (courseId) router.push(`/platform/training/course/${courseId}`)
|
||||
}
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [t, r, w, p] = await Promise.all([
|
||||
listMyLearningTasks().catch(() => null),
|
||||
listMyExamRecords().catch(() => null),
|
||||
listWrongBook().catch(() => null),
|
||||
getMyAbilityProfile().catch(() => null),
|
||||
])
|
||||
tasks.value = (t && unwrap(t)) || []
|
||||
myRecords.value = (r && unwrap(r)) || []
|
||||
wrongBook.value = (w && unwrap(w)) || []
|
||||
profile.value = (p && unwrap(p)) || null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
applyRouteSection()
|
||||
loadAll()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
// 顶部页签条(与培训计划页同款交互:底部描边 + 品牌色下划线)
|
||||
.study-tabbar {
|
||||
.training-tabbar();
|
||||
}
|
||||
|
||||
.study-tabs {
|
||||
.training-tabs();
|
||||
}
|
||||
|
||||
.study-tab {
|
||||
.training-tab();
|
||||
}
|
||||
|
||||
.panel-grid {
|
||||
.training-panel-grid();
|
||||
}
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
|
||||
&__sub {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.task-course-link {
|
||||
color: var(--td-brand-color);
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.profile-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.profile-item {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 12px 14px;
|
||||
text-align: center;
|
||||
|
||||
&__label { color: var(--td-text-color-secondary); font-size: var(--app-text-md); }
|
||||
&__value { font-size: 22px; font-weight: 700; margin-top: 4px; }
|
||||
&__sub { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); margin-top: 2px; }
|
||||
}
|
||||
|
||||
.tone-good { color: var(--td-success-color); }
|
||||
.tone-bad { color: var(--td-error-color); }
|
||||
</style>
|
||||
@@ -0,0 +1,178 @@
|
||||
<script lang="ts">
|
||||
// 课件登记取值(普通 script 块导出类型,<script setup> 内不允许 export 语句)
|
||||
export interface MaterialPickerValue {
|
||||
mode: 'upload' | 'library' | 'name'
|
||||
file: File | null
|
||||
knowledgeId: string
|
||||
name: string
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="material-picker">
|
||||
<t-radio-group :value="model.mode" size="small" @change="onModeChange">
|
||||
<t-radio-button value="upload">上传课件</t-radio-button>
|
||||
<t-radio-button value="library">从课件库选择</t-radio-button>
|
||||
<t-radio-button value="name">仅登记名称</t-radio-button>
|
||||
</t-radio-group>
|
||||
|
||||
<!-- 上传课件: 保存时自动同步进系统默认「企业培训(课件)」知识库 -->
|
||||
<div v-if="model.mode === 'upload'" class="picker-body">
|
||||
<div class="upload-row">
|
||||
<input ref="fileInputRef" type="file" :accept="ACCEPT" class="upload-input" @change="onFileChange" />
|
||||
<t-button variant="outline" size="small" @click="fileInputRef?.click()">选择文件</t-button>
|
||||
<span v-if="model.file" class="upload-name">{{ model.file.name }}</span>
|
||||
<span v-else class="upload-placeholder">未选择文件</span>
|
||||
</div>
|
||||
<div class="picker-hint">
|
||||
支持 PPT / Word / PDF / Excel / Markdown / 文本等;上传后自动同步知识库「企业培训(课件)」,可在 AI 对话中问答。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 从课件库选择: 列出「企业培训(课件)」知识库已有文档,复用不重复上传 -->
|
||||
<div v-else-if="model.mode === 'library'" class="picker-body">
|
||||
<t-select
|
||||
v-model="model.knowledgeId"
|
||||
filterable
|
||||
clearable
|
||||
:loading="loadingDocs"
|
||||
placeholder="选择课件库中的文档"
|
||||
style="width: 100%"
|
||||
@change="onKnowledgeChange"
|
||||
>
|
||||
<t-option v-for="d in docs" :key="d.id" :value="d.id" :label="d.file_name" />
|
||||
</t-select>
|
||||
<div class="picker-hint">
|
||||
数据来源:知识库「{{ coursewareKb?.name || '企业培训(课件)' }}」{{ docs.length ? `共 ${docs.length} 个文档` : '(暂无文档,可先在知识库上传)' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 仅登记名称: 保持旧行为,不同步知识库(适合暂无文件或视频等场景) -->
|
||||
<div v-else class="picker-body">
|
||||
<t-input :value="model.name" placeholder="课件名称(如 TPM培训课件v3.pptx)" @change="(v: any) => onNameChange(String(v ?? ''))" />
|
||||
<div class="picker-hint">仅登记课件名称,不同步知识库。</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import {
|
||||
getTrainingKnowledgeBases,
|
||||
type TrainingKnowledgeBaseRef,
|
||||
type TrainingKnowledgeBases,
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { get } from '@/utils/request'
|
||||
|
||||
// 与知识库文件上传支持格式保持一致(视频暂不支持同步知识库,走「仅登记名称」)
|
||||
const ACCEPT = '.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.csv,.md,.txt,.html'
|
||||
|
||||
const model = defineModel<MaterialPickerValue>({ required: true })
|
||||
|
||||
const fileInputRef = ref<HTMLInputElement | null>(null)
|
||||
const coursewareKb = ref<TrainingKnowledgeBaseRef | null>(null)
|
||||
const docs = ref<{ id: string; file_name: string }[]>([])
|
||||
const loadingDocs = ref(false)
|
||||
let docsLoaded = false
|
||||
|
||||
// 切换模式时清空其它模式的取值,避免保存时混入脏数据
|
||||
const onModeChange = (value: unknown) => {
|
||||
const mode = value as MaterialPickerValue['mode']
|
||||
model.value = { mode, file: null, knowledgeId: '', name: '' }
|
||||
if (mode === 'library') {
|
||||
void loadLibraryDocs()
|
||||
}
|
||||
}
|
||||
|
||||
const onFileChange = (e: Event) => {
|
||||
const input = e.target as HTMLInputElement
|
||||
const file = input.files?.[0] || null
|
||||
model.value = { ...model.value, file, name: file?.name || '' }
|
||||
}
|
||||
|
||||
const onKnowledgeChange = (knowledgeId: unknown) => {
|
||||
const id = String(knowledgeId || '')
|
||||
const doc = docs.value.find((d) => d.id === id)
|
||||
model.value = { ...model.value, knowledgeId: id, name: doc?.file_name || '' }
|
||||
}
|
||||
|
||||
const onNameChange = (name: string) => {
|
||||
model.value = { ...model.value, name }
|
||||
}
|
||||
|
||||
// 拉取「企业培训(课件)」默认知识库与其文档列表(惰性加载一次)
|
||||
const loadLibraryDocs = async () => {
|
||||
if (docsLoaded) return
|
||||
loadingDocs.value = true
|
||||
try {
|
||||
if (!coursewareKb.value) {
|
||||
const res = await getTrainingKnowledgeBases()
|
||||
coursewareKb.value = unwrap<TrainingKnowledgeBases>(res)?.courseware || null
|
||||
}
|
||||
if (coursewareKb.value?.id) {
|
||||
const res: any = await get(
|
||||
`/api/v1/knowledge-bases/${encodeURIComponent(coursewareKb.value.id)}/knowledge?page=1&page_size=200`,
|
||||
)
|
||||
const body = res?.data ?? res
|
||||
docs.value = (Array.isArray(body) ? body : body?.items || []).map((it: any) => ({
|
||||
id: String(it.id),
|
||||
file_name: it.file_name || it.title || it.id,
|
||||
}))
|
||||
}
|
||||
docsLoaded = true
|
||||
} catch {
|
||||
docs.value = []
|
||||
} finally {
|
||||
loadingDocs.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 预取默认知识库摘要,保证「从课件库选择」即点即用
|
||||
void loadLibraryDocs()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training.less';
|
||||
|
||||
.material-picker {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.picker-body {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.picker-hint {
|
||||
margin-top: 4px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.upload-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-height: 32px;
|
||||
|
||||
.upload-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.upload-name {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-sm);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.upload-placeholder {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<div class="workbench-panel">
|
||||
<!-- 课程目录(全员可见,默认视图) -->
|
||||
<CourseCatalog v-if="activeView === 'course'" :roles="roles" :admin="admin" />
|
||||
<!-- 个人成长 GROWTH OS(全员可见) -->
|
||||
<GrowthPanel v-else-if="activeView === 'growth'" />
|
||||
<!-- 数据驾驶舱(培训管理角色可见,由页头页签控制入口) -->
|
||||
<DashboardPanel v-else-if="activeView === 'dashboard'" :roles="roles" :admin="admin" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import CourseCatalog from './CourseCatalog.vue'
|
||||
import GrowthPanel from './GrowthPanel.vue'
|
||||
import DashboardPanel from './DashboardPanel.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
roles: string[]
|
||||
admin?: boolean
|
||||
/** 工作台当前视图:course(默认) / growth / dashboard */
|
||||
tab?: string
|
||||
}>()
|
||||
|
||||
// 驾驶舱可见口径与页头页签一致:培训管理角色(人事/课长/经理)或空间管理员
|
||||
const canSeeDashboard = computed(
|
||||
() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'exec'),
|
||||
)
|
||||
|
||||
// 兜底:无权限时 dashboard 视图回落到课程目录,避免越权渲染
|
||||
const activeView = computed(() => {
|
||||
if (props.tab === 'growth') return 'growth'
|
||||
if (props.tab === 'dashboard' && canSeeDashboard.value) return 'dashboard'
|
||||
return 'course'
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,242 @@
|
||||
// 企业培训模块共享样式 mixin。
|
||||
// 与「AI助理 / 知识库 / 工具箱」等页面保持同一套视觉语言:
|
||||
// 页面容器 .resource-list-content、卡片 .resource-card 规范、工具箱式横向页签。
|
||||
@import (reference) '@/components/css/resource-card.less';
|
||||
|
||||
// 页面容器:与知识库 / 工具箱页同款(统一内边距与滚动结构)
|
||||
.training-page-frame() {
|
||||
.resource-list-content();
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
// 页头:24px 资源图标 + 页签名称 + 角色标签,下配副标题(同知识库页头层级)
|
||||
.training-header() {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-bottom: 12px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.training-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--app-space-4);
|
||||
}
|
||||
|
||||
.training-title-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
font-family: var(--app-font-family);
|
||||
font-size: var(--app-text-4xl);
|
||||
font-weight: 600;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
.training-subtitle {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-family: var(--app-font-family);
|
||||
font-size: var(--app-text-base);
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
// 横向页签条:与工具箱页 toolbox-tabbar 同款交互(底部描边 + 品牌色下划线)
|
||||
.training-tabbar() {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.training-tabs() {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.training-tab() {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 44px;
|
||||
padding: 0 2px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-base);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: color var(--app-motion-fast) ease;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: -1px;
|
||||
height: 2px;
|
||||
border-radius: var(--app-radius-pill);
|
||||
background: transparent;
|
||||
transition: background var(--app-motion-fast) ease;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&[aria-selected='true'] {
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
> .t-icon,
|
||||
> svg {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&::after {
|
||||
background: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: -2px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
}
|
||||
}
|
||||
|
||||
// 内容卡片:对齐知识库 resource-card 规范(描边 + 8px 圆角 + 容器底色)
|
||||
.training-panel-box() {
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 14px 16px;
|
||||
|
||||
&__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-weight: 600;
|
||||
font-size: var(--app-text-lg);
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 双列卡片网格(同 Dashboard / Learning / Exam 面板布局)
|
||||
.training-panel-grid() {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
// 统计卡片组(工作台 / 签到页使用)
|
||||
.training-stat-cards() {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.training-stat-card() {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 14px 16px;
|
||||
|
||||
&__label {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
&__value {
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
&__sub {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.training-tone() {
|
||||
&.tone-good {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&.tone-warn {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
|
||||
&.tone-bad {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
// 进度行 / 列表行(工作台排名、AI 盘点等)
|
||||
.training-progress-row() {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 6px 0;
|
||||
|
||||
.progress-row__name {
|
||||
width: 90px;
|
||||
flex-shrink: 0;
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
.progress-row__bar {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.progress-row__meta {
|
||||
width: 80px;
|
||||
text-align: right;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.training-list-row() {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6px 0;
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 企业培训 Excel 导入模板(配置中心 · 导入模板管理)。
|
||||
* 模板按业务键管理:配置中心上传的自定义版本存后端 tr_templates 并全端生效,
|
||||
* 未上传时由后端回退内置默认(docs/moban 随二进制分发)。
|
||||
* - demand_collection 教育训练需求表模板.xlsx(2026-11 起的系统内置默认,
|
||||
* 含「计划培训时间」列):培训计划「年度需求收集 → 批量导入」使用;
|
||||
* 列:编号/部门/课程名称/参加人员/地点/培訓費用/內外培訓/计划培训时间/讲师/备注;
|
||||
* 后端下载时按新布局注入组织架构下拉(部门 B/参加人员 D/讲师 I)。
|
||||
* - question_bank 部门培训课程试题(题库导入版)模板.xlsx:
|
||||
* 「题库与考试 → Excel 批量导入」与「培训课程 → 创建课程 → 关联题库」指引使用;
|
||||
* 工作表:单选题/多选题/判断题,列:题目/课程名称/难度/正确答案/答案A..答案L。
|
||||
*/
|
||||
import { downloadTrainingTemplateFile, type TrainingTemplateKey } from '@/api/training'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
|
||||
export type { TrainingTemplateKey }
|
||||
|
||||
export const DEMAND_TEMPLATE_KEY: TrainingTemplateKey = 'demand_collection'
|
||||
export const QUESTION_TEMPLATE_KEY: TrainingTemplateKey = 'question_bank'
|
||||
|
||||
export const TRAINING_TEMPLATE_LABELS: Record<TrainingTemplateKey, string> = {
|
||||
demand_collection: '教育训练需求表模板',
|
||||
question_bank: '部门培训课程试题(题库导入版)模板',
|
||||
}
|
||||
|
||||
// 兜底保存扩展名与内置默认文件一致(后端返回的 fileName 缺失时用)。
|
||||
const TRAINING_TEMPLATE_EXT: Record<TrainingTemplateKey, string> = {
|
||||
demand_collection: '.xlsx',
|
||||
question_bank: '.xlsx',
|
||||
}
|
||||
|
||||
// 触发浏览器保存 Blob(带登录态经接口下载;fileName 可传列表接口返回的实际文件名)
|
||||
export async function downloadTrainingTemplate(key: TrainingTemplateKey, fileName?: string) {
|
||||
try {
|
||||
const blob = await downloadTrainingTemplateFile(key)
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = fileName || TRAINING_TEMPLATE_LABELS[key] + TRAINING_TEMPLATE_EXT[key]
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
} catch {
|
||||
MessagePlugin.error('模板下载失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user