视图修改、接口修改

This commit is contained in:
2025-10-28 19:04:35 +08:00
parent 98c73632bd
commit c5c134fbb3
96 changed files with 7122 additions and 4194 deletions

View File

@@ -11,151 +11,142 @@
</div>
<!-- 课程详情 -->
<div v-else-if="courseVO" class="course-content">
<!-- 课程封面和基本信息 -->
<div class="course-header">
<div class="cover-section">
<img
:src="courseVO.course.coverImage? FILE_DOWNLOAD_URL + courseVO.course.coverImage : defaultCover"
:alt="courseVO.course.name"
class="cover-image"
/>
</div>
<div class="info-section">
<h1 class="course-title">{{ courseVO.course.name }}</h1>
<div class="course-meta">
<div class="meta-item">
<el-icon><User /></el-icon>
<span>授课老师{{ courseVO.course.teacher }}</span>
</div>
<div class="meta-item">
<el-icon><Clock /></el-icon>
<span>课程时长{{ formatDuration(courseVO.course.duration) }}</span>
</div>
<div class="meta-item">
<el-icon><View /></el-icon>
<span>{{ courseVO.course.viewCount || 0 }} 人浏览</span>
</div>
<div class="meta-item">
<el-icon><Reading /></el-icon>
<span>{{ courseVO.course.learnCount || 0 }} 人学习</span>
</div>
</div>
<div class="course-description">
<p>{{ courseVO.course.description }}</p>
</div>
<!-- 操作按钮 -->
<div class="action-buttons">
<el-button
type="primary"
size="large"
@click="handleStartLearning"
:loading="enrolling"
>
<el-icon><VideoPlay /></el-icon>
{{ isEnrolled ? '继续学习' : '开始学习' }}
</el-button>
<el-button
size="large"
:icon="isCollected ? StarFilled : Star"
@click="handleCollect"
:type="isCollected ? 'success' : 'default'"
>
{{ isCollected ? '已收藏' : '收藏课程' }}
</el-button>
</div>
<!-- 学习进度 -->
<div v-if="learningProgress" class="learning-progress">
<div class="progress-header">
<span>学习进度</span>
<span class="progress-text">{{ learningProgress.progress }}%</span>
</div>
<el-progress
:percentage="learningProgress.progress"
:stroke-width="10"
:color="progressColor"
<div v-else-if="courseItemVO" class="course-content">
<!-- 课程信息看板 -->
<div class="course-info-panel">
<div class="panel-container">
<!-- 左侧课程封面 -->
<div class="course-cover">
<img
:src="courseItemVO.coverImage ? FILE_DOWNLOAD_URL + courseItemVO.coverImage : defaultCover"
:alt="courseItemVO.name"
@error="handleImageError"
/>
</div>
<!-- 右侧课程信息 -->
<div class="course-info">
<div class="info-content">
<!-- 课程标题 -->
<h1 class="course-title">{{ courseItemVO.name }}</h1>
<!-- 课程简介 -->
<p class="course-desc">{{ courseItemVO.description || '暂无简介' }}</p>
<!-- 课程元信息 -->
<div class="course-meta">
<div class="meta-item">
<el-avatar :size="24" :src="getTeacherAvatar()" />
<span>{{ courseItemVO.teacher || '课程讲师' }}</span>
</div>
<div class="meta-divider"></div>
<div class="meta-item">
<img src="@/assets/imgs/clock.svg" alt="time" />
<span>{{ formatDuration(courseItemVO.duration) }}</span>
</div>
<div class="meta-divider"></div>
<div class="meta-item">
<img src="@/assets/imgs/book-read.svg" alt="learning" />
<span>{{ courseItemVO.learnCount || 0 }}人学习</span>
</div>
</div>
</div>
<!-- 进度条区域 -->
<div v-if="learningProgress" class="progress-section">
<span class="progress-label">课程进度</span>
<div class="progress-bar-wrapper">
<div class="progress-bar">
<div class="progress-fill" :style="{ width: learningProgress.progress + '%' }"></div>
</div>
<span class="progress-percent">{{ learningProgress.progress }}%</span>
</div>
</div>
<!-- 操作按钮 -->
<div class="action-buttons">
<el-button
type="primary"
size="large"
@click="handleStartLearning"
:loading="enrolling"
>
{{ isEnrolled ? '继续学习' : '开始学习' }}
</el-button>
<el-button
size="large"
:plain="!isCollected"
@click="handleCollect"
>
<el-icon><Star /></el-icon>
收藏课程
</el-button>
</div>
</div>
</div>
</div>
<!-- 课程章节 -->
<el-card class="chapter-card" shadow="never">
<template #header>
<div class="card-header">
<span>课程章节</span>
<span class="chapter-count"> {{ courseVO.courseChapters.length }} </span>
</div>
</template>
<div class="chapter-section">
<!-- 标题 -->
<div class="section-title">
<div class="title-bar"></div>
<span class="title-text">课程目录</span>
</div>
<div v-if="courseVO.courseChapters.length === 0" class="empty-tip">
<!-- 章节列表 -->
<div v-if="!courseItemVO.chapters || courseItemVO.chapters.length === 0" class="empty-tip">
暂无章节内容
</div>
<el-collapse v-else v-model="activeChapters">
<el-collapse-item
v-for="(chapterVO, chapterIndex) in courseVO.courseChapters"
<div v-else class="chapter-list">
<div
v-for="(chapterItem, chapterIndex) in courseItemVO.chapters"
:key="chapterIndex"
:name="chapterIndex"
class="chapter-item"
>
<template #title>
<div class="chapter-title-bar">
<!-- 章节标题 -->
<div class="chapter-header" @click="toggleChapter(chapterIndex)">
<div class="chapter-title">
<img src="@/assets/imgs/arrow-down.svg" alt="arrow" class="chevron-icon" :class="{ 'expanded': activeChapters.includes(chapterIndex) }"/>
<span class="chapter-name">
<el-icon><DocumentCopy /></el-icon>
章节 {{ chapterIndex + 1 }}: {{ chapterVO.chapter.name }}
</span>
<span class="chapter-meta">
{{ chapterVO.nodes.length }} 个节点
{{ chapterIndex + 1 }} {{ chapterItem.name }}{{ getChapterNodes(chapterIndex).length }}小节
</span>
</div>
</template>
</div>
<!-- 节点列表 -->
<div v-if="chapterVO.nodes.length === 0" class="empty-tip">
暂无学习节点
</div>
<div v-else class="node-list">
<div v-show="activeChapters.includes(chapterIndex)" class="node-list">
<div v-if="getChapterNodes(chapterIndex).length === 0" class="empty-tip">
暂无学习节点
</div>
<div
v-for="(node, nodeIndex) in chapterVO.nodes"
v-else
v-for="(node, nodeIndex) in getChapterNodes(chapterIndex)"
:key="nodeIndex"
class="node-item"
:class="{ 'completed': isNodeCompleted(chapterIndex, nodeIndex) }"
@click="handleNodeClick(chapterIndex, nodeIndex)"
>
<div class="node-info">
<el-icon class="node-icon">
<Document v-if="node.nodeType === 0" />
<Edit v-else-if="node.nodeType === 1" />
<Upload v-else />
</el-icon>
<span class="node-name">{{ node.name }}</span>
<el-tag
v-if="node.isRequired === 1"
type="danger"
size="small"
effect="plain"
>
必修
</el-tag>
<div class="node-left">
<span class="node-number">{{ nodeIndex + 1 }}</span>
<div class="node-info">
<img v-if="node.nodeType === 2" src="@/assets/imgs/video.svg" alt="video" class="node-icon" />
<img v-else src="@/assets/imgs/article.svg" alt="article" class="node-icon" />
<span class="node-name">{{ node.name }}</span>
</div>
</div>
<div class="node-meta">
<span v-if="node.duration" class="node-duration">
<el-icon><Clock /></el-icon>
{{ node.duration }} 分钟
<div class="node-right">
<span class="node-status">
{{ getNodeStatusText(node, chapterIndex, nodeIndex) }}
</span>
<el-icon class="arrow-icon"><ArrowRight /></el-icon>
</div>
</div>
</div>
</el-collapse-item>
</el-collapse>
</el-card>
</div>
</div>
</div>
<!-- 收藏按钮底部浮动 -->
<div class="floating-collect">
@@ -182,24 +173,14 @@ import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import {
ArrowLeft,
User,
Clock,
View,
Reading,
VideoPlay,
Star,
StarFilled,
DocumentCopy,
Document,
Edit,
Upload,
ArrowRight
StarFilled
} from '@element-plus/icons-vue';
import { courseApi } from '@/apis/study';
import { learningRecordApi } from '@/apis/study';
import { userCollectionApi } from '@/apis/usercenter';
import { useStore } from 'vuex';
import type { CourseVO, LearningRecord } from '@/types';
import type { CourseItemVO, LearningRecord } from '@/types';
import { CollectionType } from '@/types';
import { FILE_DOWNLOAD_URL } from '@/config';
@@ -231,20 +212,20 @@ const userInfo = computed(() => store.getters['auth/user']);
const loading = ref(false);
const enrolling = ref(false);
const courseVO = ref<CourseVO | null>(null);
const courseItemVO = ref<CourseItemVO | null>(null);
const isCollected = ref(false);
const isEnrolled = ref(false);
const learningProgress = ref<LearningRecord | null>(null);
const activeChapters = ref<number[]>([0]); // 默认展开第一章
const defaultCover = new URL('@/assets/imgs/article-default.png', import.meta.url).href;
// 进度条颜色
const progressColor = computed(() => {
const progress = learningProgress.value?.progress || 0;
if (progress >= 80) return '#67c23a';
if (progress >= 50) return '#409eff';
return '#e6a23c';
});
// 辅助函数:获取章节的节点列表
function getChapterNodes(chapterIndex: number): CourseItemVO[] {
if (!courseItemVO.value) return [];
const chapter = courseItemVO.value.chapters?.[chapterIndex];
if (!chapter?.chapterID) return [];
return courseItemVO.value.chapterNodes?.[chapter.chapterID] || [];
}
watch(() => props.courseId, (newId) => {
if (newId) {
@@ -263,20 +244,15 @@ async function loadCourseDetail() {
const res = await courseApi.getCourseById(props.courseId);
if (res.success && res.data) {
courseVO.value = res.data;
courseItemVO.value = res.data;
// 确保数据结构完整
if (!courseVO.value.courseChapters) {
courseVO.value.courseChapters = [];
if (!courseItemVO.value.chapters) {
courseItemVO.value.chapters = [];
}
if (!courseVO.value.courseTags) {
courseVO.value.courseTags = [];
if (!courseItemVO.value.chapterNodes) {
courseItemVO.value.chapterNodes = {};
}
courseVO.value.courseChapters.forEach((chapter) => {
if (!chapter.nodes) {
chapter.nodes = [];
}
});
} else {
ElMessage.error('加载课程失败');
}
@@ -371,7 +347,7 @@ async function handleStartLearning() {
return;
}
if (!courseVO.value || courseVO.value.courseChapters.length === 0) {
if (!courseItemVO.value || !courseItemVO.value.chapters || courseItemVO.value.chapters.length === 0) {
ElMessage.warning('课程暂无内容');
return;
}
@@ -418,17 +394,66 @@ function handleBack() {
emit('back');
}
// 格式化时长
// 切换章节展开/收起
function toggleChapter(chapterIndex: number) {
const index = activeChapters.value.indexOf(chapterIndex);
if (index > -1) {
activeChapters.value.splice(index, 1);
} else {
activeChapters.value.push(chapterIndex);
}
}
// 判断节点是否完成
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function isNodeCompleted(chapterIndex: number, nodeIndex: number): boolean {
// TODO: 实际应该从学习记录中判断
return false;
}
// 获取节点状态文本
function getNodeStatusText(node: any, chapterIndex: number, nodeIndex: number): string {
const isCompleted = isNodeCompleted(chapterIndex, nodeIndex);
if (isCompleted) {
if (node.nodeType === 0) {
// 文章类型,显示字数
return '已学完';
} else if (node.nodeType === 2 && node.duration) {
// 视频类型,显示时长
return `${node.duration}分钟|已学完`;
}
return '已学完';
} else {
if (node.nodeType === 0) {
// 文章类型
return '200字';
} else if (node.nodeType === 2 && node.duration) {
// 视频类型,显示时长和学习进度
return `${node.duration}分钟`;
}
return '未学习';
}
}
// 获取讲师头像
function getTeacherAvatar(): string {
return 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png';
}
// 图片加载失败处理
function handleImageError(event: Event) {
const target = event.target as HTMLImageElement;
target.src = defaultCover;
}
function formatDuration(minutes?: number): string {
if (!minutes) return '0分';
if (!minutes) return '0小时0分';
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
if (hours > 0) {
return `${hours}小时${mins}分钟`;
}
return `${mins}分钟`;
return `${hours}小时${mins}`;
}
</script>
@@ -463,90 +488,208 @@ function formatDuration(minutes?: number): string {
padding: 24px;
}
.course-header {
background: #fff;
border-radius: 8px;
padding: 24px;
// 课程信息看板
.course-info-panel {
margin-bottom: 24px;
display: flex;
gap: 24px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
@media (max-width: 768px) {
flex-direction: column;
}
}
.cover-section {
flex-shrink: 0;
.cover-image {
width: 320px;
height: 240px;
object-fit: cover;
border-radius: 8px;
@media (max-width: 768px) {
width: 100%;
height: auto;
}
.panel-container {
display: flex;
gap: 40px;
padding: 40px 60px;
background: #FFFFFF;
border-radius: 10px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}
}
.info-section {
.course-cover {
width: 478px;
height: 237px;
flex-shrink: 0;
border-radius: 10px;
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}
.course-info {
flex: 1;
display: flex;
flex-direction: column;
gap: 16px;
}
.course-title {
font-size: 28px;
font-weight: 600;
color: #303133;
margin: 0;
line-height: 1.4;
}
.course-meta {
display: flex;
flex-wrap: wrap;
gap: 24px;
gap: 20px;
.meta-item {
.info-content {
display: flex;
flex-direction: column;
gap: 10px;
}
.course-title {
font-family: 'PingFang SC';
font-weight: 600;
font-size: 20px;
line-height: 1.4;
color: #141F38;
margin: 0;
}
.course-desc {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 14px;
line-height: 1.57;
color: rgba(0, 0, 0, 0.3);
margin: 0;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.course-meta {
display: flex;
align-items: center;
gap: 8px;
color: #606266;
font-size: 14px;
gap: 7px;
.el-icon {
color: #909399;
.meta-item {
display: flex;
align-items: center;
gap: 7px;
img {
width: 18px;
height: 18px;
}
span {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 14px;
line-height: 1.57;
color: #4E5969;
}
}
.meta-divider {
width: 1px;
height: 14px;
background: #F1F5F9;
}
}
}
.course-description {
color: #606266;
font-size: 14px;
line-height: 1.8;
.progress-section {
display: flex;
align-items: center;
gap: 14px;
p {
margin: 0;
.progress-label {
font-family: 'PingFang SC';
font-weight: 500;
font-size: 14px;
line-height: 1.71;
color: #86909C;
}
.progress-bar-wrapper {
flex: 1;
display: flex;
align-items: center;
gap: 9px;
}
.progress-bar {
flex: 1;
height: 6px;
background: #EAEAEA;
border-radius: 27px;
overflow: hidden;
.progress-fill {
height: 100%;
background: #10A5A1;
border-radius: 27px;
transition: width 0.3s ease;
}
}
.progress-percent {
font-family: 'PingFang SC';
font-weight: 500;
font-size: 14px;
line-height: 1.71;
color: #86909C;
text-align: right;
}
}
.action-buttons {
display: flex;
gap: 16px;
margin-top: 8px;
align-items: center;
gap: 27px;
:deep(.el-button) {
height: 42px;
border-radius: 8px;
font-family: 'PingFang SC';
font-weight: 500;
font-size: 16px;
padding: 8px 24px;
&.el-button--primary {
width: 180px;
background: #C62828;
border-color: #C62828;
&:hover {
background: #d32f2f;
border-color: #d32f2f;
}
}
&.el-button--default {
width: 125px;
border-color: #86909C;
color: #86909C;
img {
width: 20px;
height: 20px;
margin-right: 4px;
}
.el-icon {
margin-right: 4px;
}
&.is-plain {
background: #FFFFFF;
&:hover {
background: #f5f7fa;
}
}
&:not(.is-plain) {
background: #C62828;
border-color: #C62828;
color: #FFFFFF;
&:hover {
background: #d32f2f;
border-color: #d32f2f;
}
}
}
}
}
.learning-progress {
padding: 16px;
background: #f5f7fa;
border-radius: 8px;
.progress-header {
display: flex;
justify-content: space-between;
@@ -560,105 +703,170 @@ function formatDuration(minutes?: number): string {
}
}
.chapter-card {
:deep(.el-card__header) {
background: #fafafa;
// 课程章节区域
.chapter-section {
background: #FFFFFF;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}
.section-title {
display: flex;
align-items: center;
gap: 4px;
height: 25px;
margin-bottom: 24px;
.title-bar {
width: 3px;
height: 14px;
background: #C62828;
border-radius: 2px;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 18px;
.title-text {
font-family: 'PingFang SC';
font-weight: 600;
font-size: 16px;
line-height: 1.5;
color: #1E293B;
}
}
.chapter-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.chapter-item {
.chapter-header {
background: #F6F7F8;
border-radius: 6px;
padding: 18px 16px;
cursor: pointer;
transition: background 0.3s;
.chapter-count {
font-size: 14px;
color: #909399;
font-weight: normal;
&:hover {
background: #eef0f2;
}
}
.chapter-title {
display: flex;
align-items: center;
gap: 4px;
.chevron-icon {
width: 12px;
height: 12px;
flex-shrink: 0;
transition: transform 0.3s;
transform: rotate(-90deg);
&.expanded {
transform: rotate(0deg);
}
}
.chapter-name {
font-family: 'PingFang SC';
font-weight: 500;
font-size: 16px;
line-height: 1.5;
color: #000000;
}
}
}
.chapter-title-bar {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding-right: 20px;
.chapter-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 16px;
font-weight: 500;
}
.chapter-meta {
font-size: 14px;
color: #909399;
}
}
.node-list {
padding: 8px 0;
display: flex;
flex-direction: column;
}
.node-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 16px;
margin: 8px 0;
background: #fafafa;
border-radius: 6px;
padding: 20px 30px;
border-bottom: 1px solid #F1F5F9;
cursor: pointer;
transition: all 0.3s;
transition: background 0.3s;
&:hover {
background: #f0f2f5;
transform: translateX(4px);
background: #fafbfc;
}
.node-info {
.node-left {
display: flex;
align-items: center;
gap: 12px;
gap: 16px;
flex: 1;
.node-icon {
color: #409eff;
font-size: 18px;
}
.node-name {
.node-number {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 14px;
color: #303133;
line-height: 1.57;
color: #C62828;
flex-shrink: 0;
}
}
.node-meta {
display: flex;
align-items: center;
gap: 12px;
.node-duration {
.node-info {
display: flex;
align-items: center;
gap: 4px;
font-size: 13px;
color: #909399;
}
.arrow-icon {
color: #c0c4cc;
transition: transform 0.3s;
gap: 6px;
.node-icon {
flex-shrink: 0;
stroke: currentColor;
}
.node-name {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 14px;
line-height: 1.57;
color: #C62828;
}
}
}
&:hover .arrow-icon {
transform: translateX(4px);
.node-right {
.node-status {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 14px;
line-height: 1.57;
color: #C62828;
text-align: right;
}
}
// 已完成的节点样式
&.completed {
.node-left {
.node-number {
color: #4E5969;
}
.node-info {
.node-icon {
stroke: currentColor;
}
.node-name {
color: #4E5969;
}
}
}
.node-right {
.node-status {
color: #4E5969;
}
}
}
}