diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 94abde3..3dfd318 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -4,6 +4,7 @@ import styles from "./index.module.scss"; import { useNavigate, useParams } from "react-router-dom"; import backIcon from "../../assets/images/commen/icon-back-n.png"; import { course as vod } from "../../api/index"; +import { isEmptyObject } from "../../utils/index"; import { Empty } from "../../components"; import { HourCompenent } from "./compenents/hour"; @@ -68,7 +69,7 @@ const CoursePage = () => { useEffect(() => { if (learnRecord?.progress) { setUserCourseProgress(Math.floor(learnRecord.progress / 100)); - } else if (learnHourRecord && JSON.stringify(learnHourRecord) !== "{}") { + } else if (learnHourRecord && !isEmptyObject(learnHourRecord)) { setUserCourseProgress(1); } else { setUserCourseProgress(0); diff --git a/src/utils/index.ts b/src/utils/index.ts index 38ba46f..4b06c5e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -76,3 +76,7 @@ export function isMobile() { ); return flag; } + +export function isEmptyObject(obj: Object) { + return Object.keys(obj).length === 0; +}