web-课程列表
This commit is contained in:
@@ -1,227 +1,440 @@
|
||||
<template>
|
||||
<div class="course-center">
|
||||
<div class="course-header">
|
||||
<h2>课程中心</h2>
|
||||
<div class="course-categories">
|
||||
<div
|
||||
class="category-tab"
|
||||
v-for="category in categories"
|
||||
:key="category.id"
|
||||
:class="{ active: activeCategory === category.id }"
|
||||
@click="activeCategory = category.id"
|
||||
>
|
||||
{{ category.name }}
|
||||
<StudyPlanLayout category-name="课程中心">
|
||||
<!-- 主要内容区 -->
|
||||
<div class="main-content">
|
||||
<div class="container">
|
||||
<!-- 页面标题 -->
|
||||
<h2 class="page-title">课程列表</h2>
|
||||
|
||||
<!-- 搜索和筛选 -->
|
||||
<div class="search-filter-bar">
|
||||
<div class="search-box">
|
||||
<el-input
|
||||
v-model="searchKeyword"
|
||||
placeholder="搜索思政资源"
|
||||
class="search-input"
|
||||
clearable
|
||||
@keyup.enter="handleSearch"
|
||||
>
|
||||
<template #suffix>
|
||||
<el-button
|
||||
type="danger"
|
||||
circle
|
||||
@click="handleSearch"
|
||||
class="search-button"
|
||||
>
|
||||
<el-icon><Search /></el-icon>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 课程列表 -->
|
||||
<div v-if="loading" class="loading-container">
|
||||
<el-skeleton :rows="6" animated />
|
||||
</div>
|
||||
|
||||
<div v-else-if="courseList.length > 0" class="course-grid">
|
||||
<div
|
||||
v-for="course in courseList"
|
||||
:key="course.courseID"
|
||||
class="course-card"
|
||||
@click="handleCourseClick(course.courseID || '')"
|
||||
>
|
||||
<!-- 课程封面 -->
|
||||
<div class="course-cover">
|
||||
<img
|
||||
:src="course.coverImage ? FILE_DOWNLOAD_URL + course.coverImage : defaultCover"
|
||||
:alt="course.name"
|
||||
class="cover-image"
|
||||
/>
|
||||
<!-- 课程类型标签 -->
|
||||
<div class="course-type-tag">
|
||||
<el-icon><VideoPlay /></el-icon>
|
||||
<span>视频课程</span>
|
||||
</div>
|
||||
<!-- 分类标签 -->
|
||||
<div class="category-tag">
|
||||
{{ getCategoryName() }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 课程信息 -->
|
||||
<div class="course-info">
|
||||
<div class="view-count">
|
||||
{{ formatViewCount(course.viewCount) }}次浏览
|
||||
</div>
|
||||
<h3 class="course-title">{{ course.name }}</h3>
|
||||
<p class="course-desc">
|
||||
{{ course.description || '暂无描述' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
<el-empty description="暂无课程" />
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div v-if="total > 0" class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="pageParam.page"
|
||||
v-model:page-size="pageParam.size"
|
||||
:total="total"
|
||||
:page-sizes="[6, 12, 24, 48]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="course-grid">
|
||||
<div class="course-card" v-for="course in filteredCourses" :key="course.id" @click="viewCourse(course)">
|
||||
<div class="course-cover">
|
||||
<img :src="course.cover" :alt="course.title" />
|
||||
<div class="course-duration">{{ course.duration }}</div>
|
||||
</div>
|
||||
<div class="course-info">
|
||||
<h3>{{ course.title }}</h3>
|
||||
<p class="course-description">{{ course.description }}</p>
|
||||
<div class="course-meta">
|
||||
<span class="course-teacher">
|
||||
<i class="icon">👨🏫</i>
|
||||
{{ course.teacher }}
|
||||
</span>
|
||||
<span class="course-students">
|
||||
<i class="icon">👥</i>
|
||||
{{ course.students }} 人学习
|
||||
</span>
|
||||
</div>
|
||||
<div class="course-footer">
|
||||
<div class="course-rating">
|
||||
<span class="rating-stars">★★★★★</span>
|
||||
<span class="rating-score">{{ course.rating }}</span>
|
||||
</div>
|
||||
<el-button type="primary" size="small">开始学习</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 课程详情对话框 -->
|
||||
<el-drawer
|
||||
v-model="detailDrawerVisible"
|
||||
size="100%"
|
||||
:show-close="false"
|
||||
:with-header="false"
|
||||
direction="rtl"
|
||||
>
|
||||
<CourseDetail
|
||||
v-if="selectedCourseId"
|
||||
:course-id="selectedCourseId"
|
||||
@back="handleCloseDetail"
|
||||
@start-learning="handleStartLearning"
|
||||
/>
|
||||
</el-drawer>
|
||||
|
||||
<!-- 课程学习对话框 -->
|
||||
<el-drawer
|
||||
v-model="learningDrawerVisible"
|
||||
size="100%"
|
||||
:show-close="false"
|
||||
:with-header="false"
|
||||
direction="rtl"
|
||||
>
|
||||
<CourseLearning
|
||||
v-if="learningCourseId"
|
||||
:course-id="learningCourseId"
|
||||
:chapter-index="chapterIndex"
|
||||
:node-index="nodeIndex"
|
||||
@back="handleCloseLearning"
|
||||
/>
|
||||
</el-drawer>
|
||||
</StudyPlanLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { ElButton } from 'element-plus';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { Search, VideoPlay } from '@element-plus/icons-vue';
|
||||
import { CourseDetail, CourseLearning } from '@/views/course';
|
||||
import { courseApi } from '@/apis/study';
|
||||
import type { Course, PageParam } from '@/types';
|
||||
import { StudyPlanLayout } from '@/views/study-plan';
|
||||
import defaultCover from '@/assets/imgs/default-course-bg.png'
|
||||
import { FILE_DOWNLOAD_URL } from '@/config';
|
||||
|
||||
const router = useRouter();
|
||||
const activeCategory = ref('all');
|
||||
const courses = ref<any[]>([]);
|
||||
|
||||
const categories = [
|
||||
{ id: 'all', name: '全部课程' },
|
||||
{ id: 'party-history', name: '党史教育' },
|
||||
{ id: 'theory', name: '理论学习' },
|
||||
{ id: 'policy', name: '政策解读' },
|
||||
{ id: 'ethics', name: '道德修养' }
|
||||
];
|
||||
|
||||
const filteredCourses = computed(() => {
|
||||
if (activeCategory.value === 'all') return courses.value;
|
||||
return courses.value.filter(course => course.category === activeCategory.value);
|
||||
defineOptions({
|
||||
name: 'CourseCenterView'
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const searchKeyword = ref('');
|
||||
const courseList = ref<Course[]>([]);
|
||||
const total = ref(0);
|
||||
|
||||
// 分页参数
|
||||
const pageParam = ref<PageParam>({
|
||||
page: 1,
|
||||
size: 6
|
||||
});
|
||||
|
||||
// 课程详情
|
||||
const detailDrawerVisible = ref(false);
|
||||
const selectedCourseId = ref<string>('');
|
||||
|
||||
// 课程学习
|
||||
const learningDrawerVisible = ref(false);
|
||||
const learningCourseId = ref<string>('');
|
||||
const chapterIndex = ref(0);
|
||||
const nodeIndex = ref(0);
|
||||
|
||||
onMounted(() => {
|
||||
// TODO: 加载课程数据
|
||||
loadCourseList();
|
||||
});
|
||||
|
||||
function viewCourse(course: any) {
|
||||
router.push(`/study/course/${course.id}`);
|
||||
// 加载课程列表
|
||||
async function loadCourseList() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const filter: Course = {
|
||||
status: 1 // 只显示已上线的课程
|
||||
};
|
||||
|
||||
if (searchKeyword.value) {
|
||||
filter.name = searchKeyword.value;
|
||||
}
|
||||
|
||||
const res = await courseApi.getCoursePage(pageParam.value, filter);
|
||||
|
||||
if (res.success) {
|
||||
courseList.value = res.dataList || [];
|
||||
total.value = res.pageParam?.totalElements || 0;
|
||||
} else {
|
||||
ElMessage.error('加载课程列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载课程列表失败:', error);
|
||||
ElMessage.error('加载课程列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
function handleSearch() {
|
||||
pageParam.value.page = 1;
|
||||
loadCourseList();
|
||||
}
|
||||
|
||||
// 分页大小改变
|
||||
function handleSizeChange() {
|
||||
loadCourseList();
|
||||
}
|
||||
|
||||
// 当前页改变
|
||||
function handleCurrentChange() {
|
||||
loadCourseList();
|
||||
}
|
||||
|
||||
// 点击课程卡片
|
||||
function handleCourseClick(courseId: string) {
|
||||
selectedCourseId.value = courseId;
|
||||
detailDrawerVisible.value = true;
|
||||
}
|
||||
|
||||
// 关闭课程详情
|
||||
function handleCloseDetail() {
|
||||
detailDrawerVisible.value = false;
|
||||
selectedCourseId.value = '';
|
||||
}
|
||||
|
||||
// 开始学习
|
||||
function handleStartLearning(courseId: string, chapter: number, node: number) {
|
||||
detailDrawerVisible.value = false;
|
||||
learningCourseId.value = courseId;
|
||||
chapterIndex.value = chapter;
|
||||
nodeIndex.value = node;
|
||||
learningDrawerVisible.value = true;
|
||||
}
|
||||
|
||||
// 关闭学习页面
|
||||
function handleCloseLearning() {
|
||||
learningDrawerVisible.value = false;
|
||||
learningCourseId.value = '';
|
||||
chapterIndex.value = 0;
|
||||
nodeIndex.value = 0;
|
||||
}
|
||||
|
||||
// 格式化浏览次数
|
||||
function formatViewCount(count?: number): string {
|
||||
if (!count) return '0';
|
||||
if (count >= 10000) {
|
||||
return (count / 10000).toFixed(1) + 'w';
|
||||
}
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
// 获取分类名称(这里简化处理,实际应该从课程标签中获取)
|
||||
function getCategoryName(): string {
|
||||
// TODO: 从 courseTags 中获取第一个标签作为分类
|
||||
return '党史学习';
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.course-center {
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.course-header {
|
||||
margin-bottom: 32px;
|
||||
.main-content {
|
||||
padding: 40px 0 80px;
|
||||
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: #141F38;
|
||||
margin-bottom: 20px;
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.course-categories {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
.page-title {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #141F38;
|
||||
margin: 0 0 32px 0;
|
||||
}
|
||||
|
||||
.category-tab {
|
||||
padding: 8px 20px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
.search-filter-bar {
|
||||
margin-bottom: 40px;
|
||||
|
||||
&:hover {
|
||||
background: #ffe6e6;
|
||||
color: #C62828;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: #C62828;
|
||||
color: white;
|
||||
.search-box {
|
||||
max-width: 400px;
|
||||
|
||||
.search-input {
|
||||
:deep(.el-input__wrapper) {
|
||||
border-radius: 30px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.search-button {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
background: #C62828;
|
||||
border: none;
|
||||
|
||||
&:hover {
|
||||
background: #A82020;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.course-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 24px;
|
||||
margin-bottom: 40px;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.course-card {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
border: 1px solid transparent;
|
||||
|
||||
&:hover {
|
||||
border-color: #C62828;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 20px rgba(164, 182, 199, 0.2);
|
||||
border-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.course-cover {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
background: #f5f5f5;
|
||||
|
||||
img {
|
||||
.course-cover {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
height: 221px;
|
||||
overflow: hidden;
|
||||
|
||||
.cover-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.course-type-tag {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
left: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px 10px;
|
||||
background: rgba(198, 40, 40, 0.9);
|
||||
color: #fff;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
|
||||
.el-icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.category-tag {
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
right: -2px;
|
||||
padding: 3px 26px;
|
||||
background: #D1AD79;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
border-radius: 0 0 10px 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.course-duration {
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
right: 12px;
|
||||
padding: 4px 12px;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.course-info {
|
||||
padding: 20px;
|
||||
|
||||
h3 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #141F38;
|
||||
margin-bottom: 12px;
|
||||
line-height: 1.4;
|
||||
&:hover .cover-image {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
}
|
||||
|
||||
.course-description {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 16px;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.course-meta {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 13px;
|
||||
color: #999;
|
||||
|
||||
.icon {
|
||||
margin-right: 4px;
|
||||
.course-info {
|
||||
padding: 22px;
|
||||
|
||||
.view-count {
|
||||
position: absolute;
|
||||
top: 232px;
|
||||
right: 22px;
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.3);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.course-title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #141F38;
|
||||
margin: 0 0 8px 0;
|
||||
line-height: 1.4;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.course-desc {
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.3);
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 4;
|
||||
line-clamp: 4;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
min-height: 88px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.course-footer {
|
||||
.empty-state {
|
||||
padding: 80px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
justify-content: center;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.course-rating {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.rating-stars {
|
||||
color: #FFB400;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.rating-score {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #141F38;
|
||||
:deep(.el-drawer) {
|
||||
.el-drawer__body {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user