2025-02-23 22:51:22 +08:00
|
|
|
import { Course } from "@nice/common";
|
2025-02-24 11:50:33 +08:00
|
|
|
import React, { useContext, useMemo } from "react";
|
2025-02-24 10:16:39 +08:00
|
|
|
import { Image, Typography, Skeleton } from "antd"; // 引入 antd 组件
|
2025-02-23 22:51:22 +08:00
|
|
|
import { CourseDetailContext } from "./CourseDetailContext";
|
2025-02-24 11:50:33 +08:00
|
|
|
import {
|
|
|
|
CalendarOutlined,
|
|
|
|
EyeOutlined,
|
|
|
|
PlayCircleOutlined,
|
|
|
|
} from "@ant-design/icons";
|
2025-02-24 09:33:03 +08:00
|
|
|
import dayjs from "dayjs";
|
2025-02-24 11:50:33 +08:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2025-02-23 22:51:22 +08:00
|
|
|
|
2025-02-24 10:16:39 +08:00
|
|
|
export const CourseDetailDescription: React.FC = () => {
|
2025-02-24 11:50:33 +08:00
|
|
|
const { course, isLoading, selectedLectureId, setSelectedLectureId } =
|
2025-02-24 10:16:39 +08:00
|
|
|
useContext(CourseDetailContext);
|
2025-02-23 22:51:22 +08:00
|
|
|
const { Paragraph, Title } = Typography;
|
2025-02-24 11:50:33 +08:00
|
|
|
const firstLectureId = useMemo(() => {
|
|
|
|
return course?.sections?.[0]?.lectures?.[0]?.id;
|
|
|
|
}, [course]);
|
|
|
|
const navigate = useNavigate();
|
2025-02-23 22:51:22 +08:00
|
|
|
return (
|
|
|
|
<div className="w-full bg-white shadow-md rounded-lg border border-gray-200 p-6">
|
|
|
|
{isLoading || !course ? (
|
|
|
|
<Skeleton active paragraph={{ rows: 4 }} />
|
|
|
|
) : (
|
|
|
|
<div className="space-y-4">
|
2025-02-24 10:16:39 +08:00
|
|
|
{!selectedLectureId && (
|
|
|
|
<>
|
2025-02-24 11:50:33 +08:00
|
|
|
<div className="relative my-4 overflow-hidden flex justify-center items-center">
|
2025-02-24 10:16:39 +08:00
|
|
|
<Image
|
|
|
|
src={course?.meta?.thumbnail}
|
|
|
|
preview={false}
|
|
|
|
className="w-full h-full object-cover z-0"
|
|
|
|
/>
|
2025-02-24 11:50:33 +08:00
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
setSelectedLectureId(firstLectureId);
|
|
|
|
}}
|
|
|
|
className="w-full h-full absolute top-0 z-10 bg-black opacity-30 transition-opacity duration-300 ease-in-out hover:opacity-70 cursor-pointer">
|
|
|
|
<PlayCircleOutlined className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-white text-4xl z-10" />
|
|
|
|
</div>
|
2025-02-24 10:16:39 +08:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
2025-02-24 09:33:03 +08:00
|
|
|
<div className="text-lg font-bold">{"课程简介:"}</div>
|
|
|
|
<div className="text-gray-600 flex justify-start gap-4">
|
|
|
|
<div>{course?.subTitle}</div>
|
|
|
|
<div className="flex gap-1">
|
|
|
|
<EyeOutlined></EyeOutlined>
|
2025-02-25 09:11:15 +08:00
|
|
|
<div>{course?.meta?.views || 0}</div>
|
2025-02-24 09:33:03 +08:00
|
|
|
</div>
|
|
|
|
<div className="flex gap-1">
|
|
|
|
<CalendarOutlined></CalendarOutlined>
|
|
|
|
{dayjs(course?.createdAt).format("YYYY年M月D日")}
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-02-23 22:51:22 +08:00
|
|
|
<Paragraph
|
2025-02-24 09:33:03 +08:00
|
|
|
className="text-gray-600"
|
2025-02-23 22:51:22 +08:00
|
|
|
ellipsis={{
|
|
|
|
rows: 3,
|
|
|
|
expandable: true,
|
|
|
|
symbol: "展开",
|
|
|
|
onExpand: () => console.log("展开"),
|
|
|
|
}}>
|
2025-02-24 09:33:03 +08:00
|
|
|
{course?.content}
|
2025-02-23 22:51:22 +08:00
|
|
|
</Paragraph>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|