sync from local backup
This commit is contained in:
@@ -0,0 +1,548 @@
|
||||
.course-learn-container {
|
||||
background: var(--background-color);
|
||||
min-height: 100vh;
|
||||
padding-top: 56px;
|
||||
}
|
||||
|
||||
.course-learn-topbar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 56px;
|
||||
background: var(--card-background);
|
||||
box-shadow: var(--shadow-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 20px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
margin-right: 16px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.topbar-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.topbar-title svg {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.topbar-progress {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--primary-color);
|
||||
min-width: 40px;
|
||||
}
|
||||
|
||||
.menu-button {
|
||||
display: none;
|
||||
margin-left: 16px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.course-learn-content {
|
||||
display: flex;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 280px;
|
||||
background: var(--card-background);
|
||||
border-radius: 12px;
|
||||
box-shadow: var(--shadow-sm);
|
||||
position: sticky;
|
||||
top: 80px;
|
||||
max-height: calc(100vh - 104px);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.sidebar-header h3 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.chapter-count {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.chapter-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.chapter-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
margin-bottom: 8px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
border-left: 3px solid transparent;
|
||||
}
|
||||
|
||||
.chapter-item:hover {
|
||||
background: rgba(102, 126, 234, 0.06);
|
||||
}
|
||||
|
||||
.chapter-item.active {
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
border-left-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.chapter-item.completed {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.chapter-icon {
|
||||
margin-right: 12px;
|
||||
font-size: 16px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.chapter-item.active .chapter-icon {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.chapter-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.chapter-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 4px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.chapter-duration {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.content-card {
|
||||
background: var(--card-background);
|
||||
border-radius: 12px;
|
||||
box-shadow: var(--shadow-sm);
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
.content-header {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.content-header h1 {
|
||||
margin: 0 0 16px 0;
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.content-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.meta-tags {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.meta-duration {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.content-steps {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.content-body {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.content-body h3 {
|
||||
margin: 0 0 16px 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.markdown-content {
|
||||
font-size: 16px;
|
||||
line-height: 1.8;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.markdown-content h1,
|
||||
.markdown-content h2,
|
||||
.markdown-content h3,
|
||||
.markdown-content h4,
|
||||
.markdown-content h5,
|
||||
.markdown-content h6 {
|
||||
margin: 24px 0 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.markdown-content h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.markdown-content h2 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.markdown-content h3 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.markdown-content ul,
|
||||
.markdown-content ol {
|
||||
padding-left: 24px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.markdown-content code {
|
||||
background: rgba(127, 127, 127, 0.15);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: "SFMono-Regular", Consolas, "Courier New", monospace;
|
||||
font-size: 13px;
|
||||
color: #e11d48;
|
||||
}
|
||||
|
||||
.markdown-content pre {
|
||||
background: #1e1e2e;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
overflow-x: auto;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.markdown-content pre code {
|
||||
background: none;
|
||||
color: #a6e3a1;
|
||||
padding: 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.markdown-content blockquote {
|
||||
border-left: 4px solid var(--primary-color);
|
||||
margin: 16px 0;
|
||||
padding: 12px 16px;
|
||||
background: rgba(102, 126, 234, 0.06);
|
||||
border-radius: 0 8px 8px 0;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.markdown-content table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.markdown-content th,
|
||||
.markdown-content td {
|
||||
border: 1px solid var(--border-color);
|
||||
padding: 10px 14px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.markdown-content th {
|
||||
background: rgba(102, 126, 234, 0.06);
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.markdown-content tr:hover td {
|
||||
background: rgba(102, 126, 234, 0.04);
|
||||
}
|
||||
|
||||
.markdown-content img {
|
||||
max-width: 100%;
|
||||
border-radius: 8px;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.markdown-content a {
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.markdown-content a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.markdown-content hr {
|
||||
border: none;
|
||||
border-top: 1px solid var(--border-color);
|
||||
margin: 24px 0;
|
||||
}
|
||||
|
||||
.markdown-content strong {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.video-player-container {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.video-wrapper {
|
||||
position: relative;
|
||||
padding-bottom: 56.25%;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.video-wrapper iframe {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.native-video-player {
|
||||
width: 100%;
|
||||
max-height: 500px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.content-body.with-video {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.content-body.with-video .ant-tabs {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.content-body.with-video .ant-tabs-tab {
|
||||
padding: 8px 16px;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .video-player-container {
|
||||
background: #1a1a2e;
|
||||
}
|
||||
|
||||
.content-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 24px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
/* 暗色模式覆盖 */
|
||||
[data-theme="dark"] .chapter-item:hover {
|
||||
background: rgba(129, 140, 248, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .chapter-item.active {
|
||||
background: rgba(129, 140, 248, 0.15);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .markdown-content code {
|
||||
color: #f472b6;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .markdown-content blockquote {
|
||||
background: rgba(129, 140, 248, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .markdown-content th {
|
||||
background: rgba(129, 140, 248, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .markdown-content tr:hover td {
|
||||
background: rgba(129, 140, 248, 0.06);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.menu-button {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.course-learn-content {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 56px;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 300px;
|
||||
z-index: 99;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.3s ease;
|
||||
border-radius: 0 12px 12px 0;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.content-card {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.content-header h1 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.content-actions {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.content-actions .ant-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.topbar-progress {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.materials-content {
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.materials-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.material-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.material-card:hover {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.material-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.material-icon {
|
||||
font-size: 32px;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.material-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.material-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.material-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.empty-materials {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.empty-video {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.empty-video-icon {
|
||||
font-size: 48px;
|
||||
color: var(--border-color);
|
||||
margin-bottom: 16px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.empty-video p {
|
||||
font-size: 14px;
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,490 @@
|
||||
import "./CourseLearn.css";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Tag, Button, Progress, Spin, Tabs } from "antd";
|
||||
import { message } from "@/utils/message";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLearnTimer } from "@/hooks/useLearnTimer";
|
||||
import {
|
||||
PlayCircleOutlined,
|
||||
CheckCircleOutlined,
|
||||
ClockCircleOutlined,
|
||||
BookOutlined,
|
||||
ArrowLeftOutlined,
|
||||
MenuOutlined,
|
||||
VideoCameraOutlined,
|
||||
FileTextOutlined,
|
||||
DownloadOutlined,
|
||||
FilePdfOutlined,
|
||||
FileZipOutlined,
|
||||
FileOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
import { api_request } from "@/utils/request";
|
||||
import { useRecordHistory } from "@/hooks/useRecordHistory";
|
||||
import { BDCloudVideoView } from "@/components/BDCloudVideoView";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import remarkMath from "remark-math";
|
||||
import rehypeHighlight from "rehype-highlight";
|
||||
import rehypeKatex from "rehype-katex";
|
||||
import "katex/dist/katex.min.css";
|
||||
|
||||
interface CourseDetailData {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
category: string;
|
||||
level: string;
|
||||
color: string;
|
||||
chapters: ChapterData[];
|
||||
chapters_count: number;
|
||||
students_count: number;
|
||||
}
|
||||
|
||||
interface ChapterData {
|
||||
id: number;
|
||||
title: string;
|
||||
sort_order: number;
|
||||
duration: string;
|
||||
is_free: boolean;
|
||||
video_url: string;
|
||||
video_source: string;
|
||||
video_local_url: string;
|
||||
video_poster_url: string;
|
||||
}
|
||||
|
||||
const CourseLearn: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const courseId = searchParams.get("id");
|
||||
|
||||
const getCategoryName = (key: string): string => {
|
||||
const map: Record<string, string> = {
|
||||
'frontend': t('learn.categoryFrontendShort'),
|
||||
'backend': t('learn.categoryBackendShort'),
|
||||
'tools': t('learn.categoryToolsShort'),
|
||||
'devops': t('learn.categoryDevopsShort'),
|
||||
'security': t('learn.categorySecurityShort'),
|
||||
'basic': t('learn.categoryBasicShort'),
|
||||
};
|
||||
return map[key] || key;
|
||||
};
|
||||
|
||||
const getLevelName = (key: string): string => {
|
||||
const map: Record<string, string> = {
|
||||
'beginner': t('learn.courseLevelBeginner'),
|
||||
'advanced': t('learn.courseLevelAdvanced'),
|
||||
'intermediate': t('learn.courseLevelAdvanced'),
|
||||
};
|
||||
return map[key] || key;
|
||||
};
|
||||
|
||||
const [courseData, setCourseData] = useState<CourseDetailData | null>(null);
|
||||
const [chapters, setChapters] = useState<ChapterData[]>([]);
|
||||
const [currentChapterIndex, setCurrentChapterIndex] = useState(0);
|
||||
const [chapterContent, setChapterContent] = useState("");
|
||||
const [completedChapters, setCompletedChapters] = useState<number[]>([]);
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [materials, setMaterials] = useState<any[]>([]);
|
||||
const [videoSource, setVideoSource] = useState<'bilibili' | 'local'>('local');
|
||||
|
||||
useLearnTimer(courseData?.id);
|
||||
|
||||
useRecordHistory(
|
||||
courseData
|
||||
? {
|
||||
type: "learn",
|
||||
title: courseData.title,
|
||||
description: courseData.description,
|
||||
image: (courseData as any).cover_image_url || "",
|
||||
category: courseData.category,
|
||||
link: `/course-learn?id=${courseData.id}`,
|
||||
}
|
||||
: null
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!courseId) {
|
||||
message.error(t('learn.missingCourseId'));
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchCourseDetail = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await api_request.learn.get_course_detail(Number(courseId));
|
||||
const data = (res as any)?.data as CourseDetailData;
|
||||
if (data) {
|
||||
setCourseData(data);
|
||||
setChapters(data.chapters || []);
|
||||
if (data.chapters?.length > 0) {
|
||||
loadChapterContent(data.id, data.chapters[0].id);
|
||||
}
|
||||
loadCourseProgress(data.id);
|
||||
}
|
||||
} catch {
|
||||
message.error(t('learn.fetchDetailError'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadCourseProgress = async (cid: number) => {
|
||||
try {
|
||||
const res = await api_request.learn.getCourseProgress(cid);
|
||||
const data = (res as any)?.data;
|
||||
if (data && Array.isArray(data.completed_chapter_ids)) {
|
||||
setCompletedChapters(data.completed_chapter_ids);
|
||||
}
|
||||
} catch {
|
||||
// 进度加载失败不影响页面展示
|
||||
}
|
||||
};
|
||||
|
||||
fetchCourseDetail();
|
||||
}, [courseId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (chapters.length > 0 && chapters[currentChapterIndex]) {
|
||||
const chapter = chapters[currentChapterIndex];
|
||||
setChapterContent("");
|
||||
loadChapterContent(courseData!.id, chapter.id);
|
||||
}
|
||||
}, [currentChapterIndex]);
|
||||
|
||||
const loadChapterContent = async (cid: number, chapterId: number) => {
|
||||
try {
|
||||
const cdnUrl = `/media/learn/courses/${cid}/chapters/${chapterId}.md`;
|
||||
const response = await fetch(cdnUrl);
|
||||
if (response.ok) {
|
||||
const md = await response.text();
|
||||
setChapterContent(md);
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
try {
|
||||
const res = await api_request.learn.get_chapter_content(chapterId);
|
||||
const data = (res as any)?.data;
|
||||
setChapterContent(data?.content_md || "");
|
||||
} catch {
|
||||
setChapterContent("");
|
||||
}
|
||||
};
|
||||
|
||||
const loadMaterials = async (chapterId: number) => {
|
||||
try {
|
||||
const res = await api_request.learn.get_materials(chapterId);
|
||||
const data = (res as any)?.data;
|
||||
setMaterials(Array.isArray(data) ? data : []);
|
||||
} catch {
|
||||
setMaterials([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (chapters.length > 0 && currentChapterIndex >= 0) {
|
||||
const currentChapter = chapters[currentChapterIndex];
|
||||
if (currentChapter?.id) {
|
||||
loadMaterials(currentChapter.id);
|
||||
}
|
||||
}
|
||||
}, [currentChapterIndex, chapters]);
|
||||
|
||||
const progress = chapters.length
|
||||
? Math.round((completedChapters.length / chapters.length) * 100)
|
||||
: 0;
|
||||
|
||||
const handleChapterClick = (index: number) => {
|
||||
setCurrentChapterIndex(index);
|
||||
setSidebarOpen(false);
|
||||
};
|
||||
|
||||
const handlePrevChapter = () => {
|
||||
if (currentChapterIndex > 0) {
|
||||
setCurrentChapterIndex(currentChapterIndex - 1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNextChapter = () => {
|
||||
if (currentChapterIndex < chapters.length - 1) {
|
||||
setCurrentChapterIndex(currentChapterIndex + 1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMarkCompleted = async () => {
|
||||
const currentChapter = chapters[currentChapterIndex];
|
||||
if (currentChapter && !completedChapters.includes(currentChapter.id)) {
|
||||
try {
|
||||
await api_request.learn.markChapterCompleted(currentChapter.id, true);
|
||||
setCompletedChapters([...completedChapters, currentChapter.id]);
|
||||
message.success(t('learn.chapterMarkedCompleted'));
|
||||
} catch {
|
||||
message.error(t('learn.markCompletedError'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getChapterStatus = (chapter: ChapterData, index: number) => {
|
||||
if (completedChapters.includes(chapter.id)) return "completed";
|
||||
if (currentChapterIndex === index) return "current";
|
||||
return "available";
|
||||
};
|
||||
|
||||
const getStatusIcon = (chapter: ChapterData, index: number) => {
|
||||
const status = getChapterStatus(chapter, index);
|
||||
switch (status) {
|
||||
case "completed":
|
||||
return <CheckCircleOutlined style={{ color: "#10b981" }} />;
|
||||
case "current":
|
||||
return <PlayCircleOutlined style={{ color: "#667eea" }} />;
|
||||
default:
|
||||
return <PlayCircleOutlined style={{ color: "#94a3b8" }} />;
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="course-learn-container" style={{ display: "flex", justifyContent: "center", alignItems: "center" }}>
|
||||
<Spin size="large" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!courseData) {
|
||||
return (
|
||||
<div className="course-learn-container" style={{ display: "flex", justifyContent: "center", alignItems: "center" }}>
|
||||
<span>{t('learn.courseNotExist')}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const currentChapter = chapters[currentChapterIndex];
|
||||
|
||||
return (
|
||||
<div className="course-learn-container">
|
||||
<div className="course-learn-topbar">
|
||||
<Button
|
||||
type="text"
|
||||
icon={<ArrowLeftOutlined />}
|
||||
onClick={() => navigate(-1)}
|
||||
className="back-button"
|
||||
/>
|
||||
<div className="topbar-title">
|
||||
<BookOutlined />
|
||||
<span>{courseData.title}</span>
|
||||
</div>
|
||||
<div className="topbar-progress">
|
||||
<Progress percent={progress} size="small" style={{ width: 120 }} />
|
||||
<span className="progress-text">{progress}%</span>
|
||||
</div>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<MenuOutlined />}
|
||||
onClick={() => setSidebarOpen(!sidebarOpen)}
|
||||
className="menu-button"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="course-learn-content">
|
||||
<div className={`sidebar ${sidebarOpen ? "open" : ""}`}>
|
||||
<div className="sidebar-header">
|
||||
<h3>{t('learn.chapterList')}</h3>
|
||||
<span className="chapter-count">
|
||||
{completedChapters.length}/{chapters.length} {t('learn.chapterCompleted')}
|
||||
</span>
|
||||
</div>
|
||||
<div className="chapter-list">
|
||||
{chapters.map((chapter, index) => (
|
||||
<div
|
||||
key={chapter.id}
|
||||
className={`chapter-item ${getChapterStatus(chapter, index)} ${
|
||||
currentChapterIndex === index ? "active" : ""
|
||||
}`}
|
||||
onClick={() => handleChapterClick(index)}
|
||||
>
|
||||
<div className="chapter-icon">{getStatusIcon(chapter, index)}</div>
|
||||
<div className="chapter-info">
|
||||
<div className="chapter-title">{chapter.title}</div>
|
||||
<div className="chapter-duration">
|
||||
<ClockCircleOutlined />
|
||||
<span>{chapter.duration}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="main-content">
|
||||
<div className="content-card">
|
||||
<div className="content-header">
|
||||
<h1>{currentChapter?.title}</h1>
|
||||
<div className="content-meta">
|
||||
<div className="meta-tags">
|
||||
{courseData.category && (
|
||||
<Tag color="blue">{getCategoryName(courseData.category)}</Tag>
|
||||
)}
|
||||
{courseData.level && (
|
||||
<Tag color="green">{getLevelName(courseData.level)}</Tag>
|
||||
)}
|
||||
{(currentChapter?.video_url || currentChapter?.video_local_url) && (
|
||||
<Tag color="purple" icon={<VideoCameraOutlined />}>
|
||||
{currentChapter?.video_source === 'local' ? '本地视频' : 'B站视频'}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
<div className="meta-duration">
|
||||
<ClockCircleOutlined />
|
||||
<span>{currentChapter?.duration}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="content-body with-video">
|
||||
<Tabs
|
||||
key={`tabs-${currentChapter?.id}`}
|
||||
defaultActiveKey="docs"
|
||||
items={[
|
||||
{
|
||||
key: "docs",
|
||||
label: (
|
||||
<span>
|
||||
<FileTextOutlined /> {t('learn.documentation')}
|
||||
</span>
|
||||
),
|
||||
children: (
|
||||
<div className="markdown-content">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkMath]}
|
||||
rehypePlugins={[rehypeHighlight, rehypeKatex]}
|
||||
>
|
||||
{chapterContent || t('learn.noContent')}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
...(currentChapter?.video_url || currentChapter?.video_local_url
|
||||
? [{
|
||||
key: "video",
|
||||
label: (
|
||||
<span>
|
||||
<VideoCameraOutlined /> {t('learn.videoTutorial')}
|
||||
</span>
|
||||
),
|
||||
children: (
|
||||
<BDCloudVideoView
|
||||
videoSource={currentChapter.video_url?.includes('bilibili.com') ? 'bilibili' : 'local'}
|
||||
bilibiliUrl={currentChapter.video_url?.includes('bilibili.com') ? currentChapter.video_url : undefined}
|
||||
localUrl={!currentChapter.video_url?.includes('bilibili.com') ? currentChapter.video_url : undefined}
|
||||
posterUrl={currentChapter.video_poster_url}
|
||||
title={currentChapter.title}
|
||||
chapterId={currentChapter.id}
|
||||
sources={{
|
||||
bilibili: currentChapter.video_url?.includes('bilibili.com') ? currentChapter.video_url : undefined,
|
||||
local: !currentChapter.video_url?.includes('bilibili.com') ? currentChapter.video_url : undefined,
|
||||
}}
|
||||
activeSource={videoSource}
|
||||
onSourceChange={setVideoSource}
|
||||
/>
|
||||
),
|
||||
}]
|
||||
: [{
|
||||
key: "video",
|
||||
label: (
|
||||
<span>
|
||||
<VideoCameraOutlined /> {t('learn.videoTutorial')}
|
||||
</span>
|
||||
),
|
||||
children: (
|
||||
<div className="empty-video">
|
||||
<VideoCameraOutlined className="empty-video-icon" />
|
||||
<p>{t('learn.noVideo')}</p>
|
||||
</div>
|
||||
),
|
||||
}]),
|
||||
{
|
||||
key: "materials",
|
||||
label: (
|
||||
<span>
|
||||
<DownloadOutlined /> {t('learn.materials')}
|
||||
</span>
|
||||
),
|
||||
children: (
|
||||
<div className="materials-content">
|
||||
{materials.length > 0 ? (
|
||||
<div className="materials-list">
|
||||
{materials.map((item: any) => (
|
||||
<div key={item.id} className="material-card">
|
||||
<div className="material-info">
|
||||
<span className="material-icon">
|
||||
{item.file_type === 'pdf' ? <FilePdfOutlined /> : item.file_type === 'zip' ? <FileZipOutlined /> : <FileOutlined />}
|
||||
</span>
|
||||
<div className="material-details">
|
||||
<div className="material-title">{item.title}</div>
|
||||
<div className="material-meta">{item.file_size_display} | {t('learn.downloads')}: {item.download_count}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Button type="primary" size="small" icon={<DownloadOutlined />} onClick={() => {
|
||||
api_request.learn.download_material(item.id).then((res: any) => {
|
||||
const blob = res.data;
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = item.title;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
}).catch(() => {
|
||||
message.error(t('learn.downloadError'));
|
||||
});
|
||||
}}>
|
||||
{t('learn.download')}
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="empty-materials">{t('learn.noMaterials')}</div>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="content-actions">
|
||||
<Button
|
||||
onClick={handlePrevChapter}
|
||||
disabled={currentChapterIndex === 0}
|
||||
icon={<ArrowLeftOutlined />}
|
||||
>
|
||||
{t('learn.prevChapter')}
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleMarkCompleted}
|
||||
disabled={completedChapters.includes(currentChapter?.id)}
|
||||
icon={<CheckCircleOutlined />}
|
||||
>
|
||||
{completedChapters.includes(currentChapter?.id) ? t('learn.alreadyCompleted') : t('learn.markCompleted')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleNextChapter}
|
||||
disabled={currentChapterIndex === chapters.length - 1}
|
||||
>
|
||||
{t('learn.nextChapter')}
|
||||
<ArrowLeftOutlined style={{ transform: "rotate(180deg)" }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CourseLearn;
|
||||
Reference in New Issue
Block a user