From cd93d27e06b60461611d150014950ed41644a2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Tue, 4 Jul 2023 15:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E3=80=81=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E9=A1=B5=E9=9D=A2=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/compenents/courses-model.tsx | 28 +- src/pages/index/index.tsx | 47 +--- .../compenents/courses-model.module.scss | 74 +++++ src/pages/study/compenents/courses-model.tsx | 97 +++++++ src/pages/study/index.tsx | 256 ++---------------- 5 files changed, 235 insertions(+), 267 deletions(-) create mode 100644 src/pages/study/compenents/courses-model.module.scss create mode 100644 src/pages/study/compenents/courses-model.tsx diff --git a/src/pages/index/compenents/courses-model.tsx b/src/pages/index/compenents/courses-model.tsx index 54df993..9a3d505 100644 --- a/src/pages/index/compenents/courses-model.tsx +++ b/src/pages/index/compenents/courses-model.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import { Image, ProgressBar } from "antd-mobile"; import { useNavigate } from "react-router-dom"; import styles from "./courses-model.module.scss"; @@ -9,7 +9,8 @@ interface PropInterface { title: string; thumb: string; isRequired: number; - progress: number; + record: any; + hourCount: number; } export const CoursesModel: React.FC = ({ @@ -17,9 +18,22 @@ export const CoursesModel: React.FC = ({ title, thumb, isRequired, - progress, + record, + hourCount, }) => { const navigate = useNavigate(); + const [userCourseProgress, setUserCourseProgress] = useState(0); + + useEffect(() => { + if (record?.progress) { + setUserCourseProgress(Math.floor(record.progress / 100)); + } else if (hourCount && hourCount > 0) { + setUserCourseProgress(1); + } else { + setUserCourseProgress(0); + } + }, [record, hourCount]); + return ( <>
= ({ {isRequired === 0 && (
选修课
)} - {progress == 0 && ( + {userCourseProgress == 0 && ( <> = ({ 未学习 )} - {progress > 0 && progress < 100 && ( + {userCourseProgress > 0 && userCourseProgress < 100 && ( = ({ }} /> )} - {progress >= 100 && ( + {userCourseProgress >= 100 && (
{ const ref = useRef(null); const navigate = useNavigate(); @@ -22,7 +26,8 @@ const IndexPage = () => { const [categoryText, setCategoryText] = useState( String(result.get("catName") || "所有分类") ); - const [learnCourseRecords, setLearnCourseRecords] = useState({}); + const [learnCourseRecords, setLearnCourseRecords] = + useState({}); const [learnCourseHourCount, setLearnCourseHourCount] = useState({}); const systemConfig = useSelector((state: any) => state.systemConfig.value); const currentDepId = useSelector( @@ -293,38 +298,14 @@ const IndexPage = () => { <> {coursesList.map((item: any) => (
- {learnCourseRecords[item.id] && ( - - )} - {!learnCourseRecords[item.id] && - learnCourseHourCount[item.id] && - learnCourseHourCount[item.id] > 0 && ( - - )} - {!learnCourseRecords[item.id] && - !learnCourseHourCount[item.id] && ( - - )} +
))}
diff --git a/src/pages/study/compenents/courses-model.module.scss b/src/pages/study/compenents/courses-model.module.scss new file mode 100644 index 0000000..4489140 --- /dev/null +++ b/src/pages/study/compenents/courses-model.module.scss @@ -0,0 +1,74 @@ +.item { + width: 100%; + height: 75px; + display: flex; + flex-direction: row; + align-items: center; + .info { + flex: 1; + height: 75px; + display: flex; + flex-direction: column; + justify-content: space-between; + .title { + width: 100%; + height: 42px; + font-size: 15px; + font-weight: 400; + color: rgba(0, 0, 0, 0.88); + line-height: 21px; + overflow: hidden; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + } + .status-content { + width: 100%; + display: flex; + align-items: center; + .type { + width: 46px; + height: 24px; + background: rgba(255, 77, 79, 0.1); + border-radius: 4px; + font-size: 12px; + font-weight: 400; + color: #ff4d4f; + display: flex; + align-items: center; + justify-content: center; + margin-right: 20px; + } + .active-type { + width: 46px; + height: 24px; + background: rgba(#ff9900, 0.1); + border-radius: 4px; + font-size: 12px; + font-weight: 400; + color: #ff9900; + display: flex; + align-items: center; + justify-content: center; + margin-right: 20px; + } + + .no-pro { + height: 12px; + font-size: 12px; + font-weight: 400; + color: rgba(0, 0, 0, 0.45); + line-height: 12px; + margin-left: 10px; + } + .success { + display: flex; + align-items: center; + font-size: 12px; + font-weight: 400; + color: #ff4d4f; + } + } + } +} diff --git a/src/pages/study/compenents/courses-model.tsx b/src/pages/study/compenents/courses-model.tsx new file mode 100644 index 0000000..0a78b6d --- /dev/null +++ b/src/pages/study/compenents/courses-model.tsx @@ -0,0 +1,97 @@ +import React, { useEffect, useState } from "react"; +import { Image, ProgressBar } from "antd-mobile"; +import { useNavigate } from "react-router-dom"; +import styles from "./courses-model.module.scss"; +import mediaIcon from "../../../assets/images/commen/icon-medal.png"; + +interface PropInterface { + id: number; + title: string; + thumb: string; + isRequired: number; + record: any; +} + +export const CoursesModel: React.FC = ({ + id, + title, + thumb, + isRequired, + record, +}) => { + const navigate = useNavigate(); + const [userCourseProgress, setUserCourseProgress] = useState(0); + + useEffect(() => { + if (record?.progress) { + setUserCourseProgress(Math.floor(record.progress / 100)); + } else { + setUserCourseProgress(1); + } + }, [record]); + + return ( + <> +
{ + navigate(`/course/${id}`); + }} + > + +
+
{title}
+
+ {isRequired === 1 &&
必修课
} + {isRequired === 0 && ( +
选修课
+ )} + {userCourseProgress == 1 && ( + + )} + {userCourseProgress > 1 && userCourseProgress < 100 && ( + + )} + {userCourseProgress >= 100 && ( +
+ + 恭喜你学完此课程! +
+ )} +
+
+
+
+ + ); +}; diff --git a/src/pages/study/index.tsx b/src/pages/study/index.tsx index 1a2e0d3..29afaf8 100644 --- a/src/pages/study/index.tsx +++ b/src/pages/study/index.tsx @@ -1,18 +1,16 @@ import { useState, useEffect } from "react"; -import { Image, ProgressBar, Skeleton } from "antd-mobile"; +import { Skeleton } from "antd-mobile"; import styles from "./index.module.scss"; -import { useNavigate } from "react-router-dom"; import { course } from "../../api/index"; import { TabBarFooter, Empty } from "../../components"; -import mediaIcon from "../../assets/images/commen/icon-medal.png"; +import { CoursesModel } from "./compenents/courses-model"; import moment from "moment"; const StudyPage = () => { - const navigate = useNavigate(); const [loading, setLoading] = useState(false); - const [todayCourses, setTodayCourses] = useState([]); - const [yesterdayCourses, setYesterdayCourses] = useState([]); - const [courses, setCourses] = useState([]); + const [todayCourses, setTodayCourses] = useState([]); + const [yesterdayCourses, setYesterdayCourses] = useState([]); + const [courses, setCourses] = useState([]); useEffect(() => { document.title = "最近学习"; @@ -26,9 +24,9 @@ const StudyPage = () => { setLoading(true); course.latestLearn().then((res: any) => { let data = res.data; - let today: any = []; - let yesterday: any = []; - let box: any = []; + let today: CourseModel[] = []; + let yesterday: CourseModel[] = []; + let box: CourseModel[] = []; if (data && data.length > 0) { data.map((item: any) => { if ( @@ -79,7 +77,6 @@ const StudyPage = () => {
))} {!loading && courses.length === 0 && } - {/*
更早
*/} {!loading && ( <> {todayCourses.length > 0 && ( @@ -88,78 +85,13 @@ const StudyPage = () => { {todayCourses.map((item: any, index: number) => (
{item.course && ( -
{ - navigate(`/course/${item.course.id}`); - }} - > - -
-
- {item.course.title} -
-
- {item.course.is_required === 1 && ( -
必修课
- )} - {item.course.is_required === 0 && ( -
- 选修课 -
- )} - {item.record && ( - <> - {item.record.progress < 10000 && ( - - )} - {item.record.progress >= 10000 && ( - <> - - - 恭喜你学完此课程! - - - )} - - )} - {!item.record && ( - - )} -
-
-
+ )}
))} @@ -171,78 +103,13 @@ const StudyPage = () => { {yesterdayCourses.map((item: any, index: number) => (
{item.course && ( -
{ - navigate(`/course/${item.course.id}`); - }} - > - -
-
- {item.course.title} -
-
- {item.course.is_required === 1 && ( -
必修课
- )} - {item.course.is_required === 0 && ( -
- 选修课 -
- )} - {item.record && ( - <> - {item.record.progress < 10000 && ( - - )} - {item.record.progress >= 10000 && ( - <> - - - 恭喜你学完此课程! - - - )} - - )} - {!item.record && ( - - )} -
-
-
+ )}
))} @@ -254,78 +121,13 @@ const StudyPage = () => { {courses.map((item: any, index: number) => (
{item.course && ( -
{ - navigate(`/course/${item.course.id}`); - }} - > - -
-
- {item.course.title} -
-
- {item.course.is_required === 1 && ( -
必修课
- )} - {item.course.is_required === 0 && ( -
- 选修课 -
- )} - {item.record && ( - <> - {item.record.progress < 10000 && ( - - )} - {item.record.progress >= 10000 && ( - <> - - - 恭喜你学完此课程! - - - )} - - )} - {!item.record && ( - - )} -
-
-
+ )}
))}