From 00b74f5ab0820ff4e86c8f50f481899f6a79af6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Wed, 5 Jul 2023 09:44:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E8=AF=A6=E6=83=85=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/course/index.tsx | 3 ++- src/utils/index.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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; +}