diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 71e4705..ea7ff95 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"; @@ -66,7 +67,7 @@ const CoursePage = () => { useEffect(() => { if (learnRecord?.progress) { setUserCourseProgress(Math.floor(learnRecord.progress / 100)); - } else if (learnHourRecord) { + } else if (learnHourRecord && !isEmptyObject(learnHourRecord)) { setUserCourseProgress(1); } else { setUserCourseProgress(0); @@ -87,7 +88,7 @@ const CoursePage = () => { />
-
{course?.title}
+
{course?.title + ""}
diff --git a/src/pages/course/video.tsx b/src/pages/course/video.tsx index 8f2265d..e540291 100644 --- a/src/pages/course/video.tsx +++ b/src/pages/course/video.tsx @@ -44,7 +44,6 @@ const CoursePlayPage = () => { const totalRef = useRef(0); useEffect(() => { - window.player && window.player.destroy(); getCourse(); getDetail(); }, [params.courseId, params.hourId]); @@ -129,6 +128,7 @@ const CoursePlayPage = () => { const getVideoUrl = (data: any) => { Course.playUrl(Number(params.courseId), Number(params.hourId)).then( (res: any) => { + window.player && window.player.destroy(); setPlayUrl(res.data.url); initDPlayer(res.data.url, 0, data); } @@ -236,7 +236,6 @@ const CoursePlayPage = () => { }; const playVideo = (cid: number, id: number) => { - window.player && window.player.destroy(); navigate(`/course/${cid}/hour/${id}`, { replace: true }); }; diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 733ee82..d7ff20f 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -7,6 +7,7 @@ import { useSelector } from "react-redux"; import { useNavigate, useLocation } from "react-router-dom"; import { Footer, TabBarFooter, Empty } from "../../components"; import { CoursesModel } from "./compenents/courses-model"; +import { isEmptyObject } from "../../utils/index"; type LocalUserLearnHourRecordModel = { [key: number]: UserLearnHourRecordModel; @@ -74,7 +75,7 @@ const IndexPage = () => { return; } getData(); - }, [tabKey, currentDepId, categoryId]); + }, [currentDepId, categoryId]); const getData = () => { setLoading(true); @@ -127,7 +128,7 @@ const IndexPage = () => { const getParams = () => { user.coursesCategories().then((res: any) => { const categories = res.data.categories; - if (JSON.stringify(categories) !== "{}") { + if (!isEmptyObject(categories)) { const new_arr: any[] = checkArr(categories, 0); new_arr.unshift({ key: 0, @@ -204,9 +205,16 @@ const IndexPage = () => { activeKey={tabKey} onChange={(key: any) => { setTabKey(key); - navigate( - "/?cid=" + categoryId + "&catName=" + categoryText + "&tab=" + key - ); + setTimeout(() => { + navigate( + "/?cid=" + + categoryId + + "&catName=" + + categoryText + + "&tab=" + + key + ); + }, 250); }} style={{ "--fixed-active-line-width": "20px", diff --git a/src/pages/study/compenents/courses-model.module.scss b/src/pages/study/compenents/courses-model.module.scss index 4489140..40bcef5 100644 --- a/src/pages/study/compenents/courses-model.module.scss +++ b/src/pages/study/compenents/courses-model.module.scss @@ -4,6 +4,7 @@ display: flex; flex-direction: row; align-items: center; + margin-bottom: 20px; .info { flex: 1; height: 75px; diff --git a/src/pages/study/compenents/courses-model.tsx b/src/pages/study/compenents/courses-model.tsx index 0a78b6d..a92a6e1 100644 --- a/src/pages/study/compenents/courses-model.tsx +++ b/src/pages/study/compenents/courses-model.tsx @@ -91,7 +91,6 @@ export const CoursesModel: React.FC = ({
-
); }; diff --git a/src/pages/study/index.module.scss b/src/pages/study/index.module.scss index 8b3df06..eaea589 100644 --- a/src/pages/study/index.module.scss +++ b/src/pages/study/index.module.scss @@ -13,14 +13,14 @@ float: left; height: auto; box-sizing: border-box; - padding: 0px 20px 80px 20px; + padding: 0px 20px 60px 20px; text-align: left; overflow-x: hidden; overflow-y: auto; padding-bottom: calc( 80px + constant(safe-area-inset-bottom) ); /* 兼容iOS 11.0 - 11.2 */ - padding-bottom: calc(80px + env(safe-area-inset-bottom)); /* 兼容iOS 11.2+ */ + padding-bottom: calc(60px + env(safe-area-inset-bottom)); /* 兼容iOS 11.2+ */ .label { width: 100%; height: 40px; diff --git a/src/pages/study/index.tsx b/src/pages/study/index.tsx index 34b6aa5..f327744 100644 --- a/src/pages/study/index.tsx +++ b/src/pages/study/index.tsx @@ -21,37 +21,41 @@ const StudyPage = () => { }, []); const getCourses = () => { + if (loading) { + return; + } setLoading(true); - course.latestLearn().then((res: any) => { - let data = res.data; - let today: CourseModel[] = []; - let yesterday: CourseModel[] = []; - let box: CourseModel[] = []; - if (data && data.length > 0) { - data.map((item: any) => { - if ( - item.hour_record && - moment(item.hour_record.updated_at).isSame(moment(), "day") - ) { - today.push(item); - } else if ( - item.hour_record && - moment(item.hour_record.updated_at).isSame( - moment().subtract(1, "day"), - "day" - ) - ) { - yesterday.push(item); - } else { - box.push(item); - } - setTodayCourses(today); - setYesterdayCourses(yesterday); - setCourses(box); - }); - } - setLoading(false); - }); + course + .latestLearn() + .then((res: any) => { + let data = res.data; + let today: CourseModel[] = []; + let yesterday: CourseModel[] = []; + let box: CourseModel[] = []; + if (data && data.length > 0) { + data.map((item: any) => { + let time = moment(item.hour_record.updated_at) + .utcOffset(0) + .format("YYYY-MM-DD HH:mm:ss"); + if (moment(time).isSame(moment(), "day")) { + today.push(item); + } else if ( + moment(time).isSame(moment().subtract(1, "day"), "day") + ) { + yesterday.push(item); + } else { + box.push(item); + } + }); + } + setTodayCourses(today); + setYesterdayCourses(yesterday); + setCourses(box); + setLoading(false); + }) + .catch((e) => { + setLoading(false); + }); }; return ( @@ -76,7 +80,10 @@ const StudyPage = () => {
))} - {!loading && courses.length === 0 && } + {!loading && + courses.length === 0 && + todayCourses.length === 0 && + yesterdayCourses.length === 0 && } {!loading && ( <> {todayCourses.length > 0 && ( diff --git a/src/utils/index.ts b/src/utils/index.ts index 9471155..4b06c5e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -13,7 +13,7 @@ export function clearToken() { } export function dateFormat(dateStr: string) { - return moment(dateStr).format("YYYY-MM-DD HH:mm"); + return moment(dateStr).utcOffset(0).format("YYYY-MM-DD HH:mm"); } export function getHost() { @@ -76,3 +76,7 @@ export function isMobile() { ); return flag; } + +export function isEmptyObject(obj: Object) { + return Object.keys(obj).length === 0; +}