diff --git a/src/pages/index/compenents/courses-model.module.scss b/src/pages/index/compenents/courses-model.module.scss index d5122c5..f4d59fa 100644 --- a/src/pages/index/compenents/courses-model.module.scss +++ b/src/pages/index/compenents/courses-model.module.scss @@ -56,6 +56,9 @@ font-weight: 400; color: #ff4d4f; line-height: 24px; + display: flex; + align-items: center; + justify-content: center; } .active-type { width: 52px; @@ -66,6 +69,9 @@ font-weight: 400; color: #ff9900; line-height: 24px; + display: flex; + align-items: center; + justify-content: center; } } } diff --git a/src/pages/index/index.module.scss b/src/pages/index/index.module.scss index ba30963..63bd03c 100644 --- a/src/pages/index/index.module.scss +++ b/src/pages/index/index.module.scss @@ -40,12 +40,14 @@ display: flex; align-items: center; .info-item { - width: 216px; - text-align: left; + width: auto; font-size: 16px; font-weight: 600; color: rgba(0, 0, 0, 0.45); line-height: 24px; + &:last-child { + margin-left: 50px; + } strong { font-size: 20px; color: rgba(0, 0, 0, 0.88); diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 5e58fd4..cf1942d 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -7,10 +7,13 @@ import { AnyIfEmpty, useSelector } from "react-redux"; import { CoursesModel } from "./compenents/courses-model"; import myLesoon from "../../assets/images/commen/icon-mylesoon.png"; import studyTime from "../../assets/images/commen/icon-studytime.png"; +import { studyTimeFormat } from "../../utils/index"; const IndexPage = () => { const [tabKey, setTabKey] = useState(0); const [coursesList, setCoursesList] = useState([]); + const [learnCourseRecords, setLearnCourseRecords] = useState({}); + const [stats, setStats] = useState({}); const departments = useSelector( (state: any) => state.loginUser.value.departments @@ -18,12 +21,31 @@ const IndexPage = () => { useEffect(() => { getData(); - }, [departments]); + }, [tabKey]); const getData = () => { user.courses(departments[0].id).then((res: any) => { - setCoursesList(res.data.courses); - console.log(res.data.courses); + setStats(res.data.stats); + setLearnCourseRecords(res.data.learn_course_records); + if (tabKey === 0) { + setCoursesList(res.data.courses); + } else if (tabKey === 1) { + const arr: any = []; + res.data.courses.map((item: any) => { + if (item.is_required === 1) { + arr.push(item); + } + }); + setCoursesList(arr); + } else if (tabKey === 2) { + const arr: any = []; + res.data.courses.map((item: any) => { + if (item.is_required === 0) { + arr.push(item); + } + }); + setCoursesList(arr); + } }); }; @@ -64,10 +86,14 @@ const IndexPage = () => {
- 必修课:已完成 3 / 10 + 必修课:已完成 + {stats.required_finished_hour_count} + / {stats.required_hour_count}
- 选修课:已完成 3 / 10 + 选修课:已完成 + {stats.nun_required_finished_hour_count} + / {stats.nun_required_hour_count}
@@ -78,10 +104,39 @@ const IndexPage = () => {
- 今日:1 小时 23 分钟 + 今日: + {studyTimeFormat(stats.today_learn_duration)[0] !== 0 && ( + <> + + {" "} + {studyTimeFormat(stats.today_learn_duration)[0]}{" "} + + 天 + + )} + + {" "} + {studyTimeFormat(stats.today_learn_duration)[1]}{" "} + + 小时 + + {" "} + {studyTimeFormat(stats.today_learn_duration)[2]}{" "} + + 分钟
- 累计:24 小时 33 分钟 + 累计: + {studyTimeFormat(stats.learn_duration)[0] !== 0 && ( + <> + {studyTimeFormat(stats.learn_duration)[0]} + 天 + + )} + {studyTimeFormat(stats.learn_duration || 0)[1]} + 小时 + {studyTimeFormat(stats.learn_duration || 0)[2]} + 分钟
@@ -97,7 +152,7 @@ const IndexPage = () => { diff --git a/src/utils/index.ts b/src/utils/index.ts index d967976..e56df3e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -18,17 +18,10 @@ export function dateFormat(dateStr: string) { export function studyTimeFormat(dateStr: number) { var d = moment.duration(dateStr, "seconds"); - let value = - Math.floor(d.asDays()) + "天" + d.hours() + "时" + d.minutes() + "分"; - - if (Math.floor(d.asDays()) === 0) { - if (d.hours() === 0) { - value = d.minutes() + "分"; - } else { - value = d.hours() + "时" + d.minutes() + "分"; - } - } - + let value = []; + value.push(Math.floor(d.asDays())); + value.push(d.hours()); + value.push(d.minutes()); return value; }