公共课直播间页面改造:将直播纪要替换为课程列表
功能更新: - 创建了PublicCourseList组件,与课程直播间保持一致的课程列表样式 - 实现了公共课程数据结构,包含三个单元:AI课、企业高管公开课、营销能力课 - 添加了generatePublicCourseLiveList函数,自动将课程分类到对应单元 - 基于关键词智能分类课程(AI/AIGC、企业/管理、营销/运营等) - 垂直方向课程保留在原未分类单元中,不显示在公共课列表 UI优化: - 课程列表支持折叠展开,显示单元完成进度 - 时间轴样式显示课程进度状态 - 支持课程选择联动视频播放器 - 响应式布局,与课程直播间保持一致的交互体验 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
167
src/components/PublicCourseList/index.css
Normal file
167
src/components/PublicCourseList/index.css
Normal file
@@ -0,0 +1,167 @@
|
||||
.public-course-list {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.course-list-header {
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #e5e6eb;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.course-list-header h3 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.course-list-collapse {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.course-list-collapse .arco-collapse-item {
|
||||
margin-bottom: 8px;
|
||||
border: 1px solid #e5e6eb;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.course-list-collapse .arco-collapse-item-header {
|
||||
background: #f7f8fa;
|
||||
padding: 12px 16px;
|
||||
}
|
||||
|
||||
.unit-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.unit-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.unit-course-count {
|
||||
font-size: 12px;
|
||||
color: #86909c;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.course-timeline {
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.timeline-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: #e5e6eb;
|
||||
}
|
||||
|
||||
.timeline-dot.completed {
|
||||
background: #00b42a;
|
||||
}
|
||||
|
||||
.timeline-dot.current {
|
||||
background: #ff7d00;
|
||||
box-shadow: 0 0 0 4px rgba(255, 125, 0, 0.2);
|
||||
}
|
||||
|
||||
.timeline-dot.upcoming {
|
||||
background: #165dff;
|
||||
}
|
||||
|
||||
.course-item {
|
||||
padding: 12px;
|
||||
background: #f7f8fa;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.course-item:hover {
|
||||
background: #e8f3ff;
|
||||
transform: translateX(4px);
|
||||
}
|
||||
|
||||
.course-item.selected {
|
||||
background: #e8f3ff;
|
||||
border-left: 3px solid #165dff;
|
||||
}
|
||||
|
||||
.course-item.completed {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.course-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.course-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #1d2129;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.course-meta {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
font-size: 12px;
|
||||
color: #86909c;
|
||||
}
|
||||
|
||||
.course-status {
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.course-status.completed {
|
||||
background: #e8ffea;
|
||||
color: #00b42a;
|
||||
}
|
||||
|
||||
.course-status.current {
|
||||
background: #fff7e8;
|
||||
color: #ff7d00;
|
||||
}
|
||||
|
||||
.course-status.upcoming {
|
||||
background: #e8f3ff;
|
||||
color: #165dff;
|
||||
}
|
||||
|
||||
/* 自定义滚动条 */
|
||||
.course-list-collapse::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.course-list-collapse::-webkit-scrollbar-track {
|
||||
background: #f2f3f5;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.course-list-collapse::-webkit-scrollbar-thumb {
|
||||
background: #c9cdd4;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.course-list-collapse::-webkit-scrollbar-thumb:hover {
|
||||
background: #86909c;
|
||||
}
|
||||
156
src/components/PublicCourseList/index.jsx
Normal file
156
src/components/PublicCourseList/index.jsx
Normal file
@@ -0,0 +1,156 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Collapse, Timeline, Spin } from "@arco-design/web-react";
|
||||
import { getPublicCourseLiveList } from "@/services/courseLive";
|
||||
import "./index.css";
|
||||
|
||||
const TimelineItem = Timeline.Item;
|
||||
const CollapseItem = Collapse.Item;
|
||||
|
||||
const PublicCourseList = ({ className = "", onCourseClick }) => {
|
||||
const [courseLiveList, setCourseLiveList] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedCourseId, setSelectedCourseId] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchCourseList();
|
||||
}, []);
|
||||
|
||||
const fetchCourseList = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getPublicCourseLiveList();
|
||||
if (res.success) {
|
||||
const courseList = res.data || [];
|
||||
setCourseLiveList(courseList);
|
||||
|
||||
// 设置默认选中今天的课程(如果有)
|
||||
const todayStr = new Date().toISOString().split('T')[0];
|
||||
let foundTodayCourse = false;
|
||||
|
||||
for (const unit of courseList) {
|
||||
const todayCourse = unit.courses.find(c => c.date === todayStr);
|
||||
if (todayCourse) {
|
||||
setSelectedCourseId(todayCourse.courseId);
|
||||
// 触发课程选择事件
|
||||
if (onCourseClick) {
|
||||
onCourseClick({
|
||||
...todayCourse,
|
||||
unitName: unit.unitName
|
||||
});
|
||||
}
|
||||
foundTodayCourse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有今天的课程,选中第一个current或upcoming的课程
|
||||
if (!foundTodayCourse) {
|
||||
for (const unit of courseList) {
|
||||
const activeCourse = unit.courses.find(c => c.current || c.upcoming);
|
||||
if (activeCourse) {
|
||||
setSelectedCourseId(activeCourse.courseId);
|
||||
if (onCourseClick) {
|
||||
onCourseClick({
|
||||
...activeCourse,
|
||||
unitName: unit.unitName
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch course list:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCourseClick = (course, unitName) => {
|
||||
setSelectedCourseId(course.courseId);
|
||||
if (onCourseClick) {
|
||||
onCourseClick({
|
||||
...course,
|
||||
unitName: unitName
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const renderCourseStatus = (course) => {
|
||||
if (course.completed) {
|
||||
return <span className="course-status completed">已完成</span>;
|
||||
} else if (course.current) {
|
||||
return <span className="course-status current">正在进行</span>;
|
||||
} else if (course.upcoming) {
|
||||
return <span className="course-status upcoming">即将开始</span>;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`public-course-list ${className}`}>
|
||||
<div className="course-list-header">
|
||||
<h3>公共课程列表</h3>
|
||||
</div>
|
||||
|
||||
<Spin loading={loading} style={{ width: '100%' }}>
|
||||
<Collapse
|
||||
defaultActiveKey={courseLiveList.map(unit => unit.unitId)}
|
||||
className="course-list-collapse"
|
||||
>
|
||||
{courseLiveList.map((unit) => (
|
||||
<CollapseItem
|
||||
key={unit.unitId}
|
||||
header={
|
||||
<div className="unit-header">
|
||||
<span className="unit-name">{unit.unitName}</span>
|
||||
<span className="unit-course-count">
|
||||
{unit.courses.filter(c => c.completed).length}/{unit.courses.length} 已完成
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
name={unit.unitId}
|
||||
>
|
||||
<Timeline className="course-timeline">
|
||||
{unit.courses.map((course) => (
|
||||
<TimelineItem
|
||||
key={course.courseId}
|
||||
dot={
|
||||
<div
|
||||
className={`timeline-dot ${
|
||||
course.completed ? 'completed' :
|
||||
course.current ? 'current' :
|
||||
course.upcoming ? 'upcoming' : ''
|
||||
}`}
|
||||
/>
|
||||
}
|
||||
label={course.date}
|
||||
>
|
||||
<div
|
||||
className={`course-item ${
|
||||
selectedCourseId === course.courseId ? 'selected' : ''
|
||||
} ${course.completed ? 'completed' : ''}`}
|
||||
onClick={() => handleCourseClick(course, unit.unitName)}
|
||||
>
|
||||
<div className="course-info">
|
||||
<div className="course-name">{course.courseName}</div>
|
||||
<div className="course-meta">
|
||||
<span className="course-teacher">讲师:{course.teacherName}</span>
|
||||
{course.time && <span className="course-time">时间:{course.time}</span>}
|
||||
</div>
|
||||
</div>
|
||||
{renderCourseStatus(course)}
|
||||
</div>
|
||||
</TimelineItem>
|
||||
))}
|
||||
</Timeline>
|
||||
</CollapseItem>
|
||||
))}
|
||||
</Collapse>
|
||||
</Spin>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PublicCourseList;
|
||||
Reference in New Issue
Block a user