import { useEffect, useState } from "react"; import { Row, Col, Spin, Image, Progress } from "antd"; import styles from "./index.module.scss"; import { useParams } from "react-router-dom"; import { course as Course } from "../../api/index"; import mediaIcon from "../../assets/images/commen/icon-medal.png"; import { HourCompenent } from "./compenents/hour"; import { Empty } from "../../compenents"; const CoursePage = () => { const params = useParams(); const [loading, setLoading] = useState(true); const [course, setCourse] = useState({}); const [chapters, setChapters] = useState([]); const [hours, setHours] = useState({}); const [learnRecord, setLearnRecord] = useState({}); const [learnHourRecord, setLearnHourRecord] = useState({}); useEffect(() => { getDetail(); }, [params.courseId]); const getDetail = () => { setLoading(true); Course.detail(Number(params.courseId)) .then((res: any) => { document.title = res.data.course.title; setCourse(res.data.course); setChapters(res.data.chapters); setHours(res.data.hours); if (res.data.learn_record) { setLearnRecord(res.data.learn_record); } if (res.data.learn_hour_records) { setLearnHourRecord(res.data.learn_hour_records); } setLoading(false); }) .catch((e) => { setLoading(false); }); }; return (
{loading && (
)} {!loading && ( <>
{course.title}
{course.is_required === 1 && (
必修课
)} {course.is_required === 0 && (
选修课
)} {learnRecord.progress / 100 >= 100 && (
恭喜你学完此课程!
)}
{JSON.stringify(learnRecord) === "{}" && JSON.stringify(learnHourRecord) === "{}" && ( `${percent}%`} /> )} {JSON.stringify(learnRecord) === "{}" && JSON.stringify(learnHourRecord) !== "{}" && ( `${percent}%`} /> )} {JSON.stringify(learnRecord) !== "{}" && JSON.stringify(learnHourRecord) !== "{}" && ( `${percent}%`} /> )}
{course.short_desc && (
{course.short_desc}
)}
{chapters.length === 0 && JSON.stringify(hours) === "{}" && ( )} {chapters.length === 0 && JSON.stringify(hours) !== "{}" && (
{hours[0].map((item: any, index: number) => (
{learnHourRecord[item.id] && ( )} {!learnHourRecord[item.id] && ( )}
))}
)} {chapters.length > 0 && JSON.stringify(hours) !== "{}" && (
{chapters.map((item: any, index: number) => (
{item.name}
{hours[item.id].map((it: any, int: number) => (
{learnHourRecord[it.id] && ( )} {!learnHourRecord[it.id] && ( )}
))}
))}
)}
)}
); }; export default CoursePage;