diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index b97335c..24b7bd7 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { Image, Progress } from "antd"; +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"; @@ -9,7 +9,7 @@ import { Empty } from "../../compenents"; const CoursePage = () => { const params = useParams(); - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); const [course, setCourse] = useState({}); const [chapters, setChapters] = useState([]); const [hours, setHours] = useState({}); @@ -23,177 +23,159 @@ const CoursePage = () => { 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); - }); + 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); } - setTotalHours(arr); - } - setLoading(false); - }); + 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); + }) + .catch((e) => { + setLoading(false); + }); }; return (
-
-
-
- -
-
{course.title}
-
- {course.is_required === 1 && ( -
必修课
- )} - {course.is_required === 0 && ( -
选修课
- )} - {learnRecord.progress / 100 >= 100 && ( -
- - 恭喜你学完此课程! + {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}
+ )}
- {JSON.stringify(learnRecord) === "{}" && - JSON.stringify(learnHourRecord) === "{}" && ( - `${percent}%`} - /> +
+ {chapters.length === 0 && JSON.stringify(hours) === "{}" && ( + )} - {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] && ( + {chapters.length === 0 && JSON.stringify(hours) !== "{}" && ( +
+ {hours[0].map((item: any, index: number) => ( +
+ {learnHourRecord[item.id] && ( getDetail()} totalHours={totalHours} + onChange={() => getDetail()} > )} - {!learnHourRecord[it.id] && ( + {!learnHourRecord[item.id] && ( getDetail()} @@ -202,10 +184,52 @@ const CoursePage = () => {
))}
- ))} + )} + {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()} + > + )} +
+ ))} +
+ ))} +
+ )}
- )} -
+ + )}
); };