import { useEffect, useState } from "react"; import { 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(false); const [course, setCourse] = useState({}); const [chapters, setChapters] = useState([]); const [hours, setHours] = useState({}); const [learnRecord, setLearnRecord] = useState({}); const [learnHourRecord, setLearnHourRecord] = useState({}); const [totalHours, setTotalHours] = useState([]); useEffect(() => { getDetail(); }, [params.courseId]); const getDetail = () => { setLoading(true); Course.detail(Number(params.courseId)).then((res: any) => { 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); } if (res.data.chapters.length === 0) { setTotalHours(res.data.hours[0]); } else if (res.data.chapters.length > 0) { const arr: any = []; for (let key in res.data.hours) { res.data.hours[key].map((item: any) => { arr.push(item); }); } setTotalHours(arr); } setLoading(false); }); }; return (
{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] && ( getDetail()} > )} {!learnHourRecord[item.id] && ( getDetail()} > )}
))}
)} {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] && ( getDetail()} totalHours={totalHours} > )} {!learnHourRecord[it.id] && ( getDetail()} > )}
))}
))}
)}
); }; export default CoursePage;